Skip to content

Commit

Permalink
Toggleable lore display
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jan 8, 2022
1 parent 9e61419 commit 7d4513a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public static class Costs {
@BrigadierExcluded
@SerializedName("ignore_economy_mod")
public boolean ignoreEconomyMod = false;

@SerializedName("// Whether to add lore with cost info to the item.")
public final String _comment_addLore = "";
@SerializedName("add_lore")
public boolean addLore = true;
}


Expand Down
54 changes: 29 additions & 25 deletions common/src/main/java/org/samo_lego/blacksmiths/gui/RepairGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,37 @@ public ItemStack getItem(int index) {
}
}

ItemStack copy = itemStack.copy();
CompoundTag nbt = copy.getTag();

if (nbt != null) {
// Calculate cost
double amount = (startDmg - itemStack.getDamageValue()) * this.profession.getCostPerDamage();
VanillaEconomy economy = Blacksmiths.getInstance().getEconomy();

double cost = economy.getItemConversionCost(amount);
MutableComponent costLore = economy.getCurrencyFormat(cost);
boolean canAfford = Blacksmiths.getInstance().getEconomy().canAfford(cost, this.player) >= 0;

CompoundTag nbtDisplay = nbt.getCompound(ItemStack.TAG_DISPLAY);
ListTag nbtLore = new ListTag();

nbtLore.add(StringTag.valueOf(
Component.Serializer.toJson(
costLore.withStyle(canAfford ? ChatFormatting.GREEN : ChatFormatting.RED)
)
));

nbtDisplay.put(ItemStack.TAG_LORE, nbtLore);
nbt.put(ItemStack.TAG_DISPLAY, nbtDisplay);
copy.setTag(nbt);
// Adds lore with current cost to the item.
if (CONFIG.costs.addLore) {
ItemStack copy = itemStack.copy();
CompoundTag nbt = copy.getTag();

if (nbt != null) {
// Calculate cost
double amount = (startDmg - itemStack.getDamageValue()) * this.profession.getCostPerDamage();
VanillaEconomy economy = Blacksmiths.getInstance().getEconomy();

double cost = economy.getItemConversionCost(amount);
MutableComponent costLore = economy.getCurrencyFormat(cost);
boolean canAfford = Blacksmiths.getInstance().getEconomy().canAfford(cost, this.player) >= 0;

CompoundTag nbtDisplay = nbt.getCompound(ItemStack.TAG_DISPLAY);
ListTag nbtLore = new ListTag();

nbtLore.add(StringTag.valueOf(
Component.Serializer.toJson(
costLore.withStyle(canAfford ? ChatFormatting.GREEN : ChatFormatting.RED)
)
));

nbtDisplay.put(ItemStack.TAG_LORE, nbtLore);
nbt.put(ItemStack.TAG_DISPLAY, nbtDisplay);
copy.setTag(nbt);
}

itemStack = copy;
}

itemStack = copy;
} else {
itemStack = ItemStack.EMPTY;
}
Expand Down

0 comments on commit 7d4513a

Please sign in to comment.