From 6a200a16632a7e45374013328b68e0403578a0d6 Mon Sep 17 00:00:00 2001
From: maxcom1 <46265094+maxcom1@users.noreply.github.com>
Date: Sat, 23 Mar 2024 22:26:17 +0100
Subject: [PATCH] Add methods to change entity physics (#10334)

---
 patches/api/Freeze-Tick-Lock-API.patch        |  4 +-
 patches/api/Improve-Arrow-API.patch           | 43 -------------------
 patches/api/Missing-Entity-API.patch          | 23 ++++++++--
 patches/api/More-Projectile-API.patch         | 21 ++++++---
 patches/server/Add-Entity-Body-Yaw-API.patch  |  2 +-
 .../Add-Raw-Byte-Entity-Serialization.patch   |  2 +-
 patches/server/Collision-API.patch            |  4 +-
 patches/server/Entity-powdered-snow-API.patch |  2 +-
 patches/server/Improve-Arrow-API.patch        | 38 ----------------
 patches/server/Missing-Entity-API.patch       | 19 ++++++--
 patches/server/More-Projectile-API.patch      | 14 ++++--
 11 files changed, 66 insertions(+), 106 deletions(-)
 delete mode 100644 patches/api/Improve-Arrow-API.patch
 delete mode 100644 patches/server/Improve-Arrow-API.patch

diff --git a/patches/api/Freeze-Tick-Lock-API.patch b/patches/api/Freeze-Tick-Lock-API.patch
index 0d40775b1e..b1b38aba2d 100644
--- a/patches/api/Freeze-Tick-Lock-API.patch
+++ b/patches/api/Freeze-Tick-Lock-API.patch
@@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/entity/Entity.java
 +++ b/src/main/java/org/bukkit/entity/Entity.java
 @@ -0,0 +0,0 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
-     boolean isInvisible();
-     // Paper end - move invisibility up to Entity
+     boolean hasNoPhysics();
+     // Paper end - missing entity api
  
 +    // Paper start - Freeze Tick Lock API
 +    /**
diff --git a/patches/api/Improve-Arrow-API.patch b/patches/api/Improve-Arrow-API.patch
deleted file mode 100644
index 36f6bc94b9..0000000000
--- a/patches/api/Improve-Arrow-API.patch
+++ /dev/null
@@ -1,43 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Nesaak <52047222+Nesaak@users.noreply.github.com>
-Date: Fri, 22 May 2020 13:35:21 -0400
-Subject: [PATCH] Improve Arrow API
-
-Add method to get the arrow's itemstack and a method
-to set the arrow's "noclip" status
-
-Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
-
-diff --git a/src/main/java/org/bukkit/entity/AbstractArrow.java b/src/main/java/org/bukkit/entity/AbstractArrow.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/org/bukkit/entity/AbstractArrow.java
-+++ b/src/main/java/org/bukkit/entity/AbstractArrow.java
-@@ -0,0 +0,0 @@ public interface AbstractArrow extends Projectile {
-     }
- 
-     // Paper start
-+    /**
-+     * Gets the ItemStack for this arrow.
-+     *
-+     * @return The ItemStack, as if a player picked up the arrow
-+     */
-+    @NotNull
-+    org.bukkit.inventory.ItemStack getItemStack();
-+
-+    /**
-+     * Sets this arrow to "noclip" status.
-+     *
-+     * @param noPhysics true to set "noclip"
-+     */
-+    void setNoPhysics(boolean noPhysics);
-+
-+    /**
-+     * Gets if this arrow has "noclip".
-+     *
-+     * @return true if noclip is active
-+     */
-+    boolean hasNoPhysics();
-+
-     /**
-      * Gets the {@link PickupRule} for this arrow.
-      *
diff --git a/patches/api/Missing-Entity-API.patch b/patches/api/Missing-Entity-API.patch
index 9daa6906b7..4e7f7a2345 100644
--- a/patches/api/Missing-Entity-API.patch
+++ b/patches/api/Missing-Entity-API.patch
@@ -11,6 +11,7 @@ Co-authored-by: booky10 <boooky10@gmail.com>
 Co-authored-by: Amin <amin.haddou@frg.wwschool.de>
 Co-authored-by: TrollyLoki <trollyloki@gmail.com>
 Co-authored-by: FireInstall <kettnerl@hu-berlin.de>
+Co-authored-by: maxcom1 <46265094+maxcom1@users.noreply.github.com>
 
 diff --git a/src/main/java/io/papermc/paper/entity/SchoolableFish.java b/src/main/java/io/papermc/paper/entity/SchoolableFish.java
 new file mode 100644
@@ -423,7 +424,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
       */
      boolean isFrozen();
  
-+    // Paper start - move invisibility up to Entity
++    // Paper start - missing entity api
 +    /**
 +     * Sets whether the entity is invisible or not.
 +     * <p>
@@ -433,15 +434,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     *
 +     * @param invisible If the entity is invisible
 +     */
-+    void setInvisible(boolean invisible);
++    void setInvisible(boolean invisible); // Paper - moved up from LivingEntity
 +
 +    /**
 +     * Gets whether the entity is invisible or not.
 +     *
 +     * @return Whether the entity is invisible
 +     */
-+    boolean isInvisible();
-+    // Paper end - move invisibility up to Entity
++    boolean isInvisible(); // Paper - moved up from LivingEntity
++
++    /**
++     * Sets this entities no physics status.
++     *
++     * @param noPhysics boolean indicating if the entity should not have physics.
++     */
++    void setNoPhysics(boolean noPhysics);
++
++    /**
++     * Gets if this entity has no physics.
++     *
++     * @return true if the entity does not have physics.
++     */
++    boolean hasNoPhysics();
++    // Paper end - missing entity api
 +
      /**
       * Mark the entity's removal.
diff --git a/patches/api/More-Projectile-API.patch b/patches/api/More-Projectile-API.patch
index ead97d0bc5..8dedca669d 100644
--- a/patches/api/More-Projectile-API.patch
+++ b/patches/api/More-Projectile-API.patch
@@ -10,9 +10,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/entity/AbstractArrow.java
 +++ b/src/main/java/org/bukkit/entity/AbstractArrow.java
 @@ -0,0 +0,0 @@ public interface AbstractArrow extends Projectile {
-     @NotNull
-     org.bukkit.inventory.ItemStack getItemStack();
- 
+         ALLOWED,
+         CREATIVE_ONLY;
+     }
++
++    /**
++     * Gets the ItemStack for this arrow.
++     *
++     * @return The ItemStack, as if a player picked up the arrow
++     */
++    @NotNull
++    org.bukkit.inventory.ItemStack getItemStack();
++
 +    /**
 +     * Sets the amount of ticks this arrow has been alive in the world
 +     * This is used to determine when the arrow should be automatically despawned.
@@ -42,10 +51,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +     * @param sound sound that is played
 +     */
 +    void setHitSound(@NotNull org.bukkit.Sound sound);
-+
-     /**
-      * Sets this arrow to "noclip" status.
-      *
+     // Paper end
+ }
 diff --git a/src/main/java/org/bukkit/entity/Firework.java b/src/main/java/org/bukkit/entity/Firework.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/entity/Firework.java
diff --git a/patches/server/Add-Entity-Body-Yaw-API.patch b/patches/server/Add-Entity-Body-Yaw-API.patch
index 699c14988a..2493c6b621 100644
--- a/patches/server/Add-Entity-Body-Yaw-API.patch
+++ b/patches/server/Add-Entity-Body-Yaw-API.patch
@@ -39,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
      // Paper end
  
-     // Paper start - move up invisibility
+     // Paper start - missing entity api
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
diff --git a/patches/server/Add-Raw-Byte-Entity-Serialization.patch b/patches/server/Add-Raw-Byte-Entity-Serialization.patch
index 61c20cc4ed..96d670b2bc 100644
--- a/patches/server/Add-Raw-Byte-Entity-Serialization.patch
+++ b/patches/server/Add-Raw-Byte-Entity-Serialization.patch
@@ -46,7 +46,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
      // Paper end
  
-     // Paper start - move up invisibility
+     // Paper start - missing entity api
 diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
diff --git a/patches/server/Collision-API.patch b/patches/server/Collision-API.patch
index 0b5a027d81..1899612923 100644
--- a/patches/server/Collision-API.patch
+++ b/patches/server/Collision-API.patch
@@ -26,9 +26,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
 @@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
-         this.getHandle().setSharedFlag(Entity.FLAG_INVISIBLE, invisible);
+         return this.getHandle().noPhysics;
      }
-     // Paper end - move up invisibility
+     // Paper end - missing entity api
 +
 +    // Paper start - Collision API
 +    @Override
diff --git a/patches/server/Entity-powdered-snow-API.patch b/patches/server/Entity-powdered-snow-API.patch
index 2f8e7d7edd..a1426ef7f5 100644
--- a/patches/server/Entity-powdered-snow-API.patch
+++ b/patches/server/Entity-powdered-snow-API.patch
@@ -21,7 +21,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
      // Paper end
  
-     // Paper start - move up invisibility
+     // Paper start - missing entity api
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeleton.java
diff --git a/patches/server/Improve-Arrow-API.patch b/patches/server/Improve-Arrow-API.patch
deleted file mode 100644
index 38ffc8c59a..0000000000
--- a/patches/server/Improve-Arrow-API.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Nesaak <52047222+Nesaak@users.noreply.github.com>
-Date: Sat, 23 May 2020 10:31:11 -0400
-Subject: [PATCH] Improve Arrow API
-
-Add method to get the arrow's itemstack and a method
-to set the arrow's "noclip" status
-
-Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
-
-diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
-+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
-@@ -0,0 +0,0 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
-         this.getHandle().pickup = net.minecraft.world.entity.projectile.AbstractArrow.Pickup.byOrdinal(status.ordinal());
-     }
- 
-+    // Paper start
-+    @Override
-+    public org.bukkit.craftbukkit.inventory.CraftItemStack getItemStack() {
-+        return org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(getHandle().getPickupItem());
-+    }
-+
-+    @Override
-+    public void setNoPhysics(boolean noPhysics) {
-+        this.getHandle().setNoPhysics(noPhysics);
-+    }
-+
-+    @Override
-+    public boolean hasNoPhysics() {
-+        return this.getHandle().isNoPhysics();
-+    }
-+    // Paper end
-+
-     @Override
-     public void setTicksLived(int value) {
-         super.setTicksLived(value);
diff --git a/patches/server/Missing-Entity-API.patch b/patches/server/Missing-Entity-API.patch
index f44271ae14..41b9983b39 100644
--- a/patches/server/Missing-Entity-API.patch
+++ b/patches/server/Missing-Entity-API.patch
@@ -39,6 +39,7 @@ Co-authored-by: booky10 <boooky10@gmail.com>
 Co-authored-by: Amin <amin.haddou@frg.wwschool.de>
 Co-authored-by: TrollyLoki <trollyloki@gmail.com>
 Co-authored-by: FireInstall <kettnerl@hu-berlin.de>
+Co-authored-by: maxcom1 <46265094+maxcom1@users.noreply.github.com>
 
 diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@@ -678,18 +679,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
      // Paper end
 +
-+    // Paper start - move up invisibility
++    // Paper start - missing entity api
 +    @Override
-+    public boolean isInvisible() {
++    public boolean isInvisible() {  // Paper - moved up from LivingEntity
 +        return this.getHandle().isInvisible();
 +    }
 +
 +    @Override
-+    public void setInvisible(boolean invisible) {
++    public void setInvisible(boolean invisible) {  // Paper - moved up from LivingEntity
 +        this.getHandle().persistentInvisibility = invisible;
 +        this.getHandle().setSharedFlag(Entity.FLAG_INVISIBLE, invisible);
 +    }
-+    // Paper end - move up invisibility
++
++    @Override
++    public void setNoPhysics(boolean noPhysics) {
++        this.getHandle().noPhysics = noPhysics;
++    }
++
++    @Override
++    public boolean hasNoPhysics() {
++        return this.getHandle().noPhysics;
++    }
++    // Paper end - missing entity api
  }
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
diff --git a/patches/server/More-Projectile-API.patch b/patches/server/More-Projectile-API.patch
index fbf8640446..7e9dad172e 100644
--- a/patches/server/More-Projectile-API.patch
+++ b/patches/server/More-Projectile-API.patch
@@ -159,9 +159,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      @Override
      public boolean isInBlock() {
 @@ -0,0 +0,0 @@ public class CraftArrow extends AbstractProjectile implements AbstractArrow {
-         return org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(getHandle().getPickupItem());
+         this.getHandle().pickup = net.minecraft.world.entity.projectile.AbstractArrow.Pickup.byOrdinal(status.ordinal());
      }
  
++    // Paper start
++    @Override
++    @org.jetbrains.annotations.NotNull
++    public org.bukkit.craftbukkit.inventory.CraftItemStack getItemStack() {
++        return org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(getHandle().getPickupItem());
++    }
++
 +    @Override
 +    public void setLifetimeTicks(int ticks) {
 +        this.getHandle().life = ticks;
@@ -182,10 +189,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    public void setHitSound(@org.jetbrains.annotations.NotNull org.bukkit.Sound sound) {
 +        this.getHandle().setSoundEvent(org.bukkit.craftbukkit.CraftSound.bukkitToMinecraft(sound));
 +    }
++    // Paper end
 +
      @Override
-     public void setNoPhysics(boolean noPhysics) {
-         this.getHandle().setNoPhysics(noPhysics);
+     public void setTicksLived(int value) {
+         super.setTicksLived(value);
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java