From b457087a8150600722341feacbbd69917083e759 Mon Sep 17 00:00:00 2001 From: ImproperIssues <114215797+ItziSpyder@users.noreply.github.com> Date: Wed, 7 Aug 2024 01:59:44 -0700 Subject: [PATCH] fixed bug with entity_in_range command, added post_tick and pre_tick --- README.md | 12 ++++++++++-- .../client/clickscript/ScriptParser.java | 6 +++--- .../modules/modules/ScriptedModule.java | 17 ++++++++++++++++- .../modules/scripts/syntax/OnEventCmd.java | 4 ++++ .../util/minecraft/EntityUtils.java | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7f537fbc..3d5cedb3 100644 --- a/README.md +++ b/README.md @@ -47,15 +47,23 @@ Version: 1.2.7 Tweaks: - change clickcrystals script on tick to pretick so it doesnt flag post - - rewrite potion hud # i no one + - rewrite armor hud # i no one Add: - pull and merge PR from I-No-One - - Teams module # i no one + - added Teams module # i no one + - added FreeLook Module # i no one + - added AutoDisconnect Module # i no one Scripting: - add script command if entity pos - increased the range for entity selection from 32 to 128 + - add on post_tick + - add on pre_tick + +Patches: + - entity_in_range not working + - block ID selections with commas not working properly ``` ![demo](https://cdn.modrinth.com/data/YDYPZdGj/images/d4ad4320aaf5d8589829e3d1691ec5755422a778.png) diff --git a/src/main/java/io/github/itzispyder/clickcrystals/client/clickscript/ScriptParser.java b/src/main/java/io/github/itzispyder/clickcrystals/client/clickscript/ScriptParser.java index 13e2f499..f8660447 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/client/clickscript/ScriptParser.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/client/clickscript/ScriptParser.java @@ -238,13 +238,13 @@ public static Predicate parseBlockPredicate(String arg) { } else if (section.startsWith(":")) { String subArg = section.substring(1); - if (defaultedBlockPredicates.containsKey(subArg)) { - return defaultedBlockPredicates.get(subArg); + list.add(defaultedBlockPredicates.get(subArg)); + continue; } Identifier id = Identifier.of("minecraft", subArg); - return block -> block.getBlock() == Registries.BLOCK.get(id); + list.add(block -> block.getBlock() == Registries.BLOCK.get(id)); } else { list.add(block -> false); diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/ScriptedModule.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/ScriptedModule.java index 00b17d6d..10da183d 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/ScriptedModule.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/modules/ScriptedModule.java @@ -3,6 +3,7 @@ import io.github.itzispyder.clickcrystals.client.clickscript.ClickScript; import io.github.itzispyder.clickcrystals.client.networking.EntityStatusType; import io.github.itzispyder.clickcrystals.data.Config; +import io.github.itzispyder.clickcrystals.events.Event; import io.github.itzispyder.clickcrystals.events.EventHandler; import io.github.itzispyder.clickcrystals.events.events.client.*; import io.github.itzispyder.clickcrystals.events.events.networking.GameJoinEvent; @@ -33,7 +34,9 @@ public class ScriptedModule extends ListenerModule { public final List clickListeners = new ArrayList<>(); public final List keyListeners = new ArrayList<>(); public final List moveListeners = new ArrayList<>(); + public final List preTickListeners = new ArrayList<>(); public final List tickListeners = new ArrayList<>(); + public final List postTickListeners = new ArrayList<>(); public final List blockPlaceListeners = new ArrayList<>(); public final List blockBreakListeners = new ArrayList<>(); public final List blockPunchListeners = new ArrayList<>(); @@ -74,7 +77,9 @@ public void clearListeners() { clickListeners.clear(); keyListeners.clear(); moveListeners.clear(); + preTickListeners.clear(); tickListeners.clear(); + postTickListeners.clear(); totemPopListeners.clear(); moduleEnableListeners.clear(); @@ -105,11 +110,21 @@ public void onMouseClick(MouseClickEvent e) { @EventHandler public void onTick(ClientTickStartEvent e) { + for (TickListener l : preTickListeners) { + l.pass(e); + } for (TickListener l : tickListeners) { l.pass(e); } } + @EventHandler + public void onPostTick(ClientTickEndEvent e) { + for (TickListener l : postTickListeners) { + l.pass(e); + } + } + @EventHandler public void onBlockPlace(BlockPlaceEvent e) { for (BlockPlaceListener l : blockPlaceListeners) { @@ -225,7 +240,7 @@ public interface ClickListener { @FunctionalInterface public interface TickListener { - void pass(ClientTickStartEvent e); + void pass(Event e); } @FunctionalInterface diff --git a/src/main/java/io/github/itzispyder/clickcrystals/modules/scripts/syntax/OnEventCmd.java b/src/main/java/io/github/itzispyder/clickcrystals/modules/scripts/syntax/OnEventCmd.java index f5a95d78..629480de 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/modules/scripts/syntax/OnEventCmd.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/modules/scripts/syntax/OnEventCmd.java @@ -45,7 +45,9 @@ public void onCommand(ScriptCommand command, String line, ScriptArgs args) { case MOVE_LOOK, MOVE_POS -> passMove(args, type); case CHAT_SEND, CHAT_RECEIVE -> passChat(args, type); + case PRE_TICK -> ModuleCmd.runOnCurrentScriptModule(m -> m.preTickListeners.add(event -> exc(args, 1))); case TICK -> ModuleCmd.runOnCurrentScriptModule(m -> m.tickListeners.add(event -> exc(args, 1))); + case POST_TICK -> ModuleCmd.runOnCurrentScriptModule(m -> m.postTickListeners.add(event -> exc(args, 1))); case ITEM_USE -> ModuleCmd.runOnCurrentScriptModule(m -> m.itemUseListeners.add(event -> exc(args, 1))); case ITEM_CONSUME -> ModuleCmd.runOnCurrentScriptModule(m -> m.itemConsumeListeners.add(event -> exc(args, 1))); case MODULE_ENABLE -> ModuleCmd.runOnCurrentScriptModule(m -> m.moduleEnableListeners.add(() -> exc(args, 1))); @@ -277,7 +279,9 @@ public enum EventType { BREAK_BLOCK, PUNCH_BLOCK, INTERACT_BLOCK, + PRE_TICK, TICK, + POST_TICK, ITEM_USE, ITEM_CONSUME, TOTEM_POP, diff --git a/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java b/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java index b2f34547..822e68b6 100644 --- a/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java +++ b/src/main/java/io/github/itzispyder/clickcrystals/util/minecraft/EntityUtils.java @@ -125,7 +125,7 @@ private static HitResult ensureTargetInRange(HitResult hitResult, Vec3d cameraPo public static Entity getNearestEntity(Entity ref, double range, Predicate filter) { Vec3d at = ref.getPos(); List candidates = ref.getWorld() - .getOtherEntities(PlayerUtils.player(), Box.from(at).expand(range), ent -> ent != ref && filter.test(ref)).stream() + .getOtherEntities(PlayerUtils.player(), Box.from(at).expand(range), ent -> ent != ref && filter.test(ent)).stream() .sorted(Comparator.comparing(entity -> entity.getPos().distanceTo(at))) .toList();