mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add Shearable API (#6796)
This commit is contained in:
parent
b89c5fac03
commit
08482e72bb
2 changed files with 166 additions and 0 deletions
94
patches/api/Add-Shearable-API.patch
Normal file
94
patches/api/Add-Shearable-API.patch
Normal file
|
@ -0,0 +1,94 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
||||
Date: Sun, 17 Oct 2021 15:39:41 -0400
|
||||
Subject: [PATCH] Add Shearable API
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/entity/Shearable.java b/src/main/java/io/papermc/paper/entity/Shearable.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/entity/Shearable.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.entity;
|
||||
+
|
||||
+import net.kyori.adventure.sound.Sound;
|
||||
+import org.bukkit.entity.Entity;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * Represents an entity that can be sheared.
|
||||
+ */
|
||||
+public interface Shearable extends Entity {
|
||||
+
|
||||
+ /**
|
||||
+ * Forces the entity to be sheared and then play the effect as if it were sheared by a player.
|
||||
+ * This will cause the entity to be sheared, even if {@link Shearable#readyToBeSheared()} is false.
|
||||
+ * <p>
|
||||
+ * Some shearing behavior may cause the entity to no longer be valid
|
||||
+ * due to it being replaced by a different entity.
|
||||
+ */
|
||||
+ default void shear() {
|
||||
+ this.shear(Sound.Source.PLAYER);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Forces the entity to be sheared and then play the effect as if it were sheared by the provided source.
|
||||
+ * This will cause the entity to be sheared, even if {@link Shearable#readyToBeSheared()} is false.
|
||||
+ * <p>
|
||||
+ * Some shearing behavior may cause the entity to no longer be valid
|
||||
+ * due to it being replaced by a different entity.
|
||||
+ * <p>
|
||||
+ * This simulates the behavior of an actual shearing, which may cause events like EntityTransformEvent to be called
|
||||
+ * for mooshrooms, and EntityDropItemEvent to be called for sheep.
|
||||
+ *
|
||||
+ * @param source Sound source to play any sound effects on
|
||||
+ */
|
||||
+ void shear(@NotNull Sound.Source source);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets if the entity would be able to be sheared or not naturally using shears.
|
||||
+ *
|
||||
+ * @return if the entity can be sheared
|
||||
+ */
|
||||
+ boolean readyToBeSheared();
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/entity/MushroomCow.java b/src/main/java/org/bukkit/entity/MushroomCow.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/entity/MushroomCow.java
|
||||
+++ b/src/main/java/org/bukkit/entity/MushroomCow.java
|
||||
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* Represents a mushroom {@link Cow}
|
||||
*/
|
||||
-public interface MushroomCow extends Cow {
|
||||
+public interface MushroomCow extends Cow, io.papermc.paper.entity.Shearable { // Paper
|
||||
|
||||
/**
|
||||
* Get the variant of this cow.
|
||||
diff --git a/src/main/java/org/bukkit/entity/Sheep.java b/src/main/java/org/bukkit/entity/Sheep.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Sheep.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Sheep.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.material.Colorable;
|
||||
/**
|
||||
* Represents a Sheep.
|
||||
*/
|
||||
-public interface Sheep extends Animals, Colorable {
|
||||
+public interface Sheep extends Animals, Colorable, io.papermc.paper.entity.Shearable { // Paper - Shear API
|
||||
|
||||
/**
|
||||
* @return Whether the sheep is sheared.
|
||||
diff --git a/src/main/java/org/bukkit/entity/Snowman.java b/src/main/java/org/bukkit/entity/Snowman.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Snowman.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Snowman.java
|
||||
@@ -0,0 +0,0 @@ import com.destroystokyo.paper.entity.RangedEntity;
|
||||
/**
|
||||
* Represents a snowman entity
|
||||
*/
|
||||
-public interface Snowman extends Golem, RangedEntity { // Paper
|
||||
+public interface Snowman extends Golem, RangedEntity, io.papermc.paper.entity.Shearable { // Paper
|
||||
|
||||
/**
|
||||
* Gets whether this snowman is in "derp mode", meaning it is not wearing a
|
72
patches/server/Add-Shearable-API.patch
Normal file
72
patches/server/Add-Shearable-API.patch
Normal file
|
@ -0,0 +1,72 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
||||
Date: Sun, 17 Oct 2021 15:39:48 -0400
|
||||
Subject: [PATCH] Add Shearable API
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/entity/PaperShearable.java b/src/main/java/io/papermc/paper/entity/PaperShearable.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/entity/PaperShearable.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.entity;
|
||||
+
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import net.kyori.adventure.sound.Sound;
|
||||
+import net.minecraft.world.entity.Shearable;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public interface PaperShearable extends io.papermc.paper.entity.Shearable {
|
||||
+
|
||||
+ Shearable getHandle();
|
||||
+
|
||||
+ @Override
|
||||
+ default boolean readyToBeSheared() {
|
||||
+ return this.getHandle().readyForShearing();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ default void shear(@NotNull Sound.Source source) {
|
||||
+ this.getHandle().shear(PaperAdventure.asVanilla(source));
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.MushroomCow;
|
||||
import org.bukkit.entity.MushroomCow.Variant;
|
||||
|
||||
-public class CraftMushroomCow extends CraftCow implements MushroomCow {
|
||||
+public class CraftMushroomCow extends CraftCow implements MushroomCow, io.papermc.paper.entity.PaperShearable { // Paper
|
||||
public CraftMushroomCow(CraftServer server, net.minecraft.world.entity.animal.MushroomCow entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSheep.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSheep.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSheep.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSheep.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Sheep;
|
||||
|
||||
-public class CraftSheep extends CraftAnimals implements Sheep {
|
||||
+public class CraftSheep extends CraftAnimals implements Sheep, io.papermc.paper.entity.PaperShearable { // Paper
|
||||
public CraftSheep(CraftServer server, net.minecraft.world.entity.animal.Sheep entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Snowman;
|
||||
|
||||
-public class CraftSnowman extends CraftGolem implements Snowman, com.destroystokyo.paper.entity.CraftRangedEntity<SnowGolem> { // Paper
|
||||
+public class CraftSnowman extends CraftGolem implements Snowman, com.destroystokyo.paper.entity.CraftRangedEntity<SnowGolem>, io.papermc.paper.entity.PaperShearable { // Paper
|
||||
public CraftSnowman(CraftServer server, SnowGolem entity) {
|
||||
super(server, entity);
|
||||
}
|
Loading…
Reference in a new issue