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

Merge pull request #2467 from CURVX/fix/nether-goo-sheep

Nether Goo "Tainted Sheep"
This commit is contained in:
TheBusyBiscuit 2020-10-13 23:27:55 +02:00 committed by GitHub
commit bebb514635
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,25 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.misc;
import javax.annotation.Nonnull;
import java.util.Optional;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.GameMode;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.entity.Piglin;
import org.bukkit.entity.Sheep;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.core.attributes.PiglinBarterDrop;
import io.github.thebusybiscuit.slimefun4.core.handlers.EntityInteractHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.VillagerRune;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -16,9 +27,6 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import javax.annotation.Nonnull;
import java.util.Optional;
/**
* This {@link SlimefunItem} can only be obtained via bartering with a {@link Piglin}, its
* only current uses is the recipe for crafting the {@link VillagerRune}.
@ -37,6 +45,7 @@ public class StrangeNetherGoo extends SimpleSlimefunItem<ItemUseHandler> impleme
super(category, item, recipeType, recipe);
addItemSetting(chance);
addItemHandler(onRightClickEntity());
}
@Override
@ -56,4 +65,27 @@ public class StrangeNetherGoo extends SimpleSlimefunItem<ItemUseHandler> impleme
};
}
private EntityInteractHandler onRightClickEntity() {
return (e, item, hand) -> {
if (e.getRightClicked() instanceof Sheep) {
Sheep s = (Sheep) e.getRightClicked();
if (s.getCustomName() != null) {
e.setCancelled(true);
return;
}
if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(item, false);
}
// Give Sheep color, name and effect
s.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 60, 2));
s.setColor(DyeColor.PURPLE);
s.setCustomName(ChatColor.DARK_PURPLE + "Tainted Sheep");
e.setCancelled(true);
}
};
}
}