Culling item on belts

This commit is contained in:
drouarb 2024-07-11 00:00:27 +02:00
parent 75d337ba8c
commit 03973c4dc5
3 changed files with 43 additions and 5 deletions

View file

@ -198,10 +198,6 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
for (TransportedItemStack transported : be.getInventory()
.getTransportedItems()) {
ms.pushPose();
TransformStack.cast(ms)
.nudge(transported.angle);
float offset;
float sideOffset;
float verticalMovement;
@ -228,6 +224,18 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
.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
@ -243,7 +251,13 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
boolean renderUpright = BeltHelper.isItemUpright(transported.stack);
boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0)
.isGui3d();
int count = (int) (Mth.log2((int) (transported.stack.getCount()))) / 2;
int count = 0;
if (Minecraft.getInstance().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;

View file

@ -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<T extends BlockEntity> implements BlockEntityRenderer<T> {
@Override
@ -23,4 +27,21 @@ public abstract class SafeBlockEntityRenderer<T extends BlockEntity> 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);
}
}

View file

@ -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 <init>(Lnet/minecraft/client/gui/components/CommandSuggestions;IIILjava/util/List;Z)V # <init>
public net.minecraft.client.renderer.LevelRenderer f_172938_ # cullingFrustum
public net.minecraft.client.renderer.LevelRenderer f_109442_ # capturedFrustum