diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java index 42842880c..ce40980de 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/SwordOfBeheading.java @@ -8,6 +8,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Material; import org.bukkit.entity.Creeper; import org.bukkit.entity.Monster; +import org.bukkit.entity.Piglin; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.entity.WitherSkeleton; @@ -16,17 +17,20 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; /** * The {@link SwordOfBeheading} is a special kind of sword which allows you to obtain - * {@link Zombie}, {@link Skeleton} and {@link Creeper} skulls when killing the respective {@link Monster}. + * {@link Zombie}, {@link Skeleton}, {@link Creeper} and {@link Piglin} skulls when killing the respective + * {@link Monster}. * Additionally, you can also obtain the head of a {@link Player} by killing them too. * This sword also allows you to have a higher chance of getting the skull of a {@link WitherSkeleton} too. * @@ -41,13 +45,14 @@ public class SwordOfBeheading extends SimpleSlimefunItem { private final ItemSetting chanceSkeleton = new IntRangeSetting(this, "chance.SKELETON", 0, 40, 100); private final ItemSetting chanceWitherSkeleton = new IntRangeSetting(this, "chance.WITHER_SKELETON", 0, 25, 100); private final ItemSetting chanceCreeper = new IntRangeSetting(this, "chance.CREEPER", 0, 40, 100); + private final ItemSetting chancePiglin = new IntRangeSetting(this, "chance.PIGLIN", 0, 40, 100); private final ItemSetting chancePlayer = new IntRangeSetting(this, "chance.PLAYER", 0, 70, 100); @ParametersAreNonnullByDefault public SwordOfBeheading(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(itemGroup, item, recipeType, recipe); - addItemSetting(chanceZombie, chanceSkeleton, chanceWitherSkeleton, chanceCreeper, chancePlayer); + addItemSetting(chanceZombie, chanceSkeleton, chanceWitherSkeleton, chanceCreeper, chancePiglin, chancePlayer); } @Override @@ -56,27 +61,33 @@ public class SwordOfBeheading extends SimpleSlimefunItem { Random random = ThreadLocalRandom.current(); switch (e.getEntityType()) { - case ZOMBIE: + case ZOMBIE -> { if (random.nextInt(100) < chanceZombie.getValue()) { e.getDrops().add(new ItemStack(Material.ZOMBIE_HEAD)); } - break; - case SKELETON: + } + case SKELETON -> { if (random.nextInt(100) < chanceSkeleton.getValue()) { e.getDrops().add(new ItemStack(Material.SKELETON_SKULL)); } - break; - case CREEPER: + } + case CREEPER -> { if (random.nextInt(100) < chanceCreeper.getValue()) { e.getDrops().add(new ItemStack(Material.CREEPER_HEAD)); } - break; - case WITHER_SKELETON: + } + case WITHER_SKELETON -> { if (random.nextInt(100) < chanceWitherSkeleton.getValue()) { e.getDrops().add(new ItemStack(Material.WITHER_SKELETON_SKULL)); } - break; - case PLAYER: + } + case PIGLIN -> { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20) && + random.nextInt(100) < chancePiglin.getValue()) { + e.getDrops().add(new ItemStack(Material.PIGLIN_HEAD)); + } + } + case PLAYER -> { if (random.nextInt(100) < chancePlayer.getValue()) { ItemStack skull = new ItemStack(Material.PLAYER_HEAD); @@ -86,9 +97,8 @@ public class SwordOfBeheading extends SimpleSlimefunItem { e.getDrops().add(skull); } - break; - default: - break; + } + default -> {} } }; }