2018-08-26 18:11:49 +00:00
|
|
|
From e1de8e00ef96880a95e17dee22f3e1f1ad5ed3f5 Mon Sep 17 00:00:00 2001
|
2017-12-19 21:46:27 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Tue, 19 Dec 2017 16:31:46 -0500
|
|
|
|
Subject: [PATCH] ExperienceOrbs API for Reason/Source/Triggering player
|
|
|
|
|
|
|
|
Adds lots of information about why this orb exists.
|
|
|
|
|
|
|
|
Replaces isFromBottle() with logic that persists entity reloads too.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 7818a3b6a7..d55b076f5d 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Block.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Block.java
|
2018-08-26 18:11:49 +00:00
|
|
|
@@ -454,13 +454,13 @@ public class Block implements IMaterial {
|
2017-12-19 21:46:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- protected void dropExperience(World world, BlockPosition blockposition, int i) {
|
|
|
|
+ protected void dropExperience(World world, BlockPosition blockposition, int i, EntityPlayer player) { // Paper
|
|
|
|
if (!world.isClientSide && world.getGameRules().getBoolean("doTileDrops")) {
|
|
|
|
while (i > 0) {
|
|
|
|
int j = EntityExperienceOrb.getOrbValue(i);
|
|
|
|
|
|
|
|
i -= j;
|
|
|
|
- world.addEntity(new EntityExperienceOrb(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, j));
|
|
|
|
+ world.addEntity(new EntityExperienceOrb(world, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, j, org.bukkit.entity.ExperienceOrb.SpawnReason.BLOCK_BREAK, player)); // Paper
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityEnderDragon.java b/src/main/java/net/minecraft/server/EntityEnderDragon.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index b9afeaf72e..2c735a920d 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityEnderDragon.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityEnderDragon.java
|
|
|
|
@@ -618,7 +618,7 @@ public class EntityEnderDragon extends EntityInsentient implements IComplex, IMo
|
|
|
|
int j = EntityExperienceOrb.getOrbValue(i);
|
|
|
|
|
|
|
|
i -= j;
|
|
|
|
- this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
|
|
|
|
+ this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j, org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, this.killer, this)); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 880f496526..31c8d4bc86 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -15,9 +15,59 @@ public class EntityExperienceOrb extends Entity {
|
2017-12-19 21:46:27 +00:00
|
|
|
public int value;
|
|
|
|
private EntityHuman targetPlayer;
|
|
|
|
private int targetTime;
|
|
|
|
+ // Paper start
|
|
|
|
+ public java.util.UUID sourceEntityId;
|
|
|
|
+ public java.util.UUID triggerEntityId;
|
|
|
|
+ public org.bukkit.entity.ExperienceOrb.SpawnReason spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN;
|
|
|
|
+
|
|
|
|
+ private void loadPaperNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
+ if (!nbttagcompound.hasKeyOfType("Paper.ExpData", 10)) { // 10 = compound
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ NBTTagCompound comp = nbttagcompound.getCompound("Paper.ExpData");
|
|
|
|
+ if (comp.hasUUID("source")) {
|
|
|
|
+ this.sourceEntityId = comp.getUUID("source");
|
|
|
|
+ }
|
|
|
|
+ if (comp.hasUUID("trigger")) {
|
|
|
|
+ this.triggerEntityId = comp.getUUID("trigger");
|
|
|
|
+ }
|
|
|
|
+ if (comp.hasKey("reason")) {
|
|
|
|
+ String reason = comp.getString("reason");
|
|
|
|
+ try {
|
|
|
|
+ spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.valueOf(reason);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ this.world.getServer().getLogger().warning("Invalid spawnReason set for experience orb: " + e.getMessage() + " - " + reason);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void savePaperNBT(NBTTagCompound nbttagcompound) {
|
|
|
|
+ NBTTagCompound comp = new NBTTagCompound();
|
|
|
|
+ if (sourceEntityId != null) {
|
|
|
|
+ comp.setUUID("source", sourceEntityId);
|
|
|
|
+ }
|
|
|
|
+ if (triggerEntityId != null) {
|
|
|
|
+ comp.setUUID("trigger", triggerEntityId);
|
|
|
|
+ }
|
|
|
|
+ if (spawnReason != null && spawnReason != org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN) {
|
|
|
|
+ comp.setString("reason", spawnReason.name());
|
|
|
|
+ }
|
|
|
|
+ nbttagcompound.set("Paper.ExpData", comp);
|
|
|
|
+ }
|
2018-07-17 20:32:05 +00:00
|
|
|
|
|
|
|
public EntityExperienceOrb(World world, double d0, double d1, double d2, int i) {
|
|
|
|
+ this(world, d0, d1, d2, i, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
2017-12-19 21:46:27 +00:00
|
|
|
+ public EntityExperienceOrb(World world, double d0, double d1, double d2, int i, org.bukkit.entity.ExperienceOrb.SpawnReason reason, Entity triggerId) {
|
|
|
|
+ this(world, d0, d1, d2, i, reason, triggerId, null);
|
|
|
|
+ }
|
2018-07-17 20:32:05 +00:00
|
|
|
+
|
2017-12-19 21:46:27 +00:00
|
|
|
+ public EntityExperienceOrb(World world, double d0, double d1, double d2, int i, org.bukkit.entity.ExperienceOrb.SpawnReason reason, Entity triggerId, Entity sourceId) {
|
2018-07-17 20:32:05 +00:00
|
|
|
super(EntityTypes.EXPERIENCE_ORB, world);
|
2017-12-19 21:46:27 +00:00
|
|
|
+ this.sourceEntityId = sourceId != null ? sourceId.getUniqueID() : null;
|
|
|
|
+ this.triggerEntityId = triggerId != null ? triggerId.getUniqueID() : null;
|
|
|
|
+ this.spawnReason = reason != null ? reason : org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN;
|
|
|
|
+ // Paper end
|
|
|
|
this.setSize(0.5F, 0.5F);
|
|
|
|
this.setPosition(d0, d1, d2);
|
|
|
|
this.yaw = (float) (Math.random() * 360.0D);
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -156,12 +206,14 @@ public class EntityExperienceOrb extends Entity {
|
2017-12-19 21:46:27 +00:00
|
|
|
nbttagcompound.setShort("Health", (short) this.d);
|
|
|
|
nbttagcompound.setShort("Age", (short) this.b);
|
|
|
|
nbttagcompound.setShort("Value", (short) this.value);
|
|
|
|
+ savePaperNBT(nbttagcompound); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NBTTagCompound nbttagcompound) {
|
|
|
|
this.d = nbttagcompound.getShort("Health");
|
|
|
|
this.b = nbttagcompound.getShort("Age");
|
|
|
|
this.value = nbttagcompound.getShort("Value");
|
|
|
|
+ loadPaperNBT(nbttagcompound); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public void d(EntityHuman entityhuman) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 81de03084a..4c92896ef8 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityFishingHook.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityFishingHook.java
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -467,7 +467,7 @@ public class EntityFishingHook extends Entity {
|
2017-12-19 21:46:27 +00:00
|
|
|
this.world.addEntity(entityitem);
|
|
|
|
// CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
|
|
|
|
if (playerFishEvent.getExpToDrop() > 0) {
|
|
|
|
- this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, playerFishEvent.getExpToDrop()));
|
|
|
|
+ this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, playerFishEvent.getExpToDrop(), org.bukkit.entity.ExperienceOrb.SpawnReason.FISHING, this.owner, this)); // Paper
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2018-08-26 18:11:49 +00:00
|
|
|
if (itemstack1.getItem().a(TagsItem.FISHES)) {
|
2017-12-19 21:46:27 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 60f22959b5..1b8763f618 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2018-08-04 21:03:53 +00:00
|
|
|
@@ -354,7 +354,8 @@ public abstract class EntityLiving extends Entity {
|
2017-12-19 21:46:27 +00:00
|
|
|
int j = EntityExperienceOrb.getOrbValue(i);
|
|
|
|
|
|
|
|
i -= j;
|
|
|
|
- this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
|
|
|
|
+ EntityLiving attacker = killer != null ? killer : lastDamager; // Paper
|
2018-05-18 23:40:33 +00:00
|
|
|
+ this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j, this instanceof EntityPlayer ? org.bukkit.entity.ExperienceOrb.SpawnReason.PLAYER_DEATH : org.bukkit.entity.ExperienceOrb.SpawnReason.ENTITY_DEATH, attacker, this)); // Paper
|
2017-12-19 21:46:27 +00:00
|
|
|
}
|
|
|
|
this.expToDrop = 0;
|
|
|
|
// CraftBukkit end
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityThrownExpBottle.java b/src/main/java/net/minecraft/server/EntityThrownExpBottle.java
|
2018-07-23 08:39:55 +00:00
|
|
|
index a5e1939e05..e73dba09a6 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityThrownExpBottle.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityThrownExpBottle.java
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -36,7 +36,7 @@ public class EntityThrownExpBottle extends EntityProjectile {
|
2017-12-19 21:46:27 +00:00
|
|
|
int j = EntityExperienceOrb.getOrbValue(i);
|
|
|
|
|
|
|
|
i -= j;
|
|
|
|
- this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j));
|
|
|
|
+ this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j, org.bukkit.entity.ExperienceOrb.SpawnReason.EXP_BOTTLE, getShooter(), this)); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
this.die();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityVillager.java b/src/main/java/net/minecraft/server/EntityVillager.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 0227196f1e..8fe68c2eb4 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityVillager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityVillager.java
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -411,7 +411,7 @@ public class EntityVillager extends EntityAgeable implements NPC, IMerchant {
|
2017-12-19 21:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (merchantrecipe.j()) {
|
|
|
|
- this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY + 0.5D, this.locZ, i));
|
|
|
|
+ this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY + 0.5D, this.locZ, i, org.bukkit.entity.ExperienceOrb.SpawnReason.VILLAGER_TRADE, tradingPlayer, this)); // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.tradingPlayer instanceof EntityPlayer) {
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalBreed.java b/src/main/java/net/minecraft/server/PathfinderGoalBreed.java
|
2018-07-23 08:39:55 +00:00
|
|
|
index 4a128f707b..b870964674 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PathfinderGoalBreed.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PathfinderGoalBreed.java
|
|
|
|
@@ -122,7 +122,7 @@ public class PathfinderGoalBreed extends PathfinderGoal {
|
2018-07-17 20:32:05 +00:00
|
|
|
if (this.b.getGameRules().getBoolean("doMobLoot")) {
|
2017-12-19 21:46:27 +00:00
|
|
|
// CraftBukkit start - use event experience
|
|
|
|
if (experience > 0) {
|
2018-07-17 20:32:05 +00:00
|
|
|
- this.b.addEntity(new EntityExperienceOrb(this.b, this.animal.locX, this.animal.locY, this.animal.locZ, experience));
|
|
|
|
+ this.b.addEntity(new EntityExperienceOrb(this.b, this.animal.locX, this.animal.locY, this.animal.locZ, experience, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, entityplayer, entityageable)); // Paper
|
2017-12-19 21:46:27 +00:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 1bfa7e5e69..4e44180329 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
|
2018-08-03 05:04:28 +00:00
|
|
|
@@ -385,7 +385,7 @@ public class PlayerInteractManager {
|
2017-12-19 21:46:27 +00:00
|
|
|
|
|
|
|
// CraftBukkit start - Drop event experience
|
|
|
|
if (flag && event != null) {
|
|
|
|
- iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop());
|
|
|
|
+ iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop(), this.player); // Paper
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/SlotFurnaceResult.java b/src/main/java/net/minecraft/server/SlotFurnaceResult.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 22c47c63c7..52e296d468 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/SlotFurnaceResult.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/SlotFurnaceResult.java
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -9,7 +9,7 @@ import org.bukkit.event.inventory.FurnaceExtractEvent;
|
2017-12-19 21:46:27 +00:00
|
|
|
|
|
|
|
public class SlotFurnaceResult extends Slot {
|
|
|
|
|
|
|
|
- private final EntityHuman a;
|
|
|
|
+ private final EntityHuman a;public EntityHuman getPlayer() { return a; } // Paper OBFHELPER
|
|
|
|
private int b;
|
|
|
|
|
|
|
|
public SlotFurnaceResult(EntityHuman entityhuman, IInventory iinventory, int i, int j, int k) {
|
2018-07-17 20:32:05 +00:00
|
|
|
@@ -85,7 +85,7 @@ public class SlotFurnaceResult extends Slot {
|
|
|
|
while (i > 0) {
|
|
|
|
j = EntityExperienceOrb.getOrbValue(i);
|
|
|
|
i -= j;
|
|
|
|
- this.a.world.addEntity(new EntityExperienceOrb(this.a.world, this.a.locX, this.a.locY + 0.5D, this.a.locZ + 0.5D, j));
|
|
|
|
+ this.a.world.addEntity(new EntityExperienceOrb(this.a.world, this.a.locX, this.a.locY + 0.5D, this.a.locZ + 0.5D, j, org.bukkit.entity.ExperienceOrb.SpawnReason.FURNACE, getPlayer())); // Paper
|
|
|
|
}
|
2017-12-19 21:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-08-26 18:11:49 +00:00
|
|
|
index 5bfcedccc1..6347d3d1f2 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2018-08-26 18:11:49 +00:00
|
|
|
@@ -1209,7 +1209,7 @@ public class CraftWorld implements World {
|
2017-12-19 21:46:27 +00:00
|
|
|
} else if (TNTPrimed.class.isAssignableFrom(clazz)) {
|
|
|
|
entity = new EntityTNTPrimed(world, x, y, z, null);
|
|
|
|
} else if (ExperienceOrb.class.isAssignableFrom(clazz)) {
|
|
|
|
- entity = new EntityExperienceOrb(world, x, y, z, 0);
|
|
|
|
+ entity = new EntityExperienceOrb(world, x, y, z, 0, org.bukkit.entity.ExperienceOrb.SpawnReason.CUSTOM, null, null); // Paper
|
|
|
|
} else if (Weather.class.isAssignableFrom(clazz)) {
|
|
|
|
// not sure what this can do
|
|
|
|
if (LightningStrike.class.isAssignableFrom(clazz)) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java
|
2018-07-23 08:39:55 +00:00
|
|
|
index 3a09cab3d4..3302af0e45 100644
|
2017-12-19 21:46:27 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftExperienceOrb.java
|
|
|
|
@@ -18,6 +18,18 @@ public class CraftExperienceOrb extends CraftEntity implements ExperienceOrb {
|
|
|
|
getHandle().value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ public java.util.UUID getTriggerEntityId() {
|
|
|
|
+ return getHandle().triggerEntityId;
|
|
|
|
+ }
|
|
|
|
+ public java.util.UUID getSourceEntityId() {
|
|
|
|
+ return getHandle().sourceEntityId;
|
|
|
|
+ }
|
|
|
|
+ public SpawnReason getSpawnReason() {
|
|
|
|
+ return getHandle().spawnReason;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public EntityExperienceOrb getHandle() {
|
|
|
|
return (EntityExperienceOrb) entity;
|
|
|
|
--
|
2018-07-20 19:57:43 +00:00
|
|
|
2.18.0
|
2017-12-19 21:46:27 +00:00
|
|
|
|