Search in sources :

Example 11 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.

the class ItemJetpackFueller method onUsingTick.

@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IEnergyProvider(cofh.api.energy.IEnergyProvider) FluidStack(net.minecraftforge.fluids.FluidStack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) FuelType(tonius.simplyjetpacks.setup.FuelType) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 12 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.

the class ItemPack method drain.

@Override
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
    T pack = this.getPack(container);
    if (pack == null || pack.fuelType != FuelType.FLUID || pack.fuelFluid == null) {
        return null;
    }
    FluidStack fluid = this.getFluid(container);
    int amount = fluid != null ? fluid.amount : 0;
    int fluidExtracted = Math.min(amount, Math.min(maxDrain, pack.fuelPerTickOut));
    if (doDrain) {
        amount -= fluidExtracted;
        NBTHelper.getNBT(container).setInteger(TAG_FLUID, amount);
    }
    return fluidExtracted > 0 ? new FluidStack(FluidRegistry.getFluid(pack.fuelFluid), fluidExtracted) : null;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack)

Example 13 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project SimplyJetpacks by Tonius.

the class ItemPack method useFuel.

public int useFuel(ItemStack stack, int maxUse, boolean simulate) {
    T pack = this.getPack(stack);
    switch(pack.fuelType) {
        case ENERGY:
        default:
            int energy = this.getEnergyStored(stack);
            int energyExtracted = Math.min(energy, maxUse);
            if (!simulate) {
                energy -= energyExtracted;
                NBTHelper.getNBT(stack).setInteger(TAG_ENERGY, energy);
            }
            return energyExtracted;
        case FLUID:
            if (pack.fuelFluid == null) {
                return 0;
            }
            FluidStack fluid = this.getFluid(stack);
            int amount = fluid != null ? fluid.amount : 0;
            int fluidExtracted = Math.min(amount, maxUse);
            if (!simulate) {
                amount -= fluidExtracted;
                NBTHelper.getNBT(stack).setInteger(TAG_FLUID, amount);
            }
            return fluidExtracted;
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack)

Example 14 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.

the class GuiAerialInterface method getLiquidXPText.

private List<String> getLiquidXPText() {
    List<String> liquidXpText = new ArrayList<String>();
    liquidXpText.add("gui.tab.info.aerialInterface.liquidXp.info");
    for (Fluid fluid : PneumaticCraftAPIHandler.getInstance().liquidXPs.keySet()) {
        liquidXpText.add(EnumChatFormatting.DARK_AQUA + new FluidStack(fluid, 1).getLocalizedName() + " (" + fluid.getName() + ")");
    }
    return liquidXpText;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList)

Example 15 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project PneumaticCraft by MineMaarten.

the class GuiLogisticsBase method actionPerformed.

@Override
public void actionPerformed(IGuiWidget widget) {
    super.actionPerformed(widget);
    if (widget instanceof WidgetFluidStack) {
        boolean leftClick = Mouse.isButtonDown(0);
        boolean middleClick = Mouse.isButtonDown(2);
        boolean shift = PneumaticCraft.proxy.isSneakingInGui();
        IFluidTank tank = logistics.getTankFilter(widget.getID());
        if (tank.getFluidAmount() > 0) {
            if (middleClick) {
                logistics.setFilter(widget.getID(), (FluidStack) null);
            } else if (leftClick) {
                tank.drain(shift ? tank.getFluidAmount() / 2 : 1000, true);
                if (tank.getFluidAmount() < 1000) {
                    tank.drain(1000, true);
                }
            } else {
                tank.fill(new FluidStack(tank.getFluid().getFluid(), shift ? tank.getFluidAmount() : 1000), true);
            }
            NetworkHandler.sendToServer(new PacketSetLogisticsFluidFilterStack(logistics, tank.getFluid(), widget.getID()));
        } else {
            fluidSearchGui = new GuiLogisticsLiquidFilter(this);
            editingSlot = widget.getID();
            mc.displayGuiScreen(fluidSearchGui);
        }
    }
}
Also used : PacketSetLogisticsFluidFilterStack(pneumaticCraft.common.network.PacketSetLogisticsFluidFilterStack) WidgetFluidStack(pneumaticCraft.client.gui.widget.WidgetFluidStack) FluidStack(net.minecraftforge.fluids.FluidStack) WidgetFluidStack(pneumaticCraft.client.gui.widget.WidgetFluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Aggregations

FluidStack (net.minecraftforge.fluids.FluidStack)188 ItemStack (net.minecraft.item.ItemStack)63 TileEntity (net.minecraft.tileentity.TileEntity)30 Fluid (net.minecraftforge.fluids.Fluid)28 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)25 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)19 ArrayList (java.util.ArrayList)18 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)16 Block (net.minecraft.block.Block)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)10 Item (net.minecraft.item.Item)9 BlockPos (net.minecraft.util.math.BlockPos)9 HashMap (java.util.HashMap)6 FluidIdentifier (logisticspipes.utils.FluidIdentifier)6 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)5 IBlockState (net.minecraft.block.state.IBlockState)5 EnumFacing (net.minecraft.util.EnumFacing)5