From c44fa65ff4472c2cd859a1c86f48fafb16b75412 Mon Sep 17 00:00:00 2001 From: Poweruser_rs Date: Wed, 4 Nov 2015 02:26:18 +0100 Subject: [PATCH] Dont spam experience orb TargetEvents diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java index 0f540690b..a015e1cc1 100644 --- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java +++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java @@ -59,32 +59,43 @@ public class EntityExperienceOrb extends Entity { this.j(this.locX, (this.boundingBox.b + this.boundingBox.e) / 2.0D, this.locZ); double d0 = 8.0D; + // Poweruser start + EntityHuman foundTarget = null; if (this.targetTime < this.a - 20 + this.getId() % 100) { if (this.targetPlayer == null || this.targetPlayer.f(this) > d0 * d0) { - this.targetPlayer = this.world.findNearbyPlayer(this, d0); + foundTarget = this.world.findNearbyPlayer(this, d0); + if(foundTarget == null) { + this.targetPlayer = foundTarget; + } else if(foundTarget != null && !foundTarget.equals(this.targetPlayer)) { + // CraftBukkit start + EntityTargetEvent event = CraftEventFactory.callEntityTargetEvent(this, foundTarget, EntityTargetEvent.TargetReason.CLOSEST_PLAYER); + Entity target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle(); + if(!event.isCancelled()) { + if(target == null) { + this.targetPlayer = null; + } else if(target instanceof EntityHuman) { + this.targetPlayer = (EntityHuman) target; + } + } + // CraftBukkit end + } } - + // Poweruser end this.targetTime = this.a; } if (this.targetPlayer != null) { - // CraftBukkit start - EntityTargetEvent event = CraftEventFactory.callEntityTargetEvent(this, targetPlayer, EntityTargetEvent.TargetReason.CLOSEST_PLAYER); - Entity target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle(); - - if (!event.isCancelled() && target != null) { - double d1 = (target.locX - this.locX) / d0; - double d2 = (target.locY + (double) target.getHeadHeight() - this.locY) / d0; - double d3 = (target.locZ - this.locZ) / d0; - double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3); - double d5 = 1.0D - d4; - if (d5 > 0.0D) { - d5 *= d5; - this.motX += d1 / d4 * d5 * 0.1D; - this.motY += d2 / d4 * d5 * 0.1D; - this.motZ += d3 / d4 * d5 * 0.1D; - } - // CraftBukkit end + double d1 = (this.targetPlayer.locX - this.locX) / d0; + double d2 = (this.targetPlayer.locY + (double) this.targetPlayer.getHeadHeight() - this.locY) / d0; + double d3 = (this.targetPlayer.locZ - this.locZ) / d0; + double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3); + double d5 = 1.0D - d4; + + if (d5 > 0.0D) { + d5 *= d5; + this.motX += d1 / d4 * d5 * 0.1D; + this.motY += d2 / d4 * d5 * 0.1D; + this.motZ += d3 / d4 * d5 * 0.1D; } } -- 2.13.3