use of com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity 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