From 9dfbe061def61b99b03b5bbf66a349323709fd91 Mon Sep 17 00:00:00 2001 From: drouarb Date: Mon, 8 Jul 2024 20:53:49 +0200 Subject: [PATCH] Preserving BakedModel and switching to ItemRenderer.render instead of ItemRenderer.renderStatic for performance --- .../decoration/placard/PlacardRenderer.java | 7 ++++--- .../content/fluids/drain/ItemDrainRenderer.java | 7 ++++--- .../create/content/kinetics/belt/BeltRenderer.java | 11 ++++++----- .../kinetics/deployer/DeployerRenderer.java | 8 ++++---- .../kinetics/mechanicalArm/ArmRenderer.java | 14 +++++++------- .../create/content/kinetics/saw/SawRenderer.java | 2 +- .../content/logistics/depot/DepotRenderer.java | 7 ++++--- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java b/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java index 7081b98ae..fe98850ea 100644 --- a/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java +++ b/src/main/java/com/simibubi/create/content/decoration/placard/PlacardRenderer.java @@ -10,6 +10,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; @@ -33,8 +34,8 @@ public class PlacardRenderer extends SafeBlockEntityRenderer ItemRenderer itemRenderer = Minecraft.getInstance() .getItemRenderer(); - boolean blockItem = itemRenderer.getModel(heldItem, null, null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(heldItem, null, null, 0); + boolean blockItem = bakedModel.isGui3d(); ms.pushPose(); TransformStack.cast(ms) @@ -46,7 +47,7 @@ public class PlacardRenderer extends SafeBlockEntityRenderer .translate(0, 0, 4.5 / 16f) .scale(blockItem ? .5f : .375f); - itemRenderer.renderStatic(heldItem, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(heldItem, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java index d803e31dc..e3a9c4957 100644 --- a/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java +++ b/src/main/java/com/simibubi/create/content/fluids/drain/ItemDrainRenderer.java @@ -19,6 +19,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.util.Mth; @@ -78,8 +79,8 @@ public class ItemDrainRenderer extends SmartBlockEntityRenderer { boolean slopeAlongX = beltFacing .getAxis() == Axis.X; + ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); boolean onContraption = be.getLevel() instanceof WrappedWorld; for (TransportedItemStack transported : be.getInventory() @@ -238,11 +240,10 @@ public class BeltRenderer extends SafeBlockEntityRenderer { ms.translate(alongX ? sideOffset : 0, 0, alongX ? 0 : sideOffset); int stackLight = onContraption ? light : getPackedLight(be, offset); - ItemRenderer itemRenderer = Minecraft.getInstance() - .getItemRenderer(); + boolean renderUpright = BeltHelper.isItemUpright(transported.stack); - boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0); + boolean blockItem = bakedModel.isGui3d(); int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; Random r = new Random(transported.angle); @@ -289,7 +290,7 @@ public class BeltRenderer extends SafeBlockEntityRenderer { } ms.scale(.5f, .5f, .5f); - itemRenderer.renderStatic(null, transported.stack, TransformType.FIXED, false, ms, buffer, be.getLevel(), stackLight, overlay, 0); + itemRenderer.render(transported.stack, TransformType.FIXED, false, ms, buffer, stackLight, overlay, bakedModel); ms.popPose(); if (!renderUpright) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java index 3ce20684f..031f162ce 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/DeployerRenderer.java @@ -34,6 +34,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -89,9 +90,8 @@ public class DeployerRenderer extends SafeBlockEntityRenderer { ItemRenderer itemRenderer = Minecraft.getInstance() .getItemRenderer(); - boolean isBlockItem = - hasItem && (item.getItem() instanceof BlockItem) && itemRenderer.getModel(item, be.getLevel(), null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(item, be.getLevel(), null, 0); + boolean isBlockItem = hasItem && (item.getItem() instanceof BlockItem) && bakedModel.isGui3d(); VertexConsumer builder = buffer.getBuffer(be.goggles ? RenderType.cutout() : RenderType.solid()); BlockState blockState = be.getBlockState(); @@ -102,7 +102,7 @@ public class ArmRenderer extends KineticBlockEntityRenderer { .multiply(msLocal.last() .pose()); - itemRenderer.renderStatic(item, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(item, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); } @@ -141,13 +141,13 @@ public class ArmRenderer extends KineticBlockEntityRenderer { .renderInto(ms, builder); transformHead(msr, headAngle); - + if (inverted) msr.rotateZ(180); - + claw.transform(msLocal) .renderInto(ms, builder); - + if (inverted) msr.rotateZ(180); diff --git a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java index 926b7332a..750ca9371 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/saw/SawRenderer.java @@ -134,7 +134,7 @@ public class SawRenderer extends SafeBlockEntityRenderer { if (alongZ) ms.mulPose(Vector3f.YP.rotationDegrees(90)); ms.mulPose(Vector3f.XP.rotationDegrees(90)); - itemRenderer.renderStatic(stack, ItemTransforms.TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(stack, ItemTransforms.TransformType.FIXED, false, ms, buffer, light, overlay, modelWithOverrides); break; } diff --git a/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java b/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java index 5f830e91d..3d53879fa 100644 --- a/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java +++ b/src/main/java/com/simibubi/create/content/logistics/depot/DepotRenderer.java @@ -16,6 +16,7 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction.Axis; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -104,8 +105,8 @@ public class DepotRenderer extends SafeBlockEntityRenderer { TransformStack msr = TransformStack.cast(ms); int count = (int) (Mth.log2((int) (itemStack.getCount()))) / 2; boolean renderUpright = BeltHelper.isItemUpright(itemStack); - boolean blockItem = itemRenderer.getModel(itemStack, null, null, 0) - .isGui3d(); + BakedModel bakedModel = itemRenderer.getModel(itemStack, null, null, 0); + boolean blockItem = bakedModel.isGui3d(); ms.pushPose(); msr.rotateY(angle); @@ -131,7 +132,7 @@ public class DepotRenderer extends SafeBlockEntityRenderer { ms.translate(0, -3 / 16f, 0); msr.rotateX(90); } - itemRenderer.renderStatic(itemStack, TransformType.FIXED, light, overlay, ms, buffer, 0); + itemRenderer.render(itemStack, TransformType.FIXED, false, ms, buffer, light, overlay, bakedModel); ms.popPose(); if (!renderUpright) {