mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +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;
|
||||
|
||||
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<HosePulleyTileEntity> 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<PulleyTileEntity> ROPE_PULLEY = Create.registrate()
|
||||
.tileEntity("rope_pulley", PulleyTileEntity::new)
|
||||
.instance(() -> PulleyInstance::new)
|
||||
.instance(() -> RopePulleyInstance::new)
|
||||
.validBlocks(AllBlocks.ROPE_PULLEY)
|
||||
.renderer(() -> PulleyRenderer::new)
|
||||
.register();
|
||||
|
|
|
@ -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<OrientedData> magnet;
|
||||
final InstanceGroup<OrientedData> rope;
|
||||
final ConditionalInstance<OrientedData> 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<OrientedData> getRopeModel() {
|
||||
return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState());
|
||||
}
|
||||
protected abstract InstancedModel<OrientedData> getRopeModel();
|
||||
|
||||
protected InstancedModel<OrientedData> getMagnetModel() {
|
||||
return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState());
|
||||
}
|
||||
protected abstract InstancedModel<OrientedData> getMagnetModel();
|
||||
|
||||
protected InstancedModel<OrientedData> getHalfMagnetModel() {
|
||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState);
|
||||
}
|
||||
protected abstract InstancedModel<OrientedData> getHalfMagnetModel();
|
||||
|
||||
protected InstancedModel<OrientedData> getCoilModel() {
|
||||
return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout);
|
||||
}
|
||||
protected abstract InstancedModel<OrientedData> getCoilModel();
|
||||
|
||||
protected InstancedModel<OrientedData> getHalfRopeModel() {
|
||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF, blockState);
|
||||
}
|
||||
protected abstract InstancedModel<OrientedData> 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();
|
|
@ -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