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.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Piglin;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
|
import io.github.thebusybiscuit.cscorelib2.collections.KeyMap;
|
||||||
@ -196,11 +198,23 @@ public class SlimefunRegistry {
|
|||||||
return layouts.get(layout);
|
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() {
|
public Map<EntityType, Set<ItemStack>> getMobDrops() {
|
||||||
return mobDrops;
|
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;
|
return barterDrops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.core.attributes;
|
package io.github.thebusybiscuit.slimefun4.core.attributes;
|
||||||
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.Piglin;
|
||||||
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.PiglinListener;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
|
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
|
||||||
@ -17,6 +13,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|||||||
* @author dNiym
|
* @author dNiym
|
||||||
*
|
*
|
||||||
* @see PiglinListener
|
* @see PiglinListener
|
||||||
|
* @see RandomMobDrop
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
@ -29,9 +26,9 @@ public interface PiglinBarterDrop extends ItemAttribute {
|
|||||||
*
|
*
|
||||||
* It is recommended that this chance is kept reasonably low to feel like
|
* It is recommended that this chance is kept reasonably low to feel like
|
||||||
* a vanilla drop as a 100% chance will completely override all {@link Piglin}
|
* a vanilla drop as a 100% chance will completely override all {@link Piglin}
|
||||||
* barter drops. (NOTE: this feature only exists in 1.16+)
|
* 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();
|
int getBarteringLootChance();
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package io.github.thebusybiscuit.slimefun4.core.attributes;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
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.items.misc.BasicCircuitBoard;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.MobDropListener;
|
||||||
@ -19,6 +18,7 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|||||||
*
|
*
|
||||||
* @see BasicCircuitBoard
|
* @see BasicCircuitBoard
|
||||||
* @see MobDropListener
|
* @see MobDropListener
|
||||||
|
* @see PiglinBarterDrop
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -5,7 +5,6 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.entity.Piglin;
|
import org.bukkit.entity.Piglin;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -17,19 +16,19 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.PiglinBarterDrop;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.PiglinBarterDrop;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RandomMobDrop;
|
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This {@link Listener} prevents a {@link Piglin} from bartering with a {@link SlimefunItem} as well as
|
* This {@link Listener} prevents a {@link Piglin} from bartering with a
|
||||||
* listens to the {@link EntityDropItemEvent} to inject a {@link PiglinBarterDrop} if a dropChance() check passes.
|
* {@link SlimefunItem}.
|
||||||
|
* It also listens to the {@link EntityDropItemEvent} to
|
||||||
|
* inject a {@link PiglinBarterDrop} if the chance check passes.
|
||||||
*
|
*
|
||||||
* @author poma123
|
* @author poma123
|
||||||
* @author dNiym
|
* @author dNiym
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class PiglinListener implements Listener {
|
public class PiglinListener implements Listener {
|
||||||
|
|
||||||
public PiglinListener(SlimefunPlugin plugin) {
|
public PiglinListener(SlimefunPlugin plugin) {
|
||||||
@ -51,21 +50,28 @@ public class PiglinListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPiglinDropItem(EntityDropItemEvent e) {
|
public void onPiglinDropItem(EntityDropItemEvent e) {
|
||||||
if (e.getEntity() instanceof Piglin) {
|
if (e.getEntity() instanceof Piglin) {
|
||||||
Piglin piglin = (Piglin) e.getEntity();
|
Set<ItemStack> drops = SlimefunPlugin.getRegistry().getBarteringDrops();
|
||||||
Set<ItemStack> drops = SlimefunPlugin.getRegistry().getBarterDrops();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: Getting a new random number each iteration because multiple items could have the same
|
* 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
|
* % chance to drop, and if one fails all items with that number will fail.
|
||||||
* will allow multiple items with the same % chance to drop.
|
* Getting a new random number will allow multiple items with the same % chance to drop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (ItemStack is : drops) {
|
for (ItemStack is : drops) {
|
||||||
SlimefunItem sfi = SlimefunItem.getByItem(is);
|
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.
|
// Check the getBarteringLootChance and compare against a random number 0-100,
|
||||||
if (sfi instanceof PiglinBarterDrop && ((PiglinBarterDrop)sfi).getBarteringLootChance() > ThreadLocalRandom.current().nextInt(100)) {
|
// if the random number is greater then replace the item.
|
||||||
e.getItemDrop().setItemStack(sfi.getItem().clone());
|
if (sfi instanceof PiglinBarterDrop) {
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class RecipeType implements Keyed {
|
|||||||
});
|
});
|
||||||
|
|
||||||
public static final RecipeType MOB_DROP = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "mob_drop"), new CustomItem(Material.IRON_SWORD, "&bMob Drop"), RecipeType::registerMobDrop, "", "&rKill the specified Mob to obtain this Item");
|
public static final RecipeType MOB_DROP = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "mob_drop"), new CustomItem(Material.IRON_SWORD, "&bMob Drop"), RecipeType::registerMobDrop, "", "&rKill the specified Mob to obtain this Item");
|
||||||
public static final RecipeType BARTER_DROP = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "barter_drop"), new CustomItem(Material.GOLD_INGOT, "&bBarter Drop"), RecipeType::registerBarterDrop, "&aBarter with piglins for a chance", "&a to obtain this item");
|
public static final RecipeType BARTER_DROP = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "barter_drop"), new CustomItem(Material.GOLD_INGOT, "&bBarter Drop"), RecipeType::registerBarterDrop, "&aBarter with piglins for a chance", "&ato obtain this item");
|
||||||
|
|
||||||
public static final RecipeType HEATED_PRESSURE_CHAMBER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "heated_pressure_chamber"), SlimefunItems.HEATED_PRESSURE_CHAMBER);
|
public static final RecipeType HEATED_PRESSURE_CHAMBER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "heated_pressure_chamber"), SlimefunItems.HEATED_PRESSURE_CHAMBER);
|
||||||
public static final RecipeType FOOD_FABRICATOR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "food_fabricator"), SlimefunItems.FOOD_FABRICATOR);
|
public static final RecipeType FOOD_FABRICATOR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "food_fabricator"), SlimefunItems.FOOD_FABRICATOR);
|
||||||
@ -144,8 +144,9 @@ public class RecipeType implements Keyed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void registerBarterDrop(ItemStack[] recipe, ItemStack output) {
|
private static void registerBarterDrop(ItemStack[] recipe, ItemStack output) {
|
||||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16))
|
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
|
||||||
SlimefunPlugin.getRegistry().getBarterDrops().add(output);
|
SlimefunPlugin.getRegistry().getBarteringDrops().add(output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerMobDrop(ItemStack[] recipe, ItemStack output) {
|
private static void registerMobDrop(ItemStack[] recipe, ItemStack output) {
|
||||||
|
@ -141,6 +141,12 @@ slimefun:
|
|||||||
- 'Craft this Item as shown'
|
- 'Craft this Item as shown'
|
||||||
- 'using a Refinery'
|
- 'using a Refinery'
|
||||||
|
|
||||||
|
barter_drop:
|
||||||
|
name: 'Piglin Bartering Drop'
|
||||||
|
lore:
|
||||||
|
- 'Barter with Piglins using'
|
||||||
|
- 'Gold Ingots to obtain this Item'
|
||||||
|
|
||||||
minecraft:
|
minecraft:
|
||||||
|
|
||||||
shaped:
|
shaped:
|
||||||
|
Loading…
Reference in New Issue
Block a user