Search in sources :

Example 1 with MagnetBlock

use of com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock in project Create by Creators-of-Create.

the class Contraption method addBlocksToWorld.

public void addBlocksToWorld(Level world, StructureTransform transform) {
    for (boolean nonBrittles : Iterate.trueAndFalse) {
        for (StructureBlockInfo block : blocks.values()) {
            if (nonBrittles == BlockMovementChecks.isBrittle(block.state))
                continue;
            BlockPos targetPos = transform.apply(block.pos);
            BlockState state = transform.apply(block.state);
            if (customBlockPlacement(world, targetPos, state))
                continue;
            if (nonBrittles)
                for (Direction face : Iterate.directions) state = state.updateShape(face, world.getBlockState(targetPos.relative(face)), world, targetPos, targetPos.relative(face));
            BlockState blockState = world.getBlockState(targetPos);
            if (blockState.getDestroySpeed(world, targetPos) == -1 || (state.getCollisionShape(world, targetPos).isEmpty() && !blockState.getCollisionShape(world, targetPos).isEmpty())) {
                if (targetPos.getY() == 0)
                    targetPos = targetPos.above();
                world.levelEvent(2001, targetPos, Block.getId(state));
                Block.dropResources(state, world, targetPos, null);
                continue;
            }
            if (state.getBlock() instanceof SimpleWaterloggedBlock && state.hasProperty(BlockStateProperties.WATERLOGGED)) {
                FluidState FluidState = world.getFluidState(targetPos);
                state = state.setValue(BlockStateProperties.WATERLOGGED, FluidState.getType() == Fluids.WATER);
            }
            world.destroyBlock(targetPos, true);
            world.setBlock(targetPos, state, Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL);
            boolean verticalRotation = transform.rotationAxis == null || transform.rotationAxis.isHorizontal();
            verticalRotation = verticalRotation && transform.rotation != Rotation.NONE;
            if (verticalRotation) {
                if (state.getBlock() instanceof RopeBlock || state.getBlock() instanceof MagnetBlock)
                    world.destroyBlock(targetPos, true);
            }
            BlockEntity tileEntity = world.getBlockEntity(targetPos);
            CompoundTag tag = block.nbt;
            if (tileEntity != null)
                tag = NBTProcessors.process(tileEntity, tag, false);
            if (tileEntity != null && tag != null) {
                tag.putInt("x", targetPos.getX());
                tag.putInt("y", targetPos.getY());
                tag.putInt("z", targetPos.getZ());
                if (verticalRotation && tileEntity instanceof PulleyTileEntity) {
                    tag.remove("Offset");
                    tag.remove("InitialOffset");
                }
                if (tileEntity instanceof IMultiTileContainer && tag.contains("LastKnownPos"))
                    tag.put("LastKnownPos", NbtUtils.writeBlockPos(BlockPos.ZERO.below(Integer.MAX_VALUE - 1)));
                tileEntity.load(tag);
                if (storage.containsKey(block.pos)) {
                    MountedStorage mountedStorage = storage.get(block.pos);
                    if (mountedStorage.isValid())
                        mountedStorage.addStorageToWorld(tileEntity);
                }
                if (fluidStorage.containsKey(block.pos)) {
                    MountedFluidStorage mountedStorage = fluidStorage.get(block.pos);
                    if (mountedStorage.isValid())
                        mountedStorage.addStorageToWorld(tileEntity);
                }
            }
            transform.apply(tileEntity);
        }
    }
    for (StructureBlockInfo block : blocks.values()) {
        if (!shouldUpdateAfterMovement(block))
            continue;
        BlockPos targetPos = transform.apply(block.pos);
        world.markAndNotifyBlock(targetPos, world.getChunkAt(targetPos), block.state, block.state, Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL, 512);
    }
    for (int i = 0; i < inventory.getSlots(); i++) {
        if (!inventory.isSlotExternal(i))
            inventory.setStackInSlot(i, ItemStack.EMPTY);
    }
    for (int i = 0; i < fluidInventory.getTanks(); i++) fluidInventory.drain(fluidInventory.getFluidInTank(i), FluidAction.EXECUTE);
    for (Pair<BlockPos, Direction> pair : superglue) {
        BlockPos targetPos = transform.apply(pair.getKey());
        Direction targetFacing = transform.transformFacing(pair.getValue());
        SuperGlueEntity entity = new SuperGlueEntity(world, targetPos, targetFacing);
        if (entity.onValidSurface()) {
            if (!world.isClientSide)
                world.addFreshEntity(entity);
        }
    }
}
Also used : MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) IMultiTileContainer(com.simibubi.create.foundation.tileEntity.IMultiTileContainer) Direction(net.minecraft.core.Direction) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) PulleyTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity) BlockState(net.minecraft.world.level.block.state.BlockState) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) BlockPos(net.minecraft.core.BlockPos) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) CompoundTag(net.minecraft.nbt.CompoundTag) FluidState(net.minecraft.world.level.material.FluidState) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with MagnetBlock

use of com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock in project Create by Creators-of-Create.

the class Contraption method movePulley.

private void movePulley(Level world, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited) {
    int limit = AllConfigs.SERVER.kinetics.maxRopeLength.get();
    BlockPos ropePos = pos;
    while (limit-- >= 0) {
        ropePos = ropePos.below();
        if (!world.isLoaded(ropePos))
            break;
        BlockState ropeState = world.getBlockState(ropePos);
        Block block = ropeState.getBlock();
        if (!(block instanceof RopeBlock) && !(block instanceof MagnetBlock)) {
            if (!visited.contains(ropePos))
                frontier.add(ropePos);
            break;
        }
        addBlock(ropePos, capture(world, ropePos));
    }
}
Also used : MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) BlockState(net.minecraft.world.level.block.state.BlockState) BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) ChestBlock(net.minecraft.world.level.block.ChestBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) WindmillBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock) MechanicalPistonHeadBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock) GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) StickerBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock) MechanicalBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock) RedstoneContactBlock(com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock) PressurePlateBlock(net.minecraft.world.level.block.PressurePlateBlock) GantryCarriageBlock(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) PistonExtensionPoleBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock) ButtonBlock(net.minecraft.world.level.block.ButtonBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock)

Aggregations

MagnetBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock)2 RopeBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock)2 BlockPos (net.minecraft.core.BlockPos)2 SimpleWaterloggedBlock (net.minecraft.world.level.block.SimpleWaterloggedBlock)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)1 MechanicalBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock)1 WindmillBearingBlock (com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock)1 AbstractChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock)1 StickerBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock)1 GantryCarriageBlock (com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock)1 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)1 MechanicalPistonBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock)1 MechanicalPistonHeadBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock)1 PistonExtensionPoleBlock (com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock)1 PulleyBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock)1 PulleyTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity)1 GantryShaftBlock (com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock)1 BeltBlock (com.simibubi.create.content.contraptions.relays.belt.BeltBlock)1 RedstoneContactBlock (com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock)1