@Override public void onCastTick(World world, EntityPlayer player, ItemStack stack) { if (!world.isRemote) { BlockPos centerPos = player.getPosition(); AxisAlignedBB area = new AxisAlignedBB(centerPos).expandXyz(3F); for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(player, area)) { if (entity instanceof EntityLivingBase) { WorldServer worldServer = (WorldServer) world; if (player.getItemInUseCount() % 10 == 0 && consumePower(player)) { MessageSoulDrainFX message = new MessageSoulDrainFX(entity.posX, entity.posY + (entity.height / 2.0F), entity.posZ, player.posX, player.posY + (player.height / 2.0F), player.posZ); PacketHandler.INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint( player.dimension, player.posX, player.posY, player.posZ, 128)); entity.attackEntityFrom(DamageSource.magic, 1); world.spawnEntity(new EntityXPOrb(world, entity.posX, entity.posY + 0.5, entity.posZ, 1)); } } } } }
/** * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize */ public void onItemPickup(Entity p_71001_1_, int p_71001_2_) { if (!p_71001_1_.isDead && !this.worldObj.isRemote) { EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker(); if (p_71001_1_ instanceof EntityItem) { entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId())); } if (p_71001_1_ instanceof EntityArrow) { entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId())); } if (p_71001_1_ instanceof EntityXPOrb) { entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId())); } } }
public void handleCollectItem(SPacketCollectItem packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getCollectedItemEntityID()); EntityLivingBase entitylivingbase = (EntityLivingBase)this.clientWorldController.getEntityByID(packetIn.getEntityID()); if (entitylivingbase == null) { entitylivingbase = this.gameController.thePlayer; } if (entity != null) { if (entity instanceof EntityXPOrb) { this.clientWorldController.playSound(entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F, false); } else { this.clientWorldController.playSound(entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F, false); } this.gameController.effectRenderer.addEffect(new ParticleItemPickup(this.clientWorldController, entity, entitylivingbase, 0.5F)); this.clientWorldController.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); } }
public void handleCollectItem(S0DPacketCollectItem packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getCollectedItemEntityID()); EntityLivingBase entitylivingbase = (EntityLivingBase)this.clientWorldController.getEntityByID(packetIn.getEntityID()); if (entitylivingbase == null) { entitylivingbase = this.gameController.thePlayer; } if (entity != null) { if (entity instanceof EntityXPOrb) { this.clientWorldController.playSoundAtEntity(entity, "random.orb", 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F); } else { this.clientWorldController.playSoundAtEntity(entity, "random.pop", 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F); } this.gameController.effectRenderer.addEffect(new EntityPickupFX(this.clientWorldController, entity, entitylivingbase, 0.5F)); this.clientWorldController.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); } }
public void handleCollectItem(S0DPacketCollectItem packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getCollectedItemEntityID()); EntityLivingBase entitylivingbase = (EntityLivingBase) this.clientWorldController .getEntityByID(packetIn.getEntityID()); if (entitylivingbase == null) { entitylivingbase = this.gameController.thePlayer; } if (entity != null) { if (entity instanceof EntityXPOrb) { this.clientWorldController.playSoundAtEntity(entity, "random.orb", 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F); } else { this.clientWorldController.playSoundAtEntity(entity, "random.pop", 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F); } this.gameController.effectRenderer .addEffect(new EntityPickupFX(this.clientWorldController, entity, entitylivingbase, 0.5F)); this.clientWorldController.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); } }
public void handleCollectItem(SPacketCollectItem packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getCollectedItemEntityID()); EntityLivingBase entitylivingbase = (EntityLivingBase)this.clientWorldController.getEntityByID(packetIn.getEntityID()); if (entitylivingbase == null) { entitylivingbase = this.gameController.player; } if (entity != null) { SoundEvent soundevent = entity instanceof EntityXPOrb ? SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP : SoundEvents.ENTITY_ITEM_PICKUP; this.clientWorldController.playSound(entity.posX, entity.posY, entity.posZ, soundevent, SoundCategory.PLAYERS, 0.2F, ((this.avRandomizer.nextFloat() - this.avRandomizer.nextFloat()) * 0.7F + 1.0F) * 2.0F, false); if (entity instanceof EntityItem) { ((EntityItem)entity).getEntityItem().func_190920_e(packetIn.func_191208_c()); } this.gameController.effectRenderer.addEffect(new ParticleItemPickup(this.clientWorldController, entity, entitylivingbase, 0.5F)); this.clientWorldController.removeEntityFromWorld(packetIn.getCollectedItemEntityID()); } }
@Override public void useRecipe(MerchantRecipe recipe) { recipe.incrementToolUses(); if (recipe.getItemToBuy().getItem() instanceof ItemWeapon) { this.loadout.setStackInSlot(ItemFromData.getData(recipe.getItemToBuy()).getInt(PropertyType.SLOT), recipe.getItemToBuy()); this.switchSlot(0); } else if(recipe.getItemToBuy().getItem() instanceof ItemWearable) { this.setItemStackToSlot(EntityEquipmentSlot.HEAD, recipe.getItemToBuy()); } this.livingSoundTime = -this.getTalkInterval(); this.playSound(SoundEvents.ENTITY_VILLAGER_YES, this.getSoundVolume(), this.getSoundPitch()); int i = 3 + this.rand.nextInt(4); this.lastTrader = this.trader; this.tradeCount.put(this.trader, this.tradeCount.containsKey(trader) ? this.tradeCount.get(this.trader) + 1 : 1); this.traderFollowTicks = Math.min(4800, this.tradeCount.get(this.trader) * 250 + 350); if (recipe.getRewardsExp()) this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY + 0.5D, this.posZ, i)); }
/** * Called when the entity picks up an item. */ public void onItemPickup(Entity entityIn, int quantity) { if (!entityIn.isDead && !this.worldObj.isRemote) { EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker(); if (entityIn instanceof EntityItem) { entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId())); } if (entityIn instanceof EntityArrow) { entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId())); } if (entityIn instanceof EntityXPOrb) { entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId())); } } }
@Override public void protectedUpdate() { super.protectedUpdate(); this.getWorld().getEntitiesWithinAABB(EntityXPOrb.class, getWorkingArea().expand(2, 2, 2)).stream().filter(entityXPOrb -> !entityXPOrb.isDead).forEach(entityXPOrb -> { if (this.outExp.fill(new FluidStack(FluidsRegistry.ESSENCE, (int) (entityXPOrb.getXpValue() * 20 * BlockRegistry.mobRelocatorBlock.getEssenceMultiplier())), false) > 0) { this.outExp.fill(new FluidStack(FluidsRegistry.ESSENCE, (int) (entityXPOrb.getXpValue() * 20 * BlockRegistry.mobRelocatorBlock.getEssenceMultiplier())), true); } entityXPOrb.setDead(); }); }
/** * Gets the range an entity should be 'tracked' by players and visible in * the client. * * @param entity * @param defaultRange Default range defined by Mojang * @return */ public static int getEntityTrackingRange(Entity entity, int defaultRange) { SpigotWorldConfig config = entity.worldObj.getSpigotConfig(); // Cauldron int range = defaultRange; if ( entity instanceof EntityPlayerMP ) { range = config.playerTrackingRange; } else if ( entity.defaultActivationState || entity instanceof EntityGhast ) { range = defaultRange; } else if ( entity.activationType == 1 ) { range = config.monsterTrackingRange; } else if ( entity.activationType == 2 ) { range = config.animalTrackingRange; } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityXPOrb ) { range = config.miscTrackingRange; } // Cauldron start - allow for 0 to disable tracking ranges if (range == 0) { return defaultRange; } // Cauldron end return Math.min( config.maxTrackingRange, range ); }
private void smeltAndSpawn(EntityItem e) { ItemStack copy = e.getItem().copy(); ItemStack is = copy.splitStack(1); if (rng.nextDouble() < 0.7d) { ItemStack result = FurnaceRecipes.instance().getSmeltingResult(is).copy(); e.getEntityWorld().spawnEntity(new EntityItem(e.getEntityWorld(), e.posX, e.posY, e.posZ, result)); } else { e.getEntityWorld().spawnEntity(new EntityXPOrb(e.getEntityWorld(), e.posX, e.posY, e.posZ, 2)); } e.setItem(copy); }
@Override protected void onCrafting(ItemStack stack) { stack.onCrafting(this.player.world, this.player, this.removeCount); if (!this.player.world.isRemote) { int i = this.removeCount; CraftiniumSmelt smelt = CraftiniumSmeltRegistry.findMatchingXp(stack, this.player.world, this.forge); float f = smelt == null ? 0 : smelt.experience(stack, this.player.world, this.forge); if (f == 0.0F) { i = 0; } else if (f < 1.0F) { int j = MathHelper.floor((float) i * f); if (j < MathHelper.ceil((float) i * f) && Math.random() < (double) ((float) i * f - (float) j)) { ++j; } i = j; } while (i > 0) { int k = EntityXPOrb.getXPSplit(i); i -= k; this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k)); } } this.removeCount = 0; net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack); }
/** * handles entity death timer, experience orb and particle creation */ protected void onDeathUpdate() { ++this.deathTime; if (this.deathTime == 20) { if (!this.worldObj.isRemote && (this.recentlyHit > 0 || this.isPlayer()) && this.canDropLoot() && this.worldObj.getGameRules().getBoolean("doMobLoot")) { int i = this.getExperiencePoints(this.attackingPlayer); while (i > 0) { int j = EntityXPOrb.getXPSplit(i); i -= j; this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j)); } } this.setDead(); for (int k = 0; k < 20; ++k) { double d2 = this.rand.nextGaussian() * 0.02D; double d0 = this.rand.nextGaussian() * 0.02D; double d1 = this.rand.nextGaussian() * 0.02D; this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d2, d0, d1, new int[0]); } } }
public void useRecipe(MerchantRecipe recipe) { recipe.incrementToolUses(); this.livingSoundTime = -this.getTalkInterval(); this.playSound("mob.villager.yes", this.getSoundVolume(), this.getSoundPitch()); int i = 3 + this.rand.nextInt(4); if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0) { this.timeUntilReset = 40; this.needsInitilization = true; this.isWillingToMate = true; if (this.buyingPlayer != null) { this.lastBuyingPlayer = this.buyingPlayer.getName(); } else { this.lastBuyingPlayer = null; } i += 5; } if (recipe.getItemToBuy().getItem() == Items.emerald) { this.wealth += recipe.getItemToBuy().stackSize; } if (recipe.getRewardsExp()) { this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY + 0.5D, this.posZ, i)); } }
public S11PacketSpawnExperienceOrb(EntityXPOrb xpOrb) { this.entityID = xpOrb.getEntityId(); this.posX = MathHelper.floor_double(xpOrb.posX * 32.0D); this.posY = MathHelper.floor_double(xpOrb.posY * 32.0D); this.posZ = MathHelper.floor_double(xpOrb.posZ * 32.0D); this.xpValue = xpOrb.getXpValue(); }
/** * Spawns the given amount of experience into the World as XP orb entities */ protected void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount) { if (!worldIn.isRemote) { while (amount > 0) { int i = EntityXPOrb.getXPSplit(amount); amount -= i; worldIn.spawnEntityInWorld(new EntityXPOrb(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, i)); } } }
/** * Spawns an experience orb and sets its value (amount of XP) */ public void handleSpawnExperienceOrb(S11PacketSpawnExperienceOrb packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = new EntityXPOrb(this.clientWorldController, (double)packetIn.getX() / 32.0D, (double)packetIn.getY() / 32.0D, (double)packetIn.getZ() / 32.0D, packetIn.getXPValue()); entity.serverPosX = packetIn.getX(); entity.serverPosY = packetIn.getY(); entity.serverPosZ = packetIn.getZ(); entity.rotationYaw = 0.0F; entity.rotationPitch = 0.0F; entity.setEntityId(packetIn.getEntityID()); this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity); }
/** * Spawns the given amount of experience into the World as XP orb entities */ protected void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount) { if (!worldIn.isRemote) { while (amount > 0) { int i = EntityXPOrb.getXPSplit(amount); amount -= i; worldIn.spawnEntityInWorld(new EntityXPOrb(worldIn, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, i)); } } }
/** * Spawns an experience orb and sets its value (amount of XP) */ public void handleSpawnExperienceOrb(S11PacketSpawnExperienceOrb packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); Entity entity = new EntityXPOrb(this.clientWorldController, (double) packetIn.getX() / 32.0D, (double) packetIn.getY() / 32.0D, (double) packetIn.getZ() / 32.0D, packetIn.getXPValue()); entity.serverPosX = packetIn.getX(); entity.serverPosY = packetIn.getY(); entity.serverPosZ = packetIn.getZ(); entity.rotationYaw = 0.0F; entity.rotationPitch = 0.0F; entity.setEntityId(packetIn.getEntityID()); this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity); }
private void destroyXp() { AxisAlignedBB bb = getAABBForExtension(); List<EntityXPOrb> ents = getWorld().getEntitiesWithinAABB(EntityXPOrb.class, bb); for (EntityXPOrb ent : ents) { getWorld().removeEntity(ent); } }
public static void onPlayerPickupXP(PlayerPickupXpEvent event) { EntityPlayer player = event.entityPlayer; EntityXPOrb orb = event.orb; if (player.worldObj.isRemote) return; if (!EtFuturum.enableMending) return; ItemStack[] stacks = new ItemStack[5]; stacks[0] = player.getCurrentEquippedItem(); // held stacks[1] = player.getEquipmentInSlot(1); // boots stacks[2] = player.getEquipmentInSlot(2); // leggings stacks[3] = player.getEquipmentInSlot(3); // chestplate stacks[4] = player.getEquipmentInSlot(4); // helmet for (ItemStack stack : stacks) if (stack != null && stack.getItemDamage() > 0 && EnchantmentHelper.getEnchantmentLevel(mending.effectId, stack) > 0) { int xp = orb.xpValue; while (xp > 0 && stack.getItemDamage() > 0) { stack.setItemDamage(stack.getItemDamage() - 2); xp--; } if (xp <= 0) { orb.setDead(); event.setCanceled(true); return; } } }
/** * Spawns an experience orb and sets its value (amount of XP) */ public void handleSpawnExperienceOrb(SPacketSpawnExperienceOrb packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); double d0 = packetIn.getX(); double d1 = packetIn.getY(); double d2 = packetIn.getZ(); Entity entity = new EntityXPOrb(this.clientWorldController, d0, d1, d2, packetIn.getXPValue()); EntityTracker.updateServerPosition(entity, d0, d1, d2); entity.rotationYaw = 0.0F; entity.rotationPitch = 0.0F; entity.setEntityId(packetIn.getEntityID()); this.clientWorldController.addEntityToWorld(packetIn.getEntityID(), entity); }
/** * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. */ protected void onCrafting(ItemStack stack) { stack.onCrafting(this.player.world, this.player, this.removeCount); if (!this.player.world.isRemote) { int i = this.removeCount; float f = FurnaceRecipes.instance().getSmeltingExperience(stack); if (f == 0.0F) { i = 0; } else if (f < 1.0F) { int j = MathHelper.floor((float)i * f); if (j < MathHelper.ceil((float)i * f) && Math.random() < (double)((float)i * f - (float)j)) { ++j; } i = j; } while (i > 0) { int k = EntityXPOrb.getXPSplit(i); i -= k; this.player.world.spawnEntity(new EntityXPOrb(this.player.world, this.player.posX, this.player.posY + 0.5D, this.player.posZ + 0.5D, k)); } } this.removeCount = 0; net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack); }
/** * handles entity death timer, experience orb and particle creation */ protected void onDeathUpdate() { ++this.deathTime; if (this.deathTime == 20) { if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean("doMobLoot"))) { int i = this.getExperiencePoints(this.attackingPlayer); while (i > 0) { int j = EntityXPOrb.getXPSplit(i); i -= j; this.world.spawnEntityInWorld(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j)); } } this.setDead(); for (int k = 0; k < 20; ++k) { double d2 = this.rand.nextGaussian() * 0.02D; double d0 = this.rand.nextGaussian() * 0.02D; double d1 = this.rand.nextGaussian() * 0.02D; this.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d2, d0, d1, new int[0]); } } }
/** * Called when the entity picks up an item. */ public void onItemPickup(Entity entityIn, int quantity) { if (!entityIn.isDead && !this.world.isRemote) { EntityTracker entitytracker = ((WorldServer)this.world).getEntityTracker(); if (entityIn instanceof EntityItem || entityIn instanceof EntityArrow || entityIn instanceof EntityXPOrb) { entitytracker.sendToAllTrackingEntity(entityIn, new SPacketCollectItem(entityIn.getEntityId(), this.getEntityId(), quantity)); } } }
public void useRecipe(MerchantRecipe recipe) { recipe.incrementToolUses(); this.livingSoundTime = -this.getTalkInterval(); this.playSound(SoundEvents.ENTITY_VILLAGER_YES, this.getSoundVolume(), this.getSoundPitch()); int i = 3 + this.rand.nextInt(4); if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0) { this.timeUntilReset = 40; this.needsInitilization = true; this.isWillingToMate = true; if (this.buyingPlayer != null) { this.lastBuyingPlayer = this.buyingPlayer.getName(); } else { this.lastBuyingPlayer = null; } i += 5; } if (recipe.getItemToBuy().getItem() == Items.EMERALD) { this.wealth += recipe.getItemToBuy().func_190916_E(); } if (recipe.getRewardsExp()) { this.world.spawnEntityInWorld(new EntityXPOrb(this.world, this.posX, this.posY + 0.5D, this.posZ, i)); } }