Search in sources :

Example 16 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack in project MineFactoryReloaded by powercrystals.

the class TileEntityLiquiCrafter method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    NBTTagList nbttaglist = nbttagcompound.getTagList("Tanks");
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
        NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
        int j = nbttagcompound1.getByte("Tank") & 0xff;
        if (j >= 0 && j < _tanks.length) {
            LiquidStack l = LiquidStack.loadLiquidStackFromNBT(nbttagcompound1);
            if (l != null && l.asItemStack().getItem() != null && LiquidContainerRegistry.isLiquid(l.asItemStack())) {
                _tanks[j].setLiquid(l);
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) LiquidStack(net.minecraftforge.liquids.LiquidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 17 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack in project MineFactoryReloaded by powercrystals.

the class TileEntityLiquiCrafter method checkResources.

private void checkResources() {
    List<ItemResourceTracker> requiredItems = new LinkedList<ItemResourceTracker>();
    inv: for (int i = 0; i < 9; i++) {
        if (_inventory[i] != null) {
            if (LiquidContainerRegistry.isFilledContainer(_inventory[i])) {
                LiquidStack l = LiquidContainerRegistry.getLiquidForFilledItem(_inventory[i]);
                for (ItemResourceTracker t : requiredItems) {
                    if (t.id == l.itemID && t.meta == l.itemMeta) {
                        t.required += 1000;
                        continue inv;
                    }
                }
                requiredItems.add(new ItemResourceTracker(l.itemID, l.itemMeta, 1000));
            } else {
                for (ItemResourceTracker t : requiredItems) {
                    if (t.id == _inventory[i].itemID && t.meta == _inventory[i].getItemDamage()) {
                        t.required++;
                        continue inv;
                    }
                }
                requiredItems.add(new ItemResourceTracker(_inventory[i].itemID, _inventory[i].getItemDamage(), 1));
            }
        }
    }
    for (int i = 11; i < 29; i++) {
        if (_inventory[i] != null) {
            for (ItemResourceTracker t : requiredItems) {
                if (t.id == _inventory[i].itemID && (t.meta == _inventory[i].getItemDamage() || _inventory[i].getItem().isDamageable())) {
                    if (!_inventory[i].getItem().hasContainerItem()) {
                        t.found += _inventory[i].stackSize;
                    } else {
                        t.found += 1;
                    }
                    break;
                }
            }
        }
    }
    for (int i = 0; i < _tanks.length; i++) {
        LiquidStack l = _tanks[i].getLiquid();
        if (l == null || l.amount == 0) {
            continue;
        }
        for (ItemResourceTracker t : requiredItems) {
            if (t.id == l.itemID && t.meta == l.itemMeta) {
                t.found += l.amount;
                break;
            }
        }
    }
    for (ItemResourceTracker t : requiredItems) {
        if (t.found < t.required) {
            _resourcesChangedSinceLastFailedCraft = false;
            return;
        }
    }
    for (int i = 11; i < 29; i++) {
        if (_inventory[i] != null) {
            for (ItemResourceTracker t : requiredItems) {
                if (t.id == _inventory[i].itemID && (t.meta == _inventory[i].getItemDamage() || _inventory[i].getItem().isDamageable())) {
                    int use;
                    if (_inventory[i].getItem().hasContainerItem()) {
                        use = 1;
                        ItemStack container = _inventory[i].getItem().getContainerItemStack(_inventory[i]);
                        if (container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage()) {
                            _inventory[i] = null;
                        } else {
                            _inventory[i] = container;
                        }
                    } else {
                        use = Math.min(t.required, _inventory[i].stackSize);
                        _inventory[i].stackSize -= use;
                    }
                    t.required -= use;
                    if (_inventory[i] != null && _inventory[i].stackSize == 0) {
                        _inventory[i] = null;
                    }
                    if (t.required == 0) {
                        requiredItems.remove(t);
                    }
                    break;
                }
            }
        }
    }
    for (int i = 0; i < _tanks.length; i++) {
        LiquidStack l = _tanks[i].getLiquid();
        if (l == null || l.amount == 0) {
            continue;
        }
        for (ItemResourceTracker t : requiredItems) {
            if (t.id == l.itemID && t.meta == l.itemMeta) {
                int use = Math.min(t.required, l.amount);
                _tanks[i].drain(use, true);
                t.required -= use;
                if (t.required == 0) {
                    requiredItems.remove(t);
                }
                break;
            }
        }
    }
    if (_inventory[10] == null) {
        _inventory[10] = _inventory[9].copy();
        _inventory[10].stackSize = _inventory[9].stackSize;
    } else {
        _inventory[10].stackSize += _inventory[9].stackSize;
    }
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 18 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack in project MineFactoryReloaded by powercrystals.

the class TileEntityLiquiCrafter method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    NBTTagList tanks = new NBTTagList();
    for (int i = 0; i < _tanks.length; i++) {
        if (_tanks[i].getLiquid() != null) {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            nbttagcompound1.setByte("Tank", (byte) i);
            LiquidStack l = _tanks[i].getLiquid();
            l.writeToNBT(nbttagcompound1);
            tanks.appendTag(nbttagcompound1);
        }
    }
    nbttagcompound.setTag("Tanks", tanks);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) LiquidStack(net.minecraftforge.liquids.LiquidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 19 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack in project MineFactoryReloaded by powercrystals.

the class MineFactoryReloadedCore method postInit.

@PostInit
public void postInit(FMLPostInitializationEvent evt) {
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("milk", new LiquidStack(milkLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(Item.bucketMilk), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("sludge", new LiquidStack(sludgeLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(sludgeBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("sewage", new LiquidStack(sewageLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(sewageBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("mobEssence", new LiquidStack(essenceLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(mobEssenceBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("biofuel", new LiquidStack(biofuelLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(bioFuelBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("meat", new LiquidStack(meatLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(meatBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("pinkslime", new LiquidStack(pinkSlimeLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(pinkSlimeBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("chocolatemilk", new LiquidStack(chocolateMilkLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(chocolateMilkBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("mushroomsoup", new LiquidStack(mushroomSoupLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(mushroomSoupBucketItem), new ItemStack(Item.bucketEmpty)));
    LiquidContainerRegistry.registerLiquid(new LiquidContainerData(LiquidDictionary.getOrCreateLiquid("mushroomsoup", new LiquidStack(mushroomSoupLiquid, LiquidContainerRegistry.BUCKET_VOLUME)), new ItemStack(Item.bowlSoup), new ItemStack(Item.bowlEmpty)));
    TileEntityUnifier.updateUnifierLiquids();
    for (ItemStack s : OreDictionary.getOres("itemRubber")) {
        FurnaceRecipes.smelting().addSmelting(s.itemID, s.getItemDamage(), new ItemStack(rawPlasticItem), 0.3F);
    }
    FurnaceRecipes.smelting().addSmelting(Item.sugar.itemID, new ItemStack(sugarCharcoalItem), 0.1F);
    FurnaceRecipes.smelting().addSmelting(meatIngotRawItem.itemID, new ItemStack(meatIngotCookedItem), 0.5F);
    FurnaceRecipes.smelting().addSmelting(meatNuggetRawItem.itemID, new ItemStack(meatNuggetCookedItem), 0.3F);
    String[] biomeWhitelist = MFRConfig.rubberTreeBiomeWhitelist.getString().split(",");
    for (String biome : biomeWhitelist) {
        MFRRegistry.registerRubberTreeBiome(biome);
    }
    String[] biomeBlacklist = MFRConfig.rubberTreeBiomeBlacklist.getString().split(",");
    for (String biome : biomeBlacklist) {
        MFRRegistry.getRubberTreeBiomes().remove(biome);
    }
    if (MFRConfig.vanillaRecipes.getBoolean(true)) {
        new Vanilla().registerRecipes();
    }
    if (MFRConfig.thermalExpansionRecipes.getBoolean(false)) {
        new ThermalExpansion().registerRecipes();
    }
    if (MFRConfig.gregTechRecipes.getBoolean(false)) {
        new GregTech().registerRecipes();
    }
    for (int i = 0; i < 14; i++) {
        FacadeManager.addFacade(new ItemStack(factoryDecorativeBrickBlock.blockID, 1, i));
    }
    for (int i = 0; i < 12; i++) {
        FacadeManager.addFacade(new ItemStack(factoryDecorativeStoneBlock.blockID, 1, i));
    }
    FacadeManager.addFacade(new ItemStack(factoryRoadBlock.blockID, 1, 0));
    FacadeManager.addFacade(new ItemStack(factoryRoadBlock.blockID, 1, 1));
    FacadeManager.addFacade(new ItemStack(factoryRoadBlock.blockID, 1, 4));
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) GregTech(powercrystals.minefactoryreloaded.setup.recipe.GregTech) Vanilla(powercrystals.minefactoryreloaded.setup.recipe.Vanilla) LiquidContainerData(net.minecraftforge.liquids.LiquidContainerData) ThermalExpansion(powercrystals.minefactoryreloaded.setup.recipe.ThermalExpansion) ItemStack(net.minecraft.item.ItemStack) PostInit(cpw.mods.fml.common.Mod.PostInit)

Example 20 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack in project MineFactoryReloaded by powercrystals.

the class MFRLiquidMover method pumpLiquid.

public static void pumpLiquid(ILiquidTank tank, TileEntityFactory from) {
    if (tank != null && tank.getLiquid() != null && tank.getLiquid().amount > 0) {
        LiquidStack l = tank.getLiquid().copy();
        l.amount = Math.min(l.amount, LiquidContainerRegistry.BUCKET_VOLUME);
        for (BlockPosition adj : new BlockPosition(from).getAdjacent(true)) {
            TileEntity tile = from.worldObj.getBlockTileEntity(adj.x, adj.y, adj.z);
            if (tile instanceof ITankContainer) {
                int filled = ((ITankContainer) tile).fill(adj.orientation.getOpposite(), l, true);
                tank.drain(filled, true);
                l.amount -= filled;
                if (l.amount <= 0) {
                    break;
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LiquidStack(net.minecraftforge.liquids.LiquidStack) BlockPosition(powercrystals.core.position.BlockPosition) ITankContainer(net.minecraftforge.liquids.ITankContainer)

Aggregations

LiquidStack (net.minecraftforge.liquids.LiquidStack)22 ItemStack (net.minecraft.item.ItemStack)13 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 LinkedList (java.util.LinkedList)3 ILiquidTank (net.minecraftforge.liquids.ILiquidTank)3 LiquidContainerData (net.minecraftforge.liquids.LiquidContainerData)3 PostInit (cpw.mods.fml.common.Mod.PostInit)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ITankContainer (net.minecraftforge.liquids.ITankContainer)2 IInventoryManager (powercrystals.core.inventory.IInventoryManager)2 Init (cpw.mods.fml.common.Mod.Init)1 EntityLiving (net.minecraft.entity.EntityLiving)1 ICrafting (net.minecraft.inventory.ICrafting)1 Item (net.minecraft.item.Item)1 Icon (net.minecraft.util.Icon)1 BiomeGenBase (net.minecraft.world.biome.BiomeGenBase)1 LiquidTank (net.minecraftforge.liquids.LiquidTank)1 BlockPosition (powercrystals.core.position.BlockPosition)1 IFactoryRanchable (powercrystals.minefactoryreloaded.api.IFactoryRanchable)1