Search in sources :

Example 86 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project Railcraft by Railcraft.

the class SteamBoiler method convertSteam.

public int convertSteam(int numTanks) {
    if (!isBoiling())
        return 0;
    partialConversions += numTanks * getHeatLevel();
    int waterCost = (int) partialConversions;
    if (waterCost <= 0)
        return 0;
    partialConversions -= waterCost;
    FluidStack water = tankWater.drainInternal(waterCost, false);
    if (water == null)
        return 0;
    waterCost = Math.min(waterCost, water.amount);
    FluidStack steam = Fluids.STEAM.get(Steam.STEAM_PER_UNIT_WATER * waterCost);
    if (steam == null)
        return 0;
    tankWater.drainInternal(waterCost, true);
    tankSteam.fillInternal(steam, true);
    return steam.amount;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack)

Example 87 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project Railcraft by Railcraft.

the class EntityCartTank method onUpdate.

@Override
public void onUpdate() {
    super.onUpdate();
    if (Game.isClient(worldObj)) {
        return;
    }
    FluidStack fluidStack = tank.getFluid();
    if (!Fluids.areIdentical(fluidStack, getFluidStack()))
        setFluidStack(fluidStack);
    update++;
    ItemStack topSlot = invLiquids.getStackInSlot(SLOT_INPUT);
    if (!InvTools.isEmpty(topSlot) && !FluidItemHelper.isContainer(topSlot)) {
        invLiquids.setInventorySlotContents(SLOT_INPUT, null);
        entityDropItem(topSlot, 1);
    }
    ItemStack bottomSlot = invLiquids.getStackInSlot(SLOT_OUTPUT);
    if (!InvTools.isEmpty(bottomSlot) && !FluidItemHelper.isContainer(bottomSlot)) {
        invLiquids.setInventorySlotContents(SLOT_OUTPUT, null);
        entityDropItem(bottomSlot, 1);
    }
//FIXME
//        if (update % FluidTools.BUCKET_FILL_TIME == 0)
//            FluidTools.processContainers(tank, invLiquids, SLOT_INPUT, SLOT_OUTPUT);
}
Also used : OptionalFluidStack(mods.railcraft.common.fluids.OptionalFluidStack) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 88 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.

the class TileKettle method useKettle.

@SuppressWarnings("ConstantConditions")
public boolean useKettle(EntityPlayer player, EnumHand hand, ItemStack heldItem) {
    if (!world.isRemote) {
        if (heldItem.isEmpty()) {
            if (!getContainer().isEmpty()) {
                giveItem(player, hand, ItemStack.EMPTY, getContainer());
                setContainer(ItemStack.EMPTY);
            } else if (inv.isFull() && hasIngredients() && mode != Mode.RITUAL) {
                itemRitualLogic();
            }
            return true;
        }
        //Held Item is not empty
        if (heldItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP)) {
            handleLiquid(heldItem.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.UP));
        } else if (heldItem.getItem() == Items.POTIONITEM && PotionUtils.getEffectsFromStack(heldItem).isEmpty()) {
            int level = inv.getFluidAmount();
            if (level < BUCKET_VOLUME && (inv.getFluid() == null || inv.hasFluid(FluidRegistry.WATER))) {
                play(SoundEvents.ITEM_BUCKET_FILL, 1F, 1F);
                giveItem(player, hand, heldItem, new ItemStack(Items.GLASS_BOTTLE));
                FluidStack fluidStack = new FluidStack(FluidRegistry.WATER, 250);
                inv.fill(fluidStack, true);
            }
        } else if (heldItem.getItem() == Items.GLASS_BOTTLE) {
            if (mode == Mode.POTION) {
                potionRecipeLogic(player, hand, heldItem);
            } else if (mode == Mode.CUSTOM) {
                potionCustomLogic(player, hand, heldItem);
            }
        } else if (getContainer().isEmpty()) {
            ItemStack copy = heldItem.copy();
            copy.setCount(1);
            setContainer(copy);
            giveItem(player, hand, heldItem, ItemStack.EMPTY);
        }
    }
    return true;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 89 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.

the class TileKettle method tryTurnLiquid.

private void tryTurnLiquid() {
    if (!isBoiling() && hasIngredients() && inv.isFull()) {
        Map<Item, FluidStack> fluids = KettleRegistry.getFluidItems();
        Item item = ingredients[0].getItem();
        if (fluids.containsKey(item)) {
            int count = 8;
            for (ItemStack ingredient : ingredients) {
                if (ingredient.isEmpty())
                    break;
                if (item == ingredient.getItem()) {
                    if (ingredient.getCount() > 1) {
                        while (ingredient.getCount() > 0 && count > 0) {
                            ingredient.shrink(1);
                            --count;
                        }
                    } else if (--count <= 0)
                        break;
                } else
                    return;
            }
            if (count <= 0) {
                FluidStack fluid = fluids.get(item).copy();
                play(fluid.getFluid().getFillSound(), 1F, 1F);
                inv.setFluid(fluid);
                onLiquidChange();
            }
        }
    }
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 90 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project Witchworks by Um-Mitternacht.

the class TileKettle method handleLiquid.

private void handleLiquid(IFluidHandlerItem handler) {
    if (inv.isEmpty()) {
        FluidStack drain = handler.drain(BUCKET_VOLUME, false);
        if (drain != null && drain.amount <= BUCKET_VOLUME) {
            handler.drain(drain.amount, true);
            inv.setFluid(drain);
            onLiquidChange();
            play(drain.getFluid().getEmptySound(), 1F, 1F);
        }
    } else {
        if (inv.isFull()) {
            FluidStack fill = inv.drain(BUCKET_VOLUME, false);
            FluidStack compare = handler.drain(BUCKET_VOLUME, false);
            int filled = handler.fill(fill, false);
            if (fill != null && (compare == null || fill.isFluidEqual(compare)) && filled <= BUCKET_VOLUME) {
                handler.fill(fill, true);
                inv.drain(filled, true);
                play(fill.getFluid().getEmptySound(), 1F, 1F);
            }
        } else {
            FluidStack drain = handler.drain(BUCKET_VOLUME, false);
            if (drain != null && drain.isFluidEqual(inv.getFluid()) && drain.amount <= BUCKET_VOLUME) {
                handler.drain(drain.amount, true);
                inv.fill(drain, true);
                play(drain.getFluid().getFillSound(), 1F, 1F);
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack)

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