use of net.minecraft.entity.item.EntityItem in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method teleportDrops.
@SubscribeEvent(priority = EventPriority.LOWEST)
public void teleportDrops(@Nonnull BlockEvent.HarvestDropsEvent event) {
if (event.isCanceled())
return;
EntityPlayer player = event.getHarvester();
if (player == null || event.getHarvester().getHeldItemMainhand().getItem() != this)
return;
World world = event.getWorld();
float chance = event.getDropChance();
for (ItemStack stack : event.getDrops()) {
if (world.rand.nextFloat() <= chance) {
EntityItem toSpawn = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
world.spawnEntity(toSpawn);
}
}
event.getDrops().clear();
}
use of net.minecraft.entity.item.EntityItem in project Overloaded by CJ-MC-Mods.
the class BlockItemInterface method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.isRemote)
return true;
TileEntity te = worldIn.getTileEntity(pos);
if (!(te instanceof TileItemInterface))
return true;
TileItemInterface anInterface = (TileItemInterface) te;
ItemStack stack = anInterface.getStoredItem();
if (stack.isEmpty()) {
ItemStack handStack = playerIn.getHeldItem(hand);
if (handStack.isEmpty())
return true;
ItemStack returnedItem = anInterface.insertItem(0, handStack, false);
playerIn.setHeldItem(hand, returnedItem);
} else {
if (!playerIn.getHeldItem(hand).isEmpty())
return true;
ItemStack toSpawn = anInterface.extractItem(0, 1, false);
if (toSpawn.isEmpty())
return true;
worldIn.spawnEntity(new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ, toSpawn));
}
return true;
}
use of net.minecraft.entity.item.EntityItem in project ICBM-Classic by BuiltBrokenModding.
the class ItemDefuser method onLeftClickEntity.
/**
* Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
* return value is true further processing is canceled and the entity is not attacked.
*
* @param itemStack The Item being used
* @param player The player that is attacking
* @param entity The entity being attacked
* @return True to cancel the rest of the interaction.
*/
@Override
public boolean onLeftClickEntity(ItemStack itemStack, EntityPlayer player, Entity entity) {
if (this.getEnergy(itemStack) >= ENERGY_COST) {
if (entity instanceof EntityExplosive) {
if (!entity.worldObj.isRemote) {
EntityExplosive entityTNT = (EntityExplosive) entity;
EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(ICBMClassic.blockExplosive, 1, entityTNT.explosiveID.ordinal()));
float var13 = 0.05F;
Random random = new Random();
entityItem.motionX = ((float) random.nextGaussian() * var13);
entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
entityItem.motionZ = ((float) random.nextGaussian() * var13);
entity.worldObj.spawnEntityInWorld(entityItem);
}
entity.setDead();
} else if (entity instanceof EntityTNTPrimed) {
if (!entity.worldObj.isRemote) {
EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(Blocks.tnt));
float var13 = 0.05F;
Random random = new Random();
entityItem.motionX = ((float) random.nextGaussian() * var13);
entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
entityItem.motionZ = ((float) random.nextGaussian() * var13);
entity.worldObj.spawnEntityInWorld(entityItem);
}
entity.setDead();
} else if (entity instanceof EntityBombCart) {
((EntityBombCart) entity).killMinecart(DamageSource.generic);
}
this.discharge(itemStack, ENERGY_COST, true);
return true;
} else {
player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.defuser.nopower")));
}
return false;
}
use of net.minecraft.entity.item.EntityItem in project minecolonies by Minecolonies.
the class EntityFishHook method spawnLootAndExp.
/**
* Spawns a random loot from the loot table.
* and some exp orbs.
* Should be called when retrieving a hook.
*
* @param citizen the fisherman getting the loot.
*/
private void spawnLootAndExp(@NotNull final EntityCitizen citizen) {
final double citizenPosX = citizen.posX;
final double citizenPosY = citizen.posY;
final double citizenPosZ = citizen.posZ;
@NotNull final EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, this.getFishingLoot(citizen));
final double distanceX = citizenPosX - this.posX;
final double distanceY = citizenPosY - this.posY;
final double distanceZ = citizenPosZ - this.posZ;
entityitem.motionX = distanceX * 0.1;
entityitem.motionY = distanceY * 0.1 + Math.sqrt(Math.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ)) * 0.08;
entityitem.motionZ = distanceZ * 0.1;
this.world.spawnEntity(entityitem);
citizen.world.spawnEntity(new EntityXPOrb(citizen.world, citizenPosX, citizenPosY + 0.D, citizenPosZ + 0.5, this.rand.nextInt(6) + 1));
}
use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.
the class BlockEssenceGenerator method breakBlock.
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
if (par1World.isRemote) {
super.breakBlock(par1World, par2, par3, par4, par5, par6);
return;
}
TileEntityObelisk obelisk = getTileEntity(par1World, par2, par3, par4);
if (obelisk == null)
return;
for (int l = 0; l < obelisk.getSizeInventory(); l++) {
ItemStack itemstack = obelisk.getStackInSlot(l);
if (itemstack == null) {
continue;
}
float f = par1World.rand.nextFloat() * 0.8F + 0.1F;
float f1 = par1World.rand.nextFloat() * 0.8F + 0.1F;
float f2 = par1World.rand.nextFloat() * 0.8F + 0.1F;
do {
if (itemstack.stackSize <= 0) {
break;
}
int i1 = par1World.rand.nextInt(21) + 10;
if (i1 > itemstack.stackSize) {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
newItem.setTagCompound(itemstack.getTagCompound());
EntityItem entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, newItem);
float f3 = 0.05F;
entityitem.motionX = (float) par1World.rand.nextGaussian() * f3;
entityitem.motionY = (float) par1World.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) par1World.rand.nextGaussian() * f3;
par1World.spawnEntityInWorld(entityitem);
} while (true);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
Aggregations