diff --git a/src/main/java/fr/firstmegagame4/env/driven/assets/client/EDAEnvJsonVisitors.java b/src/main/java/fr/firstmegagame4/env/driven/assets/client/EDAEnvJsonVisitors.java index 3f47459..33c74ca 100644 --- a/src/main/java/fr/firstmegagame4/env/driven/assets/client/EDAEnvJsonVisitors.java +++ b/src/main/java/fr/firstmegagame4/env/driven/assets/client/EDAEnvJsonVisitors.java @@ -34,7 +34,7 @@ else if (FabricLoader.getInstance().isModLoaded("sodium")) { } else if (FabricLoader.getInstance().isModLoaded("axiom")) { if (view instanceof ChunkedBlockRegion region) { - return new AxiomBlockEnvJsonVisitor.ChunkedBlock(region, pos); + return new AxiomBlockEnvJsonVisitor.ChunkedBlockVisitor(region, pos); } } return new EmptyVisitor(); diff --git a/src/main/java/fr/firstmegagame4/env/driven/assets/client/impl/axiom/AxiomBlockEnvJsonVisitor.java b/src/main/java/fr/firstmegagame4/env/driven/assets/client/impl/axiom/AxiomBlockEnvJsonVisitor.java index cd7214a..5324630 100644 --- a/src/main/java/fr/firstmegagame4/env/driven/assets/client/impl/axiom/AxiomBlockEnvJsonVisitor.java +++ b/src/main/java/fr/firstmegagame4/env/driven/assets/client/impl/axiom/AxiomBlockEnvJsonVisitor.java @@ -1,6 +1,7 @@ package fr.firstmegagame4.env.driven.assets.client.impl.axiom; import com.moulberry.axiom.render.regions.ChunkedBlockRegion; +import com.moulberry.axiom.render.regions.MapBlockAndTintGetter; import fr.firstmegagame4.env.driven.assets.client.EDAEnvJsonVisitors; import fr.firstmegagame4.env.driven.assets.client.EDAUtils; import fr.firstmegagame4.env.json.api.EnvJsonVisitor; @@ -21,13 +22,13 @@ */ public class AxiomBlockEnvJsonVisitor { - public static class ChunkedBlock implements EnvJsonVisitor { + public static class ChunkedBlockVisitor implements EnvJsonVisitor { private final ChunkedBlockRegion region; private final ClientWorld fallback; private final BlockPos pos; - public ChunkedBlock(ChunkedBlockRegion region, BlockPos pos) { + public ChunkedBlockVisitor(ChunkedBlockRegion region, BlockPos pos) { this.region = region; this.fallback = MinecraftClient.getInstance().world; this.pos = pos; @@ -104,4 +105,88 @@ public boolean applyVoid(VoidEnvJsonRule.Localization localization) { }; } } + + public static class MapBlockVisitor implements EnvJsonVisitor { + + private final MapBlockAndTintGetter map; + private final ClientWorld fallback; + private final BlockPos pos; + + public MapBlockVisitor(MapBlockAndTintGetter map, BlockPos pos) { + this.map = map; + this.fallback = MinecraftClient.getInstance().world; + this.pos = pos; + } + + @Override + public boolean applyDimensionKey(RegistryKey dimensionKey) { + return this.fallback.getRegistryKey() == dimensionKey; + } + + @Override + public boolean applyDimensionTag(TagKey dimensionTag) { + return EDAUtils.worldIsIn(this.fallback, dimensionTag); + } + + @Override + public boolean applyBiomeKey(RegistryKey biomeKey) { + return this.fallback.getBiome(this.pos).matchesKey(biomeKey); + } + + @Override + public boolean applyBiomeTag(TagKey biomeTag) { + return this.fallback.getBiome(this.pos).isIn(biomeTag); + } + + @Override + public boolean applyXCoord(Int2BooleanFunction operation) { + return operation.get(this.pos.getX()); + } + + @Override + public boolean applyYCoord(Int2BooleanFunction operation) { + return operation.get(this.pos.getY()); + } + + @Override + public boolean applyZCoord(Int2BooleanFunction operation) { + return operation.get(this.pos.getZ()); + } + + @Override + public boolean applySubmerged(boolean submerged) { + if (submerged) { + return EDAUtils.lookupSubmerged(this.map, this.pos, this.map::getBlockState); + } else { + return !EDAUtils.lookupSubmerged(this.map, this.pos, this.map::getBlockState); + } + } + + @Override + public boolean applySky(SkyEnvJsonRule.Localization localization) { + return switch (localization) { + case BELOW -> this.pos.getY() < this.fallback.getTopY() - 1; + case AT -> this.pos.getY() == this.fallback.getTopY() - 1; + case ABOVE -> this.pos.getY() > this.fallback.getTopY() - 1; + }; + } + + @Override + public boolean applyWater(WaterEnvJsonRule.Localization localization) { + return switch (localization) { + case BELOW -> this.pos.getY() < this.fallback.getSeaLevel() - 1; + case AT -> this.pos.getY() == this.fallback.getSeaLevel() - 1; + case ABOVE -> this.pos.getY() > this.fallback.getSeaLevel() - 1; + }; + } + + @Override + public boolean applyVoid(VoidEnvJsonRule.Localization localization) { + return switch (localization) { + case BELOW -> this.pos.getY() < this.fallback.getBottomY(); + case AT -> this.pos.getY() == this.fallback.getBottomY(); + case ABOVE -> this.pos.getY() > this.fallback.getBottomY(); + }; + } + } } diff --git a/src/main/java/fr/firstmegagame4/env/driven/assets/client/model/plugin/EDAModelLoadingPlugin.java b/src/main/java/fr/firstmegagame4/env/driven/assets/client/model/plugin/EDAModelLoadingPlugin.java index b44d5b0..f8a6395 100644 --- a/src/main/java/fr/firstmegagame4/env/driven/assets/client/model/plugin/EDAModelLoadingPlugin.java +++ b/src/main/java/fr/firstmegagame4/env/driven/assets/client/model/plugin/EDAModelLoadingPlugin.java @@ -1,6 +1,5 @@ package fr.firstmegagame4.env.driven.assets.client.model.plugin; -import fr.firstmegagame4.env.driven.assets.client.EDAUtils; import fr.firstmegagame4.env.driven.assets.client.duck.BakedModelDuckInterface; import fr.firstmegagame4.env.driven.assets.client.duck.JsonUnbakedModelDuckInterface; import fr.firstmegagame4.env.driven.assets.client.model.EDABakedModel; @@ -14,7 +13,7 @@ public class EDAModelLoadingPlugin implements ModelLoadingPlugin { private static BakedModel modifyModelAfterBake(@Nullable BakedModel model, ModelModifier.AfterBake.Context context) { if (model != null && !model.isBuiltin() && context.sourceModel() instanceof JsonUnbakedModelDuckInterface jum && model instanceof BakedModelDuckInterface ducked) { ((BakedModelDuckInterface) model).env_driven_assets$setEnvJson(jum.env_driven_assets$getEnvJson()); - return new EDABakedModel(context.loader(), model); + return new EDABakedModel(context.loader(), model, context.settings()); } return model; } diff --git a/src/main/resources/env_driven_assets.accesswidener b/src/main/resources/env_driven_assets.accesswidener index d7a4044..d0957d3 100644 --- a/src/main/resources/env_driven_assets.accesswidener +++ b/src/main/resources/env_driven_assets.accesswidener @@ -1,5 +1,6 @@ accessWidener v1 named +accessible class com/moulberry/axiom/render/ChunkRenderOverrider$MappedBlockAndTintGetter accessible class net/minecraft/client/render/model/BakedModelManager$BakingResult accessible class net/minecraft/client/render/model/ModelLoader$BakedModelCacheKey -accessible class net/minecraft/client/render/model/ModelLoader$BakerImpl \ No newline at end of file +accessible class net/minecraft/client/render/model/ModelLoader$BakerImpl