use of com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock in project Create by Creators-of-Create.
the class Contraption method moveBlock.
/**
* move the first block in frontier queue
*/
protected boolean moveBlock(Level world, @Nullable Direction forcedDirection, Queue<BlockPos> frontier, Set<BlockPos> visited) throws AssemblyException {
BlockPos pos = frontier.poll();
if (pos == null)
return false;
visited.add(pos);
if (world.isOutsideBuildHeight(pos))
return true;
if (!world.isLoaded(pos))
throw AssemblyException.unloadedChunk(pos);
if (isAnchoringBlockAt(pos))
return true;
BlockState state = world.getBlockState(pos);
if (!BlockMovementChecks.isMovementNecessary(state, world, pos))
return true;
if (!movementAllowed(state, world, pos))
throw AssemblyException.unmovableBlock(pos, state);
if (state.getBlock() instanceof AbstractChassisBlock && !moveChassis(world, pos, forcedDirection, frontier, visited))
return false;
if (AllBlocks.BELT.has(state))
moveBelt(pos, frontier, visited, state);
if (AllBlocks.GANTRY_CARRIAGE.has(state))
moveGantryPinion(world, pos, frontier, visited, state);
if (AllBlocks.GANTRY_SHAFT.has(state))
moveGantryShaft(world, pos, frontier, visited, state);
if (AllBlocks.STICKER.has(state) && state.getValue(StickerBlock.EXTENDED)) {
Direction offset = state.getValue(StickerBlock.FACING);
BlockPos attached = pos.relative(offset);
if (!visited.contains(attached) && !BlockMovementChecks.isNotSupportive(world.getBlockState(attached), offset.getOpposite()))
frontier.add(attached);
}
// Double Chest halves stick together
if (state.hasProperty(ChestBlock.TYPE) && state.hasProperty(ChestBlock.FACING) && state.getValue(ChestBlock.TYPE) != ChestType.SINGLE) {
Direction offset = ChestBlock.getConnectedDirection(state);
BlockPos attached = pos.relative(offset);
if (!visited.contains(attached))
frontier.add(attached);
}
// Bearings potentially create stabilized sub-contraptions
if (AllBlocks.MECHANICAL_BEARING.has(state))
moveBearing(pos, frontier, visited, state);
// WM Bearings attach their structure when moved
if (AllBlocks.WINDMILL_BEARING.has(state))
moveWindmillBearing(pos, frontier, visited, state);
// Seats transfer their passenger to the contraption
if (state.getBlock() instanceof SeatBlock)
moveSeat(world, pos);
// Pulleys drag their rope and their attached structure
if (state.getBlock() instanceof PulleyBlock)
movePulley(world, pos, frontier, visited);
// Pistons drag their attaches poles and extension
if (state.getBlock() instanceof MechanicalPistonBlock)
if (!moveMechanicalPiston(world, pos, frontier, visited, state))
return false;
if (isExtensionPole(state))
movePistonPole(world, pos, frontier, visited, state);
if (isPistonHead(state))
movePistonHead(world, pos, frontier, visited, state);
// Cart assemblers attach themselves
BlockPos posDown = pos.below();
BlockState stateBelow = world.getBlockState(posDown);
if (!visited.contains(posDown) && AllBlocks.CART_ASSEMBLER.has(stateBelow))
frontier.add(posDown);
Map<Direction, SuperGlueEntity> superglue = SuperGlueHandler.gatherGlue(world, pos);
// Slime blocks and super glue drag adjacent blocks if possible
for (Direction offset : Iterate.directions) {
BlockPos offsetPos = pos.relative(offset);
BlockState blockState = world.getBlockState(offsetPos);
if (isAnchoringBlockAt(offsetPos))
continue;
if (!movementAllowed(blockState, world, offsetPos)) {
if (offset == forcedDirection)
throw AssemblyException.unmovableBlock(pos, state);
continue;
}
boolean wasVisited = visited.contains(offsetPos);
boolean faceHasGlue = superglue.containsKey(offset);
boolean blockAttachedTowardsFace = BlockMovementChecks.isBlockAttachedTowards(blockState, world, offsetPos, offset.getOpposite());
boolean brittle = BlockMovementChecks.isBrittle(blockState);
boolean canStick = !brittle && state.canStickTo(blockState) && blockState.canStickTo(state);
if (canStick) {
if (state.getPistonPushReaction() == PushReaction.PUSH_ONLY || blockState.getPistonPushReaction() == PushReaction.PUSH_ONLY) {
canStick = false;
}
if (BlockMovementChecks.isNotSupportive(state, offset)) {
canStick = false;
}
if (BlockMovementChecks.isNotSupportive(blockState, offset.getOpposite())) {
canStick = false;
}
}
if (!wasVisited && (canStick || blockAttachedTowardsFace || faceHasGlue || (offset == forcedDirection && !BlockMovementChecks.isNotSupportive(state, forcedDirection))))
frontier.add(offsetPos);
if (faceHasGlue)
addGlue(superglue.get(offset));
}
addBlock(pos, capture(world, pos));
if (blocks.size() <= AllConfigs.SERVER.kinetics.maxBlocksMoved.get())
return true;
else
throw AssemblyException.structureTooLarge();
}
Aggregations