Search in sources :

Example 1 with IToolPipette

use of forestry.api.core.IToolPipette in project ForestryMC by ForestryMC.

the class TankWidget method handleMouseClick.

@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
    EntityPlayer player = manager.minecraft.player;
    ItemStack itemstack = player.inventory.getItemStack();
    if (itemstack.isEmpty()) {
        return;
    }
    Item held = itemstack.getItem();
    Container container = manager.gui.inventorySlots;
    if (held instanceof IToolPipette && container instanceof IContainerLiquidTanks) {
        ((IContainerLiquidTanks) container).handlePipetteClickClient(slot, player);
    }
}
Also used : Item(net.minecraft.item.Item) Container(net.minecraft.inventory.Container) IContainerLiquidTanks(forestry.core.gui.IContainerLiquidTanks) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IToolPipette(forestry.api.core.IToolPipette) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IToolPipette

use of forestry.api.core.IToolPipette in project ForestryMC by ForestryMC.

the class ContainerLiquidTanksHelper method handlePipetteClick.

@Override
public void handlePipetteClick(int slot, EntityPlayerMP player) {
    ItemStack itemstack = player.inventory.getItemStack();
    Item held = itemstack.getItem();
    if (!(held instanceof IToolPipette)) {
        return;
    }
    IToolPipette pipette = (IToolPipette) held;
    IFluidTank tank = tile.getTankManager().getTank(slot);
    int liquidAmount = tank.getFluidAmount();
    IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(itemstack);
    if (fluidHandlerItem != null) {
        if (pipette.canPipette(itemstack) && liquidAmount > 0) {
            if (liquidAmount > 0) {
                if (tank instanceof FluidTank) {
                    FluidStack fillAmount = ((FluidTank) tank).drainInternal(Fluid.BUCKET_VOLUME, false);
                    int filled = fluidHandlerItem.fill(fillAmount, true);
                    tank.drain(filled, true);
                    player.inventory.setItemStack(fluidHandlerItem.getContainer());
                    player.updateHeldItem();
                }
            }
        } else {
            FluidStack potential = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
            if (potential != null) {
                if (tank instanceof FluidTank) {
                    int fill = ((FluidTank) tank).fillInternal(potential, true);
                    fluidHandlerItem.drain(fill, true);
                    player.inventory.setItemStack(fluidHandlerItem.getContainer());
                    player.updateHeldItem();
                }
            }
        }
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) Item(net.minecraft.item.Item) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) IToolPipette(forestry.api.core.IToolPipette) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Aggregations

IToolPipette (forestry.api.core.IToolPipette)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 IContainerLiquidTanks (forestry.core.gui.IContainerLiquidTanks)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Container (net.minecraft.inventory.Container)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 FluidTank (net.minecraftforge.fluids.FluidTank)1 IFluidTank (net.minecraftforge.fluids.IFluidTank)1 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)1