Search in sources :

Example 31 with FluidStack

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

the class RecipeFluid method matches.

@Override
public boolean matches(InventoryCrafting inv, World world) {
    if (fluidIndex >= inv.getSizeInventory())
        return false;
    ItemStack stack = inv.getStackInSlot(fluidIndex);
    FluidStack otherFluid = FluidContainerRegistry.getFluidForFilledItem(stack);
    if (otherFluid != null && otherFluid.isFluidEqual(fluidStack) && otherFluid.amount == fluidStack.amount) {
        recipe.getInput()[fluidIndex] = stack.copy();
        boolean matches = recipe.matches(inv, world);
        recipe.getInput()[fluidIndex] = originalStack;
        return matches;
    } else {
        return false;
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 32 with FluidStack

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

the class FarmLogicSquid method tryPlaceSoil.

private boolean tryPlaceSoil(int x, int y, int z, boolean isLast) {
    if (housing.getWorld().getBlock(x, y, z).isReplaceable(housing.getWorld(), x, y, z)) {
        if (!isLast && shouldTurnIntoWater(x, y, z)) {
            if ((housing.getWorld().getBlock(x, y, z) != Blocks.water || housing.getWorld().getBlockMetadata(x, y, z) != 0) && housing.hasLiquid(new FluidStack(FluidRegistry.getFluid("water"), 1000))) {
                housing.removeLiquid(new FluidStack(FluidRegistry.getFluid("water"), 1000));
                housing.getWorld().setBlock(x, y, z, Blocks.water);
                return true;
            }
        } else {
            for (Block res : Forestry.farmStructureBlocks) {
                if (housing.hasResources(new ItemStack[] { new ItemStack(res) })) {
                    housing.removeResources(new ItemStack[] { new ItemStack(res) });
                    housing.getWorld().setBlock(x, y, z, res);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack)

Example 33 with FluidStack

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

the class TileEntityBase method autoExportLiquid.

public void autoExportLiquid() {
    FluidStack extractedStack = ((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, Integer.MAX_VALUE, false);
    if (extractedStack != null) {
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            TileEntity te = getTileCache()[d.ordinal()].getTileEntity();
            if (te instanceof IFluidHandler) {
                if (((IFluidHandler) te).canFill(d.getOpposite(), extractedStack.getFluid())) {
                    int filledAmount = ((IFluidHandler) te).fill(d.getOpposite(), extractedStack, true);
                    ((IFluidHandler) this).drain(ForgeDirection.UNKNOWN, filledAmount, true);
                    extractedStack.amount -= filledAmount;
                    if (extractedStack.amount <= 0)
                        break;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)

Example 34 with FluidStack

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

the class TileEntityLiquidHopper method exportItem.

@Override
protected boolean exportItem(int maxItems) {
    ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
    if (tank.getFluid() != null) {
        TileEntity neighbor = IOHelper.getNeighbor(this, dir);
        if (neighbor instanceof IFluidHandler) {
            IFluidHandler fluidHandler = (IFluidHandler) neighbor;
            if (fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
                FluidStack fluid = tank.getFluid().copy();
                fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
                if (fluid.amount > 0) {
                    tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
                    if (tank.getFluidAmount() <= 0)
                        tank.setFluid(null);
                    return true;
                }
            }
        }
    }
    if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
        for (EntityItem entity : getNeighborItems(this, dir)) {
            if (!entity.isDead) {
                List<ItemStack> returnedItems = new ArrayList<ItemStack>();
                if (FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
                    if (entity.getEntityItem().stackSize <= 0)
                        entity.setDead();
                    for (ItemStack stack : returnedItems) {
                        EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
                        item.motionX = entity.motionX;
                        item.motionY = entity.motionY;
                        item.motionZ = entity.motionZ;
                        worldObj.spawnEntityInWorld(item);
                    }
                    return true;
                }
            }
        }
    }
    if (getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
        if (worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
            FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
            if (extractedFluid != null && extractedFluid.amount == 1000) {
                Block fluidBlock = extractedFluid.getFluid().getBlock();
                if (fluidBlock != null) {
                    drain(ForgeDirection.UNKNOWN, 1000, true);
                    worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) EntityItem(net.minecraft.entity.item.EntityItem)

Example 35 with FluidStack

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

the class FluidUtils method tryExtractingLiquid.

public static boolean tryExtractingLiquid(TileEntity te, ItemStack liquidContainer, List<ItemStack> returnedItems) {
    if (te instanceof IFluidHandler) {
        IFluidHandler fluidHandler = (IFluidHandler) te;
        if (liquidContainer != null) {
            int containerCapacity = FluidContainerRegistry.getContainerCapacity(liquidContainer);
            if (containerCapacity > 0 || liquidContainer.getItem() == Items.bucket) {
                if (containerCapacity == 0)
                    containerCapacity = 1000;
                FluidStack extractedLiquid = fluidHandler.drain(ForgeDirection.UNKNOWN, containerCapacity, false);
                if (extractedLiquid != null && extractedLiquid.amount == containerCapacity) {
                    ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(extractedLiquid, liquidContainer);
                    if (filledContainer != null) {
                        fluidHandler.drain(ForgeDirection.UNKNOWN, containerCapacity, true);
                        liquidContainer.stackSize--;
                        returnedItems.add(filledContainer.copy());
                        return true;
                    }
                }
            } else if (liquidContainer.getItem() instanceof IFluidContainerItem) {
                IFluidContainerItem container = (IFluidContainerItem) liquidContainer.getItem();
                ItemStack singleItem = liquidContainer.copy();
                singleItem.stackSize = 1;
                FluidStack extractedLiquid = fluidHandler.drain(ForgeDirection.UNKNOWN, container.getCapacity(singleItem), false);
                if (extractedLiquid != null) {
                    int filledAmount = container.fill(singleItem, extractedLiquid, true);
                    if (filledAmount > 0) {
                        liquidContainer.stackSize--;
                        returnedItems.add(singleItem);
                        FluidStack fluid = extractedLiquid.copy();
                        fluid.amount = filledAmount;
                        fluidHandler.drain(ForgeDirection.UNKNOWN, fluid, true);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

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