Assemble gantry carriage when shaft is extended

This commit is contained in:
reidbhuntley 2021-05-21 00:46:35 -04:00
parent 305b16fea9
commit d0040260d7
2 changed files with 26 additions and 10 deletions

View file

@ -98,7 +98,7 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
return state;
boolean connect = AllBlocks.GANTRY_SHAFT.has(neighbour) && neighbour.get(FACING) == facing;
Part part = state.get(PART);
Part part = state.get(PART), prevPart = part;
if (direction.getAxisDirection() == facing.getAxisDirection()) {
if (connect) {
if (part == Part.END)
@ -125,6 +125,13 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
}
}
if (!world.isRemote() && part == Part.MIDDLE && prevPart != Part.MIDDLE) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof GantryShaftTileEntity) {
((GantryShaftTileEntity)te).checkAttachedCarriageBlocks(true);
}
}
return state.with(PART, part);
}

View file

@ -19,11 +19,8 @@ public class GantryShaftTileEntity extends KineticTileEntity {
super(typeIn);
}
@Override
public void onSpeedChanged(float previousSpeed) {
super.onSpeedChanged(previousSpeed);
if (!canAssembleOn())
public void checkAttachedCarriageBlocks(boolean willBeMiddle) {
if (!canAssembleOn(willBeMiddle))
return;
for (Direction d : Iterate.directions) {
if (d.getAxis() == getBlockState().get(GantryShaftBlock.FACING)
@ -39,7 +36,12 @@ public class GantryShaftTileEntity extends KineticTileEntity {
if (tileEntity instanceof GantryCarriageTileEntity)
((GantryCarriageTileEntity) tileEntity).queueAssembly();
}
}
@Override
public void onSpeedChanged(float previousSpeed) {
super.onSpeedChanged(previousSpeed);
checkAttachedCarriageBlocks(false);
}
@Override
@ -73,6 +75,10 @@ public class GantryShaftTileEntity extends KineticTileEntity {
}
public boolean canAssembleOn() {
return canAssembleOn(false);
}
public boolean canAssembleOn(boolean willBeMiddle) {
BlockState blockState = getBlockState();
if (!AllBlocks.GANTRY_SHAFT.has(blockState))
return false;
@ -80,6 +86,9 @@ public class GantryShaftTileEntity extends KineticTileEntity {
return false;
float speed = getPinionMovementSpeed();
if (willBeMiddle)
return speed != 0;
switch (blockState.get(GantryShaftBlock.PART)) {
case END:
return speed < 0;