Search in sources :

Example 1 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class LockAttachment method use.

private boolean use(EntityPlayer player, ItemStack holding) {
    if (player.worldObj.isRemote)
        return false;
    ILockable lockable = (ILockable) tileEntity;
    ItemStack lock = lockable.getLock();
    if (lock == null) {
        if (StackUtils.isLock(holding) && lockable.isLockValid(holding)) {
            lockable.setLock(holding);
            player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
            return true;
        }
    } else if (StackUtils.isKey(holding)) {
        IKey keyType = (IKey) holding.getItem();
        ILock lockType = (ILock) lock.getItem();
        boolean success = keyType.unlock(holding, lock, true);
        lockType.onUnlock(lock, holding, lockable, player, success);
        if (!success)
            return true;
        if (player.isSneaking()) {
            AxisAlignedBB box = getHighlightBox();
            double x = (box.minX + box.maxX) / 2;
            double y = (box.minY + box.maxY) / 2;
            double z = (box.minZ + box.maxZ) / 2;
            EntityItem item = WorldUtils.spawnItem(player.worldObj, x, y, z, lock);
            lockable.setLock(null);
        } else
            lockable.useUnlocked(player);
        return true;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IKey(net.mcft.copy.betterstorage.api.lock.IKey) ItemStack(net.minecraft.item.ItemStack) ILock(net.mcft.copy.betterstorage.api.lock.ILock) EntityItem(net.minecraft.entity.item.EntityItem) ILockable(net.mcft.copy.betterstorage.api.lock.ILockable)

Example 2 with EntityItem

use of net.minecraft.entity.item.EntityItem in project compactsolars by cpw.

the class BlockCompactSolar method dropContent.

public void dropContent(int newSize, TileEntityCompactSolar tileSolar, World world) {
    for (int l = newSize; l < tileSolar.getSizeInventory(); l++) {
        ItemStack itemstack = tileSolar.getStackInSlot(l);
        if (itemstack == null) {
            continue;
        }
        float f = random.nextFloat() * 0.8F + 0.1F;
        float f1 = random.nextFloat() * 0.8F + 0.1F;
        float f2 = random.nextFloat() * 0.8F + 0.1F;
        while (itemstack.stackSize > 0) {
            int i1 = random.nextInt(21) + 10;
            if (i1 > itemstack.stackSize) {
                i1 = itemstack.stackSize;
            }
            itemstack.stackSize -= i1;
            EntityItem entityitem = new EntityItem(world, (float) tileSolar.xCoord + f, (float) tileSolar.yCoord + (newSize > 0 ? 1 : 0) + f1, (float) tileSolar.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
            float f3 = 0.05F;
            entityitem.motionX = (float) random.nextGaussian() * f3;
            entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) random.nextGaussian() * f3;
            if (itemstack.hasTagCompound()) {
                entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
            }
            world.spawnEntityInWorld(entityitem);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class WorldUtils method spawnItem.

// Item spawning related functions
/** Spawns an ItemStack in the world. */
public static EntityItem spawnItem(World world, double x, double y, double z, ItemStack stack) {
    if ((stack == null) || (stack.stackSize <= 0))
        return null;
    EntityItem item = new EntityItem(world, x, y, z, stack);
    world.spawnEntityInWorld(item);
    return item;
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 4 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class WorldUtils method dropStackFromEntity.

/** Spawns an ItemStack as if it was dropped from an entity on death. */
public static EntityItem dropStackFromEntity(Entity entity, ItemStack stack, float speed) {
    EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
    EntityItem item;
    if (player == null) {
        double y = entity.posY + entity.getEyeHeight() - 0.3;
        item = spawnItem(entity.worldObj, entity.posX, y, entity.posZ, stack);
        if (item == null)
            return null;
        item.delayBeforeCanPickup = 40;
        float f1 = RandomUtils.getFloat(0.5F);
        float f2 = RandomUtils.getFloat((float) Math.PI * 2.0F);
        item.motionX = -MathHelper.sin(f2) * f1;
        item.motionY = 0.2;
        item.motionZ = MathHelper.cos(f2) * f1;
        return item;
    } else
        item = player.dropPlayerItemWithRandomChoice(stack, true);
    if (item != null) {
        item.motionX *= speed / 4;
        item.motionZ *= speed / 4;
    }
    return item;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class WorldUtils method spawnItemWithMotion.

/** Spawns an ItemStack in the world with random motion. */
public static EntityItem spawnItemWithMotion(World world, double x, double y, double z, ItemStack stack) {
    EntityItem item = spawnItem(world, x, y, z, stack);
    if (item != null) {
        item.motionX = RandomUtils.getGaussian() * 0.05F;
        item.motionY = RandomUtils.getGaussian() * 0.05F + 0.2F;
        item.motionZ = RandomUtils.getGaussian() * 0.05F;
    }
    return item;
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)253 ItemStack (net.minecraft.item.ItemStack)157 TileEntity (net.minecraft.tileentity.TileEntity)42 EntityPlayer (net.minecraft.entity.player.EntityPlayer)31 Entity (net.minecraft.entity.Entity)23 ArrayList (java.util.ArrayList)16 BlockPos (net.minecraft.util.math.BlockPos)16 Random (java.util.Random)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)11 World (net.minecraft.world.World)11 List (java.util.List)10 Block (net.minecraft.block.Block)10 Item (net.minecraft.item.Item)10 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6