Search in sources :

Example 96 with EntityItem

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

the class EntityThrownSickle method setDead.

@Override
public void setDead() {
    if (getThrowingEntity() != null && getThrowingEntity() instanceof EntityNatureGuardian) {
        ((EntityNatureGuardian) getThrowingEntity()).hasSickle = true;
    } else if (getThrowingEntity() != null && getThrowingEntity() instanceof EntityPlayer) {
        if (!worldObj.isRemote)
            if (getThrowingEntity().getHealth() <= 0) {
                PlayerTracker.storeSoulboundItemForRespawn((EntityPlayer) getThrowingEntity(), ItemsCommonProxy.natureScytheEnchanted.copy());
            } else {
                if (!((EntityPlayer) getThrowingEntity()).inventory.addItemStackToInventory(ItemsCommonProxy.natureScytheEnchanted.copy())) {
                    EntityItem item = new EntityItem(worldObj);
                    item.setPosition(posX, posY, posZ);
                    item.setEntityItemStack(ItemsCommonProxy.natureScytheEnchanted.copy());
                    worldObj.spawnEntityInWorld(item);
                }
            }
    }
    super.setDead();
}
Also used : EntityNatureGuardian(am2.bosses.EntityNatureGuardian) DummyEntityPlayer(am2.utility.DummyEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 97 with EntityItem

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

the class EntityWhirlwind method onCollideWithPlayer.

@Override
public void onCollideWithPlayer(EntityPlayer player) {
    if (!worldObj.isRemote) {
        Integer cd = cooldownList.get(player);
        if (cd == null || cd <= 0) {
            if (!worldObj.isRemote && rand.nextInt(100) < 10) {
                int slot = player.inventory.mainInventory.length + rand.nextInt(4);
                if (player.inventory.getStackInSlot(slot) != null) {
                    ItemStack armorStack = player.inventory.getStackInSlot(slot).copy();
                    if (!player.inventory.addItemStackToInventory(armorStack)) {
                        EntityItem item = new EntityItem(worldObj);
                        item.setPosition(player.posX, player.posY, player.posZ);
                        item.setVelocity(rand.nextDouble() * 0.2 - 0.1, rand.nextDouble() * 0.2 - 0.1, rand.nextDouble() * 0.2 - 0.1);
                        worldObj.spawnEntityInWorld(item);
                    }
                    player.inventory.setInventorySlotContents(slot, null);
                }
            }
            player.attackEntityFrom(DamageSources.causeEntityWindDamage(this), 2);
            float velX = worldObj.rand.nextFloat() * 0.2f;
            float veZ = worldObj.rand.nextFloat() * 0.2f;
            player.addVelocity(velX, 0.8, veZ);
            AMNetHandler.INSTANCE.sendVelocityAddPacket(worldObj, player, velX, 0.8, veZ);
            player.fallDistance = 0;
            setCooldownFor(player);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 98 with EntityItem

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

the class EntityAICookNearbyFood method updateTask.

@Override
public void updateTask() {
    Entity inanimate = ExtendedProperties.For(entityHost).getInanimateTarget();
    double distance = this.entityHost.getDistanceSqToEntity(inanimate);
    if (distance > 9D) {
        this.entityHost.getNavigator().tryMoveToXYZ(inanimate.posX, inanimate.posY, inanimate.posZ, this.entityHost.getAIMoveSpeed());
    } else {
        this.entityHost.getNavigator().clearPathEntity();
        this.entityHost.getLookHelper().setLookPositionWithEntity(inanimate, 30.0F, 30.0F);
        if (timeSpentCooking < 30) {
            timeSpentCooking++;
            if (entityHost.getDataWatcher().getWatchableObjectInt(19) != inanimate.getEntityId()) {
                entityHost.getDataWatcher().updateObject(19, inanimate.getEntityId());
            }
        } else {
            ItemStack smelted = FurnaceRecipes.smelting().getSmeltingResult(((EntityItem) inanimate).getEntityItem());
            timeSpentCooking = 0;
            ExtendedProperties.For(entityHost).setInanimateTarget(null);
            entityHost.getDataWatcher().updateObject(19, 0);
            if (smelted != null) {
                EntityItem item = new EntityItem(inanimate.worldObj, inanimate.posX, inanimate.posY, inanimate.posZ, new ItemStack(smelted.getItem(), smelted.stackSize));
                entityHost.worldObj.spawnEntityInWorld(item);
                inanimate.setDead();
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 99 with EntityItem

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

the class ParticleApproachEntity method doUpdate.

@Override
public void doUpdate() {
    if (target == null) {
        this.finish();
        return;
    }
    double posX;
    double posZ;
    double posY = particle.posY;
    double angle;
    double distanceToTarget = particle.getDistanceSqToEntity(target);
    double deltaZ = target.posZ - particle.posZ;
    double deltaX = target.posX - particle.posX;
    angle = Math.atan2(deltaZ, deltaX);
    double radians = angle;
    posX = particle.posX + (approachSpeed * Math.cos(radians));
    posZ = particle.posZ + (approachSpeed * Math.sin(radians));
    double deltaY;
    if (target instanceof EntityLiving) {
        EntityLiving entityliving = (EntityLiving) target;
        deltaY = posY - (entityliving.posY + entityliving.getEyeHeight());
    } else if (target instanceof EntityItem) {
        deltaY = posY - target.posY;
    } else {
        deltaY = (target.boundingBox.minY + target.boundingBox.maxY) / 2D - posY;
    }
    double horizontalDistance = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ);
    float pitchRotation = (float) (-Math.atan2(deltaY, horizontalDistance));
    double pitchRadians = pitchRotation;
    posY = particle.posY - (approachSpeed * Math.sin(pitchRadians));
    if (distanceToTarget <= (targetDistance * targetDistance)) {
        this.finish();
    } else {
        particle.setPosition(posX, posY, posZ);
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityItem(net.minecraft.entity.item.EntityItem)

Example 100 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ConvenientAdditions by Necr0.

the class CABlockContainer method dropItemHandler.

public void dropItemHandler(World world, BlockPos pos, ItemStackHandlerAutoSave handler, boolean clearHandler) {
    for (ItemStack item : handler.getStacks()) {
        if (item != null) {
            float rx = world.rand.nextFloat() * 0.8F + 0.1F;
            float ry = world.rand.nextFloat() * 0.8F + 0.1F;
            float rz = world.rand.nextFloat() * 0.8F + 0.1F;
            EntityItem entityItem = new EntityItem(world, pos.getX() + rx, pos.getY() + ry, pos.getZ() + rz, item);
            float factor = 0.05F;
            entityItem.motionX = world.rand.nextGaussian() * factor;
            entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F;
            entityItem.motionZ = world.rand.nextGaussian() * factor;
            world.spawnEntity(entityItem);
        }
    }
    if (clearHandler)
        handler.setStacks(NonNullList.withSize(handler.getSlots(), ItemStack.EMPTY));
}
Also used : ItemStack(net.minecraft.item.ItemStack) 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