mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Refactor away TileEntityInstance#init
- Move it to the constructor. - An instance is now discarded and recreated if TileEntityInstance#shouldReset return true. - Mark a bunch of stuff final.
This commit is contained in:
parent
a356f8a91a
commit
6a0ad77fe7
25 changed files with 155 additions and 246 deletions
|
@ -17,13 +17,24 @@ public abstract class KineticTileInstance<T extends KineticTileEntity> extends T
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void updateRotation(InstanceKey<RotatingData> key, Direction.Axis axis) {
|
protected final void updateRotation(InstanceKey<RotatingData> key, Direction.Axis axis) {
|
||||||
key.getInstance()
|
updateRotation(key, axis, tile.getSpeed());
|
||||||
.setColor(tile.network)
|
}
|
||||||
.setRotationalSpeed(tile.getSpeed())
|
|
||||||
|
protected final void updateRotation(InstanceKey<RotatingData> key, Direction.Axis axis, float speed) {
|
||||||
|
updateRotation(key.getInstance(), axis, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void updateRotation(RotatingData key, Direction.Axis axis, float speed) {
|
||||||
|
key.setColor(tile.network)
|
||||||
|
.setRotationalSpeed(speed)
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
.setRotationAxis(axis);
|
.setRotationAxis(axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final void updateRotation(RotatingData key, Direction.Axis axis) {
|
||||||
|
updateRotation(key, axis, tile.getSpeed());
|
||||||
|
}
|
||||||
|
|
||||||
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, float speed, Direction.Axis axis) {
|
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, float speed, Direction.Axis axis) {
|
||||||
key.getInstance()
|
key.getInstance()
|
||||||
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
|
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
|
||||||
|
|
|
@ -11,20 +11,17 @@ import net.minecraft.util.Direction;
|
||||||
|
|
||||||
public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntity> {
|
public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntity> {
|
||||||
|
|
||||||
protected InstanceKey<RotatingData> rotatingModelKey;
|
protected final InstanceKey<RotatingData> rotatingModelKey;
|
||||||
|
|
||||||
public SingleRotatingInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
public SingleRotatingInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||||
rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
|
rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void update() {
|
||||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||||
updateRotation(rotatingModelKey, axis);
|
updateRotation(rotatingModelKey, axis);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,6 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami
|
||||||
|
|
||||||
public HandCrankInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
public HandCrankInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
AllBlockPartials renderedHandle = null;
|
AllBlockPartials renderedHandle = null;
|
||||||
|
|
|
@ -18,28 +18,21 @@ import static com.simibubi.create.content.contraptions.base.DirectionalKineticBl
|
||||||
|
|
||||||
public class DeployerInstance extends ShaftInstance implements IDynamicInstance {
|
public class DeployerInstance extends ShaftInstance implements IDynamicInstance {
|
||||||
|
|
||||||
DeployerTileEntity tile;
|
final DeployerTileEntity tile;
|
||||||
|
final Direction facing;
|
||||||
|
final float yRot;
|
||||||
|
final float zRot;
|
||||||
|
final float zRotPole;
|
||||||
|
|
||||||
Direction facing;
|
protected final InstanceKey<ModelData> pole;
|
||||||
|
|
||||||
InstanceKey<ModelData> pole;
|
protected InstanceKey<ModelData> hand;
|
||||||
|
|
||||||
AllBlockPartials currentHand;
|
AllBlockPartials currentHand;
|
||||||
InstanceKey<ModelData> hand;
|
|
||||||
|
|
||||||
float yRot;
|
|
||||||
float zRot;
|
|
||||||
float zRotPole;
|
|
||||||
|
|
||||||
float progress = Float.NaN;
|
float progress = Float.NaN;
|
||||||
|
|
||||||
public DeployerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
public DeployerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
this.tile = (DeployerTileEntity) super.tile;
|
this.tile = (DeployerTileEntity) super.tile;
|
||||||
facing = blockState.get(FACING);
|
facing = blockState.get(FACING);
|
||||||
|
|
|
@ -10,43 +10,29 @@ 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.InstancedModel;
|
||||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.Vector3f;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
||||||
|
|
||||||
protected InstanceKey<RotatingData> shaft;
|
protected final InstanceKey<RotatingData> shaft;
|
||||||
protected InstanceKey<RotatingData> fan;
|
protected final InstanceKey<RotatingData> fan;
|
||||||
|
final Direction.Axis axis;
|
||||||
|
final Direction direction;
|
||||||
|
|
||||||
public FanInstance(InstancedTileRenderer<?> modelManager, EncasedFanTileEntity tile) {
|
public FanInstance(InstancedTileRenderer<?> modelManager, EncasedFanTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
direction = blockState.get(FACING);
|
||||||
protected void init() {
|
axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||||
final Direction direction = blockState.get(FACING);
|
|
||||||
final Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
|
||||||
|
|
||||||
InstancedModel<RotatingData> shaftHalf =
|
shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||||
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
|
fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||||
InstancedModel<RotatingData> fanInner =
|
|
||||||
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
|
|
||||||
|
|
||||||
shaft = shaftHalf.createInstance();
|
updateRotation(shaft.getInstance().setTileEntity(tile), axis);
|
||||||
shaft.getInstance()
|
updateRotation(fan.getInstance().setTileEntity(tile), axis, getFanSpeed());
|
||||||
.setRotationalSpeed(tile.getSpeed())
|
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
|
||||||
.setTileEntity(tile);
|
|
||||||
|
|
||||||
|
|
||||||
fan = fanInner.createInstance();
|
|
||||||
fan.getInstance()
|
|
||||||
.setRotationalSpeed(getFanSpeed())
|
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
|
||||||
.setTileEntity(tile);
|
|
||||||
|
|
||||||
updateLight();
|
updateLight();
|
||||||
}
|
}
|
||||||
|
@ -61,21 +47,13 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUpdate() {
|
protected void update() {
|
||||||
Direction.Axis axis = blockState.get(FACING).getAxis();
|
|
||||||
updateRotation(shaft, axis);
|
updateRotation(shaft, axis);
|
||||||
|
updateRotation(fan, axis, getFanSpeed());
|
||||||
fan.getInstance()
|
|
||||||
.setColor(tile.network)
|
|
||||||
.setRotationalSpeed(getFanSpeed())
|
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLight() {
|
public void updateLight() {
|
||||||
final Direction direction = blockState.get(FACING);
|
|
||||||
|
|
||||||
BlockPos behind = pos.offset(direction.getOpposite());
|
BlockPos behind = pos.offset(direction.getOpposite());
|
||||||
relight(behind, shaft.getInstance());
|
relight(behind, shaft.getInstance());
|
||||||
|
|
||||||
|
|
|
@ -23,21 +23,22 @@ import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements IDynamicInstance {
|
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
protected Direction facing;
|
protected final Direction facing;
|
||||||
|
protected final Direction connection;
|
||||||
|
|
||||||
protected boolean connectedLeft;
|
protected boolean connectedLeft;
|
||||||
protected float connectorAngleMult;
|
protected float connectorAngleMult;
|
||||||
|
|
||||||
protected Direction connection;
|
protected final InstanceKey<RotatingData> shaft;
|
||||||
|
|
||||||
protected InstanceKey<RotatingData> shaft;
|
protected final InstanceKey<ModelData> wheel;
|
||||||
|
|
||||||
protected InstanceKey<ModelData> wheel;
|
protected List<InstanceKey<ModelData>> connectors;
|
||||||
protected InstanceKey<ModelData> upperRotating;
|
protected InstanceKey<ModelData> upperRotating;
|
||||||
protected InstanceKey<ModelData> lowerRotating;
|
protected InstanceKey<ModelData> lowerRotating;
|
||||||
protected InstanceKey<ModelData> upperSliding;
|
protected InstanceKey<ModelData> upperSliding;
|
||||||
protected InstanceKey<ModelData> lowerSliding;
|
protected InstanceKey<ModelData> lowerSliding;
|
||||||
|
|
||||||
protected List<InstanceKey<ModelData>> connectors;
|
|
||||||
|
|
||||||
protected float lastAngle = Float.NaN;
|
protected float lastAngle = Float.NaN;
|
||||||
|
|
||||||
|
@ -45,10 +46,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
||||||
|
|
||||||
public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) {
|
public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
|
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
|
||||||
|
|
||||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||||
|
@ -77,7 +75,6 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLight();
|
updateLight();
|
||||||
firstFrame = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,7 +132,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUpdate() {
|
protected void update() {
|
||||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||||
updateRotation(shaft, axis);
|
updateRotation(shaft, axis);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,9 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
|
||||||
|
|
||||||
public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) {
|
public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
Block block = blockState
|
Block block = blockState
|
||||||
.getBlock();
|
.getBlock();
|
||||||
if (!(block instanceof EngineBlock))
|
if (!(block instanceof EngineBlock))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,11 @@ import net.minecraft.util.Direction;
|
||||||
|
|
||||||
public class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance {
|
public class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance {
|
||||||
|
|
||||||
private InstanceKey<RotatingData> mixerHead;
|
private final InstanceKey<RotatingData> mixerHead;
|
||||||
private InstanceKey<ModelData> mixerPole;
|
private final InstanceKey<ModelData> mixerPole;
|
||||||
|
|
||||||
public MixerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
public MixerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
|
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
|
||||||
.createInstance();
|
.createInstance();
|
||||||
|
|
|
@ -14,15 +14,10 @@ import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||||
|
|
||||||
public class PressInstance extends ShaftInstance implements IDynamicInstance {
|
public class PressInstance extends ShaftInstance implements IDynamicInstance {
|
||||||
|
|
||||||
private InstanceKey<ModelData> pressHead;
|
private final InstanceKey<ModelData> pressHead;
|
||||||
|
|
||||||
public PressInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
public PressInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
pressHead = modelManager.getMaterial(RenderMaterials.MODELS)
|
pressHead = modelManager.getMaterial(RenderMaterials.MODELS)
|
||||||
.getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState)
|
.getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState)
|
||||||
|
|
|
@ -10,37 +10,39 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class StickerInstance extends TileEntityInstance<StickerTileEntity> implements IDynamicInstance {
|
public class StickerInstance extends TileEntityInstance<StickerTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
float lastOffset = Float.NaN;
|
float lastOffset = Float.NaN;
|
||||||
|
final Direction facing;
|
||||||
|
final boolean fakeWorld;
|
||||||
|
final int offset;
|
||||||
|
|
||||||
private InstanceKey<ModelData> head;
|
private final InstanceKey<ModelData> head;
|
||||||
|
|
||||||
public StickerInstance(InstancedTileRenderer<?> modelManager, StickerTileEntity tile) {
|
public StickerInstance(InstancedTileRenderer<?> modelManager, StickerTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance();
|
head = modelManager.getMaterial(RenderMaterials.MODELS).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();
|
updateLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame() {
|
public void beginFrame() {
|
||||||
blockState = world.getBlockState(pos);
|
|
||||||
|
|
||||||
float offset = tile.piston.getValue(AnimationTickHolder.getPartialTicks());
|
float offset = tile.piston.getValue(AnimationTickHolder.getPartialTicks());
|
||||||
|
|
||||||
if (tile.getWorld() != Minecraft.getInstance().world)
|
if (fakeWorld)
|
||||||
offset = blockState.get(StickerBlock.EXTENDED) ? 1 : 0;
|
offset = this.offset;
|
||||||
|
|
||||||
if (Math.abs(offset - lastOffset) < 1e-4)
|
if (MathHelper.epsilonEquals(offset, lastOffset))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Direction facing = blockState.get(StickerBlock.FACING);
|
|
||||||
MatrixStack stack = new MatrixStack();
|
MatrixStack stack = new MatrixStack();
|
||||||
MatrixStacker.of(stack)
|
MatrixStacker.of(stack)
|
||||||
.translate(getFloatingPos())
|
.translate(getFloatingPos())
|
||||||
|
|
|
@ -19,32 +19,33 @@ import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
public class GantryCarriageInstance extends ShaftInstance implements IDynamicInstance {
|
public class GantryCarriageInstance extends ShaftInstance implements IDynamicInstance {
|
||||||
|
|
||||||
private InstanceKey<ModelData> gantryCogs;
|
private final InstanceKey<ModelData> gantryCogs;
|
||||||
|
|
||||||
|
final Direction facing;
|
||||||
|
final Boolean alongFirst;
|
||||||
|
final Direction.Axis rotationAxis;
|
||||||
|
final BlockPos visualPos;
|
||||||
|
|
||||||
public GantryCarriageInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
public GantryCarriageInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS)
|
gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS)
|
||||||
.getModel(AllBlockPartials.GANTRY_COGS, blockState)
|
.getModel(AllBlockPartials.GANTRY_COGS, blockState)
|
||||||
.createInstance();
|
.createInstance();
|
||||||
|
|
||||||
|
facing = blockState.get(GantryCarriageBlock.FACING);
|
||||||
|
alongFirst = blockState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
|
||||||
|
rotationAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
|
||||||
|
|
||||||
|
visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos()
|
||||||
|
: tile.getPos()
|
||||||
|
.offset(facing.getOpposite());
|
||||||
|
|
||||||
updateLight();
|
updateLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beginFrame() {
|
public void beginFrame() {
|
||||||
blockState = tile.getBlockState();
|
|
||||||
Direction facing = blockState.get(GantryCarriageBlock.FACING);
|
|
||||||
Boolean alongFirst = blockState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
|
|
||||||
Direction.Axis rotationAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
|
|
||||||
BlockPos visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos()
|
|
||||||
: tile.getPos()
|
|
||||||
.offset(facing.getOpposite());
|
|
||||||
float angleForTe = GantryCarriageRenderer.getAngleForTe(tile, visualPos, rotationAxis);
|
float angleForTe = GantryCarriageRenderer.getAngleForTe(tile, visualPos, rotationAxis);
|
||||||
|
|
||||||
Direction.Axis gantryAxis = Direction.Axis.X;
|
Direction.Axis gantryAxis = Direction.Axis.X;
|
||||||
|
|
|
@ -19,17 +19,12 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc
|
||||||
|
|
||||||
protected InstanceKey<ModelData> pointer;
|
protected InstanceKey<ModelData> pointer;
|
||||||
|
|
||||||
protected double xRot;
|
protected final double xRot;
|
||||||
protected double yRot;
|
protected final double yRot;
|
||||||
protected int pointerRotationOffset;
|
protected final int pointerRotationOffset;
|
||||||
|
|
||||||
public FluidValveInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
public FluidValveInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
Direction facing = blockState.get(FluidValveBlock.FACING);
|
Direction facing = blockState.get(FluidValveBlock.FACING);
|
||||||
|
|
||||||
|
@ -39,9 +34,8 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc
|
||||||
Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(blockState);
|
Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(blockState);
|
||||||
Direction.Axis shaftAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
|
Direction.Axis shaftAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
|
||||||
|
|
||||||
pointerRotationOffset = 0;
|
boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical();
|
||||||
if (pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical())
|
pointerRotationOffset = twist ? 90 : 0;
|
||||||
pointerRotationOffset = 90;
|
|
||||||
|
|
||||||
pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance();
|
pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance();
|
||||||
|
|
||||||
|
|
|
@ -22,23 +22,20 @@ import net.minecraft.world.LightType;
|
||||||
|
|
||||||
public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
|
public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
|
||||||
|
|
||||||
private boolean upward;
|
boolean upward;
|
||||||
private boolean diagonal;
|
boolean diagonal;
|
||||||
private boolean sideways;
|
boolean sideways;
|
||||||
private boolean vertical;
|
boolean vertical;
|
||||||
private boolean alongX;
|
boolean alongX;
|
||||||
private boolean alongZ;
|
boolean alongZ;
|
||||||
private BeltSlope beltSlope;
|
BeltSlope beltSlope;
|
||||||
private Direction facing;
|
Direction facing;
|
||||||
protected ArrayList<InstanceKey<BeltData>> keys;
|
protected ArrayList<InstanceKey<BeltData>> keys;
|
||||||
protected InstanceKey<RotatingData> pulleyKey;
|
protected InstanceKey<RotatingData> pulleyKey;
|
||||||
|
|
||||||
public BeltInstance(InstancedTileRenderer<?> modelManager, BeltTileEntity tile) {
|
public BeltInstance(InstancedTileRenderer<?> modelManager, BeltTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
if (!AllBlocks.BELT.has(blockState))
|
if (!AllBlocks.BELT.has(blockState))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -77,7 +74,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void update() {
|
||||||
DyeColor color = tile.color.orElse(null);
|
DyeColor color = tile.color.orElse(null);
|
||||||
|
|
||||||
boolean bottom = true;
|
boolean bottom = true;
|
||||||
|
|
|
@ -17,14 +17,11 @@ import net.minecraft.util.Direction;
|
||||||
|
|
||||||
public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity> {
|
public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity> {
|
||||||
|
|
||||||
protected ArrayList<InstanceKey<RotatingData>> keys;
|
protected final ArrayList<InstanceKey<RotatingData>> keys;
|
||||||
|
|
||||||
public SplitShaftInstance(InstancedTileRenderer<?> modelManager, SplitShaftTileEntity tile) {
|
public SplitShaftInstance(InstancedTileRenderer<?> modelManager, SplitShaftTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
keys = new ArrayList<>(2);
|
keys = new ArrayList<>(2);
|
||||||
|
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
|
@ -43,7 +40,7 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void update() {
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
|
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,12 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public abstract class GaugeInstance extends ShaftInstance implements IDynamicInstance {
|
public abstract class GaugeInstance extends ShaftInstance implements IDynamicInstance {
|
||||||
|
|
||||||
protected ArrayList<DialFace> faces;
|
protected final ArrayList<DialFace> faces;
|
||||||
|
|
||||||
protected MatrixStack ms;
|
protected MatrixStack ms;
|
||||||
|
|
||||||
protected GaugeInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
protected GaugeInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||||
super(dispatcher, tile);
|
super(dispatcher, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
faces = new ArrayList<>(2);
|
faces = new ArrayList<>(2);
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,12 @@ import net.minecraft.world.LightType;
|
||||||
|
|
||||||
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||||
|
|
||||||
protected EnumMap<Direction, InstanceKey<RotatingData>> keys;
|
protected final EnumMap<Direction, InstanceKey<RotatingData>> keys;
|
||||||
protected Direction sourceFacing;
|
protected Direction sourceFacing;
|
||||||
|
|
||||||
public GearboxInstance(InstancedTileRenderer<?> modelManager, GearboxTileEntity tile) {
|
public GearboxInstance(InstancedTileRenderer<?> modelManager, GearboxTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
keys = new EnumMap<>(Direction.class);
|
keys = new EnumMap<>(Direction.class);
|
||||||
|
|
||||||
final Direction.Axis boxAxis = blockState.get(BlockStateProperties.AXIS);
|
final Direction.Axis boxAxis = blockState.get(BlockStateProperties.AXIS);
|
||||||
|
@ -78,7 +75,7 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void update() {
|
||||||
updateSourceFacing();
|
updateSourceFacing();
|
||||||
for (Map.Entry<Direction, InstanceKey<RotatingData>> key : keys.entrySet()) {
|
for (Map.Entry<Direction, InstanceKey<RotatingData>> key : keys.entrySet()) {
|
||||||
Direction direction = key.getKey();
|
Direction direction = key.getKey();
|
||||||
|
|
|
@ -3,12 +3,13 @@ package com.simibubi.create.content.logistics.block;
|
||||||
import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat;
|
import com.simibubi.create.foundation.render.backend.gl.attrib.VertexFormat;
|
||||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||||
|
import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight;
|
||||||
import net.minecraft.client.renderer.Vector3f;
|
import net.minecraft.client.renderer.Vector3f;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class FlapData extends InstanceData {
|
public class FlapData extends InstanceData implements IFlatLight<FlapData> {
|
||||||
|
|
||||||
public static VertexFormat FORMAT = VertexFormat.builder()
|
public static VertexFormat FORMAT = VertexFormat.builder()
|
||||||
.addAttributes(FlapVertexAttributes.class)
|
.addAttributes(FlapVertexAttributes.class)
|
||||||
|
@ -61,11 +62,13 @@ public class FlapData extends InstanceData {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public FlapData setBlockLight(int blockLight) {
|
public FlapData setBlockLight(int blockLight) {
|
||||||
this.blockLight = (byte) ((blockLight & 0xF) << 4);
|
this.blockLight = (byte) ((blockLight & 0xF) << 4);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public FlapData setSkyLight(int skyLight) {
|
public FlapData setSkyLight(int skyLight) {
|
||||||
this.skyLight = (byte) ((skyLight & 0xF) << 4);
|
this.skyLight = (byte) ((skyLight & 0xF) << 4);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -16,15 +16,11 @@ import java.util.Map;
|
||||||
|
|
||||||
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements IDynamicInstance {
|
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
|
private final Map<Direction, ArrayList<InstanceKey<FlapData>>> tunnelFlaps;
|
||||||
private Map<Direction, ArrayList<InstanceKey<FlapData>>> tunnelFlaps;
|
|
||||||
|
|
||||||
public BeltTunnelInstance(InstancedTileRenderer<?> modelManager, BeltTunnelTileEntity tile) {
|
public BeltTunnelInstance(InstancedTileRenderer<?> modelManager, BeltTunnelTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
tunnelFlaps = new EnumMap<>(Direction.class);
|
tunnelFlaps = new EnumMap<>(Direction.class);
|
||||||
|
|
||||||
InstancedModel<FlapData> model = modelManager.getMaterial(KineticRenderMaterials.FLAPS)
|
InstancedModel<FlapData> model = modelManager.getMaterial(KineticRenderMaterials.FLAPS)
|
||||||
|
@ -82,9 +78,6 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onUpdate() { }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLight() {
|
public void updateLight() {
|
||||||
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
|
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
|
||||||
|
|
|
@ -9,16 +9,13 @@ import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||||
|
|
||||||
public class AdjustableRepeaterInstance extends TileEntityInstance<AdjustableRepeaterTileEntity> implements ITickableInstance {
|
public class AdjustableRepeaterInstance extends TileEntityInstance<AdjustableRepeaterTileEntity> implements ITickableInstance {
|
||||||
|
|
||||||
protected InstanceKey<ModelData> indicator;
|
protected final InstanceKey<ModelData> indicator;
|
||||||
|
|
||||||
protected int previousState;
|
protected int previousState;
|
||||||
|
|
||||||
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
|
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
|
indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
|
||||||
|
|
||||||
MatrixStack ms = new MatrixStack();
|
MatrixStack ms = new MatrixStack();
|
||||||
|
|
|
@ -12,14 +12,11 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> implements IDynamicInstance {
|
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
private ArrayList<InstanceKey<FlapData>> flaps;
|
private final ArrayList<InstanceKey<FlapData>> flaps;
|
||||||
|
|
||||||
public FunnelInstance(InstancedTileRenderer<?> modelManager, FunnelTileEntity tile) {
|
public FunnelInstance(InstancedTileRenderer<?> modelManager, FunnelTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
flaps = new ArrayList<>(4);
|
flaps = new ArrayList<>(4);
|
||||||
|
|
||||||
if (!tile.hasFlap()) return;
|
if (!tile.hasFlap()) return;
|
||||||
|
@ -71,16 +68,8 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLight() {
|
public void updateLight() {
|
||||||
if (flaps == null) return;
|
if (flaps != null)
|
||||||
|
relight(pos, flaps.stream().map(InstanceKey::getInstance));
|
||||||
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
|
|
||||||
int skyLight = world.getLightLevel(LightType.SKY, pos);
|
|
||||||
|
|
||||||
for (InstanceKey<FlapData> it : flaps) {
|
|
||||||
it.getInstance()
|
|
||||||
.setBlockLight(blockLight)
|
|
||||||
.setSkyLight(skyLight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,24 +24,19 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance {
|
public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance {
|
||||||
|
|
||||||
private InstanceKey<ModelData> base;
|
final InstanceKey<ModelData> base;
|
||||||
private InstanceKey<ModelData> lowerBody;
|
final InstanceKey<ModelData> lowerBody;
|
||||||
private InstanceKey<ModelData> upperBody;
|
final InstanceKey<ModelData> upperBody;
|
||||||
private InstanceKey<ModelData> head;
|
final InstanceKey<ModelData> head;
|
||||||
private InstanceKey<ModelData> claw;
|
final InstanceKey<ModelData> claw;
|
||||||
private ArrayList<InstanceKey<ModelData>> clawGrips;
|
private final ArrayList<InstanceKey<ModelData>> clawGrips;
|
||||||
|
|
||||||
private ArrayList<InstanceKey<ModelData>> models;
|
private final ArrayList<InstanceKey<ModelData>> models;
|
||||||
|
|
||||||
private boolean firstTick = true;
|
private boolean firstTick = true;
|
||||||
|
|
||||||
public ArmInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
public ArmInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||||
|
|
||||||
|
@ -58,8 +53,6 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
|
||||||
clawGrips = Lists.newArrayList(clawGrip1, clawGrip2);
|
clawGrips = Lists.newArrayList(clawGrip1, clawGrip2);
|
||||||
models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2);
|
models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2);
|
||||||
|
|
||||||
firstTick = true;
|
|
||||||
beginFrame();
|
|
||||||
updateLight();
|
updateLight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,15 @@ import net.minecraft.util.Direction;
|
||||||
|
|
||||||
public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntity> implements IDynamicInstance {
|
public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
protected InstanceKey<ModelData> handle;
|
protected final InstanceKey<ModelData> handle;
|
||||||
protected InstanceKey<ModelData> indicator;
|
protected final InstanceKey<ModelData> indicator;
|
||||||
|
|
||||||
private float rX;
|
final float rX;
|
||||||
private float rY;
|
final float rY;
|
||||||
|
|
||||||
public AnalogLeverInstance(InstancedTileRenderer<?> modelManager, AnalogLeverTileEntity tile) {
|
public AnalogLeverInstance(InstancedTileRenderer<?> modelManager, AnalogLeverTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||||
|
|
||||||
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance();
|
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance();
|
||||||
|
|
|
@ -11,15 +11,11 @@ import net.minecraft.util.Direction;
|
||||||
|
|
||||||
public class SchematicannonInstance extends TileEntityInstance<SchematicannonTileEntity> implements IDynamicInstance {
|
public class SchematicannonInstance extends TileEntityInstance<SchematicannonTileEntity> implements IDynamicInstance {
|
||||||
|
|
||||||
private InstanceKey<ModelData> connector;
|
private final InstanceKey<ModelData> connector;
|
||||||
private InstanceKey<ModelData> pipe;
|
private final InstanceKey<ModelData> pipe;
|
||||||
|
|
||||||
public SchematicannonInstance(InstancedTileRenderer<?> modelManager, SchematicannonTileEntity tile) {
|
public SchematicannonInstance(InstancedTileRenderer<?> modelManager, SchematicannonTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init() {
|
|
||||||
|
|
||||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||||
|
|
||||||
|
|
|
@ -79,11 +79,6 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
return getMaterial(RenderMaterials.MODELS);
|
return getMaterial(RenderMaterials.MODELS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public <T extends TileEntity> TileEntityInstance<? super T> getInstance(T tile) {
|
|
||||||
return getInstance(tile, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T extends TileEntity> TileEntityInstance<? super T> getInstance(T tile, boolean create) {
|
public <T extends TileEntity> TileEntityInstance<? super T> getInstance(T tile, boolean create) {
|
||||||
|
@ -127,7 +122,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
if (!Backend.canUseInstancing()) return;
|
if (!Backend.canUseInstancing()) return;
|
||||||
|
|
||||||
if (tile instanceof IInstanceRendered) {
|
if (tile instanceof IInstanceRendered) {
|
||||||
getInstance(tile);
|
getInstance(tile, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +138,16 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
if (tile instanceof IInstanceRendered) {
|
if (tile instanceof IInstanceRendered) {
|
||||||
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
||||||
|
|
||||||
if (instance != null)
|
if (instance != null) {
|
||||||
instance.update();
|
|
||||||
|
if (instance.shouldReset()) {
|
||||||
|
removeInternal(tile, instance);
|
||||||
|
|
||||||
|
getInstance(tile, true);
|
||||||
|
} else {
|
||||||
|
instance.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,17 +155,25 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||||
if (!Backend.canUseInstancing()) return;
|
if (!Backend.canUseInstancing()) return;
|
||||||
|
|
||||||
if (tile instanceof IInstanceRendered) {
|
if (tile instanceof IInstanceRendered) {
|
||||||
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
removeInternal(tile);
|
||||||
|
|
||||||
if (instance != null) {
|
|
||||||
instance.remove();
|
|
||||||
instances.remove(tile);
|
|
||||||
dynamicInstances.remove(tile);
|
|
||||||
tickableInstances.remove(tile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends TileEntity> void removeInternal(T tile) {
|
||||||
|
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
||||||
|
|
||||||
|
if (instance != null) {
|
||||||
|
removeInternal(tile, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends TileEntity> void removeInternal(T tile, TileEntityInstance<? super T> instance) {
|
||||||
|
instance.remove();
|
||||||
|
instances.remove(tile);
|
||||||
|
dynamicInstances.remove(tile);
|
||||||
|
tickableInstances.remove(tile);
|
||||||
|
}
|
||||||
|
|
||||||
public void clean() {
|
public void clean() {
|
||||||
instances.keySet().removeIf(TileEntity::isRemoved);
|
instances.keySet().removeIf(TileEntity::isRemoved);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
||||||
protected final T tile;
|
protected final T tile;
|
||||||
protected final World world;
|
protected final World world;
|
||||||
protected final BlockPos pos;
|
protected final BlockPos pos;
|
||||||
protected BlockState blockState;
|
protected final BlockState blockState;
|
||||||
|
|
||||||
public TileEntityInstance(InstancedTileRenderer<?> modelManager, T tile) {
|
public TileEntityInstance(InstancedTileRenderer<?> modelManager, T tile) {
|
||||||
this.modelManager = modelManager;
|
this.modelManager = modelManager;
|
||||||
|
@ -24,30 +24,15 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
||||||
this.world = tile.getWorld();
|
this.world = tile.getWorld();
|
||||||
this.pos = tile.getPos();
|
this.pos = tile.getPos();
|
||||||
this.blockState = tile.getBlockState();
|
this.blockState = tile.getBlockState();
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void update() {
|
|
||||||
BlockState currentState = tile.getBlockState();
|
|
||||||
if (blockState == currentState) {
|
|
||||||
onUpdate();
|
|
||||||
} else {
|
|
||||||
remove();
|
|
||||||
blockState = currentState;
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquire all {@link InstanceKey}s and initialize any data you may need to calculate the instance properties.
|
* 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}.
|
||||||
*/
|
*/
|
||||||
protected abstract void init();
|
protected void update() { }
|
||||||
|
|
||||||
/**
|
|
||||||
* Update changed instance data using the {@link InstanceKey}s you got in {@link #init()}.
|
|
||||||
* You don't have to update light data. That should be done in {@link #updateLight()}
|
|
||||||
*/
|
|
||||||
protected void onUpdate() { }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a light update occurs in the world. If your model needs it, update light here.
|
* Called when a light update occurs in the world. If your model needs it, update light here.
|
||||||
|
@ -59,23 +44,27 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
||||||
*/
|
*/
|
||||||
public abstract void remove();
|
public abstract void remove();
|
||||||
|
|
||||||
|
public boolean shouldReset() {
|
||||||
|
return tile.getBlockState() != blockState;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockPos getFloatingPos() {
|
public BlockPos getFloatingPos() {
|
||||||
return pos.subtract(modelManager.getOriginCoordinate());
|
return pos.subtract(modelManager.getOriginCoordinate());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <L extends IFlatLight<?>> void relight(BlockPos pos, IFlatLight<?>... models) {
|
protected void relight(BlockPos pos, IFlatLight<?>... models) {
|
||||||
relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models);
|
relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <L extends IFlatLight<?>> void relight(BlockPos pos, Stream<IFlatLight<?>> models) {
|
protected void relight(BlockPos pos, Stream<IFlatLight<?>> models) {
|
||||||
relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models);
|
relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <L extends IFlatLight<?>> void relight(int block, int sky, IFlatLight<?>... models) {
|
protected void relight(int block, int sky, IFlatLight<?>... models) {
|
||||||
relight(block, sky, Arrays.stream(models));
|
relight(block, sky, Arrays.stream(models));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <L extends IFlatLight<?>> void relight(int block, int sky, Stream<IFlatLight<?>> models) {
|
protected void relight(int block, int sky, Stream<IFlatLight<?>> models) {
|
||||||
models.forEach(model -> model.setBlockLight(block).setSkyLight(sky));
|
models.forEach(model -> model.setBlockLight(block).setSkyLight(sky));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue