Skip to content

Commit

Permalink
Some Work On Axiom Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Feb 7, 2024
1 parent 7b8f189 commit 259b87f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<World> dimensionKey) {
return this.fallback.getRegistryKey() == dimensionKey;
}

@Override
public boolean applyDimensionTag(TagKey<World> dimensionTag) {
return EDAUtils.worldIsIn(this.fallback, dimensionTag);
}

@Override
public boolean applyBiomeKey(RegistryKey<Biome> biomeKey) {
return this.fallback.getBiome(this.pos).matchesKey(biomeKey);
}

@Override
public boolean applyBiomeTag(TagKey<Biome> 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();
};
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/env_driven_assets.accesswidener
Original file line number Diff line number Diff line change
@@ -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
accessible class net/minecraft/client/render/model/ModelLoader$BakerImpl

0 comments on commit 259b87f

Please sign in to comment.