Search in sources :

Example 91 with EntityItem

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

the class BlockLectern method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
    TileEntityLectern te = getTileEntity(world, x, y, z);
    if (te == null) {
        return;
    }
    if (!world.isRemote) {
        if (te.hasStack()) {
            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;
            ItemStack newItem = new ItemStack(te.getStack().getItem(), 1, te.getStack().getItemDamage());
            if (te.getStack().stackTagCompound != null)
                newItem.setTagCompound((NBTTagCompound) te.getStack().stackTagCompound.copy());
            EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + 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);
        }
    }
    super.breakBlock(world, x, y, z, par5, par6);
}
Also used : TileEntityLectern(am2.blocks.tileentities.TileEntityLectern) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 92 with EntityItem

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

the class BlockManaBattery method destroy.

private void destroy(World world, int i, int j, int k) {
    TileEntityManaBattery te = getTileEntity(world, i, j, k);
    if (te != null && !world.isRemote) {
        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;
        int dmg = (int) ((PowerNodeRegistry.For(world).getPower(te, te.getPowerType()) / te.getCapacity()) * 100);
        if (dmg == 0)
            dmg = 1;
        ItemStack stack = new ItemStack(this);
        stack.damageItem(stack.getMaxDamage() - dmg, new EntityDummyCaster(world));
        stack.stackTagCompound = new NBTTagCompound();
        stack.stackTagCompound.setFloat("mana_battery_charge", PowerNodeRegistry.For(world).getPower(te, te.getPowerType()));
        stack.stackTagCompound.setInteger("mana_battery_powertype", te.getPowerType().ID());
        if (!stack.stackTagCompound.hasKey("Lore"))
            stack.stackTagCompound.setTag("Lore", new NBTTagList());
        NBTTagList tagList = new NBTTagList();
        PowerTypes powerType = te.getPowerType();
        float amt = PowerNodeRegistry.For(world).getPower(te, powerType);
        tagList.appendTag(new NBTTagString(String.format("Contains %.2f %s%s etherium", amt, powerType.chatColor(), powerType.name())));
        stack.stackTagCompound.setTag("Lore", tagList);
        EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, stack);
        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);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PowerTypes(am2.api.power.PowerTypes) EntityDummyCaster(am2.entities.EntityDummyCaster) TileEntityManaBattery(am2.blocks.tileentities.TileEntityManaBattery) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 93 with EntityItem

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

the class BossSpawnHelper method checkForWaterGuardianSpawn.

private void checkForWaterGuardianSpawn(World world, int x, int y, int z) {
    if (!world.isRaining())
        return;
    BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
    Type[] types = BiomeDictionary.getTypesForBiome(biome);
    boolean containsWaterType = false;
    for (Type type : types) {
        if (type == Type.WATER || type == Type.SWAMP || type == Type.BEACH || type == Type.OCEAN || type == Type.RIVER || type == Type.WET) {
            containsWaterType = true;
            break;
        }
    }
    if (!containsWaterType)
        return;
    for (int i = -1; i <= 1; ++i) for (int j = -1; j <= 1; ++j) if (!world.canBlockSeeTheSky(x + i, y + 1, z + j))
        return;
    List<EntityItem> itemsInRange = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1));
    if (itemsInRange.size() != 2)
        return;
    boolean hasBucket = false;
    boolean hasBoat = false;
    for (EntityItem item : itemsInRange) {
        if (item.isDead)
            continue;
        if (item.getEntityItem().getItem() == Items.boat)
            hasBoat = true;
        else if (item.getEntityItem().getItem() == Items.water_bucket)
            hasBucket = true;
    }
    if (hasBoat && hasBucket && !world.isRemote) {
        for (EntityItem item : itemsInRange) {
            item.setDead();
        }
        EntityWaterGuardian guardian = new EntityWaterGuardian(world);
        guardian.setPosition(x + 0.5, y + 1, z + 0.5);
        queuedBosses.put(guardian, world);
    }
}
Also used : Type(net.minecraftforge.common.BiomeDictionary.Type) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase) EntityItem(net.minecraft.entity.item.EntityItem)

Example 94 with EntityItem

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

the class BossSpawnHelper method checkForEnderGuardianSpawn.

public void checkForEnderGuardianSpawn(World world, int x, int y, int z) {
    if (world.provider.dimensionId != 1)
        return;
    for (int i = -1; i <= 1; ++i) for (int j = -1; j <= 1; ++j) if (i == 0 && j == 0)
        continue;
    else if (!world.canBlockSeeTheSky(x + i, y + 1, z + j))
        return;
    List<EntityItem> itemsInRange = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1));
    if (itemsInRange.size() != 2)
        return;
    boolean hasEnderEssence = false;
    boolean hasEyeofEnder = false;
    boolean hasStructure = false;
    for (EntityItem item : itemsInRange) {
        if (item.isDead)
            continue;
        if (item.getEntityItem().getItem() == Items.ender_eye)
            hasEyeofEnder = true;
        else if (item.getEntityItem().getItem() == ItemsCommonProxy.essence && item.getEntityItem().getItemDamage() == ItemsCommonProxy.essence.META_ENDER)
            hasEnderEssence = true;
    }
    hasStructure = true;
    for (int i = -1; i <= 1; ++i) {
        for (int j = -1; j <= 1; ++j) {
            hasStructure &= world.getBlock(x + i, y - 1, z + j) == Blocks.coal_block;
        }
    }
    hasStructure &= world.getBlock(x - 2, y, z) == Blocks.fire;
    hasStructure &= world.getBlock(x + 2, y, z) == Blocks.fire;
    hasStructure &= world.getBlock(x, y, z - 2) == Blocks.fire;
    hasStructure &= world.getBlock(x, y, z + 2) == Blocks.fire;
    hasStructure &= world.getBlock(x, y, z) == BlocksCommonProxy.blackAurem;
    if (!hasStructure || !hasEnderEssence || !hasEyeofEnder)
        return;
    if (!world.isRemote) {
        world.setBlockToAir(x - 2, y, z);
        world.setBlockToAir(x + 2, y, z);
        world.setBlockToAir(x, y, z - 2);
        world.setBlockToAir(x, y, z + 2);
        world.setBlockToAir(x, y, z);
        for (EntityItem item : itemsInRange) {
            item.setDead();
        }
        EntityEnderGuardian guardian = new EntityEnderGuardian(world);
        guardian.setPosition(x + 0.5, y + 1, z + 0.5);
        world.spawnEntityInWorld(guardian);
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 95 with EntityItem

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

the class BossSpawnHelper method checkForArcaneGuardianSpawn.

private void checkForArcaneGuardianSpawn(World world, int x, int y, int z) {
    List<EntityItem> itemsInRange = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1));
    if (itemsInRange.size() != 1)
        return;
    if (itemsInRange.get(0).getEntityItem().getItem() != ItemsCommonProxy.essence || itemsInRange.get(0).getEntityItem().getItemDamage() != ItemsCommonProxy.essence.META_ARCANE)
        return;
    boolean hasStructure = false;
    TileEntityLectern lectern = null;
    //+z check
    if (world.getBlock(x - 1, y, z + 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 1, z + 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 2, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 1, z + 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 2, z + 2) == Blocks.bookshelf) {
        if (world.getBlock(x, y, z + 2) == BlocksCommonProxy.blockLectern) {
            lectern = (TileEntityLectern) world.getTileEntity(x, y, z + 2);
            hasStructure = true;
        }
    }
    //-z check
    if (world.getBlock(x - 1, y, z - 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 1, z - 2) == Blocks.bookshelf && world.getBlock(x - 1, y + 2, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 1, z - 2) == Blocks.bookshelf && world.getBlock(x + 1, y + 2, z - 2) == Blocks.bookshelf) {
        if (world.getBlock(x, y, z - 2) == BlocksCommonProxy.blockLectern) {
            lectern = (TileEntityLectern) world.getTileEntity(x, y, z - 2);
            hasStructure = true;
        }
    }
    //+x check
    if (world.getBlock(x + 2, y, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 1, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 2, z - 1) == Blocks.bookshelf && world.getBlock(x + 2, y, z + 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 1, z + 1) == Blocks.bookshelf && world.getBlock(x + 2, y + 2, z + 1) == Blocks.bookshelf) {
        if (world.getBlock(x + 2, y, z) == BlocksCommonProxy.blockLectern) {
            lectern = (TileEntityLectern) world.getTileEntity(x + 2, y, z);
            hasStructure = true;
        }
    }
    //-x check
    if (world.getBlock(x - 2, y, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 1, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 2, z - 1) == Blocks.bookshelf && world.getBlock(x - 2, y, z + 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 1, z + 1) == Blocks.bookshelf && world.getBlock(x - 2, y + 2, z + 1) == Blocks.bookshelf) {
        if (world.getBlock(x - 2, y, z) == BlocksCommonProxy.blockLectern) {
            lectern = (TileEntityLectern) world.getTileEntity(x - 2, y, z);
            hasStructure = true;
        }
    }
    if (hasStructure && lectern != null && lectern.hasStack() && lectern.getStack().getItem() == ItemsCommonProxy.arcaneCompendium) {
        itemsInRange.get(0).setDead();
        EntityArcaneGuardian guardian = new EntityArcaneGuardian(world);
        guardian.setPosition(x + 0.5, y + 1, z + 0.5);
        queuedBosses.put(guardian, world);
    }
}
Also used : TileEntityLectern(am2.blocks.tileentities.TileEntityLectern) EntityItem(net.minecraft.entity.item.EntityItem)

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