diff options
Diffstat (limited to 'src/main/java')
6 files changed, 192 insertions, 1 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 14ee656a..37b493e2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -36,6 +36,7 @@ import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.listener.WorldListener; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneContactHelper; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneFavourites; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; @@ -342,6 +343,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(TitleUtil.getInstance()); MinecraftForge.EVENT_BUS.register(EnderNodeHighlighter.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneFavourites.getInstance()); + MinecraftForge.EVENT_BUS.register(AbiphoneContactHelper.getInstance()); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java new file mode 100644 index 00000000..d2a5fc84 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneContactHelper.java @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2022 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.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; + +import java.util.List; +import java.util.Map; + +public class AbiphoneContactHelper { + + private static final AbiphoneContactHelper INSTANCE = new AbiphoneContactHelper(); + + public static AbiphoneContactHelper getInstance() { + return INSTANCE; + } + + private String selectedWaypointName = ""; + private long lastClick = 0L; + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; + if (!Utils.getOpenChestName().equals("Contacts Directory")) return; + + List<String> list = event.toolTip; + if (list == null) return; + if (list.isEmpty()) return; + String rawNpcName = event.itemStack.getDisplayName(); + String npcName = StringUtils.cleanColour(rawNpcName); + + JsonObject data = getJsonData(npcName); + if (data == null) return; + + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactRequirements) { + if (data.has("requirement")) { + JsonArray requirements = data.get("requirement").getAsJsonArray(); + if (requirements.size() > 0) { + list.add(" "); + list.add("§e§lRequirements:"); + + for (JsonElement requirementObject : requirements) { + String requirement = requirementObject.getAsString(); + list.add(requirement); + } + } + } + } + + if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactMarker) { + if (data.has("x")) { + if (selectedWaypointName.equals(npcName)) { + list.set(0, npcName + " §f- §aMarker set!"); + } + + list.add(" "); + if (selectedWaypointName.equals(npcName)) { + list.add("§eClick to remove the marker!"); + } else { + list.add("§eClick to set a marker!"); + } + list.add("§eShift-Click to teleport to the nearest waypoint!"); + } + } + } + + @SubscribeEvent + public void onStackClick(SlotClickEvent event) { + if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.abiphoneContactMarker) return; + if (!Utils.getOpenChestName().equals("Contacts Directory")) return; + + ItemStack stack = event.slot.getStack(); + if (stack == null || stack.getDisplayName() == null) return; + + String rawNpcName = stack.getDisplayName(); + String npcName = StringUtils.cleanColour(rawNpcName); + + JsonObject data = getJsonData(npcName); + if (data == null) return; + if (!data.has("x")) return; + + int x = data.get("x").getAsInt(); + int y = data.get("y").getAsInt(); + int z = data.get("z").getAsInt(); + + String rawIslandName = data.get("island").getAsString(); + if (rawIslandName == null) return; + + if (lastClick + 500 > System.currentTimeMillis()) return; + lastClick = System.currentTimeMillis(); + + boolean shiftPressed = Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); + if (selectedWaypointName.equals(npcName) && !shiftPressed) { + NotEnoughUpdates.INSTANCE.navigation.untrackWaypoint(); + selectedWaypointName = ""; + } else { + trackWaypoint(rawNpcName, x, y, z, rawIslandName); + if (shiftPressed) { + NotEnoughUpdates.INSTANCE.navigation.useWarpCommand(); + } + selectedWaypointName = npcName; + } + Utils.playPressSound(); + } + + private static void trackWaypoint(String rawNpcName, int x, int y, int z, String rawIslandName) { + JsonObject waypoint = new JsonObject(); + waypoint.add("x", new JsonPrimitive(x)); + waypoint.add("y", new JsonPrimitive(y)); + waypoint.add("z", new JsonPrimitive(z)); + waypoint.add("displayname", new JsonPrimitive(rawNpcName)); + waypoint.add("island", new JsonPrimitive(rawIslandName)); + waypoint.add("internalname", new JsonPrimitive("abiphone-contact-" + rawNpcName)); + + NotEnoughUpdates.INSTANCE.navigation.trackWaypoint(waypoint); + } + + private JsonObject getJsonData(String npcName) { + JsonObject abiphone = Constants.ABIPHONE; + if (abiphone == null) return null; + + JsonObject contacts = abiphone.getAsJsonObject(); + for (Map.Entry<String, JsonElement> entry : contacts.entrySet()) { + String repoName = entry.getKey(); + if (repoName.equals(npcName)) { + return entry.getValue().getAsJsonObject(); + } + } + return null; + } + + public void resetMarker() { + selectedWaypointName = ""; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java index 89e95e25..9bdc4608 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java @@ -389,8 +389,10 @@ public class Navigation { && NotEnoughUpdates.INSTANCE.config.misc.untrackCloseWaypoints && island.equals(SBInfo.getInstance().mode)) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - if (thePlayer != null && thePlayer.getDistanceSq(position) < 16) + if (thePlayer != null && thePlayer.getDistanceSq(position) < 16) { untrackWaypoint(); + AbiphoneContactHelper.getInstance().resetMarker(); + } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java index dcb1344c..35c80579 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -87,6 +87,10 @@ public class GuiNavigation extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); String name = searchResults.get(i); JsonObject json = NotEnoughUpdates.INSTANCE.navigation.getWaypoints().get(name); + + //to prevent an NPE when trying to render a waypoint from AbiphoneContactExtraInformation + if (json == null) continue; + boolean selected = name.equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); int baseX = guiLeft + LIST_START_X; int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index 1697098e..5c320db1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -218,6 +218,22 @@ public class TooltipTweaks { @Expose @ConfigOption( + name = "Abiphone NPC Requirements", + desc = "Show what the NPC needs in order to add him as contact in the abiphone" + ) + @ConfigEditorBoolean + public boolean abiphoneContactRequirements = true; + + @Expose + @ConfigOption( + name = "Abiphone NPC Location", + desc = "Click on an NPC to set an marker at the location" + ) + @ConfigEditorBoolean + public boolean abiphoneContactMarker = true; + + @Expose + @ConfigOption( name = "Essence Price In Shop", desc = "Show the essence price in the essence shop in the dungeon hub" ) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java index 5a228dc4..e7674aa9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java @@ -76,6 +76,7 @@ public class Constants { public static JsonObject TROPHYFISH; public static JsonObject WEIGHT; public static JsonObject RNGSCORE; + public static JsonObject ABIPHONE; private static final ReentrantLock lock = new ReentrantLock(); @@ -98,6 +99,7 @@ public class Constants { TROPHYFISH = Utils.getConstant("trophyfish", gson); WEIGHT = Utils.getConstant("weight", gson); RNGSCORE = Utils.getConstant("rngscore", gson); + ABIPHONE = Utils.getConstant("abiphone", gson); parseEssenceCosts(); } catch (Exception ex) { |