New *Required Biome* stat that makes items only work in certain biomes. Case and space insensitive

Adding 'mountains' will make this work on every biome variant that has 'mountains' in its name (Like modified_gravelly_mountains).

Use the '!' prefix to blacklist biomes instead. '!forest' will make the item not work in any forest variant.
This commit is contained in:
Gunging 2021-02-22 18:56:09 -06:00
parent 3cc3c966cb
commit 1d83b9e5ab
4 changed files with 63 additions and 6 deletions

View File

@ -113,6 +113,7 @@ public class ItemStats {
MOVEMENT_SPEED = new MovementSpeed(),
TWO_HANDED = new BooleanStat("TWO_HANDED", Material.IRON_INGOT, "Two Handed", new String[]{"If set to true, a player will be", "significantly slower if holding two", "items, one being Two Handed."}, new String[]{"piercing", "slashing", "blunt", "offhand", "range", "tool"}),
EQUIP_PRIORITY = new DoubleStat("EQUIP_PRIORITY", VersionMaterial.DIAMOND_HORSE_ARMOR.toMaterial(), "Equip Priority", new String[]{"Sets the level of priority this item has for the", "right click to swap equipped armor feature."}),
REQUIRED_BIOMES = new RequiredBiomes(),
// Permanent Effects
PERM_EFFECTS = new PermanentEffects(),

View File

@ -285,7 +285,7 @@ public class Enchants extends ItemStat implements Upgradable {
// Update
//UPGRD//MMOItems. Log("\u00a7b -> \u00a77Final level \u00a7f" + value);
dataEnchants.addEnchant(e, SilentNumbers.Round(value));
dataEnchants.addEnchant(e, SilentNumbers.Round(value - 0.5));
}
// Yes

View File

@ -0,0 +1,56 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.bukkit.Material;
import java.util.ArrayList;
public class RequiredBiomes extends StringListStat implements ItemRestriction, GemStoneStat {
public RequiredBiomes() {
super("REQUIRED_BIOMES", Material.JUNGLE_SAPLING, "Required Biomes", new String[] { "The biome the player must be within", "for this item to activate." }, new String[] { "!block", "all" });
}
@Override
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
// bruh
if (!item.hasTag(getNBTPath())) { return true; }
// Find the relevant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (item.hasTag(getNBTPath())) { relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), item, SupportedNBTTagValues.STRING)); }
// Generate data
StringListData data = (StringListData) getLoadedNBT(relevantTags);
if (data != null) {
// Check every string, must match once
for (String biome : data.getList()) {
// Crop
String tst = biome.toLowerCase().replace(" ", "_").replace("-", "_"); boolean counter = false;
if (tst.startsWith("!")) { counter = true; tst = tst.substring(1); }
// Get biome
String b = player.getPlayer().getLocation().getBlock().getBiome().getKey().getKey();
// Check
if (b.contains(tst)) { return !counter; }
}
return false;
}
return true;
}
}

View File

@ -15,27 +15,27 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
import org.jetbrains.annotations.NotNull;
public class StringListData implements StatData, RandomStatData, Mergeable {
private final List<String> list;
@NotNull private final List<String> list;
public StringListData() {
this(new ArrayList<>());
}
public StringListData(String[] array) {
public StringListData(@NotNull String[] array) {
this(Arrays.asList(array));
}
public StringListData(JsonArray array) {
public StringListData(@NotNull JsonArray array) {
this();
array.forEach(str -> list.add(str.getAsString()));
}
public StringListData(List<String> list) {
public StringListData(@NotNull List<String> list) {
this.list = list;
}
public List<String> getList() {
@NotNull public List<String> getList() {
return list;
}