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; return state;
boolean connect = AllBlocks.GANTRY_SHAFT.has(neighbour) && neighbour.get(FACING) == facing; 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 (direction.getAxisDirection() == facing.getAxisDirection()) {
if (connect) { if (connect) {
if (part == Part.END) 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); return state.with(PART, part);
} }
@ -260,7 +267,7 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
return super.areStatesKineticallyEquivalent(oldState, newState) return super.areStatesKineticallyEquivalent(oldState, newState)
&& oldState.get(POWERED) == newState.get(POWERED); && oldState.get(POWERED) == newState.get(POWERED);
} }
@Override @Override
public float getParticleTargetRadius() { public float getParticleTargetRadius() {
return .35f; return .35f;
@ -270,7 +277,7 @@ public class GantryShaftBlock extends DirectionalKineticBlock {
public float getParticleInitialRadius() { public float getParticleInitialRadius() {
return .25f; return .25f;
} }
@Override @Override
public boolean allowsMovement(BlockState state, IBlockReader reader, BlockPos pos, PathType type) { public boolean allowsMovement(BlockState state, IBlockReader reader, BlockPos pos, PathType type) {
return false; return false;

View file

@ -19,15 +19,12 @@ public class GantryShaftTileEntity extends KineticTileEntity {
super(typeIn); super(typeIn);
} }
@Override public void checkAttachedCarriageBlocks(boolean willBeMiddle) {
public void onSpeedChanged(float previousSpeed) { if (!canAssembleOn(willBeMiddle))
super.onSpeedChanged(previousSpeed);
if (!canAssembleOn())
return; return;
for (Direction d : Iterate.directions) { for (Direction d : Iterate.directions) {
if (d.getAxis() == getBlockState().get(GantryShaftBlock.FACING) if (d.getAxis() == getBlockState().get(GantryShaftBlock.FACING)
.getAxis()) .getAxis())
continue; continue;
BlockPos offset = pos.offset(d); BlockPos offset = pos.offset(d);
BlockState pinionState = world.getBlockState(offset); BlockState pinionState = world.getBlockState(offset);
@ -39,7 +36,12 @@ public class GantryShaftTileEntity extends KineticTileEntity {
if (tileEntity instanceof GantryCarriageTileEntity) if (tileEntity instanceof GantryCarriageTileEntity)
((GantryCarriageTileEntity) tileEntity).queueAssembly(); ((GantryCarriageTileEntity) tileEntity).queueAssembly();
} }
}
@Override
public void onSpeedChanged(float previousSpeed) {
super.onSpeedChanged(previousSpeed);
checkAttachedCarriageBlocks(false);
} }
@Override @Override
@ -73,6 +75,10 @@ public class GantryShaftTileEntity extends KineticTileEntity {
} }
public boolean canAssembleOn() { public boolean canAssembleOn() {
return canAssembleOn(false);
}
public boolean canAssembleOn(boolean willBeMiddle) {
BlockState blockState = getBlockState(); BlockState blockState = getBlockState();
if (!AllBlocks.GANTRY_SHAFT.has(blockState)) if (!AllBlocks.GANTRY_SHAFT.has(blockState))
return false; return false;
@ -80,6 +86,9 @@ public class GantryShaftTileEntity extends KineticTileEntity {
return false; return false;
float speed = getPinionMovementSpeed(); float speed = getPinionMovementSpeed();
if (willBeMiddle)
return speed != 0;
switch (blockState.get(GantryShaftBlock.PART)) { switch (blockState.get(GantryShaftBlock.PART)) {
case END: case END:
return speed < 0; return speed < 0;
@ -99,7 +108,7 @@ public class GantryShaftTileEntity extends KineticTileEntity {
return 0; return 0;
return MathHelper.clamp(-getSpeed() / 512f, -.49f, .49f); return MathHelper.clamp(-getSpeed() / 512f, -.49f, .49f);
} }
@Override @Override
protected boolean isNoisy() { protected boolean isNoisy() {
return false; return false;