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();
}
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));
}
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);
}
}
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);
}
}
}
Aggregations