mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +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) {
|
||||
key.getInstance()
|
||||
.setColor(tile.network)
|
||||
.setRotationalSpeed(tile.getSpeed())
|
||||
updateRotation(key, axis, 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))
|
||||
.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) {
|
||||
key.getInstance()
|
||||
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
|
||||
|
|
|
@ -11,20 +11,17 @@ import net.minecraft.util.Direction;
|
|||
|
||||
public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntity> {
|
||||
|
||||
protected InstanceKey<RotatingData> rotatingModelKey;
|
||||
protected final InstanceKey<RotatingData> rotatingModelKey;
|
||||
|
||||
public SingleRotatingInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
public void update() {
|
||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
updateRotation(rotatingModelKey, axis);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,6 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami
|
|||
|
||||
public HandCrankInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
Block block = blockState.getBlock();
|
||||
AllBlockPartials renderedHandle = null;
|
||||
|
|
|
@ -18,28 +18,21 @@ import static com.simibubi.create.content.contraptions.base.DirectionalKineticBl
|
|||
|
||||
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;
|
||||
InstanceKey<ModelData> hand;
|
||||
|
||||
float yRot;
|
||||
float zRot;
|
||||
float zRotPole;
|
||||
|
||||
float progress = Float.NaN;
|
||||
|
||||
public DeployerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
this.tile = (DeployerTileEntity) super.tile;
|
||||
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.InstancedTileRenderer;
|
||||
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
||||
|
||||
protected InstanceKey<RotatingData> shaft;
|
||||
protected InstanceKey<RotatingData> fan;
|
||||
protected final InstanceKey<RotatingData> shaft;
|
||||
protected final InstanceKey<RotatingData> fan;
|
||||
final Direction.Axis axis;
|
||||
final Direction direction;
|
||||
|
||||
public FanInstance(InstancedTileRenderer<?> modelManager, EncasedFanTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
final Direction direction = blockState.get(FACING);
|
||||
final Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
direction = blockState.get(FACING);
|
||||
axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
|
||||
InstancedModel<RotatingData> shaftHalf =
|
||||
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
|
||||
InstancedModel<RotatingData> fanInner =
|
||||
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
|
||||
shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||
fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||
|
||||
shaft = shaftHalf.createInstance();
|
||||
shaft.getInstance()
|
||||
.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);
|
||||
updateRotation(shaft.getInstance().setTileEntity(tile), axis);
|
||||
updateRotation(fan.getInstance().setTileEntity(tile), axis, getFanSpeed());
|
||||
|
||||
updateLight();
|
||||
}
|
||||
|
@ -61,21 +47,13 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onUpdate() {
|
||||
Direction.Axis axis = blockState.get(FACING).getAxis();
|
||||
protected void update() {
|
||||
updateRotation(shaft, axis);
|
||||
|
||||
fan.getInstance()
|
||||
.setColor(tile.network)
|
||||
.setRotationalSpeed(getFanSpeed())
|
||||
.setRotationOffset(getRotationOffset(axis))
|
||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
|
||||
updateRotation(fan, axis, getFanSpeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
final Direction direction = blockState.get(FACING);
|
||||
|
||||
BlockPos behind = pos.offset(direction.getOpposite());
|
||||
relight(behind, shaft.getInstance());
|
||||
|
||||
|
|
|
@ -23,21 +23,22 @@ import net.minecraft.util.math.MathHelper;
|
|||
|
||||
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements IDynamicInstance {
|
||||
|
||||
protected Direction facing;
|
||||
protected final Direction facing;
|
||||
protected final Direction connection;
|
||||
|
||||
protected boolean connectedLeft;
|
||||
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> lowerRotating;
|
||||
protected InstanceKey<ModelData> upperSliding;
|
||||
protected InstanceKey<ModelData> lowerSliding;
|
||||
|
||||
protected List<InstanceKey<ModelData>> connectors;
|
||||
|
||||
protected float lastAngle = Float.NaN;
|
||||
|
||||
|
@ -45,10 +46,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
|||
|
||||
public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
|
||||
|
||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
|
@ -77,7 +75,6 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
|||
}
|
||||
|
||||
updateLight();
|
||||
firstFrame = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -135,7 +132,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onUpdate() {
|
||||
protected void update() {
|
||||
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
|
||||
updateRotation(shaft, axis);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,9 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
|
|||
|
||||
public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
Block block = blockState
|
||||
.getBlock();
|
||||
.getBlock();
|
||||
if (!(block instanceof EngineBlock))
|
||||
return;
|
||||
|
||||
|
|
|
@ -14,16 +14,11 @@ import net.minecraft.util.Direction;
|
|||
|
||||
public class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance {
|
||||
|
||||
private InstanceKey<RotatingData> mixerHead;
|
||||
private InstanceKey<ModelData> mixerPole;
|
||||
private final InstanceKey<RotatingData> mixerHead;
|
||||
private final InstanceKey<ModelData> mixerPole;
|
||||
|
||||
public MixerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
|
||||
.createInstance();
|
||||
|
|
|
@ -14,15 +14,10 @@ import com.simibubi.create.foundation.utility.MatrixStacker;
|
|||
|
||||
public class PressInstance extends ShaftInstance implements IDynamicInstance {
|
||||
|
||||
private InstanceKey<ModelData> pressHead;
|
||||
private final InstanceKey<ModelData> pressHead;
|
||||
|
||||
public PressInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
pressHead = modelManager.getMaterial(RenderMaterials.MODELS)
|
||||
.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 net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class StickerInstance extends TileEntityInstance<StickerTileEntity> implements IDynamicInstance {
|
||||
|
||||
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) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
blockState = world.getBlockState(pos);
|
||||
|
||||
float offset = tile.piston.getValue(AnimationTickHolder.getPartialTicks());
|
||||
|
||||
if (tile.getWorld() != Minecraft.getInstance().world)
|
||||
offset = blockState.get(StickerBlock.EXTENDED) ? 1 : 0;
|
||||
if (fakeWorld)
|
||||
offset = this.offset;
|
||||
|
||||
if (Math.abs(offset - lastOffset) < 1e-4)
|
||||
if (MathHelper.epsilonEquals(offset, lastOffset))
|
||||
return;
|
||||
|
||||
Direction facing = blockState.get(StickerBlock.FACING);
|
||||
MatrixStack stack = new MatrixStack();
|
||||
MatrixStacker.of(stack)
|
||||
.translate(getFloatingPos())
|
||||
|
|
|
@ -19,32 +19,33 @@ import net.minecraft.util.math.BlockPos;
|
|||
|
||||
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) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS)
|
||||
.getModel(AllBlockPartials.GANTRY_COGS, blockState)
|
||||
.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();
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
Direction.Axis gantryAxis = Direction.Axis.X;
|
||||
|
|
|
@ -19,17 +19,12 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc
|
|||
|
||||
protected InstanceKey<ModelData> pointer;
|
||||
|
||||
protected double xRot;
|
||||
protected double yRot;
|
||||
protected int pointerRotationOffset;
|
||||
protected final double xRot;
|
||||
protected final double yRot;
|
||||
protected final int pointerRotationOffset;
|
||||
|
||||
public FluidValveInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
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 shaftAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
|
||||
|
||||
pointerRotationOffset = 0;
|
||||
if (pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical())
|
||||
pointerRotationOffset = 90;
|
||||
boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical();
|
||||
pointerRotationOffset = twist ? 90 : 0;
|
||||
|
||||
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> {
|
||||
|
||||
private boolean upward;
|
||||
private boolean diagonal;
|
||||
private boolean sideways;
|
||||
private boolean vertical;
|
||||
private boolean alongX;
|
||||
private boolean alongZ;
|
||||
private BeltSlope beltSlope;
|
||||
private Direction facing;
|
||||
boolean upward;
|
||||
boolean diagonal;
|
||||
boolean sideways;
|
||||
boolean vertical;
|
||||
boolean alongX;
|
||||
boolean alongZ;
|
||||
BeltSlope beltSlope;
|
||||
Direction facing;
|
||||
protected ArrayList<InstanceKey<BeltData>> keys;
|
||||
protected InstanceKey<RotatingData> pulleyKey;
|
||||
|
||||
public BeltInstance(InstancedTileRenderer<?> modelManager, BeltTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
if (!AllBlocks.BELT.has(blockState))
|
||||
return;
|
||||
|
||||
|
@ -77,7 +74,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
public void update() {
|
||||
DyeColor color = tile.color.orElse(null);
|
||||
|
||||
boolean bottom = true;
|
||||
|
|
|
@ -17,14 +17,11 @@ import net.minecraft.util.Direction;
|
|||
|
||||
public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity> {
|
||||
|
||||
protected ArrayList<InstanceKey<RotatingData>> keys;
|
||||
protected final ArrayList<InstanceKey<RotatingData>> keys;
|
||||
|
||||
public SplitShaftInstance(InstancedTileRenderer<?> modelManager, SplitShaftTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
keys = new ArrayList<>(2);
|
||||
|
||||
Block block = blockState.getBlock();
|
||||
|
@ -43,7 +40,7 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
public void update() {
|
||||
Block block = blockState.getBlock();
|
||||
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
|
||||
|
||||
|
|
|
@ -18,17 +18,12 @@ import java.util.ArrayList;
|
|||
|
||||
public abstract class GaugeInstance extends ShaftInstance implements IDynamicInstance {
|
||||
|
||||
protected ArrayList<DialFace> faces;
|
||||
protected final ArrayList<DialFace> faces;
|
||||
|
||||
protected MatrixStack ms;
|
||||
|
||||
protected GaugeInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
faces = new ArrayList<>(2);
|
||||
|
||||
|
|
|
@ -18,15 +18,12 @@ import net.minecraft.world.LightType;
|
|||
|
||||
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||
|
||||
protected EnumMap<Direction, InstanceKey<RotatingData>> keys;
|
||||
protected final EnumMap<Direction, InstanceKey<RotatingData>> keys;
|
||||
protected Direction sourceFacing;
|
||||
|
||||
public GearboxInstance(InstancedTileRenderer<?> modelManager, GearboxTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
keys = new EnumMap<>(Direction.class);
|
||||
|
||||
final Direction.Axis boxAxis = blockState.get(BlockStateProperties.AXIS);
|
||||
|
@ -78,7 +75,7 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
public void update() {
|
||||
updateSourceFacing();
|
||||
for (Map.Entry<Direction, InstanceKey<RotatingData>> key : keys.entrySet()) {
|
||||
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.instancing.InstanceData;
|
||||
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.util.math.BlockPos;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class FlapData extends InstanceData {
|
||||
public class FlapData extends InstanceData implements IFlatLight<FlapData> {
|
||||
|
||||
public static VertexFormat FORMAT = VertexFormat.builder()
|
||||
.addAttributes(FlapVertexAttributes.class)
|
||||
|
@ -61,11 +62,13 @@ public class FlapData extends InstanceData {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlapData setBlockLight(int blockLight) {
|
||||
this.blockLight = (byte) ((blockLight & 0xF) << 4);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlapData setSkyLight(int skyLight) {
|
||||
this.skyLight = (byte) ((skyLight & 0xF) << 4);
|
||||
return this;
|
||||
|
|
|
@ -16,15 +16,11 @@ import java.util.Map;
|
|||
|
||||
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements IDynamicInstance {
|
||||
|
||||
|
||||
private Map<Direction, ArrayList<InstanceKey<FlapData>>> tunnelFlaps;
|
||||
private final Map<Direction, ArrayList<InstanceKey<FlapData>>> tunnelFlaps;
|
||||
|
||||
public BeltTunnelInstance(InstancedTileRenderer<?> modelManager, BeltTunnelTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
tunnelFlaps = new EnumMap<>(Direction.class);
|
||||
|
||||
InstancedModel<FlapData> model = modelManager.getMaterial(KineticRenderMaterials.FLAPS)
|
||||
|
@ -82,9 +78,6 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onUpdate() { }
|
||||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
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 {
|
||||
|
||||
protected InstanceKey<ModelData> indicator;
|
||||
protected final InstanceKey<ModelData> indicator;
|
||||
|
||||
protected int previousState;
|
||||
|
||||
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
|
||||
|
||||
MatrixStack ms = new MatrixStack();
|
||||
|
|
|
@ -12,14 +12,11 @@ import java.util.ArrayList;
|
|||
|
||||
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) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
flaps = new ArrayList<>(4);
|
||||
|
||||
if (!tile.hasFlap()) return;
|
||||
|
@ -71,16 +68,8 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
|
|||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
if (flaps == null) return;
|
||||
|
||||
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);
|
||||
}
|
||||
if (flaps != null)
|
||||
relight(pos, flaps.stream().map(InstanceKey::getInstance));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,24 +24,19 @@ import java.util.ArrayList;
|
|||
|
||||
public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance {
|
||||
|
||||
private InstanceKey<ModelData> base;
|
||||
private InstanceKey<ModelData> lowerBody;
|
||||
private InstanceKey<ModelData> upperBody;
|
||||
private InstanceKey<ModelData> head;
|
||||
private InstanceKey<ModelData> claw;
|
||||
private ArrayList<InstanceKey<ModelData>> clawGrips;
|
||||
final InstanceKey<ModelData> base;
|
||||
final InstanceKey<ModelData> lowerBody;
|
||||
final InstanceKey<ModelData> upperBody;
|
||||
final InstanceKey<ModelData> head;
|
||||
final InstanceKey<ModelData> claw;
|
||||
private final ArrayList<InstanceKey<ModelData>> clawGrips;
|
||||
|
||||
private ArrayList<InstanceKey<ModelData>> models;
|
||||
private final ArrayList<InstanceKey<ModelData>> models;
|
||||
|
||||
private boolean firstTick = true;
|
||||
|
||||
public ArmInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||
|
||||
|
@ -58,8 +53,6 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
|
|||
clawGrips = Lists.newArrayList(clawGrip1, clawGrip2);
|
||||
models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2);
|
||||
|
||||
firstTick = true;
|
||||
beginFrame();
|
||||
updateLight();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,18 +14,15 @@ import net.minecraft.util.Direction;
|
|||
|
||||
public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntity> implements IDynamicInstance {
|
||||
|
||||
protected InstanceKey<ModelData> handle;
|
||||
protected InstanceKey<ModelData> indicator;
|
||||
protected final InstanceKey<ModelData> handle;
|
||||
protected final InstanceKey<ModelData> indicator;
|
||||
|
||||
private float rX;
|
||||
private float rY;
|
||||
final float rX;
|
||||
final float rY;
|
||||
|
||||
public AnalogLeverInstance(InstancedTileRenderer<?> modelManager, AnalogLeverTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||
|
||||
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 {
|
||||
|
||||
private InstanceKey<ModelData> connector;
|
||||
private InstanceKey<ModelData> pipe;
|
||||
private final InstanceKey<ModelData> connector;
|
||||
private final InstanceKey<ModelData> pipe;
|
||||
|
||||
public SchematicannonInstance(InstancedTileRenderer<?> modelManager, SchematicannonTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
|
||||
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
|
||||
|
||||
|
|
|
@ -79,11 +79,6 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
|||
return getMaterial(RenderMaterials.MODELS);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends TileEntity> TileEntityInstance<? super T> getInstance(T tile) {
|
||||
return getInstance(tile, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
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 (tile instanceof IInstanceRendered) {
|
||||
getInstance(tile);
|
||||
getInstance(tile, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,8 +138,16 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
|||
if (tile instanceof IInstanceRendered) {
|
||||
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
||||
|
||||
if (instance != null)
|
||||
instance.update();
|
||||
if (instance != null) {
|
||||
|
||||
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 (tile instanceof IInstanceRendered) {
|
||||
TileEntityInstance<? super T> instance = getInstance(tile, false);
|
||||
|
||||
if (instance != null) {
|
||||
instance.remove();
|
||||
instances.remove(tile);
|
||||
dynamicInstances.remove(tile);
|
||||
tickableInstances.remove(tile);
|
||||
}
|
||||
removeInternal(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() {
|
||||
instances.keySet().removeIf(TileEntity::isRemoved);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
|||
protected final T tile;
|
||||
protected final World world;
|
||||
protected final BlockPos pos;
|
||||
protected BlockState blockState;
|
||||
protected final BlockState blockState;
|
||||
|
||||
public TileEntityInstance(InstancedTileRenderer<?> modelManager, T tile) {
|
||||
this.modelManager = modelManager;
|
||||
|
@ -24,30 +24,15 @@ public abstract class TileEntityInstance<T extends TileEntity> {
|
|||
this.world = tile.getWorld();
|
||||
this.pos = tile.getPos();
|
||||
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();
|
||||
|
||||
/**
|
||||
* 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() { }
|
||||
protected void update() { }
|
||||
|
||||
/**
|
||||
* 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 boolean shouldReset() {
|
||||
return tile.getBlockState() != blockState;
|
||||
}
|
||||
|
||||
public BlockPos getFloatingPos() {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue