aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker')
-rw-r--r--src/main/java/de/hysky/skyblocker/SkyblockerMod.java1
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java88
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/Resettable.java15
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/chat/ChatMessageListener.java2
5 files changed, 87 insertions, 25 deletions
diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
index 0dc1b409..e6b2d25a 100644
--- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
+++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java
@@ -167,6 +167,7 @@ public class SkyblockerMod implements ClientModInitializer {
ItemProtection.init();
CreeperBeams.init();
Boulder.init();
+ ThreeWeirdos.init();
VisitorHelper.init();
ItemRarityBackgrounds.init();
MuseumItemCache.init();
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
index f5e0461d..42034d9f 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/DungeonPuzzle.java
@@ -6,6 +6,7 @@ import de.hysky.skyblocker.events.DungeonEvents;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.dungeon.secrets.Room;
import de.hysky.skyblocker.utils.Constants;
+import de.hysky.skyblocker.utils.Resettable;
import de.hysky.skyblocker.utils.Tickable;
import de.hysky.skyblocker.utils.render.Renderable;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
@@ -16,7 +17,7 @@ import java.util.Set;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
-public abstract class DungeonPuzzle implements Tickable, Renderable {
+public abstract class DungeonPuzzle implements Tickable, Renderable, Resettable {
protected final String puzzleName;
@NotNull
private final Set<String> roomNames;
@@ -46,13 +47,14 @@ public abstract class DungeonPuzzle implements Tickable, Renderable {
}
return Command.SINGLE_SUCCESS;
})))))));
- ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> reset());
+ ClientPlayConnectionEvents.JOIN.register(this);
}
public boolean shouldSolve() {
return shouldSolve;
}
+ @Override
public void reset() {
shouldSolve = false;
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
index 30119204..98d32c68 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdos.java
@@ -1,39 +1,85 @@
package de.hysky.skyblocker.skyblock.dungeon.puzzle;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.chat.ChatFilterResult;
-import de.hysky.skyblocker.utils.chat.ChatPatternListener;
+import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
+import de.hysky.skyblocker.skyblock.dungeon.secrets.Room;
+import de.hysky.skyblocker.utils.render.RenderHelper;
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
+import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.text.Text;
+import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
+import net.minecraft.util.hit.HitResult;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.Box;
+import net.minecraft.world.World;
+import java.util.List;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-public class ThreeWeirdos extends ChatPatternListener {
- public ThreeWeirdos() {
- super("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest\\!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest\\!)$");
+public class ThreeWeirdos extends DungeonPuzzle {
+ protected static final Pattern PATTERN = Pattern.compile("^\\[NPC] ([A-Z][a-z]+): (?:The reward is(?: not in my chest!|n't in any of our chests\\.)|My chest (?:doesn't have the reward\\. We are all telling the truth\\.|has the reward and I'm telling the truth!)|At least one of them is lying, and the reward is not in [A-Z][a-z]+'s chest!|Both of them are telling the truth\\. Also, [A-Z][a-z]+ has the reward in their chest!)$");
+ private static final float[] GREEN_COLOR_COMPONENTS = new float[]{0, 1, 0};
+ private static BlockPos pos;
+
+ private ThreeWeirdos() {
+ super("three-weirdos", "three-chests");
+ ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
+ World world = MinecraftClient.getInstance().world;
+ if (overlay || !shouldSolve() || !SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos || world == null || !DungeonManager.isCurrentRoomMatched()) return;
+
+ @SuppressWarnings("DataFlowIssue")
+ Matcher matcher = PATTERN.matcher(Formatting.strip(message.getString()));
+ if (!matcher.matches()) return;
+ String name = matcher.group(1);
+ Room room = DungeonManager.getCurrentRoom();
+
+ checkForNPC(world, room, new BlockPos(13, 69, 24), name);
+ checkForNPC(world, room, new BlockPos(15, 69, 25), name);
+ checkForNPC(world, room, new BlockPos(17, 69, 24), name);
+ });
+ UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> {
+ if (blockHitResult.getType() == HitResult.Type.BLOCK && blockHitResult.getBlockPos().equals(pos)) {
+ pos = null;
+ }
+ return ActionResult.PASS;
+ });
}
- @Override
- public ChatFilterResult state() {
- return SkyblockerConfigManager.get().dungeons.puzzleSolvers.solveThreeWeirdos ? null : ChatFilterResult.PASS;
+ public static void init() {
+ new ThreeWeirdos();
}
- @Override
- public boolean onMatch(Text message, Matcher matcher) {
- MinecraftClient client = MinecraftClient.getInstance();
- if (client.player == null || client.world == null) return false;
- client.world.getEntitiesByClass(
+ private void checkForNPC(World world, Room room, BlockPos relative, String name) {
+ BlockPos npcPos = room.relativeToActual(relative);
+ List<ArmorStandEntity> npcs = world.getEntitiesByClass(
ArmorStandEntity.class,
- client.player.getBoundingBox().expand(3),
- entity -> {
- Text customName = entity.getCustomName();
- return customName != null && customName.getString().equals(matcher.group(1));
- }
- ).forEach(
- entity -> entity.setCustomName(Text.of(Formatting.GREEN + matcher.group(1)))
+ Box.enclosing(npcPos, npcPos),
+ entity -> entity.getName().getString().equals(name)
);
- return false;
+ if (!npcs.isEmpty()) {
+ pos = room.relativeToActual(relative.add(1, 0, 0));
+ npcs.forEach(entity -> entity.setCustomName(Text.literal(name).formatted(Formatting.GREEN)));
+ }
+ }
+
+ @Override
+ public void tick(MinecraftClient client) {}
+
+ @Override
+ public void render(WorldRenderContext context) {
+ if (shouldSolve() && pos != null) {
+ RenderHelper.renderFilled(context, pos, GREEN_COLOR_COMPONENTS, 0.5f, true);
+ }
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ pos = null;
}
}
diff --git a/src/main/java/de/hysky/skyblocker/utils/Resettable.java b/src/main/java/de/hysky/skyblocker/utils/Resettable.java
new file mode 100644
index 00000000..d16a316b
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/utils/Resettable.java
@@ -0,0 +1,15 @@
+package de.hysky.skyblocker.utils;
+
+import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
+import net.fabricmc.fabric.api.networking.v1.PacketSender;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.network.ClientPlayNetworkHandler;
+
+public interface Resettable extends ClientPlayConnectionEvents.Join {
+ void reset();
+
+ @Override
+ default void onPlayReady(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client) {
+ reset();
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/utils/chat/ChatMessageListener.java b/src/main/java/de/hysky/skyblocker/utils/chat/ChatMessageListener.java
index 1f0caff5..f6195171 100644
--- a/src/main/java/de/hysky/skyblocker/utils/chat/ChatMessageListener.java
+++ b/src/main/java/de/hysky/skyblocker/utils/chat/ChatMessageListener.java
@@ -3,7 +3,6 @@ package de.hysky.skyblocker.utils.chat;
import de.hysky.skyblocker.skyblock.barn.HungryHiker;
import de.hysky.skyblocker.skyblock.barn.TreasureHunter;
import de.hysky.skyblocker.skyblock.dungeon.Reparty;
-import de.hysky.skyblocker.skyblock.dungeon.puzzle.ThreeWeirdos;
import de.hysky.skyblocker.skyblock.dungeon.puzzle.Trivia;
import de.hysky.skyblocker.skyblock.dwarven.Fetchur;
import de.hysky.skyblocker.skyblock.dwarven.Puzzler;
@@ -40,7 +39,6 @@ public interface ChatMessageListener {
new Fetchur(),
new Puzzler(),
new Reparty(),
- new ThreeWeirdos(),
new Trivia(),
new TreasureHunter(),
new HungryHiker(),