diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 8f2ecaa00..e090e03a3 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -1,6 +1,5 @@ package com.simibubi.create; -import com.simibubi.create.content.contraptions.base.BackHalfShaftInstance; import com.simibubi.create.content.contraptions.base.HalfShaftInstance; import com.simibubi.create.content.contraptions.base.HorizontalHalfShaftInstance; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; @@ -61,9 +60,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.gan import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonTileEntity; -import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyInstance; -import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyRenderer; -import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity; +import com.simibubi.create.content.contraptions.components.structureMovement.pulley.*; import com.simibubi.create.content.contraptions.components.turntable.TurntableTileEntity; import com.simibubi.create.content.contraptions.components.waterwheel.WaterWheelTileEntity; import com.simibubi.create.content.contraptions.fluids.PumpCogInstance; @@ -312,7 +309,7 @@ public class AllTileEntities { public static final TileEntityEntry HOSE_PULLEY = Create.registrate() .tileEntity("hose_pulley", HosePulleyTileEntity::new) - .instance(() -> ShaftInstance::new) + .instance(() -> HosePulleyInstance::new) .validBlocks(AllBlocks.HOSE_PULLEY) .renderer(() -> HosePulleyRenderer::new) .register(); @@ -399,7 +396,7 @@ public class AllTileEntities { public static final TileEntityEntry ROPE_PULLEY = Create.registrate() .tileEntity("rope_pulley", PulleyTileEntity::new) - .instance(() -> PulleyInstance::new) + .instance(() -> RopePulleyInstance::new) .validBlocks(AllBlocks.ROPE_PULLEY) .renderer(() -> PulleyRenderer::new) .register(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java similarity index 77% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyInstance.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java index 8253ba25d..ed449c4a7 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/PulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java @@ -10,6 +10,7 @@ import net.minecraft.world.LightType; import java.util.Arrays; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; import com.simibubi.create.foundation.render.backend.core.OrientedData; import com.simibubi.create.foundation.render.backend.instancing.*; @@ -21,28 +22,26 @@ import com.simibubi.create.foundation.render.backend.light.LightUpdateListener; import com.simibubi.create.foundation.render.backend.light.LightUpdater; import com.simibubi.create.foundation.utility.AnimationTickHolder; -public class PulleyInstance extends ShaftInstance implements IDynamicInstance, LightUpdateListener { +public abstract class AbstractPulleyInstance extends ShaftInstance implements IDynamicInstance, LightUpdateListener { - final PulleyTileEntity tile = (PulleyTileEntity) super.tile; final OrientedData coil; final SelectInstance magnet; final InstanceGroup rope; final ConditionalInstance halfRope; - private float offset; - private final Direction rotatingAbout; - private final Vector3f rotationAxis; + protected float offset; + protected final Direction rotatingAbout; + protected final Vector3f rotationAxis; private byte[] bLight = new byte[1]; private byte[] sLight = new byte[1]; private GridAlignedBB volume; - public PulleyInstance(InstancedTileRenderer dispatcher, PulleyTileEntity tile) { + public AbstractPulleyInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { super(dispatcher, tile); rotatingAbout = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis); rotationAxis = rotatingAbout.getUnitVector(); - updateOffset(); coil = getCoilModel() .createInstance() @@ -53,17 +52,19 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L .addModel(getHalfMagnetModel()); rope = new InstanceGroup<>(getRopeModel()); - resizeRope(); - halfRope = new ConditionalInstance<>(getHalfRopeModel(), this::shouldRenderHalfRope); - - beginFrame(); } @Override public void beginFrame() { updateOffset(); + transformModels(); + } + + private void transformModels() { + resizeRope(); + coil.setRotation(rotationAxis.getDegreesQuaternion(offset * 180)); magnet.update().get().ifPresent(data -> { @@ -85,7 +86,6 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L .setSkyLight(sLight[0]); }); - resizeRope(); if (isRunning()) { int size = rope.size(); for (int i = 0; i < size; i++) { @@ -115,34 +115,19 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L halfRope.delete(); } - protected InstancedModel getRopeModel() { - return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState()); - } + protected abstract InstancedModel getRopeModel(); - protected InstancedModel getMagnetModel() { - return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState()); - } + protected abstract InstancedModel getMagnetModel(); - protected InstancedModel getHalfMagnetModel() { - return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState); - } + protected abstract InstancedModel getHalfMagnetModel(); - protected InstancedModel getCoilModel() { - return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout); - } + protected abstract InstancedModel getCoilModel(); - protected InstancedModel getHalfRopeModel() { - return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF, blockState); - } + protected abstract InstancedModel getHalfRopeModel(); - protected float getOffset() { - float partialTicks = AnimationTickHolder.getPartialTicks(); - return PulleyRenderer.getTileOffset(partialTicks, tile); - } + protected abstract float getOffset(); - protected boolean isRunning() { - return tile.running || tile.isVirtual(); - } + protected abstract boolean isRunning(); protected void resizeRope() { int neededRopeCount = getNeededRopeCount(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java new file mode 100644 index 000000000..8003596b2 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java @@ -0,0 +1,45 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.pulley; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.content.contraptions.fluids.actors.HosePulleyTileEntity; +import com.simibubi.create.foundation.render.backend.core.OrientedData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.utility.AnimationTickHolder; + +public class HosePulleyInstance extends AbstractPulleyInstance { + final HosePulleyTileEntity tile = (HosePulleyTileEntity) super.tile; + + public HosePulleyInstance(InstancedTileRenderer dispatcher, HosePulleyTileEntity tile) { + super(dispatcher, tile); + beginFrame(); + } + + protected InstancedModel getRopeModel() { + return getOrientedMaterial().getModel(AllBlockPartials.HOSE, blockState); + } + + protected InstancedModel getMagnetModel() { + return getOrientedMaterial().getModel(AllBlockPartials.HOSE_MAGNET, blockState); + } + + protected InstancedModel getHalfMagnetModel() { + return getOrientedMaterial().getModel(AllBlockPartials.HOSE_HALF_MAGNET, blockState); + } + + protected InstancedModel getCoilModel() { + return AllBlockPartials.HOSE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout); + } + + protected InstancedModel getHalfRopeModel() { + return getOrientedMaterial().getModel(AllBlockPartials.HOSE_HALF, blockState); + } + + protected float getOffset() { + return tile.getInterpolatedOffset(AnimationTickHolder.getPartialTicks()); + } + + protected boolean isRunning() { + return true; + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java new file mode 100644 index 000000000..9bceb011b --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java @@ -0,0 +1,49 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.pulley; + +import net.minecraft.world.ILightReader; + +import com.simibubi.create.AllBlockPartials; +import com.simibubi.create.AllBlocks; +import com.simibubi.create.content.contraptions.base.KineticTileEntity; +import com.simibubi.create.foundation.render.backend.core.OrientedData; +import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; +import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer; +import com.simibubi.create.foundation.utility.AnimationTickHolder; + +public class RopePulleyInstance extends AbstractPulleyInstance { + final PulleyTileEntity tile = (PulleyTileEntity) super.tile; + + public RopePulleyInstance(InstancedTileRenderer dispatcher, PulleyTileEntity tile) { + super(dispatcher, tile); + beginFrame(); + } + + protected InstancedModel getRopeModel() { + return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState()); + } + + protected InstancedModel getMagnetModel() { + return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState()); + } + + protected InstancedModel getHalfMagnetModel() { + return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState); + } + + protected InstancedModel getCoilModel() { + return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout); + } + + protected InstancedModel getHalfRopeModel() { + return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF, blockState); + } + + protected float getOffset() { + float partialTicks = AnimationTickHolder.getPartialTicks(); + return PulleyRenderer.getTileOffset(partialTicks, tile); + } + + protected boolean isRunning() { + return tile.running || tile.isVirtual(); + } +}