diff --git a/src/main/java/com/glisco/isometricrenders/render/BatchRenderable.java b/src/main/java/com/glisco/isometricrenders/render/BatchRenderable.java index 353e885..1dac4a2 100644 --- a/src/main/java/com/glisco/isometricrenders/render/BatchRenderable.java +++ b/src/main/java/com/glisco/isometricrenders/render/BatchRenderable.java @@ -6,6 +6,7 @@ import com.glisco.isometricrenders.screen.IsometricUI; import com.glisco.isometricrenders.util.ExportPathSpec; import com.glisco.isometricrenders.util.ImageIO; +import com.glisco.isometricrenders.util.ParticleRestriction; import com.glisco.isometricrenders.util.Translate; import io.wispforest.owo.ui.component.ButtonComponent; import io.wispforest.owo.ui.component.Components; @@ -20,7 +21,6 @@ public class BatchRenderable> implements Renderable { - private final BatchPropertyBundle properties; private final List delegates; private final String contentType; @@ -38,8 +38,6 @@ private BatchRenderable(String source, List delegates) { this.contentType = ExportPathSpec.exportRoot().resolve("batches/") .relativize(ImageIO.next(ExportPathSpec.exportRoot().resolve("batches/" + source + "/"))).toString(); - - this.properties = new BatchPropertyBundle(this.currentDelegate.properties()); this.renderDelay = Math.max((int) Math.pow(GlobalProperties.exportResolution / 1024f, 2) * 100L, 75); } @@ -51,6 +49,11 @@ public static > BatchRenderable of(String source, Lis } } + @Override + public void prepare() { + this.currentDelegate.prepare(); + } + @Override public void emitVertices(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta) { this.currentDelegate.emitVertices(matrices, vertexConsumers, tickDelta); @@ -70,6 +73,21 @@ public void draw(Matrix4f modelViewMatrix) { this.currentDelegate.draw(modelViewMatrix); } + @Override + public void cleanUp() { + this.currentDelegate.cleanUp(); + } + + @Override + public void dispose() { + this.delegates.forEach(Renderable::dispose); + } + + @Override + public ParticleRestriction particleRestriction() { + return this.currentDelegate.particleRestriction(); + } + private void start() { this.batchActive = true; this.currentIndex = 0; @@ -86,7 +104,7 @@ private void reset() { @Override public BatchPropertyBundle properties() { - return this.properties; + return new BatchPropertyBundle(this.currentDelegate.properties()); } @Override diff --git a/src/main/java/com/glisco/isometricrenders/render/ItemRenderable.java b/src/main/java/com/glisco/isometricrenders/render/ItemRenderable.java index 6d27390..7f2d78f 100644 --- a/src/main/java/com/glisco/isometricrenders/render/ItemRenderable.java +++ b/src/main/java/com/glisco/isometricrenders/render/ItemRenderable.java @@ -2,19 +2,39 @@ import com.glisco.isometricrenders.property.DefaultPropertyBundle; import com.glisco.isometricrenders.util.ExportPathSpec; +import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.json.ModelTransformation; import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.util.math.RotationAxis; public class ItemRenderable extends DefaultRenderable { - private static final DefaultPropertyBundle PROPERTIES = new DefaultPropertyBundle(); + private static BakedModel currentModel = null; + private static final DefaultPropertyBundle PROPERTIES = new DefaultPropertyBundle() { + @Override + public void applyToViewMatrix(MatrixStack modelViewStack) { + final float scale = (this.scale.get() / 100f) * (currentModel != null && currentModel.hasDepth() ? 2f : 1.75f); + modelViewStack.scale(scale, scale, scale); + + modelViewStack.translate(this.xOffset.get() / 26000d, this.yOffset.get() / -26000d, 0); + + modelViewStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(this.slant.get())); + if (currentModel != null) currentModel.getTransformation().getTransformation(ModelTransformationMode.GUI).apply(false, modelViewStack); + modelViewStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(this.rotation.get())); + + this.updateAndApplyRotationOffset(modelViewStack); + } + }; static { PROPERTIES.slant.setDefaultValue(0).setToDefault(); @@ -28,27 +48,37 @@ public ItemRenderable(ItemStack stack) { } @Override - public void emitVertices(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta) { - final var itemRenderer = MinecraftClient.getInstance().getItemRenderer(); - final var hasDepth = itemRenderer.getModel(this.stack, null, null, 0).hasDepth(); - final float scale = hasDepth ? 2f : 1.75f; - - matrices.push(); - matrices.scale(scale, scale, scale); - - // This funny matrix manipulation here is done in order to - // avoid funny axis rotation on models with depth - if (hasDepth) { - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-this.properties().rotation.get())); - matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(30)); - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(this.properties().rotation.get() + 135)); + public void prepare() { + var itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + if (this.stack.isOf(Items.TRIDENT)) { + currentModel = itemRenderer.getModels().getModelManager().getModel(ModelIdentifier.ofVanilla("trident", "inventory")); + } else if (this.stack.isOf(Items.SPYGLASS)) { + currentModel = itemRenderer.getModels().getModelManager().getModel(ModelIdentifier.ofVanilla("spyglass", "inventory")); } else { - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); + currentModel = itemRenderer.getModel(this.stack, MinecraftClient.getInstance().world, null, 0); } + } + + @Override + public void emitVertices(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta) { + final var itemRenderer = MinecraftClient.getInstance().getItemRenderer(); + final var model = itemRenderer.getModel(this.stack, null, null, 0); - itemRenderer.renderItem(this.stack, ModelTransformationMode.FIXED, LightmapTextureManager.MAX_LIGHT_COORDINATE, - OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, MinecraftClient.getInstance().world, 0); - matrices.pop(); + itemRenderer.renderItem( + this.stack, + ModelTransformationMode.GUI, + false, + matrices, + vertexConsumers, + LightmapTextureManager.MAX_LIGHT_COORDINATE, + OverlayTexture.DEFAULT_UV, + new TransformlessBakedModel(model) + ); + } + + @Override + public void cleanUp() { + currentModel = null; } @Override @@ -63,4 +93,15 @@ public ExportPathSpec exportPath() { "item" ); } + + private static class TransformlessBakedModel extends ForwardingBakedModel { + public TransformlessBakedModel(BakedModel inner) { + this.wrapped = inner; + } + + @Override + public ModelTransformation getTransformation() { + return ModelTransformation.NONE; + } + } }