PaperMC/patches/server/0137-Shoulder-Entities-Release-API.patch

95 lines
4.1 KiB
Diff
Raw Permalink Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 17 Jun 2017 15:18:30 -0400
Subject: [PATCH] Shoulder Entities Release API
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-12-03 19:05:31 +01:00
index 2f4909a26d6473bcf1bf4f71d05d77d2212ad745..4dcc510061adfd07a15fa7007aa4863f7e5d0037 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-12-03 19:05:31 +01:00
@@ -1951,7 +1951,31 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
}
2024-10-22 22:38:26 +02:00
+ // Paper start - release entity api
2021-06-11 14:02:28 +02:00
+ public Entity releaseLeftShoulderEntity() {
2023-06-07 22:19:14 +02:00
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityLeft());
2021-06-11 14:02:28 +02:00
+ if (entity != null) {
+ this.setShoulderEntityLeft(new CompoundTag());
+ }
+ return entity;
+ }
+
+ public Entity releaseRightShoulderEntity() {
2023-06-07 22:19:14 +02:00
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityRight());
2021-06-11 14:02:28 +02:00
+ if (entity != null) {
+ this.setShoulderEntityRight(new CompoundTag());
+ }
+ return entity;
+ }
2024-10-22 22:38:26 +02:00
+ // Paper end - release entity api
2023-06-07 21:37:42 +02:00
+
private boolean respawnEntityOnShoulder(CompoundTag nbttagcompound) { // CraftBukkit void->boolean
2024-10-22 22:38:26 +02:00
+ // Paper start - release entity api - return entity - overload
2023-06-07 22:19:14 +02:00
+ return this.respawnEntityOnShoulder0(nbttagcompound) != null;
2021-06-11 14:02:28 +02:00
+ }
+
2023-06-07 21:37:42 +02:00
+ private Entity respawnEntityOnShoulder0(CompoundTag nbttagcompound) { // CraftBukkit void->boolean
2024-10-22 22:38:26 +02:00
+ // 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
2021-06-11 14:02:28 +02:00
if (entity instanceof TamableAnimal) {
2024-12-03 19:05:31 +01:00
@@ -1959,11 +1983,11 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
}
entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ());
2023-06-07 21:37:42 +02:00
- return ((ServerLevel) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit
2021-06-11 14:02:28 +02:00
- }).orElse(true); // CraftBukkit
2024-10-22 22:38:26 +02:00
+ 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
2021-06-11 14:02:28 +02:00
}
- return true; // CraftBukkit
+ return null; // Paper - return null
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2024-10-22 22:38:26 +02:00
index bfa44c4e37618df3f745bccc6e775ce16c19490d..768a6e3f5d75d37ae114ffcf2b090fe9de769381 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2024-10-22 22:38:26 +02:00
@@ -544,6 +544,32 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
this.getHandle().getCooldowns().addCooldown(CraftItemStack.asNMSCopy(item), ticks);
2021-06-11 14:02:28 +02:00
}
+ // 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) {
2021-06-12 13:18:01 +02:00
return this.discoverRecipes(Arrays.asList(recipe)) != 0;