Search in sources :

Example 1 with CombinedTankWrapper

use of com.simibubi.create.foundation.fluid.CombinedTankWrapper in project Create by Creators-of-Create.

the class Contraption method onEntityCreated.

public void onEntityCreated(AbstractContraptionEntity entity) {
    this.entity = entity;
    // Create subcontraptions
    for (BlockFace blockFace : pendingSubContraptions) {
        Direction face = blockFace.getFace();
        StabilizedContraption subContraption = new StabilizedContraption(face);
        Level world = entity.level;
        BlockPos pos = blockFace.getPos();
        try {
            if (!subContraption.assemble(world, pos))
                continue;
        } catch (AssemblyException e) {
            continue;
        }
        subContraption.removeBlocksFromWorld(world, BlockPos.ZERO);
        OrientedContraptionEntity movedContraption = OrientedContraptionEntity.create(world, subContraption, face);
        BlockPos anchor = blockFace.getConnectedPos();
        movedContraption.setPos(anchor.getX() + .5f, anchor.getY(), anchor.getZ() + .5f);
        world.addFreshEntity(movedContraption);
        stabilizedSubContraptions.put(movedContraption.getUUID(), new BlockFace(toLocalPos(pos), face));
    }
    // Gather itemhandlers of mounted storage
    List<IItemHandlerModifiable> list = storage.values().stream().map(MountedStorage::getItemHandler).collect(Collectors.toList());
    inventory = new ContraptionInvWrapper(Arrays.copyOf(list.toArray(), list.size(), IItemHandlerModifiable[].class));
    List<IFluidHandler> fluidHandlers = fluidStorage.values().stream().map(MountedFluidStorage::getFluidHandler).collect(Collectors.toList());
    fluidInventory = new CombinedTankWrapper(Arrays.copyOf(fluidHandlers.toArray(), fluidHandlers.size(), IFluidHandler[].class));
    gatherBBsOffThread();
}
Also used : BlockFace(com.simibubi.create.foundation.utility.BlockFace) Direction(net.minecraft.core.Direction) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Level(net.minecraft.world.level.Level) ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper)

Example 2 with CombinedTankWrapper

use of com.simibubi.create.foundation.fluid.CombinedTankWrapper in project Create by Creators-of-Create.

the class BasinTileEntity method addBehaviours.

@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
    behaviours.add(new DirectBeltInputBehaviour(this));
    filtering = new FilteringBehaviour(this, new BasinValueBox()).moveText(new Vec3(2, -8, 0)).withCallback(newFilter -> contentsChanged = true).forRecipes();
    behaviours.add(filtering);
    inputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.INPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true);
    outputTank = new SmartFluidTankBehaviour(SmartFluidTankBehaviour.OUTPUT, this, 2, 1000, true).whenFluidUpdates(() -> contentsChanged = true).forbidInsertion();
    behaviours.add(inputTank);
    behaviours.add(outputTank);
    fluidCapability = LazyOptional.of(() -> {
        LazyOptional<? extends IFluidHandler> inputCap = inputTank.getCapability();
        LazyOptional<? extends IFluidHandler> outputCap = outputTank.getCapability();
        return new CombinedTankWrapper(inputCap.orElse(null), outputCap.orElse(null));
    });
}
Also used : DirectBeltInputBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.DirectBeltInputBehaviour) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) SmartFluidTankBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.fluid.SmartFluidTankBehaviour) LazyOptional(net.minecraftforge.common.util.LazyOptional) Vec3(net.minecraft.world.phys.Vec3) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper)

Example 3 with CombinedTankWrapper

use of com.simibubi.create.foundation.fluid.CombinedTankWrapper 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"));
}
Also used : BeltBlock(com.simibubi.create.content.contraptions.relays.belt.BeltBlock) Arrays(java.util.Arrays) AABB(net.minecraft.world.phys.AABB) SeatBlock(com.simibubi.create.content.contraptions.components.actors.SeatBlock) DebugPackets(net.minecraft.network.protocol.game.DebugPackets) Dist(net.minecraftforge.api.distmarker.Dist) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CombinedInvWrapper(net.minecraftforge.items.wrapper.CombinedInvWrapper) NbtUtils(net.minecraft.nbt.NbtUtils) ChestBlock(net.minecraft.world.level.block.ChestBlock) SimpleWaterloggedBlock(net.minecraft.world.level.block.SimpleWaterloggedBlock) Set(java.util.Set) PoiType(net.minecraft.world.entity.ai.village.poi.PoiType) BooleanOp(net.minecraft.world.phys.shapes.BooleanOp) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) AllInteractionBehaviours(com.simibubi.create.AllInteractionBehaviours) WindmillBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.WindmillBearingBlock) MechanicalPistonHeadBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonHeadBlock) FluidState(net.minecraft.world.level.material.FluidState) PulleyBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.world.item.ItemStack) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) GantryShaftBlock(com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock) ICoordinate(com.simibubi.create.foundation.utility.ICoordinate) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) BlockState(net.minecraft.world.level.block.state.BlockState) CreativeCrateTileEntity(com.simibubi.create.content.logistics.block.inventories.CreativeCrateTileEntity) FilteringBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour) ArrayList(java.util.ArrayList) StickerBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.StickerBlock) BiConsumer(java.util.function.BiConsumer) BlockFace(com.simibubi.create.foundation.utility.BlockFace) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) Nullable(javax.annotation.Nullable) SeatEntity(com.simibubi.create.content.contraptions.components.actors.SeatEntity) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Iterate(com.simibubi.create.foundation.utility.Iterate) AllMovementBehaviours(com.simibubi.create.AllMovementBehaviours) MechanicalBearingBlock(com.simibubi.create.content.contraptions.components.structureMovement.bearing.MechanicalBearingBlock) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper) NBTHelper(com.simibubi.create.foundation.utility.NBTHelper) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) ListTag(net.minecraft.nbt.ListTag) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) EmptyLighter(com.simibubi.create.content.contraptions.components.structureMovement.render.EmptyLighter) IMultiTileContainer(com.simibubi.create.foundation.tileEntity.IMultiTileContainer) Direction(net.minecraft.core.Direction) RedstoneContactBlock(com.simibubi.create.content.logistics.block.redstone.RedstoneContactBlock) PressurePlateBlock(net.minecraft.world.level.block.PressurePlateBlock) FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) GantryCarriageBlock(com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock) Rotation(net.minecraft.world.level.block.Rotation) MutablePair(org.apache.commons.lang3.tuple.MutablePair) GameData(net.minecraftforge.registries.GameData) RopeBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.RopeBlock) MechanicalPistonBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock) AllConfigs(com.simibubi.create.foundation.config.AllConfigs) PulleyTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity) UniqueLinkedList(com.simibubi.create.foundation.utility.UniqueLinkedList) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) NBTProcessors(com.simibubi.create.foundation.utility.NBTProcessors) UUID(java.util.UUID) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption) MagnetBlock(com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyBlock.MagnetBlock) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.world.level.block.Blocks) Objects(java.util.Objects) AbstractChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.AbstractChassisBlock) PistonExtensionPoleBlock(com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) BlockPos(net.minecraft.core.BlockPos) HashMapPalette(net.minecraft.world.level.chunk.HashMapPalette) Entry(java.util.Map.Entry) Optional(java.util.Optional) LevelAccessor(net.minecraft.world.level.LevelAccessor) IFluidTank(net.minecraftforge.fluids.IFluidTank) Queue(java.util.Queue) Shapes(net.minecraft.world.phys.shapes.Shapes) Level(net.minecraft.world.level.Level) Tag(net.minecraft.nbt.Tag) PistonType(net.minecraft.world.level.block.state.properties.PistonType) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) FluidAction(net.minecraftforge.fluids.capability.IFluidHandler.FluidAction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerLevel(net.minecraft.server.level.ServerLevel) HashSet(java.util.HashSet) ItemVaultTileEntity(com.simibubi.create.content.logistics.block.vault.ItemVaultTileEntity) Axis(net.minecraft.core.Direction.Axis) IRotate(com.simibubi.create.content.contraptions.base.IRotate) PushReaction(net.minecraft.world.level.material.PushReaction) ButtonBlock(net.minecraft.world.level.block.ButtonBlock) Fluids(net.minecraft.world.level.material.Fluids) AllBlocks(com.simibubi.create.AllBlocks) ChestType(net.minecraft.world.level.block.state.properties.ChestType) Iterator(java.util.Iterator) SuperGlueHandler(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueHandler) MechanicalPistonBlock.isPistonHead(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isPistonHead) PistonState(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.PistonState) Entity(net.minecraft.world.entity.Entity) MechanicalPistonBlock.isExtensionPole(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.isExtensionPole) ChassisTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity) Vec3(net.minecraft.world.phys.Vec3) Block(net.minecraft.world.level.block.Block) FluidTankTileEntity(com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) BlockPos(net.minecraft.core.BlockPos) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) Tag(net.minecraft.nbt.Tag) StructureBlockInfo(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo) CompoundTag(net.minecraft.nbt.CompoundTag) IFluidTank(net.minecraftforge.fluids.IFluidTank) CombinedTankWrapper(com.simibubi.create.foundation.fluid.CombinedTankWrapper) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

CombinedTankWrapper (com.simibubi.create.foundation.fluid.CombinedTankWrapper)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 StabilizedContraption (com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)2 FilteringBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBehaviour)2 Vec3 (net.minecraft.world.phys.Vec3)2 AllBlocks (com.simibubi.create.AllBlocks)1 AllInteractionBehaviours (com.simibubi.create.AllInteractionBehaviours)1 AllMovementBehaviours (com.simibubi.create.AllMovementBehaviours)1 IRotate (com.simibubi.create.content.contraptions.base.IRotate)1 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)1 SeatBlock (com.simibubi.create.content.contraptions.components.actors.SeatBlock)1 SeatEntity (com.simibubi.create.content.contraptions.components.actors.SeatEntity)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 ChassisTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.chassis.ChassisTileEntity)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 SuperGlueHandler (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueHandler)1