Search in sources :

Example 1 with ITankMachine

use of binnie.core.machines.power.ITankMachine in project Binnie by ForestryMC.

the class ContainerCraftGUI method sendTankChanges.

private void sendTankChanges() {
    ITankMachine tanks = Machine.getInterface(ITankMachine.class, this.window.getInventory());
    if (tanks != null && this.window.isServer()) {
        for (int i = 0; i < tanks.getTankInfos().length; ++i) {
            final TankInfo tank = tanks.getTankInfos()[i];
            if (!this.getTankInfo(i).equals(tank)) {
                this.syncedNBT.put("tank-update-" + i, this.createTankNBT(i, tank));
                this.syncedTanks.put(i, tank);
            }
        }
    }
}
Also used : ITankMachine(binnie.core.machines.power.ITankMachine) TankInfo(binnie.core.machines.power.TankInfo)

Example 2 with ITankMachine

use of binnie.core.machines.power.ITankMachine in project Binnie by ForestryMC.

the class TransferRequest method transfer.

public TransferResult transfer(@Nullable EntityPlayer player, boolean doAdd) {
    ItemStack item = this.returnItem;
    if (item.isEmpty() || this.destination == null) {
        return TransferResult.FAILURE;
    }
    if (this.transferLiquids && this.destination instanceof ITankMachine && item.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
        ITankMachine tankMachine = (ITankMachine) this.destination;
        IFluidHandler fluidHandler = tankMachine.getHandler(targetTanks);
        if (fluidHandler != null) {
            ItemStack singleCopy = ItemHandlerHelper.copyStackWithSize(item, 1);
            FluidActionResult fluidActionResult;
            if (this.origin != null && doAdd) {
                IItemHandler itemHandler = new InvWrapper(this.origin);
                fluidActionResult = FluidUtil.tryEmptyContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                if (!fluidActionResult.isSuccess()) {
                    fluidActionResult = FluidUtil.tryFillContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                }
            } else {
                fluidActionResult = FluidUtil.tryEmptyContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                if (!fluidActionResult.isSuccess()) {
                    fluidActionResult = FluidUtil.tryFillContainer(singleCopy, fluidHandler, Fluid.BUCKET_VOLUME, player, doAdd);
                }
            }
            if (fluidActionResult.isSuccess()) {
                if (item.getCount() == 1) {
                    return new TransferResult(fluidActionResult.result);
                } else {
                    ItemStack itemCopy = item.copy();
                    itemCopy.shrink(1);
                    return new TransferResult(fluidActionResult.result, itemCopy);
                }
            }
            return TransferResult.FAILURE;
        }
    }
    if (!item.isEmpty()) {
        for (final int slot : this.targetSlots) {
            if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
                if (this.destination instanceof IInventorySlots) {
                    InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
                    if (inventorySlot != null && inventorySlot.isRecipe()) {
                        continue;
                    }
                }
                ItemStack stackInSlot = this.destination.getStackInSlot(slot);
                if (!stackInSlot.isEmpty()) {
                    if (item.isStackable()) {
                        final ItemStack merged = stackInSlot.copy();
                        final NonNullList<ItemStack> newStacks = mergeStacks(item.copy(), merged.copy());
                        item = newStacks.get(0);
                        if (!areItemsEqual(merged, newStacks.get(1))) {
                            this.insertedSlots.add(new TransferSlot(slot, this.destination));
                        }
                        if (doAdd) {
                            this.destination.setInventorySlotContents(slot, newStacks.get(1));
                        }
                        if (item.isEmpty()) {
                            return new TransferResult(ItemStack.EMPTY);
                        }
                    }
                }
            }
        }
    }
    if (!item.isEmpty()) {
        for (final int slot : this.targetSlots) {
            if (this.destination.isItemValidForSlot(slot, item) || this.ignoreReadOnly) {
                if (this.destination instanceof IInventorySlots) {
                    InventorySlot inventorySlot = ((IInventorySlots) this.destination).getSlot(slot);
                    if (inventorySlot != null && inventorySlot.isRecipe()) {
                        continue;
                    }
                }
                if (this.destination.getStackInSlot(slot).isEmpty()) {
                    this.insertedSlots.add(new TransferSlot(slot, this.destination));
                    if (doAdd) {
                        this.destination.setInventorySlotContents(slot, item.copy());
                    }
                    return new TransferResult(ItemStack.EMPTY);
                }
            }
        }
    }
    this.setReturnItem(item);
    return new TransferResult(item);
}
Also used : ITankMachine(binnie.core.machines.power.ITankMachine) IInventorySlots(binnie.core.machines.inventory.IInventorySlots) IItemHandler(net.minecraftforge.items.IItemHandler) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventorySlot(binnie.core.machines.inventory.InventorySlot) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

ITankMachine (binnie.core.machines.power.ITankMachine)2 IInventorySlots (binnie.core.machines.inventory.IInventorySlots)1 InventorySlot (binnie.core.machines.inventory.InventorySlot)1 TankInfo (binnie.core.machines.power.TankInfo)1 ItemStack (net.minecraft.item.ItemStack)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1