Search in sources :

Example 66 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockEssenceRefiner method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    if (!keepRefinerInventory) {
        TileEntityEssenceRefiner refiner = (TileEntityEssenceRefiner) world.getTileEntity(i, j, k);
        if (refiner == null)
            return;
        for (int l = 0; l < refiner.getSizeInventory() - 3; l++) {
            ItemStack itemstack = refiner.getStackInSlot(l);
            if (itemstack == null) {
                continue;
            }
            float f = world.rand.nextFloat() * 0.8F + 0.1F;
            float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
            float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
            do {
                if (itemstack.stackSize <= 0) {
                    break;
                }
                int i1 = world.rand.nextInt(21) + 10;
                if (i1 > itemstack.stackSize) {
                    i1 = itemstack.stackSize;
                }
                itemstack.stackSize -= i1;
                ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
                newItem.setTagCompound(itemstack.getTagCompound());
                EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newItem);
                float f3 = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * f3;
                entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
                world.spawnEntityInWorld(entityitem);
            } while (true);
        }
    }
    super.breakBlock(world, i, j, k, par5, metadata);
}
Also used : TileEntityEssenceRefiner(am2.blocks.tileentities.TileEntityEssenceRefiner) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 67 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockArcaneDeconstructor method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    TileEntityArcaneDeconstructor deconstructor = (TileEntityArcaneDeconstructor) world.getTileEntity(i, j, k);
    if (deconstructor == null)
        return;
    for (int l = 0; l < deconstructor.getSizeInventory() - 3; l++) {
        ItemStack itemstack = deconstructor.getStackInSlot(l);
        if (itemstack == null) {
            continue;
        }
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
        do {
            if (itemstack.stackSize <= 0) {
                break;
            }
            int i1 = world.rand.nextInt(21) + 10;
            if (i1 > itemstack.stackSize) {
                i1 = itemstack.stackSize;
            }
            itemstack.stackSize -= i1;
            ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
            newItem.setTagCompound(itemstack.getTagCompound());
            EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newItem);
            float f3 = 0.05F;
            entityitem.motionX = (float) world.rand.nextGaussian() * f3;
            entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
            world.spawnEntityInWorld(entityitem);
        } while (true);
    }
    super.breakBlock(world, i, j, k, par5, metadata);
}
Also used : TileEntityArcaneDeconstructor(am2.blocks.tileentities.TileEntityArcaneDeconstructor) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 68 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockArcaneReconstructor method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    if (!world.isRemote) {
        TileEntityArcaneReconstructor reconstructor = (TileEntityArcaneReconstructor) world.getTileEntity(i, j, k);
        if (reconstructor == null)
            return;
        for (int l = 0; l < reconstructor.getSizeInventory() - 3; l++) {
            ItemStack itemstack = reconstructor.getStackInSlot(l);
            if (itemstack == null) {
                continue;
            }
            float f = world.rand.nextFloat() * 0.8F + 0.1F;
            float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
            float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
            do {
                if (itemstack.stackSize <= 0) {
                    break;
                }
                int i1 = world.rand.nextInt(21) + 10;
                if (i1 > itemstack.stackSize) {
                    i1 = itemstack.stackSize;
                }
                itemstack.stackSize -= i1;
                ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
                newItem.setTagCompound(itemstack.getTagCompound());
                EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newItem);
                float f3 = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * f3;
                entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
                world.spawnEntityInWorld(entityitem);
            } while (true);
        }
    }
    super.breakBlock(world, i, j, k, par5, metadata);
}
Also used : ItemStack(net.minecraft.item.ItemStack) TileEntityArcaneReconstructor(am2.blocks.tileentities.TileEntityArcaneReconstructor) EntityItem(net.minecraft.entity.item.EntityItem)

Example 69 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockInertSpawner method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block oldBlockID, int oldMetadata) {
    TileEntityInertSpawner spawner = (TileEntityInertSpawner) world.getTileEntity(x, y, z);
    //if there is no habitat at the location break out
    if (spawner == null)
        return;
    //if the habitat has a flicker throw it on the ground
    if (spawner.getStackInSlot(0) != null) {
        ItemStack stack = spawner.getStackInSlot(0);
        float offsetX = world.rand.nextFloat() * 0.8F + 0.1F;
        float offsetY = world.rand.nextFloat() * 0.8F + 0.1F;
        float offsetZ = world.rand.nextFloat() * 0.8F + 0.1F;
        float force = 0.05F;
        EntityItem entityItem = new EntityItem(world, x + offsetX, y + offsetY, z + offsetZ, stack);
        entityItem.motionX = (float) world.rand.nextGaussian() * force;
        entityItem.motionY = (float) world.rand.nextGaussian() * force + 0.2F;
        entityItem.motionZ = (float) world.rand.nextGaussian() * force;
        world.spawnEntityInWorld(entityItem);
    }
    super.breakBlock(world, x, y, z, oldBlockID, oldMetadata);
}
Also used : TileEntityInertSpawner(am2.blocks.tileentities.TileEntityInertSpawner) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 70 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockKeystoneChest method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    if (world.isRemote) {
        super.breakBlock(world, i, j, k, par5, metadata);
        return;
    }
    TileEntityKeystoneChest receptacle = (TileEntityKeystoneChest) world.getTileEntity(i, j, k);
    if (receptacle == null)
        return;
    if (KeystoneUtilities.instance.getKeyFromRunes(receptacle.getRunesInKey()) == 0) {
        for (int l = 0; l < receptacle.getSizeInventory() - 3; l++) {
            ItemStack itemstack = receptacle.getStackInSlot(l);
            if (itemstack == null) {
                continue;
            }
            float f = world.rand.nextFloat() * 0.8F + 0.1F;
            float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
            float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
            do {
                if (itemstack.stackSize <= 0) {
                    break;
                }
                int i1 = world.rand.nextInt(21) + 10;
                if (i1 > itemstack.stackSize) {
                    i1 = itemstack.stackSize;
                }
                itemstack.stackSize -= i1;
                ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
                newItem.setTagCompound(itemstack.getTagCompound());
                EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newItem);
                float f3 = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * f3;
                entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
                world.spawnEntityInWorld(entityitem);
            } while (true);
        }
        super.breakBlock(world, i, j, k, par5, metadata);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) TileEntityKeystoneChest(am2.blocks.tileentities.TileEntityKeystoneChest)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)284 ItemStack (net.minecraft.item.ItemStack)178 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayer (net.minecraft.entity.player.EntityPlayer)36 Entity (net.minecraft.entity.Entity)26 ArrayList (java.util.ArrayList)19 BlockPos (net.minecraft.util.math.BlockPos)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 World (net.minecraft.world.World)16 Random (java.util.Random)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 Item (net.minecraft.item.Item)13 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 List (java.util.List)11 Block (net.minecraft.block.Block)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 IBlockState (net.minecraft.block.state.IBlockState)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6