Search in sources :

Example 31 with ItemStack

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

the class TileEntityRancher method activateMachine.

@Override
public boolean activateMachine() {
    MFRLiquidMover.pumpLiquid(_tank, this);
    boolean didDrop = false;
    List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
    for (Object o : entities) {
        EntityLiving e = (EntityLiving) o;
        if (MFRRegistry.getRanchables().containsKey(e.getClass())) {
            IFactoryRanchable r = MFRRegistry.getRanchables().get(e.getClass());
            List<ItemStack> drops = r.ranch(worldObj, e, this);
            if (drops != null) {
                for (ItemStack s : drops) {
                    if (LiquidContainerRegistry.isLiquid(s)) {
                        _tank.fill(new LiquidStack(s.itemID, LiquidContainerRegistry.BUCKET_VOLUME, s.getItemDamage()), true);
                        didDrop = true;
                        continue;
                    }
                    doDrop(s);
                    didDrop = true;
                }
                if (didDrop) {
                    setIdleTicks(20);
                    return true;
                }
            }
        }
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) EntityLiving(net.minecraft.entity.EntityLiving) ItemStack(net.minecraft.item.ItemStack) IFactoryRanchable(powercrystals.minefactoryreloaded.api.IFactoryRanchable)

Example 32 with ItemStack

use of net.minecraft.item.ItemStack 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 33 with ItemStack

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

the class TileEntityUnifier method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (!worldObj.isRemote) {
        ItemStack output = null;
        if (_inventory[0] != null) {
            List<String> names = OreDictTracker.getNamesFromItem(_inventory[0]);
            if (names == null || names.size() != 1) {
                output = _inventory[0].copy();
            } else if (_preferredOutputs.containsKey(names.get(0))) {
                output = _preferredOutputs.get(names.get(0)).copy();
                output.stackSize = _inventory[0].stackSize;
            } else {
                output = OreDictionary.getOres(names.get(0)).get(0).copy();
                output.stackSize = _inventory[0].stackSize;
            }
            moveItemStack(output);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 34 with ItemStack

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

the class TileEntityVet method activateMachine.

@Override
public boolean activateMachine() {
    List<?> entities = worldObj.getEntitiesWithinAABB(EntityLiving.class, _areaManager.getHarvestArea().toAxisAlignedBB());
    for (Object o : entities) {
        if (!(o instanceof EntityLiving) || o instanceof EntityPlayer || o instanceof EntityMob) {
            continue;
        }
        EntityLiving e = (EntityLiving) o;
        for (int i = 0; i < getSizeInventory(); i++) {
            ItemStack s = getStackInSlot(i);
            if (s != null && s.getItem() instanceof ISyringe) {
                if (((ISyringe) s.getItem()).canInject(worldObj, e, s)) {
                    if (((ISyringe) s.getItem()).inject(worldObj, e, s)) {
                        s.itemID = MineFactoryReloadedCore.syringeEmptyItem.itemID;
                        return true;
                    }
                }
            }
        }
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) EntityLiving(net.minecraft.entity.EntityLiving) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ISyringe(powercrystals.minefactoryreloaded.api.ISyringe) ItemStack(net.minecraft.item.ItemStack)

Example 35 with ItemStack

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

the class TileEntityWeather method activateMachine.

@Override
public boolean activateMachine() {
    MFRLiquidMover.pumpLiquid(_tank, this);
    if (worldObj.getWorldInfo().isRaining() && canSeeSky()) {
        BiomeGenBase bgb = worldObj.getBiomeGenForCoords(this.xCoord, this.zCoord);
        if (!bgb.canSpawnLightningBolt() && !bgb.getEnableSnow()) {
            setIdleTicks(getIdleTicksMax());
            return false;
        }
        setWorkDone(getWorkDone() + 1);
        if (getWorkDone() >= getWorkMax()) {
            if (bgb.getFloatTemperature() >= 0.15F) {
                if (_tank.fill(new LiquidStack(Block.waterStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME), true) > 0) {
                    setWorkDone(0);
                    return true;
                } else {
                    setWorkDone(getWorkMax());
                    return false;
                }
            } else {
                doDrop(new ItemStack(Item.snowball));
                setWorkDone(0);
            }
        }
        return true;
    }
    setIdleTicks(getIdleTicksMax());
    return false;
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase) 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