mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Shoulder Entities Release API
This commit is contained in:
parent
551d6ee71e
commit
aab7ec1655
2 changed files with 56 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue