ExperienceOrb merging/stacking API and fixes

Adds an option for maximum exp value when merging orbs

Adds ExperienceOrbMergeEvent
Fired when the server is about to merge 2 experience orbs
as entities. Plugins can cancel it if they want to ensure experience orbs do not lose important
metadata such as spawn reason, or conditionally move data from source to target.

Fixes an issue where the stacked count was not taking into account
for mending repairs and when merging with spigot's merge-on-spawn
logic

== AT ==
public net.minecraft.world.entity.ExperienceOrb count

Co-authored-by: Aikar <aikar@aikar.co>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
BillyGalbreath
2017-11-10 23:03:12 -05:00
parent e5e4cc7020
commit e91df097e9
3 changed files with 48 additions and 8 deletions

View File

@@ -119,7 +119,7 @@
}
}
@@ -150,12 +227,20 @@
@@ -150,18 +227,27 @@
}
public static void award(ServerLevel world, Vec3 pos, int amount) {
@@ -141,8 +141,22 @@
}
}
@@ -190,7 +275,7 @@
}
private static boolean tryMergeToExisting(ServerLevel world, Vec3 pos, int amount) {
+ // Paper - TODO some other event for this kind of merge
AABB axisalignedbb = AABB.ofSize(pos, 1.0D, 1.0D, 1.0D);
int j = world.getRandom().nextInt(40);
List<ExperienceOrb> list = world.getEntities(EntityTypeTest.forClass(ExperienceOrb.class), axisalignedbb, (entityexperienceorb) -> {
@@ -188,9 +274,14 @@
}
private void merge(ExperienceOrb other) {
+ // Paper start - call orb merge event
+ if (!new com.destroystokyo.paper.event.entity.ExperienceOrbMergeEvent((org.bukkit.entity.ExperienceOrb) this.getBukkitEntity(), (org.bukkit.entity.ExperienceOrb) other.getBukkitEntity()).callEvent()) {
+ return;
+ }
+ // Paper end - call orb merge event
this.count += other.count;
this.age = Math.min(this.age, other.age);
- other.discard();
@@ -150,7 +164,7 @@
}
private void setUnderwaterMovement() {
@@ -215,7 +300,7 @@
@@ -215,7 +306,7 @@
this.markHurt();
this.health = (int) ((float) this.health - amount);
if (this.health <= 0) {
@@ -159,7 +173,7 @@
}
return true;
@@ -226,33 +311,35 @@
@@ -226,33 +317,35 @@
public void addAdditionalSaveData(CompoundTag nbt) {
nbt.putShort("Health", (short) this.health);
nbt.putShort("Age", (short) this.age);
@@ -201,7 +215,7 @@
}
}
@@ -266,12 +353,20 @@
@@ -266,12 +359,20 @@
ItemStack itemstack = ((EnchantedItemInUse) optional.get()).itemStack();
int j = EnchantmentHelper.modifyDurabilityToRepairFromXp(player.serverLevel(), itemstack, amount);
int k = Math.min(j, itemstack.getDamageValue());
@@ -218,11 +232,11 @@
int l = amount - k * amount / j;
if (l > 0) {
+ this.value = l; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls
+ // this.value = l; // CraftBukkit - update exp value of orb for PlayerItemMendEvent calls // Paper - the value field should not be mutated here because it doesn't take "count" into account
return this.repairPlayerItems(player, l);
}
}
@@ -291,6 +386,24 @@
@@ -291,6 +392,24 @@
}
public static int getExperienceValue(int value) {