diff --git a/gradle.properties b/gradle.properties index 074d601..502d72f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,6 @@ satin_version=1.8.0 sodium_version=mc1.19-0.4.2 iris_version=1.19.x-v1.2.5 -mod_version = 6.0.5 +mod_version = 6.1.0 maven_group = net.ludocrypt archives_base_name = limlib \ No newline at end of file diff --git a/src/main/java/net/ludocrypt/limlib/access/BakedModelAccess.java b/src/main/java/net/ludocrypt/limlib/access/BakedModelAccess.java deleted file mode 100644 index 47d4800..0000000 --- a/src/main/java/net/ludocrypt/limlib/access/BakedModelAccess.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.ludocrypt.limlib.access; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import com.mojang.datafixers.util.Pair; - -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Direction; - -public interface BakedModelAccess { - - public Map>>> getSubQuads(); - -} diff --git a/src/main/java/net/ludocrypt/limlib/access/ModelAccess.java b/src/main/java/net/ludocrypt/limlib/access/ModelAccess.java new file mode 100644 index 0000000..94cb841 --- /dev/null +++ b/src/main/java/net/ludocrypt/limlib/access/ModelAccess.java @@ -0,0 +1,15 @@ +package net.ludocrypt.limlib.access; + +import java.util.Optional; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.util.Identifier; + +public interface ModelAccess { + + public Optional getLiminalQuadRenderer(); + + public void setLiminalQuadRenderer(@Nullable Identifier id); + +} diff --git a/src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java b/src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java deleted file mode 100644 index f6af138..0000000 --- a/src/main/java/net/ludocrypt/limlib/access/UnbakedModelAccess.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.ludocrypt.limlib.access; - -import java.util.List; -import java.util.Map; - -import net.minecraft.client.render.model.json.JsonUnbakedModel; -import net.minecraft.client.render.model.json.ModelElement; -import net.minecraft.util.Identifier; - -public interface UnbakedModelAccess { - - public Map> getSubElements(); - - public void putSubElements(Map> map); - - public JsonUnbakedModel getParent(); - -} diff --git a/src/main/java/net/ludocrypt/limlib/api/render/LiminalQuadRenderer.java b/src/main/java/net/ludocrypt/limlib/api/render/LiminalQuadRenderer.java index 77d0826..50e4cf8 100644 --- a/src/main/java/net/ludocrypt/limlib/api/render/LiminalQuadRenderer.java +++ b/src/main/java/net/ludocrypt/limlib/api/render/LiminalQuadRenderer.java @@ -3,15 +3,14 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.List; -import java.util.Optional; import java.util.function.Consumer; +import org.jetbrains.annotations.Nullable; import org.lwjgl.system.MemoryStack; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.datafixers.util.Pair; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -24,6 +23,7 @@ import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat.DrawMode; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; @@ -32,6 +32,7 @@ import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Vec3f; import net.minecraft.util.math.Vector4f; +import net.minecraft.util.math.random.Random; import net.minecraft.world.World; @Environment(EnvType.CLIENT) @@ -41,31 +42,31 @@ public abstract class LiminalQuadRenderer { public List itemRenderQueue = Lists.newArrayList(); - public abstract void renderQuad(BakedQuad quad, BufferBuilder bufferBuilder, Matrix4f matrix, Camera camera, World world, MatrixStack matrices, List>> quads); + public abstract void renderQuad(BakedQuad quad, BufferBuilder bufferBuilder, Matrix4f matrix, Camera camera, World world, MatrixStack matrices, BakedModel model, @Nullable BlockState state, @Nullable Direction dir, Random random); - public void renderQuads(List>> quads, World world, BlockPos pos, BlockState state, MatrixStack matrices, Camera camera) { + public void renderModel(BakedModel model, World world, BlockPos pos, BlockState state, MatrixStack matrices, Camera camera) { Matrix4f matrix = setupMatrix(matrices, camera, true); BufferBuilder bufferBuilder = setupRenderer(matrices, camera); - for (Pair> quadPair : quads) { - BakedQuad quad = quadPair.getFirst(); - if (quadPair.getSecond().isPresent()) { - if (Block.shouldDrawSide(state, world, pos, quadPair.getSecond().get(), pos.offset(quadPair.getSecond().get()))) { - this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, quads); - } - } else { - this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, quads); - } + Random random = Random.create(state.getRenderingSeed(pos)); + + for (Direction dir : Direction.values()) { + model.getQuads(state, dir, random).stream().filter((quad) -> Block.shouldDrawSide(state, world, pos, dir, pos)).forEach((quad) -> this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, model, state, dir, random)); } + model.getQuads(state, null, random).forEach((quad) -> this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, model, state, null, random)); this.endRenderer(bufferBuilder, matrices, camera); } - public void renderItemQuads(List>> quads, World world, ItemStack stack, MatrixStack matrices, Camera camera, boolean inGui) { + public void renderItemModel(BakedModel model, World world, ItemStack stack, MatrixStack matrices, Camera camera, boolean inGui) { Matrix4f matrix = setupMatrix(matrices, camera, !inGui); BufferBuilder bufferBuilder = setupRenderer(matrices, camera); - quads.forEach((pair) -> this.renderQuad(pair.getFirst(), bufferBuilder, matrix, camera, world, matrices, quads)); + Random random = Random.create(42L); + for (Direction dir : Direction.values()) { + model.getQuads(null, dir, random).forEach((quad) -> this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, model, null, dir, random)); + } + model.getQuads(null, null, random).forEach((quad) -> this.renderQuad(quad, bufferBuilder, matrix, camera, world, matrices, model, null, null, random)); this.endRenderer(bufferBuilder, matrices, camera); } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/WorldRendererMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/WorldRendererMixin.java index 4c3ef0d..d5b9d51 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/WorldRendererMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/WorldRendererMixin.java @@ -16,8 +16,8 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.loader.api.FabricLoader; -import net.ludocrypt.limlib.access.BakedModelAccess; import net.ludocrypt.limlib.access.DimensionTypeAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.ludocrypt.limlib.access.RenderDataAccess; import net.ludocrypt.limlib.access.WorldRendererAccess; import net.ludocrypt.limlib.api.LiminalEffects; @@ -35,6 +35,7 @@ import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.WorldRenderer; import net.minecraft.client.render.WorldRenderer.ChunkInfo; +import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -177,7 +178,8 @@ public void renderBlocks(Framebuffer framebuffer, float tickDelta, MatrixStack m matrices.push(); matrices.translate(pos.getX() - camera.getPos().getX(), pos.getY() - camera.getPos().getY(), pos.getZ() - camera.getPos().getZ()); - ((BakedModelAccess) MinecraftClient.getInstance().getBlockRenderManager().getModel(state)).getSubQuads().forEach((id, quads) -> LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).renderQuads(quads, world, pos, state, matrices, camera)); + BakedModel model = MinecraftClient.getInstance().getBlockRenderManager().getModel(state); + LimlibRendering.LIMINAL_QUAD_RENDERER.get(((ModelAccess) model).getLiminalQuadRenderer().get()).renderModel(model, world, pos, state, matrices, camera); matrices.pop(); }); diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/ChunkBuilderBuiltChunkRebuildTaskMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/ChunkBuilderBuiltChunkRebuildTaskMixin.java index 0c9265c..9cec8a4 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/ChunkBuilderBuiltChunkRebuildTaskMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/ChunkBuilderBuiltChunkRebuildTaskMixin.java @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import net.ludocrypt.limlib.access.BakedModelAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.ludocrypt.limlib.access.RenderDataAccess; import net.minecraft.block.BlockState; import net.minecraft.client.render.RenderLayer; @@ -40,7 +40,7 @@ public class ChunkBuilderBuiltChunkRebuildTaskMixin { @Inject(method = "Lnet/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask;render(FFFLnet/minecraft/client/render/chunk/BlockBufferBuilderStorage;)Lnet/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk$RebuildTask$RenderData;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/chunk/ChunkRendererRegion;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;", ordinal = 0, shift = Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) private void limlib$render(float cameraX, float cameraY, float cameraZ, BlockBufferBuilderStorage blockBufferBuilderStorage, CallbackInfoReturnable ci, RenderData renderData, int i, BlockPos blockPos, BlockPos blockPos2, ChunkOcclusionDataBuilder chunkOcclusionDataBuilder, ChunkRendererRegion chunkRendererRegion, MatrixStack matrixStack, Set set, Random random, BlockRenderManager blockRenderManager, Iterator var15, BlockPos blockPos3) { BlockState blockState = chunkRendererRegion.getBlockState(blockPos3); - if (!((BakedModelAccess) blockRenderManager.getModel(blockState)).getSubQuads().isEmpty()) { + if (((ModelAccess) blockRenderManager.getModel(blockState)).getLiminalQuadRenderer().isPresent()) { ((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos3.toImmutable(), blockState); } } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/sodium/ChunkRenderRebuildTaskMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/sodium/ChunkRenderRebuildTaskMixin.java index 10374a0..2f79925 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/sodium/ChunkRenderRebuildTaskMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/chunk/sodium/ChunkRenderRebuildTaskMixin.java @@ -18,7 +18,7 @@ import me.jellysquid.mods.sodium.client.render.pipeline.context.ChunkRenderCacheLocal; import me.jellysquid.mods.sodium.client.util.task.CancellationSource; import me.jellysquid.mods.sodium.client.world.WorldSlice; -import net.ludocrypt.limlib.access.BakedModelAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.ludocrypt.limlib.access.RenderDataAccess; import net.minecraft.block.BlockState; import net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder; @@ -32,7 +32,7 @@ public class ChunkRenderRebuildTaskMixin { @Inject(method = "Lme/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask;performBuild(Lme/jellysquid/mods/sodium/client/gl/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationSource;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/BlockPos$Mutable;set(III)Lnet/minecraft/util/math/BlockPos$Mutable;", ordinal = 1, shift = Shift.AFTER, remap = false), locals = LocalCapture.CAPTURE_FAILHARD, remap = false, require = 0) private void limlib$performBuild$mapped(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable ci, ChunkRenderData.Builder renderData, ChunkOcclusionDataBuilder occluder, ChunkRenderBounds.Builder bounds, ChunkBuildBuffers buffers, ChunkRenderCacheLocal cache, WorldSlice slice, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Mutable blockPos, Mutable offset) { BlockState blockState = slice.getBlockState(blockPos); - if (!((BakedModelAccess) cache.getBlockModels().getModel(blockState)).getSubQuads().isEmpty()) { + if (((ModelAccess) cache.getBlockModels().getModel(blockState)).getLiminalQuadRenderer().isPresent()) { ((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos.toImmutable(), blockState); } } @@ -41,7 +41,7 @@ public class ChunkRenderRebuildTaskMixin { @Inject(method = "Lme/jellysquid/mods/sodium/client/render/chunk/tasks/ChunkRenderRebuildTask;performBuild(Lme/jellysquid/mods/sodium/client/gl/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationSource;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/class_2338$class_2339;method_10103(III)Lnet/minecraft/class_2338$class_2339;", ordinal = 1, shift = Shift.AFTER, remap = false), locals = LocalCapture.CAPTURE_FAILHARD, remap = false, require = 0) private void limlib$performBuild$unmapped(ChunkBuildContext buildContext, CancellationSource cancellationSource, CallbackInfoReturnable ci, ChunkRenderData.Builder renderData, ChunkOcclusionDataBuilder occluder, ChunkRenderBounds.Builder bounds, ChunkBuildBuffers buffers, ChunkRenderCacheLocal cache, WorldSlice slice, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, Mutable blockPos, Mutable offset) { BlockState blockState = slice.getBlockState(blockPos); - if (!((BakedModelAccess) cache.getBlockModels().getModel(blockState)).getSubQuads().isEmpty()) { + if (((ModelAccess) cache.getBlockModels().getModel(blockState)).getLiminalQuadRenderer().isPresent()) { ((RenderDataAccess) (Object) renderData).getCustomQuadData().put(blockPos.toImmutable(), blockState); } } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/gui/ItemRendererMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/gui/ItemRendererMixin.java index d702ed9..05c80fa 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/gui/ItemRendererMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/gui/ItemRendererMixin.java @@ -11,9 +11,9 @@ import com.google.common.collect.Lists; import net.fabricmc.loader.api.FabricLoader; -import net.ludocrypt.limlib.access.BakedModelAccess; import net.ludocrypt.limlib.access.IrisClientAccess; import net.ludocrypt.limlib.access.ItemRendererAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.ludocrypt.limlib.access.WorldRendererAccess; import net.ludocrypt.limlib.impl.LimlibRendering; import net.minecraft.client.MinecraftClient; @@ -40,7 +40,7 @@ public class ItemRendererMixin implements ItemRendererAccess { MatrixStack matrixStack = new MatrixStack(); matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix().copy()); List immediateRenderer = Lists.newArrayList(); - ((BakedModelAccess) model).getSubQuads().forEach((id, quads) -> (isHandRendering ? LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).heldItemRenderQueue : isItemRendering ? LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).itemRenderQueue : immediateRenderer).add(() -> LimlibRendering.LIMINAL_QUAD_RENDERER.get(id).renderItemQuads(quads, client.world, stack.copy(), matrixStack, client.gameRenderer.getCamera(), inGui))); + LimlibRendering.LIMINAL_QUAD_RENDERER.get(((ModelAccess) model).getLiminalQuadRenderer().get()).renderItemModel(model, client.world, stack.copy(), matrixStack, client.gameRenderer.getCamera(), inGui); immediateRenderer.forEach(Runnable::run); immediateRenderer.clear(); } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/BakedModelMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/BakedModelMixin.java index 92f5812..a213b97 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/BakedModelMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/BakedModelMixin.java @@ -1,26 +1,24 @@ package net.ludocrypt.limlib.mixin.client.render.model; -import java.util.List; -import java.util.Map; import java.util.Optional; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; -import com.google.common.collect.Maps; -import com.mojang.datafixers.util.Pair; - -import net.ludocrypt.limlib.access.BakedModelAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.BakedQuad; import net.minecraft.util.Identifier; -import net.minecraft.util.math.Direction; @Mixin(BakedModel.class) -public interface BakedModelMixin extends BakedModelAccess { +public interface BakedModelMixin extends ModelAccess { + + @Override + default Optional getLiminalQuadRenderer() { + return Optional.empty(); + } @Override - default Map>>> getSubQuads() { - return Maps.newHashMap(); + default void setLiminalQuadRenderer(@Nullable Identifier id) { } } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/GeneralBakedModelMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/GeneralBakedModelMixin.java index ea195fe..5b74f26 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/GeneralBakedModelMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/GeneralBakedModelMixin.java @@ -1,29 +1,27 @@ package net.ludocrypt.limlib.mixin.client.render.model; -import java.util.List; -import java.util.Map; import java.util.Optional; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; -import com.google.common.collect.Maps; -import com.mojang.datafixers.util.Pair; - -import net.ludocrypt.limlib.access.BakedModelAccess; -import net.minecraft.client.render.model.BakedQuad; +import net.ludocrypt.limlib.access.ModelAccess; import net.minecraft.util.Identifier; -import net.minecraft.util.math.Direction; @Mixin(targets = { "net/minecraft/client/render/model/BasicBakedModel", "net/minecraft/client/render/model/BuiltinBakedModel", "net/minecraft/client/render/model/MultipartBakedModel", "net/minecraft/client/render/model/WeightedBakedModel", "net/fabricmc/fabric/api/renderer/v1/model/ForwardingBakedModel" }) -public class GeneralBakedModelMixin implements BakedModelAccess { +public class GeneralBakedModelMixin implements ModelAccess { @Unique - private Map>>> subQuads = Maps.newHashMap(); + private Optional liminalQuadRenderer = Optional.empty(); + + @Override + public Optional getLiminalQuadRenderer() { + return liminalQuadRenderer; + } @Override - public Map>>> getSubQuads() { - return subQuads; + public void setLiminalQuadRenderer(Identifier id) { + liminalQuadRenderer = Optional.ofNullable(id); } } diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelDeserializerMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelDeserializerMixin.java index 82d7076..9370c37 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelDeserializerMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelDeserializerMixin.java @@ -2,7 +2,6 @@ import java.lang.reflect.Type; import java.util.List; -import java.util.Map; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -10,12 +9,11 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.google.common.collect.Maps; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import net.ludocrypt.limlib.access.UnbakedModelAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.ludocrypt.limlib.impl.LimlibRendering; import net.minecraft.client.render.model.json.JsonUnbakedModel; import net.minecraft.client.render.model.json.ModelElement; @@ -26,16 +24,12 @@ public abstract class JsonUnbakedModelDeserializerMixin { @Inject(method = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel$Deserializer;deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;", at = @At("RETURN"), cancellable = true) private void limlib$deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable ci) { - Map> map = Maps.newHashMap(); JsonObject jsonObject = jsonElement.getAsJsonObject(); - if (jsonObject.has("limlib_extra")) { - LimlibRendering.LIMINAL_QUAD_RENDERER.getEntrySet().forEach((entry) -> { - if (jsonObject.get("limlib_extra").getAsJsonObject().has(entry.getKey().getValue().toString())) { - map.put(entry.getKey().getValue(), elementsFromJson(jsonDeserializationContext, jsonObject.get("limlib_extra").getAsJsonObject().get(entry.getKey().getValue().toString()).getAsJsonObject())); - } - }); + if (jsonObject.has("limlib_renderer")) { + if (LimlibRendering.LIMINAL_QUAD_RENDERER.containsId(new Identifier(jsonObject.get("limlib_renderer").getAsString()))) { + ((ModelAccess) ci.getReturnValue()).setLiminalQuadRenderer(new Identifier(jsonObject.get("limlib_renderer").getAsString())); + } } - ((UnbakedModelAccess) ci.getReturnValue()).putSubElements(map); } @Shadow diff --git a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelMixin.java b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelMixin.java index 31cad9d..a86f205 100644 --- a/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelMixin.java +++ b/src/main/java/net/ludocrypt/limlib/mixin/client/render/model/JsonUnbakedModelMixin.java @@ -1,91 +1,37 @@ package net.ludocrypt.limlib.mixin.client.render.model; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.function.Function; -import org.apache.commons.compress.utils.Lists; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import com.google.common.collect.Maps; -import com.mojang.datafixers.util.Pair; - -import net.ludocrypt.limlib.access.BakedModelAccess; -import net.ludocrypt.limlib.access.UnbakedModelAccess; +import net.ludocrypt.limlib.access.ModelAccess; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.render.model.json.JsonUnbakedModel; import net.minecraft.client.render.model.json.ModelElement; import net.minecraft.client.render.model.json.ModelElementFace; -import net.minecraft.client.texture.MissingSprite; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; @Mixin(JsonUnbakedModel.class) -public abstract class JsonUnbakedModelMixin implements UnbakedModelAccess { +public abstract class JsonUnbakedModelMixin implements ModelAccess { @Unique - private Map> subElements = Maps.newHashMap(); - - @Shadow - public String id; - - @Shadow - protected JsonUnbakedModel parent; - - @Inject(method = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel;getTextureDependencies(Ljava/util/function/Function;Ljava/util/Set;)Ljava/util/Collection;", at = @At(value = "INVOKE", target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V", ordinal = 0, shift = Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) - private void limlib$getTextureDependencies(Function unbakedModelGetter, Set> unresolvedTextureReferences, CallbackInfoReturnable> ci, Set set, JsonUnbakedModel jsonUnbakedModel, Set set2) { - this.getSubElements().forEach((subElementId, subElement) -> { - subElement.forEach((modelElement) -> { - modelElement.faces.values().forEach((modelElementFace) -> { - SpriteIdentifier spriteIdentifier = this.resolveSprite(modelElementFace.textureId); - if (Objects.equals(spriteIdentifier.getTextureId(), MissingSprite.getMissingSpriteId())) { - unresolvedTextureReferences.add(Pair.of(modelElementFace.textureId, this.id)); - } - set2.add(spriteIdentifier); - }); - }); - }); - } + private Optional liminalQuadRenderer = Optional.empty(); @Inject(method = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel;bake(Lnet/minecraft/client/render/model/ModelLoader;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/function/Function;Lnet/minecraft/client/render/model/ModelBakeSettings;Lnet/minecraft/util/Identifier;Z)Lnet/minecraft/client/render/model/BakedModel;", at = @At("RETURN"), cancellable = true) private void limlib$bake(ModelLoader loader, JsonUnbakedModel parent, Function textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth, CallbackInfoReturnable ci) { - Map>>> subQuads = Maps.newHashMap(); - - this.getSubElements().forEach((subElementId, subElement) -> { - List>> quads = Lists.newArrayList(); - subElement.forEach((modelElement) -> { - for (Direction direction : modelElement.faces.keySet()) { - ModelElementFace modelElementFace = modelElement.faces.get(direction); - Sprite sprite2 = textureGetter.apply(this.resolveSprite(modelElementFace.textureId)); - if (modelElementFace.cullFace == null) { - quads.add(Pair.of(createQuad(modelElement, modelElementFace, sprite2, direction, settings, id), Optional.empty())); - continue; - } - quads.add(Pair.of(createQuad(modelElement, modelElementFace, sprite2, direction, settings, id), Optional.of(Direction.transform(settings.getRotation().getMatrix(), modelElementFace.cullFace)))); - } - }); - - subQuads.put(subElementId, quads); - }); - - ((BakedModelAccess) ci.getReturnValue()).getSubQuads().putAll(subQuads); + ((ModelAccess) ci.getReturnValue()).setLiminalQuadRenderer(liminalQuadRenderer.orElse(null)); } @Shadow @@ -95,26 +41,13 @@ public abstract class JsonUnbakedModelMixin implements UnbakedModelAccess { public abstract SpriteIdentifier resolveSprite(String spriteName); @Override - public Map> getSubElements() { - Map> conjoinedElements = Maps.newHashMap(); - - conjoinedElements.putAll(this.subElements); - - if (this.parent != null) { - conjoinedElements.putAll(((UnbakedModelAccess) this.parent).getSubElements()); - } - - return conjoinedElements; - } - - @Override - public void putSubElements(Map> map) { - this.subElements.putAll(map); + public Optional getLiminalQuadRenderer() { + return liminalQuadRenderer; } @Override - public JsonUnbakedModel getParent() { - return this.parent; + public void setLiminalQuadRenderer(Identifier id) { + liminalQuadRenderer = Optional.ofNullable(id); } }