Search in sources :

Example 21 with FluidStack

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

the class ContainerAmadron method retrieveOrderItems.

public static EntityDrone retrieveOrderItems(AmadronOffer offer, int times, World itemWorld, ChunkPosition itemPos, World liquidWorld, ChunkPosition liquidPos) {
    if (offer.getInput() instanceof ItemStack) {
        if (itemWorld == null || itemPos == null)
            return null;
        ItemStack queryingItems = (ItemStack) offer.getInput();
        int amount = queryingItems.stackSize * times;
        List<ItemStack> stacks = new ArrayList<ItemStack>();
        while (amount > 0) {
            ItemStack stack = queryingItems.copy();
            stack.stackSize = Math.min(amount, stack.getMaxStackSize());
            stacks.add(stack);
            amount -= stack.stackSize;
        }
        return (EntityDrone) PneumaticRegistry.getInstance().retrieveItemsAmazonStyle(itemWorld, itemPos.chunkPosX, itemPos.chunkPosY, itemPos.chunkPosZ, stacks.toArray(new ItemStack[stacks.size()]));
    } else {
        if (liquidWorld == null || liquidPos == null)
            return null;
        FluidStack queryingFluid = ((FluidStack) offer.getInput()).copy();
        queryingFluid.amount *= times;
        return (EntityDrone) PneumaticRegistry.getInstance().retrieveFluidAmazonStyle(liquidWorld, liquidPos.chunkPosX, liquidPos.chunkPosY, liquidPos.chunkPosZ, queryingFluid);
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 22 with FluidStack

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

the class ContainerAmadron method capShoppingAmount.

public static int capShoppingAmount(AmadronOffer offer, int wantedAmount, IInventory inputInv, IInventory outputInv, IFluidHandler inputFluidHandler, IFluidHandler outputFluidHandler, ContainerAmadron container) {
    if (container != null && offer.getStock() >= 0 && wantedAmount > offer.getStock()) {
        wantedAmount = offer.getStock();
        container.problemState = EnumProblemState.OUT_OF_STOCK;
    }
    if (offer.getInput() instanceof ItemStack) {
        if (inputInv != null) {
            ItemStack searchingItem = (ItemStack) offer.getInput();
            int count = 0;
            for (int i = 0; i < inputInv.getSizeInventory(); i++) {
                if (inputInv.getStackInSlot(i) != null && inputInv.getStackInSlot(i).isItemEqual(searchingItem) && ItemStack.areItemStackTagsEqual(inputInv.getStackInSlot(i), searchingItem)) {
                    count += inputInv.getStackInSlot(i).stackSize;
                }
            }
            int maxAmount = count / ((ItemStack) offer.getInput()).stackSize;
            if (wantedAmount > maxAmount) {
                if (container != null)
                    container.problemState = EnumProblemState.NOT_ENOUGH_ITEMS;
                wantedAmount = maxAmount;
            }
        } else if (outputInv == null) {
            wantedAmount = 0;
            if (container != null)
                container.problemState = EnumProblemState.NO_ITEM_PROVIDER;
        }
    } else {
        if (inputFluidHandler != null) {
            FluidStack searchingFluid = ((FluidStack) offer.getInput()).copy();
            searchingFluid.amount = Integer.MAX_VALUE;
            FluidStack extracted = inputFluidHandler.drain(ForgeDirection.UP, searchingFluid, false);
            int maxAmount = 0;
            if (extracted != null)
                maxAmount = extracted.amount / ((FluidStack) offer.getInput()).amount;
            if (wantedAmount > maxAmount) {
                if (container != null)
                    container.problemState = EnumProblemState.NOT_ENOUGH_FLUID;
                wantedAmount = maxAmount;
            }
        } else if (outputFluidHandler == null) {
            wantedAmount = 0;
            if (container != null)
                container.problemState = EnumProblemState.NO_FLUID_PROVIDER;
        }
    }
    if (offer.getOutput() instanceof ItemStack) {
        if (outputInv != null) {
            ItemStack providingItem = ((ItemStack) offer.getOutput()).copy();
            providingItem.stackSize *= wantedAmount;
            ItemStack remainder = IOHelper.insert(outputInv, providingItem.copy(), 0, true);
            if (remainder != null) {
                int maxAmount = (providingItem.stackSize - remainder.stackSize) / ((ItemStack) offer.getOutput()).stackSize;
                if (wantedAmount > maxAmount) {
                    wantedAmount = maxAmount;
                    if (container != null)
                        container.problemState = EnumProblemState.NOT_ENOUGH_ITEM_SPACE;
                }
            }
        } else if (inputInv == null) {
            wantedAmount = 0;
            if (container != null)
                container.problemState = EnumProblemState.NO_ITEM_PROVIDER;
        }
    } else {
        if (outputFluidHandler != null) {
            FluidStack providingFluid = ((FluidStack) offer.getOutput()).copy();
            providingFluid.amount *= wantedAmount;
            int amountFilled = outputFluidHandler.fill(ForgeDirection.UP, providingFluid, false);
            int maxAmount = amountFilled / ((FluidStack) offer.getOutput()).amount;
            if (wantedAmount > maxAmount) {
                wantedAmount = maxAmount;
                if (container != null)
                    container.problemState = EnumProblemState.NOT_ENOUGH_FLUID_SPACE;
            }
        } else if (inputFluidHandler == null) {
            wantedAmount = 0;
            if (container != null)
                container.problemState = EnumProblemState.NO_FLUID_PROVIDER;
        }
    }
    return wantedAmount;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 23 with FluidStack

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

the class FluidPlastic method mixFluid.

public static FluidStack mixFluid(FluidStack plastic, FluidStack otherPlastic) {
    if (plastic == null)
        return otherPlastic;
    if (otherPlastic == null)
        return plastic;
    int[] otherColor = getColor3(otherPlastic);
    int[] color = getColor3(plastic);
    double ratio = (double) plastic.amount / (plastic.amount + otherPlastic.amount);
    int[] newColor = new int[3];
    for (int i = 0; i < 3; i++) {
        newColor[i] = (int) (ratio * color[i] + (1 - ratio) * otherColor[i]);
    }
    NBTTagCompound newTag = new NBTTagCompound();
    newTag.setInteger("color", (newColor[0] << 16) + (newColor[1] << 8) + newColor[2]);
    // newTag.setInteger("temperature", (int)(ratio * getTemperatureS(plastic) + (1 - ratio) * getTemperatureS(otherPlastic)));
    return new FluidStack(Fluids.plastic, plastic.amount + otherPlastic.amount, newTag);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 24 with FluidStack

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

the class PacketSyncAmadronOffers method writeFluidOrItemStack.

public static void writeFluidOrItemStack(Object object, ByteBuf buf) {
    if (object instanceof ItemStack) {
        buf.writeByte(0);
        ByteBufUtils.writeItemStack(buf, (ItemStack) object);
    } else {
        buf.writeByte(1);
        FluidStack stack = (FluidStack) object;
        ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
        buf.writeInt(stack.amount);
        ByteBufUtils.writeTag(buf, stack.tag);
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 25 with FluidStack

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

the class ProgWidgetLiquidInventoryCondition method getEvaluator.

@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
    return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {

        @Override
        protected boolean evaluate(ChunkPosition pos) {
            TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
            int count = 0;
            if (te instanceof IFluidHandler) {
                List<FluidStack> visitedStacks = new ArrayList<FluidStack>();
                IFluidHandler inv = (IFluidHandler) te;
                for (int i = 0; i < 6; i++) {
                    if (((ISidedWidget) widget).getSides()[i]) {
                        FluidTankInfo[] info = inv.getTankInfo(ForgeDirection.getOrientation(i));
                        if (info != null) {
                            for (FluidTankInfo inf : info) {
                                if (inf.fluid != null && !visitedStacks.contains(visitedStacks) && ProgWidgetLiquidFilter.isLiquidValid(inf.fluid.getFluid(), widget, 1)) {
                                    visitedStacks.add(inf.fluid);
                                    count += inf.fluid.amount;
                                }
                            }
                        }
                    }
                }
            } else {
                Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
                if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                    count += 1000;
                }
            }
            return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount();
        }
    };
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) DroneAIBlockCondition(pneumaticCraft.common.ai.DroneAIBlockCondition) FluidStack(net.minecraftforge.fluids.FluidStack) ChunkPosition(net.minecraft.world.ChunkPosition) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) 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