From d50e07369bf04c064a65b43defbb6fde4f026b79 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 4 Feb 2021 19:21:25 -0800 Subject: [PATCH] flywheels render with the new tech, and therefore have more accurate lighting --- .../com/simibubi/create/AllTileEntities.java | 3 +- .../contraptions/base/HalfShaftInstance.java | 7 +- .../base/HorizontalHalfShaftInstance.java | 4 +- .../components/flywheel/FlyWheelInstance.java | 72 +++++++++++++++++++ .../components/flywheel/FlywheelRenderer.java | 6 +- 5 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 8fb212476..fcf40110d 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -17,6 +17,7 @@ import com.simibubi.create.content.contraptions.components.fan.EncasedFanRendere import com.simibubi.create.content.contraptions.components.fan.EncasedFanTileEntity; import com.simibubi.create.content.contraptions.components.fan.FanInstance; import com.simibubi.create.content.contraptions.components.fan.NozzleTileEntity; +import com.simibubi.create.content.contraptions.components.flywheel.FlyWheelInstance; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelRenderer; import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity; import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineRenderer; @@ -372,7 +373,7 @@ public class AllTileEntities { .tileEntity("flywheel", FlywheelTileEntity::new) .validBlocks(AllBlocks.FLYWHEEL) .renderer(() -> FlywheelRenderer::new) - .onRegister(HorizontalHalfShaftInstance::register) + .onRegister(FlyWheelInstance::register) .register(); public static final TileEntityEntry FURNACE_ENGINE = Create.registrate() 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 d25b28b73..fc85c9193 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 @@ -18,18 +18,17 @@ public class HalfShaftInstance extends SingleRotatingInstance { InstancedTileRenderRegistry.instance.register(type, HalfShaftInstance::new)); } - public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected InstancedModel getModel() { - BlockState state = tile.getBlockState(); Direction dir = getShaftDirection(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, state, dir); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir); } protected Direction getShaftDirection() { - return tile.getBlockState().get(BlockStateProperties.FACING); + return lastState.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 4c4af041f..7c20f6959 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 @@ -14,12 +14,12 @@ public class HorizontalHalfShaftInstance extends HalfShaftInstance { InstancedTileRenderRegistry.instance.register(type, HorizontalHalfShaftInstance::new)); } - public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected Direction getShaftDirection() { - return tile.getBlockState().get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); + return lastState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite(); } } 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 new file mode 100644 index 000000000..c0b7405e8 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -0,0 +1,72 @@ +package com.simibubi.create.content.contraptions.components.flywheel; + +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.foundation.render.SuperByteBuffer; +import com.simibubi.create.foundation.render.instancing.*; +import net.minecraft.block.BlockState; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.Rotation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; + +import java.util.function.Consumer; + +public class FlyWheelInstance extends KineticTileInstance { + public static void register(TileEntityType type) { + DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> + InstancedTileRenderRegistry.instance.register(type, FlyWheelInstance::new)); + } + + protected Direction facing; + + protected InstanceKey shaft; + protected InstanceKey wheel; + + public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { + super(modelManager, tile); + } + + @Override + protected void init() { + facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); + + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + Consumer setup = setupFunc(tile.getSpeed(), axis); + shaft = shaftModel().setupInstance(setup); + wheel = wheelModel().setupInstance(setup); + } + + @Override + protected void onUpdate() { + Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); + updateRotation(shaft, axis); + updateRotation(wheel, axis); + } + + @Override + public void updateLight() { + shaft.modifyInstance(this::relight); + wheel.modifyInstance(this::relight); + } + + @Override + public void remove() { + shaft.delete(); + wheel.delete(); + shaft = null; + wheel = null; + } + + protected InstancedModel shaftModel() { + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, facing.getOpposite()); + } + + protected InstancedModel wheelModel() { + BlockState rotate = lastState.rotate(Rotation.CLOCKWISE_90); + return AllBlockPartials.FLYWHEEL.renderOnDirectionalSouthRotating(modelManager, rotate, rotate.get(BlockStateProperties.HORIZONTAL_FACING)); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 9c4d6b6be..97a9828f0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -69,9 +69,9 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { .renderInto(ms, vb); } - kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) - .getAxis(), AngleHelper.rad(angle), light); - wheel.renderInto(ms, vb); +// kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) +// .getAxis(), AngleHelper.rad(angle), light); +// wheel.renderInto(ms, vb); }