Search in sources :

Example 36 with ItemStack

use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntityItemRouter method weightedRouteItem.

private ItemStack weightedRouteItem(ItemStack stack, int[] routes) {
    ItemStack remainingOverall = stack.copy();
    if (stack.stackSize >= totalWeight(routes)) {
        int startingAmount = stack.stackSize;
        for (int i = 0; i < routes.length; i++) {
            ItemStack stackForThisRoute = stack.copy();
            stackForThisRoute.stackSize = startingAmount * routes[i] / totalWeight(routes);
            if (stackForThisRoute.stackSize > 0) {
                ItemStack remainingFromThisRoute = UtilInventory.dropStack(this, stackForThisRoute, _outputDirections[i], _outputDirections[i]);
                if (remainingFromThisRoute == null) {
                    remainingOverall.stackSize -= stackForThisRoute.stackSize;
                } else {
                    remainingOverall.stackSize -= (stackForThisRoute.stackSize - remainingFromThisRoute.stackSize);
                }
                if (remainingOverall.stackSize <= 0) {
                    break;
                }
            }
        }
    }
    if (0 < remainingOverall.stackSize && remainingOverall.stackSize < totalWeight(routes)) {
        int outdir = weightedRandomSide(routes);
        remainingOverall = UtilInventory.dropStack(this, remainingOverall, _outputDirections[outdir], _outputDirections[outdir]);
    }
    return remainingOverall;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 37 with ItemStack

use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntityLaserDrill method getRandomDrop.

private ItemStack getRandomDrop() {
    List<WeightedRandomItemStack> drops = new LinkedList<WeightedRandomItemStack>();
    int boost = WeightedRandom.getTotalWeight(MFRRegistry.getLaserOres()) / 30;
    for (WeightedRandomItem i : MFRRegistry.getLaserOres()) {
        WeightedRandomItemStack oldStack = (WeightedRandomItemStack) i;
        WeightedRandomItemStack newStack = new WeightedRandomItemStack(oldStack.itemWeight, oldStack.getStack());
        drops.add(newStack);
        for (ItemStack s : _inventory) {
            if (s == null || s.itemID != MineFactoryReloadedCore.laserFocusItem.itemID || MFRRegistry.getLaserPreferredOres(s.getItemDamage()) == null) {
                continue;
            }
            List<ItemStack> preferredOres = MFRRegistry.getLaserPreferredOres(s.getItemDamage());
            for (ItemStack preferredOre : preferredOres) {
                if (UtilInventory.stacksEqual(newStack.getStack(), preferredOre)) {
                    newStack.itemWeight += boost;
                }
            }
        }
    }
    return ((WeightedRandomItemStack) WeightedRandom.getRandomItem(_rand, drops)).getStack();
}
Also used : WeightedRandomItem(net.minecraft.util.WeightedRandomItem) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 38 with ItemStack

use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntityLiquiCrafter method decrStackSize.

@Override
public ItemStack decrStackSize(int slot, int size) {
    ItemStack result = super.decrStackSize(slot, size);
    if (slot < 9)
        calculateOutput();
    onFactoryInventoryChanged();
    return result;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 39 with ItemStack

use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntityFertilizer method activateMachine.

@Override
public boolean activateMachine() {
    BlockPosition bp = _areaManager.getNextBlock();
    int targetId = worldObj.getBlockId(bp.x, bp.y, bp.z);
    if (!MFRRegistry.getFertilizables().containsKey(new Integer(targetId))) {
        setIdleTicks(getIdleTicksMax());
        return false;
    }
    for (int stackIndex = 0; stackIndex < getSizeInventory(); stackIndex++) {
        ItemStack fertStack = getStackInSlot(stackIndex);
        if (fertStack == null || !MFRRegistry.getFertilizers().containsKey(new Integer(fertStack.itemID))) {
            continue;
        }
        IFactoryFertilizer fertilizer = MFRRegistry.getFertilizers().get(new Integer(fertStack.itemID));
        IFactoryFertilizable fertilizable = MFRRegistry.getFertilizables().get(new Integer(targetId));
        if (fertilizer.getFertilizerMeta() != fertStack.getItemDamage()) {
            continue;
        }
        if (!fertilizable.canFertilizeBlock(worldObj, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
            continue;
        }
        if (fertilizable.fertilize(worldObj, _rand, bp.x, bp.y, bp.z, fertilizer.getFertilizerType())) {
            fertilizer.consume(fertStack);
            if (fertStack.stackSize <= 0) {
                setInventorySlotContents(stackIndex, null);
            }
            return true;
        }
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : IFactoryFertilizable(powercrystals.minefactoryreloaded.api.IFactoryFertilizable) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack) IFactoryFertilizer(powercrystals.minefactoryreloaded.api.IFactoryFertilizer)

Example 40 with ItemStack

use of net.minecraft.item.ItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntityFisher method activateMachine.

@Override
public boolean activateMachine() {
    if (_isJammed || worldObj.getWorldTime() % 137 == 0) {
        Area fishingHole = _ham.getHarvestArea();
        for (BlockPosition bp : fishingHole.getPositionsBottomFirst()) {
            if (worldObj.getBlockId(bp.x, bp.y, bp.z) != Block.waterStill.blockID) {
                _isJammed = true;
                setIdleTicks(getIdleTicksMax());
                return false;
            }
        }
    }
    _isJammed = false;
    setWorkDone(getWorkDone() + 1);
    if (getWorkDone() > getWorkMax()) {
        doDrop(new ItemStack(Item.fishRaw));
        setWorkDone(0);
    }
    return true;
}
Also used : Area(powercrystals.core.position.Area) BlockPosition(powercrystals.core.position.BlockPosition) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2944 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)294 ArrayList (java.util.ArrayList)276 EntityItem (net.minecraft.entity.item.EntityItem)192 EntityPlayer (net.minecraft.entity.player.EntityPlayer)185 Slot (net.minecraft.inventory.Slot)183 Block (net.minecraft.block.Block)181 TileEntity (net.minecraft.tileentity.TileEntity)179 Item (net.minecraft.item.Item)137 BlockPos (net.minecraft.util.math.BlockPos)125 IBlockState (net.minecraft.block.state.IBlockState)118 NBTTagList (net.minecraft.nbt.NBTTagList)86 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)86 World (net.minecraft.world.World)81 IInventory (net.minecraft.inventory.IInventory)75 FluidStack (net.minecraftforge.fluids.FluidStack)67 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)64 ResourceLocation (net.minecraft.util.ResourceLocation)63 List (java.util.List)61 Entity (net.minecraft.entity.Entity)55