Search in sources :

Example 1 with SeatBlock

use of com.simibubi.create.content.contraptions.components.actors.SeatBlock 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();
}
Also used : SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) BlockState(net.minecraft.world.level.block.state.BlockState) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock)

Example 2 with SeatBlock

use of com.simibubi.create.content.contraptions.components.actors.SeatBlock in project Create by Creators-of-Create.

the class Contraption method addPassengersToWorld.

public void addPassengersToWorld(Level world, StructureTransform transform, List<Entity> seatedEntities) {
    for (Entity seatedEntity : seatedEntities) {
        if (getSeatMapping().isEmpty())
            continue;
        Integer seatIndex = getSeatMapping().get(seatedEntity.getUUID());
        if (seatIndex == null)
            continue;
        BlockPos seatPos = getSeats().get(seatIndex);
        seatPos = transform.apply(seatPos);
        if (!(world.getBlockState(seatPos).getBlock() instanceof SeatBlock))
            continue;
        if (SeatBlock.isSeatOccupied(world, seatPos))
            continue;
        SeatBlock.sitDown(world, seatPos, seatedEntity);
    }
}
Also used : BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CreativeCrateTileEntity(com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity) SeatEntity(com.simibubi.create.content.contraptions.components.actors.SeatEntity) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) PulleyTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) Entity(net.minecraft.world.entity.Entity) ChassisTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) BlockPos(net.minecraft.core.BlockPos)

Aggregations

SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)2 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)2 BlockPos (net.minecraft.core.BlockPos)2 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)1 SeatEntity (com.simibubi.create.content.contraptions.components.actors.SeatEntity)1 AbstractChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock)1 ChassisTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity)1 MechanicalPistonBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock)1 PulleyBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock)1 PulleyTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity)1 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)1 CreativeCrateTileEntity (com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity)1 ItemVaultTileEntity (com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity)1 Direction (net.minecraft.core.Direction)1 Entity (net.minecraft.world.entity.Entity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 BlockState (net.minecraft.world.level.block.state.BlockState)1