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;
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations