Add methods to change entity physics (#10334)

This commit is contained in:
maxcom1 2024-03-23 22:26:17 +01:00
parent 0c76cbb7cc
commit 6a200a1663
11 changed files with 66 additions and 106 deletions

View File

@ -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
+ /**

View File

@ -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.
*

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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