Some housekeeping and documentation.

This commit is contained in:
JozsefA 2021-03-25 14:29:52 -07:00
parent 8c79174904
commit a56514c308
37 changed files with 228 additions and 206 deletions

View file

@ -15,7 +15,7 @@ public class HalfShaftInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
Direction dir = getShaftDirection();
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir);
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState, dir);
}
protected Direction getShaftDirection() {

View file

@ -20,16 +20,6 @@ public class KineticData extends BasicData {
super(owner);
}
public KineticData setTileEntity(KineticTileEntity te) {
setPosition(te.getPos());
if (te.hasSource()) {
setColor(te.network);
}else {
setColor(0xFF, 0xFF, 0x00);
}
return this;
}
public KineticData setPosition(BlockPos pos) {
return setPosition(pos.getX(), pos.getY(), pos.getZ());
}
@ -39,11 +29,9 @@ public class KineticData extends BasicData {
}
public KineticData setPosition(int x, int y, int z) {
BlockPos origin = owner.renderer.getOriginCoordinate();
return setPosition((float) (x - origin.getX()),
(float) (y - origin.getY()),
(float) (z - origin.getZ()));
return setPosition((float) (x),
(float) (y),
(float) (z));
}
public KineticData setPosition(float x, float y, float z) {
@ -60,6 +48,15 @@ public class KineticData extends BasicData {
return this;
}
public KineticData setColor(KineticTileEntity te) {
if (te.hasSource()) {
setColor(te.network);
}else {
setColor(0xFF, 0xFF, 0x00);
}
return this;
}
public KineticData setColor(Long l) {
if (l != null)
return setColor(l.longValue());

View file

@ -8,41 +8,55 @@ import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction;
import net.minecraft.world.LightType;
public abstract class KineticTileInstance<T extends KineticTileEntity> extends TileEntityInstance<T> {
protected final Direction.Axis axis;
public KineticTileInstance(InstancedTileRenderer<?> modelManager, T tile) {
super(modelManager, tile);
axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
}
protected final void updateRotation(InstanceKey<RotatingData> key, Direction.Axis axis) {
updateRotation(key, axis, tile.getSpeed());
protected final void updateRotation(RotatingData instance) {
updateRotation(instance, getRotationAxis(), getTileSpeed());
}
protected final void updateRotation(InstanceKey<RotatingData> key, Direction.Axis axis, float speed) {
updateRotation(key.getInstance(), axis, speed);
protected final void updateRotation(RotatingData instance, Direction.Axis axis) {
updateRotation(instance, axis, getTileSpeed());
}
protected final void updateRotation(RotatingData key, Direction.Axis axis, float speed) {
key.setRotationAxis(axis)
protected final void updateRotation(RotatingData instance, float speed) {
updateRotation(instance, getRotationAxis(), speed);
}
protected final void updateRotation(RotatingData instance, Direction.Axis axis, float speed) {
instance.setRotationAxis(axis)
.setRotationOffset(getRotationOffset(axis))
.setRotationalSpeed(speed)
.setColor(tile.network);
.setColor(tile);
}
protected final void updateRotation(RotatingData key, Direction.Axis axis) {
updateRotation(key, axis, tile.getSpeed());
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key) {
return setup(key, getRotationAxis(), getTileSpeed());
}
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, float speed, Direction.Axis axis) {
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, Direction.Axis axis) {
return setup(key, axis, getTileSpeed());
}
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, float speed) {
return setup(key, getRotationAxis(), speed);
}
protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, Direction.Axis axis, float speed) {
key.getInstance()
.setRotationAxis(axis)
.setRotationalSpeed(speed)
.setRotationOffset(getRotationOffset(axis))
.setTileEntity(tile)
.setSkyLight(world.getLightLevel(LightType.SKY, pos))
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos));
.setColor(tile)
.setPosition(getInstancePosition());
return key;
}
@ -57,16 +71,24 @@ public abstract class KineticTileInstance<T extends KineticTileEntity> extends T
return offset;
}
protected Direction.Axis getRotationAxis() {
return axis;
}
protected float getTileSpeed() {
return tile.getSpeed();
}
protected BlockState shaft() {
return shaft(getRotationAxis());
}
protected final RenderMaterial<?, InstancedModel<RotatingData>> getRotatingMaterial() {
return renderer.getMaterial(KineticRenderMaterials.ROTATING);
}
public static BlockState shaft(Direction.Axis axis) {
return AllBlocks.SHAFT.getDefaultState()
.with(ShaftBlock.AXIS, axis);
}
public Direction.Axis getRotationAxis() {
return ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
}
protected final RenderMaterial<?, InstancedModel<RotatingData>> rotatingMaterial() {
return modelManager.getMaterial(KineticRenderMaterials.ROTATING);
.with(ShaftBlock.AXIS, axis);
}
}

View file

@ -12,6 +12,6 @@ public class ShaftlessCogInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(modelManager, tile.getBlockState());
return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(renderer, tile.getBlockState());
}
}

View file

@ -1,39 +1,34 @@
package com.simibubi.create.content.contraptions.base;
import static com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer.KINETIC_TILE;
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.block.BlockState;
import net.minecraft.util.Direction;
public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntity> {
protected final InstanceKey<RotatingData> rotatingModelKey;
protected final InstanceKey<RotatingData> rotatingModel;
public SingleRotatingInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
super(modelManager, tile);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
rotatingModel = setup(getModel().createInstance());
}
@Override
public void update() {
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
updateRotation(rotatingModelKey, axis);
updateRotation(rotatingModel.getInstance());
}
@Override
public void updateLight() {
relight(pos, rotatingModelKey.getInstance());
relight(pos, rotatingModel.getInstance());
}
@Override
public void remove() {
rotatingModelKey.delete();
rotatingModel.delete();
}
protected BlockState getRenderedBlockState() {
@ -41,6 +36,6 @@ public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntit
}
protected InstancedModel<RotatingData> getModel() {
return rotatingMaterial().getModel(KINETIC_TILE, getRenderedBlockState());
return getRotatingMaterial().getModel(getRenderedBlockState());
}
}

View file

@ -14,6 +14,6 @@ public class DrillInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState());
return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(renderer, tile.getBlockState());
}
}

View file

@ -36,7 +36,7 @@ public class HarvesterActorInstance extends ActorInstance {
public HarvesterActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) {
super(modelManager, context);
RenderMaterial<?, InstancedModel<ModelData>> renderMaterial = modelManager.transformMaterial();
RenderMaterial<?, InstancedModel<ModelData>> renderMaterial = modelManager.getTransformMaterial();
BlockState state = context.state;

View file

@ -35,6 +35,6 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance {
stacker.unCentre();
return stack;
};
return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState, facing, ms);
return getRotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState, facing, ms);
}
}

View file

@ -30,8 +30,6 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami
facing = blockState.get(BlockStateProperties.FACING);
InstancedModel<ModelData> model = renderedHandle.renderOnDirectionalSouthModel(modelManager, blockState, facing.getOpposite());
crank = model.createInstance();
updateLight();
}
@Override
@ -45,7 +43,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami
MatrixStack ms = new MatrixStack();
MatrixStacker.of(ms)
.translate(getFloatingPos())
.translate(getInstancePosition())
.centre()
.rotate(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis), angle)
.unCentre();

View file

@ -37,7 +37,7 @@ public class DeployerActorInstance extends ActorInstance {
public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) {
super(modelManager, context);
RenderMaterial<ContraptionProgram, InstancedModel<ModelData>> mat = modelManager.transformMaterial();
RenderMaterial<ContraptionProgram, InstancedModel<ModelData>> mat = modelManager.getTransformMaterial();
BlockState state = context.state;
DeployerTileEntity.Mode mode = NBTHelper.readEnum(context.tileData, "Mode", DeployerTileEntity.Mode.class);
@ -56,7 +56,7 @@ public class DeployerActorInstance extends ActorInstance {
Direction.Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
shaft = modelManager.getMaterial(KineticRenderMaterials.ROTATING)
.getModel(KineticTileEntityRenderer.KINETIC_TILE, KineticTileInstance.shaft(axis))
.getModel(KineticTileInstance.shaft(axis))
.createInstance();
int blockLight = localBlockLight();

View file

@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.deployer;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData;
import com.simibubi.create.foundation.utility.AngleHelper;
@ -46,7 +45,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance,
zRot = facing == Direction.UP ? 270 : facing == Direction.DOWN ? 90 : 0;
zRotPole = rotatePole ? 90 : 0;
pole = RenderMaterials.ORIENTED.get(modelManager).getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance();
pole = getOrientedMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance();
updateHandPose();
relight(pos, pole.getInstance());
@ -73,7 +72,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance,
: currentHand == AllBlockPartials.DEPLOYER_HAND_HOLDING ? 4 / 16f : 3 / 16f;
float distance = Math.min(MathHelper.clamp(progress, 0, 1) * (tile.reach + handLength), 21 / 16f);
Vec3i facingVec = facing.getDirectionVec();
BlockPos blockPos = getFloatingPos();
BlockPos blockPos = getInstancePosition();
float x = blockPos.getX() + ((float) facingVec.getX()) * distance;
float y = blockPos.getY() + ((float) facingVec.getY()) * distance;
@ -107,7 +106,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance,
if (hand != null) hand.delete();
hand = RenderMaterials.ORIENTED.get(modelManager).getModel(currentHand, blockState).createInstance();
hand = getOrientedMaterial().getModel(currentHand, blockState).createInstance();
relight(pos, hand.getInstance());
updateRotation(pole, hand, yRot, zRot, zRotPole);

View file

@ -17,27 +17,18 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
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);
direction = blockState.get(FACING);
axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
RotatingData shaftInstance = shaft.getInstance();
shaftInstance.setTileEntity(tile);
updateRotation(shaftInstance, axis);
RotatingData fanInstance = fan.getInstance();
fanInstance.setTileEntity(tile);
updateRotation(fanInstance, axis, getFanSpeed());
updateLight();
setup(shaft);
setup(fan, getFanSpeed());
}
private float getFanSpeed() {
@ -51,8 +42,8 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
@Override
protected void update() {
updateRotation(shaft, axis);
updateRotation(fan, axis, getFanSpeed());
updateRotation(shaft.getInstance());
updateRotation(fan.getInstance(), getFanSpeed());
}
@Override

View file

@ -6,10 +6,8 @@ import java.util.List;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
@ -49,8 +47,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
shaft = setup(shaftModel().createInstance(), tile.getSpeed(), axis);
shaft = setup(shaftModel().createInstance());
wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, blockState.rotate(Rotation.CLOCKWISE_90)).createInstance();
@ -62,7 +59,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
connectorAngleMult = flipAngle ? -1 : 1;
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED);
RenderMaterial<?, InstancedModel<ModelData>> mat = getTransformMaterial();
upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance();
lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance();
@ -73,8 +70,6 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
} else {
connectors = Collections.emptyList();
}
updateLight();
}
@Override
@ -90,7 +85,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
if (connection != null) {
float rotation = angle * connectorAngleMult;
@ -133,8 +128,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
@Override
protected void update() {
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
updateRotation(shaft, axis);
updateRotation(shaft.getInstance());
}
@Override
@ -156,7 +150,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
}
protected InstancedModel<RotatingData> shaftModel() {
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, facing.getOpposite());
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState, facing.getOpposite());
}
protected void transformConnector(MatrixStacker ms, boolean upper, boolean rotating, float angle, boolean flip) {

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.render.backend.instancing.TileEntityInstance;
@ -30,14 +29,14 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
Direction facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
this.frame = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(frame, blockState).createInstance();
this.frame = getTransformMaterial().getModel(frame, blockState).createInstance();
float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing));
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos())
msr.translate(getInstancePosition())
.nudge(tile.hashCode())
.centre()
.rotate(Direction.UP, angle)
@ -46,8 +45,6 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
this.frame.getInstance()
.setTransform(ms);
updateLight();
}
@Override

View file

@ -15,6 +15,6 @@ public class MillStoneCogInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
return AllBlockPartials.MILLSTONE_COG.renderOnRotating(modelManager, tile.getBlockState());
return AllBlockPartials.MILLSTONE_COG.renderOnRotating(renderer, tile.getBlockState());
}
}

View file

@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.ShaftlessCogInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -20,13 +19,13 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta
public MixerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
super(dispatcher, tile);
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
mixerHead = getRotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
.createInstance();
mixerHead.getInstance()
.setRotationAxis(Direction.Axis.Y);
mixerPole = modelManager.getMaterial(RenderMaterials.TRANSFORMED)
mixerPole = getTransformMaterial()
.getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState)
.createInstance();
@ -36,7 +35,6 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta
transformPole(renderedHeadOffset);
transformHead(mixer, renderedHeadOffset);
updateLight();
}
@Override
@ -56,7 +54,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta
float speed = mixer.getRenderedHeadRotationSpeed(AnimationTickHolder.getPartialTicks());
mixerHead.getInstance()
.setPosition(pos)
.setPosition(getInstancePosition())
.nudge(0, -renderedHeadOffset, 0)
.setRotationalSpeed(speed * 2);
}
@ -65,7 +63,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
msr.translate(0, -renderedHeadOffset, 0);
mixerPole.getInstance().setTransform(ms);

View file

@ -20,7 +20,6 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance {
pressHead = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontalModel(dispatcher, blockState).createInstance();
updateLight();
transformModels((MechanicalPressTileEntity) tile);
}
@ -39,7 +38,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance {
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
msr.translate(0, -renderedHeadOffset, 0);
pressHead.getInstance()

View file

@ -4,7 +4,6 @@ import static net.minecraft.state.properties.BlockStateProperties.FACING;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
@ -21,8 +20,8 @@ public class SawInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
if (blockState.get(FACING).getAxis().isHorizontal())
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180));
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180));
else
return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis()));
return getRotatingMaterial().getModel(shaft());
}
}

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.ch
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AngleHelper;
@ -24,13 +23,11 @@ public class StickerInstance extends TileEntityInstance<StickerTileEntity> imple
public StickerInstance(InstancedTileRenderer<?> modelManager, StickerTileEntity tile) {
super(modelManager, tile);
head = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance();
head = getTransformMaterial().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
@ -45,7 +42,7 @@ public class StickerInstance extends TileEntityInstance<StickerTileEntity> imple
MatrixStack stack = new MatrixStack();
MatrixStacker.of(stack)
.translate(getFloatingPos())
.translate(getInstancePosition())
.nudge(tile.hashCode())
.centre()
.rotateY(AngleHelper.horizontalAngle(facing))

View file

@ -5,7 +5,6 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
@ -29,7 +28,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns
public GantryCarriageInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
super(dispatcher, tile);
gantryCogs = modelManager.getMaterial(RenderMaterials.TRANSFORMED)
gantryCogs = getTransformMaterial()
.getModel(AllBlockPartials.GANTRY_COGS, blockState)
.createInstance();
@ -40,8 +39,6 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns
visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos()
: tile.getPos()
.offset(facing.getOpposite());
updateLight();
}
@Override
@ -62,7 +59,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns
MatrixStack ms = new MatrixStack();
MatrixStacker.of(ms)
.translate(getFloatingPos())
.translate(getInstancePosition())
.centre()
.rotateY(AngleHelper.horizontalAngle(facing))
.rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90)
@ -77,7 +74,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns
@Override
public void updateLight() {
relight(pos, gantryCogs.getInstance());
relight(pos, gantryCogs.getInstance(), rotatingModel.getInstance());
}
@Override

View file

@ -15,6 +15,6 @@ public class PumpCogInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(modelManager, tile.getBlockState());
return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(renderer, tile.getBlockState());
}
}

View file

@ -37,9 +37,8 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc
boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical();
pointerRotationOffset = twist ? 90 : 0;
pointer = modelManager.transformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance();
pointer = renderer.getTransformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance();
updateLight();
transformPointer((FluidValveTileEntity) tile);
}
@ -58,7 +57,7 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc
MatrixStack ms = new MatrixStack();
MatrixStacker.of(ms)
.translate(getFloatingPos())
.translate(getInstancePosition())
.centre()
.rotateY(yRot)
.rotateX(xRot)

View file

@ -69,7 +69,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
if (tile.hasPulley()) {
InstancedModel<RotatingData> pulleyModel = getPulleyModel();
pulleyKey = setup(pulleyModel.createInstance(), tile.getSpeed(), getRotationAxis());
pulleyKey = setup(pulleyModel.createInstance());
}
}
@ -83,13 +83,13 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
key.getInstance()
.setScrollTexture(spriteShiftEntry)
.setColor(tile.network)
.setColor(tile)
.setRotationalSpeed(getScrollSpeed());
bottom = false;
}
if (pulleyKey != null) {
updateRotation(pulleyKey, getRotationAxis());
updateRotation(pulleyKey.getInstance());
}
}
@ -139,7 +139,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
return modelTransform;
};
return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms);
return getRotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms);
}
private Direction getOrientation() {
@ -159,13 +159,14 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
Quaternion q = new Quaternion(rotX, rotY, rotZ, true);
key.getInstance()
.setScrollTexture(spriteShift)
.setScrollMult(diagonal ? 3f / 8f : 0.5f)
.setRotation(q)
.setRotationalSpeed(getScrollSpeed())
.setRotationOffset(bottom ? 0.5f : 0f)
.setTileEntity(tile)
key.getInstance()
.setScrollTexture(spriteShift)
.setScrollMult(diagonal ? 3f / 8f : 0.5f)
.setRotation(q)
.setRotationalSpeed(getScrollSpeed())
.setRotationOffset(bottom ? 0.5f : 0f)
.setColor(tile)
.setPosition(getInstancePosition())
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos));

View file

@ -18,7 +18,7 @@ public class ShaftInstance extends SingleRotatingInstance {
@Override
protected BlockState getRenderedBlockState() {
return shaft(getRotationAxis());
return shaft();
}
}

View file

@ -24,19 +24,18 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
keys = new ArrayList<>(2);
Block block = blockState.getBlock();
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
float speed = tile.getSpeed();
for (Direction dir : Iterate.directionsInAxis(boxAxis)) {
for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) {
InstancedModel<RotatingData> half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir);
float splitSpeed = speed * tile.getRotationSpeedModifier(dir);
keys.add(setup(half.createInstance(), splitSpeed, boxAxis));
keys.add(setup(half.createInstance(), splitSpeed));
}
updateLight();
}
@Override
@ -47,13 +46,13 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
Direction[] directions = Iterate.directionsInAxis(boxAxis);
for (int i : Iterate.zeroAndOne) {
updateRotation(keys.get(i), directions[i]);
updateRotation(keys.get(i).getInstance(), tile.getSpeed() * tile.getRotationSpeedModifier(directions[i]));
}
}
@Override
public void updateLight() {
keys.forEach(key -> relight(pos, ((InstanceKey<? extends KineticData>) key).getInstance()));
relight(pos, keys.stream().map(InstanceKey::getInstance));
}
@Override
@ -62,13 +61,4 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
keys.clear();
}
protected void updateRotation(InstanceKey<RotatingData> key, Direction dir) {
Direction.Axis axis = dir.getAxis();
key.getInstance()
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir))
.setRotationOffset(getRotationOffset(axis))
.setColor(tile.network);
}
}

View file

@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
@ -30,12 +29,12 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns
GaugeTileEntity gaugeTile = (GaugeTileEntity) tile;
GaugeBlock gaugeBlock = (GaugeBlock) blockState.getBlock();
InstancedModel<ModelData> dialModel = modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_DIAL, blockState);
InstancedModel<ModelData> dialModel = getTransformMaterial().getModel(AllBlockPartials.GAUGE_DIAL, blockState);
InstancedModel<ModelData> headModel = getHeadModel();
ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
float progress = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), gaugeTile.prevDialState, gaugeTile.dialState);
@ -49,8 +48,6 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns
face.setupTransform(msr, progress);
}
updateLight();
}
private DialFace makeFace(Direction face, InstancedModel<ModelData> dialModel, InstancedModel<ModelData> headModel) {
@ -151,7 +148,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns
@Override
protected InstancedModel<ModelData> getHeadModel() {
return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState);
return getTransformMaterial().getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState);
}
}
@ -162,7 +159,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns
@Override
protected InstancedModel<ModelData> getHeadModel() {
return modelManager.getMaterial(RenderMaterials.TRANSFORMED).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState);
return getTransformMaterial().getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState);
}
}
}

View file

@ -44,8 +44,8 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
key.getInstance()
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setRotationalSpeed(getSpeed(direction))
.setRotationOffset(getRotationOffset(axis))
.setTileEntity(tile)
.setRotationOffset(getRotationOffset(axis)).setColor(tile)
.setPosition(getInstancePosition())
.setBlockLight(blockLight)
.setSkyLight(skyLight);
@ -81,12 +81,7 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
Direction direction = key.getKey();
Direction.Axis axis = direction.getAxis();
key.getValue()
.getInstance()
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setRotationalSpeed(getSpeed(direction))
.setRotationOffset(getRotationOffset(axis))
.setColor(tile.network);
updateRotation(key.getValue().getInstance(), axis, getSpeed(direction));
}
}

View file

@ -16,18 +16,16 @@ public class AdjustableRepeaterInstance extends TileEntityInstance<AdjustableRep
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
super(modelManager, tile);
indicator = modelManager.transformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
indicator = modelManager.getTransformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
MatrixStack ms = new MatrixStack();
MatrixStacker.of(ms).translate(getFloatingPos());
MatrixStacker.of(ms).translate(getInstancePosition());
indicator.getInstance()
.setTransform(ms)
.setColor(getColor());
previousState = tile.state;
updateLight();
}
@Override

View file

@ -6,7 +6,6 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
@ -38,7 +37,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
public ArmInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
super(modelManager, tile);
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED);
RenderMaterial<?, InstancedModel<ModelData>> mat = getTransformMaterial();
base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance();
lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance();
@ -52,8 +51,6 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
clawGrips = Lists.newArrayList(clawGrip1, clawGrip2);
models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2);
updateLight();
}
@Override
@ -91,7 +88,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
MatrixStack msLocal = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(msLocal);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
msr.centre();
if (blockState.get(ArmBlock.CEILING))
@ -147,7 +144,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
@Override
protected InstancedModel<RotatingData> getModel() {
return AllBlockPartials.ARM_COG.renderOnRotating(modelManager, tile.getBlockState());
return AllBlockPartials.ARM_COG.renderOnRotating(renderer, tile.getBlockState());
}
@Override

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.logistics.block.redstone;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AngleHelper;
@ -23,7 +22,7 @@ public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntit
public AnalogLeverInstance(InstancedTileRenderer<?> modelManager, AnalogLeverTileEntity tile) {
super(modelManager, tile);
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED);
RenderMaterial<?, InstancedModel<ModelData>> mat = getTransformMaterial();
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance();
indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance();
@ -33,7 +32,6 @@ public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntit
rY = AngleHelper.horizontalAngle(blockState.get(AnalogLeverBlock.HORIZONTAL_FACING));
setupModel();
updateLight();
}
@Override
@ -46,7 +44,7 @@ public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntit
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
transform(msr);
float state = tile.clientState.get(AnimationTickHolder.getPartialTicks());

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.schematics.block;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -17,12 +16,10 @@ public class SchematicannonInstance extends TileEntityInstance<SchematicannonTil
public SchematicannonInstance(InstancedTileRenderer<?> modelManager, SchematicannonTileEntity tile) {
super(modelManager, tile);
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.TRANSFORMED);
RenderMaterial<?, InstancedModel<ModelData>> mat = getTransformMaterial();
connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance();
pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance();
updateLight();
}
@Override
@ -39,7 +36,7 @@ public class SchematicannonInstance extends TileEntityInstance<SchematicannonTil
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(getInstancePosition());
ms.push();
msr.centre();

View file

@ -1,9 +1,17 @@
package com.simibubi.create.foundation.render.backend.instancing;
/**
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
* the start of a frame. By implementing {@link IDynamicInstance}, a {@link TileEntityInstance}
* can animate its models in ways that could not be easily achieved by shader attribute
* parameterization.
*
* <br><br> If your goal is offloading work to shaders, but you're unsure exactly how you need
* to parameterize the instances, you're encouraged to implement this for prototyping.
*/
public interface IDynamicInstance {
/**
* Called every frame. This can be used to smoothly change instance data
* to allow for fancy animations that could not be achieved on the GPU alone.
* Called every frame.
*/
void beginFrame();
}

View file

@ -1,10 +1,25 @@
package com.simibubi.create.foundation.render.backend.instancing;
/**
* An interface giving {@link TileEntityInstance}s a hook to have a function called at
* the end of every tick. By implementing {@link ITickableInstance}, a {@link TileEntityInstance}
* can update frequently, but not every frame.
* <br> There are a few cases in which this should be considered over {@link IDynamicInstance}:
* <ul>
* <li>
* You'd like to change something about the instance every now and then.
* eg. adding or removing parts, snapping to a different rotation.
* </li>
* <li>
* Your TileEntity does animate, but the animation doesn't have
* to be smooth, in which case this could be an optimization.
* </li>
* </ul>
*/
public interface ITickableInstance {
/**
* Called every tick. This is useful for things that don't have to be smooth,
* or to recalculate something that would only change after a game tick.
*/
void tick();
/**
* Called every tick.
*/
void tick();
}

View file

@ -68,11 +68,11 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
return (RenderMaterial<P, M>) materials.get(materialType);
}
public RenderMaterial<P, InstancedModel<ModelData>> transformMaterial() {
public RenderMaterial<P, InstancedModel<ModelData>> getTransformMaterial() {
return getMaterial(RenderMaterials.TRANSFORMED);
}
public RenderMaterial<P, InstancedModel<OrientedData>> orientedMaterial() {
public RenderMaterial<P, InstancedModel<OrientedData>> getOrientedMaterial() {
return getMaterial(RenderMaterials.ORIENTED);
}
@ -167,6 +167,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
TileEntityInstance<? super T> renderer = InstancedTileRenderRegistry.instance.create(this, tile);
if (renderer != null) {
renderer.updateLight();
instances.put(tile, renderer);
if (renderer instanceof IDynamicInstance)

View file

@ -1,10 +1,5 @@
package com.simibubi.create.foundation.render.backend.instancing;
import com.simibubi.create.foundation.render.backend.gl.BasicProgram;
public class MaterialType<M extends InstancedModel<?>> {
public <P extends BasicProgram> RenderMaterial<?, M> get(InstancedTileRenderer<P> renderer) {
return renderer.getMaterial(this);
}
}

View file

@ -56,7 +56,7 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
this.layerPredicate = layerPredicate;
registerCompartment(Compartment.PARTIAL);
registerCompartment(Compartment.DIRECTIONAL_PARTIAL);
registerCompartment(KineticTileEntityRenderer.KINETIC_TILE);
registerCompartment(Compartment.GENERIC_TILE);
}
public boolean canRenderInLayer(RenderType layer) {
@ -120,8 +120,8 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
() -> buildModel(partial.get(), referenceState, modelTransform.get()));
}
public MODEL getModel(Compartment<BlockState> compartment, BlockState toRender) {
return get(compartment, toRender, () -> buildModel(toRender));
public MODEL getModel(BlockState toRender) {
return get(Compartment.GENERIC_TILE, toRender, () -> buildModel(toRender));
}
public <T> MODEL get(Compartment<T> compartment, T key, Supplier<MODEL> supplier) {

View file

@ -1,6 +1,9 @@
package com.simibubi.create.foundation.render.backend.instancing;
import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.render.backend.instancing.impl.OrientedData;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -10,16 +13,33 @@ import net.minecraft.world.World;
import java.util.Arrays;
import java.util.stream.Stream;
/**
* The layer between a {@link TileEntity} and the Flywheel backend.
*
* <br><br> {@link #updateLight()} is called after construction.
*
* <br><br> There are a few additional features that overriding classes can opt in to:
* <ul>
* <li>{@link IDynamicInstance}</li>
* <li>{@link ITickableInstance}</li>
* </ul>
* See the interfaces' documentation for more information about each one.
*
* <br> Implementing one or more of these will give a {@link TileEntityInstance} access
* to more interesting and regular points within a tick or a frame.
*
* @param <T> The type of {@link TileEntity} your class is an instance of.
*/
public abstract class TileEntityInstance<T extends TileEntity> {
protected final InstancedTileRenderer<?> modelManager;
protected final InstancedTileRenderer<?> renderer;
protected final T tile;
protected final World world;
protected final BlockPos pos;
protected final BlockState blockState;
public TileEntityInstance(InstancedTileRenderer<?> modelManager, T tile) {
this.modelManager = modelManager;
public TileEntityInstance(InstancedTileRenderer<?> renderer, T tile) {
this.renderer = renderer;
this.tile = tile;
this.world = tile.getWorld();
this.pos = tile.getPos();
@ -30,26 +50,46 @@ public abstract class TileEntityInstance<T extends TileEntity> {
* 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}.
* <br><br> If your animations are complex or more CPU driven, see {@link IDynamicInstance} or {@link ITickableInstance}.
*/
protected void update() { }
/**
* Called when a light update occurs in the world. If your model needs it, update light here.
* Called after construction and when a light update occurs in the world.
*
* <br> If your model needs it, update light here.
*/
public void updateLight() { }
/**
* Call {@link InstanceKey#delete()} on all acquired keys.
* Free any acquired resources.
*
* <br> eg. call {@link InstanceKey#delete()}.
*/
public abstract void remove();
/**
* Just before {@link #update()} would be called, <code>shouldReset()</code> is checked.
* If this function returns <code>true</code>, then this instance will be {@link #remove}d,
* and another instance will be constructed to replace it. This allows for more sane resource
* acquisition compared to trying to update everything within the lifetime of an instance.
*
* @return <code>true</code> if this instance should be discarded and refreshed.
*/
public boolean shouldReset() {
return tile.getBlockState() != blockState;
}
public BlockPos getFloatingPos() {
return pos.subtract(modelManager.getOriginCoordinate());
/**
* In order to accommodate for floating point precision errors at high coordinates,
* {@link InstancedTileRenderer}s are allowed to arbitrarily adjust the origin, and
* shift the world matrix provided as a shader uniform accordingly.
*
* @return The {@link BlockPos} at which the {@link TileEntity} this instance
* represents should be rendered at to appear in the correct location.
*/
public BlockPos getInstancePosition() {
return pos.subtract(renderer.getOriginCoordinate());
}
protected void relight(BlockPos pos, IFlatLight<?>... models) {
@ -67,4 +107,12 @@ public abstract class TileEntityInstance<T extends TileEntity> {
protected void relight(int block, int sky, Stream<IFlatLight<?>> models) {
models.forEach(model -> model.setBlockLight(block).setSkyLight(sky));
}
protected RenderMaterial<?, InstancedModel<ModelData>> getTransformMaterial() {
return renderer.getTransformMaterial();
}
protected RenderMaterial<?, InstancedModel<OrientedData>> getOrientedMaterial() {
return renderer.getOrientedMaterial();
}
}