public class ItemChorusFruit extends Item { public ItemChorusFruit(Item.Info item_info) { super(item_info); } public ItemStack a(ItemStack itemstack, World world, EntityLiving entityliving) { // consume(ItemStack, World, Entity) ItemStack itemstack1 = super.a(itemstack, world, entityliving); // Get new item (lower amount by 1, call consumption events) if (!world.y) { // if the world is done loading double d0 = entityliving.dc(); // entity X double d1 = entityliving.de(); // entity Y double d2 = entityliving.di(); // entity Z for(int i = 0; i < 16; ++i) { // 15 attempts double d3 = entityliving.dc() + (entityliving.dK().nextDouble() - 0.5) * 16.0; // entity X + random number between -8 and 8, including decimals double d4 = MathHelper.a(entityliving.de() + (double)(entityliving.dK().nextInt(16) - 8), (double)world.u_(), (double)(world.u_() + ((WorldServer)world).j() - 1)); // entity Y + random number between -8 and 8, limited to the world's Y double d5 = entityliving.di() + (entityliving.dK().nextDouble() - 0.5) * 16.0; // entity Z + random number between -8 and 8, including decimals if (entityliving.bF()) { entityliving.p(); // parity check? this internally sees if another entity exists and assumes its position (???) } Optional status = entityliving.randomTeleport(d3, d4, d5, true, TeleportCause.CHORUS_FRUIT); // randomTeleport to the target location, does nearby block scanning if (!status.isPresent()) { break; // If the position is invalid, stops trying } if ((Boolean)status.get()) { // If the position is valid, and ready to teleport SoundEffect soundeffect = entityliving instanceof EntityFox ? SoundEffects.gA : SoundEffects.cY; // selects the sound effect (different for foxes apparently) world.a((EntityHuman)null, d0, d1, d2, soundeffect, SoundCategory.h, 1.0F, 1.0F); // plays the sound at the old position entityliving.a(soundeffect, 1.0F, 1.0F); // plays the sound specifically to the target entity at the new position break; } } if (entityliving instanceof EntityHuman) { ((EntityHuman)entityliving).fK().a(this, 20); // 1 second cooldown } } return itemstack1; } }