1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Merge pull request #3961 from ybw0014/feat/piglin-head

Allow sword of beheading drop piglin heads
This commit is contained in:
Alessio Colombo 2023-12-06 14:24:49 +01:00 committed by GitHub
commit 963349d8f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Piglin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.WitherSkeleton; 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.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; 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.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.EntityKillHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
/** /**
* The {@link SwordOfBeheading} is a special kind of sword which allows you to obtain * 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. * 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. * 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<EntityKillHandler> {
private final ItemSetting<Integer> chanceSkeleton = new IntRangeSetting(this, "chance.SKELETON", 0, 40, 100); private final ItemSetting<Integer> chanceSkeleton = new IntRangeSetting(this, "chance.SKELETON", 0, 40, 100);
private final ItemSetting<Integer> chanceWitherSkeleton = new IntRangeSetting(this, "chance.WITHER_SKELETON", 0, 25, 100); private final ItemSetting<Integer> chanceWitherSkeleton = new IntRangeSetting(this, "chance.WITHER_SKELETON", 0, 25, 100);
private final ItemSetting<Integer> chanceCreeper = new IntRangeSetting(this, "chance.CREEPER", 0, 40, 100); private final ItemSetting<Integer> chanceCreeper = new IntRangeSetting(this, "chance.CREEPER", 0, 40, 100);
private final ItemSetting<Integer> chancePiglin = new IntRangeSetting(this, "chance.PIGLIN", 0, 40, 100);
private final ItemSetting<Integer> chancePlayer = new IntRangeSetting(this, "chance.PLAYER", 0, 70, 100); private final ItemSetting<Integer> chancePlayer = new IntRangeSetting(this, "chance.PLAYER", 0, 70, 100);
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public SwordOfBeheading(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { public SwordOfBeheading(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe); super(itemGroup, item, recipeType, recipe);
addItemSetting(chanceZombie, chanceSkeleton, chanceWitherSkeleton, chanceCreeper, chancePlayer); addItemSetting(chanceZombie, chanceSkeleton, chanceWitherSkeleton, chanceCreeper, chancePiglin, chancePlayer);
} }
@Override @Override
@ -56,27 +61,33 @@ public class SwordOfBeheading extends SimpleSlimefunItem<EntityKillHandler> {
Random random = ThreadLocalRandom.current(); Random random = ThreadLocalRandom.current();
switch (e.getEntityType()) { switch (e.getEntityType()) {
case ZOMBIE: case ZOMBIE -> {
if (random.nextInt(100) < chanceZombie.getValue()) { if (random.nextInt(100) < chanceZombie.getValue()) {
e.getDrops().add(new ItemStack(Material.ZOMBIE_HEAD)); e.getDrops().add(new ItemStack(Material.ZOMBIE_HEAD));
} }
break; }
case SKELETON: case SKELETON -> {
if (random.nextInt(100) < chanceSkeleton.getValue()) { if (random.nextInt(100) < chanceSkeleton.getValue()) {
e.getDrops().add(new ItemStack(Material.SKELETON_SKULL)); e.getDrops().add(new ItemStack(Material.SKELETON_SKULL));
} }
break; }
case CREEPER: case CREEPER -> {
if (random.nextInt(100) < chanceCreeper.getValue()) { if (random.nextInt(100) < chanceCreeper.getValue()) {
e.getDrops().add(new ItemStack(Material.CREEPER_HEAD)); e.getDrops().add(new ItemStack(Material.CREEPER_HEAD));
} }
break; }
case WITHER_SKELETON: case WITHER_SKELETON -> {
if (random.nextInt(100) < chanceWitherSkeleton.getValue()) { if (random.nextInt(100) < chanceWitherSkeleton.getValue()) {
e.getDrops().add(new ItemStack(Material.WITHER_SKELETON_SKULL)); 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()) { if (random.nextInt(100) < chancePlayer.getValue()) {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD); ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
@ -86,9 +97,8 @@ public class SwordOfBeheading extends SimpleSlimefunItem<EntityKillHandler> {
e.getDrops().add(skull); e.getDrops().add(skull);
} }
break; }
default: default -> {}
break;
} }
}; };
} }