use of com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity in project Create by Creators-of-Create.
the class Contraption method getTileEntityNBT.
@Nullable
protected CompoundTag getTileEntityNBT(Level world, BlockPos pos) {
BlockEntity tileentity = world.getBlockEntity(pos);
if (tileentity == null)
return null;
CompoundTag nbt = tileentity.saveWithFullMetadata();
nbt.remove("x");
nbt.remove("y");
nbt.remove("z");
if ((tileentity instanceof FluidTankTileEntity || tileentity instanceof ItemVaultTileEntity) && nbt.contains("Controller"))
nbt.put("Controller", NbtUtils.writeBlockPos(toLocalPos(NbtUtils.readBlockPos(nbt.getCompound("Controller")))));
return nbt;
}
use of com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity in project Create by Creators-of-Create.
the class MountedFluidStorage method tick.
public void tick(Entity entity, BlockPos pos, boolean isRemote) {
if (!isRemote) {
if (packetCooldown > 0)
packetCooldown--;
else if (sendPacket) {
sendPacket = false;
AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> entity), new ContraptionFluidPacket(entity.getId(), pos, tank.getFluid()));
packetCooldown = 8;
}
return;
}
if (!(te instanceof FluidTankTileEntity))
return;
FluidTankTileEntity tank = (FluidTankTileEntity) te;
tank.getFluidLevel().tick();
}
use of com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity in project Create by Creators-of-Create.
the class FluidMovementActorScenes method transfer.
public static void transfer(SceneBuilder scene, SceneBuildingUtil util) {
scene.title("portable_fluid_interface", "Contraption Fluid Exchange");
scene.configureBasePlate(0, 0, 6);
scene.scaleSceneView(0.95f);
scene.setSceneOffsetY(-1);
scene.showBasePlate();
scene.idle(5);
Selection pipes = util.select.fromTo(2, 1, 3, 0, 1, 3).add(util.select.position(0, 1, 4));
BlockPos pumpPos = util.grid.at(0, 1, 4);
Selection kinetics = util.select.fromTo(1, 1, 7, 1, 1, 4);
Selection tank = util.select.fromTo(0, 1, 5, 0, 3, 5);
Selection largeCog = util.select.position(2, 0, 7);
FluidStack chocolate = new FluidStack(FluidHelper.convertToStill(AllFluids.CHOCOLATE.get()), 1000);
BlockPos ct1 = util.grid.at(5, 3, 2);
BlockPos ct2 = util.grid.at(6, 3, 2);
BlockPos st = util.grid.at(0, 1, 5);
Capability<IFluidHandler> fhc = CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
Class<FluidTankTileEntity> type = FluidTankTileEntity.class;
ItemStack bucket = AllFluids.CHOCOLATE.get().getAttributes().getBucket(chocolate);
scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.fill(FluidHelper.copyStackWithAmount(chocolate, 10000), FluidAction.EXECUTE)));
BlockPos bearing = util.grid.at(5, 1, 2);
scene.world.showSection(util.select.position(bearing), Direction.DOWN);
scene.idle(5);
ElementLink<WorldSectionElement> contraption = scene.world.showIndependentSection(util.select.fromTo(5, 2, 2, 6, 4, 2), Direction.DOWN);
scene.world.configureCenterOfRotation(contraption, util.vector.centerOf(bearing));
scene.idle(10);
scene.world.rotateBearing(bearing, 360, 70);
scene.world.rotateSection(contraption, 0, 360, 0, 70);
scene.overlay.showText(60).pointAt(util.vector.topOf(bearing.above(2))).colored(PonderPalette.RED).placeNearTarget().attachKeyFrame().text("Fluid Tanks on moving contraptions cannot be accessed by any pipes");
scene.idle(70);
BlockPos psi = util.grid.at(4, 2, 2);
scene.world.showSectionAndMerge(util.select.position(psi), Direction.EAST, contraption);
scene.idle(13);
scene.effects.superGlue(psi, Direction.EAST, true);
scene.overlay.showText(80).pointAt(util.vector.topOf(psi)).colored(PonderPalette.GREEN).placeNearTarget().attachKeyFrame().text("This component can interact with fluid tanks without the need to stop the contraption");
scene.idle(90);
BlockPos psi2 = psi.west(2);
scene.world.showSection(util.select.position(psi2), Direction.DOWN);
scene.overlay.showSelectionWithText(util.select.position(psi.west()), 50).colored(PonderPalette.RED).placeNearTarget().attachKeyFrame().text("Place a second one with a gap of 1 or 2 blocks inbetween");
scene.idle(55);
scene.world.rotateBearing(bearing, 360, 60);
scene.world.rotateSection(contraption, 0, 360, 0, 60);
scene.idle(20);
scene.overlay.showText(40).placeNearTarget().pointAt(util.vector.of(3, 3, 2.5)).text("Whenever they pass by each other, they will engage in a connection");
scene.idle(35);
Selection both = util.select.fromTo(2, 2, 2, 4, 2, 2);
Class<PortableFluidInterfaceTileEntity> psiClass = PortableFluidInterfaceTileEntity.class;
scene.world.modifyTileNBT(both, psiClass, nbt -> {
nbt.putFloat("Distance", 1);
nbt.putFloat("Timer", 40);
});
scene.idle(20);
scene.overlay.showOutline(PonderPalette.GREEN, psi, util.select.fromTo(5, 3, 2, 6, 4, 2), 80);
scene.idle(10);
scene.overlay.showSelectionWithText(util.select.position(psi2), 70).placeNearTarget().colored(PonderPalette.GREEN).attachKeyFrame().text("While engaged, the stationary interface will represent ALL Tanks on the contraption");
scene.idle(80);
ElementLink<WorldSectionElement> p = scene.world.showIndependentSection(tank, Direction.DOWN);
scene.world.moveSection(p, util.vector.of(0, 0, -1), 0);
scene.idle(5);
scene.world.showSectionAndMerge(pipes, Direction.EAST, p);
scene.idle(5);
scene.world.showSectionAndMerge(largeCog, Direction.UP, p);
scene.world.showSectionAndMerge(kinetics, Direction.NORTH, p);
scene.idle(10);
scene.overlay.showText(70).placeNearTarget().pointAt(util.vector.topOf(pumpPos)).attachKeyFrame().text("Fluid can now be inserted...");
scene.idle(30);
for (int i = 0; i < 16; i++) {
if (i == 8)
scene.overlay.showControls(new InputWindowElement(util.vector.blockSurface(util.grid.at(5, 3, 2), Direction.WEST).add(0, 0.5, 0), Pointing.LEFT).withItem(bucket), 30);
scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.drain(1000, FluidAction.EXECUTE)));
scene.world.modifyTileEntity(ct1, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.fill(chocolate, FluidAction.EXECUTE)));
scene.idle(2);
}
for (int i = 0; i < 8; i++) {
scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.drain(1000, FluidAction.EXECUTE)));
scene.world.modifyTileEntity(ct2, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.fill(chocolate, FluidAction.EXECUTE)));
scene.idle(2);
}
scene.idle(50);
scene.overlay.showText(40).placeNearTarget().pointAt(util.vector.topOf(pumpPos)).text("...or extracted from the contraption");
scene.world.multiplyKineticSpeed(util.select.everywhere(), -1);
scene.world.propagatePipeChange(pumpPos);
scene.idle(30);
for (int i = 0; i < 8; i++) {
scene.world.modifyTileEntity(ct2, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.drain(1000, FluidAction.EXECUTE)));
scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.fill(chocolate, FluidAction.EXECUTE)));
scene.idle(2);
}
for (int i = 0; i < 16; i++) {
scene.world.modifyTileEntity(ct1, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.drain(1000, FluidAction.EXECUTE)));
scene.world.modifyTileEntity(st, type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.fill(chocolate, FluidAction.EXECUTE)));
scene.idle(2);
}
scene.world.modifyTileEntity(util.grid.at(2, 2, 3), type, te -> te.getCapability(fhc).ifPresent(ifh -> ifh.drain(8000, FluidAction.EXECUTE)));
scene.idle(50);
scene.overlay.showText(120).placeNearTarget().attachKeyFrame().pointAt(util.vector.topOf(psi2)).text("After no contents have been exchanged for a while, the contraption will continue on its way");
scene.world.modifyTileNBT(both, psiClass, nbt -> nbt.putFloat("Timer", 9));
scene.idle(15);
scene.markAsFinished();
scene.world.rotateBearing(bearing, 270, 120);
scene.world.rotateSection(contraption, 0, 270, 0, 120);
}
use of com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity in project Create by Creators-of-Create.
the class Contraption method readNBT.
public void readNBT(Level world, CompoundTag nbt, boolean spawnData) {
blocks.clear();
presentTileEntities.clear();
specialRenderedTileEntities.clear();
Tag blocks = nbt.get("Blocks");
// used to differentiate between the 'old' and the paletted serialization
boolean usePalettedDeserialization = blocks != null && blocks.getId() == 10 && ((CompoundTag) blocks).contains("Palette");
readBlocksCompound(blocks, world, usePalettedDeserialization);
actors.clear();
nbt.getList("Actors", 10).forEach(c -> {
CompoundTag comp = (CompoundTag) c;
StructureBlockInfo info = this.blocks.get(NbtUtils.readBlockPos(comp.getCompound("Pos")));
MovementContext context = MovementContext.readNBT(world, info, comp, this);
getActors().add(MutablePair.of(info, context));
});
superglue.clear();
NBTHelper.iterateCompoundList(nbt.getList("Superglue", Tag.TAG_COMPOUND), c -> superglue.add(Pair.of(NbtUtils.readBlockPos(c.getCompound("Pos")), Direction.from3DDataValue(c.getByte("Direction")))));
seats.clear();
NBTHelper.iterateCompoundList(nbt.getList("Seats", Tag.TAG_COMPOUND), c -> seats.add(NbtUtils.readBlockPos(c)));
seatMapping.clear();
NBTHelper.iterateCompoundList(nbt.getList("Passengers", Tag.TAG_COMPOUND), c -> seatMapping.put(NbtUtils.loadUUID(NBTHelper.getINBT(c, "Id")), c.getInt("Seat")));
stabilizedSubContraptions.clear();
NBTHelper.iterateCompoundList(nbt.getList("SubContraptions", Tag.TAG_COMPOUND), c -> stabilizedSubContraptions.put(c.getUUID("Id"), BlockFace.fromNBT(c.getCompound("Location"))));
storage.clear();
NBTHelper.iterateCompoundList(nbt.getList("Storage", Tag.TAG_COMPOUND), c -> storage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedStorage.deserialize(c.getCompound("Data"))));
fluidStorage.clear();
NBTHelper.iterateCompoundList(nbt.getList("FluidStorage", Tag.TAG_COMPOUND), c -> fluidStorage.put(NbtUtils.readBlockPos(c.getCompound("Pos")), MountedFluidStorage.deserialize(c.getCompound("Data"))));
interactors.clear();
NBTHelper.iterateCompoundList(nbt.getList("Interactors", Tag.TAG_COMPOUND), c -> {
BlockPos pos = NbtUtils.readBlockPos(c.getCompound("Pos"));
MovingInteractionBehaviour behaviour = AllInteractionBehaviours.of(getBlocks().get(pos).state.getBlock());
if (behaviour != null)
interactors.put(pos, behaviour);
});
if (spawnData)
fluidStorage.forEach((pos, mfs) -> {
BlockEntity tileEntity = presentTileEntities.get(pos);
if (!(tileEntity instanceof FluidTankTileEntity))
return;
FluidTankTileEntity tank = (FluidTankTileEntity) tileEntity;
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof FluidTank)
((FluidTank) tankInventory).setFluid(mfs.tank.getFluid());
tank.getFluidLevel().start(tank.getFillState());
mfs.assignTileEntity(tank);
});
IItemHandlerModifiable[] handlers = new IItemHandlerModifiable[storage.size()];
int index = 0;
for (MountedStorage mountedStorage : storage.values()) handlers[index++] = mountedStorage.getItemHandler();
IFluidHandler[] fluidHandlers = new IFluidHandler[fluidStorage.size()];
index = 0;
for (MountedFluidStorage mountedStorage : fluidStorage.values()) fluidHandlers[index++] = mountedStorage.getFluidHandler();
inventory = new ContraptionInvWrapper(handlers);
fluidInventory = new CombinedTankWrapper(fluidHandlers);
if (nbt.contains("BoundsFront"))
bounds = NBTHelper.readAABB(nbt.getList("BoundsFront", 5));
stalled = nbt.getBoolean("Stalled");
hasUniversalCreativeCrate = nbt.getBoolean("BottomlessSupply");
anchor = NbtUtils.readBlockPos(nbt.getCompound("Anchor"));
}
use of com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity in project Create by Creators-of-Create.
the class MountedFluidStorage method updateFluid.
public void updateFluid(FluidStack fluid) {
tank.setFluid(fluid);
if (!(te instanceof FluidTankTileEntity))
return;
float fillState = tank.getFluidAmount() / (float) tank.getCapacity();
FluidTankTileEntity tank = (FluidTankTileEntity) te;
if (tank.getFluidLevel() == null)
tank.setFluidLevel(new InterpolatedChasingValue().start(fillState));
tank.getFluidLevel().target(fillState);
IFluidTank tankInventory = tank.getTankInventory();
if (tankInventory instanceof SmartFluidTank)
((SmartFluidTank) tankInventory).setFluid(fluid);
}
Aggregations