mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added piglin bartering to translation files
This commit is contained in:
parent
8a9dfe25a8
commit
e870f82afd
@ -13,7 +13,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Piglin;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
|
||||
@ -196,11 +198,23 @@ public class SlimefunRegistry {
|
||||
return layouts.get(layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a {@link Map} connecting the {@link EntityType} with a {@link Set}
|
||||
* of {@link ItemStack ItemStacks} which would be dropped when an {@link Entity} of that type was killed.
|
||||
*
|
||||
* @return The {@link Map} of custom mob drops
|
||||
*/
|
||||
public Map<EntityType, Set<ItemStack>> getMobDrops() {
|
||||
return mobDrops;
|
||||
}
|
||||
|
||||
public Set<ItemStack> getBarterDrops() {
|
||||
/**
|
||||
* This returns a {@link Set} of {@link ItemStack ItemStacks} which can be obtained by bartering
|
||||
* with {@link Piglin Piglins}.
|
||||
*
|
||||
* @return A {@link Set} of bartering drops
|
||||
*/
|
||||
public Set<ItemStack> getBarteringDrops() {
|
||||
return barterDrops;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,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 org.bukkit.entity.Piglin;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.misc.BasicCircuitBoard;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.PiglinListener;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
@ -17,6 +13,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
* @author dNiym
|
||||
*
|
||||
* @see PiglinListener
|
||||
* @see RandomMobDrop
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@ -31,7 +28,7 @@ public interface PiglinBarterDrop extends ItemAttribute {
|
||||
* a vanilla drop as a 100% chance will completely override all {@link Piglin}
|
||||
* barter drops. (NOTE: this feature only exists in 1.16+)
|
||||
*
|
||||
* @return The integer chance (0-100%) this {@link SlimefunItem} has to drop.
|
||||
* @return The integer chance (1-99%) this {@link SlimefunItem} has to drop.
|
||||
*/
|
||||
int getBarteringLootChance();
|
||||
|
||||
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -19,6 +18,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
*
|
||||
* @see BasicCircuitBoard
|
||||
* @see MobDropListener
|
||||
* @see PiglinBarterDrop
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
|
@ -5,7 +5,6 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Piglin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -17,19 +16,19 @@ 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} as well as
|
||||
* listens to the {@link EntityDropItemEvent} to inject a {@link PiglinBarterDrop} if a dropChance() check passes.
|
||||
* This {@link Listener} prevents a {@link Piglin} from bartering with a
|
||||
* {@link SlimefunItem}.
|
||||
* It also listens to the {@link EntityDropItemEvent} to
|
||||
* inject a {@link PiglinBarterDrop} if the chance check passes.
|
||||
*
|
||||
* @author poma123
|
||||
* @author dNiym
|
||||
*
|
||||
*/
|
||||
|
||||
public class PiglinListener implements Listener {
|
||||
|
||||
public PiglinListener(SlimefunPlugin plugin) {
|
||||
@ -51,25 +50,32 @@ public class PiglinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPiglinDropItem(EntityDropItemEvent e) {
|
||||
if (e.getEntity() instanceof Piglin) {
|
||||
Piglin piglin = (Piglin) e.getEntity();
|
||||
Set<ItemStack> drops = SlimefunPlugin.getRegistry().getBarterDrops();
|
||||
Set<ItemStack> drops = SlimefunPlugin.getRegistry().getBarteringDrops();
|
||||
|
||||
/*
|
||||
* NOTE: Getting a new random number each iteration because multiple items could have the same
|
||||
* % chance to drop, and if one fails all items with that number will fail. Getting a new random number
|
||||
* will allow multiple items with the same % chance to drop.
|
||||
* % chance to drop, and if one fails all items with that number will fail.
|
||||
* Getting a new random number will allow multiple items with the same % chance to drop.
|
||||
*/
|
||||
|
||||
for (ItemStack is : drops) {
|
||||
SlimefunItem sfi = SlimefunItem.getByItem(is);
|
||||
//Check the getBarteringLootChance and compare against a random number 1-100, if the random number is greater then replace the item.
|
||||
if (sfi instanceof PiglinBarterDrop && ((PiglinBarterDrop)sfi).getBarteringLootChance() > ThreadLocalRandom.current().nextInt(100)) {
|
||||
e.getItemDrop().setItemStack(sfi.getItem().clone());
|
||||
// Check the getBarteringLootChance and compare against a random number 0-100,
|
||||
// if the random number is greater then replace the item.
|
||||
if (sfi instanceof PiglinBarterDrop) {
|
||||
int chance = ((PiglinBarterDrop) sfi).getBarteringLootChance();
|
||||
|
||||
if (chance < 1 || chance >= 100) {
|
||||
sfi.warn("The Piglin Bartering chance must be between 1-99%");
|
||||
}
|
||||
else if (chance > ThreadLocalRandom.current().nextInt(100)) {
|
||||
e.getItemDrop().setItemStack(sfi.getRecipeOutput());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteractEntity(PlayerInteractEntityEvent e) {
|
||||
|
@ -144,8 +144,9 @@ public class RecipeType implements Keyed {
|
||||
}
|
||||
|
||||
private static void registerBarterDrop(ItemStack[] recipe, ItemStack output) {
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16))
|
||||
SlimefunPlugin.getRegistry().getBarterDrops().add(output);
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
|
||||
SlimefunPlugin.getRegistry().getBarteringDrops().add(output);
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerMobDrop(ItemStack[] recipe, ItemStack output) {
|
||||
|
@ -141,6 +141,12 @@ slimefun:
|
||||
- 'Craft this Item as shown'
|
||||
- 'using a Refinery'
|
||||
|
||||
barter_drop:
|
||||
name: 'Piglin Bartering Drop'
|
||||
lore:
|
||||
- 'Barter with Piglins using'
|
||||
- 'Gold Ingots to obtain this Item'
|
||||
|
||||
minecraft:
|
||||
|
||||
shaped:
|
||||
|
Loading…
Reference in New Issue
Block a user