use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project Create by Creators-of-Create.
the class ClockworkBearingTileEntity method assemble.
public void assemble() {
if (!(level.getBlockState(worldPosition).getBlock() instanceof ClockworkBearingBlock))
return;
Direction direction = getBlockState().getValue(BlockStateProperties.FACING);
// Collect Construct
Pair<ClockworkContraption, ClockworkContraption> contraption;
try {
contraption = ClockworkContraption.assembleClockworkAt(level, worldPosition, direction);
lastException = null;
} catch (AssemblyException e) {
lastException = e;
sendData();
return;
}
if (contraption == null)
return;
if (contraption.getLeft() == null)
return;
if (contraption.getLeft().getBlocks().isEmpty())
return;
BlockPos anchor = worldPosition.relative(direction);
contraption.getLeft().removeBlocksFromWorld(level, BlockPos.ZERO);
hourHand = ControlledContraptionEntity.create(level, this, contraption.getLeft());
hourHand.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
hourHand.setRotationAxis(direction.getAxis());
level.addFreshEntity(hourHand);
AllTriggers.triggerForNearbyPlayers(AllTriggers.CLOCKWORK_BEARING, level, worldPosition, 5);
if (contraption.getRight() != null) {
anchor = worldPosition.relative(direction, contraption.getRight().offset + 1);
contraption.getRight().removeBlocksFromWorld(level, BlockPos.ZERO);
minuteHand = ControlledContraptionEntity.create(level, this, contraption.getRight());
minuteHand.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
minuteHand.setRotationAxis(direction.getAxis());
level.addFreshEntity(minuteHand);
}
// Run
running = true;
hourAngle = 0;
minuteAngle = 0;
sendData();
}
use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project LittleContraptions by EDToaster.
the class BargeAssemblerBlockEntity method assemble.
protected void assemble(Level world, BlockPos pos, ContraptionBargeEntity barge) {
if (!barge.getPassengers().isEmpty())
return;
CartAssemblerTileEntity.CartMovementMode mode = CartAssemblerTileEntity.CartMovementMode.ROTATE;
MountedContraption contraption = new MountedContraption(mode);
try {
if (!contraption.assemble(world, pos)) {
return;
}
lastException = null;
} catch (AssemblyException e) {
lastException = e;
e.printStackTrace();
return;
}
Direction initialOrientation = BargeAssemblerBlock.getHorizontalDirection(getBlockState());
contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
contraption.startMoving(world);
contraption.expandBoundsAroundAxis(Direction.Axis.Y);
OrientedContraptionEntity entity = OrientedContraptionEntity.create(world, contraption, initialOrientation);
entity.setPos(pos.getX(), pos.getY(), pos.getZ());
world.addFreshEntity(entity);
entity.startRiding(barge);
}
use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project Create by Creators-of-Create.
the class CartAssemblerTileEntity method assemble.
protected void assemble(Level world, BlockPos pos, AbstractMinecart cart) {
if (!cart.getPassengers().isEmpty())
return;
LazyOptional<MinecartController> optional = cart.getCapability(CapabilityMinecartController.MINECART_CONTROLLER_CAPABILITY);
if (optional.isPresent() && optional.orElse(null).isCoupledThroughContraption())
return;
CartMovementMode mode = CartMovementMode.values()[movementMode.value];
MountedContraption contraption = new MountedContraption(mode);
try {
if (!contraption.assemble(world, pos))
return;
lastException = null;
sendData();
} catch (AssemblyException e) {
lastException = e;
sendData();
return;
}
boolean couplingFound = contraption.connectedCart != null;
Direction initialOrientation = CartAssemblerBlock.getHorizontalDirection(getBlockState());
if (couplingFound) {
cart.setPos(pos.getX() + .5f, pos.getY(), pos.getZ() + .5f);
if (!CouplingHandler.tryToCoupleCarts(null, world, cart.getId(), contraption.connectedCart.getId()))
return;
}
contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
contraption.startMoving(world);
contraption.expandBoundsAroundAxis(Axis.Y);
if (couplingFound) {
Vec3 diff = contraption.connectedCart.position().subtract(cart.position());
initialOrientation = Direction.fromYRot(Mth.atan2(diff.z, diff.x) * 180 / Math.PI);
}
OrientedContraptionEntity entity = OrientedContraptionEntity.create(world, contraption, initialOrientation);
if (couplingFound)
entity.setCouplingId(cart.getUUID());
entity.setPos(pos.getX(), pos.getY(), pos.getZ());
world.addFreshEntity(entity);
entity.startRiding(cart);
if (cart instanceof MinecartFurnace) {
CompoundTag nbt = cart.serializeNBT();
nbt.putDouble("PushZ", 0);
nbt.putDouble("PushX", 0);
cart.deserializeNBT(nbt);
}
}
use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project Create by Creators-of-Create.
the class GantryCarriageTileEntity method tryAssemble.
private void tryAssemble() {
BlockState blockState = getBlockState();
if (!(blockState.getBlock() instanceof GantryCarriageBlock))
return;
Direction direction = blockState.getValue(GantryCarriageBlock.FACING);
GantryContraption contraption = new GantryContraption(direction);
BlockEntity shaftTe = level.getBlockEntity(worldPosition.relative(direction.getOpposite()));
if (!(shaftTe instanceof GantryShaftTileEntity))
return;
BlockState shaftState = shaftTe.getBlockState();
if (!AllBlocks.GANTRY_SHAFT.has(shaftState))
return;
float pinionMovementSpeed = ((GantryShaftTileEntity) shaftTe).getPinionMovementSpeed();
Direction shaftOrientation = shaftState.getValue(GantryShaftBlock.FACING);
Direction movementDirection = shaftOrientation;
if (pinionMovementSpeed < 0)
movementDirection = movementDirection.getOpposite();
try {
lastException = null;
if (!contraption.assemble(level, worldPosition))
return;
sendData();
} catch (AssemblyException e) {
lastException = e;
sendData();
return;
}
if (ContraptionCollider.isCollidingWithWorld(level, contraption, worldPosition.relative(movementDirection), movementDirection))
return;
contraption.removeBlocksFromWorld(level, BlockPos.ZERO);
GantryContraptionEntity movedContraption = GantryContraptionEntity.create(level, contraption, shaftOrientation);
BlockPos anchor = worldPosition;
movedContraption.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
AllSoundEvents.CONTRAPTION_ASSEMBLE.playOnServer(level, worldPosition);
level.addFreshEntity(movedContraption);
}
use of com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException in project Create by Creators-of-Create.
the class MechanicalBearingTileEntity method assemble.
public void assemble() {
if (!(level.getBlockState(worldPosition).getBlock() instanceof BearingBlock))
return;
Direction direction = getBlockState().getValue(BearingBlock.FACING);
BearingContraption contraption = new BearingContraption(isWindmill(), direction);
try {
if (!contraption.assemble(level, worldPosition))
return;
lastException = null;
} catch (AssemblyException e) {
lastException = e;
sendData();
return;
}
if (isWindmill())
AllTriggers.triggerForNearbyPlayers(AllTriggers.WINDMILL, level, worldPosition, 5);
if (contraption.getSailBlocks() >= 16 * 8)
AllTriggers.triggerForNearbyPlayers(AllTriggers.MAXED_WINDMILL, level, worldPosition, 5);
contraption.removeBlocksFromWorld(level, BlockPos.ZERO);
movedContraption = ControlledContraptionEntity.create(level, this, contraption);
BlockPos anchor = worldPosition.relative(direction);
movedContraption.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
movedContraption.setRotationAxis(direction.getAxis());
level.addFreshEntity(movedContraption);
AllSoundEvents.CONTRAPTION_ASSEMBLE.playOnServer(level, worldPosition);
running = true;
angle = 0;
sendData();
updateGeneratedRotation();
}
Aggregations