use of net.minecraft.entity.item.EntityItem in project ConvenientAdditions by Necr0.
the class EventHandlerLuck method luck.
@SubscribeEvent
public void luck(HarvestDropsEvent e) {
//e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), 3);
if (e.getHarvester() != null && !e.getHarvester().isSneaking() && !e.getHarvester().getHeldItemMainhand().isEmpty() && e.getHarvester().getHeldItemMainhand().getItem() == ModItems.itemAdventurersPickaxe) {
int luck = (int) ModItems.itemAdventurersPickaxe.getToolProperty(e.getHarvester().getHeldItemMainhand(), "mining_luck");
if (Helper.doesOreDictMatch(e.getState(), "ore", true) && luck > 0) {
e.setDropChance(0f);
for (ItemStack s : e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), luck)) {
double x = e.getPos().getX() + .5, y = e.getPos().getY() + .5, z = e.getPos().getZ() + .5;
e.getWorld().spawnEntity(new EntityItem(e.getWorld(), x, y, z, s));
}
}
}
}
use of net.minecraft.entity.item.EntityItem in project Minechem by iopleke.
the class ItemHelper method throwItemStack.
public static void throwItemStack(World world, ItemStack itemStack, double x, double y, double z) {
if (itemStack != null) {
Random random = new Random();
float xFloat = random.nextFloat() * 0.8F + 0.1F;
float yFloat = random.nextFloat() * 0.8F + 0.1F;
float zFloat = random.nextFloat() * 0.8F + 0.1F;
float motionMultiplier = 0.05F;
EntityItem entityitem = new EntityItem(world, (float) x + xFloat, (float) y + yFloat, (float) z + zFloat, itemStack);
entityitem.motionX = (float) random.nextGaussian() * motionMultiplier;
entityitem.motionY = (float) random.nextGaussian() * motionMultiplier + 0.2F;
entityitem.motionZ = (float) random.nextGaussian() * motionMultiplier;
world.spawnEntityInWorld(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);
}
}
}
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;
}
Aggregations