mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Add Shearable API
This commit is contained in:
parent
6e271dc9e4
commit
2e77028ed4
7 changed files with 67 additions and 4 deletions
|
@ -0,0 +1,8 @@
|
|||
--- a/net/minecraft/world/entity/Shearable.java
|
||||
+++ b/net/minecraft/world/entity/Shearable.java
|
||||
@@ -8,4 +8,5 @@
|
||||
void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears);
|
||||
|
||||
boolean readyForShearing();
|
||||
+ net.minecraft.world.level.Level level(); // Shearable API - expose default level needed for shearing.
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package io.papermc.paper.entity;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Shearable;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
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) {
|
||||
if (!(this.getHandle().level() instanceof final ServerLevel serverLevel)) return;
|
||||
this.getHandle().shear(serverLevel, PaperAdventure.asVanilla(source), new ItemStack(Items.SHEARS));
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import org.bukkit.craftbukkit.CraftServer;
|
|||
import org.bukkit.entity.Bogged;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
|
||||
public class CraftBogged extends CraftAbstractSkeleton implements Bogged {
|
||||
public class CraftBogged extends CraftAbstractSkeleton implements Bogged, io.papermc.paper.entity.PaperShearable { // Paper - Shear API
|
||||
|
||||
public CraftBogged(CraftServer server, net.minecraft.world.entity.monster.Bogged entity) {
|
||||
super(server, entity);
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.bukkit.entity.MushroomCow;
|
|||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.bukkit.DyeColor;
|
|||
import org.bukkit.craftbukkit.CraftServer;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.SnowGolem;
|
|||
import org.bukkit.craftbukkit.CraftServer;
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package io.papermc.paper.entity;
|
||||
|
||||
import com.destroystokyo.paper.entity.ai.MobGoalHelper;
|
||||
import io.github.classgraph.ClassGraph;
|
||||
import io.github.classgraph.ScanResult;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.Shearable;
|
||||
import org.bukkit.support.environment.Normal;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@Normal
|
||||
class ShearableTest {
|
||||
|
||||
static List<Class<Shearable>> nmsShearables() {
|
||||
try (final ScanResult result = new ClassGraph().enableClassInfo().whitelistPackages("net.minecraft.world.entity").scan()) {
|
||||
return result.getClassesImplementing(Shearable.class.getName()).loadClasses(Shearable.class);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ParameterizedTest
|
||||
@MethodSource("nmsShearables")
|
||||
void ensureImplementsShearable(final Class<? extends Shearable> shearableNmsClass) {
|
||||
final Class<? extends org.bukkit.entity.Mob> bukkitClass = MobGoalHelper.toBukkitClass((Class<? extends Mob>) shearableNmsClass);
|
||||
Assertions.assertTrue(io.papermc.paper.entity.Shearable.class.isAssignableFrom(bukkitClass), bukkitClass.getName() + " does not implement Shearable");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue