From aab7ec1655f62570e7a25a6df49021eef3ecb626 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 17 Jun 2017 15:18:30 -0400 Subject: [PATCH] Shoulder Entities Release API --- .../world/entity/player/Player.java.patch | 38 +++++++++++++++---- .../craftbukkit/entity/CraftHumanEntity.java | 26 +++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch index 1028a8d8db..041d43c0d5 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/player/Player.java.patch @@ -428,14 +428,11 @@ } } -@@ -1798,26 +1939,31 @@ +@@ -1798,26 +1939,55 @@ public void removeEntitiesOnShoulder() { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { - this.respawnEntityOnShoulder(this.getShoulderEntityLeft()); -- this.setShoulderEntityLeft(new CompoundTag()); -- this.respawnEntityOnShoulder(this.getShoulderEntityRight()); -- this.setShoulderEntityRight(new CompoundTag()); + // CraftBukkit start + if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) { + this.setShoulderEntityLeft(new CompoundTag()); @@ -444,14 +441,39 @@ + this.setShoulderEntityRight(new CompoundTag()); + } + // CraftBukkit end ++ } ++ ++ } ++ ++ // Paper start - release entity api ++ public Entity releaseLeftShoulderEntity() { ++ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityLeft()); ++ if (entity != null) { + this.setShoulderEntityLeft(new CompoundTag()); +- this.respawnEntityOnShoulder(this.getShoulderEntityRight()); ++ } ++ return entity; ++ } ++ ++ public Entity releaseRightShoulderEntity() { ++ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityRight()); ++ if (entity != null) { + this.setShoulderEntityRight(new CompoundTag()); } ++ return entity; ++ } ++ // Paper end - release entity api ++ private boolean respawnEntityOnShoulder(CompoundTag nbttagcompound) { // CraftBukkit void->boolean ++ // Paper start - release entity api - return entity - overload ++ return this.respawnEntityOnShoulder0(nbttagcompound) != null; } - private void respawnEntityOnShoulder(CompoundTag entityNbt) { - if (!this.level().isClientSide && !entityNbt.isEmpty()) { - EntityType.create(entityNbt, this.level(), EntitySpawnReason.LOAD).ifPresent((entity) -> { -+ private boolean respawnEntityOnShoulder(CompoundTag nbttagcompound) { // CraftBukkit void->boolean ++ private Entity respawnEntityOnShoulder0(CompoundTag nbttagcompound) { // CraftBukkit void->boolean ++ // Paper end - release entity api - return entity - overload + if (!this.level().isClientSide && !nbttagcompound.isEmpty()) { + return EntityType.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).map((entity) -> { // CraftBukkit if (entity instanceof TamableAnimal) { @@ -461,11 +483,11 @@ entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ()); - ((ServerLevel) this.level()).addWithUUID(entity); - }); -+ return ((ServerLevel) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit -+ }).orElse(true); // CraftBukkit ++ return ((ServerLevel) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY) ? entity : null; // CraftBukkit // Paper start - release entity api - return entity ++ }).orElse(null); // CraftBukkit // Paper end - release entity api - return entity } -+ return true; // CraftBukkit ++ return null; // Paper - return null } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index bfa44c4e37..768a6e3f5d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -544,6 +544,32 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { this.getHandle().getCooldowns().addCooldown(CraftItemStack.asNMSCopy(item), ticks); } + // Paper start + @Override + public org.bukkit.entity.Entity releaseLeftShoulderEntity() { + if (!getHandle().getShoulderEntityLeft().isEmpty()) { + Entity entity = getHandle().releaseLeftShoulderEntity(); + if (entity != null) { + return entity.getBukkitEntity(); + } + } + + return null; + } + + @Override + public org.bukkit.entity.Entity releaseRightShoulderEntity() { + if (!getHandle().getShoulderEntityRight().isEmpty()) { + Entity entity = getHandle().releaseRightShoulderEntity(); + if (entity != null) { + return entity.getBukkitEntity(); + } + } + + return null; + } + // Paper end + @Override public boolean discoverRecipe(NamespacedKey recipe) { return this.discoverRecipes(Arrays.asList(recipe)) != 0;