mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
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:
parent
d0e5be24d7
commit
8ce0f47f01
13 changed files with 164 additions and 200 deletions
|
@ -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,28 +17,29 @@ 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()
|
||||||
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
|
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
|
||||||
|
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float getRotationOffset(final Direction.Axis axis) {
|
protected float getRotationOffset(final Direction.Axis axis) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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();
|
model.getInstance(model.createInstance())
|
||||||
data.setPosition(context.localPos)
|
.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
|
||||||
|
|
|
@ -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);
|
model.getInstance(model.createInstance())
|
||||||
data.setPosition(context.localPos)
|
.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,
|
||||||
|
|
|
@ -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);
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
|
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||||
|
.setTileEntity(tile);
|
||||||
|
|
||||||
data.setRotationalSpeed(tile.getSpeed())
|
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
|
||||||
.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();
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
fan.getInstance()
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
.setRotationalSpeed(getFanSpeed())
|
||||||
.setTileEntity(tile)
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
.setBlockLight(blockLight)
|
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||||
.setSkyLight(skyLight);
|
.setTileEntity(tile);
|
||||||
});
|
|
||||||
|
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());
|
putLight(shaft, behind);
|
||||||
int blockLight = world.getLightLevel(LightType.BLOCK, behind);
|
|
||||||
int skyLight = world.getLightLevel(LightType.SKY, behind);
|
BlockPos inFront = pos.offset(direction);
|
||||||
data.setBlockLight(blockLight)
|
putLight(fan, inFront);
|
||||||
.setSkyLight(skyLight);
|
}
|
||||||
});
|
|
||||||
fan.modifyInstance(data -> {
|
private void putLight(InstanceKey<RotatingData> key, BlockPos pos) {
|
||||||
BlockPos inFront = pos.offset(direction);
|
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
|
||||||
int blockLight = world.getLightLevel(LightType.BLOCK, inFront);
|
int skyLight = world.getLightLevel(LightType.SKY, pos);
|
||||||
int skyLight = world.getLightLevel(LightType.SKY, inFront);
|
|
||||||
data.setBlockLight(blockLight)
|
key.getInstance()
|
||||||
.setSkyLight(skyLight);
|
.setBlockLight(blockLight)
|
||||||
});
|
.setSkyLight(skyLight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
.setColor(tile.network)
|
.setScrollTexture(spriteShiftEntry)
|
||||||
.setRotationalSpeed(getScrollSpeed()));
|
.setColor(tile.network)
|
||||||
|
.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,22 +163,22 @@ 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)
|
||||||
.setRotationalSpeed(getScrollSpeed())
|
.setRotationalSpeed(getScrollSpeed())
|
||||||
.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir))
|
.setColor(tile.network)
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
.setRotationalSpeed(tile.getSpeed() * tile.getRotationSpeedModifier(dir))
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
});
|
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
|
||||||
.setSkyLight(skyLight)
|
key.getInstance()
|
||||||
.setRotationalSpeed(getSpeed(direction))
|
.setBlockLight(blockLight)
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
.setSkyLight(skyLight)
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
.setRotationalSpeed(getSpeed(direction))
|
||||||
.setTileEntity(tile);
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
});
|
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector())
|
||||||
|
.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()
|
||||||
.setRotationalSpeed(getSpeed(direction))
|
.getInstance()
|
||||||
.setRotationOffset(getRotationOffset(axis))
|
.setColor(tile.network)
|
||||||
.setRotationAxis(Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis).getUnitVector());
|
.setRotationalSpeed(getSpeed(direction))
|
||||||
});
|
.setRotationOffset(getRotationOffset(axis))
|
||||||
|
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,17 +53,20 @@ 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)
|
|
||||||
.setSegmentOffset(segmentOffset, 0, 0)
|
key.getInstance()
|
||||||
.setBlockLight(blockLight)
|
.setPosition(pos)
|
||||||
.setSkyLight(skyLight)
|
.setSegmentOffset(segmentOffset, 0, 0)
|
||||||
.setHorizontalAngle(horizontalAngle)
|
.setBlockLight(blockLight)
|
||||||
.setFlapness(flapness)
|
.setSkyLight(skyLight)
|
||||||
.setFlapScale(flapScale)
|
.setHorizontalAngle(horizontalAngle)
|
||||||
.setPivotVoxelSpace(0, 10, 1)
|
.setFlapness(flapness)
|
||||||
.setIntensity(intensity);
|
.setFlapScale(flapScale)
|
||||||
}));
|
.setPivotVoxelSpace(0, 10, 1)
|
||||||
|
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,15 +48,20 @@ 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();
|
||||||
.setSegmentOffset(segmentOffset, 0, -tile.getFlapOffset())
|
|
||||||
.setBlockLight(blockLight)
|
key.getInstance()
|
||||||
.setSkyLight(skyLight)
|
.setPosition(pos)
|
||||||
.setHorizontalAngle(horizontalAngle)
|
.setSegmentOffset(segmentOffset, 0, -tile.getFlapOffset())
|
||||||
.setFlapness(flapness)
|
.setBlockLight(blockLight)
|
||||||
.setFlapScale(-1)
|
.setSkyLight(skyLight)
|
||||||
.setPivotVoxelSpace(0, 10, 9.5f)
|
.setHorizontalAngle(horizontalAngle)
|
||||||
.setIntensity(intensity)));
|
.setFlapness(flapness)
|
||||||
|
.setFlapScale(-1)
|
||||||
|
.setPivotVoxelSpace(0, 10, 9.5f)
|
||||||
|
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue