Search in sources :

Example 1 with AssemblyException

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();
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 2 with AssemblyException

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);
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) MountedContraption(com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption) OrientedContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity) CartAssemblerTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity) Direction(net.minecraft.core.Direction)

Example 3 with AssemblyException

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);
    }
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) OrientedContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity) Vec3(net.minecraft.world.phys.Vec3) MinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController) CapabilityMinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController) Direction(net.minecraft.core.Direction) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 4 with AssemblyException

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);
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) BlockState(net.minecraft.world.level.block.state.BlockState) GantryShaftTileEntity(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 5 with AssemblyException

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();
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Aggregations

AssemblyException (com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException)6 Direction (net.minecraft.core.Direction)5 BlockPos (net.minecraft.core.BlockPos)4 OrientedContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 Vec3 (net.minecraft.world.phys.Vec3)2 IDisplayAssemblyExceptions (com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions)1 CartAssemblerTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity)1 MountedContraption (com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption)1 CapabilityMinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController)1 MinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController)1 GantryShaftTileEntity (com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 TextComponent (net.minecraft.network.chat.TextComponent)1 MinecartFurnace (net.minecraft.world.entity.vehicle.MinecartFurnace)1 ClipContext (net.minecraft.world.level.ClipContext)1 Level (net.minecraft.world.level.Level)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1