Search in sources :

Example 1 with WeightedRandomItemStack

use of powercrystals.core.random.WeightedRandomItemStack in project MineFactoryReloaded by powercrystals.

the class TileEntitySludgeBoiler method activateMachine.

@Override
protected boolean activateMachine() {
    if (_tank.getLiquid() != null && _tank.getLiquid().amount > 10) {
        _tank.drain(10, true);
        setWorkDone(getWorkDone() + 1);
        _tick++;
        if (getWorkDone() >= getWorkMax()) {
            ItemStack s = ((WeightedRandomItemStack) WeightedRandom.getRandomItem(_rand, MFRRegistry.getSludgeDrops())).getStack();
            doDrop(s);
            setWorkDone(0);
        }
        if (_tick >= 23) {
            Area a = new Area(new BlockPosition(this), 3, 3, 3);
            List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, a.toAxisAlignedBB());
            for (Object o : entities) {
                if (o instanceof EntityPlayer) {
                    ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.hunger.id, 20 * 20, 0));
                }
                if (o instanceof EntityPlayer) {
                    ((EntityPlayer) o).addPotionEffect(new PotionEffect(Potion.poison.id, 6 * 20, 0));
                }
            }
            _tick = 0;
        }
        return true;
    }
    return false;
}
Also used : Area(powercrystals.core.position.Area) PotionEffect(net.minecraft.potion.PotionEffect) BlockPosition(powercrystals.core.position.BlockPosition) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WeightedRandomItemStack(powercrystals.core.random.WeightedRandomItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 2 with WeightedRandomItemStack

use of powercrystals.core.random.WeightedRandomItemStack 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)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 WeightedRandomItemStack (powercrystals.core.random.WeightedRandomItemStack)2 LinkedList (java.util.LinkedList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 PotionEffect (net.minecraft.potion.PotionEffect)1 WeightedRandomItem (net.minecraft.util.WeightedRandomItem)1 Area (powercrystals.core.position.Area)1 BlockPosition (powercrystals.core.position.BlockPosition)1