diff options
author | olim <bobq4582@gmail.com> | 2024-04-29 21:50:44 +0100 |
---|---|---|
committer | olim <bobq4582@gmail.com> | 2024-07-01 14:26:13 +0100 |
commit | b700db32f2bccde3b6381d5d28136814c9fe9e37 (patch) | |
tree | ad087f5183710eacc06be91de4fb4122c000c8fa /src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo | |
parent | 9a59ee74d4e61aa2d31076a587fbf9ed2d6c6a64 (diff) | |
download | Skyblocker-b700db32f2bccde3b6381d5d28136814c9fe9e37.tar.gz Skyblocker-b700db32f2bccde3b6381d5d28136814c9fe9e37.tar.bz2 Skyblocker-b700db32f2bccde3b6381d5d28136814c9fe9e37.zip |
initial commit
detection of when the player is in the dojo and the helper for the discipline is implemented
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo')
4 files changed, 167 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java new file mode 100644 index 00000000..d5e19f28 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java @@ -0,0 +1,51 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.client.MinecraftClient; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Util; + +import java.awt.*; +import java.util.HashMap; + +public class DisciplineTestHelper { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + + private static final HashMap<String, String> SWORD_TO_NAME_LOOKUP = Util.make(new HashMap<>(), map -> { + map.put("WOOD_SWORD","Wood"); + map.put("IRON_SWORD","Iron"); + map.put("GOLD_SWORD","Gold"); + map.put("DIAMOND_SWORD","Diamond"); + }); + private static final HashMap<String, Integer> SWORD_TO_COLOR_LOOKUP = Util.make(new HashMap<>(), map -> { + map.put("WOOD_SWORD",0xa52a2a); + map.put("IRON_SWORD",0xc0c0c0); + map.put("GOLD_SWORD",0xffd700); + map.put("DIAMOND_SWORD",0x00ffff); + }); + + public static boolean isCorrect(String name) { + if (DojoManager.currentChallenge != DojoManager.DojoChallenges.DISCIPLINE || CLIENT == null || CLIENT.player == null) { + return false; + } + String heldId = ItemTooltip.getInternalNameFromNBT(CLIENT.player.getMainHandStack(), true); + if (SWORD_TO_NAME_LOOKUP.containsKey(heldId)) { + + return SWORD_TO_NAME_LOOKUP.get(heldId).equals(name); + } + return false; + } + + public static int getColor() { + if (DojoManager.currentChallenge != DojoManager.DojoChallenges.DISCIPLINE || CLIENT == null || CLIENT.player == null) { + return 0; + } + String heldId = ItemTooltip.getInternalNameFromNBT(CLIENT.player.getMainHandStack(), true); + if (SWORD_TO_COLOR_LOOKUP.containsKey(heldId)) { + return SWORD_TO_COLOR_LOOKUP.get(heldId); + } + return 0; + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java new file mode 100644 index 00000000..f133746a --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -0,0 +1,93 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import de.hysky.skyblocker.utils.Location; +import de.hysky.skyblocker.utils.Utils; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.text.Text; + +import java.util.Arrays; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DojoManager { + + private static final String START_MESSAGE = "§e[NPC] §eMaster Tao§f: Ahhh, here we go! Let's get you into the Arena."; + private static final Pattern TEST_OF_PATTERN = Pattern.compile("\\s+Test of (\\w+) OBJECTIVES"); + private static final String CHALLENGE_FINISHED_REGEX = "\\s+CHALLENGE ((COMPLEATED)|(FAILED))"; + + protected enum DojoChallenges { + NONE("none"), + DISCIPLINE("Discipline"), + SWIFTNESS("Swiftness"), + TENACITY("Tenacity"); + + private final String name; + + DojoChallenges(String name) { + this.name = name; + } + + public static DojoChallenges from(String name) { + return Arrays.stream(DojoChallenges.values()).filter(n -> name.equals(n.name)).findFirst().orElse(NONE); + } + } + + protected static DojoChallenges currentChallenge = DojoChallenges.NONE; + private static boolean inAreana = false; + + public static void init() { + ClientReceiveMessageEvents.GAME.register(DojoManager::onMessage); + WorldRenderEvents.AFTER_TRANSLUCENT.register(DojoManager::render); + ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); + + } + + private static void reset() { + inAreana = false; + currentChallenge = DojoChallenges.NONE; + } + + + private static void onMessage(Text text, Boolean overlay) { + + if (Utils.getLocation() != Location.CRIMSON_ISLE || overlay) { + return; + } + if (text.getString().equals(START_MESSAGE)) { + inAreana = true; + return; + } + if (!inAreana) { + return; + } + if (text.getString().matches(CHALLENGE_FINISHED_REGEX)) { + reset(); + return; + } + + //look for a message saying what challenge is starting if one has not already been found + if (currentChallenge != DojoChallenges.NONE) { + return; + } + Matcher nextChallenge = TEST_OF_PATTERN.matcher(text.getString()); + if (nextChallenge.matches()) { + currentChallenge = DojoChallenges.from(nextChallenge.group(1)); + } + } + + private static void render(WorldRenderContext context) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + return; + } + switch (currentChallenge) { + case SWIFTNESS -> SwiftnessTestHelper.render(context); + case TENACITY -> TenacityTestHelper.render(context); + } + //System.out.println(currentChallenge); + } + + +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java new file mode 100644 index 00000000..580c7d87 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java @@ -0,0 +1,12 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; + +public class SwiftnessTestHelper { + + + + protected static void render(WorldRenderContext context) { + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java new file mode 100644 index 00000000..48c1aaa0 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java @@ -0,0 +1,11 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; + +public class TenacityTestHelper { + + + protected static void render(WorldRenderContext context) { + + } +} |