Recipe Book displaying recipes now supported

**Requires MythicLib Update (1.0.18)**
This commit is contained in:
Gunging 2021-04-05 04:24:33 -05:00
parent c82962cd61
commit 65ee66984a
16 changed files with 241 additions and 35 deletions

View File

@ -100,7 +100,7 @@
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicLib</artifactId>
<version>1.0.17</version>
<version>1.0.18</version>
<scope>provided</scope>
</dependency>

View File

@ -593,7 +593,7 @@ public class MMOItems extends LuminePlugin {
if (type == null || id == null) { return null; }
// Valid template?
MMOItemTemplate found = templateManager.getTemplate(type, id);
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
// Build if found
@ -627,7 +627,7 @@ public class MMOItems extends LuminePlugin {
if (type == null || id == null) { return null; }
// Valid template?
MMOItemTemplate found = templateManager.getTemplate(type, id);
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
// Build if found
@ -662,7 +662,7 @@ public class MMOItems extends LuminePlugin {
if (type == null || id == null) { return null; }
// Valid template?
MMOItemTemplate found = templateManager.getTemplate(type, id);
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
// Build if found

View File

@ -6,9 +6,14 @@ import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.utils.items.ItemFactory;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -79,7 +84,7 @@ public class MMOItemUIFilter implements UIFilter {
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
// Type exists?
Type t = MMOItems.plugin.getTypes().get(argument);
Type t = MMOItems.plugin.getType(argument);
// Nope
if (t == null) {
@ -92,7 +97,7 @@ public class MMOItemUIFilter implements UIFilter {
}
// Can find item?
if (!MMOItems.plugin.getTemplates().hasTemplate(t, data)) {
if (MMOItems.plugin.getMMOItem(t, data) == null) {
// Error
@ -143,15 +148,35 @@ public class MMOItemUIFilter implements UIFilter {
@Override
public ItemStack getItemStack(@NotNull String argument, @NotNull String data, @Nullable FriendlyFeedbackProvider ffp) {
if (!isValid(argument, data, ffp)) { return null; }
argument = argument.replace(" ", "_").replace("-", "_").toUpperCase();
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
return MMOItems.plugin.getItem(argument, data);
}
@NotNull
@Override
public ItemStack getDisplayStack(@NotNull String argument, @NotNull String data, @Nullable FriendlyFeedbackProvider ffp) {
if (!isValid(argument, data, ffp)) { return ItemFactory.of(Material.STRUCTURE_VOID).name("\u00a7cInvalid MMOItem \u00a7e" + argument + " " + data).build(); }
argument = argument.replace(" ", "_").replace("-", "_").toUpperCase();
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(argument), data);
//noinspection ConstantConditions
ItemStackBuilder builder = m.newBuilder();
// Build display NBT and roll
NBTItem nbt = builder.buildNBT(true);
return new DynamicLore(nbt).build();
}
@NotNull
@Override
public ArrayList<String> getDescription(@NotNull String argument, @NotNull String data) {
// Check validity
if (!isValid(argument, data, null)) { return SilentNumbers.toArrayList("This MMOItem is $finvalid$b."); }
argument = argument.replace(" ", "_").replace("-", "_").toUpperCase();
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
return SilentNumbers.toArrayList(SilentNumbers.getItemName(MMOItems.plugin.getItem(argument, data)));
}

View File

@ -10,12 +10,14 @@ import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.item.util.DynamicLore;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
import net.Indyuce.mmoitems.stat.data.EnchantListData;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Previewable;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
@ -103,7 +105,16 @@ public class ItemStackBuilder {
/**
* @return Returns built NBTItem with applied tags and lore
*/
public NBTItem buildNBT() {
public NBTItem buildNBT() { return buildNBT(false); }
/**
* @return Returns built NBTItem with applied tags and lore
*
* @param forDisplay Should this item's lore display potential stats
* (like RNG ranges before rolling) rather than the
* stats it will have?
*/
public NBTItem buildNBT(boolean forDisplay) {
// Clone as to not conflict in any way
MMOItem builtMMOItem = mmoitem.clone();
//GEM//MMOItems.Log("\u00a7e+ \u00a77Building \u00a7c" + mmoitem.getType().getName() + " " + mmoitem.getId() + "\u00a77 (Size \u00a7e" + mmoitem.getStatHistories().size() + "\u00a77 Historic)");
@ -131,8 +142,20 @@ public class ItemStackBuilder {
builtMMOItem.setData(stat, s.recalculate(true));
}
// Make necessary lore changes
stat.whenApplied(this, builtMMOItem.getData(stat));
if (forDisplay && stat instanceof Previewable) {
// Get Template
MMOItemTemplate template = MMOItems.plugin.getTemplates().getTemplate(builtMMOItem.getType(), builtMMOItem.getId());
if (template == null) { throw new IllegalArgumentException("MMOItem $r" + builtMMOItem.getType().getId() + " " + builtMMOItem.getId() + "$b doesn't exist."); }
// Make necessary lore changes
((Previewable) stat).whenPreviewed(this, builtMMOItem.getData(stat), template.getBaseItemData().get(stat));
} else {
// Make necessary lore changes
stat.whenApplied(this, builtMMOItem.getData(stat));
}
// Something went wrong...
} catch (IllegalArgumentException|NullPointerException exception) {

View File

@ -10,6 +10,7 @@ import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.ItemReference;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
@ -17,6 +18,7 @@ import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;

View File

@ -183,9 +183,6 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
return recipe;
}
static int recipeCount = 0;
/**
* Reads this list of strings as a Shapeless Recipe
* to craft this MMOItem.
@ -222,7 +219,7 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
poofs.add(new MythicRecipeIngredient(p));
}
if (!nonAirFound) { throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Shapeless recipe containing only AIR, $fignored$b.")); }
String recipeName = type + "." + id + "." + recipeCount++;
String recipeName = type + "." + id;
// Build Main
ShapedRecipe shapedRecipe = ShapedRecipe.single(recipeName, new ProvidedUIFilter(MMOItemUIFilter.get(), type.getId(), id, Math.max(template.getCraftedAmount(), 1)));
@ -326,7 +323,7 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
rowNumber++;
}
if (!nonAirFound) { throw new IllegalArgumentException(FriendlyFeedbackProvider.quickForConsole(FFPMMOItems.get(), "Shaped recipe containing only AIR, $fignored$b.")); }
String recipeName = type + "." + id + "." + recipeCount++;
String recipeName = type + "." + id;
// Build Main
ShapedRecipe shapedRecipe = ShapedRecipe.single(recipeName, new ProvidedUIFilter(MMOItemUIFilter.get(), type.getId(), id, Math.max(template.getCraftedAmount(), 1)));
@ -374,7 +371,7 @@ public class CustomRecipe implements Comparable<CustomRecipe> {
MythicRecipeIngredient itemIngredient = new MythicRecipeIngredient(itemPoof);
MythicRecipeIngredient ingotIngredient = new MythicRecipeIngredient(ingotPoof);
String recipeName = type + "." + id + "." + recipeCount++;
String recipeName = type + "." + id;
// Build Main
ShapedRecipe shapedRecipe = ShapedRecipe.single(recipeName, new ProvidedUIFilter(MMOItemUIFilter.get(), type.getId(), id, Math.max(template.getCraftedAmount(), 1)));

View File

@ -62,7 +62,7 @@ public class NumericStatFormula implements RandomStatData {
maxSpread = config.getDouble("max-spread", .3);
Validate.isTrue(spread >= 0, "Spread must be positive");
Validate.isTrue(maxSpread >= 0, "Max spread must be positive and lower than 1");
Validate.isTrue(maxSpread >= 0, "Max spread must be positive");
return;
}
@ -144,7 +144,19 @@ public class NumericStatFormula implements RandomStatData {
*/
public double calculate(double levelScalingFactor) {
if (useRelativeSpread) { return (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(RANDOM.nextGaussian() * spread, -maxSpread), maxSpread)); }
// Calculate yes
return calculate(levelScalingFactor, RANDOM.nextGaussian());
}
/**
* @param levelScalingFactor Level to scale the scale with
* @param random Result of <code>RANDOM.nextGaussian()</code> or whatever other
* value that you actually want to pass.
* @return The calculated value
*/
public double calculate(double levelScalingFactor, double random) {
if (useRelativeSpread) { return (base + scale * levelScalingFactor) * (1 + Math.min(Math.max(random * spread, -maxSpread), maxSpread)); }
/*
* The mean, the center of the distribution
@ -156,7 +168,7 @@ public class NumericStatFormula implements RandomStatData {
* at mean 0, and standard deviation 1, multiplied
* by the spread chosen.
*/
double gaussSpread = RANDOM.nextGaussian() * spread;
double gaussSpread = random * spread;
/*
* Does it exceed the max spread (positive or negative)? Not anymore!

View File

@ -1,13 +1,11 @@
package net.Indyuce.mmoitems.manager;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import io.lumine.mythic.lib.api.crafting.recipes.MythicRecipeBlueprint;
import io.lumine.mythic.lib.api.crafting.recipes.MythicRecipeStation;
import io.lumine.mythic.lib.api.util.Ref;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import net.Indyuce.mmoitems.api.crafting.recipe.SmithingCombinationType;
@ -67,7 +65,7 @@ public class RecipeManager implements Reloadable {
* <b>Except that for the time being, only Workbench recipes are supported
* by mythic lib so for any other kind use the legacy array.</b>
*/
final HashSet<MythicRecipeBlueprint> customRecipes = new HashSet<>();
final HashMap<NamespacedKey, MythicRecipeBlueprint> customRecipes = new HashMap<>();
private boolean book, amounts;
@ -179,11 +177,12 @@ public class RecipeManager implements Reloadable {
MythicRecipeBlueprint blueprint = CustomRecipe.generateSmithing(type, id, item, ingot, dropGems, enchants, upgrade);
// Remember it
customRecipes.add(blueprint);
// Enable it
blueprint.deploy(MythicRecipeStation.SMITHING);
Ref<NamespacedKey> nk = new Ref<>();
blueprint.deploy(MythicRecipeStation.SMITHING, nk);
// Remember it
customRecipes.put(nk.getValue(), blueprint);
}
/**
@ -228,11 +227,12 @@ public class RecipeManager implements Reloadable {
blueprint = CustomRecipe.generateShaped(type, id, list);
}
// Remember it
customRecipes.add(blueprint);
// Enable it
blueprint.deploy(MythicRecipeStation.WORKBENCH);
Ref<NamespacedKey> nk = new Ref<>();
blueprint.deploy(MythicRecipeStation.WORKBENCH, nk);
// Remember it
customRecipes.put(nk.getValue(), blueprint);
/*
CustomRecipe recipe = new CustomRecipe(type, id, list, shapeless);
@ -262,10 +262,19 @@ public class RecipeManager implements Reloadable {
public Set<CustomRecipe> getLegacyCustomRecipes() {
return legacyCraftingRecipes;
}
public HashSet<MythicRecipeBlueprint> getCustomRecipes() { return customRecipes; }
public HashMap<NamespacedKey, MythicRecipeBlueprint> getCustomRecipes() { return customRecipes; }
public Set<NamespacedKey> getNamespacedKeys() {
return loadedLegacyRecipes.stream().map(recipe -> ((Keyed) recipe).getKey()).collect(Collectors.toSet());
ArrayList<NamespacedKey> generatedNKs = null;
public ArrayList<NamespacedKey> getNamespacedKeys() {
if (generatedNKs != null) { return generatedNKs; }
// Collect all Namespaces
ArrayList<NamespacedKey> nkMythic = new ArrayList<>(customRecipes.keySet());
ArrayList<NamespacedKey> nkLegacy = loadedLegacyRecipes.stream().map(recipe -> ((Keyed) recipe).getKey()).distinct().collect(Collectors.toCollection(ArrayList::new));
nkMythic.addAll(nkLegacy);
generatedNKs = nkMythic;
return generatedNKs;
}
public void sortRecipes() {
@ -291,10 +300,11 @@ public class RecipeManager implements Reloadable {
loadedLegacyRecipes.clear();
// Disable and forget all blueprints
for (MythicRecipeBlueprint b : customRecipes) { b.disable(); }
for (NamespacedKey b : customRecipes.keySet()) { Bukkit.removeRecipe(b); customRecipes.get(b).disable(); }
customRecipes.clear();
// Load all recipes
generatedNKs = null;
loadRecipes();
// Refresh the book I suppose

View File

@ -1,14 +1,19 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -33,6 +38,9 @@ public class CustomModelData extends DoubleStat implements GemStoneStat {
item.addItemTag(getAppliedNBT(data));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException { whenApplied(item, currentData); }
@NotNull
@Override public ArrayList<ItemTag> getAppliedNBT(@NotNull StatData data) {

View File

@ -1,13 +1,18 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.inventory.meta.Damageable;
import org.jetbrains.annotations.NotNull;
@ -26,6 +31,8 @@ public class ItemDamage extends DoubleStat implements GemStoneStat {
if (item.getMeta() instanceof Damageable)
((Damageable) item.getMeta()).setDamage((int) ((DoubleData) data).getValue());
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException { whenApplied(item, currentData);}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this is an empty array

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.Upgradable;
import org.bukkit.ChatColor;
@ -37,6 +38,10 @@ public class MaximumDurability extends DoubleStat implements ItemRestriction, Ge
super.whenApplied(item, data);
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException { whenApplied(item, currentData); }
@Override
public @NotNull
ArrayList<ItemTag> getAppliedNBT(@NotNull StatData data) {

View File

@ -1,5 +1,10 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
@ -22,4 +27,41 @@ public class PickaxePower extends DoubleStat {
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", pickPower));
item.getLore().insert("pickaxe-power", formatNumericStat(pickPower, "#", "" + pickPower));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException {
Validate.isTrue(currentData instanceof DoubleData, "Current Data is not Double Data");
Validate.isTrue(templateData instanceof NumericStatFormula, "Template Data is not Numeric Stat Formula");
// Get Value
double techMinimum = ((NumericStatFormula) templateData).calculate(0, -2.5);
double techMaximum = ((NumericStatFormula) templateData).calculate(0, 2.5);
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
return;
}
if (techMinimum < 0 && !handleNegativeStats()) {
techMinimum = 0;
}
if (techMinimum < ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread()) {
techMinimum = ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread();
}
if (techMaximum > ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread()) {
techMaximum = ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread();
}
// Add NBT Path
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", ((DoubleData) currentData).getValue()));
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) { builtRange = new StatFormat("##").format(techMinimum); }
else { builtRange = new StatFormat("##").format(techMinimum) + "-" + new StatFormat("##").format(techMaximum); }
// Just display normally
item.getLore().insert("pickaxe-power", formatNumericStat(techMinimum, "#", builtRange));
}
}
}

View File

@ -10,6 +10,8 @@ import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.RequiredLevelData;
@ -19,6 +21,7 @@ import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.data.type.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.jetbrains.annotations.NotNull;
@ -48,6 +51,35 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
// Insert NBT
item.addItemTag(getAppliedNBT(data));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException {
Validate.isTrue(currentData instanceof DoubleData, "Current Data is not Double Data");
Validate.isTrue(templateData instanceof NumericStatFormula, "Template Data is not Numeric Stat Formula");
// Get Value
double techMinimum = ((NumericStatFormula) templateData).calculate(0, -2.5);
double techMaximum = ((NumericStatFormula) templateData).calculate(0, 2.5);
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) { return; }
if (techMinimum < 0 && !handleNegativeStats()) { techMinimum = 0; }
if (techMinimum < ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread()) { techMinimum = ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread(); }
if (techMaximum > ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread()) { techMaximum = ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread(); }
// Add NBT Path
item.addItemTag(getAppliedNBT(currentData));
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) { builtRange = SilentNumbers.readableRounding(techMinimum, 0); }
else { builtRange = SilentNumbers.readableRounding(techMinimum, 0) + "-" + SilentNumbers.readableRounding(techMaximum, 0); }
// Just display normally
item.getLore().insert("required-level", formatNumericStat(techMinimum, "#", builtRange));
}
}
@NotNull
@Override

View File

@ -1,12 +1,16 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
public class SoulboundLevel extends DoubleStat {
@ -21,4 +25,6 @@ public class SoulboundLevel extends DoubleStat {
item.addItemTag(new ItemTag("MMOITEMS_SOULBOUND_LEVEL", value));
item.getLore().insert("soulbound-level", formatNumericStat(value, "#", MMOUtils.intToRoman(value)));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException { whenApplied(item, currentData);}
}

View File

@ -1,10 +1,15 @@
package net.Indyuce.mmoitems.stat.block;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.api.util.StatFormat;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@ -19,4 +24,7 @@ public class BlockID extends DoubleStat {
super.whenApplied(item, data);
item.addItemTag(new ItemTag("CustomModelData", (int) ((DoubleData) data).getValue() +1000));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException { whenApplied(item, currentData); }
}

View File

@ -0,0 +1,29 @@
package net.Indyuce.mmoitems.stat.type;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import org.jetbrains.annotations.NotNull;
/**
* Suppose this stat may display different in an item before
* it is crafted (say, a double stat displays a range of the
* values it can have) than when its crafted (where the double
* stat displays the RNG result it got when crafted)
*
* @author Gunging
*/
public interface Previewable {
/**
* Literally a copy of {@link ItemStat#whenApplied(ItemStackBuilder, StatData)}
* but that puts the 'preview lore' in instead of the actual stat lore.
*
* @param item Item being built
* @param currentData Current Data of the item
* @param templateData Random Data of the item
*
* @throws IllegalArgumentException If something go wrong
*/
void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull StatData currentData, @NotNull RandomStatData templateData) throws IllegalArgumentException;
}