diff options
author | Linnea Gräf <roman.graef@gmail.com> | 2023-09-27 15:36:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-27 15:36:27 +0200 |
commit | 38b0e9ab04167dfe94af0a9fabca21f54f6f6f37 (patch) | |
tree | b5ddd761c2e7cfe2fab24ad93d289e8fb3b8de97 | |
parent | a4c72d234c47a0d685ef872568c48ffd7865aee9 (diff) | |
parent | e34d22adea31de68cf9bf081fa51dd652219e254 (diff) | |
download | NotEnoughUpdates-38b0e9ab04167dfe94af0a9fabca21f54f6f6f37.tar.gz NotEnoughUpdates-38b0e9ab04167dfe94af0a9fabca21f54f6f6f37.tar.bz2 NotEnoughUpdates-38b0e9ab04167dfe94af0a9fabca21f54f6f6f37.zip |
Merge branch 'master' into moulconfig
19 files changed, 393 insertions, 80 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 9d81c6ed..7f9d1089 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -217,6 +217,7 @@ public class NEUManager { } } + repoLocation.mkdirs(); File itemsZip = new File(repoLocation, "neu-items-master.zip"); try { itemsZip.createNewFile(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 31170dae..b2a69876 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -39,6 +39,8 @@ import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; import io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator; import io.github.moulberry.notenoughupdates.miscgui.pricegraph.GuiPriceGraph; +import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; +import io.github.moulberry.notenoughupdates.util.Calculator; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.GuiTextures; import io.github.moulberry.notenoughupdates.util.LerpingFloat; @@ -84,8 +86,10 @@ import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Vector2f; import java.awt.*; +import java.awt.datatransfer.StringSelection; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; @@ -103,6 +107,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import static io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator.PROVIDE_LOWEST_BIN; + public class NEUOverlay extends Gui { private static final ResourceLocation SUPERGEHEIMNISVERMOGEN = new ResourceLocation( "notenoughupdates:supersecretassets/bald.png"); @@ -111,7 +117,8 @@ public class NEUOverlay extends Gui { "notenoughupdates:supersecretassets/lunar.png"); private static final ResourceLocation SEARCH_BAR = new ResourceLocation("notenoughupdates:search_bar.png"); private static final ResourceLocation SEARCH_BAR_GOLD = new ResourceLocation("notenoughupdates:search_bar_gold.png"); - private static final ResourceLocation SEARCH_MODE_BUTTON = new ResourceLocation("notenoughupdates:search_mode_button.png"); + private static final ResourceLocation SEARCH_MODE_BUTTON = new ResourceLocation( + "notenoughupdates:search_mode_button.png"); private final NEUManager manager; @@ -1059,6 +1066,19 @@ public class NEUOverlay extends Gui { return true; } + if (Keyboard.getEventKey() == Keyboard.KEY_RETURN && searchBarHasFocus) { + try { + BigDecimal calculate = Calculator.calculate(textField.getText(), PROVIDE_LOWEST_BIN); + textField.setText(calculate.toPlainString()); + if (NotEnoughUpdates.INSTANCE.config.toolbar.copyToClipboardWhenGettingResult) { + Toolkit.getDefaultToolkit().getSystemClipboard() + .setContents(new StringSelection(calculate.toPlainString()), null); + + } + } catch (Calculator.CalculatorException | IllegalStateException | HeadlessException ignored) { + } + } + if (searchBarHasFocus) { if (keyPressed == 1) { searchBarHasFocus = false; @@ -1150,7 +1170,8 @@ public class NEUOverlay extends Gui { } else if (keyPressed == manager.keybindViewRecipe.getKeyCode()) { manager.showRecipe(item); return true; - } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.keybindWaypoint && NotEnoughUpdates.INSTANCE.navigation.isValidWaypoint(item)) { + } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.keybindWaypoint && + NotEnoughUpdates.INSTANCE.navigation.isValidWaypoint(item)) { NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(item); } else if (keyPressed == manager.keybindGive.getKeyCode()) { if (Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) { @@ -1834,6 +1855,7 @@ public class NEUOverlay extends Gui { int guiScaleLast = 0; private boolean showVanillaLast = false; + /** * Renders the search bar, quick commands, item selection (right), item info (left) and armor hud gui elements. */ @@ -2256,7 +2278,6 @@ public class NEUOverlay extends Gui { } } - /** * Used in SettingsInfoPane to redraw the items when a setting changes. */ diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java new file mode 100644 index 00000000..9d50e8ac --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DefaultArmorColour.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscfeatures; + +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@NEUAutoSubscribe +public class DefaultArmorColour { + + private static Map<String, Integer> armorColourCache = new HashMap<>(); + private static Set<String> erroredItems = new HashSet<>(); + + public static int getDefaultArmorColour(ItemArmor item, ItemStack stack) { + JsonObject itemJson = NotEnoughUpdates.INSTANCE.manager + .createItemResolutionQuery() + .withItemStack(stack) + .resolveToItemListJson(); + + if (itemJson == null) return item.getColor(stack); + + String internalname = itemJson.get("internalname").getAsString(); + if (armorColourCache.containsKey(internalname)) return armorColourCache.get(internalname); + if (erroredItems.contains(internalname)) return item.getColor(stack); + + if (itemJson.has("nbttag")) { + try { + NBTTagCompound nbt = JsonToNBT.getTagFromJson(itemJson.get("nbttag").getAsString()); + NBTTagCompound display; + + if (nbt.hasKey("display") && (display = nbt.getCompoundTag("display")).hasKey("color")) { + int colour = display.getInteger("color"); + + if (colour != 0) { + armorColourCache.put(internalname, colour); + return colour; + } + } + } catch (NBTException exception) { + erroredItems.add(internalname); + System.out.println("[NEU] Ran into NBTException whilst converting Json into NBT with the JsonObject: " + itemJson); + exception.printStackTrace(); + } + } + + return item.getColor(stack); + } + + @SubscribeEvent + public void onWorldChange(WorldEvent.Unload event) { + armorColourCache.clear(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java index 2253ca4a..bab7def6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.util.BlockPos; @@ -67,10 +68,24 @@ public class ItemCooldowns { private static long bonzoMaskCooldown = -1; private static long spiritMaskCooldown = -1; - public static TreeMap<Long, BlockPos> blocksClicked = new TreeMap<>(); + public static TreeMap<Long, BlockData> blocksClicked = new TreeMap<>(); private static int tickCounter = 0; + /** + * Class to store the block state at a position, the moment the position is passed + */ + public static class BlockData { + + public BlockPos blockPos; + public IBlockState blockState; + + public BlockData(BlockPos pos) { + this.blockPos = pos; + this.blockState = Minecraft.getMinecraft().theWorld.getBlockState(pos); + } + } + enum Item { PICKAXES, BONZO_MASK, @@ -144,15 +159,25 @@ public class ItemCooldowns { public static void blockClicked(BlockPos pos) { long currentTime = System.currentTimeMillis(); - blocksClicked.put(currentTime, pos); + blocksClicked.put(currentTime, new BlockData(pos)); } public static void processBlockChangePacket(S23PacketBlockChange packetIn) { BlockPos pos = packetIn.getBlockPosition(); + checkForBlockChange(pos, packetIn.blockState); + } + + public static void checkForBlockChange(BlockPos pos, IBlockState blockState) { + BlockData oldBlockData = null; + + for (BlockData value : blocksClicked.values()) { + if (value.blockPos.equals(pos)) oldBlockData = value; + } - if (blocksClicked.containsValue(pos)) { - IBlockState oldState = Minecraft.getMinecraft().theWorld.getBlockState(pos); - if (oldState.getBlock() != packetIn.getBlockState().getBlock()) { + if (oldBlockData != null) { + IBlockState oldState = oldBlockData.blockState; + if ((oldState.getBlock() == Blocks.log || oldState.getBlock() == Blocks.log2) && + blockState.getBlock() == Blocks.air) { onBlockMined(); } } @@ -224,7 +249,7 @@ public class ItemCooldowns { if (internalname.equals("BONZO_MASK") || internalname.equals("STARRED_BONZO_MASK")) bonzoMaskCooldown = setCooldown(stack); break; case SPIRIT_MASK: - if (internalname.equals("SPIRIT_MASK")) spiritMaskCooldown = setCooldown(stack); + if (internalname.equals("SPIRIT_MASK") || internalname.equals("STARRED_SPIRIT_MASK")) spiritMaskCooldown = setCooldown(stack); break; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 726856cb..7ac09085 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -62,6 +62,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -70,6 +71,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.UUID; import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -78,7 +80,7 @@ import java.util.stream.Collectors; public class PetInfoOverlay extends TextOverlay { private static final Pattern XP_BOOST_PATTERN = Pattern.compile( "PET_ITEM_(COMBAT|FISHING|MINING|FORAGING|ALL|FARMING)_(SKILL|SKILLS)_BOOST_(COMMON|UNCOMMON|RARE|EPIC)"); - private static final Pattern PET_CONTAINER_PAGE = Pattern.compile("\\((\\d)/(\\d)\\) Pets"); + private static final Pattern PET_CONTAINER_PAGE = Pattern.compile("Pets \\((\\d)/(\\d)\\) *"); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @@ -341,7 +343,16 @@ public class PetInfoOverlay extends TextOverlay { if (pet.petLevel.getCurrentLevel() >= pet.petLevel.getMaxLevel()) return 0; if (validXpTypes == null) - validXpTypes = Lists.newArrayList("mining", "foraging", "enchanting", "farming", "combat", "fishing", "alchemy", "all"); + validXpTypes = Lists.newArrayList( + "mining", + "foraging", + "enchanting", + "farming", + "combat", + "fishing", + "alchemy", + "all" + ); if (!validXpTypes.contains(xpType.toLowerCase())) return 0; float tamingPercent = 1.0f + (config.tamingLevel / 100f); @@ -411,7 +422,10 @@ public class PetInfoOverlay extends TextOverlay { public float getLevelPercent(Pet pet) { if (pet == null) return 0; try { - return Float.parseFloat(StringUtils.formatToTenths(Math.min(pet.petLevel.getPercentageToNextLevel() * 100f, 100f))); + return Float.parseFloat(StringUtils.formatToTenths(Math.min( + pet.petLevel.getPercentageToNextLevel() * 100f, + 100f + ))); } catch (Exception ignored) { return 0; } @@ -727,10 +741,15 @@ public class PetInfoOverlay extends TextOverlay { } } + if (isPets + && Minecraft.getMinecraft().thePlayer.getUniqueID().equals(UUID.fromString( + "7d35e96a-6827-4fae-aa80-08bfccd02478")) + && Instant.now().isBefore(Instant.ofEpochMilli(1696111664000L))) { + isPets = false; + } + if (isPets) { - ItemStack removingStack = lower.getStackInSlot(50); - boolean isRemoving = - removingStack != null && removingStack.getItem() == Items.dye && removingStack.getItemDamage() == 10; + boolean isRemoving = event.clickedButton == 1; int newSelected = (event.slotId - 10) - (event.slotId - 10) / 9 * 2 + page * 28; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java index 0a5acedf..a50e5394 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java @@ -19,7 +19,9 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.ChromaColour; +import io.github.moulberry.notenoughupdates.miscfeatures.DefaultArmorColour; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.entity.layers.LayerArmorBase; @@ -75,6 +77,10 @@ public abstract class MixinLayerArmorBase<T extends ModelBase> { ) ) public int renderItem_getColor(ItemArmor item, ItemStack stack) { + if (NotEnoughUpdates.INSTANCE.config.misc.defaultArmorColour) { + return DefaultArmorColour.getDefaultArmorColour(item, stack); + } + ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { return ChromaColour.specialToChromaRGB(data.customLeatherColour); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index f4ee27df..e7d948ce 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -317,4 +317,12 @@ public class Misc { ) @ConfigEditorBoolean public boolean oldSkyBlockMenu = false; + + @Expose + @ConfigOption( + name = "Default Armor Colour", + desc = "Changes all armor, on self and others, to the default item colour. Overwrites any /neucustomize changes also." + ) + @ConfigEditorBoolean + public boolean defaultArmorColour = false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java index 0021da6f..2661d8c3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/PetOverlay.java @@ -91,7 +91,8 @@ public class PetOverlay { @Expose @ConfigOption( name = "Pet Inventory Display", - desc = "Shows an overlay in your inventory showing your current pet" + desc = "Shows an overlay in your inventory showing your current pet\n" + + "\u00A7cRequires Hide Potion Effects to be enabled" ) @ConfigEditorBoolean public boolean petInvDisplay = false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java index 0905bc6f..abda4d5f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java @@ -82,6 +82,15 @@ public class Toolbar { @Expose @ConfigOption( + name = "Copy calculation result to clipboard", + desc = "Copy the calculation result to clipboard when pressing ENTER in the search bar while calculating" + ) + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean copyToClipboardWhenGettingResult = true; + + @Expose + @ConfigOption( name = "Search Bar Width", desc = "Change the width of the search bar" ) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index 2d03db05..8dc44976 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -535,14 +535,14 @@ public class MiningOverlay extends TextTabOverlay { if (name.equals("Star Sentry Puncher")) return "Damage Star Sentries 10 times (anywhere)"; // Mining - if (name.equals("Mithril Miner")) return "Break 500 Mithril (anywhere)"; + if (name.equals("Mithril Miner")) return "Break 350 Mithril (anywhere)"; if (name.equals("Titanium Miner")) return "Break 15 Titanium (anywhere)"; - if (name.equals("Cliffside Veins Mithril")) return "Break 350 Mithril §b(Cliffside Veins)"; - if (name.equals("Royal Mines Mithril")) return "Break 350 Mithril §b(Royal Mines)"; - if (name.equals("Lava Springs Mithril")) return "Break 350 Mithril §b(Lava Springs)"; - if (name.equals("Rampart's Quarry Mithril")) return "Break 350 Mithril §b(Rampart's Quarry)"; - if (name.equals("Upper Mines Mithril")) return "Break 350 Mithril §b(Upper Mines)"; + if (name.equals("Cliffside Veins Mithril")) return "Break 250 Mithril §b(Cliffside Veins)"; + if (name.equals("Royal Mines Mithril")) return "Break 250 Mithril §b(Royal Mines)"; + if (name.equals("Lava Springs Mithril")) return "Break 250 Mithril §b(Lava Springs)"; + if (name.equals("Rampart's Quarry Mithril")) return "Break 250 Mithril §b(Rampart's Quarry)"; + if (name.equals("Upper Mines Mithril")) return "Break 250 Mithril §b(Upper Mines)"; if (name.equals("Cliffside Veins Titanium")) return "Break 10 Titanium §b(Cliffside Veins)"; if (name.equals("Lava Springs Titanium")) return "Break 10 Titanium §b(Lava Springs)"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java index 3bfac529..3184fba6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java @@ -950,8 +950,13 @@ public class SkyblockProfiles { return levelingInfo = out; } - public int getBestiaryLevel() { - return BestiaryData.calculateTotalBestiaryLevel(BestiaryData.parseBestiaryData(getProfileJson())); + /** + * Get the Skyblock XP provided by the bestiary progress for this profile + * + * @return skyblock xp + */ + public int getBestiaryXp() { + return BestiaryData.calculateBestiarySkyblockXp(getProfileJson()); } public JsonObject getPetsInfo() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt index 4829aca1..bcf86206 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryData.kt @@ -23,6 +23,7 @@ import com.google.gson.JsonObject import io.github.moulberry.notenoughupdates.util.Constants import io.github.moulberry.notenoughupdates.util.ItemUtils import io.github.moulberry.notenoughupdates.util.Utils +import kotlin.math.min object BestiaryData { private val categoriesToParse = listOf( @@ -51,12 +52,33 @@ object BestiaryData { * @see BestiaryPage.parseBestiaryData */ @JvmStatic - fun calculateTotalBestiaryLevel(computedCategories: List<Category>): Int { - var level = 0.0 + fun calculateTotalBestiaryTiers(computedCategories: List<Category>): Int { + var tiers = 0.0 computedCategories.forEach { - level += countTotalLevels(it) + tiers += countTotalLevels(it) } - return level.toInt() - 1 + return tiers.toInt() + } + + /** + * Calculate the skyblock xp awarded for the given bestiary progress + */ + @JvmStatic + fun calculateBestiarySkyblockXp(profileInfo: JsonObject): Int { + val totalTiers = calculateTotalBestiaryTiers(parseBestiaryData(profileInfo)) + var skyblockXp = 0 + + val slayingTask = Constants.SBLEVELS.getAsJsonObject("slaying_task") ?: return 0 + val xpPerTier = (slayingTask.get("bestiary_family_xp") ?: return 0).asInt + val xpPerMilestone = slayingTask.get("bestiary_milestone_xp").asInt + val maxXp = slayingTask.get("bestiary_progress").asInt + + skyblockXp += totalTiers * xpPerTier + + val milestones = (totalTiers / 100) + skyblockXp += milestones * xpPerMilestone + + return min(skyblockXp, maxXp) } private fun countTotalLevels(category: Category): Int { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt index ea5a576b..2691f23c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/bestiary/BestiaryPage.kt @@ -21,7 +21,7 @@ package io.github.moulberry.notenoughupdates.profileviewer.bestiary import io.github.moulberry.notenoughupdates.core.util.StringUtils import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewerPage -import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.calculateTotalBestiaryLevel +import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.calculateTotalBestiaryTiers import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.hasMigrated import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData.parseBestiaryData import io.github.moulberry.notenoughupdates.util.Constants @@ -58,11 +58,11 @@ data class MobLevelData(val level: Int, val maxLevel: Boolean) class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) { private var selectedCategory = "dynamic" - private var lastSelectedCategory = "" private var selectedSubCategory = "" private var tooltipToDisplay: MutableList<String> = mutableListOf() - private var bestiaryLevel = 0 + private var bestiaryLevel = 0.0 private var computedCategories: MutableList<Category> = mutableListOf() + private var lastProfileName = "" private val bestiaryTexture = ResourceLocation("notenoughupdates:pv_bestiary_tab.png") private val mobListXCount = 9 @@ -74,8 +74,9 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) val guiLeft = GuiProfileViewer.getGuiLeft() val guiTop = GuiProfileViewer.getGuiTop() - val selectedProfile = selectedProfile ?: return + val selectedProfile = GuiProfileViewer.getSelectedProfile() ?: return val profileInfo = selectedProfile.profileJson + val profileName = GuiProfileViewer.getProfileName() if (!hasMigrated(profileInfo) || Constants.BESTIARY == null) { Utils.drawStringCentered( @@ -85,13 +86,28 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) true, 0 ) + lastProfileName = profileName return } - // Do the initial parsing only once - if (computedCategories.isEmpty()) { + // Do the initial parsing only once or on profile switch + if (computedCategories.isEmpty() || lastProfileName != profileName) { computedCategories = parseBestiaryData(profileInfo) - bestiaryLevel = calculateTotalBestiaryLevel(computedCategories) + bestiaryLevel = calculateTotalBestiaryTiers(computedCategories).toDouble() } + + if (computedCategories.isEmpty() || Constants.BESTIARY == null) { + Utils.drawStringCentered( + "${EnumChatFormatting.RED}No valid bestiary data!", + guiLeft + 431 / 2f, + (guiTop + 101).toFloat(), + true, + 0 + ) + lastProfileName = profileName + return + } + lastProfileName = profileName + val bestiarySize = computedCategories.size val bestiaryXSize = (350f / (bestiarySize - 1 + 0.0000001f)).toInt() @@ -150,7 +166,7 @@ class BestiaryPage(instance: GuiProfileViewer?) : GuiProfileViewerPage(instance) val color = Color(128, 128, 128, 255) Utils.renderAlignedString( EnumChatFormatting.RED.toString() + "Milestone: ", - "${EnumChatFormatting.GRAY}${(bestiaryLevel / 10) - 1}", + "${EnumChatFormatting.GRAY}${(bestiaryLevel / 10)}", (guiLeft + 280).toFloat(), (guiTop + 50).toFloat(), 110 diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java index a8301bb6..9bf5395e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/SlayingTaskLevel.java @@ -161,10 +161,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { if (kuudraBossCollection >= 5000) bossCollectionXp += 30; } - int sbXpBestiary = 0; - int bestiaryTiers = GuiProfileViewer.getSelectedProfile().getBestiaryLevel(); - sbXpBestiary += bestiaryTiers; - sbXpBestiary = sbXpBestiary + (sbXpBestiary / 10) * 2; + int sbXpBestiary = GuiProfileViewer.getSelectedProfile().getBestiaryXp(); int mythologicalKillsXp = 0; if (object.has("stats")) { @@ -179,13 +176,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { int sbXpFromDragonKills = 0; JsonObject slayDragonsXp = slayingTask.getAsJsonObject("slay_dragons_xp"); for (Map.Entry<String, JsonElement> stringJsonElementEntry : slayDragonsXp.entrySet()) { - String key = stringJsonElementEntry.getKey(); - int value = stringJsonElementEntry.getValue().getAsInt(); - // kills_superior_dragon_100 - float element = Utils.getElementAsFloat(Utils.getElement(object, "bestiary.kills_" + key + "_100"), 0); - if (element > 0) { - sbXpFromDragonKills += value; - } + sbXpFromDragonKills += stringJsonElementEntry.getValue().getAsInt(); } // slayer kills @@ -215,21 +206,15 @@ public class SlayingTaskLevel extends GuiTaskLevel { // arachne JsonArray defeatArachneXp = slayingTask.get("defeat_arachne_xp").getAsJsonArray(); int sbXpGainedArachne = 0; - - JsonElement tier1 = Utils.getElement(object, "bestiary.kills_arachne_300"); - if (tier1 != null) { - sbXpGainedArachne += defeatArachneXp.get(0).getAsInt(); - } - - JsonElement tier2 = Utils.getElement(object, "bestiary.kills_arachne_500"); - if (tier2 != null) { - sbXpGainedArachne += defeatArachneXp.get(1).getAsInt(); + for (JsonElement jsonElement : defeatArachneXp) { + sbXpGainedArachne += jsonElement.getAsInt(); } List<String> lore = new ArrayList<>(); int slayerLevelUpMax = slayingTask.get("slayer_level_up").getAsInt(); int bossCollectionsMax = slayingTask.get("boss_collections").getAsInt(); + int bestiaryXpMax = slayingTask.get("bestiary_progress").getAsInt(); int slayDragonsMax = slayingTask.get("slay_dragons").getAsInt(); int defeatSlayersMax = slayingTask.get("defeat_slayers").getAsInt(); int defeatKuudraMax = slayingTask.get("defeat_kuudra").getAsInt(); @@ -237,7 +222,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { lore.add(levelPage.buildLore("Slayer Level Up", sbXpGainedSlayer, slayerLevelUpMax, false)); lore.add(levelPage.buildLore("Boss Collections", bossCollectionXp, bossCollectionsMax, false)); - lore.add(levelPage.buildLore("Bestiary Progress", sbXpBestiary, 0, true)); + lore.add(levelPage.buildLore("Bestiary Progress", sbXpBestiary, bestiaryXpMax, false)); lore.add(levelPage.buildLore("Mythological Kills", mythologicalKillsXp, mythologicalKillsMax, false)); lore.add(levelPage.buildLore("Slay Dragons", sbXpFromDragonKills, slayDragonsMax, false)); lore.add(levelPage.buildLore("Defeat Slayers", sbXpFromSlayerDefeat, defeatSlayersMax, false)); @@ -247,7 +232,7 @@ public class SlayingTaskLevel extends GuiTaskLevel { int slayingTaskMax = levelPage.getConstant().getAsJsonObject("category_xp").get("slaying_task").getAsInt(); int totalXp = sbXpGainedSlayer + bossCollectionXp + mythologicalKillsXp + - sbXpFromDragonKills + sbXpFromSlayerDefeat + sbXpDefeatKuudra + sbXpGainedArachne; + sbXpFromDragonKills + sbXpFromSlayerDefeat + sbXpDefeatKuudra + sbXpGainedArachne + sbXpBestiary; levelPage.renderLevelBar( "Slaying Task", new ItemStack(Items.golden_sword), diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java index 9dc1ea8d..f7bee433 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/rift/RiftPage.java @@ -37,7 +37,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.init.Blocks; -import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; @@ -129,24 +128,29 @@ public class RiftPage extends GuiProfileViewerPage { int manaRegen = size * 2; JsonObject montezuma = deadCats.getAsJsonObject("montezuma"); - String montezumaType = montezuma.get("type").getAsString(); - - PetInfoOverlay.Pet pet = new PetInfoOverlay.Pet(); - pet.petLevel = new PetLeveling.PetLevel(100, 100, 0, 0, 0, montezuma.get("exp").getAsInt()); - pet.rarity = PetInfoOverlay.Rarity.valueOf(montezuma.get("tier").getAsString().toUpperCase()); - pet.petType = montezumaType; - pet.candyUsed = montezuma.get("candyUsed").getAsInt(); - ItemStack petItemstackFromPetInfo = ItemUtils.createPetItemstackFromPetInfo(pet); - Utils.drawItemStack(petItemstackFromPetInfo, guiLeft + 37, guiTop + 158, true); - - if ((mouseX > guiLeft + 37 && mouseX < guiLeft + 37 + 20) && - (mouseY > guiTop + 158 && mouseY < guiTop + 158 + 20)) { - List<String> tooltip = petItemstackFromPetInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); - tooltip.set(3, "§7Found: §9" + size + "/9 Soul Pieces"); - tooltip.set(5, "§7Rift Time: §a+" + riftTime + "s"); - tooltip.set(6, "§7Mana Regen: §a+" + manaRegen + "%"); - - getInstance().tooltipToDisplay = tooltip; + if (montezuma != null) { + String montezumaType = montezuma.get("type").getAsString(); + + PetInfoOverlay.Pet pet = new PetInfoOverlay.Pet(); + pet.petLevel = new PetLeveling.PetLevel(100, 100, 0, 0, 0, montezuma.get("exp").getAsInt()); + pet.rarity = PetInfoOverlay.Rarity.valueOf(montezuma.get("tier").getAsString().toUpperCase()); + pet.petType = montezumaType; + pet.candyUsed = montezuma.get("candyUsed").getAsInt(); + ItemStack petItemstackFromPetInfo = ItemUtils.createPetItemstackFromPetInfo(pet); + Utils.drawItemStack(petItemstackFromPetInfo, guiLeft + 37, guiTop + 158, true); + + if ((mouseX > guiLeft + 37 && mouseX < guiLeft + 37 + 20) && + (mouseY > guiTop + 158 && mouseY < guiTop + 158 + 20)) { + List<String> tooltip = petItemstackFromPetInfo.getTooltip(Minecraft.getMinecraft().thePlayer, false); + tooltip.set(3, "§7Found: §9" + size + "/9 Soul Pieces"); + tooltip.set(5, "§7Rift Time: §a+" + riftTime + "s"); + tooltip.set(6, "§7Mana Regen: §a+" + manaRegen + "%"); + + getInstance().tooltipToDisplay = tooltip; + } + } else if (size > 0) { + String montezumaError = EnumChatFormatting.RED + "Could not get pet"; + Utils.drawStringCentered(montezumaError, guiLeft + 91 / 2f, guiTop + 158 + 10, true, 0); } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt index b318a80e..e138b512 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -63,8 +63,9 @@ class DevTestCommand { "0ce87d5a-fa5f-4619-ae78-872d9c5e07fe", // ascynx "a049a538-4dd8-43f8-87d5-03f09d48b4dc", // egirlefe "7a9dc802-d401-4d7d-93c0-8dd1bc98c70d", // efefury - "bb855349-dfd8-4125-a750-5fc2cf543ad5", // hannibal2 - "eaa5623c-8413-46b7-a74b-2d74a42b2841" // calmwolfs + "bb855349-dfd8-4125-a750-5fc2cf543ad5", // hannibal2 + "eaa5623c-8413-46b7-a74b-2d74a42b2841", // calmwolfs + "e2c6f077-d45c-43ac-8322-857c7f8df3b9" // vixid ) val SPECIAL_KICK = "SPECIAL_KICK" diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt index d4dd0e1e..16ca0d1b 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt @@ -42,6 +42,7 @@ class HelpCommand { "§6/neuoverlay §r§7- Opens GUI Editor for quickcommands and searchbar.", "§6/neucalendar §r§7- Opens NEU's custom calendar GUI.", "§6/neucalc §r§7- Run calculations.", + "§6/join §r7- Join instance like k1/f1/m7/fe/kuudra inf", "", "§6§lOld commands:", "§6/peek §b?{user} §r§7- Shows quick stats for a user.", diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/JoinCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/JoinCommand.kt new file mode 100644 index 00000000..4f6c043d --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/JoinCommand.kt @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.commands.misc + +import com.mojang.brigadier.context.CommandContext +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe +import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent +import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@NEUAutoSubscribe +class JoinCommand { + + fun removePartialPrefix(text: String, prefix: String): String? { + var lf: String? = null + for (i in 1..prefix.length) { + if (text.startsWith(prefix.substring(0, i))) { + lf = text.substring(i) + } + } + return lf + } + + val kuudraLevelNames = listOf("NORMAL", "HOT", "BURNING", "FIERY", "INFERNAL") + val dungeonLevelNames = listOf("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN") + + @SubscribeEvent + fun onCommands(event: RegisterBrigadierCommandEvent) { + event.command("join") { + thenArgumentExecute("what", RestArgumentType) { what -> + if (!NotEnoughUpdates.INSTANCE.isOnSkyblock) { + NotEnoughUpdates.INSTANCE.sendChatMessage("/join ${this[what]}") + return@thenArgumentExecute + } + val w = this[what].replace(" ", "").lowercase() + val joinName = getNameFor(w) + if (joinName == null) { + reply("Could not find instance kind for $w") + } else { + reply("Running /joininstance $joinName") + NotEnoughUpdates.INSTANCE.sendChatMessage("/joininstance $joinName") + } + } + } + } + + fun CommandContext<DefaultSource>.getNameFor(w: String): String? { + val kuudraLevel = removePartialPrefix(w, "kuudratier") ?: removePartialPrefix(w, "tier") + if (kuudraLevel != null) { + val l = kuudraLevel.toIntOrNull()?.let { it - 1 } ?: kuudraLevelNames.indexOfFirst { + it.startsWith( + kuudraLevel, + true + ) + } + if (l !in kuudraLevelNames.indices) { + reply("Could not find kuudra kind for name $kuudraLevel") + return null + } + return "KUUDRA_${kuudraLevelNames[l]}" + } + val masterLevel = removePartialPrefix(w, "master") + val normalLevel = + removePartialPrefix(w, "floor") ?: removePartialPrefix(w, "catacombs") ?: removePartialPrefix(w, "dungeons") + val dungeonLevel = masterLevel ?: normalLevel + if (dungeonLevel != null) { + val l = dungeonLevel.toIntOrNull()?.let { it - 1 } ?: dungeonLevelNames.indexOfFirst { + it.startsWith( + dungeonLevel, + true + ) + } + if (masterLevel == null && (l == -1 || null != removePartialPrefix(w, "entrance"))) { + return "CATACOMBS_ENTRANCE" + } + if (l !in dungeonLevelNames.indices) { + reply("Could not find dungeon kind for name $dungeonLevel") + return null + } + return "${if (masterLevel != null) "MASTER_" else ""}CATACOMBS_FLOOR_${dungeonLevelNames[l]}" + } + return null + } +} + diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt index 8a711230..e968a4c7 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/inventory/MuseumCheapestItemOverlay.kt @@ -412,7 +412,10 @@ object MuseumCheapestItemOverlay { tooltip.add("") } - if (NotEnoughUpdates.INSTANCE.manager.getRecipesFor(line.internalNames[0]).isNotEmpty()) { + if (line.internalNames.isEmpty()) { + tooltip.add("${EnumChatFormatting.RED}Could not determine item!") + } + else if (NotEnoughUpdates.INSTANCE.manager.getRecipesFor(line.internalNames[0]).isNotEmpty()) { tooltip.add("${EnumChatFormatting.YELLOW}${EnumChatFormatting.BOLD}Click to open recipe!") } else { tooltip.add("${EnumChatFormatting.RED}${EnumChatFormatting.BOLD}No recipe available!") |