1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

made requested changes

This commit is contained in:
dniym 2020-07-26 10:20:17 -04:00
parent 22a0623485
commit ba8aafe312
3 changed files with 48 additions and 15 deletions

View File

@ -0,0 +1,39 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* This interface, when attached to a {@link SlimefunItem}, provides an easy method for adding
* a % chance to drop for an {@link SlimefunItem} on {@link EntityItemDropEvent}, this chance is 0-100
* and used in conjunction with the BARTER_DROP {@link RecipeType}.
*
* @author dNiym
*
* @see MobDropListener
*
*/
@FunctionalInterface
public interface PiglinBarterDrop extends RandomMobDrop {
/**
* Implement this method to make the object have a variable chance of being
* dropped by Piglins when bartering with them. This interface should be used
* with a {@link SlimefunItem} item that has the BARTER_DROP {@link RecipeType}.
*
* It is recommended that this chance is kept reasonably low to feel like
* a vanilla drop as a 100% chance will completely override all Piglin
* barter drops. (NOTE: this feature only exists in 1.16+)
*
* @return The integer chance (0-100%) {@link SlimefunItem} has to drop.
*/
// int getMobDropChance();
}

View File

@ -2,6 +2,8 @@ package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;

View File

@ -16,25 +16,16 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.PiglinBarterDrop;
import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* This {@link Listener} prevents a {@link Piglin} from bartering with a {@link SlimefunItem}.
* This {@link Listener} prevents a {@link Piglin} from bartering with a {@link SlimefunItem} as well as
* listens to the EntityDropItemEvent to inject a {@link PiglinBarterDrop} if a dropChance() check passes.
*
* @author poma123
*
*/
/**
* Also {@link Listener} Listens to the EntityDropItemEvent event to inject a {@link RandomMobDrop} if its dropChance() check passes.
* this would only be possible if the {@link RecipeType} is of PiglinBarter type.
*
* @author dNiym
*
* @see getBarterDrops
* @see RandomMobDrop
* @author poma123, dNiym
*
*/
@ -59,6 +50,7 @@ public class PiglinListener implements Listener {
@EventHandler
public void onPiglinDropItem(EntityDropItemEvent e) {
if (e.getEntity() instanceof Piglin) {
Piglin piggy = (Piglin) e.getEntity();
Set<ItemStack> drops = SlimefunPlugin.getRegistry().getBarterDrops();
/*
@ -69,8 +61,8 @@ public class PiglinListener implements Listener {
for (ItemStack is : drops) {
SlimefunItem sfi = SlimefunItem.getByItem(is);
if (sfi instanceof RandomMobDrop && ((RandomMobDrop)sfi).getMobDropChance() >= ThreadLocalRandom.current().nextInt(100)) {
Item drop = e.getEntity().getWorld().dropItemNaturally(((Piglin)e.getEntity()).getEyeLocation(), sfi.getItem());
if (sfi instanceof PiglinBarterDrop && ((PiglinBarterDrop)sfi).getMobDropChance() >= ThreadLocalRandom.current().nextInt(100)) {
Item drop = e.getEntity().getWorld().dropItemNaturally(piggy.getEyeLocation(), sfi.getItem());
drop.setVelocity(e.getItemDrop().getVelocity());
e.getItemDrop().remove();
return;