1
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:
TheBusyBiscuit 2020-08-04 12:40:08 +02:00
parent 8a9dfe25a8
commit e870f82afd
6 changed files with 65 additions and 41 deletions

View File

@ -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;
@ -70,7 +72,7 @@ public class SlimefunRegistry {
private final Set<SlimefunItem> radioactive = new HashSet<>();
private final Set<String> activeChunks = ConcurrentHashMap.newKeySet();
private final Set<ItemStack> barterDrops = new HashSet<>();
private final KeyMap<GEOResource> geoResources = new KeyMap<>();
private final Map<UUID, PlayerProfile> profiles = new ConcurrentHashMap<>();
@ -196,14 +198,26 @@ 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;
}
public Set<SlimefunItem> getRadioactiveItems() {
return radioactive;
}
@ -271,7 +285,7 @@ public class SlimefunRegistry {
public Map<String, ItemStack> getAutomatedCraftingChamberRecipes() {
return automatedCraftingChamberRecipes;
}
public boolean logDuplicateBlockEntries() {
return logDuplicateBlockEntries;
}

View File

@ -1,37 +1,34 @@
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;
/**
* This interface, when attached to a {@link SlimefunItem}, provides a variable (0-100%) chance for
* a {@link SlimefunItem} to be dropped by a {@link Piglin} on {@link EntityItemDropEvent}.
* a {@link SlimefunItem} to be dropped by a {@link Piglin} on {@link EntityItemDropEvent}.
*
* @author dNiym
*
* @see PiglinListener
* @see RandomMobDrop
*
*/
@FunctionalInterface
public interface PiglinBarterDrop extends ItemAttribute {
/**
* Implement this method to make this {@link SlimefunItem} have a variable chance
* of being dropped by a {@link Piglin} when bartering with them. This interface
* Implement this method to make this {@link SlimefunItem} have a variable chance
* of being dropped by a {@link Piglin} when bartering with them. This interface
* should be used with the {@link RecipeType#BARTER_DROP}.
*
* 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}
* barter drops. (NOTE: this feature only exists in 1.16+)
* 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();

View File

@ -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
@ -26,7 +26,7 @@ public interface RandomMobDrop extends ItemAttribute {
/**
* Implement this method to make the object have a variable chance of being
* added to the dropList when {@link EntityType} specified in
* added to the dropList when {@link EntityType} specified in
* the {@link RecipeType#MOB_DROP} is killed by the {@link Player}.
*
* @return The integer chance (0-100%) {@link SlimefunItem} has to drop.

View File

@ -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,26 +50,33 @@ 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.
* 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.
*/
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());
return;
}
// 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) {
if (!e.getRightClicked().isValid() || e.getRightClicked().getType() != EntityType.PIGLIN) {

View File

@ -48,8 +48,8 @@ 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 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 FOOD_FABRICATOR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "food_fabricator"), SlimefunItems.FOOD_FABRICATOR);
public static final RecipeType FOOD_COMPOSTER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance(), "food_composter"), SlimefunItems.FOOD_COMPOSTER);
@ -144,10 +144,11 @@ 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) {
String mob = ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase(Locale.ROOT).replace(' ', '_');
EntityType entity = EntityType.valueOf(mob);

View File

@ -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: