From 04ccf6e738cfbc4c7aace72b9662c699aeec97b9 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 27 Jan 2021 16:28:39 -0800 Subject: [PATCH] belt light --- .../contraptions/relays/belt/BeltHelper.java | 4 ++ .../relays/belt/BeltRenderer.java | 56 ++++--------------- .../relays/belt/BeltTileEntity.java | 17 ++++++ 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java index 63360a12a..0268ea996 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltHelper.java @@ -40,6 +40,10 @@ public class BeltHelper { return getSegmentTE(world, controllerPos); } + public static BeltTileEntity getBeltForOffset(BeltTileEntity controller, float offset) { + return getBeltAtSegment(controller, (int) Math.floor(offset)); + } + public static BeltTileEntity getBeltAtSegment(BeltTileEntity controller, int segment) { BlockPos pos = getPositionForOffset(controller, segment); TileEntity te = controller.getWorld() diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index 984fc6b49..bbaa75d8f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -148,50 +148,6 @@ public class BeltRenderer extends SafeTileEntityRenderer { } } - public void markForRebuild(InstanceContext ctx) { - BeltTileEntity te = ctx.te; - - BlockState blockState = te.getBlockState(); - if (!AllBlocks.BELT.has(blockState)) - return; - - BeltSlope beltSlope = blockState.get(BeltBlock.SLOPE); - BeltPart part = blockState.get(BeltBlock.PART); - Direction facing = blockState.get(BeltBlock.HORIZONTAL_FACING); - AxisDirection axisDirection = facing.getAxisDirection(); - - boolean downward = beltSlope == BeltSlope.DOWNWARD; - boolean upward = beltSlope == BeltSlope.UPWARD; - boolean diagonal = downward || upward; - boolean start = part == BeltPart.START; - boolean end = part == BeltPart.END; - boolean sideways = beltSlope == BeltSlope.SIDEWAYS; - boolean vertical = beltSlope == BeltSlope.VERTICAL; - - if (downward || vertical && axisDirection == AxisDirection.POSITIVE) { - boolean b = start; - start = end; - end = b; - } - - for (boolean bottom : Iterate.trueAndFalse) { - - AllBlockPartials beltPartial = getBeltPartial(diagonal, start, end, bottom); - - InstancedModel beltBuffer = beltPartial.renderOnBelt(ctx, blockState); - - beltBuffer.clearInstanceData(); - - // Diagonal belt do not have a separate bottom model - if (diagonal) - break; - } - - InstancedModel rotatingBuffer = getPulleyModel(ctx, blockState, sideways); - - rotatingBuffer.clearInstanceData(); - } - private InstancedModel getPulleyModel(InstanceContext ctx, BlockState blockState, boolean sideways) { Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); @@ -246,11 +202,14 @@ public class BeltRenderer extends SafeTileEntityRenderer { float sideOffset = MathHelper.lerp(partialTicks, transported.prevSideOffset, transported.sideOffset); float verticalMovement = verticality; + if (te.getSpeed() == 0) { offset = transported.beltPosition; sideOffset = transported.sideOffset; } + int stackLight = getPackedLight(te, offset); + if (offset < .5) verticalMovement = 0; verticalMovement = verticalMovement * (Math.min(offset, te.beltLength - .5f) - .5f); @@ -318,7 +277,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { } ms.scale(.5f, .5f, .5f); - itemRenderer.renderItem(transported.stack, TransformType.FIXED, light, overlay, ms, buffer); + itemRenderer.renderItem(transported.stack, TransformType.FIXED, stackLight, overlay, ms, buffer); ms.pop(); if (!renderUpright) { @@ -335,4 +294,11 @@ public class BeltRenderer extends SafeTileEntityRenderer { ms.pop(); } + protected int getPackedLight(BeltTileEntity controller, float beltPos) { + BeltTileEntity belt = BeltHelper.getBeltForOffset(controller, beltPos); + + if (belt == null) return 0; + + return (belt.skyLight << 20) | (belt.blockLight << 4); + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java index c1f04f296..2635ae9c3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltTileEntity.java @@ -27,6 +27,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import net.minecraft.world.LightType; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelProperty; @@ -61,6 +62,10 @@ public class BeltTileEntity extends KineticTileEntity { public CompoundNBT trackerUpdateTag; + // client + public byte blockLight; + public byte skyLight; + public static enum CasingType { NONE, ANDESITE, BRASS; } @@ -211,6 +216,7 @@ public class BeltTileEntity extends KineticTileEntity { if (!clientPacket) return; + updateLight(); if (casingBefore == casing) return; requestModelDataUpdate(); @@ -465,4 +471,15 @@ public class BeltTileEntity extends KineticTileEntity { return new ModelDataMap.Builder().withInitial(CASING_PROPERTY, casing) .build(); } + + @Override + public void onChunkLightUpdate() { + super.onChunkLightUpdate(); + updateLight(); + } + + private void updateLight() { + skyLight = (byte) world.getLightLevel(LightType.SKY, pos); + blockLight = (byte) world.getLightLevel(LightType.BLOCK, pos); + } }