mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Instanced rope pulleys
- The "magnet" texture is broken
This commit is contained in:
parent
4b49763e0c
commit
f2b064fa49
4 changed files with 116 additions and 40 deletions
|
@ -1,6 +1,5 @@
|
||||||
package com.simibubi.create;
|
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.HalfShaftInstance;
|
||||||
import com.simibubi.create.content.contraptions.base.HorizontalHalfShaftInstance;
|
import com.simibubi.create.content.contraptions.base.HorizontalHalfShaftInstance;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
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.mounted.CartAssemblerTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonRenderer;
|
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.piston.MechanicalPistonTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyInstance;
|
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.*;
|
||||||
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.turntable.TurntableTileEntity;
|
import com.simibubi.create.content.contraptions.components.turntable.TurntableTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.waterwheel.WaterWheelTileEntity;
|
import com.simibubi.create.content.contraptions.components.waterwheel.WaterWheelTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.fluids.PumpCogInstance;
|
import com.simibubi.create.content.contraptions.fluids.PumpCogInstance;
|
||||||
|
@ -312,7 +309,7 @@ public class AllTileEntities {
|
||||||
|
|
||||||
public static final TileEntityEntry<HosePulleyTileEntity> HOSE_PULLEY = Create.registrate()
|
public static final TileEntityEntry<HosePulleyTileEntity> HOSE_PULLEY = Create.registrate()
|
||||||
.tileEntity("hose_pulley", HosePulleyTileEntity::new)
|
.tileEntity("hose_pulley", HosePulleyTileEntity::new)
|
||||||
.instance(() -> ShaftInstance::new)
|
.instance(() -> HosePulleyInstance::new)
|
||||||
.validBlocks(AllBlocks.HOSE_PULLEY)
|
.validBlocks(AllBlocks.HOSE_PULLEY)
|
||||||
.renderer(() -> HosePulleyRenderer::new)
|
.renderer(() -> HosePulleyRenderer::new)
|
||||||
.register();
|
.register();
|
||||||
|
@ -399,7 +396,7 @@ public class AllTileEntities {
|
||||||
|
|
||||||
public static final TileEntityEntry<PulleyTileEntity> ROPE_PULLEY = Create.registrate()
|
public static final TileEntityEntry<PulleyTileEntity> ROPE_PULLEY = Create.registrate()
|
||||||
.tileEntity("rope_pulley", PulleyTileEntity::new)
|
.tileEntity("rope_pulley", PulleyTileEntity::new)
|
||||||
.instance(() -> PulleyInstance::new)
|
.instance(() -> RopePulleyInstance::new)
|
||||||
.validBlocks(AllBlocks.ROPE_PULLEY)
|
.validBlocks(AllBlocks.ROPE_PULLEY)
|
||||||
.renderer(() -> PulleyRenderer::new)
|
.renderer(() -> PulleyRenderer::new)
|
||||||
.register();
|
.register();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.world.LightType;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import com.simibubi.create.AllBlockPartials;
|
import com.simibubi.create.AllBlockPartials;
|
||||||
import com.simibubi.create.AllBlocks;
|
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.content.contraptions.relays.encased.ShaftInstance;
|
||||||
import com.simibubi.create.foundation.render.backend.core.OrientedData;
|
import com.simibubi.create.foundation.render.backend.core.OrientedData;
|
||||||
import com.simibubi.create.foundation.render.backend.instancing.*;
|
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.render.backend.light.LightUpdater;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
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 OrientedData coil;
|
||||||
final SelectInstance<OrientedData> magnet;
|
final SelectInstance<OrientedData> magnet;
|
||||||
final InstanceGroup<OrientedData> rope;
|
final InstanceGroup<OrientedData> rope;
|
||||||
final ConditionalInstance<OrientedData> halfRope;
|
final ConditionalInstance<OrientedData> halfRope;
|
||||||
|
|
||||||
private float offset;
|
protected float offset;
|
||||||
private final Direction rotatingAbout;
|
protected final Direction rotatingAbout;
|
||||||
private final Vector3f rotationAxis;
|
protected final Vector3f rotationAxis;
|
||||||
|
|
||||||
private byte[] bLight = new byte[1];
|
private byte[] bLight = new byte[1];
|
||||||
private byte[] sLight = new byte[1];
|
private byte[] sLight = new byte[1];
|
||||||
private GridAlignedBB volume;
|
private GridAlignedBB volume;
|
||||||
|
|
||||||
public PulleyInstance(InstancedTileRenderer<?> dispatcher, PulleyTileEntity tile) {
|
public AbstractPulleyInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
|
|
||||||
rotatingAbout = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis);
|
rotatingAbout = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis);
|
||||||
rotationAxis = rotatingAbout.getUnitVector();
|
rotationAxis = rotatingAbout.getUnitVector();
|
||||||
updateOffset();
|
|
||||||
|
|
||||||
coil = getCoilModel()
|
coil = getCoilModel()
|
||||||
.createInstance()
|
.createInstance()
|
||||||
|
@ -53,17 +52,19 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L
|
||||||
.addModel(getHalfMagnetModel());
|
.addModel(getHalfMagnetModel());
|
||||||
|
|
||||||
rope = new InstanceGroup<>(getRopeModel());
|
rope = new InstanceGroup<>(getRopeModel());
|
||||||
resizeRope();
|
|
||||||
|
|
||||||
halfRope = new ConditionalInstance<>(getHalfRopeModel(), this::shouldRenderHalfRope);
|
halfRope = new ConditionalInstance<>(getHalfRopeModel(), this::shouldRenderHalfRope);
|
||||||
|
|
||||||
beginFrame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame() {
|
public void beginFrame() {
|
||||||
updateOffset();
|
updateOffset();
|
||||||
|
|
||||||
|
transformModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transformModels() {
|
||||||
|
resizeRope();
|
||||||
|
|
||||||
coil.setRotation(rotationAxis.getDegreesQuaternion(offset * 180));
|
coil.setRotation(rotationAxis.getDegreesQuaternion(offset * 180));
|
||||||
magnet.update().get().ifPresent(data ->
|
magnet.update().get().ifPresent(data ->
|
||||||
{
|
{
|
||||||
|
@ -85,7 +86,6 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L
|
||||||
.setSkyLight(sLight[0]);
|
.setSkyLight(sLight[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
resizeRope();
|
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
int size = rope.size();
|
int size = rope.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
@ -115,34 +115,19 @@ public class PulleyInstance extends ShaftInstance implements IDynamicInstance, L
|
||||||
halfRope.delete();
|
halfRope.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InstancedModel<OrientedData> getRopeModel() {
|
protected abstract InstancedModel<OrientedData> getRopeModel();
|
||||||
return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InstancedModel<OrientedData> getMagnetModel() {
|
protected abstract InstancedModel<OrientedData> getMagnetModel();
|
||||||
return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InstancedModel<OrientedData> getHalfMagnetModel() {
|
protected abstract InstancedModel<OrientedData> getHalfMagnetModel();
|
||||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InstancedModel<OrientedData> getCoilModel() {
|
protected abstract InstancedModel<OrientedData> getCoilModel();
|
||||||
return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected InstancedModel<OrientedData> getHalfRopeModel() {
|
protected abstract InstancedModel<OrientedData> getHalfRopeModel();
|
||||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF, blockState);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float getOffset() {
|
protected abstract float getOffset();
|
||||||
float partialTicks = AnimationTickHolder.getPartialTicks();
|
|
||||||
return PulleyRenderer.getTileOffset(partialTicks, tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isRunning() {
|
protected abstract boolean isRunning();
|
||||||
return tile.running || tile.isVirtual();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void resizeRope() {
|
protected void resizeRope() {
|
||||||
int neededRopeCount = getNeededRopeCount();
|
int neededRopeCount = getNeededRopeCount();
|
|
@ -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<OrientedData> getRopeModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlockPartials.HOSE, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getMagnetModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlockPartials.HOSE_MAGNET, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getHalfMagnetModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlockPartials.HOSE_HALF_MAGNET, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getCoilModel() {
|
||||||
|
return AllBlockPartials.HOSE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getHalfRopeModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlockPartials.HOSE_HALF, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float getOffset() {
|
||||||
|
return tile.getInterpolatedOffset(AnimationTickHolder.getPartialTicks());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isRunning() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<OrientedData> getRopeModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getMagnetModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getHalfMagnetModel() {
|
||||||
|
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> getCoilModel() {
|
||||||
|
return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstancedModel<OrientedData> 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue