1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
--- a/net/minecraft/world/entity/ExperienceOrb.java
+++ b/net/minecraft/world/entity/ExperienceOrb.java
@@ -20,6 +20,12 @@
import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
+// CraftBukkit end
public class ExperienceOrb extends Entity {
@@ -62,6 +65,7 @@
@Override
public void tick() {
super.tick();
+ Player prevTarget = this.followingPlayer;// CraftBukkit - store old target
this.xo = this.getX();
this.yo = this.getY();
this.zo = this.getZ();
@@ -87,10 +91,25 @@
this.followingPlayer = null;
}
- if (this.followingPlayer != null) {
- Vec3 vec3 = new Vec3(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
- double d0 = vec3.lengthSqr();
+ // CraftBukkit start
+ boolean cancelled = false;
+ if (this.followingPlayer != prevTarget) {
+ EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this, followingPlayer, (followingPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET);
+ LivingEntity target = (event.getTarget() == null) ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle();
+ cancelled = event.isCancelled();
+ if (cancelled) {
+ followingPlayer = prevTarget;
+ } else {
+ followingPlayer = (target instanceof Player) ? (Player) target : null;
+ }
+ }
+
+ if (this.followingPlayer != null && !cancelled) {
+ // CraftBukkit end
+ Vec3 vec3d = new Vec3(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ());
+ double d0 = vec3d.lengthSqr();
+
if (d0 < 64.0D) {
double d1 = 1.0D - Math.sqrt(d0) / 8.0D;
@@ -235,13 +248,13 @@
@Override
public void playerTouch(Player player) {
if (!this.level().isClientSide) {
- if (player.takeXpDelay == 0) {
- player.takeXpDelay = 2;
- player.take(this, 1);
- int i = this.repairPlayerItems(player, this.value);
+ if (entity.takeXpDelay == 0) {
+ entity.takeXpDelay = CraftEventFactory.callPlayerXpCooldownEvent(entity, 2, PlayerExpCooldownChangeEvent.ChangeReason.PICKUP_ORB).getNewCooldown(); // CraftBukkit - entityhuman.takeXpDelay = 2;
+ entity.take(this, 1);
+ int i = this.repairPlayerItems(entity, this.value);
if (i > 0) {
- player.giveExperiencePoints(i);
+ entity.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(entity, i).getAmount()); // CraftBukkit - this.value -> event.getAmount()
}
--this.count;
@@ -258,10 +271,18 @@
if (entry != null) {
ItemStack itemstack = (ItemStack) entry.getValue();
- int j = Math.min(this.xpToDurability(i), itemstack.getDamageValue());
+ int j = Math.min(this.xpToDurability(repairAmount), itemstack.getDamageValue());
+ // CraftBukkit start
+ org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(player, this, itemstack, entry.getKey(), j);
+ j = event.getRepairAmount();
+ if (event.isCancelled()) {
+ return repairAmount;
+ }
+ // CraftBukkit end
itemstack.setDamageValue(itemstack.getDamageValue() - j);
- int k = i - this.durabilityToXp(j);
+ int k = repairAmount - this.durabilityToXp(j);
+ this.value = k; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls
return k > 0 ? this.repairPlayerItems(player, k) : 0;
} else {
@@ -285,8 +306,26 @@
return this.value >= 2477 ? 10 : (this.value >= 1237 ? 9 : (this.value >= 617 ? 8 : (this.value >= 307 ? 7 : (this.value >= 149 ? 6 : (this.value >= 73 ? 5 : (this.value >= 37 ? 4 : (this.value >= 17 ? 3 : (this.value >= 7 ? 2 : (this.value >= 3 ? 1 : 0)))))))));
}
- public static int getExperienceValue(int i) {
- return i >= 2477 ? 2477 : (i >= 1237 ? 1237 : (i >= 617 ? 617 : (i >= 307 ? 307 : (i >= 149 ? 149 : (i >= 73 ? 73 : (i >= 37 ? 37 : (i >= 17 ? 17 : (i >= 7 ? 7 : (i >= 3 ? 3 : 1)))))))));
+ public static int getExperienceValue(int expValue) {
+ // CraftBukkit start
+ if (expValue > 162670129) return expValue - 100000;
+ if (expValue > 81335063) return 81335063;
+ if (expValue > 40667527) return 40667527;
+ if (expValue > 20333759) return 20333759;
+ if (expValue > 10166857) return 10166857;
+ if (expValue > 5083423) return 5083423;
+ if (expValue > 2541701) return 2541701;
+ if (expValue > 1270849) return 1270849;
+ if (expValue > 635413) return 635413;
+ if (expValue > 317701) return 317701;
+ if (expValue > 158849) return 158849;
+ if (expValue > 79423) return 79423;
+ if (expValue > 39709) return 39709;
+ if (expValue > 19853) return 19853;
+ if (expValue > 9923) return 9923;
+ if (expValue > 4957) return 4957;
+ // CraftBukkit end
+ return expValue >= 2477 ? 2477 : (expValue >= 1237 ? 1237 : (expValue >= 617 ? 617 : (expValue >= 307 ? 307 : (expValue >= 149 ? 149 : (expValue >= 73 ? 73 : (expValue >= 37 ? 37 : (expValue >= 17 ? 17 : (expValue >= 7 ? 7 : (expValue >= 3 ? 3 : 1)))))))));
}
@Override
|