From f6cfd377a7afab0d73818a83e88ef6248af96141 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Sat, 20 Mar 2021 16:30:09 -0700 Subject: [PATCH] Ticking things. - Differentiate tickable and dynamic instances. - Instanced repeaters. --- .../com/simibubi/create/AllTileEntities.java | 3 + .../contraptions/base/HalfShaftInstance.java | 8 +-- .../base/HorizontalHalfShaftInstance.java | 6 +- .../base/KineticTileInstance.java | 4 +- .../base/SingleRotatingInstance.java | 6 +- .../crafter/MechanicalCrafterInstance.java | 8 +-- .../components/crank/HandCrankInstance.java | 16 ++--- .../components/deployer/DeployerInstance.java | 12 ++-- .../components/fan/FanInstance.java | 17 ++---- .../components/flywheel/FlyWheelInstance.java | 34 +++++------ .../flywheel/engine/EngineInstance.java | 12 +--- .../components/mixer/MixerInstance.java | 16 ++--- .../components/press/PressInstance.java | 13 ++--- .../components/saw/SawInstance.java | 8 +-- .../chassis/StickerInstance.java | 16 ++--- .../gantry/GantryCarriageInstance.java | 19 +++--- .../fluids/pipes/FluidValveInstance.java | 12 ++-- .../relays/belt/BeltInstance.java | 16 +++-- .../relays/encased/SplitShaftInstance.java | 10 ++-- .../relays/gauge/GaugeInstance.java | 16 ++--- .../relays/gearbox/GearboxInstance.java | 8 +-- .../belts/tunnel/BeltTunnelInstance.java | 9 +-- .../diodes/AdjustableRepeaterInstance.java | 58 +++++++++++++++++++ .../diodes/AdjustableRepeaterTileEntity.java | 4 +- .../block/funnel/FunnelInstance.java | 13 ++--- .../block/mechanicalArm/ArmInstance.java | 26 ++++----- .../block/redstone/AnalogLeverInstance.java | 17 ++---- .../block/SchematicannonInstance.java | 20 ++----- .../backend/instancing/IDynamicInstance.java | 8 +++ .../backend/instancing/ITickableInstance.java | 4 +- .../instancing/InstancedTileRenderer.java | 22 +++++-- .../instancing/TileEntityInstance.java | 9 ++- .../ColoredOverlayTileEntityRenderer.java | 13 +++-- 33 files changed, 221 insertions(+), 242 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/instancing/IDynamicInstance.java diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 88b073b28..2a10eda64 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -97,6 +97,7 @@ import com.simibubi.create.content.logistics.block.chute.SmartChuteTileEntity; import com.simibubi.create.content.logistics.block.depot.DepotRenderer; import com.simibubi.create.content.logistics.block.depot.DepotTileEntity; import com.simibubi.create.content.logistics.block.diodes.AdjustablePulseRepeaterTileEntity; +import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterInstance; import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterRenderer; import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterTileEntity; import com.simibubi.create.content.logistics.block.funnel.FunnelInstance; @@ -595,6 +596,7 @@ public class AllTileEntities { public static final TileEntityEntry ADJUSTABLE_REPEATER = Create.registrate() .tileEntity("adjustable_repeater", AdjustableRepeaterTileEntity::new) + .instance(() -> AdjustableRepeaterInstance::new) .validBlocks(AllBlocks.ADJUSTABLE_REPEATER) .renderer(() -> AdjustableRepeaterRenderer::new) .register(); @@ -602,6 +604,7 @@ public class AllTileEntities { public static final TileEntityEntry ADJUSTABLE_PULSE_REPEATER = Create.registrate() .tileEntity("adjustable_pulse_repeater", AdjustablePulseRepeaterTileEntity::new) + .instance(() -> AdjustableRepeaterInstance::new) .validBlocks(AllBlocks.ADJUSTABLE_PULSE_REPEATER) .renderer(() -> AdjustableRepeaterRenderer::new) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index 6002f3140..7b5249963 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -2,14 +2,10 @@ package com.simibubi.create.content.contraptions.base; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class HalfShaftInstance extends SingleRotatingInstance { public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { @@ -19,10 +15,10 @@ public class HalfShaftInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { Direction dir = getShaftDirection(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir); } protected Direction getShaftDirection() { - return lastState.get(BlockStateProperties.FACING); + return blockState.get(BlockStateProperties.FACING); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index af5bfec0f..d5a21d468 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,13 +1,9 @@ package com.simibubi.create.content.contraptions.base; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class HorizontalHalfShaftInstance extends HalfShaftInstance { @@ -17,6 +13,6 @@ public class HorizontalHalfShaftInstance extends HalfShaftInstance { @Override protected Direction getShaftDirection() { - return lastState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); + return blockState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index be44b81f3..9c94b9062 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -37,7 +37,7 @@ public abstract class KineticTileInstance extends T } protected float getRotationOffset(final Direction.Axis axis) { - float offset = CogWheelBlock.isLargeCog(lastState) ? 11.25f : 0; + float offset = CogWheelBlock.isLargeCog(blockState) ? 11.25f : 0; double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY()) + ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2; if (d == 0) { @@ -52,7 +52,7 @@ public abstract class KineticTileInstance extends T } public Direction.Axis getRotationAxis() { - return ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + return ((IRotate) blockState.getBlock()).getRotationAxis(blockState); } protected final RenderMaterial> rotatingMaterial() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index 44e9c93d0..ed80fdc9c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -19,13 +19,13 @@ public class SingleRotatingInstance extends KineticTileInstance getModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java index 3cdf21954..adb9fd3e2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -8,14 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class MechanicalCrafterInstance extends SingleRotatingInstance { @@ -25,7 +21,7 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - Direction facing = lastState.get(MechanicalCrafterBlock.HORIZONTAL_FACING); + Direction facing = blockState.get(MechanicalCrafterBlock.HORIZONTAL_FACING); Supplier ms = () -> { MatrixStack stack = new MatrixStack(); @@ -39,6 +35,6 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance { stacker.unCentre(); return stack; }; - return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, lastState, facing, ms); + return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState, facing, ms); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java index cb5240516..309be16a0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java @@ -4,21 +4,15 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.content.logistics.block.redstone.AnalogLeverInstance; -import com.simibubi.create.content.logistics.block.redstone.AnalogLeverTileEntity; -import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.Block; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class HandCrankInstance extends SingleRotatingInstance implements ITickableInstance { +public class HandCrankInstance extends SingleRotatingInstance implements IDynamicInstance { private InstanceKey crank; private Direction facing; @@ -31,22 +25,22 @@ public class HandCrankInstance extends SingleRotatingInstance implements ITickab protected void init() { super.init(); - Block block = lastState.getBlock(); + Block block = blockState.getBlock(); AllBlockPartials renderedHandle = null; if (block instanceof HandCrankBlock) renderedHandle = ((HandCrankBlock) block).getRenderedHandle(); if (renderedHandle == null) return; - facing = lastState.get(BlockStateProperties.FACING); - InstancedModel model = renderedHandle.renderOnDirectionalSouthModel(modelManager, lastState, facing.getOpposite()); + facing = blockState.get(BlockStateProperties.FACING); + InstancedModel model = renderedHandle.renderOnDirectionalSouthModel(modelManager, blockState, facing.getOpposite()); crank = model.createInstance(); updateLight(); } @Override - public void tick() { + public void beginFrame() { if (crank == null) return; HandCrankTileEntity crankTile = (HandCrankTileEntity) tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java index 86803cd0e..4cd49184a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java @@ -16,7 +16,7 @@ import net.minecraft.util.math.Vec3d; import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; -public class DeployerInstance extends ShaftInstance implements ITickableInstance { +public class DeployerInstance extends ShaftInstance implements IDynamicInstance { DeployerTileEntity tile; @@ -42,22 +42,22 @@ public class DeployerInstance extends ShaftInstance implements ITickableInstance super.init(); this.tile = (DeployerTileEntity) super.tile; - facing = lastState.get(FACING); + facing = blockState.get(FACING); - boolean rotatePole = lastState.get(AXIS_ALONG_FIRST_COORDINATE) ^ facing.getAxis() == Direction.Axis.Z; + boolean rotatePole = blockState.get(AXIS_ALONG_FIRST_COORDINATE) ^ facing.getAxis() == Direction.Axis.Z; yRot = AngleHelper.horizontalAngle(facing); zRot = facing == Direction.UP ? 270 : facing == Direction.DOWN ? 90 : 0; zRotPole = rotatePole ? 90 : 0; - pole = modelManager.getBasicMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, lastState).createInstance(); + pole = modelManager.getBasicMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); updateHandPose(); relight(pos, pole.getInstance()); } @Override - public void tick() { + public void beginFrame() { boolean newHand = updateHandPose(); @@ -100,7 +100,7 @@ public class DeployerInstance extends ShaftInstance implements ITickableInstance if (hand != null) hand.delete(); - hand = modelManager.getBasicMaterial().getModel(currentHand, lastState).createInstance(); + hand = modelManager.getBasicMaterial().getModel(currentHand, blockState).createInstance(); relight(pos, hand.getInstance()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 0416c1564..b2ba34186 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -8,16 +8,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class FanInstance extends KineticTileInstance { @@ -30,13 +25,13 @@ public class FanInstance extends KineticTileInstance { @Override protected void init() { - final Direction direction = lastState.get(FACING); - final Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + final Direction direction = blockState.get(FACING); + final Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); InstancedModel shaftHalf = - AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()); InstancedModel fanInner = - AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); + AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()); shaft = shaftHalf.createInstance(); shaft.getInstance() @@ -67,7 +62,7 @@ public class FanInstance extends KineticTileInstance { @Override protected void onUpdate() { - Direction.Axis axis = lastState.get(FACING).getAxis(); + Direction.Axis axis = blockState.get(FACING).getAxis(); updateRotation(shaft, axis); fan.getInstance() @@ -79,7 +74,7 @@ public class FanInstance extends KineticTileInstance { @Override public void updateLight() { - final Direction direction = lastState.get(FACING); + final Direction direction = blockState.get(FACING); BlockPos behind = pos.offset(direction.getOpposite()); relight(behind, shaft.getInstance()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index bb2279a6f..132e4713d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -1,17 +1,14 @@ package com.simibubi.create.content.contraptions.components.flywheel; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; @@ -20,16 +17,11 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.Rotation; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class FlyWheelInstance extends KineticTileInstance implements ITickableInstance { +public class FlyWheelInstance extends KineticTileInstance implements IDynamicInstance { protected Direction facing; protected boolean connectedLeft; @@ -57,16 +49,16 @@ public class FlyWheelInstance extends KineticTileInstance im @Override protected void init() { - facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); + facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING); - Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); shaft = setup(shaftModel().createInstance(), tile.getSpeed(), axis); - wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, lastState.rotate(Rotation.CLOCKWISE_90)).createInstance(); + wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, blockState.rotate(Rotation.CLOCKWISE_90)).createInstance(); - connection = FlywheelBlock.getConnection(lastState); + connection = FlywheelBlock.getConnection(blockState); if (connection != null) { - connectedLeft = lastState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT; + connectedLeft = blockState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT; boolean flipAngle = connection.getAxis() == Direction.Axis.X ^ connection.getAxisDirection() == Direction.AxisDirection.NEGATIVE; @@ -74,10 +66,10 @@ public class FlyWheelInstance extends KineticTileInstance im RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); - upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, lastState).createInstance(); - lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, lastState).createInstance(); - upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, lastState).createInstance(); - lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, lastState).createInstance(); + upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); + lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); + upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, blockState).createInstance(); + lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, blockState).createInstance(); connectors = Lists.newArrayList(upperRotating, lowerRotating, upperSliding, lowerSliding); } else { @@ -89,7 +81,7 @@ public class FlyWheelInstance extends KineticTileInstance im } @Override - public void tick() { + public void beginFrame() { float partialTicks = AnimationTickHolder.getPartialTicks(); @@ -144,7 +136,7 @@ public class FlyWheelInstance extends KineticTileInstance im @Override protected void onUpdate() { - Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); updateRotation(shaft, axis); } @@ -167,7 +159,7 @@ public class FlyWheelInstance extends KineticTileInstance im } protected InstancedModel shaftModel() { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, facing.getOpposite()); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, facing.getOpposite()); } protected void transformConnector(MatrixStacker ms, boolean upper, boolean rotating, float angle, boolean flip) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index cac76a426..ebee39e59 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.TileEntityInstance; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; @@ -12,12 +11,7 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.block.Block; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class EngineInstance extends TileEntityInstance { @@ -29,7 +23,7 @@ public class EngineInstance extends TileEntityInstance { @Override protected void init() { - Block block = lastState + Block block = blockState .getBlock(); if (!(block instanceof EngineBlock)) return; @@ -37,9 +31,9 @@ public class EngineInstance extends TileEntityInstance { EngineBlock engineBlock = (EngineBlock) block; AllBlockPartials frame = engineBlock.getFrameModel(); - Direction facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); + Direction facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING); - this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, lastState).createInstance(); + this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, blockState).createInstance(); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java index d8325b5b0..bd9ce61da 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java @@ -5,22 +5,14 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.ShaftlessCogInstance; -import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.client.renderer.Vector3d; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class MixerInstance extends ShaftlessCogInstance implements ITickableInstance { +public class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance { private InstanceKey mixerHead; private InstanceKey mixerPole; @@ -33,14 +25,14 @@ public class MixerInstance extends ShaftlessCogInstance implements ITickableInst protected void init() { super.init(); - mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, lastState) + mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState) .createInstance(); mixerHead.getInstance() .setRotationAxis(Direction.Axis.Y); mixerPole = modelManager.getMaterial(RenderMaterials.MODELS) - .getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, lastState) + .getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState) .createInstance(); @@ -53,7 +45,7 @@ public class MixerInstance extends ShaftlessCogInstance implements ITickableInst } @Override - public void tick() { + public void beginFrame() { MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) tile; float renderedHeadOffset = getRenderedHeadOffset(mixer); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java index 8af6fa19f..831539c69 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java @@ -5,19 +5,14 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.RenderMaterials; -import com.simibubi.create.foundation.render.backend.instancing.ITickableInstance; +import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class PressInstance extends ShaftInstance implements ITickableInstance { +public class PressInstance extends ShaftInstance implements IDynamicInstance { private InstanceKey pressHead; @@ -30,7 +25,7 @@ public class PressInstance extends ShaftInstance implements ITickableInstance { super.init(); pressHead = modelManager.getMaterial(RenderMaterials.MODELS) - .getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, lastState) + .getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState) .createInstance(); updateLight(); @@ -38,7 +33,7 @@ public class PressInstance extends ShaftInstance implements ITickableInstance { } @Override - public void tick() { + public void beginFrame() { MechanicalPressTileEntity press = (MechanicalPressTileEntity) tile; if (!press.running) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index 7cff62d3a..7b06a384a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -8,13 +8,9 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Rotation; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class SawInstance extends SingleRotatingInstance { @@ -24,8 +20,8 @@ public class SawInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - if (lastState.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); + if (blockState.get(FACING).getAxis().isHorizontal()) + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); else return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis())); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java index 6e692fcb9..7499176f5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java @@ -9,13 +9,9 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.Minecraft; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class StickerInstance extends TileEntityInstance implements ITickableInstance { +public class StickerInstance extends TileEntityInstance implements IDynamicInstance { float lastOffset = Float.NaN; @@ -27,24 +23,24 @@ public class StickerInstance extends TileEntityInstance imple @Override protected void init() { - head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, lastState).createInstance(); + head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); updateLight(); } @Override - public void tick() { - lastState = world.getBlockState(pos); + public void beginFrame() { + blockState = world.getBlockState(pos); float offset = tile.piston.getValue(AnimationTickHolder.getPartialTicks()); if (tile.getWorld() != Minecraft.getInstance().world) - offset = lastState.get(StickerBlock.EXTENDED) ? 1 : 0; + offset = blockState.get(StickerBlock.EXTENDED) ? 1 : 0; if (Math.abs(offset - lastOffset) < 1e-4) return; - Direction facing = lastState.get(StickerBlock.FACING); + Direction facing = blockState.get(StickerBlock.FACING); MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) .translate(getFloatingPos()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java index 1b9cc2e27..085819e38 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java @@ -6,23 +6,18 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.RenderMaterials; -import com.simibubi.create.foundation.render.backend.instancing.ITickableInstance; +import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.client.renderer.Vector3f; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class GantryCarriageInstance extends ShaftInstance implements ITickableInstance { +public class GantryCarriageInstance extends ShaftInstance implements IDynamicInstance { private InstanceKey gantryCogs; @@ -35,17 +30,17 @@ public class GantryCarriageInstance extends ShaftInstance implements ITickableIn super.init(); gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS) - .getModel(AllBlockPartials.GANTRY_COGS, lastState) + .getModel(AllBlockPartials.GANTRY_COGS, blockState) .createInstance(); updateLight(); } @Override - public void tick() { - lastState = tile.getBlockState(); - Direction facing = lastState.get(GantryCarriageBlock.FACING); - Boolean alongFirst = lastState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE); + public void beginFrame() { + blockState = tile.getBlockState(); + Direction facing = blockState.get(GantryCarriageBlock.FACING); + Boolean alongFirst = blockState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE); Direction.Axis rotationAxis = KineticTileEntityRenderer.getRotationAxisOf(tile); BlockPos visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos() : tile.getPos() diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java index 4e180a43d..765156582 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java @@ -5,7 +5,7 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; -import com.simibubi.create.foundation.render.backend.instancing.ITickableInstance; +import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; @@ -15,7 +15,7 @@ import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.util.Direction; import net.minecraft.util.math.MathHelper; -public class FluidValveInstance extends ShaftInstance implements ITickableInstance { +public class FluidValveInstance extends ShaftInstance implements IDynamicInstance { protected InstanceKey pointer; @@ -31,26 +31,26 @@ public class FluidValveInstance extends ShaftInstance implements ITickableInstan protected void init() { super.init(); - Direction facing = lastState.get(FluidValveBlock.FACING); + Direction facing = blockState.get(FluidValveBlock.FACING); yRot = AngleHelper.horizontalAngle(facing); xRot = facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90; - Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(lastState); + Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(blockState); Direction.Axis shaftAxis = KineticTileEntityRenderer.getRotationAxisOf(tile); pointerRotationOffset = 0; if (pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical()) pointerRotationOffset = 90; - pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, lastState).createInstance(); + pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); updateLight(); transformPointer((FluidValveTileEntity) tile); } @Override - public void tick() { + public void beginFrame() { FluidValveTileEntity valve = (FluidValveTileEntity) tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 1891a7a2b..8b2845933 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -6,14 +6,12 @@ import java.util.function.Supplier; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; -import com.simibubi.create.content.contraptions.base.KineticData; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.block.render.SpriteShiftEntry; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; -import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.MatrixStacker; @@ -41,13 +39,13 @@ public class BeltInstance extends KineticTileInstance { @Override protected void init() { - if (!AllBlocks.BELT.has(lastState)) + if (!AllBlocks.BELT.has(blockState)) return; keys = new ArrayList<>(2); - beltSlope = lastState.get(BeltBlock.SLOPE); - facing = lastState.get(BeltBlock.HORIZONTAL_FACING); + beltSlope = blockState.get(BeltBlock.SLOPE); + facing = blockState.get(BeltBlock.HORIZONTAL_FACING); upward = beltSlope == BeltSlope.UPWARD; diagonal = beltSlope.isDiagonal(); sideways = beltSlope == BeltSlope.SIDEWAYS; @@ -55,7 +53,7 @@ public class BeltInstance extends KineticTileInstance { alongX = facing.getAxis() == Direction.Axis.X; alongZ = facing.getAxis() == Direction.Axis.Z; - BeltPart part = lastState.get(BeltBlock.PART); + BeltPart part = blockState.get(BeltBlock.PART); boolean start = part == BeltPart.START; boolean end = part == BeltPart.END; DyeColor color = tile.color.orElse(null); @@ -64,7 +62,7 @@ public class BeltInstance extends KineticTileInstance { AllBlockPartials beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom); SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); - InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, lastState); + InstancedModel beltModel = beltPartial.renderOnBelt(modelManager, blockState); keys.add(setup(beltModel.createInstance(), bottom, spriteShift)); @@ -144,11 +142,11 @@ public class BeltInstance extends KineticTileInstance { return modelTransform; }; - return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, lastState, dir, ms); + return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); } private Direction getOrientation() { - Direction dir = lastState.get(BeltBlock.HORIZONTAL_FACING) + Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING) .rotateY(); if (beltSlope == BeltSlope.SIDEWAYS) dir = Direction.UP; diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 641d72a68..73a3d6a28 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -27,14 +27,14 @@ public class SplitShaftInstance extends KineticTileInstance(2); - Block block = lastState.getBlock(); - final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(lastState); + Block block = blockState.getBlock(); + final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState); float speed = tile.getSpeed(); for (Direction dir : Iterate.directionsInAxis(boxAxis)) { - InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir); + InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir); float splitSpeed = speed * tile.getRotationSpeedModifier(dir); @@ -44,8 +44,8 @@ public class SplitShaftInstance extends KineticTileInstance faces; @@ -33,9 +33,9 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn faces = new ArrayList<>(2); GaugeTileEntity gaugeTile = (GaugeTileEntity) tile; - GaugeBlock gaugeBlock = (GaugeBlock) lastState.getBlock(); + GaugeBlock gaugeBlock = (GaugeBlock) blockState.getBlock(); - InstancedModel dialModel = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_DIAL, lastState); + InstancedModel dialModel = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_DIAL, blockState); InstancedModel headModel = getHeadModel(); ms = new MatrixStack(); @@ -45,7 +45,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn float progress = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), gaugeTile.prevDialState, gaugeTile.dialState); for (Direction facing : Iterate.directions) { - if (!gaugeBlock.shouldRenderHeadOnFace(world, pos, lastState, facing)) + if (!gaugeBlock.shouldRenderHeadOnFace(world, pos, blockState, facing)) continue; DialFace face = makeFace(facing, dialModel, headModel); @@ -63,7 +63,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn } @Override - public void tick() { + public void beginFrame() { GaugeTileEntity gaugeTile = (GaugeTileEntity) tile; if (MathHelper.epsilonEquals(gaugeTile.prevDialState, gaugeTile.dialState)) @@ -156,7 +156,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, lastState); + return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState); } } @@ -167,7 +167,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, lastState); + return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState); } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index ec75b02a6..77d89ad6d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -8,17 +8,13 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.foundation.render.backend.instancing.InstanceKey; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; -import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry; import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; public class GearboxInstance extends KineticTileInstance { @@ -33,7 +29,7 @@ public class GearboxInstance extends KineticTileInstance { protected void init() { keys = new EnumMap<>(Direction.class); - final Direction.Axis boxAxis = lastState.get(BlockStateProperties.AXIS); + final Direction.Axis boxAxis = blockState.get(BlockStateProperties.AXIS); int blockLight = world.getLightLevel(LightType.BLOCK, pos); int skyLight = world.getLightLevel(LightType.SKY, pos); @@ -44,7 +40,7 @@ public class GearboxInstance extends KineticTileInstance { if (boxAxis == axis) continue; - InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction); + InstancedModel shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction); InstanceKey key = shaft.createInstance(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java index 31b3dd558..47aaf49bb 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java @@ -6,18 +6,15 @@ import com.simibubi.create.content.logistics.block.FlapData; import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; import java.util.Map; -public class BeltTunnelInstance extends TileEntityInstance implements ITickableInstance { +public class BeltTunnelInstance extends TileEntityInstance implements IDynamicInstance { private Map>> tunnelFlaps; @@ -31,7 +28,7 @@ public class BeltTunnelInstance extends TileEntityInstance tunnelFlaps = new EnumMap<>(Direction.class); InstancedModel model = modelManager.getMaterial(KineticRenderMaterials.FLAPS) - .getModel(AllBlockPartials.BELT_TUNNEL_FLAP, lastState); + .getModel(AllBlockPartials.BELT_TUNNEL_FLAP, blockState); int blockLight = world.getLightLevel(LightType.BLOCK, pos); int skyLight = world.getLightLevel(LightType.SKY, pos); @@ -71,7 +68,7 @@ public class BeltTunnelInstance extends TileEntityInstance } @Override - public void tick() { + public void beginFrame() { tunnelFlaps.forEach((direction, keys) -> { InterpolatedValue flapValue = tile.flaps.get(direction); if (flapValue == null) { diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java new file mode 100644 index 000000000..3d4ef9fdc --- /dev/null +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java @@ -0,0 +1,58 @@ +package com.simibubi.create.content.logistics.block.diodes; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.foundation.render.backend.instancing.*; +import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; +import com.simibubi.create.foundation.utility.ColorHelper; +import com.simibubi.create.foundation.utility.MatrixStacker; + +public class AdjustableRepeaterInstance extends TileEntityInstance implements ITickableInstance { + + protected InstanceKey indicator; + + protected int previousState; + + public AdjustableRepeaterInstance(InstancedTileRenderer modelManager, AdjustableRepeaterTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); + + MatrixStack ms = new MatrixStack(); + MatrixStacker.of(ms).translate(getFloatingPos()); + + indicator.getInstance() + .setTransform(ms) + .setColor(getColor()); + + previousState = tile.state; + + updateLight(); + } + + @Override + public void tick() { + if (previousState == tile.state) return; + + indicator.getInstance().setColor(getColor()); + + previousState = tile.state; + } + + @Override + public void updateLight() { + relight(pos, indicator.getInstance()); + } + + @Override + public void remove() { + indicator.delete(); + } + + protected int getColor() { + return ColorHelper.mixColors(0x2C0300, 0xCD0000, tile.state / (float) tile.maxState.getValue()); + } +} diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterTileEntity.java index 7c4515a1c..543d8c93d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterTileEntity.java @@ -5,6 +5,7 @@ import static net.minecraft.block.RedstoneDiodeBlock.POWERED; import java.util.List; +import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour; @@ -15,7 +16,7 @@ import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.MathHelper; -public class AdjustableRepeaterTileEntity extends SmartTileEntity { +public class AdjustableRepeaterTileEntity extends SmartTileEntity implements IInstanceRendered { public int state; public boolean charging; @@ -119,5 +120,4 @@ public class AdjustableRepeaterTileEntity extends SmartTileEntity { state += charging ? 1 : -1; } - } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java index 693e045b7..d3db0c74d 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java @@ -5,15 +5,12 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials; import com.simibubi.create.content.logistics.block.FlapData; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.utility.AnimationTickHolder; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; -public class FunnelInstance extends TileEntityInstance implements ITickableInstance { +public class FunnelInstance extends TileEntityInstance implements IDynamicInstance { private ArrayList> flaps; @@ -27,15 +24,15 @@ public class FunnelInstance extends TileEntityInstance impleme if (!tile.hasFlap()) return; - AllBlockPartials flapPartial = (lastState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP + AllBlockPartials flapPartial = (blockState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP : AllBlockPartials.BELT_FUNNEL_FLAP); InstancedModel model = modelManager.getMaterial(KineticRenderMaterials.FLAPS) - .getModel(flapPartial, lastState); + .getModel(flapPartial, blockState); int blockLight = world.getLightLevel(LightType.BLOCK, pos); int skyLight = world.getLightLevel(LightType.SKY, pos); - Direction direction = FunnelBlock.getFunnelFacing(lastState); + Direction direction = FunnelBlock.getFunnelFacing(blockState); float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks()); float horizontalAngle = direction.getOpposite().getHorizontalAngle(); @@ -62,7 +59,7 @@ public class FunnelInstance extends TileEntityInstance impleme } @Override - public void tick() { + public void beginFrame() { if (flaps == null) return; float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks()); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 7a504c7b1..b63c070d3 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -6,7 +6,6 @@ import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; -import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; @@ -19,16 +18,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; import java.util.ArrayList; -import java.util.stream.Stream; -public class ArmInstance extends SingleRotatingInstance implements ITickableInstance { +public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance { private InstanceKey base; private InstanceKey lowerBody; @@ -51,13 +45,13 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.MODELS); - base = mat.getModel(AllBlockPartials.ARM_BASE, lastState).createInstance(); - lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, lastState).createInstance(); - upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, lastState).createInstance(); - head = mat.getModel(AllBlockPartials.ARM_HEAD, lastState).createInstance(); - claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, lastState).createInstance(); + base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); + lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); + upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, blockState).createInstance(); + head = mat.getModel(AllBlockPartials.ARM_HEAD, blockState).createInstance(); + claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, blockState).createInstance(); - InstancedModel clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, lastState); + InstancedModel clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, blockState); InstanceKey clawGrip1 = clawHalfModel.createInstance(); InstanceKey clawGrip2 = clawHalfModel.createInstance(); @@ -65,12 +59,12 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); firstTick = true; - tick(); + beginFrame(); updateLight(); } @Override - public void tick() { + public void beginFrame() { ArmTileEntity arm = (ArmTileEntity) tile; boolean settled = arm.baseAngle.settled() && arm.lowerArmAngle.settled() && arm.upperArmAngle.settled() && arm.headAngle.settled(); @@ -107,7 +101,7 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst msr.translate(getFloatingPos()); msr.centre(); - if (lastState.get(ArmBlock.CEILING)) + if (blockState.get(ArmBlock.CEILING)) msr.rotateX(180); ArmRenderer.transformBase(msr, baseAngle); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java index b14a2cef2..def1976ce 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -2,8 +2,6 @@ package com.simibubi.create.content.logistics.block.redstone; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.contraptions.components.flywheel.FlyWheelInstance; -import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; @@ -12,12 +10,9 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.MatrixStacker; import net.minecraft.state.properties.AttachFace; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class AnalogLeverInstance extends TileEntityInstance implements ITickableInstance { +public class AnalogLeverInstance extends TileEntityInstance implements IDynamicInstance { protected InstanceKey handle; protected InstanceKey indicator; @@ -33,19 +28,19 @@ public class AnalogLeverInstance extends TileEntityInstance> mat = modelManager.getMaterial(RenderMaterials.MODELS); - handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, lastState).createInstance(); - indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, lastState).createInstance(); + handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance(); + indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance(); - AttachFace face = lastState.get(AnalogLeverBlock.FACE); + AttachFace face = blockState.get(AnalogLeverBlock.FACE); rX = face == AttachFace.FLOOR ? 0 : face == AttachFace.WALL ? 90 : 180; - rY = AngleHelper.horizontalAngle(lastState.get(AnalogLeverBlock.HORIZONTAL_FACING)); + rY = AngleHelper.horizontalAngle(blockState.get(AnalogLeverBlock.HORIZONTAL_FACING)); setupModel(); updateLight(); } @Override - public void tick() { + public void beginFrame() { if (!tile.clientState.settled()) setupModel(); } diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java index 97f27b930..fd9ddce84 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java @@ -1,27 +1,15 @@ package com.simibubi.create.content.schematics.block; import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; import com.simibubi.create.AllBlockPartials; -import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelInstance; -import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity; -import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; -import net.minecraft.block.BlockState; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LightType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.fml.DistExecutor; -public class SchematicannonInstance extends TileEntityInstance implements ITickableInstance { +public class SchematicannonInstance extends TileEntityInstance implements IDynamicInstance { private InstanceKey connector; private InstanceKey pipe; @@ -35,14 +23,14 @@ public class SchematicannonInstance extends TileEntityInstance> mat = modelManager.getMaterial(RenderMaterials.MODELS); - connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, lastState).createInstance(); - pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, lastState).createInstance(); + connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance(); + pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance(); updateLight(); } @Override - public void tick() { + public void beginFrame() { float partialTicks = AnimationTickHolder.getPartialTicks(); double[] cannonAngles = SchematicannonRenderer.getCannonAngles(tile, pos, partialTicks); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IDynamicInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IDynamicInstance.java new file mode 100644 index 000000000..0af4bc1eb --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/IDynamicInstance.java @@ -0,0 +1,8 @@ +package com.simibubi.create.foundation.render.backend.instancing; + +public interface IDynamicInstance { + /** + * Called every frame, this can be used to make more dynamic animations. + */ + void beginFrame(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java index 4d79545a4..04a6f7ec0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/ITickableInstance.java @@ -1,8 +1,6 @@ package com.simibubi.create.foundation.render.backend.instancing; public interface ITickableInstance { - /** - * Called every frame, this can be used to make more dynamic animations. - */ + void tick(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 172431730..54142c6e4 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -4,7 +4,6 @@ import java.util.*; import javax.annotation.Nullable; -import com.simibubi.create.foundation.ponder.PonderWorld; import com.simibubi.create.foundation.render.backend.Backend; import com.simibubi.create.foundation.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.gl.BasicProgram; @@ -26,6 +25,7 @@ public abstract class InstancedTileRenderer

{ protected Map> instances = new HashMap<>(); protected Map tickableInstances = new HashMap<>(); + protected Map dynamicInstances = new HashMap<>(); protected Map, RenderMaterial> materials = new HashMap<>(); @@ -45,12 +45,18 @@ public abstract class InstancedTileRenderer

{ if (ticks % 10 == 0) { clean(); } + + if (tickableInstances.size() > 0) + tickableInstances.values().forEach(ITickableInstance::tick); } public void beginFrame(double cameraX, double cameraY, double cameraZ) { - queuedAdditions.forEach(this::add); - queuedAdditions.clear(); - tickableInstances.values().forEach(ITickableInstance::tick); + if (queuedAdditions.size() > 0) { + queuedAdditions.forEach(this::add); + queuedAdditions.clear(); + } + if (dynamicInstances.size() > 0) + dynamicInstances.values().forEach(IDynamicInstance::beginFrame); } public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { @@ -93,8 +99,11 @@ public abstract class InstancedTileRenderer

{ if (renderer != null) { instances.put(tile, renderer); + if (renderer instanceof IDynamicInstance) + dynamicInstances.put(tile, (IDynamicInstance) renderer); + if (renderer instanceof ITickableInstance) - tickableInstances.put(tile, (ITickableInstance) renderer); + tickableInstances.put(tile, ((ITickableInstance) renderer)); } return renderer; @@ -148,6 +157,7 @@ public abstract class InstancedTileRenderer

{ if (instance != null) { instance.remove(); instances.remove(tile); + dynamicInstances.remove(tile); tickableInstances.remove(tile); } } @@ -162,7 +172,7 @@ public abstract class InstancedTileRenderer

{ material.delete(); } instances.clear(); - tickableInstances.clear(); + dynamicInstances.clear(); } public boolean canCreateInstance(TileEntity tile) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java index b5241999c..fd31e3569 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/TileEntityInstance.java @@ -1,7 +1,6 @@ package com.simibubi.create.foundation.render.backend.instancing; import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight; -import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -17,24 +16,24 @@ public abstract class TileEntityInstance { protected final T tile; protected final World world; protected final BlockPos pos; - protected BlockState lastState; + protected BlockState blockState; public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { this.modelManager = modelManager; this.tile = tile; this.world = tile.getWorld(); this.pos = tile.getPos(); - this.lastState = tile.getBlockState(); + this.blockState = tile.getBlockState(); init(); } public final void update() { BlockState currentState = tile.getBlockState(); - if (lastState == currentState) { + if (blockState == currentState) { onUpdate(); } else { remove(); - lastState = currentState; + blockState = currentState; init(); } } diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java index 23df51f8f..a72e40dc2 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/renderer/ColoredOverlayTileEntityRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.tileEntity.renderer; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import net.minecraft.block.BlockState; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.RenderType; @@ -21,8 +22,10 @@ public abstract class ColoredOverlayTileEntityRenderer ext @Override protected void renderSafe(T te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { - SuperByteBuffer render = render(te.getWorld(), te.getPos(), te.getBlockState(), getOverlayBuffer(te), - getColor(te, partialTicks)); + + if (FastRenderDispatcher.available(te.getWorld())) return; + + SuperByteBuffer render = render(getOverlayBuffer(te), getColor(te, partialTicks), light); render.renderInto(ms, buffer.getBuffer(RenderType.getSolid())); } @@ -30,10 +33,8 @@ public abstract class ColoredOverlayTileEntityRenderer ext protected abstract SuperByteBuffer getOverlayBuffer(T te); - public static SuperByteBuffer render(World world, BlockPos pos, BlockState state, SuperByteBuffer buffer, - int color) { - int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(world, state, pos); - return buffer.color(color).light(packedLightmapCoords); + public static SuperByteBuffer render(SuperByteBuffer buffer, int color, int light) { + return buffer.color(color).light(light); } }