Skip to content

Commit

Permalink
Added price display to books in hex (Moulberry#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
NopoTheGamer authored Sep 22, 2022
1 parent e5f1c29 commit 2d9bf47
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,12 @@ public void tick() {
if (ea != null) {
NBTTagCompound enchantments = ea.getCompoundTag("enchantments");
if (enchantments != null) {
String enchId = Utils.cleanColour(book.getDisplayName()).toLowerCase().replace(" ", "_").replace(
"-",
"_"
);
String enchId = Utils
.cleanColour(book.getDisplayName())
.toLowerCase()
.replace(" ", "_")
.replace("-", "_")
.replaceAll("[^a-z_]", "");
String name = Utils.cleanColour(book.getDisplayName());
int enchLevel = -1;
if (name.equalsIgnoreCase("Bane of Arthropods")) {
Expand Down Expand Up @@ -455,7 +457,8 @@ public void tick() {
.cleanColour(book.getDisplayName())
.toLowerCase()
.replace(" ", "_")
.replace("-", "_");
.replace("-", "_")
.replaceAll("[^a-z_]", "");
if (enchId.equalsIgnoreCase("_")) continue;
enchId = ItemUtils.fixEnchantId(enchId, true);
String name = Utils.cleanColour(book.getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ public Enchantment(

if (level >= 1 && Constants.ENCHANTS.has("enchants_xp_cost")) {
JsonObject allCosts = Constants.ENCHANTS.getAsJsonObject("enchants_xp_cost");
JsonObject maxLevel = null;
if (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel && Constants.ENCHANTS.has(
"max_xp_table_levels")) {
maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels");
}

if (allCosts.has(this.enchId)) {
JsonArray costs = allCosts.getAsJsonArray(this.enchId);

if (costs.size() >= 1) {
if (useMaxLevelForCost) {
this.xpCost = costs.get(costs.size() - 1).getAsInt();
int cost =
(maxLevel != null && maxLevel.has(this.enchId) ? maxLevel.get(this.enchId).getAsInt() : costs.size());
this.xpCost = costs.get(cost - 1).getAsInt();
} else if (level - 1 < costs.size()) {
this.xpCost = costs.get(level - 1).getAsInt();
} else {
Expand Down Expand Up @@ -442,7 +450,7 @@ private void tickEnchants() {
ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex);
ItemStack xpBottle = cc.getLowerChestInventory().getStackInSlot(50);
if (!hasXpBottle && xpBottle != null &&
xpBottle.getItem() == Items.experience_bottle) { //Make show when in dungeon screen
xpBottle.getItem() == Items.experience_bottle) {
String name = "Buy Xp Bottles";
String id = "XP_BOTTLE";
Enchantment xpBottleEnch = new Enchantment(50, name, id,
Expand All @@ -465,10 +473,12 @@ private void tickEnchants() {
if (ea != null) {
NBTTagCompound enchantments = ea.getCompoundTag("enchantments");
if (enchantments != null) {
String enchId = Utils.cleanColour(book.getDisplayName()).toLowerCase().replace(" ", "_").replace(
"-",
"_"
);
String enchId = Utils
.cleanColour(book.getDisplayName())
.toLowerCase()
.replace(" ", "_")
.replace("-", "_")
.replaceAll("[^a-z_]", "");
String name = Utils.cleanColour(book.getDisplayName());
int enchLevel = -1;
if (name.equalsIgnoreCase("Bane of Arthropods")) {
Expand All @@ -494,6 +504,13 @@ private void tickEnchants() {
String price = numberFormat.format(enchantment.price);
enchantment.displayLore.set(index, "\u00a76" + price + ".0 Coins");
}
if (lore.contains("Loading...")) {
if (enchantment.price > 0) {
enchantment.displayLore.set(index, "\u00a7eClick to buy on the Bazaar!");
} else {
enchantment.displayLore.set(index, "\u00a7cNot enough supply on the Bazaar!");
}
}
index++;
}
enchantment.displayLore.remove(0);
Expand All @@ -506,10 +523,23 @@ private void tickEnchants() {
continue;
}

boolean aboveMaxLevelFromEt = false;
if (NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel && Constants.ENCHANTS != null) {
JsonObject maxLevel = null;
if (Constants.ENCHANTS.has("max_xp_table_levels")) {
maxLevel = Constants.ENCHANTS.getAsJsonObject("max_xp_table_levels");
}
if (maxLevel != null && maxLevel.has(enchId)) {
if (enchantment.level > maxLevel.get(enchId).getAsInt()) {
aboveMaxLevelFromEt = true;
}
}
}

if (enchanterCurrentEnch == null) {
enchanterCurrentEnch = enchantment;
} else if (updateLevel) {
if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level) {
if (removingEnchantPlayerLevel < 0 && enchantment.level > enchanterCurrentEnch.level && !aboveMaxLevelFromEt) {
enchanterCurrentEnch = enchantment;
} else if (removingEnchantPlayerLevel >= 0 && enchantment.level < enchanterCurrentEnch.level) {
enchanterCurrentEnch = enchantment;
Expand Down Expand Up @@ -545,7 +575,7 @@ private void tickEnchants() {
ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex);
ItemStack xpBottle = cc.getLowerChestInventory().getStackInSlot(50);
if (!hasXpBottle && xpBottle != null &&
xpBottle.getItem() == Items.experience_bottle) { //Make show when in dungeon screen
xpBottle.getItem() == Items.experience_bottle) {
String name = "Buy Xp Bottles";
String id = "XP_BOTTLE";
Enchantment xpBottleEnch = new Enchantment(50, name, id,
Expand All @@ -565,7 +595,8 @@ private void tickEnchants() {
.cleanColour(book.getDisplayName())
.toLowerCase()
.replace(" ", "_")
.replace("-", "_");
.replace("-", "_")
.replaceAll("[^a-z_]", "");
if (enchId.equalsIgnoreCase("_")) continue;
enchId = ItemUtils.fixEnchantId(enchId, true);
String name = Utils.cleanColour(book.getDisplayName());
Expand Down Expand Up @@ -702,7 +733,7 @@ private void tickBooks() {
ItemStack book = cc.getLowerChestInventory().getStackInSlot(slotIndex);
ItemStack randomReforge = cc.getLowerChestInventory().getStackInSlot(48);
if (!hasRandomReforge && randomReforge != null &&
randomReforge.getItem() == Item.getItemFromBlock(Blocks.anvil)) { //Make show when in dungeon screen
randomReforge.getItem() == Item.getItemFromBlock(Blocks.anvil)) {
String name = Utils.cleanColour(randomReforge.getDisplayName());
String id = Utils.cleanColour(randomReforge.getDisplayName());
if (name.equals("Convert to Dungeon Item")) {
Expand Down Expand Up @@ -1639,6 +1670,48 @@ private void renderEnchantment(float partialTicks) {
);
Minecraft.getMinecraft().fontRendererObj.drawString(levelStr, left + 8 - levelWidth / 2, top + 4, colour, false);

String priceStr = "" + numberFormat.format(enchanterCurrentEnch.price) + " Coins";
if (enchanterCurrentEnch.price < 0) priceStr = "";
int priceWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(priceStr);
int priceTop = guiTop + 16;
int x = 180;
int color = 0x2d2102;
Minecraft.getMinecraft().fontRendererObj.drawString(
priceStr,
guiLeft + x - priceWidth / 2 - 1,
priceTop + 4,
color,
false
);
Minecraft.getMinecraft().fontRendererObj.drawString(
priceStr,
guiLeft + x - priceWidth / 2 + 1,
priceTop + 4,
color,
false
);
Minecraft.getMinecraft().fontRendererObj.drawString(
priceStr,
guiLeft + x - priceWidth / 2,
priceTop + 4 - 1,
color,
false
);
Minecraft.getMinecraft().fontRendererObj.drawString(
priceStr,
guiLeft + x - priceWidth / 2,
priceTop + 4 + 1,
color,
false
);
Minecraft.getMinecraft().fontRendererObj.drawString(
priceStr,
guiLeft + x - priceWidth / 2,
priceTop + 4,
0xfcba03,
false
);

//Enchant name
String name = WordUtils.capitalizeFully(ItemUtils
.fixEnchantId(enchanterCurrentEnch.enchId, false)
Expand Down Expand Up @@ -3572,6 +3645,15 @@ private List<String> renderSettings(int mouseX, int mouseY, List<String> tooltip
Gui.drawRect(guiLeft + 295, guiTop + 147, guiLeft + 295 + 16, guiTop + 147 + 16, 0x80ffffff);
tooltipToDisplay = createTooltip("Enable GUI", 0, "On", "Off");
break;
case 1:
Gui.drawRect(guiLeft + 295 + 18, guiTop + 147, guiLeft + 295 + 16 + 18, guiTop + 147 + 16, 0x80ffffff);
tooltipToDisplay = createTooltip("Max Level",
(NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel ? 0 : 1),
"Enabled", "Disabled");
tooltipToDisplay.add(1, EnumChatFormatting.GRAY + "Show max level of enchant");
tooltipToDisplay.add(2, EnumChatFormatting.GRAY + "from either hex or enchantment table");
tooltipToDisplay.add(3, EnumChatFormatting.GRAY + "max level");
break;
case 2:
Gui.drawRect(guiLeft + 295, guiTop + 147 + 18, guiLeft + 295 + 16, guiTop + 147 + 16 + 18, 0x80ffffff);
tooltipToDisplay = createTooltip("Sort enchants...",
Expand Down Expand Up @@ -4342,6 +4424,10 @@ public boolean mouseInput(int mouseX, int mouseY) {
NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableHexGUI = false;
break;
}
case 1: {
NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel = !NotEnoughUpdates.INSTANCE.config.enchantingSolvers.maxEnchLevel;
break;
}
case 2: {
int val = NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enchantSorting;
val += direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public class Enchanting {
@ConfigAccordionId(id = 1)
public int enchantOrdering = 0;

@Expose
@ConfigOption(
name = "Use highest level from /et in /hex",
desc = "Show max level from /et in hex instead of highest possible"
)
@ConfigEditorBoolean()
@ConfigAccordionId(id = 1)
public boolean maxEnchLevel = false;

@ConfigOption(
name = "Enchanting Solvers",
desc = ""
Expand Down

0 comments on commit 2d9bf47

Please sign in to comment.