mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Culling item on belts
This commit is contained in:
parent
75d337ba8c
commit
03973c4dc5
3 changed files with 43 additions and 5 deletions
|
@ -198,10 +198,6 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
|
||||||
|
|
||||||
for (TransportedItemStack transported : be.getInventory()
|
for (TransportedItemStack transported : be.getInventory()
|
||||||
.getTransportedItems()) {
|
.getTransportedItems()) {
|
||||||
ms.pushPose();
|
|
||||||
TransformStack.cast(ms)
|
|
||||||
.nudge(transported.angle);
|
|
||||||
|
|
||||||
float offset;
|
float offset;
|
||||||
float sideOffset;
|
float sideOffset;
|
||||||
float verticalMovement;
|
float verticalMovement;
|
||||||
|
@ -228,6 +224,18 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
|
||||||
.getAxis() == Axis.Z);
|
.getAxis() == Axis.Z);
|
||||||
float slopeAngle = onSlope ? tiltForward ? -45 : 45 : 0;
|
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);
|
ms.translate(offsetVec.x, offsetVec.y, offsetVec.z);
|
||||||
|
|
||||||
boolean alongX = beltFacing
|
boolean alongX = beltFacing
|
||||||
|
@ -243,7 +251,13 @@ public class BeltRenderer extends SafeBlockEntityRenderer<BeltBlockEntity> {
|
||||||
boolean renderUpright = BeltHelper.isItemUpright(transported.stack);
|
boolean renderUpright = BeltHelper.isItemUpright(transported.stack);
|
||||||
boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0)
|
boolean blockItem = itemRenderer.getModel(transported.stack, be.getLevel(), null, 0)
|
||||||
.isGui3d();
|
.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);
|
Random r = new Random(transported.angle);
|
||||||
|
|
||||||
boolean slopeShadowOnly = renderUpright && onSlope;
|
boolean slopeShadowOnly = renderUpright && onSlope;
|
||||||
|
|
|
@ -2,10 +2,14 @@ package com.simibubi.create.foundation.blockEntity.renderer;
|
||||||
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
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.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
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> {
|
public abstract class SafeBlockEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,4 +27,21 @@ public abstract class SafeBlockEntityRenderer<T extends BlockEntity> implements
|
||||||
return !be.hasLevel() || be.getBlockState()
|
return !be.hasLevel() || be.getBlockState()
|
||||||
.getBlock() == Blocks.AIR;
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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.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
|
||||||
|
|
Loading…
Reference in a new issue