From a56514c308a425a959a7b6d38a87938413cb854e Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 25 Mar 2021 14:29:52 -0700 Subject: [PATCH] Some housekeeping and documentation. --- .../contraptions/base/HalfShaftInstance.java | 2 +- .../contraptions/base/KineticData.java | 27 ++++---- .../base/KineticTileInstance.java | 68 ++++++++++++------- .../base/ShaftlessCogInstance.java | 2 +- .../base/SingleRotatingInstance.java | 17 ++--- .../components/actors/DrillInstance.java | 2 +- .../actors/HarvesterActorInstance.java | 2 +- .../crafter/MechanicalCrafterInstance.java | 2 +- .../components/crank/HandCrankInstance.java | 4 +- .../deployer/DeployerActorInstance.java | 4 +- .../components/deployer/DeployerInstance.java | 7 +- .../components/fan/FanInstance.java | 17 ++--- .../components/flywheel/FlyWheelInstance.java | 16 ++--- .../flywheel/engine/EngineInstance.java | 7 +- .../millstone/MillStoneCogInstance.java | 2 +- .../components/mixer/MixerInstance.java | 10 ++- .../components/press/PressInstance.java | 3 +- .../components/saw/SawInstance.java | 5 +- .../chassis/StickerInstance.java | 7 +- .../gantry/GantryCarriageInstance.java | 9 +-- .../contraptions/fluids/PumpCogInstance.java | 2 +- .../fluids/pipes/FluidValveInstance.java | 5 +- .../relays/belt/BeltInstance.java | 23 ++++--- .../relays/encased/ShaftInstance.java | 2 +- .../relays/encased/SplitShaftInstance.java | 22 ++---- .../relays/gauge/GaugeInstance.java | 11 ++- .../relays/gearbox/GearboxInstance.java | 11 +-- .../diodes/AdjustableRepeaterInstance.java | 6 +- .../block/mechanicalArm/ArmInstance.java | 9 +-- .../block/redstone/AnalogLeverInstance.java | 6 +- .../block/SchematicannonInstance.java | 7 +- .../backend/instancing/IDynamicInstance.java | 12 +++- .../backend/instancing/ITickableInstance.java | 25 +++++-- .../instancing/InstancedTileRenderer.java | 5 +- .../backend/instancing/MaterialType.java | 5 -- .../backend/instancing/RenderMaterial.java | 6 +- .../instancing/TileEntityInstance.java | 64 ++++++++++++++--- 37 files changed, 228 insertions(+), 206 deletions(-) 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 7b5249963..8e974deab 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 @@ -15,7 +15,7 @@ public class HalfShaftInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { Direction dir = getShaftDirection(); - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState, dir); } protected Direction getShaftDirection() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java index 56b0714d3..18e48cb8f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java @@ -20,16 +20,6 @@ public class KineticData extends BasicData { super(owner); } - public KineticData setTileEntity(KineticTileEntity te) { - setPosition(te.getPos()); - if (te.hasSource()) { - setColor(te.network); - }else { - setColor(0xFF, 0xFF, 0x00); - } - return this; - } - public KineticData setPosition(BlockPos pos) { return setPosition(pos.getX(), pos.getY(), pos.getZ()); } @@ -39,11 +29,9 @@ public class KineticData extends BasicData { } public KineticData setPosition(int x, int y, int z) { - BlockPos origin = owner.renderer.getOriginCoordinate(); - - return setPosition((float) (x - origin.getX()), - (float) (y - origin.getY()), - (float) (z - origin.getZ())); + return setPosition((float) (x), + (float) (y), + (float) (z)); } public KineticData setPosition(float x, float y, float z) { @@ -60,6 +48,15 @@ public class KineticData extends BasicData { return this; } + public KineticData setColor(KineticTileEntity te) { + if (te.hasSource()) { + setColor(te.network); + }else { + setColor(0xFF, 0xFF, 0x00); + } + return this; + } + public KineticData setColor(Long l) { if (l != null) return setColor(l.longValue()); 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 a31e26f09..72eb1f9d3 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 @@ -8,41 +8,55 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; -import net.minecraft.world.LightType; public abstract class KineticTileInstance extends TileEntityInstance { + protected final Direction.Axis axis; + public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { super(modelManager, tile); + + axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); } - protected final void updateRotation(InstanceKey key, Direction.Axis axis) { - updateRotation(key, axis, tile.getSpeed()); + protected final void updateRotation(RotatingData instance) { + updateRotation(instance, getRotationAxis(), getTileSpeed()); } - protected final void updateRotation(InstanceKey key, Direction.Axis axis, float speed) { - updateRotation(key.getInstance(), axis, speed); + protected final void updateRotation(RotatingData instance, Direction.Axis axis) { + updateRotation(instance, axis, getTileSpeed()); } - protected final void updateRotation(RotatingData key, Direction.Axis axis, float speed) { - key.setRotationAxis(axis) + protected final void updateRotation(RotatingData instance, float speed) { + updateRotation(instance, getRotationAxis(), speed); + } + + protected final void updateRotation(RotatingData instance, Direction.Axis axis, float speed) { + instance.setRotationAxis(axis) .setRotationOffset(getRotationOffset(axis)) .setRotationalSpeed(speed) - .setColor(tile.network); + .setColor(tile); } - protected final void updateRotation(RotatingData key, Direction.Axis axis) { - updateRotation(key, axis, tile.getSpeed()); + protected final InstanceKey setup(InstanceKey key) { + return setup(key, getRotationAxis(), getTileSpeed()); } - protected final InstanceKey setup(InstanceKey key, float speed, Direction.Axis axis) { + protected final InstanceKey setup(InstanceKey key, Direction.Axis axis) { + return setup(key, axis, getTileSpeed()); + } + + protected final InstanceKey setup(InstanceKey key, float speed) { + return setup(key, getRotationAxis(), speed); + } + + protected final InstanceKey setup(InstanceKey key, Direction.Axis axis, float speed) { key.getInstance() .setRotationAxis(axis) .setRotationalSpeed(speed) .setRotationOffset(getRotationOffset(axis)) - .setTileEntity(tile) - .setSkyLight(world.getLightLevel(LightType.SKY, pos)) - .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)); + .setColor(tile) + .setPosition(getInstancePosition()); return key; } @@ -57,16 +71,24 @@ public abstract class KineticTileInstance extends T return offset; } + protected Direction.Axis getRotationAxis() { + return axis; + } + + protected float getTileSpeed() { + return tile.getSpeed(); + } + + protected BlockState shaft() { + return shaft(getRotationAxis()); + } + + protected final RenderMaterial> getRotatingMaterial() { + return renderer.getMaterial(KineticRenderMaterials.ROTATING); + } + public static BlockState shaft(Direction.Axis axis) { return AllBlocks.SHAFT.getDefaultState() - .with(ShaftBlock.AXIS, axis); - } - - public Direction.Axis getRotationAxis() { - return ((IRotate) blockState.getBlock()).getRotationAxis(blockState); - } - - protected final RenderMaterial> rotatingMaterial() { - return modelManager.getMaterial(KineticRenderMaterials.ROTATING); + .with(ShaftBlock.AXIS, axis); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index 952846454..7c9fd17c2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -12,6 +12,6 @@ public class ShaftlessCogInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(modelManager, tile.getBlockState()); + return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(renderer, tile.getBlockState()); } } 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 ab81c0462..c0d7d9e93 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 @@ -1,39 +1,34 @@ package com.simibubi.create.content.contraptions.base; -import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.KINETIC_TILE; - 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 net.minecraft.block.BlockState; -import net.minecraft.util.Direction; public class SingleRotatingInstance extends KineticTileInstance { - protected final InstanceKey rotatingModelKey; + protected final InstanceKey rotatingModel; public SingleRotatingInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); - Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); - rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis); + rotatingModel = setup(getModel().createInstance()); } @Override public void update() { - Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); - updateRotation(rotatingModelKey, axis); + updateRotation(rotatingModel.getInstance()); } @Override public void updateLight() { - relight(pos, rotatingModelKey.getInstance()); + relight(pos, rotatingModel.getInstance()); } @Override public void remove() { - rotatingModelKey.delete(); + rotatingModel.delete(); } protected BlockState getRenderedBlockState() { @@ -41,6 +36,6 @@ public class SingleRotatingInstance extends KineticTileInstance getModel() { - return rotatingMaterial().getModel(KINETIC_TILE, getRenderedBlockState()); + return getRotatingMaterial().getModel(getRenderedBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index dbd7b9b92..da5a33476 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -14,6 +14,6 @@ public class DrillInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); + return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(renderer, tile.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java index 1ce83ff38..43d31684c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java @@ -36,7 +36,7 @@ public class HarvesterActorInstance extends ActorInstance { public HarvesterActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> renderMaterial = modelManager.transformMaterial(); + RenderMaterial> renderMaterial = modelManager.getTransformMaterial(); BlockState state = context.state; 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 adb9fd3e2..2d88b431c 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 @@ -35,6 +35,6 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance { stacker.unCentre(); return stack; }; - return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState, facing, ms); + return getRotatingMaterial().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 382471548..f825d1927 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 @@ -30,8 +30,6 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami facing = blockState.get(BlockStateProperties.FACING); InstancedModel model = renderedHandle.renderOnDirectionalSouthModel(modelManager, blockState, facing.getOpposite()); crank = model.createInstance(); - - updateLight(); } @Override @@ -45,7 +43,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami MatrixStack ms = new MatrixStack(); MatrixStacker.of(ms) - .translate(getFloatingPos()) + .translate(getInstancePosition()) .centre() .rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis), angle) .unCentre(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java index 4d73c88ef..8cf440adf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java @@ -37,7 +37,7 @@ public class DeployerActorInstance extends ActorInstance { public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { super(modelManager, context); - RenderMaterial> mat = modelManager.transformMaterial(); + RenderMaterial> mat = modelManager.getTransformMaterial(); BlockState state = context.state; DeployerTileEntity.Mode mode = NBTHelper.readEnum(context.tileData, "Mode", DeployerTileEntity.Mode.class); @@ -56,7 +56,7 @@ public class DeployerActorInstance extends ActorInstance { Direction.Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state); shaft = modelManager.getMaterial(KineticRenderMaterials.ROTATING) - .getModel(KineticTileEntityRenderer.KINETIC_TILE, KineticTileInstance.shaft(axis)) + .getModel(KineticTileInstance.shaft(axis)) .createInstance(); int blockLight = localBlockLight(); 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 2b334a52e..f05361148 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 @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.deployer; 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.*; import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -46,7 +45,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, zRot = facing == Direction.UP ? 270 : facing == Direction.DOWN ? 90 : 0; zRotPole = rotatePole ? 90 : 0; - pole = RenderMaterials.ORIENTED.get(modelManager).getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); + pole = getOrientedMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance(); updateHandPose(); relight(pos, pole.getInstance()); @@ -73,7 +72,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, : currentHand == AllBlockPartials.DEPLOYER_HAND_HOLDING ? 4 / 16f : 3 / 16f; float distance = Math.min(MathHelper.clamp(progress, 0, 1) * (tile.reach + handLength), 21 / 16f); Vec3i facingVec = facing.getDirectionVec(); - BlockPos blockPos = getFloatingPos(); + BlockPos blockPos = getInstancePosition(); float x = blockPos.getX() + ((float) facingVec.getX()) * distance; float y = blockPos.getY() + ((float) facingVec.getY()) * distance; @@ -107,7 +106,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, if (hand != null) hand.delete(); - hand = RenderMaterials.ORIENTED.get(modelManager).getModel(currentHand, blockState).createInstance(); + hand = getOrientedMaterial().getModel(currentHand, blockState).createInstance(); relight(pos, hand.getInstance()); updateRotation(pole, hand, yRot, zRot, zRotPole); 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 8660b5628..b2beb5a75 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 @@ -17,27 +17,18 @@ public class FanInstance extends KineticTileInstance { protected final InstanceKey shaft; protected final InstanceKey fan; - final Direction.Axis axis; final Direction direction; public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { super(modelManager, tile); direction = blockState.get(FACING); - axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance(); fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance(); - RotatingData shaftInstance = shaft.getInstance(); - shaftInstance.setTileEntity(tile); - updateRotation(shaftInstance, axis); - - RotatingData fanInstance = fan.getInstance(); - fanInstance.setTileEntity(tile); - updateRotation(fanInstance, axis, getFanSpeed()); - - updateLight(); + setup(shaft); + setup(fan, getFanSpeed()); } private float getFanSpeed() { @@ -51,8 +42,8 @@ public class FanInstance extends KineticTileInstance { @Override protected void update() { - updateRotation(shaft, axis); - updateRotation(fan, axis, getFanSpeed()); + updateRotation(shaft.getInstance()); + updateRotation(fan.getInstance(), getFanSpeed()); } @Override 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 6b323f0f2..8b1fc41bf 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 @@ -6,10 +6,8 @@ import java.util.List; 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.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; @@ -49,8 +47,7 @@ public class FlyWheelInstance extends KineticTileInstance im facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING); - Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); - shaft = setup(shaftModel().createInstance(), tile.getSpeed(), axis); + shaft = setup(shaftModel().createInstance()); wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, blockState.rotate(Rotation.CLOCKWISE_90)).createInstance(); @@ -62,7 +59,7 @@ public class FlyWheelInstance extends KineticTileInstance im connectorAngleMult = flipAngle ? -1 : 1; - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); + RenderMaterial> mat = getTransformMaterial(); upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); @@ -73,8 +70,6 @@ public class FlyWheelInstance extends KineticTileInstance im } else { connectors = Collections.emptyList(); } - - updateLight(); } @Override @@ -90,7 +85,7 @@ public class FlyWheelInstance extends KineticTileInstance im MatrixStack ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); - msr.translate(getFloatingPos()); + msr.translate(getInstancePosition()); if (connection != null) { float rotation = angle * connectorAngleMult; @@ -133,8 +128,7 @@ public class FlyWheelInstance extends KineticTileInstance im @Override protected void update() { - Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); - updateRotation(shaft, axis); + updateRotation(shaft.getInstance()); } @Override @@ -156,7 +150,7 @@ public class FlyWheelInstance extends KineticTileInstance im } protected InstancedModel shaftModel() { - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, facing.getOpposite()); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, 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 b2830d978..370cd50e0 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 @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; 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.InstancedTileRenderer; import com.simibubi.create.foundation.render.backend.instancing.TileEntityInstance; @@ -30,14 +29,14 @@ public class EngineInstance extends TileEntityInstance { Direction facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING); - this.frame = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(frame, blockState).createInstance(); + this.frame = getTransformMaterial().getModel(frame, blockState).createInstance(); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); MatrixStack ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); - msr.translate(getFloatingPos()) + msr.translate(getInstancePosition()) .nudge(tile.hashCode()) .centre() .rotate(Direction.UP, angle) @@ -46,8 +45,6 @@ public class EngineInstance extends TileEntityInstance { this.frame.getInstance() .setTransform(ms); - - updateLight(); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index cc06621a6..dded6ee67 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -15,6 +15,6 @@ public class MillStoneCogInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - return AllBlockPartials.MILLSTONE_COG.renderOnRotating(modelManager, tile.getBlockState()); + return AllBlockPartials.MILLSTONE_COG.renderOnRotating(renderer, tile.getBlockState()); } } 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 0290fdfb7..50098f65f 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,7 +5,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.ShaftlessCogInstance; -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; @@ -20,13 +19,13 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta public MixerInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); - mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState) + mixerHead = getRotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState) .createInstance(); mixerHead.getInstance() .setRotationAxis(Direction.Axis.Y); - mixerPole = modelManager.getMaterial(RenderMaterials.TRANSFORMED) + mixerPole = getTransformMaterial() .getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState) .createInstance(); @@ -36,7 +35,6 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta transformPole(renderedHeadOffset); transformHead(mixer, renderedHeadOffset); - updateLight(); } @Override @@ -56,7 +54,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta float speed = mixer.getRenderedHeadRotationSpeed(AnimationTickHolder.getPartialTicks()); mixerHead.getInstance() - .setPosition(pos) + .setPosition(getInstancePosition()) .nudge(0, -renderedHeadOffset, 0) .setRotationalSpeed(speed * 2); } @@ -65,7 +63,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta MatrixStack ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); - msr.translate(getFloatingPos()); + msr.translate(getInstancePosition()); msr.translate(0, -renderedHeadOffset, 0); mixerPole.getInstance().setTransform(ms); 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 cacf1d99d..b4a3eff51 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 @@ -20,7 +20,6 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { pressHead = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontalModel(dispatcher, blockState).createInstance(); - updateLight(); transformModels((MechanicalPressTileEntity) tile); } @@ -39,7 +38,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { MatrixStack ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); - msr.translate(getFloatingPos()); + msr.translate(getInstancePosition()); msr.translate(0, -renderedHeadOffset, 0); pressHead.getInstance() 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 7b06a384a..606ffe62b 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 @@ -4,7 +4,6 @@ import static net.minecraft.state.properties.BlockStateProperties.FACING; 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.base.RotatingData; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; @@ -21,8 +20,8 @@ public class SawInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { if (blockState.get(FACING).getAxis().isHorizontal()) - return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); + return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180)); else - return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis())); + return getRotatingMaterial().getModel(shaft()); } } 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 dffa94083..3fd32da92 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 @@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.ch 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.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; import com.simibubi.create.foundation.utility.AngleHelper; @@ -24,13 +23,11 @@ public class StickerInstance extends TileEntityInstance imple public StickerInstance(InstancedTileRenderer modelManager, StickerTileEntity tile) { super(modelManager, tile); - head = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); + head = getTransformMaterial().getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); fakeWorld = tile.getWorld() != Minecraft.getInstance().world; facing = blockState.get(StickerBlock.FACING); offset = blockState.get(StickerBlock.EXTENDED) ? 1 : 0; - - updateLight(); } @Override @@ -45,7 +42,7 @@ public class StickerInstance extends TileEntityInstance imple MatrixStack stack = new MatrixStack(); MatrixStacker.of(stack) - .translate(getFloatingPos()) + .translate(getInstancePosition()) .nudge(tile.hashCode()) .centre() .rotateY(AngleHelper.horizontalAngle(facing)) 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 096548d84..1ea699d6c 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 @@ -5,7 +5,6 @@ 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.RenderMaterials; 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; @@ -29,7 +28,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns public GantryCarriageInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); - gantryCogs = modelManager.getMaterial(RenderMaterials.TRANSFORMED) + gantryCogs = getTransformMaterial() .getModel(AllBlockPartials.GANTRY_COGS, blockState) .createInstance(); @@ -40,8 +39,6 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos() : tile.getPos() .offset(facing.getOpposite()); - - updateLight(); } @Override @@ -62,7 +59,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns MatrixStack ms = new MatrixStack(); MatrixStacker.of(ms) - .translate(getFloatingPos()) + .translate(getInstancePosition()) .centre() .rotateY(AngleHelper.horizontalAngle(facing)) .rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90) @@ -77,7 +74,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns @Override public void updateLight() { - relight(pos, gantryCogs.getInstance()); + relight(pos, gantryCogs.getInstance(), rotatingModel.getInstance()); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index efca3411e..786c5dca8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -15,6 +15,6 @@ public class PumpCogInstance extends SingleRotatingInstance { @Override protected InstancedModel getModel() { - return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState()); + return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(renderer, tile.getBlockState()); } } 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 c21a668ae..2fa1f8a28 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 @@ -37,9 +37,8 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical(); pointerRotationOffset = twist ? 90 : 0; - pointer = modelManager.transformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); + pointer = renderer.getTransformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); - updateLight(); transformPointer((FluidValveTileEntity) tile); } @@ -58,7 +57,7 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc MatrixStack ms = new MatrixStack(); MatrixStacker.of(ms) - .translate(getFloatingPos()) + .translate(getInstancePosition()) .centre() .rotateY(yRot) .rotateX(xRot) 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 7b06006f3..5781336c3 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 @@ -69,7 +69,7 @@ public class BeltInstance extends KineticTileInstance { if (tile.hasPulley()) { InstancedModel pulleyModel = getPulleyModel(); - pulleyKey = setup(pulleyModel.createInstance(), tile.getSpeed(), getRotationAxis()); + pulleyKey = setup(pulleyModel.createInstance()); } } @@ -83,13 +83,13 @@ public class BeltInstance extends KineticTileInstance { SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); key.getInstance() .setScrollTexture(spriteShiftEntry) - .setColor(tile.network) + .setColor(tile) .setRotationalSpeed(getScrollSpeed()); bottom = false; } if (pulleyKey != null) { - updateRotation(pulleyKey, getRotationAxis()); + updateRotation(pulleyKey.getInstance()); } } @@ -139,7 +139,7 @@ public class BeltInstance extends KineticTileInstance { return modelTransform; }; - return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); + return getRotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms); } private Direction getOrientation() { @@ -159,13 +159,14 @@ public class BeltInstance extends KineticTileInstance { Quaternion q = new Quaternion(rotX, rotY, rotZ, true); - key.getInstance() - .setScrollTexture(spriteShift) - .setScrollMult(diagonal ? 3f / 8f : 0.5f) - .setRotation(q) - .setRotationalSpeed(getScrollSpeed()) - .setRotationOffset(bottom ? 0.5f : 0f) - .setTileEntity(tile) + key.getInstance() + .setScrollTexture(spriteShift) + .setScrollMult(diagonal ? 3f / 8f : 0.5f) + .setRotation(q) + .setRotationalSpeed(getScrollSpeed()) + .setRotationOffset(bottom ? 0.5f : 0f) + .setColor(tile) + .setPosition(getInstancePosition()) .setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) .setSkyLight(world.getLightLevel(LightType.SKY, pos)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index 9805e7f05..a17c27479 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -18,7 +18,7 @@ public class ShaftInstance extends SingleRotatingInstance { @Override protected BlockState getRenderedBlockState() { - return shaft(getRotationAxis()); + return shaft(); } } 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 3c4272e1f..d55d5f4ce 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 @@ -24,19 +24,18 @@ public class SplitShaftInstance extends KineticTileInstance(2); - Block block = blockState.getBlock(); - final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState); - float speed = tile.getSpeed(); - for (Direction dir : Iterate.directionsInAxis(boxAxis)) { + for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) { InstancedModel half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir); float splitSpeed = speed * tile.getRotationSpeedModifier(dir); - keys.add(setup(half.createInstance(), splitSpeed, boxAxis)); + keys.add(setup(half.createInstance(), splitSpeed)); } + + updateLight(); } @Override @@ -47,13 +46,13 @@ public class SplitShaftInstance extends KineticTileInstance relight(pos, ((InstanceKey) key).getInstance())); + relight(pos, keys.stream().map(InstanceKey::getInstance)); } @Override @@ -62,13 +61,4 @@ public class SplitShaftInstance extends KineticTileInstance key, Direction dir) { - Direction.Axis axis = dir.getAxis(); - - key.getInstance() - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) - .setRotationOffset(getRotationOffset(axis)) - .setColor(tile.network); - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java index 11e672ad0..4af5eaa0a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java @@ -4,7 +4,6 @@ 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.relays.encased.ShaftInstance; -import com.simibubi.create.foundation.render.backend.RenderMaterials; 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.InstancedModel; @@ -30,12 +29,12 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns GaugeTileEntity gaugeTile = (GaugeTileEntity) tile; GaugeBlock gaugeBlock = (GaugeBlock) blockState.getBlock(); - InstancedModel dialModel = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_DIAL, blockState); + InstancedModel dialModel = getTransformMaterial().getModel(AllBlockPartials.GAUGE_DIAL, blockState); InstancedModel headModel = getHeadModel(); ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); - msr.translate(getFloatingPos()); + msr.translate(getInstancePosition()); float progress = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), gaugeTile.prevDialState, gaugeTile.dialState); @@ -49,8 +48,6 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns face.setupTransform(msr, progress); } - - updateLight(); } private DialFace makeFace(Direction face, InstancedModel dialModel, InstancedModel headModel) { @@ -151,7 +148,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState); + return getTransformMaterial().getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState); } } @@ -162,7 +159,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns @Override protected InstancedModel getHeadModel() { - return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState); + return getTransformMaterial().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 836422301..b34e56917 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 @@ -44,8 +44,8 @@ public class GearboxInstance extends KineticTileInstance { key.getInstance() .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffset(axis)) - .setTileEntity(tile) + .setRotationOffset(getRotationOffset(axis)).setColor(tile) + .setPosition(getInstancePosition()) .setBlockLight(blockLight) .setSkyLight(skyLight); @@ -81,12 +81,7 @@ public class GearboxInstance extends KineticTileInstance { Direction direction = key.getKey(); Direction.Axis axis = direction.getAxis(); - key.getValue() - .getInstance() - .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) - .setRotationalSpeed(getSpeed(direction)) - .setRotationOffset(getRotationOffset(axis)) - .setColor(tile.network); + updateRotation(key.getValue().getInstance(), axis, getSpeed(direction)); } } 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 index a0a6c33ea..4666c2b39 100644 --- 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 @@ -16,18 +16,16 @@ public class AdjustableRepeaterInstance extends TileEntityInstance modelManager, AdjustableRepeaterTileEntity tile) { super(modelManager, tile); - indicator = modelManager.transformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); + indicator = modelManager.getTransformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); MatrixStack ms = new MatrixStack(); - MatrixStacker.of(ms).translate(getFloatingPos()); + MatrixStacker.of(ms).translate(getInstancePosition()); indicator.getInstance() .setTransform(ms) .setColor(getColor()); previousState = tile.state; - - updateLight(); } @Override 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 046e446a8..9e680a157 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.render.backend.RenderMaterials; import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData; @@ -38,7 +37,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta public ArmInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); + RenderMaterial> mat = getTransformMaterial(); base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); @@ -52,8 +51,6 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta clawGrips = Lists.newArrayList(clawGrip1, clawGrip2); models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2); - - updateLight(); } @Override @@ -91,7 +88,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta MatrixStack msLocal = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(msLocal); - msr.translate(getFloatingPos()); + msr.translate(getInstancePosition()); msr.centre(); if (blockState.get(ArmBlock.CEILING)) @@ -147,7 +144,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta @Override protected InstancedModel getModel() { - return AllBlockPartials.ARM_COG.renderOnRotating(modelManager, tile.getBlockState()); + return AllBlockPartials.ARM_COG.renderOnRotating(renderer, tile.getBlockState()); } @Override 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 78fffc5c5..8245a1e9f 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,7 +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.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.AngleHelper; @@ -23,7 +22,7 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, AnalogLeverTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); + RenderMaterial> mat = getTransformMaterial(); handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance(); indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance(); @@ -33,7 +32,6 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, SchematicannonTileEntity tile) { super(modelManager, tile); - RenderMaterial> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED); + RenderMaterial> mat = getTransformMaterial(); connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance(); pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance(); - - updateLight(); } @Override @@ -39,7 +36,7 @@ public class SchematicannonInstance extends TileEntityInstance
If your goal is offloading work to shaders, but you're unsure exactly how you need + * to parameterize the instances, you're encouraged to implement this for prototyping. + */ public interface IDynamicInstance { /** - * Called every frame. This can be used to smoothly change instance data - * to allow for fancy animations that could not be achieved on the GPU alone. + * Called every frame. */ 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 a93f7b8d3..196ef9360 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,10 +1,25 @@ package com.simibubi.create.foundation.render.backend.instancing; +/** + * An interface giving {@link TileEntityInstance}s a hook to have a function called at + * the end of every tick. By implementing {@link ITickableInstance}, a {@link TileEntityInstance} + * can update frequently, but not every frame. + *
There are a few cases in which this should be considered over {@link IDynamicInstance}: + *
    + *
  • + * You'd like to change something about the instance every now and then. + * eg. adding or removing parts, snapping to a different rotation. + *
  • + *
  • + * Your TileEntity does animate, but the animation doesn't have + * to be smooth, in which case this could be an optimization. + *
  • + *
+ */ public interface ITickableInstance { - /** - * Called every tick. This is useful for things that don't have to be smooth, - * or to recalculate something that would only change after a game tick. - */ - void tick(); + /** + * Called every tick. + */ + 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 a0a488329..193d4e5be 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 @@ -68,11 +68,11 @@ public abstract class InstancedTileRenderer

{ return (RenderMaterial) materials.get(materialType); } - public RenderMaterial> transformMaterial() { + public RenderMaterial> getTransformMaterial() { return getMaterial(RenderMaterials.TRANSFORMED); } - public RenderMaterial> orientedMaterial() { + public RenderMaterial> getOrientedMaterial() { return getMaterial(RenderMaterials.ORIENTED); } @@ -167,6 +167,7 @@ public abstract class InstancedTileRenderer

{ TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { + renderer.updateLight(); instances.put(tile, renderer); if (renderer instanceof IDynamicInstance) diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java index bda912737..4865eecd6 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/MaterialType.java @@ -1,10 +1,5 @@ package com.simibubi.create.foundation.render.backend.instancing; -import com.simibubi.create.foundation.render.backend.gl.BasicProgram; - public class MaterialType> { - public

RenderMaterial get(InstancedTileRenderer

renderer) { - return renderer.getMaterial(this); - } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java index bfdd3fd4e..d9557abec 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/RenderMaterial.java @@ -56,7 +56,7 @@ public class RenderMaterial

buildModel(partial.get(), referenceState, modelTransform.get())); } - public MODEL getModel(Compartment compartment, BlockState toRender) { - return get(compartment, toRender, () -> buildModel(toRender)); + public MODEL getModel(BlockState toRender) { + return get(Compartment.GENERIC_TILE, toRender, () -> buildModel(toRender)); } public MODEL get(Compartment compartment, T key, Supplier supplier) { 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 4c66529da..97da4b18b 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,6 +1,9 @@ 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 com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData; + import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; @@ -10,16 +13,33 @@ import net.minecraft.world.World; import java.util.Arrays; import java.util.stream.Stream; +/** + * The layer between a {@link TileEntity} and the Flywheel backend. + * + *

{@link #updateLight()} is called after construction. + * + *

There are a few additional features that overriding classes can opt in to: + *

    + *
  • {@link IDynamicInstance}
  • + *
  • {@link ITickableInstance}
  • + *
+ * See the interfaces' documentation for more information about each one. + * + *
Implementing one or more of these will give a {@link TileEntityInstance} access + * to more interesting and regular points within a tick or a frame. + * + * @param The type of {@link TileEntity} your class is an instance of. + */ public abstract class TileEntityInstance { - protected final InstancedTileRenderer modelManager; + protected final InstancedTileRenderer renderer; protected final T tile; protected final World world; protected final BlockPos pos; protected final BlockState blockState; - public TileEntityInstance(InstancedTileRenderer modelManager, T tile) { - this.modelManager = modelManager; + public TileEntityInstance(InstancedTileRenderer renderer, T tile) { + this.renderer = renderer; this.tile = tile; this.world = tile.getWorld(); this.pos = tile.getPos(); @@ -30,26 +50,46 @@ public abstract class TileEntityInstance { * Update instance data here. Good for when data doesn't change very often and when animations are GPU based. * Don't query lighting data here, that's handled separately in {@link #updateLight()}. * - * If your animations are complex and more CPU driven, use {@link IDynamicInstance} or {@link ITickableInstance}. + *

If your animations are complex or more CPU driven, see {@link IDynamicInstance} or {@link ITickableInstance}. */ protected void update() { } /** - * Called when a light update occurs in the world. If your model needs it, update light here. + * Called after construction and when a light update occurs in the world. + * + *
If your model needs it, update light here. */ public void updateLight() { } /** - * Call {@link InstanceKey#delete()} on all acquired keys. + * Free any acquired resources. + * + *
eg. call {@link InstanceKey#delete()}. */ public abstract void remove(); + /** + * Just before {@link #update()} would be called, shouldReset() is checked. + * If this function returns true, then this instance will be {@link #remove}d, + * and another instance will be constructed to replace it. This allows for more sane resource + * acquisition compared to trying to update everything within the lifetime of an instance. + * + * @return true if this instance should be discarded and refreshed. + */ public boolean shouldReset() { return tile.getBlockState() != blockState; } - public BlockPos getFloatingPos() { - return pos.subtract(modelManager.getOriginCoordinate()); + /** + * In order to accommodate for floating point precision errors at high coordinates, + * {@link InstancedTileRenderer}s are allowed to arbitrarily adjust the origin, and + * shift the world matrix provided as a shader uniform accordingly. + * + * @return The {@link BlockPos} at which the {@link TileEntity} this instance + * represents should be rendered at to appear in the correct location. + */ + public BlockPos getInstancePosition() { + return pos.subtract(renderer.getOriginCoordinate()); } protected void relight(BlockPos pos, IFlatLight... models) { @@ -67,4 +107,12 @@ public abstract class TileEntityInstance { protected void relight(int block, int sky, Stream> models) { models.forEach(model -> model.setBlockLight(block).setSkyLight(sky)); } + + protected RenderMaterial> getTransformMaterial() { + return renderer.getTransformMaterial(); + } + + protected RenderMaterial> getOrientedMaterial() { + return renderer.getOrientedMaterial(); + } }