diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java index 8010472f4..cd5af645f 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltRenderer.java @@ -195,15 +195,12 @@ public class BeltRenderer extends SafeBlockEntityRenderer { boolean slopeAlongX = beltFacing .getAxis() == Axis.X; - ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); + Minecraft mc = Minecraft.getInstance(); + ItemRenderer itemRenderer = mc.getItemRenderer(); boolean onContraption = be.getLevel() instanceof WrappedWorld; for (TransportedItemStack transported : be.getInventory() .getTransportedItems()) { - ms.pushPose(); - TransformStack.cast(ms) - .nudge(transported.angle); - float offset; float sideOffset; float verticalMovement; @@ -230,6 +227,18 @@ public class BeltRenderer extends SafeBlockEntityRenderer { .getAxis() == Axis.Z); float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0; + Vec3 itemPos = beltStartOffset.add( + be.getBlockPos().getX(), + be.getBlockPos().getY(), + be.getBlockPos().getZ()) + .add(offsetVec); + + if (this.shouldCullItem(itemPos)) { + continue; + } + + ms.pushPose(); + TransformStack.cast(ms).nudge(transported.angle); ms.translate(offsetVec.x, offsetVec.y, offsetVec.z); boolean alongX = beltFacing @@ -244,7 +253,11 @@ public class BeltRenderer extends SafeBlockEntityRenderer { boolean renderUpright = BeltHelper.isItemUpright(transported.stack); BakedModel bakedModel = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0); boolean blockItem = bakedModel.isGui3d(); - int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; + + int count = 0; + if (mc.player.getEyePosition(1.0F).distanceTo(itemPos) < 16) + count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2; + Random r = new Random(transported.angle); boolean slopeShadowOnly = renderUpright && onSlope; @@ -265,7 +278,7 @@ public class BeltRenderer extends SafeBlockEntityRenderer { } if (renderUpright) { - Entity renderViewEntity = Minecraft.getInstance().cameraEntity; + Entity renderViewEntity = mc.cameraEntity; if (renderViewEntity != null) { Vec3 positionVec = renderViewEntity.position(); Vec3 vectorForOffset = BeltHelper.getVectorForOffset(be, offset); diff --git a/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java index 1ecb77e29..f26940d4c 100644 --- a/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/blockEntity/renderer/SafeBlockEntityRenderer.java @@ -2,10 +2,14 @@ package com.simibubi.create.foundation.blockEntity.renderer; import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; public abstract class SafeBlockEntityRenderer implements BlockEntityRenderer { @Override @@ -23,4 +27,21 @@ public abstract class SafeBlockEntityRenderer implements return !be.hasLevel() || be.getBlockState() .getBlock() == Blocks.AIR; } + + public boolean shouldCullItem(Vec3 itemPos) { + Frustum frustum = Minecraft.getInstance().levelRenderer.capturedFrustum != null ? + Minecraft.getInstance().levelRenderer.capturedFrustum : + Minecraft.getInstance().levelRenderer.cullingFrustum; + + AABB itemBB = new AABB( + itemPos.x - 0.25, + itemPos.y - 0.25, + itemPos.z - 0.25, + itemPos.x + 0.25, + itemPos.y + 0.25, + itemPos.z + 0.25 + ); + + return !frustum.isVisible(itemBB); + } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index a911f646d..1bc660abe 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -42,3 +42,6 @@ public net.minecraft.client.model.AgeableListModel f_102012_ # bodyYOffset public net.minecraft.client.gui.components.CommandSuggestions f_93866_ # suggestions public net.minecraft.client.gui.components.CommandSuggestions$SuggestionsList (Lnet/minecraft/client/gui/components/CommandSuggestions;IIILjava/util/List;Z)V # + +public net.minecraft.client.renderer.LevelRenderer f_172938_ # cullingFrustum +public net.minecraft.client.renderer.LevelRenderer f_109442_ # capturedFrustum