Search in sources :

Example 1 with SimpleWaterloggedBlock

use of net.minecraft.world.level.block.SimpleWaterloggedBlock in project Create by Creators-of-Create.

the class PulleyTileEntity method assemble.

@Override
protected void assemble() throws AssemblyException {
    if (!(level.getBlockState(worldPosition).getBlock() instanceof PulleyBlock))
        return;
    if (speed == 0)
        return;
    int maxLength = AllConfigs.SERVER.kinetics.maxRopeLength.get();
    int i = 1;
    while (i <= maxLength) {
        BlockPos ropePos = worldPosition.below(i);
        BlockState ropeState = level.getBlockState(ropePos);
        if (!AllBlocks.ROPE.has(ropeState) && !AllBlocks.PULLEY_MAGNET.has(ropeState)) {
            break;
        }
        ++i;
    }
    offset = i - 1;
    if (offset >= getExtensionRange() && getSpeed() > 0)
        return;
    if (offset <= 0 && getSpeed() < 0)
        return;
    // Collect Construct
    if (!level.isClientSide) {
        needsContraption = false;
        BlockPos anchor = worldPosition.below(Mth.floor(offset + 1));
        initialOffset = Mth.floor(offset);
        PulleyContraption contraption = new PulleyContraption(initialOffset);
        boolean canAssembleStructure = contraption.assemble(level, anchor);
        if (canAssembleStructure) {
            Direction movementDirection = getSpeed() > 0 ? Direction.DOWN : Direction.UP;
            if (ContraptionCollider.isCollidingWithWorld(level, contraption, anchor.relative(movementDirection), movementDirection))
                canAssembleStructure = false;
        }
        if (!canAssembleStructure && getSpeed() > 0)
            return;
        for (i = ((int) offset); i > 0; i--) {
            BlockPos offset = worldPosition.below(i);
            BlockState oldState = level.getBlockState(offset);
            if (oldState.getBlock() instanceof SimpleWaterloggedBlock && oldState.hasProperty(BlockStateProperties.WATERLOGGED) && oldState.getValue(BlockStateProperties.WATERLOGGED)) {
                level.setBlock(offset, Blocks.WATER.defaultBlockState(), 66);
                continue;
            }
            level.setBlock(offset, Blocks.AIR.defaultBlockState(), 66);
        }
        if (!contraption.getBlocks().isEmpty()) {
            contraption.removeBlocksFromWorld(level, BlockPos.ZERO);
            movedContraption = ControlledContraptionEntity.create(level, this, contraption);
            movedContraption.setPos(anchor.getX(), anchor.getY(), anchor.getZ());
            level.addFreshEntity(movedContraption);
            forceMove = true;
            needsContraption = true;
        }
    }
    clientOffsetDiff = 0;
    running = true;
    sendData();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Example 2 with SimpleWaterloggedBlock

use of net.minecraft.world.level.block.SimpleWaterloggedBlock in project MoreBoots by North-West-Wind.

the class WaterBootsItem method onLivingUpdate.

@Override
public void onLivingUpdate(final LivingEvent.LivingUpdateEvent event) {
    LivingEntity entity = event.getEntityLiving();
    ItemStack boots = entity.getItemBySlot(EquipmentSlot.FEET);
    Vec3 pos = entity.position();
    BlockPos blockPos = new BlockPos(pos);
    BlockPos under = blockPos.below();
    FluidState underneath = entity.level.getFluidState(under);
    BlockState underneathBlock = entity.level.getBlockState(under);
    if (underneath.getType() instanceof LavaFluid && !(underneathBlock.getBlock() instanceof SimpleWaterloggedBlock)) {
        LavaFluid lava = (LavaFluid) underneath.getType();
        if (lava.isSource(underneath))
            entity.level.setBlockAndUpdate(under, Blocks.OBSIDIAN.defaultBlockState());
        else
            entity.level.setBlockAndUpdate(under, Blocks.COBBLESTONE.defaultBlockState());
        entity.playSound(SoundEvents.LAVA_EXTINGUISH, 1, 1);
        boots.hurtAndBreak(1, entity, playerEntity -> playerEntity.playSound(SoundEvents.ITEM_BREAK, 1, 1));
    } else if (entity.level.getBlockState(blockPos).getBlock().equals(Blocks.FIRE))
        entity.level.setBlockAndUpdate(blockPos, Blocks.AIR.defaultBlockState());
    if (entity.isInWater() && boots.getMaxDamage() - boots.getDamageValue() > 0 && entity.getRandom().nextInt(10) == 0)
        boots.setDamageValue(Math.max(boots.getDamageValue() - 2, 0));
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) FluidState(net.minecraft.world.level.material.FluidState) LavaFluid(net.minecraft.world.level.material.LavaFluid)

Example 3 with SimpleWaterloggedBlock

use of net.minecraft.world.level.block.SimpleWaterloggedBlock in project Create by Creators-of-Create.

the class Contraption method removeBlocksFromWorld.

public void removeBlocksFromWorld(Level world, BlockPos offset) {
    storage.values().forEach(MountedStorage::removeStorageFromWorld);
    fluidStorage.values().forEach(MountedFluidStorage::removeStorageFromWorld);
    glueToRemove.forEach(SuperGlueEntity::discard);
    for (boolean brittles : Iterate.trueAndFalse) {
        for (Iterator<StructureBlockInfo> iterator = blocks.values().iterator(); iterator.hasNext(); ) {
            StructureBlockInfo block = iterator.next();
            if (brittles != BlockMovementChecks.isBrittle(block.state))
                continue;
            BlockPos add = block.pos.offset(anchor).offset(offset);
            if (customBlockRemoval(world, add, block.state))
                continue;
            BlockState oldState = world.getBlockState(add);
            Block blockIn = oldState.getBlock();
            if (block.state.getBlock() != blockIn)
                iterator.remove();
            world.removeBlockEntity(add);
            int flags = Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_SUPPRESS_DROPS | Block.UPDATE_KNOWN_SHAPE | Block.UPDATE_CLIENTS | Block.UPDATE_IMMEDIATE;
            if (blockIn instanceof SimpleWaterloggedBlock && oldState.hasProperty(BlockStateProperties.WATERLOGGED) && oldState.getValue(BlockStateProperties.WATERLOGGED)) {
                world.setBlock(add, Blocks.WATER.defaultBlockState(), flags);
                continue;
            }
            world.setBlock(add, Blocks.AIR.defaultBlockState(), flags);
        }
    }
    for (StructureBlockInfo block : blocks.values()) {
        BlockPos add = block.pos.offset(anchor).offset(offset);
        // if (!shouldUpdateAfterMovement(block))
        // continue;
        int flags = Block.UPDATE_MOVE_BY_PISTON | Block.UPDATE_ALL;
        world.sendBlockUpdated(add, block.state, Blocks.AIR.defaultBlockState(), flags);
        // when the blockstate is set to air, the block's POI data is removed, but
        // markAndNotifyBlock tries to
        // remove it again, so to prevent an error from being logged by double-removal
        // we add the POI data back now
        // (code copied from ServerWorld.onBlockStateChange)
        ServerLevel serverWorld = (ServerLevel) world;
        PoiType.forState(block.state).ifPresent(poiType -> {
            world.getServer().execute(() -> {
                serverWorld.getPoiManager().add(add, poiType);
                DebugPackets.sendPoiAddedPacket(serverWorld, add);
            });
        });
        world.markAndNotifyBlock(add, world.getChunkAt(add), block.state, Blocks.AIR.defaultBlockState(), flags, 512);
        block.state.updateIndirectNeighbourShapes(world, add, flags & -2);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) BlockState(net.minecraft.world.level.block.state.BlockState) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) 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) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)

Example 4 with SimpleWaterloggedBlock

use of net.minecraft.world.level.block.SimpleWaterloggedBlock 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)

Aggregations

BlockPos (net.minecraft.core.BlockPos)4 SimpleWaterloggedBlock (net.minecraft.world.level.block.SimpleWaterloggedBlock)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)2 MagnetBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock)2 RopeBlock (com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock)2 Direction (net.minecraft.core.Direction)2 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)2 FluidState (net.minecraft.world.level.material.FluidState)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 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