From c1aac9ca353a1b839125be86e0a11ffa37a422ed Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 22 Oct 2022 22:55:28 -0400 Subject: [PATCH] Don't fire EntityToggleSitEvent on deserialization & reorder some api patches (#8495) --- patches/api/Added-EntityToggleSitEvent.patch | 12 ------- .../server/Added-EntityToggleSitEvent.patch | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/patches/api/Added-EntityToggleSitEvent.patch b/patches/api/Added-EntityToggleSitEvent.patch index 1135f24c10..4e9afcb22f 100644 --- a/patches/api/Added-EntityToggleSitEvent.patch +++ b/patches/api/Added-EntityToggleSitEvent.patch @@ -26,26 +26,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private boolean cancelled; -+ private final Entity entity; + private final boolean isSitting; + + public EntityToggleSitEvent(@NotNull Entity entity, boolean isSitting) { + super(entity); -+ this.entity = entity; + this.isSitting = isSitting; + } + + /** -+ * The entity involved. -+ * -+ * @return The entity. -+ */ -+ @NotNull -+ public Entity getEntity() { -+ return this.entity; -+ } -+ -+ /** + * Gets the new sitting state that the entity will change to. + * + * @return If it's going to sit or not. diff --git a/patches/server/Added-EntityToggleSitEvent.patch b/patches/server/Added-EntityToggleSitEvent.patch index f73cd5107b..9ae5b1fa88 100644 --- a/patches/server/Added-EntityToggleSitEvent.patch +++ b/patches/server/Added-EntityToggleSitEvent.patch @@ -8,11 +8,25 @@ diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/m index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java +++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java +@@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { + } + + this.orderedToSit = nbt.getBoolean("Sitting"); +- this.setInSittingPose(this.orderedToSit); ++ this.setInSittingPose(this.orderedToSit, false); // Paper - Don't fire event + } + + @Override @@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { } public void setInSittingPose(boolean inSittingPose) { -+ if (!new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), inSittingPose).callEvent()) return; // Paper start - call EntityToggleSitEvent ++ // Paper start ++ this.setInSittingPose(inSittingPose, true); ++ } ++ public void setInSittingPose(boolean inSittingPose, boolean callEvent) { ++ // Paper end ++ if (callEvent && !new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), inSittingPose).callEvent()) return; // Paper start - call EntityToggleSitEvent byte b = this.entityData.get(DATA_FLAGS_ID); if (inSittingPose) { this.entityData.set(DATA_FLAGS_ID, (byte)(b | 1)); @@ -20,11 +34,25 @@ diff --git a/src/main/java/net/minecraft/world/entity/animal/Fox.java b/src/main index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/Fox.java +++ b/src/main/java/net/minecraft/world/entity/animal/Fox.java +@@ -0,0 +0,0 @@ public class Fox extends Animal { + + this.setSleeping(nbt.getBoolean("Sleeping")); + this.setFoxType(Fox.Type.byName(nbt.getString("Type"))); +- this.setSitting(nbt.getBoolean("Sitting")); ++ this.setSitting(nbt.getBoolean("Sitting"), false); // Paper + this.setIsCrouching(nbt.getBoolean("Crouching")); + if (this.level instanceof ServerLevel) { + this.setTargetGoals(); @@ -0,0 +0,0 @@ public class Fox extends Animal { } public void setSitting(boolean sitting) { -+ if (!new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), sitting).callEvent()) return; // Paper start - call EntityToggleSitEvent ++ this.setSitting(sitting, true); ++ } ++ // Paper start ++ public void setSitting(boolean sitting, boolean fireEvent) { ++ if (fireEvent && !new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), sitting).callEvent()) return; ++ // Paper end this.setFlag(1, sitting); }