mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-28 15:41:04 +01:00
Bugfixes to the RevID update system:
+ Option to not reroll RNG stats actually works now. Bugfixes to item skins: + Skin source information no longer lost when MMOItem is read from an Item Stack (would cause it to be lost when RevID updating even if keep skins was enabled).
This commit is contained in:
parent
044a443fb4
commit
2684945a2e
@ -92,6 +92,9 @@ public class ItemSkin extends UseItem {
|
||||
return new ApplyResult(item);
|
||||
}
|
||||
|
||||
public static final String tagHasSkin = "MMOITEMS_HAS_SKIN";
|
||||
public static final String tagSkinID = "MMOITEMS_SKIN_ID";
|
||||
|
||||
/**
|
||||
* Applies the skin information from a skin consumable onto any item.
|
||||
*
|
||||
@ -104,16 +107,15 @@ public class ItemSkin extends UseItem {
|
||||
*/
|
||||
@NotNull public static ItemStack applySkin(@NotNull NBTItem target, @NotNull NBTItem skinItemNBT, @NotNull MMOItem skinItemMMO) {
|
||||
|
||||
target.addTag(new ItemTag("MMOITEMS_HAS_SKIN", true));
|
||||
target.addTag(new ItemTag("MMOITEMS_SKIN_ID", skinItemNBT.getString("MMOITEMS_ITEM_ID")));
|
||||
target.addTag(new ItemTag(tagHasSkin, true));
|
||||
target.addTag(new ItemTag(tagSkinID, skinItemNBT.getString(tagSkinID)));
|
||||
if (skinItemNBT.getInteger("CustomModelData") != 0) {
|
||||
target.addTag(new ItemTag("CustomModelData", skinItemNBT.getInteger("CustomModelData"))); }
|
||||
if (!skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES").isEmpty()) {
|
||||
target.addTag(new ItemTag("MMOITEMS_ITEM_PARTICLES", skinItemNBT.getString("MMOITEMS_ITEM_PARTICLES"))); }
|
||||
|
||||
ItemStack item = target.toItem();
|
||||
if (item.getType() != skinItemNBT.getItem().getType())
|
||||
item.setType(skinItemNBT.getItem().getType());
|
||||
if (item.getType() != skinItemNBT.getItem().getType()) { item.setType(skinItemNBT.getItem().getType()); }
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
ItemMeta skinMeta = skinItemNBT.getItem().getItemMeta();
|
||||
|
@ -24,7 +24,7 @@ public class RFFKeepSkins implements Listener {
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping Skins");
|
||||
|
||||
// Got skin?
|
||||
if (!event.getReforger().getNBTItem().getBoolean("MMOITEMS_HAS_SKIN")) { return; }
|
||||
if (!event.getReforger().getNBTItem().getBoolean(ItemSkin.tagHasSkin)) { return; }
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Item has skin");
|
||||
|
||||
// Apply skin to result
|
||||
|
@ -9,6 +9,7 @@ import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.Indyuce.mmoitems.stat.type.StatHistory;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -21,11 +22,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class RFGKeepRNG implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onReforge(MMOItemReforgeEvent event) {
|
||||
|
||||
// Rerolling stats? Nevermind
|
||||
if (event.getOptions().shouldReroll()) { return; }
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping RNG Rolls");
|
||||
if (event.getOptions().shouldReroll()) {
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping new item (Complete RNG Reroll)");
|
||||
return; }
|
||||
|
||||
//RFG// MMOItems.log("§8Reforge §4EFG§7 Keeping old RNG Rolls");
|
||||
|
||||
/*
|
||||
* Proceed to go through all stats
|
||||
@ -33,7 +38,9 @@ public class RFGKeepRNG implements Listener {
|
||||
for (ItemStat stat : event.getOldMMOItem().getStats()) {
|
||||
|
||||
// Skip if it cant merge
|
||||
if (!(stat.getClearStatData() instanceof Mergeable)) { continue; }
|
||||
if (!(stat.getClearStatData() instanceof Mergeable)) {
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 even mergeable");
|
||||
continue; }
|
||||
|
||||
/*
|
||||
* These stats are exempt from this 'keeping' operation.
|
||||
@ -46,18 +53,26 @@ public class RFGKeepRNG implements Listener {
|
||||
ItemStats.ENCHANTS.equals(stat) ||
|
||||
ItemStats.SOULBOUND.equals(stat) ||
|
||||
ItemStats.GEM_SOCKETS.equals(stat)) {
|
||||
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is \u00a7cnot\u00a77 processed here");
|
||||
continue; }
|
||||
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 being \u00a7bprocessed\u00a77...");
|
||||
|
||||
// Stat history in the old item
|
||||
StatHistory hist = StatHistory.from(event.getOldMMOItem(), stat);
|
||||
|
||||
// Alr what the template say, this roll too rare to be kept?
|
||||
RandomStatData source = event.getReforger().getTemplate().getBaseItemData().get(stat);
|
||||
|
||||
/*
|
||||
* Decide if this data is too far from RNG to
|
||||
* preserve its rolls, even if it should be
|
||||
* preserving the rolls.
|
||||
*/
|
||||
StatData keptData = shouldRerollRegardless(stat, source, hist.getOriginalData(), event.getReforger().getGenerationItemLevel());
|
||||
|
||||
// Old roll is ridiculously low probability under the new parameters. Forget.
|
||||
if (keptData == null) { return; }
|
||||
if (keptData == null) { continue; }
|
||||
|
||||
// Fetch History from the new item
|
||||
StatHistory clear = StatHistory.from(event.getNewMMOItem(), stat);
|
||||
@ -72,18 +87,23 @@ public class RFGKeepRNG implements Listener {
|
||||
*
|
||||
* In contrast to reforging, in which it is expected its RNG to be rerolled, updating should not do it
|
||||
* except in the most dire scenarios:
|
||||
* <br><br>
|
||||
* + The mean/standard deviation changing significantly:
|
||||
* If the chance of getting the same roll is ridiculously low (3.5SD) under the new settings, reroll.
|
||||
*
|
||||
* + The stat is no longer there, or a new stat was added
|
||||
* The chance of getting a roll of 0 will be evaluated per the rule above.
|
||||
* <br><br>
|
||||
* + The stat is no longer there: Mean and SD become zero, so the rule above always removes the old roll.
|
||||
* <br><br>
|
||||
* + There is a new stat: The original data is null so this method cannot be called, will roll the
|
||||
* new stat to actually add it for the first time.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Nullable StatData shouldRerollRegardless(@NotNull ItemStat stat, @NotNull RandomStatData source, @NotNull StatData original, int determinedItemLevel) {
|
||||
|
||||
// Not Mergeable, impossible to keep
|
||||
if (!(source instanceof UpdatableRandomStatData)) { return null; }
|
||||
if (!(source instanceof UpdatableRandomStatData)) {
|
||||
//RFG// MMOItems.log("§8Reforge §3RNG§7 Stat\u00a7f " + stat.getId() + "\u00a77 is not updatable!");
|
||||
return null; }
|
||||
|
||||
// Just pass on
|
||||
return ((UpdatableRandomStatData) source).reroll(stat, original, determinedItemLevel);
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.api.interaction.ItemSkin;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
@ -44,9 +45,22 @@ public class StoredTagsData implements StatData, Mergeable {
|
||||
|
||||
public StoredTagsData(NBTItem nbt) {
|
||||
for (String tag : nbt.getTags()) {
|
||||
|
||||
// Usually ignore mmoitems
|
||||
if (tag.startsWith("MMOITEMS_")) {
|
||||
|
||||
// Do not delete the skin tags (save them here)
|
||||
if (!ItemSkin.tagHasSkin.equals(tag) && !ItemSkin.tagSkinID.equals(tag)) {
|
||||
|
||||
// Not either of the skin tags, skip this.
|
||||
// Must be handled by its respective stat.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Any vanilla or MMOItem tag should be ignored as those are
|
||||
// automatically handled. Same for the History stat ones.
|
||||
if (ignoreList.contains(tag) || tag.startsWith("MMOITEMS_") || tag.startsWith(ItemStackBuilder.history_keyword))
|
||||
if (ignoreList.contains(tag) || tag.startsWith(ItemStackBuilder.history_keyword))
|
||||
continue;
|
||||
|
||||
// As more methods are added we can add more types here
|
||||
|
@ -32,8 +32,9 @@ public interface UpdatableRandomStatData {
|
||||
*
|
||||
* @param determinedItemLevel The level of the item
|
||||
*
|
||||
* @return The rerolled StatData if the original is unreasonable, but if it must be kept,
|
||||
* it should be a clone of the original, probably using {@link Mergeable#cloneData()}
|
||||
* @return The rerolled StatData if the original is unreasonable.
|
||||
* <br><br>
|
||||
* If the original is reasonable, a clone of it, probably using {@link Mergeable#cloneData()}
|
||||
*/
|
||||
@NotNull <T extends StatData> T reroll(@NotNull ItemStat stat, @NotNull T original, int determinedItemLevel);
|
||||
}
|
||||
|
@ -247,6 +247,23 @@ permissions:
|
||||
abilities: false
|
||||
items: true
|
||||
|
||||
#
|
||||
# When item stats has a numeric range of possibilities.
|
||||
# attack-damage:
|
||||
# base: 10
|
||||
# spread: 1
|
||||
#
|
||||
# Using the spread, a level, and a random number, we
|
||||
# obtain a random number (very related to the spread): 1.7
|
||||
#
|
||||
# If additive-spread-formula is true, this is added to the base:
|
||||
# RESULT: 10 + 1.7 = 11.7 attack damage
|
||||
#
|
||||
# If additive-spread-formula is false, this is multiplied to the base:
|
||||
# RESULT: 10 * 1.7 = 17 attack damage
|
||||
#
|
||||
additive-spread-formula: false
|
||||
|
||||
# Disables non MMOItems from being crafted in the vanilla workbench.
|
||||
# Add [] if the list is empty.
|
||||
disable-vanilla-recipes: []
|
||||
|
Loading…
Reference in New Issue
Block a user