No more 7 circles of callbacks.

- Instead of using consumers to edit instance data, just give the user a pointer to the data.
 - Easier to use, more predictable access.
This commit is contained in:
JozsefA 2021-03-08 02:02:47 -08:00
parent d0e5be24d7
commit 8ce0f47f01
13 changed files with 164 additions and 200 deletions

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.contraptions.base; package com.simibubi.create.content.contraptions.base;
import java.util.function.Consumer;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock;
@ -19,27 +17,28 @@ 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.modifyInstance(data -> { key.getInstance()
data.setColor(tile.network) .setColor(tile.network)
.setRotationalSpeed(tile.getSpeed()) .setRotationalSpeed(tile.getSpeed())
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(axis); .setRotationAxis(axis);
});
} }
protected final Consumer<RotatingData> setupFunc(float speed, Direction.Axis axis) { protected final InstanceKey<RotatingData> setup(InstanceKey<RotatingData> key, float speed, Direction.Axis axis) {
return data -> { key.getInstance()
data.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) .setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos)) .setSkyLight(world.getLightLevel(LightType.SKY, pos))
.setTileEntity(tile) .setTileEntity(tile)
.setRotationalSpeed(speed) .setRotationalSpeed(speed)
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(axis); .setRotationAxis(axis);
};
return key;
} }
protected final void relight(KineticData<?> data) { protected final void relight(InstanceKey<? extends KineticData<?>> key) {
data.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) key.getInstance()
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos)); .setSkyLight(world.getLightLevel(LightType.SKY, pos));
} }

View file

@ -28,7 +28,7 @@ public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntit
@Override @Override
protected void init() { protected void init() {
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
rotatingModelKey = getModel().createInstance(setupFunc(tile.getSpeed(), axis)); rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
} }
@Override @Override
@ -39,7 +39,7 @@ public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntit
@Override @Override
public void updateLight() { public void updateLight() {
rotatingModelKey.modifyInstance(this::relight); relight(rotatingModelKey);
} }
@Override @Override

View file

@ -6,10 +6,7 @@ import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption; import com.simibubi.create.content.contraptions.components.structureMovement.render.RenderedContraption;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -34,16 +31,15 @@ public class DrillInstance extends SingleRotatingInstance {
BlockState state = context.state; BlockState state = context.state;
InstancedModel<ContraptionActorData> model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state); InstancedModel<ContraptionActorData> model = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state);
model.createInstance(data -> {
Direction facing = state.get(DrillBlock.FACING); Direction facing = state.get(DrillBlock.FACING);
float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0); float eulerX = AngleHelper.verticalAngle(facing) + ((facing.getAxis() == Direction.Axis.Y) ? 180 : 0);
float eulerY = facing.getHorizontalAngle(); float eulerY = facing.getHorizontalAngle();
data.setPosition(context.localPos) model.getInstance(model.createInstance())
.setPosition(context.localPos)
.setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos))
.setRotationOffset(0) .setRotationOffset(0)
.setRotationAxis(0, 0, 1) .setRotationAxis(0, 0, 1)
.setLocalRotation(eulerX, eulerY, 0); .setLocalRotation(eulerX, eulerY, 0);
});
} }
@Override @Override

View file

@ -46,17 +46,16 @@ public class HarvesterRenderer extends SafeTileEntityRenderer<HarvesterTileEntit
BlockState state = context.state; BlockState state = context.state;
InstancedModel<ContraptionActorData> model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state); InstancedModel<ContraptionActorData> model = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state);
model.createInstance(data -> {
Direction facing = state.get(HORIZONTAL_FACING); Direction facing = state.get(HORIZONTAL_FACING);
float originOffset = 1 / 16f; float originOffset = 1 / 16f;
Vector3f rotOffset = new Vector3f(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f); Vector3f rotOffset = new Vector3f(0.5f, -2 * originOffset + 0.5f, originOffset + 0.5f);
data.setPosition(context.localPos) model.getInstance(model.createInstance())
.setPosition(context.localPos)
.setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos)) .setBlockLight(contraption.renderWorld.getLightLevel(LightType.BLOCK, context.localPos))
.setRotationOffset(0) .setRotationOffset(0)
.setRotationCenter(rotOffset) .setRotationCenter(rotOffset)
.setRotationAxis(-1, 0, 0) .setRotationAxis(-1, 0, 0)
.setLocalRotation(0, facing.getHorizontalAngle(), 0); .setLocalRotation(0, facing.getHorizontalAngle(), 0);
});
} }
public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal, public static void renderInContraption(MovementContext context, MatrixStack ms, MatrixStack msLocal,

View file

@ -28,7 +28,7 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
protected InstanceKey<RotatingData> shaft; protected InstanceKey<RotatingData> shaft;
protected InstanceKey<RotatingData> fan; protected InstanceKey<RotatingData> fan;
public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { public FanInstance(InstancedTileRenderer<?> modelManager, EncasedFanTileEntity tile) {
super(modelManager, tile); super(modelManager, tile);
} }
@ -42,30 +42,22 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
InstancedModel<RotatingData> fanInner = InstancedModel<RotatingData> fanInner =
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite()); AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite());
shaft = shaftHalf.createInstance(data -> { shaft = shaftHalf.createInstance();
BlockPos behind = pos.offset(direction.getOpposite()); shaft.getInstance()
int blockLight = world.getLightLevel(LightType.BLOCK, behind); .setRotationalSpeed(tile.getSpeed())
int skyLight = world.getLightLevel(LightType.SKY, behind);
data.setRotationalSpeed(tile.getSpeed())
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setTileEntity(tile) .setTileEntity(tile);
.setBlockLight(blockLight)
.setSkyLight(skyLight);
});
fan = fanInner.createInstance(data -> {
BlockPos inFront = pos.offset(direction);
int blockLight = world.getLightLevel(LightType.BLOCK, inFront);
int skyLight = world.getLightLevel(LightType.SKY, inFront);
data.setRotationalSpeed(getFanSpeed())
fan = fanInner.createInstance();
fan.getInstance()
.setRotationalSpeed(getFanSpeed())
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setTileEntity(tile) .setTileEntity(tile);
.setBlockLight(blockLight)
.setSkyLight(skyLight); updateLight();
});
} }
private float getFanSpeed() { private float getFanSpeed() {
@ -82,32 +74,31 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
Direction.Axis axis = lastState.get(FACING).getAxis(); Direction.Axis axis = lastState.get(FACING).getAxis();
updateRotation(shaft, axis); updateRotation(shaft, axis);
fan.modifyInstance(data -> { fan.getInstance()
data.setColor(tile.network) .setColor(tile.network)
.setRotationalSpeed(getFanSpeed()) .setRotationalSpeed(getFanSpeed())
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
});
} }
@Override @Override
public void updateLight() { public void updateLight() {
final Direction direction = lastState.get(FACING); final Direction direction = lastState.get(FACING);
shaft.modifyInstance(data -> {
BlockPos behind = pos.offset(direction.getOpposite()); BlockPos behind = pos.offset(direction.getOpposite());
int blockLight = world.getLightLevel(LightType.BLOCK, behind); putLight(shaft, behind);
int skyLight = world.getLightLevel(LightType.SKY, behind);
data.setBlockLight(blockLight)
.setSkyLight(skyLight);
});
fan.modifyInstance(data -> {
BlockPos inFront = pos.offset(direction); BlockPos inFront = pos.offset(direction);
int blockLight = world.getLightLevel(LightType.BLOCK, inFront); putLight(fan, inFront);
int skyLight = world.getLightLevel(LightType.SKY, inFront); }
data.setBlockLight(blockLight)
private void putLight(InstanceKey<RotatingData> key, BlockPos pos) {
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
int skyLight = world.getLightLevel(LightType.SKY, pos);
key.getInstance()
.setBlockLight(blockLight)
.setSkyLight(skyLight); .setSkyLight(skyLight);
});
} }
@Override @Override

View file

@ -39,8 +39,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> {
facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING);
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
Consumer<RotatingData> setup = setupFunc(tile.getSpeed(), axis); shaft = setup(shaftModel().createInstance(), tile.getSpeed(), axis);
shaft = shaftModel().createInstance(setup);
// wheel = wheelModel().setupInstance(setup); // wheel = wheelModel().setupInstance(setup);
} }
@ -53,14 +52,13 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> {
@Override @Override
public void updateLight() { public void updateLight() {
shaft.modifyInstance(this::relight); relight(shaft);
// wheel.modifyInstance(this::relight); // wheel.modifyInstance(this::relight);
} }
@Override @Override
public void remove() { public void remove() {
shaft.delete(); shaft.delete();
shaft = null;
// wheel.delete(); // wheel.delete();
// wheel = null; // wheel = null;
} }

View file

@ -72,9 +72,8 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
InstancedModel<BeltData> beltModel = beltPartial.renderOnBelt(modelManager, lastState); InstancedModel<BeltData> beltModel = beltPartial.renderOnBelt(modelManager, lastState);
Consumer<BeltData> setupFunc = setupFunc(bottom, spriteShift);
keys.add(beltModel.createInstance(setupFunc)); keys.add(setup(beltModel.createInstance(), bottom, spriteShift));
if (diagonal) break; if (diagonal) break;
} }
@ -82,7 +81,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
if (tile.hasPulley()) { if (tile.hasPulley()) {
InstancedModel<RotatingData> pulleyModel = getPulleyModel(); InstancedModel<RotatingData> pulleyModel = getPulleyModel();
pulleyKey = pulleyModel.createInstance(setupFunc(tile.getSpeed(), getRotationAxis())); pulleyKey = setup(pulleyModel.createInstance(), tile.getSpeed(), getRotationAxis());
} }
} }
@ -94,9 +93,10 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
for (InstanceKey<BeltData> key : keys) { for (InstanceKey<BeltData> key : keys) {
SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); SpriteShiftEntry spriteShiftEntry = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
key.modifyInstance(data -> data.setScrollTexture(spriteShiftEntry) key.getInstance()
.setScrollTexture(spriteShiftEntry)
.setColor(tile.network) .setColor(tile.network)
.setRotationalSpeed(getScrollSpeed())); .setRotationalSpeed(getScrollSpeed());
bottom = false; bottom = false;
} }
@ -107,11 +107,9 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
@Override @Override
public void updateLight() { public void updateLight() {
for (InstanceKey<BeltData> key : keys) { keys.forEach(this::relight);
key.modifyInstance(this::relight);
}
if (pulleyKey != null) pulleyKey.modifyInstance(this::relight); if (pulleyKey != null) relight(pulleyKey);
} }
@Override @Override
@ -165,14 +163,13 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
return dir; return dir;
} }
private Consumer<BeltData> setupFunc(boolean bottom, SpriteShiftEntry spriteShift) { private InstanceKey<BeltData> setup(InstanceKey<BeltData> key, boolean bottom, SpriteShiftEntry spriteShift) {
return data -> {
float rotX = (!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0) + (beltSlope == BeltSlope.DOWNWARD ? 180 : 0); float rotX = (!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0) + (beltSlope == BeltSlope.DOWNWARD ? 180 : 0);
float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0); float rotY = facing.getHorizontalAngle() + (upward ? 180 : 0) + (sideways ? 90 : 0);
float rotZ = sideways ? 90 : ((vertical && facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) ? 180 : 0); float rotZ = sideways ? 90 : ((vertical && facing.getAxisDirection() == Direction.AxisDirection.NEGATIVE) ? 180 : 0);
BlockPos pos = tile.getPos(); key.getInstance()
data.setTileEntity(tile) .setTileEntity(tile)
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos)) .setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos)) .setSkyLight(world.getLightLevel(LightType.SKY, pos))
.setRotation(rotX, rotY, rotZ) .setRotation(rotX, rotY, rotZ)
@ -180,7 +177,8 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
.setRotationOffset(bottom ? 0.5f : 0f) .setRotationOffset(bottom ? 0.5f : 0f)
.setScrollTexture(spriteShift) .setScrollTexture(spriteShift)
.setScrollMult(diagonal ? 3f / 8f : 0.5f); .setScrollMult(diagonal ? 3f / 8f : 0.5f);
};
return key;
} }
} }

View file

@ -45,7 +45,7 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
float splitSpeed = speed * tile.getRotationSpeedModifier(dir); float splitSpeed = speed * tile.getRotationSpeedModifier(dir);
keys.add(half.createInstance(setupFunc(splitSpeed, boxAxis))); keys.add(setup(half.createInstance(), splitSpeed, boxAxis));
} }
} }
@ -63,9 +63,7 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
@Override @Override
public void updateLight() { public void updateLight() {
for (InstanceKey<RotatingData> key : keys) { keys.forEach(this::relight);
key.modifyInstance(this::relight);
}
} }
@Override @Override
@ -75,13 +73,12 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
} }
protected void updateRotation(InstanceKey<RotatingData> key, Direction dir) { protected void updateRotation(InstanceKey<RotatingData> key, Direction dir) {
key.modifyInstance(data -> {
Direction.Axis axis = dir.getAxis(); Direction.Axis axis = dir.getAxis();
data.setColor(tile.network) key.getInstance()
.setColor(tile.network)
.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir)) .setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir))
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
});
} }
} }

View file

@ -50,14 +50,16 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction); InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction);
InstanceKey<RotatingData> key = shaft.createInstance(data -> { InstanceKey<RotatingData> key = shaft.createInstance();
data.setBlockLight(blockLight)
key.getInstance()
.setBlockLight(blockLight)
.setSkyLight(skyLight) .setSkyLight(skyLight)
.setRotationalSpeed(getSpeed(direction)) .setRotationalSpeed(getSpeed(direction))
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()) .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
.setTileEntity(tile); .setTileEntity(tile);
});
keys.put(direction, key); keys.put(direction, key);
} }
} }
@ -87,15 +89,15 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
public void onUpdate() { public void onUpdate() {
updateSourceFacing(); updateSourceFacing();
for (Map.Entry<Direction, InstanceKey<RotatingData>> key : keys.entrySet()) { for (Map.Entry<Direction, InstanceKey<RotatingData>> key : keys.entrySet()) {
key.getValue().modifyInstance(data -> {
Direction direction = key.getKey(); Direction direction = key.getKey();
Direction.Axis axis = direction.getAxis(); Direction.Axis axis = direction.getAxis();
data.setColor(tile.network) key.getValue()
.getInstance()
.setColor(tile.network)
.setRotationalSpeed(getSpeed(direction)) .setRotationalSpeed(getSpeed(direction))
.setRotationOffset(getRotationOffset(axis)) .setRotationOffset(getRotationOffset(axis))
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector()); .setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
});
} }
} }
@ -105,7 +107,9 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos); int skyLight = tile.getWorld().getLightLevel(LightType.SKY, pos);
for (InstanceKey<RotatingData> key : keys.values()) { for (InstanceKey<RotatingData> key : keys.values()) {
key.modifyInstance(data -> data.setBlockLight(blockLight).setSkyLight(skyLight)); key.getInstance()
.setBlockLight(blockLight)
.setSkyLight(skyLight);
} }
} }

View file

@ -53,8 +53,10 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
float intensity = segment == 3 ? 1.5f : segment + 1; float intensity = segment == 3 ? 1.5f : segment + 1;
float segmentOffset = -3 / 16f * segment; float segmentOffset = -3 / 16f * segment;
flaps.add(model.createInstance(flapData -> { InstanceKey<FlapData> key = model.createInstance();
flapData.setPosition(pos)
key.getInstance()
.setPosition(pos)
.setSegmentOffset(segmentOffset, 0, 0) .setSegmentOffset(segmentOffset, 0, 0)
.setBlockLight(blockLight) .setBlockLight(blockLight)
.setSkyLight(skyLight) .setSkyLight(skyLight)
@ -63,7 +65,8 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
.setFlapScale(flapScale) .setFlapScale(flapScale)
.setPivotVoxelSpace(0, 10, 1) .setPivotVoxelSpace(0, 10, 1)
.setIntensity(intensity); .setIntensity(intensity);
}));
flaps.add(key);
} }
tunnelFlaps.put(direction, flaps); tunnelFlaps.put(direction, flaps);
@ -80,7 +83,7 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
float flapness = flapValue.get(AnimationTickHolder.getPartialTicks()); float flapness = flapValue.get(AnimationTickHolder.getPartialTicks());
for (InstanceKey<FlapData> key : keys) { for (InstanceKey<FlapData> key : keys) {
key.modifyInstance(data -> data.setFlapness(flapness)); key.getInstance().setFlapness(flapness);
} }
}); });
} }
@ -95,8 +98,8 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
for (ArrayList<InstanceKey<FlapData>> instanceKeys : tunnelFlaps.values()) { for (ArrayList<InstanceKey<FlapData>> instanceKeys : tunnelFlaps.values()) {
for (InstanceKey<FlapData> it : instanceKeys) { for (InstanceKey<FlapData> it : instanceKeys) {
it.modifyInstance(data -> data.setBlockLight(blockLight) it.getInstance().setBlockLight(blockLight)
.setSkyLight(skyLight)); .setSkyLight(skyLight);
} }
} }
} }

View file

@ -48,7 +48,10 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
float intensity = segment == 3 ? 1.5f : segment + 1; float intensity = segment == 3 ? 1.5f : segment + 1;
float segmentOffset = -3 / 16f * segment; float segmentOffset = -3 / 16f * segment;
flaps.add(model.createInstance(flapData -> flapData.setPosition(pos) InstanceKey<FlapData> key = model.createInstance();
key.getInstance()
.setPosition(pos)
.setSegmentOffset(segmentOffset, 0, -tile.getFlapOffset()) .setSegmentOffset(segmentOffset, 0, -tile.getFlapOffset())
.setBlockLight(blockLight) .setBlockLight(blockLight)
.setSkyLight(skyLight) .setSkyLight(skyLight)
@ -56,7 +59,9 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
.setFlapness(flapness) .setFlapness(flapness)
.setFlapScale(-1) .setFlapScale(-1)
.setPivotVoxelSpace(0, 10, 9.5f) .setPivotVoxelSpace(0, 10, 9.5f)
.setIntensity(intensity))); .setIntensity(intensity);
flaps.add(key);
} }
} }
@ -67,7 +72,7 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks()); float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks());
for (InstanceKey<FlapData> key : flaps) { for (InstanceKey<FlapData> key : flaps) {
key.modifyInstance(data -> data.setFlapness(flapness)); key.getInstance().setFlapness(flapness);
} }
} }
@ -79,8 +84,9 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
int skyLight = world.getLightLevel(LightType.SKY, pos); int skyLight = world.getLightLevel(LightType.SKY, pos);
for (InstanceKey<FlapData> it : flaps) { for (InstanceKey<FlapData> it : flaps) {
it.modifyInstance(data -> data.setBlockLight(blockLight) it.getInstance()
.setSkyLight(skyLight)); .setBlockLight(blockLight)
.setSkyLight(skyLight);
} }
} }

View file

@ -21,10 +21,6 @@ public class InstanceKey<D extends InstanceData> {
return index != INVALID; return index != INVALID;
} }
public void modifyInstance(Consumer<D> edit) {
model.modifyInstance(this, edit);
}
public D getInstance() { public D getInstance() {
return model.getInstance(this); return model.getInstance(this);
} }

View file

@ -85,16 +85,6 @@ public abstract class InstancedModel<D extends InstanceData> extends BufferedMod
return this.data.get(key.index); return this.data.get(key.index);
} }
public synchronized void modifyInstance(InstanceKey<D> key, Consumer<D> edit) {
verifyKey(key);
D data = this.data.get(key.index);
edit.accept(data);
markIndexChanged(key.index);
}
public synchronized InstanceKey<D> createInstance() { public synchronized InstanceKey<D> createInstance() {
D instanceData = newInstance(); D instanceData = newInstance();
@ -107,19 +97,6 @@ public abstract class InstancedModel<D extends InstanceData> extends BufferedMod
return key; return key;
} }
public synchronized InstanceKey<D> createInstance(Consumer<D> setup) {
D instanceData = newInstance();
setup.accept(instanceData);
InstanceKey<D> key = new InstanceKey<>(this, data.size());
data.add(instanceData);
keys.add(key);
markIndexChanged(key.index);
return key;
}
protected void doRender() { protected void doRender() {
vao.with(vao -> { vao.with(vao -> {
renderSetup(); renderSetup();