Search in sources :

Example 6 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.

the class PipeFluidProvider method getAvailableFluids.

@Override
public Map<FluidIdentifier, Integer> getAvailableFluids() {
    Map<FluidIdentifier, Integer> map = new HashMap<>();
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
        boolean fallback = true;
        if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
            ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
            if (handler instanceof ISpecialTankAccessHandler) {
                fallback = false;
                Map<FluidIdentifier, Long> tmp = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
                for (Entry<FluidIdentifier, Long> entry : tmp.entrySet()) {
                    if (map.containsKey(entry.getKey())) {
                        long addition = ((long) map.get(entry.getKey())) + entry.getValue();
                        map.put(entry.getKey(), addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                    } else {
                        map.put(entry.getKey(), entry.getValue() > Integer.MAX_VALUE ? Integer.MAX_VALUE : entry.getValue().intValue());
                    }
                }
            }
        }
        if (fallback) {
            FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
            if (tanks != null) {
                for (FluidTankInfo tank : tanks) {
                    if (tank == null) {
                        continue;
                    }
                    FluidStack liquid;
                    if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
                        FluidIdentifier ident = FluidIdentifier.get(liquid);
                        if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
                            if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
                                if (map.containsKey(ident)) {
                                    long addition = ((long) map.get(ident)) + tank.fluid.amount;
                                    map.put(ident, addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
                                } else {
                                    map.put(ident, tank.fluid.amount);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    Map<FluidIdentifier, Integer> result = new HashMap<>();
    //Reduce what has been reserved, add.
    for (Entry<FluidIdentifier, Integer> fluid : map.entrySet()) {
        int remaining = fluid.getValue() - getFluidOrderManager().totalFluidsCountInOrders(fluid.getKey());
        if (remaining < 1) {
            continue;
        }
        result.put(fluid.getKey(), remaining);
    }
    return result;
}
Also used : ISpecialTankHandler(logisticspipes.interfaces.ISpecialTankHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) ISpecialTankAccessHandler(logisticspipes.interfaces.ISpecialTankAccessHandler) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 7 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.

the class AssemblyTable method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof TileAssemblyTable)) {
        return false;
    }
    TileAssemblyTable table = (TileAssemblyTable) tile;
    //current pipe inputs/outputs
    final ItemIdentifierInventory inputs = new ItemIdentifierInventory(inventory.getSizeInventory() - 2, "AssemblyTableDummyInv", 64, false);
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        inputs.setInventorySlotContents(i, inventory.getIDStackInSlot(i));
    }
    ItemStack output = inventory.getStackInSlot(inventory.getSizeInventory() - 2);
    //see if there's a recipe planned in the table that matches the current pipe settings, if yes take the next, otherwise take the first
    FlexibleRecipe<ItemStack> firstRecipe = null;
    FlexibleRecipe<ItemStack> nextRecipe = null;
    boolean takeNext = false;
    for (IFlexibleRecipe<ItemStack> r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
        if (!(r instanceof FlexibleRecipe)) {
            continue;
        }
        if (!((FlexibleRecipe<ItemStack>) r).inputFluids.isEmpty()) {
            continue;
        }
        if (table.isPlanned(r)) {
            if (firstRecipe == null) {
                firstRecipe = (FlexibleRecipe<ItemStack>) r;
            }
            if (takeNext) {
                nextRecipe = (FlexibleRecipe<ItemStack>) r;
                break;
            }
            if (output != null && ItemStack.areItemStacksEqual(output, ((FlexibleRecipe<ItemStack>) r).output)) {
                if (((FlexibleRecipe<ItemStack>) r).canBeCrafted(new // Read Proxy to IInventory
                IFlexibleCrafter() {

                    @Override
                    public int getCraftingItemStackSize() {
                        return inputs.getSizeInventory();
                    }

                    @Override
                    public ItemStack getCraftingItemStack(int paramInt) {
                        return inputs.getStackInSlot(paramInt);
                    }

                    @Override
                    public int getCraftingFluidStackSize() {
                        return 0;
                    }

                    @Override
                    public FluidStack getCraftingFluidStack(int paramInt) {
                        return null;
                    }

                    @Override
                    public ItemStack decrCraftingItemStack(int paramInt1, int paramInt2) {
                        return null;
                    }

                    @Override
                    public FluidStack decrCraftingFluidStack(int paramInt1, int paramInt2) {
                        return null;
                    }
                })) {
                    takeNext = true;
                }
            }
        }
    }
    if (nextRecipe == null) {
        nextRecipe = firstRecipe;
    }
    if (nextRecipe == null) {
        return false;
    }
    // Import
    inventory.setInventorySlotContents(inventory.getSizeInventory() - 2, nextRecipe.output);
    try {
        for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
            inventory.clearInventorySlotContents(i);
        }
        int i = 0;
        for (Object input : nextRecipe.inputItems) {
            ItemStack processed = null;
            if (input instanceof String) {
                List<ItemStack> ores = OreDictionary.getOres((String) input);
                if (ores != null && ores.size() > 0) {
                    input = ores.get(0);
                }
            } else if (input instanceof ItemStack) {
                processed = (ItemStack) input;
            } else if (input instanceof Item) {
                processed = new ItemStack((Item) input);
            } else if (input instanceof Block) {
                processed = new ItemStack((Block) input, 1, 0);
            } else if (input instanceof Integer) {
                processed = null;
            } else {
                throw new IllegalArgumentException("Unknown Object passed to recipe!");
            }
            if (processed != null) {
                inventory.setInventorySlotContents(i, processed);
                ++i;
            }
        }
    } catch (ClassCastException e) {
    // TODO: make it show a nice error or
    // remove this hack altogether.
    }
    // Compact
    inventory.compact_first(9);
    return true;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Item(net.minecraft.item.Item) TileAssemblyTable(buildcraft.silicon.TileAssemblyTable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) FlexibleRecipe(buildcraft.core.recipes.FlexibleRecipe) IFlexibleRecipe(buildcraft.api.recipes.IFlexibleRecipe)

Example 8 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.

the class LogisticsRenderPipe method renderFluids.

// BC copy, except where marked with XXX
private void renderFluids(CoreUnroutedPipe pipe, double x, double y, double z) {
    // XXX PipeTransportFluids trans = pipe.transport;
    PipeFluidTransportLogistics trans = (PipeFluidTransportLogistics) (pipe.transport);
    boolean needsRender = false;
    for (int i = 0; i < 7; ++i) {
        FluidStack fluidStack = trans.renderCache[i];
        if (fluidStack != null && fluidStack.amount > 0) {
            needsRender = true;
            break;
        }
    }
    if (!needsRender) {
        return;
    }
    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glTranslatef((float) x, (float) y, (float) z);
    int skylight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Sky, pipe.getX(), pipe.getY(), pipe.getZ());
    int blocklight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Block, pipe.getX(), pipe.getY(), pipe.getZ());
    // sides
    boolean sides = false, above = false;
    for (int i = 0; i < 6; ++i) {
        FluidStack fluidStack = trans.renderCache[i];
        if (fluidStack != null && fluidStack.amount > 0) {
            DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
            if (d == null) {
                continue;
            }
            // XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
            int stage = (int) ((float) fluidStack.amount / (float) (trans.getSideCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
            if (stage >= LogisticsRenderPipe.LIQUID_STAGES) {
                stage = LogisticsRenderPipe.LIQUID_STAGES - 1;
            }
            if (stage < 0) {
                stage = 0;
            }
            GL11.glPushMatrix();
            int list = 0;
            switch(ForgeDirection.VALID_DIRECTIONS[i]) {
                case UP:
                    above = true;
                    list = d.sideVertical[stage];
                    break;
                case DOWN:
                    GL11.glTranslatef(0, -0.75F, 0);
                    list = d.sideVertical[stage];
                    break;
                case EAST:
                case WEST:
                case SOUTH:
                case NORTH:
                    sides = true;
                    // Yes, this is kind of ugly, but was easier than transform the coordinates above.
                    GL11.glTranslatef(0.5F, 0.0F, 0.5F);
                    GL11.glRotatef(angleY[i], 0, 1, 0);
                    GL11.glRotatef(angleZ[i], 0, 0, 1);
                    GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
                    list = d.sideHorizontal[stage];
                    break;
                default:
            }
            bindTexture(TextureMap.locationBlocksTexture);
            FluidRenderer.setColorForFluidStack(fluidStack);
            GL11.glCallList(list);
            GL11.glPopMatrix();
        }
    }
    // CENTER
    FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
    if (fluidStack != null && fluidStack.amount > 0) {
        DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
        if (d != null) {
            // XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
            int stage = (int) ((float) fluidStack.amount / (float) (trans.getInnerCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
            bindTexture(TextureMap.locationBlocksTexture);
            FluidRenderer.setColorForFluidStack(fluidStack);
            if (above) {
                GL11.glCallList(d.centerVertical[stage]);
            }
            if (!above || sides) {
                GL11.glCallList(d.centerHorizontal[stage]);
            }
        }
    }
    GL11.glPopAttrib();
    GL11.glPopMatrix();
}
Also used : PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 9 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.

the class BuildCraftTankHandler method getAvailableLiquid.

@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
    Map<FluidIdentifier, Long> map = new HashMap<>();
    FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
    for (FluidTankInfo tank : tanks) {
        if (tank == null) {
            continue;
        }
        FluidStack liquid;
        if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
            FluidIdentifier ident = FluidIdentifier.get(liquid);
            if (((IFluidHandler) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
                if (map.containsKey(ident)) {
                    long addition = map.get(ident) + tank.fluid.amount;
                    map.put(ident, addition);
                } else {
                    map.put(ident, (long) tank.fluid.amount);
                }
            }
        }
    }
    return map;
}
Also used : FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 10 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.

the class PipeFluidTransportLogistics method computeFluidUpdate.

/**
	 * Computes the PacketFluidUpdate packet for transmission to a client
	 * 
	 * @param initPacket
	 *            everything is sent, no delta stuff ( first packet )
	 * @param persistChange
	 *            The render cache change is persisted
	 * @return PacketFluidUpdate liquid update packet
	 */
private ModernPacket computeFluidUpdate(boolean initPacket, boolean persistChange) {
    boolean changed = false;
    if (initClient > 0) {
        initClient--;
        if (initClient == 1) {
            changed = true;
        }
    }
    FluidStack[] renderCache = this.renderCache.clone();
    for (ForgeDirection dir : PipeFluidTransportLogistics.orientations) {
        FluidStack current;
        if (dir != ForgeDirection.UNKNOWN) {
            current = sideTanks[dir.ordinal()].getFluid();
        } else {
            current = internalTank.getFluid();
        }
        FluidStack prev = renderCache[dir.ordinal()];
        if (prev == null && current == null) {
            continue;
        }
        if (prev == null && current != null) {
            changed = true;
            renderCache[dir.ordinal()] = current.copy();
            continue;
        }
        if (prev != null && current == null) {
            changed = true;
            renderCache[dir.ordinal()] = null;
            continue;
        }
        if (prev.getFluidID() != current.getFluidID() || initPacket) {
            changed = true;
            renderCache[dir.ordinal()] = new FluidStack(current.getFluid(), renderCache[dir.ordinal()].amount);
        }
        if (prev.amount != current.amount || initPacket) {
            changed = true;
            renderCache[dir.ordinal()].amount = current.amount;
        }
    }
    if (persistChange) {
        this.renderCache = renderCache;
    }
    if (changed || initPacket) {
        return PacketHandler.getPacket(PipeFluidUpdate.class).setRenderCache(renderCache).setPosX(container.xCoord).setPosY(container.yCoord).setPosZ(container.zCoord).setChunkDataPacket(initPacket);
    }
    return null;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) PipeFluidUpdate(logisticspipes.network.packets.pipe.PipeFluidUpdate)

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