Search in sources :

Example 1 with FluidTank

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

the class PipeFluidBasic method sinkAmount.

@Override
public int sinkAmount(FluidStack stack) {
    if (!guiOpenedBy.isEmpty()) {
        //Don't sink when the gui is open
        return 0;
    }
    FluidIdentifier ident = FluidIdentifier.get(stack);
    if (filterInv.getStackInSlot(0) == null) {
        return 0;
    }
    if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
        return 0;
    }
    int onTheWay = this.countOnRoute(ident);
    int freeSpace = -onTheWay;
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
        FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
        freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
        freeSpace += ident.getFreeSpaceInsideTank(tank);
        if (freeSpace >= stack.amount) {
            return stack.amount;
        }
    }
    return freeSpace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 2 with FluidTank

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

the class NetworkUtils method getSyncedFieldsForField.

private static List<SyncedField> getSyncedFieldsForField(Field field, Object te, Class searchedAnnotation) {
    boolean isLazy = field.getAnnotation(LazySynced.class) != null;
    List<SyncedField> syncedFields = new ArrayList<SyncedField>();
    SyncedField syncedField = getSyncedFieldForField(field, te);
    if (syncedField != null) {
        syncedFields.add(syncedField.setLazy(isLazy));
        return syncedFields;
    } else {
        Object o;
        try {
            int filteredIndex = field.getAnnotation(FilteredSynced.class) != null ? field.getAnnotation(FilteredSynced.class).index() : -1;
            field.setAccessible(true);
            o = field.get(te);
            if (o instanceof int[]) {
                int[] array = (int[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedInt(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedInt(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof float[]) {
                float[] array = (float[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedFloat(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedFloat(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof double[]) {
                double[] array = (double[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedDouble(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedDouble(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof boolean[]) {
                boolean[] array = (boolean[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedBoolean(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof String[]) {
                String[] array = (String[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedString(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedString(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o.getClass().isArray() && o.getClass().getComponentType().isEnum()) {
                Object[] enumArray = (Object[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedEnum(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < enumArray.length; i++) {
                        syncedFields.add(new SyncedEnum(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof ItemStack[]) {
                ItemStack[] array = (ItemStack[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedItemStack(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (o instanceof FluidTank[]) {
                FluidTank[] array = (FluidTank[]) o;
                if (filteredIndex >= 0) {
                    syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(filteredIndex).setLazy(isLazy));
                } else {
                    for (int i = 0; i < array.length; i++) {
                        syncedFields.add(new SyncedFluidTank(te, field).setArrayIndex(i).setLazy(isLazy));
                    }
                }
                return syncedFields;
            }
            if (field.getType().isArray()) {
                Object[] array = (Object[]) o;
                for (Object obj : array) {
                    syncedFields.addAll(getSyncedFields(obj, searchedAnnotation));
                }
            } else {
                syncedFields.addAll(getSyncedFields(o, searchedAnnotation));
            }
            if (syncedFields.size() > 0)
                return syncedFields;
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.warning("Field " + field + " didn't produce any syncable fields!");
        return syncedFields;
    }
}
Also used : ArrayList(java.util.ArrayList) SyncedBoolean(pneumaticCraft.common.inventory.SyncedField.SyncedBoolean) SyncedString(pneumaticCraft.common.inventory.SyncedField.SyncedString) SyncedInt(pneumaticCraft.common.inventory.SyncedField.SyncedInt) SyncedDouble(pneumaticCraft.common.inventory.SyncedField.SyncedDouble) SyncedEnum(pneumaticCraft.common.inventory.SyncedField.SyncedEnum) SyncedField(pneumaticCraft.common.inventory.SyncedField) SyncedItemStack(pneumaticCraft.common.inventory.SyncedField.SyncedItemStack) SyncedFluidTank(pneumaticCraft.common.inventory.SyncedField.SyncedFluidTank) FluidTank(net.minecraftforge.fluids.FluidTank) SyncedItemStack(pneumaticCraft.common.inventory.SyncedField.SyncedItemStack) ItemStack(net.minecraft.item.ItemStack) SyncedFluidTank(pneumaticCraft.common.inventory.SyncedField.SyncedFluidTank) SyncedFloat(pneumaticCraft.common.inventory.SyncedField.SyncedFloat) SyncedString(pneumaticCraft.common.inventory.SyncedField.SyncedString)

Example 3 with FluidTank

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

the class SemiBlockLogistics method addDrops.

@Override
public void addDrops(List<ItemStack> drops) {
    super.addDrops(drops);
    boolean shouldAddTag = false;
    for (int i = 0; i < filters.getSizeInventory(); i++) {
        if (filters.getStackInSlot(i) != null) {
            //Only set a tag when there are requests.
            shouldAddTag = true;
            break;
        }
    }
    for (FluidTank fluidFilter : fluidFilters) {
        if (fluidFilter.getFluidAmount() > 0) {
            shouldAddTag = true;
            break;
        }
    }
    if (invisible)
        shouldAddTag = true;
    if (shouldAddTag) {
        ItemStack drop = drops.get(0);
        NBTTagCompound tag = new NBTTagCompound();
        writeToNBT(tag);
        drop.setTagCompound(tag);
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 4 with FluidTank

use of net.minecraftforge.fluids.FluidTank in project ImmersiveEngineering by BluSunrize.

the class TileEntitySheetmetalTank method getComparatorInputOverride.

@Override
public int getComparatorInputOverride() {
    if (pos == 4)
        return (15 * tank.getFluidAmount()) / tank.getCapacity();
    TileEntitySheetmetalTank master = master();
    if (//4 layers of storage
    offset[1] >= 1 && offset[1] <= 4 && master != null) {
        FluidTank t = master.tank;
        int layer = offset[1] - 1;
        int vol = t.getCapacity() / 4;
        int filled = t.getFluidAmount() - layer * vol;
        int ret = Math.min(15, Math.max(0, (15 * filled) / vol));
        return ret;
    }
    return 0;
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) IComparatorOverride(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)

Example 5 with FluidTank

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

the class SemiBlockLogistics method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound tag) {
    super.writeToNBT(tag);
    TileEntityBase.writeInventoryToNBT(tag, filters, "filters");
    NBTTagList tagList = new NBTTagList();
    for (int i = 0; i < fluidFilters.length; i++) {
        FluidTank filter = fluidFilters[i];
        if (filter.getFluid() != null) {
            NBTTagCompound t = new NBTTagCompound();
            t.setInteger("index", i);
            filter.writeToNBT(t);
            tagList.appendTag(t);
        }
    }
    tag.setTag("fluidFilters", tagList);
    tag.setBoolean("invisible", invisible);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

FluidTank (net.minecraftforge.fluids.FluidTank)9 IFluidTank (net.minecraftforge.fluids.IFluidTank)5 ItemStack (net.minecraft.item.ItemStack)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)3 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)2 FluidIdentifier (logisticspipes.utils.FluidIdentifier)2 Pair (logisticspipes.utils.tuples.Pair)2 TileEntity (net.minecraft.tileentity.TileEntity)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IngredientStack (blusunrize.immersiveengineering.api.crafting.IngredientStack)1 IComparatorOverride (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 LogisticsPipes (logisticspipes.LogisticsPipes)1 IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)1 IRequireReliableFluidTransport (logisticspipes.interfaces.routing.IRequireReliableFluidTransport)1