From b700db32f2bccde3b6381d5d28136814c9fe9e37 Mon Sep 17 00:00:00 2001 From: olim Date: Mon, 29 Apr 2024 21:50:44 +0100 Subject: initial commit detection of when the player is in the dojo and the helper for the discipline is implemented --- .../java/de/hysky/skyblocker/SkyblockerMod.java | 2 + .../crimson/dojo/DisciplineTestHelper.java | 51 ++++++++++++ .../skyblock/crimson/dojo/DojoManager.java | 93 ++++++++++++++++++++++ .../skyblock/crimson/dojo/SwiftnessTestHelper.java | 12 +++ .../skyblock/crimson/dojo/TenacityTestHelper.java | 11 +++ .../hysky/skyblocker/skyblock/entity/MobGlow.java | 16 ++++ src/main/java/de/hysky/skyblocker/utils/Utils.java | 2 +- 7 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index d793e73d..28722558 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -11,6 +11,7 @@ import de.hysky.skyblocker.skyblock.chat.ChatRuleAnnouncementScreen; import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler; import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder; import de.hysky.skyblocker.skyblock.chocolatefactory.TimeTowerReminder; +import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.crimson.kuudra.Kuudra; import de.hysky.skyblocker.skyblock.dungeon.*; import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen; @@ -179,6 +180,7 @@ public class SkyblockerMod implements ClientModInitializer { ApiUtils.init(); Debug.init(); Kuudra.init(); + DojoManager.init(); RenderHelper.init(); FancyStatusBars.init(); EventNotifications.init(); 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 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 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) { + + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java index d6f9410b..d373d2e1 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java @@ -1,15 +1,18 @@ package de.hysky.skyblocker.skyblock.entity; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.crimson.dojo.DisciplineTestHelper; import de.hysky.skyblocker.skyblock.dungeon.LividColor; import de.hysky.skyblocker.skyblock.end.TheEnd; import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.SlayerUtils; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.culling.OcclusionCulling; import net.minecraft.entity.Entity; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.mob.EndermanEntity; +import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.entity.passive.BatEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -28,6 +31,7 @@ public class MobGlow { if (OcclusionCulling.getReducedCuller().isVisible(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ)) { String name = entity.getName().getString(); + // Dungeons if (Utils.isInDungeons() && !entity.isInvisible()) { return switch (entity) { @@ -46,6 +50,7 @@ public class MobGlow { }; } + return switch (entity) { // Rift case PlayerEntity p when Utils.isInTheRift() && !entity.isInvisible() && name.equals("Blobbercyst ") -> SkyblockerConfigManager.get().otherLocations.rift.blobbercystGlow; @@ -57,6 +62,9 @@ public class MobGlow { // Special Zelot case EndermanEntity enderman when Utils.isInTheEnd() && !entity.isInvisible() -> TheEnd.isSpecialZealot(enderman); + //dojo + case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE -> DisciplineTestHelper.isCorrect(getArmourStandName(zombie)); + default -> false; }; } @@ -73,6 +81,13 @@ public class MobGlow { List armorStands = getArmorStands(entity); return !armorStands.isEmpty() && armorStands.getFirst().getName().getString().contains("✯"); } + public static String getArmourStandName(Entity entity) { + List armorStands = getArmorStands(entity); + if (armorStands.isEmpty()) { + return null; + } + return armorStands.getFirst().getName().getString(); + } public static List getArmorStands(Entity entity) { return getArmorStands(entity.getWorld(), entity.getBoundingBox()); @@ -94,6 +109,7 @@ public class MobGlow { case EndermanEntity enderman when TheEnd.isSpecialZealot(enderman) -> Formatting.RED.getColorValue(); case ArmorStandEntity armorStand when isNukekubiHead(armorStand) -> 0x990099; + case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE -> DisciplineTestHelper.getColor(); default -> 0xf57738; }; diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 84b3cb9e..f383c94a 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -95,7 +95,7 @@ public class Utils { } public static boolean isInDungeons() { - return location == Location.DUNGEON || FabricLoader.getInstance().isDevelopmentEnvironment(); + return location == Location.DUNGEON ; // || FabricLoader.getInstance().isDevelopmentEnvironment() } public static boolean isInCrystalHollows() { -- cgit From e39a80fa3e4f0e81137e1c9825decb52ae4344ff Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Apr 2024 12:34:20 +0100 Subject: add swiftness helper works but for some reason some block updates are not sent to the function so sometimes dose not update --- .../mixins/ClientPlayNetworkHandlerMixin.java | 6 ++++- .../skyblock/crimson/dojo/DojoManager.java | 16 +++++++++++-- .../skyblock/crimson/dojo/SwiftnessTestHelper.java | 28 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index 48389d40..feb5a1cb 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -5,13 +5,14 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import com.llamalad7.mixinextras.sugar.Local; import de.hysky.skyblocker.skyblock.CompactDamage; import de.hysky.skyblocker.skyblock.FishingHelper; -import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder; +import de.hysky.skyblocker.skyblock.crimson.dojo.SwiftnessTestHelper; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; import de.hysky.skyblocker.skyblock.end.EnderNodes; import de.hysky.skyblocker.skyblock.end.TheEnd; import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual; +import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.SlayerUtils; import de.hysky.skyblocker.utils.Utils; import net.minecraft.block.Blocks; @@ -49,6 +50,9 @@ public abstract class ClientPlayNetworkHandlerMixin { BeaconHighlighter.beaconPositions.add(packet.getPos()); } } + if (Utils.getLocation() == Location.CRIMSON_ISLE) { + SwiftnessTestHelper.blockUpdate(packet); + } } @Inject(method = "method_37472", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;removeEntity(ILnet/minecraft/entity/Entity$RemovalReason;)V")) 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 index f133746a..8e8482ea 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -1,12 +1,15 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; +import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.scheduler.Scheduler; 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 net.minecraft.world.updater.WorldUpdater; import java.util.Arrays; import java.util.regex.Matcher; @@ -16,7 +19,7 @@ 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))"; + private static final String CHALLENGE_FINISHED_REGEX = "\\s+CHALLENGE ((COMPLETED)|(FAILED))"; protected enum DojoChallenges { NONE("none"), @@ -41,13 +44,17 @@ public class DojoManager { public static void init() { ClientReceiveMessageEvents.GAME.register(DojoManager::onMessage); WorldRenderEvents.AFTER_TRANSLUCENT.register(DojoManager::render); + Scheduler.INSTANCE.scheduleCyclic(DojoManager::update, 5); ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); } + + private static void reset() { inAreana = false; currentChallenge = DojoChallenges.NONE; + SwiftnessTestHelper.reset(); } @@ -78,6 +85,12 @@ public class DojoManager { } } + private static void update() { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + return; + } + } + private static void render(WorldRenderContext context) { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { return; @@ -86,7 +99,6 @@ public class DojoManager { 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 index 580c7d87..d2a9ae57 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java @@ -1,12 +1,40 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; +import de.hysky.skyblocker.utils.render.RenderHelper; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; public class SwiftnessTestHelper { + private static BlockPos lastBlock; + protected static void reset() { + lastBlock = null; + } + + //dojo cwords: + //-189 99 -580 + //-223 99 -614 + + public static void blockUpdate(BlockUpdateS2CPacket packet) { + if (DojoManager.currentChallenge == DojoManager.DojoChallenges.SWIFTNESS) { + if (packet.getState().isOf(Blocks.LIME_WOOL)) { + lastBlock = packet.getPos(); + } + } + } protected static void render(WorldRenderContext context) { + if (DojoManager.currentChallenge != DojoManager.DojoChallenges.SWIFTNESS || lastBlock == null) { + return; + } + RenderHelper.renderOutline(context,new Box(lastBlock),new float[]{0f,1f,0f},3,true); } } -- cgit From b2dff8d0f292b819138a2bb118f318063568e3fe Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Apr 2024 15:26:58 +0100 Subject: add masteryTest helper create helper for the mastery challenge --- .../mixins/ClientPlayNetworkHandlerMixin.java | 3 +- .../skyblock/crimson/dojo/DojoManager.java | 12 ++++- .../skyblock/crimson/dojo/MasteryTestHelper.java | 58 ++++++++++++++++++++++ .../skyblock/crimson/dojo/SwiftnessTestHelper.java | 10 ++-- 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index feb5a1cb..b7d505f3 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -5,6 +5,7 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import com.llamalad7.mixinextras.sugar.Local; import de.hysky.skyblocker.skyblock.CompactDamage; import de.hysky.skyblocker.skyblock.FishingHelper; +import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.crimson.dojo.SwiftnessTestHelper; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; @@ -51,7 +52,7 @@ public abstract class ClientPlayNetworkHandlerMixin { } } if (Utils.getLocation() == Location.CRIMSON_ISLE) { - SwiftnessTestHelper.blockUpdate(packet); + DojoManager.onBlockUpdate(packet); } } 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 index 8e8482ea..b3796841 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -8,6 +8,7 @@ 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.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.text.Text; import net.minecraft.world.updater.WorldUpdater; @@ -23,6 +24,7 @@ public class DojoManager { protected enum DojoChallenges { NONE("none"), + MASTERY("Mastery"), DISCIPLINE("Discipline"), SWIFTNESS("Swiftness"), TENACITY("Tenacity"); @@ -55,11 +57,11 @@ public class DojoManager { inAreana = false; currentChallenge = DojoChallenges.NONE; SwiftnessTestHelper.reset(); + MasteryTestHelper.reset(); } private static void onMessage(Text text, Boolean overlay) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || overlay) { return; } @@ -85,6 +87,13 @@ public class DojoManager { } } + public static void onBlockUpdate(BlockUpdateS2CPacket packet) { + switch (currentChallenge) { + case SWIFTNESS -> SwiftnessTestHelper.onBlockUpdate(packet); + case MASTERY -> MasteryTestHelper.onBlockUpdate(packet); + } + } + private static void update() { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { return; @@ -98,6 +107,7 @@ public class DojoManager { switch (currentChallenge) { case SWIFTNESS -> SwiftnessTestHelper.render(context); case TENACITY -> TenacityTestHelper.render(context); + case MASTERY -> MasteryTestHelper.render(context); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java new file mode 100644 index 00000000..85fd5e1c --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java @@ -0,0 +1,58 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import de.hysky.skyblocker.utils.render.RenderHelper; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.block.Blocks; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +import java.text.DecimalFormat; +import java.util.*; + +public class MasteryTestHelper { + + private static final float[] LIGHT_GRAY = { 192 / 255f, 192 / 255f, 192 / 255f }; + private static final DecimalFormat FORMATTER = new DecimalFormat("0.00"); + + private static List blockOrder = new ArrayList<>(); + private static Map endTimes =new HashMap<>(); + + protected static void reset() { + blockOrder = new ArrayList<>(); + endTimes =new HashMap<>(); + } + + + public static void onBlockUpdate(BlockUpdateS2CPacket packet) { + BlockPos pos = packet.getPos(); + if (packet.getState().isOf(Blocks.LIME_WOOL)) { + blockOrder.add(pos); + endTimes.put(pos,System.currentTimeMillis()+6850); + } + if (packet.getState().isAir()) { + blockOrder.remove(pos); + } + } + + protected static void render(WorldRenderContext context) { + //render connecting lines + if (!blockOrder.isEmpty()) { + RenderHelper.renderLineFromCursor(context, blockOrder.getFirst().toCenterPos(),LIGHT_GRAY,1f, 2); + } + if (blockOrder.size() >= 2) { + RenderHelper.renderLinesFromPoints(context, new Vec3d[]{blockOrder.get(0).toCenterPos(), blockOrder.get(1).toCenterPos()}, new float[]{0f, 1f, 0f}, 1, 2, false); + } + + //render times + long currentTime = System.currentTimeMillis(); + for (BlockPos pos : blockOrder) { + long blockEndTime = endTimes.get(pos); + float secondsTime = Math.max((blockEndTime - currentTime) / 1000f, 0); + RenderHelper.renderText(context, Text.literal(FORMATTER.format(secondsTime)), pos.add(0, 1, 0).toCenterPos(), 3, true); + + } + + } +} 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 index d2a9ae57..5d5f3bab 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/SwiftnessTestHelper.java @@ -22,16 +22,14 @@ public class SwiftnessTestHelper { //-189 99 -580 //-223 99 -614 - public static void blockUpdate(BlockUpdateS2CPacket packet) { - if (DojoManager.currentChallenge == DojoManager.DojoChallenges.SWIFTNESS) { - if (packet.getState().isOf(Blocks.LIME_WOOL)) { - lastBlock = packet.getPos(); - } + public static void onBlockUpdate(BlockUpdateS2CPacket packet) { + if (packet.getState().isOf(Blocks.LIME_WOOL)) { + lastBlock = packet.getPos(); } } protected static void render(WorldRenderContext context) { - if (DojoManager.currentChallenge != DojoManager.DojoChallenges.SWIFTNESS || lastBlock == null) { + if (lastBlock == null) { return; } RenderHelper.renderOutline(context,new Box(lastBlock),new float[]{0f,1f,0f},3,true); -- cgit From 472af1f8dd2ece6a4cc9ba81534f973780978394 Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Apr 2024 21:12:40 +0100 Subject: add tenacity helper added helper for tenacity however there seems to be randomness so can not highlight block its going to hit --- .../skyblock/crimson/dojo/DojoManager.java | 30 +++++++---- .../skyblock/crimson/dojo/MasteryTestHelper.java | 9 ++-- .../skyblock/crimson/dojo/TenacityTestHelper.java | 58 ++++++++++++++++++++++ 3 files changed, 84 insertions(+), 13 deletions(-) (limited to 'src/main/java') 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 index b3796841..7b7b7a3b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -1,16 +1,16 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; -import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.utils.Location; import de.hysky.skyblocker.utils.Utils; -import de.hysky.skyblocker.utils.scheduler.Scheduler; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents; 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.client.world.ClientWorld; +import net.minecraft.entity.Entity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.text.Text; -import net.minecraft.world.updater.WorldUpdater; import java.util.Arrays; import java.util.regex.Matcher; @@ -46,21 +46,19 @@ public class DojoManager { public static void init() { ClientReceiveMessageEvents.GAME.register(DojoManager::onMessage); WorldRenderEvents.AFTER_TRANSLUCENT.register(DojoManager::render); - Scheduler.INSTANCE.scheduleCyclic(DojoManager::update, 5); ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); - + ClientEntityEvents.ENTITY_LOAD.register(DojoManager::onEntitySpawn); + ClientEntityEvents.ENTITY_UNLOAD.register(DojoManager::onEntityDespawn); } - - private static void reset() { inAreana = false; currentChallenge = DojoChallenges.NONE; SwiftnessTestHelper.reset(); MasteryTestHelper.reset(); + TenacityTestHelper.reset(); } - private static void onMessage(Text text, Boolean overlay) { if (Utils.getLocation() != Location.CRIMSON_ISLE || overlay) { return; @@ -88,16 +86,30 @@ public class DojoManager { } public static void onBlockUpdate(BlockUpdateS2CPacket packet) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + return; + } switch (currentChallenge) { case SWIFTNESS -> SwiftnessTestHelper.onBlockUpdate(packet); case MASTERY -> MasteryTestHelper.onBlockUpdate(packet); } } + private static void onEntitySpawn(Entity entity, ClientWorld clientWorld) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + return; + } + switch (currentChallenge) { + case TENACITY -> TenacityTestHelper.onEntitySpawn(entity); + } + } - private static void update() { + private static void onEntityDespawn(Entity entity, ClientWorld clientWorld) { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { return; } + switch (currentChallenge) { + case TENACITY -> TenacityTestHelper.onEntityDespawn(entity); + } } private static void render(WorldRenderContext context) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java index 85fd5e1c..2bbe4255 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/MasteryTestHelper.java @@ -16,12 +16,12 @@ public class MasteryTestHelper { private static final float[] LIGHT_GRAY = { 192 / 255f, 192 / 255f, 192 / 255f }; private static final DecimalFormat FORMATTER = new DecimalFormat("0.00"); - private static List blockOrder = new ArrayList<>(); - private static Map endTimes =new HashMap<>(); + private static final List blockOrder = new ArrayList<>(); + private static final Map endTimes =new HashMap<>(); protected static void reset() { - blockOrder = new ArrayList<>(); - endTimes =new HashMap<>(); + blockOrder.clear(); + endTimes.clear(); } @@ -33,6 +33,7 @@ public class MasteryTestHelper { } if (packet.getState().isAir()) { blockOrder.remove(pos); + endTimes.remove(pos); } } 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 index 48c1aaa0..dd975625 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java @@ -1,11 +1,69 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; +import de.hysky.skyblocker.utils.render.RenderHelper; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.block.Blocks; +import net.minecraft.entity.Entity; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Vec3d; + +import java.util.*; public class TenacityTestHelper { + private static final Map> fireBallsWithStartPos = new HashMap<>(); + + private static int floorY = 98; //todo is there multiple y levels + + protected static void reset() { + fireBallsWithStartPos.clear(); + } + + protected static void render(WorldRenderContext context) { + for (ArmorStandEntity fireball : fireBallsWithStartPos.keySet()) { + List linePositions = fireBallsWithStartPos.get(fireball); + Vec3d fireballPos = getCoalOffset(fireball.getPos()); + if (linePositions.getFirst().distanceTo(fireballPos) < 0.5 ) { //just spawned can not find line yet + continue; + } + if (linePositions.size() < 2) { + //calculate line for fireball and add it to its line values + double changeY = linePositions.getFirst().y - fireballPos.y; + double multipleToGround = (linePositions.getFirst().y - floorY) / changeY; + Vec3d distance = fireballPos.subtract(linePositions.getFirst()).multiply(multipleToGround); + Vec3d lineEnd = linePositions.getFirst().add(distance); + linePositions.add(lineEnd); + } + RenderHelper.renderLinesFromPoints(context, new Vec3d[]{linePositions.get(0), linePositions.get(1)},new float[]{1f, 0f, 0f}, 1, 3, false); + //could outline block to be broken but seems to have some random pattern so not usefull + } + + } + + public static void onEntitySpawn(Entity entity) { + if (entity instanceof ArmorStandEntity armorStand) { + //todo they should be holding coal block but are not holding anything + List lineBlocks = new ArrayList<>(); + lineBlocks.add(getCoalOffset(armorStand.getPos())); + fireBallsWithStartPos.put(armorStand,lineBlocks); + } + + } + public static void onEntityDespawn(Entity entity) { + if (entity instanceof ArmorStandEntity armorStand) { + fireBallsWithStartPos.remove(entity); + } } + + private static Vec3d getCoalOffset(Vec3d pos) { + return pos.add(0,1,0); + } + } -- cgit From 468a8391dc8964811159ba529b5397f1d7162fa8 Mon Sep 17 00:00:00 2001 From: olim Date: Tue, 30 Apr 2024 21:14:51 +0100 Subject: simplify code do not bother trying to work out exact block as it seems to be random --- .../hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/main/java') 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 index dd975625..d3b0b9a0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java @@ -17,8 +17,7 @@ public class TenacityTestHelper { private static final Map> fireBallsWithStartPos = new HashMap<>(); - - private static int floorY = 98; //todo is there multiple y levels + protected static void reset() { fireBallsWithStartPos.clear(); @@ -34,9 +33,7 @@ public class TenacityTestHelper { } if (linePositions.size() < 2) { //calculate line for fireball and add it to its line values - double changeY = linePositions.getFirst().y - fireballPos.y; - double multipleToGround = (linePositions.getFirst().y - floorY) / changeY; - Vec3d distance = fireballPos.subtract(linePositions.getFirst()).multiply(multipleToGround); + Vec3d distance = fireballPos.subtract(linePositions.getFirst()).multiply(100); Vec3d lineEnd = linePositions.getFirst().add(distance); linePositions.add(lineEnd); } -- cgit From 18e3b77939d726e2aedfddfda76f488c864bbe94 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 1 May 2024 16:12:31 +0100 Subject: fix tenacity helper rework tenacity helper to use particals to work out randomness and fix to be mainly accurate --- .../mixins/ClientPlayNetworkHandlerMixin.java | 2 +- .../skyblock/crimson/dojo/DojoManager.java | 12 +++ .../skyblock/crimson/dojo/TenacityTestHelper.java | 92 +++++++++++++++------- 3 files changed, 77 insertions(+), 29 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java index b7d505f3..454d3fb2 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/ClientPlayNetworkHandlerMixin.java @@ -6,7 +6,6 @@ import com.llamalad7.mixinextras.sugar.Local; import de.hysky.skyblocker.skyblock.CompactDamage; import de.hysky.skyblocker.skyblock.FishingHelper; import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; -import de.hysky.skyblocker.skyblock.crimson.dojo.SwiftnessTestHelper; import de.hysky.skyblocker.skyblock.dungeon.DungeonScore; import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager; import de.hysky.skyblocker.skyblock.end.BeaconHighlighter; @@ -102,6 +101,7 @@ public abstract class ClientPlayNetworkHandlerMixin { @Inject(method = "onParticle", at = @At("RETURN")) private void skyblocker$onParticle(ParticleS2CPacket packet, CallbackInfo ci) { MythologicalRitual.onParticle(packet); + DojoManager.onParticle(packet); EnderNodes.onParticle(packet); } 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 index 7b7b7a3b..b7b39f32 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.text.Text; import java.util.Arrays; @@ -22,6 +23,7 @@ public class DojoManager { private static final Pattern TEST_OF_PATTERN = Pattern.compile("\\s+Test of (\\w+) OBJECTIVES"); private static final String CHALLENGE_FINISHED_REGEX = "\\s+CHALLENGE ((COMPLETED)|(FAILED))"; + protected enum DojoChallenges { NONE("none"), MASTERY("Mastery"), @@ -49,6 +51,7 @@ public class DojoManager { ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); ClientEntityEvents.ENTITY_LOAD.register(DojoManager::onEntitySpawn); ClientEntityEvents.ENTITY_UNLOAD.register(DojoManager::onEntityDespawn); + } private static void reset() { @@ -112,6 +115,15 @@ public class DojoManager { } } + public static void onParticle(ParticleS2CPacket packet) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + return; + } + switch (currentChallenge) { + case TENACITY -> TenacityTestHelper.onParticle(packet); + } + } + private static void render(WorldRenderContext context) { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { return; 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 index d3b0b9a0..3639c351 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/TenacityTestHelper.java @@ -2,65 +2,101 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; import de.hysky.skyblocker.utils.render.RenderHelper; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; -import net.minecraft.block.Blocks; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.entity.decoration.ArmorStandEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Box; +import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RaycastContext; import java.util.*; public class TenacityTestHelper { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); - private static final Map> fireBallsWithStartPos = new HashMap<>(); - + private static final Map fireBallsWithStartPos = new HashMap<>(); + + private static final Map particleOffsets = new HashMap<>(); protected static void reset() { fireBallsWithStartPos.clear(); + particleOffsets.clear(); } protected static void render(WorldRenderContext context) { for (ArmorStandEntity fireball : fireBallsWithStartPos.keySet()) { - List linePositions = fireBallsWithStartPos.get(fireball); - Vec3d fireballPos = getCoalOffset(fireball.getPos()); - if (linePositions.getFirst().distanceTo(fireballPos) < 0.5 ) { //just spawned can not find line yet - continue; - } - if (linePositions.size() < 2) { - //calculate line for fireball and add it to its line values - Vec3d distance = fireballPos.subtract(linePositions.getFirst()).multiply(100); - Vec3d lineEnd = linePositions.getFirst().add(distance); - linePositions.add(lineEnd); + Vec3d lineStart = fireBallsWithStartPos.get(fireball).add(particleOffsets.getOrDefault(fireball, Vec3d.ZERO)); + Vec3d fireballPos = fireball.getPos().add(particleOffsets.getOrDefault(fireball, Vec3d.ZERO)); + + Vec3d distance = fireballPos.subtract(lineStart); + if (distance.length() > 0.02) { //if big enough gap try from start calculate and show trajectory + distance = distance.multiply(100); + Vec3d lineEnd = lineStart.add(distance); + + RenderHelper.renderLinesFromPoints(context, new Vec3d[]{lineStart, lineEnd},new float[]{1f, 0f, 0f}, 1, 3, false); + + //get highlighted block + HitResult hitResult = raycast(lineStart, lineEnd, fireball); + if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK && hitResult instanceof BlockHitResult blockHitResult) { + RenderHelper.renderFilled(context, blockHitResult.getBlockPos(),new float[]{1f, 0f, 0f}, 0.5f, false); + } } - RenderHelper.renderLinesFromPoints(context, new Vec3d[]{linePositions.get(0), linePositions.get(1)},new float[]{1f, 0f, 0f}, 1, 3, false); - //could outline block to be broken but seems to have some random pattern so not usefull } + } + public static HitResult raycast(Vec3d start, Vec3d end, ArmorStandEntity fireball) { + if (CLIENT == null || CLIENT.world == null) { + return null; + } + return CLIENT.world.raycast(new RaycastContext(start, end, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.ANY, fireball)); } public static void onEntitySpawn(Entity entity) { + if (CLIENT == null || CLIENT.player == null) { + return; + } if (entity instanceof ArmorStandEntity armorStand) { - //todo they should be holding coal block but are not holding anything - List lineBlocks = new ArrayList<>(); - lineBlocks.add(getCoalOffset(armorStand.getPos())); - fireBallsWithStartPos.put(armorStand,lineBlocks); + Vec3d fireballPos = armorStand.getPos(); + Vec3d playerPos = armorStand.getPos(); + // they should be holding coal block but are not holding anything idk just check they are close enough to the player + if (fireballPos.distanceTo(playerPos) < 50 && Math.abs(fireballPos.y - playerPos.y) < 5){ + fireBallsWithStartPos.put(armorStand,armorStand.getPos()); + } } - } public static void onEntityDespawn(Entity entity) { if (entity instanceof ArmorStandEntity armorStand) { - fireBallsWithStartPos.remove(entity); + fireBallsWithStartPos.remove(armorStand); } } - private static Vec3d getCoalOffset(Vec3d pos) { - return pos.add(0,1,0); + public static void onParticle(ParticleS2CPacket packet) { + if (!ParticleTypes.FLAME.equals(packet.getParameters().getType())) { + return; + } + //get nearest fireball to particle + Vec3d particlePos = new Vec3d(packet.getX(), packet.getY(), packet.getZ()); + ArmorStandEntity neareastFireball = null; + double clostestDistance = 50; + for (ArmorStandEntity fireball : fireBallsWithStartPos.keySet()) { + double distance = fireball.getPos().distanceTo(particlePos); + if (distance < clostestDistance) { + neareastFireball = fireball; + clostestDistance = distance; + } + } + if (neareastFireball == null) { //can not find fireball near particle + return; + } + //adjust fireball offset with particle pos + Vec3d delta = particlePos.subtract(neareastFireball.getPos()); + //update values + particleOffsets.put(neareastFireball, delta); } - } -- cgit From 654b66e62bdb63a2ef3dc9607c941027c6c07812 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 1 May 2024 17:03:56 +0100 Subject: add force test helpder add helper for the force test. unsure if timer is correct. sometimes last to long? --- .../crimson/dojo/DisciplineTestHelper.java | 22 ++++++--- .../skyblock/crimson/dojo/DojoManager.java | 49 ++++++++++++++----- .../skyblock/crimson/dojo/ForceTestHelper.java | 55 ++++++++++++++++++++++ .../hysky/skyblocker/skyblock/entity/MobGlow.java | 6 +-- 4 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java (limited to 'src/main/java') 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 index d5e19f28..6312bbdc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DisciplineTestHelper.java @@ -1,17 +1,23 @@ 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.entity.mob.ZombieEntity; import net.minecraft.util.Util; -import java.awt.*; +import java.text.DecimalFormat; import java.util.HashMap; +import java.util.Map; public class DisciplineTestHelper { private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final DecimalFormat FORMATTER = new DecimalFormat("0.0"); + + private static final Map zombies = new HashMap<>(); + + protected static void reset() { + zombies.clear(); + } private static final HashMap SWORD_TO_NAME_LOOKUP = Util.make(new HashMap<>(), map -> { map.put("WOOD_SWORD","Wood"); @@ -26,8 +32,8 @@ public class DisciplineTestHelper { map.put("DIAMOND_SWORD",0x00ffff); }); - public static boolean isCorrect(String name) { - if (DojoManager.currentChallenge != DojoManager.DojoChallenges.DISCIPLINE || CLIENT == null || CLIENT.player == null) { + protected static boolean shouldGlow(String name) { + if (CLIENT == null || CLIENT.player == null) { return false; } String heldId = ItemTooltip.getInternalNameFromNBT(CLIENT.player.getMainHandStack(), true); @@ -38,7 +44,7 @@ public class DisciplineTestHelper { return false; } - public static int getColor() { + protected static int getColor() { if (DojoManager.currentChallenge != DojoManager.DojoChallenges.DISCIPLINE || CLIENT == null || CLIENT.player == null) { return 0; } @@ -48,4 +54,6 @@ public class DisciplineTestHelper { } 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 index b7b39f32..61a8d010 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -26,6 +26,7 @@ public class DojoManager { protected enum DojoChallenges { NONE("none"), + FORCE("Force"), MASTERY("Mastery"), DISCIPLINE("Discipline"), SWIFTNESS("Swiftness"), @@ -43,7 +44,7 @@ public class DojoManager { } protected static DojoChallenges currentChallenge = DojoChallenges.NONE; - private static boolean inAreana = false; + public static boolean inArena = false; public static void init() { ClientReceiveMessageEvents.GAME.register(DojoManager::onMessage); @@ -55,11 +56,12 @@ public class DojoManager { } private static void reset() { - inAreana = false; + inArena = false; currentChallenge = DojoChallenges.NONE; SwiftnessTestHelper.reset(); MasteryTestHelper.reset(); TenacityTestHelper.reset(); + ForceTestHelper.reset(); } private static void onMessage(Text text, Boolean overlay) { @@ -67,10 +69,10 @@ public class DojoManager { return; } if (text.getString().equals(START_MESSAGE)) { - inAreana = true; + inArena = true; return; } - if (!inAreana) { + if (!inArena) { return; } if (text.getString().matches(CHALLENGE_FINISHED_REGEX)) { @@ -88,8 +90,30 @@ public class DojoManager { } } + public static boolean shouldGlow(String name) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + return false; + } + return switch (currentChallenge) { + case DISCIPLINE -> DisciplineTestHelper.shouldGlow(name); + case FORCE -> ForceTestHelper.shouldGlow(name); + default -> false; + }; + } + + public static int getColor() { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + return 0xf57738; + } + return switch (currentChallenge) { + case DISCIPLINE -> DisciplineTestHelper.getColor(); + case FORCE -> ForceTestHelper.getColor(); + default -> 0xf57738; + }; + } + public static void onBlockUpdate(BlockUpdateS2CPacket packet) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } switch (currentChallenge) { @@ -98,37 +122,40 @@ public class DojoManager { } } private static void onEntitySpawn(Entity entity, ClientWorld clientWorld) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } switch (currentChallenge) { case TENACITY -> TenacityTestHelper.onEntitySpawn(entity); + case FORCE -> ForceTestHelper.onEntitySpawn(entity); } } private static void onEntityDespawn(Entity entity, ClientWorld clientWorld) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } switch (currentChallenge) { case TENACITY -> TenacityTestHelper.onEntityDespawn(entity); + case FORCE -> ForceTestHelper.onEntityDespawn(entity); } } public static void onParticle(ParticleS2CPacket packet) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } - switch (currentChallenge) { - case TENACITY -> TenacityTestHelper.onParticle(packet); + if (currentChallenge == DojoChallenges.TENACITY) { + TenacityTestHelper.onParticle(packet); } } private static void render(WorldRenderContext context) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inAreana) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; } switch (currentChallenge) { + case FORCE -> ForceTestHelper.render(context); case SWIFTNESS -> SwiftnessTestHelper.render(context); case TENACITY -> TenacityTestHelper.render(context); case MASTERY -> MasteryTestHelper.render(context); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java new file mode 100644 index 00000000..bf27ce1f --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java @@ -0,0 +1,55 @@ +package de.hysky.skyblocker.skyblock.crimson.dojo; + +import de.hysky.skyblocker.utils.render.RenderHelper; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.mob.ZombieEntity; +import net.minecraft.text.Text; +import net.minecraft.util.math.Vec3d; + +import java.awt.*; +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.Map; + +public class ForceTestHelper { + + private static final DecimalFormat FORMATTER = new DecimalFormat("0.0"); + + private static final Map zombies = new HashMap<>(); + + protected static void reset() { + zombies.clear(); + } + + protected static boolean shouldGlow(String name) { + if (name == null) return false; + return name.contains("-"); + } + + protected static int getColor() { + return Color.RED.getRGB(); + } + + protected static void onEntitySpawn(Entity entity) { + if (entity instanceof ZombieEntity zombie) { + zombies.put(zombie, System.currentTimeMillis() + 10100); //they last for 10100 millis ish so this is the time they despawn + } + } + protected static void onEntityDespawn(Entity entity) { + if (entity instanceof ZombieEntity zombie) { + zombies.remove(zombie); + } + } + + protected static void render(WorldRenderContext context) { + //render times + long currentTime = System.currentTimeMillis(); + for (Map.Entry zombie : zombies.entrySet()) { + float secondsTime = Math.max((zombie.getValue() - currentTime) / 1000f, 0); + Vec3d lablePos = zombie.getKey().getEyePos(); + RenderHelper.renderText(context, Text.literal(FORMATTER.format(secondsTime)), lablePos, 1.5f, true); + + } + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java index d373d2e1..182fae77 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/entity/MobGlow.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.entity; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.crimson.dojo.DisciplineTestHelper; +import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager; import de.hysky.skyblocker.skyblock.dungeon.LividColor; import de.hysky.skyblocker.skyblock.end.TheEnd; import de.hysky.skyblocker.utils.ItemUtils; @@ -63,7 +63,7 @@ public class MobGlow { case EndermanEntity enderman when Utils.isInTheEnd() && !entity.isInvisible() -> TheEnd.isSpecialZealot(enderman); //dojo - case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE -> DisciplineTestHelper.isCorrect(getArmourStandName(zombie)); + case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE && DojoManager.inArena -> DojoManager.shouldGlow(getArmourStandName(zombie)); default -> false; }; @@ -109,7 +109,7 @@ public class MobGlow { case EndermanEntity enderman when TheEnd.isSpecialZealot(enderman) -> Formatting.RED.getColorValue(); case ArmorStandEntity armorStand when isNukekubiHead(armorStand) -> 0x990099; - case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE -> DisciplineTestHelper.getColor(); + case ZombieEntity zombie when Utils.getLocation() == Location.CRIMSON_ISLE && DojoManager.inArena -> DojoManager.getColor(); default -> 0xf57738; }; -- cgit From d23f2f42e9fc57e06341a372c319fec54f510899 Mon Sep 17 00:00:00 2001 From: olim Date: Wed, 1 May 2024 19:21:59 +0100 Subject: clean up and fix force test when mob is hit in force reset timer --- .../skyblock/crimson/dojo/DojoManager.java | 25 ++++++++++++++++++- .../skyblock/crimson/dojo/ForceTestHelper.java | 28 ++++++++++++++++++++-- .../skyblock/crimson/dojo/TenacityTestHelper.java | 13 +++------- 3 files changed, 53 insertions(+), 13 deletions(-) (limited to 'src/main/java') 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 index 61a8d010..dd2df117 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/DojoManager.java @@ -7,11 +7,18 @@ 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.fabricmc.fabric.api.event.player.AttackEntityCallback; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.world.World; import java.util.Arrays; import java.util.regex.Matcher; @@ -19,6 +26,7 @@ import java.util.regex.Pattern; public class DojoManager { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); 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 ((COMPLETED)|(FAILED))"; @@ -52,6 +60,7 @@ public class DojoManager { ClientPlayConnectionEvents.JOIN.register((_handler, _sender, _client) -> reset()); ClientEntityEvents.ENTITY_LOAD.register(DojoManager::onEntitySpawn); ClientEntityEvents.ENTITY_UNLOAD.register(DojoManager::onEntityDespawn); + AttackEntityCallback.EVENT.register(DojoManager::onEntityAttacked); } @@ -122,7 +131,11 @@ public class DojoManager { } } private static void onEntitySpawn(Entity entity, ClientWorld clientWorld) { - if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena || CLIENT == null || CLIENT.player == null) { + return; + } + //check close by + if (entity.distanceTo(CLIENT.player) > 50 || Math.abs(entity.getBlockY() - CLIENT.player.getBlockY()) > 5){ return; } switch (currentChallenge) { @@ -141,6 +154,16 @@ public class DojoManager { } } + private static ActionResult onEntityAttacked(PlayerEntity playerEntity, World world, Hand hand, Entity entity, EntityHitResult entityHitResult) { + if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { + return null; + } + switch (currentChallenge) { + case FORCE -> ForceTestHelper.onEntityAttacked(entity); + } + return ActionResult.PASS; + } + public static void onParticle(ParticleS2CPacket packet) { if (Utils.getLocation() != Location.CRIMSON_ISLE || !inArena) { return; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java index bf27ce1f..c709f64a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/crimson/dojo/ForceTestHelper.java @@ -2,9 +2,11 @@ package de.hysky.skyblocker.skyblock.crimson.dojo; import de.hysky.skyblocker.utils.render.RenderHelper; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.math.Vec3d; import java.awt.*; @@ -36,9 +38,19 @@ public class ForceTestHelper { zombies.put(zombie, System.currentTimeMillis() + 10100); //they last for 10100 millis ish so this is the time they despawn } } + + protected static void onEntityAttacked(Entity entity) { + if (entity instanceof ZombieEntity zombie) { + if (zombies.containsKey(zombie)) {