From ae7101c490d86b76a990834bf4db38e04ddb5187 Mon Sep 17 00:00:00 2001 From: Samuel Willows Date: Sun, 24 Nov 2024 10:50:59 -0800 Subject: [PATCH] improved VisualRange.java - fixed entity checks improved AutoEZ.java - fixed major thingy --- .../org/snail/plus/modules/chat/AutoEZ.java | 57 ++++++++------- .../snail/plus/modules/chat/VisualRange.java | 71 +++++++++---------- .../snail/plus/modules/combat/webAura.java | 7 ++ .../java/org/snail/plus/utils/WorldUtils.java | 2 +- 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/snail/plus/modules/chat/AutoEZ.java b/src/main/java/org/snail/plus/modules/chat/AutoEZ.java index 2eb991f..841495e 100644 --- a/src/main/java/org/snail/plus/modules/chat/AutoEZ.java +++ b/src/main/java/org/snail/plus/modules/chat/AutoEZ.java @@ -10,7 +10,6 @@ import meteordevelopment.orbit.EventHandler; import net.minecraft.entity.player.PlayerEntity; import org.snail.plus.Addon; -import org.snail.plus.utils.CombatUtils; import org.snail.plus.utils.WorldUtils; import java.util.List; @@ -22,8 +21,8 @@ public class AutoEZ extends Module { private final Setting> messageSetting = sgGeneral.add(new StringListSetting.Builder() .name("message") - .description("Custom message to send.") - .defaultValue("") + .description("Custom message to send. placeholders: %Entity%, %Coords%") + .defaultValue("ez %Entity%, coords: %Coords%", "gg %Entity%, coords: %Coords%") .build()); private final Setting dm = sgGeneral.add(new BoolSetting.Builder() @@ -32,7 +31,12 @@ public class AutoEZ extends Module { .defaultValue(true) .build()); - private boolean sent = false; + Random random = new Random(); + boolean sentMessage = false; + Runnable reset = () -> mc.execute(() -> { + sentMessage = false; + random = new Random(); + }); public AutoEZ() { super(Addon.Snail, "Auto EZ+", "sends a custom message when a player you've killed dies"); @@ -40,42 +44,37 @@ public AutoEZ() { @Override public void onActivate() { - sent = false; + reset.run(); } @Override public void onDeactivate() { - sent = false; + reset.run(); } @EventHandler private void onTick(TickEvent.Post event) { - if (sent) { - return; - } - - for (PlayerEntity player : mc.world.getPlayers()) { - if (CombatUtils.getLastAttacker(player) == mc.player) { - sendEzMessage(player); - sent = true; - break; + mc.execute(() -> { + if (mc.player == null || mc.world == null) return; + for (PlayerEntity player : mc.world.getPlayers()) { + if ((player.isDead() && !player.equals(mc.player) && !sentMessage)) { + sendMessages(List.of(player)); + sentMessage = true; + } } - } + }); } - private void sendEzMessage(PlayerEntity player) { - List messages = messageSetting.get(); - String msg = messages.get(new Random().nextInt(messages.size())) - .replace("{victim}", WorldUtils.getName(player)) - .replace("{coords}", WorldUtils.getCoords(player)); - sendMsg(msg, dm.get(), player); - } - - private void sendMsg(String msg, boolean dm, PlayerEntity player) { - if (dm) { - ChatUtils.sendPlayerMsg("/msg " + WorldUtils.getName(player) + " " + msg); - } else { - mc.player.networkHandler.sendChatMessage(msg); + private void sendMessages(List entity) { + for (PlayerEntity player : entity) { + String message = messageSetting.get().get(random.nextInt(messageSetting.get().size())); + message = message.replace("%Entity%", player.getName().getString()); + message = message.replace("%Coords%", WorldUtils.getCoords(player)); + if (dm.get()) { + ChatUtils.sendPlayerMsg("/msg" + message); + } else { + ChatUtils.sendPlayerMsg(message); + } } } } \ No newline at end of file diff --git a/src/main/java/org/snail/plus/modules/chat/VisualRange.java b/src/main/java/org/snail/plus/modules/chat/VisualRange.java index 588fdb6..d043e87 100644 --- a/src/main/java/org/snail/plus/modules/chat/VisualRange.java +++ b/src/main/java/org/snail/plus/modules/chat/VisualRange.java @@ -7,6 +7,7 @@ import meteordevelopment.orbit.EventHandler; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.sound.SoundEvent; import org.snail.plus.Addon; import org.snail.plus.utils.WorldUtils; @@ -15,8 +16,6 @@ import java.util.List; import java.util.Random; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; public class VisualRange extends Module { @@ -39,7 +38,8 @@ public class VisualRange extends Module { private final Setting maxAmount = sgVisualRange.add(new IntSetting.Builder() .name("max-amount") .description("The cap of how many players the visual range notifies.") - .defaultValue(3) + .defaultValue(20) + .sliderRange(1, 100) .build()); private final Setting> sounds = sgVisualRange.add(new SoundEventListSetting.Builder() @@ -47,62 +47,57 @@ public class VisualRange extends Module { .description("Sounds to play when a player is spotted") .build()); public double x, y, z; - private List players; - private ExecutorService executor = Executors.newSingleThreadExecutor(); + private final List entitiesList = new ArrayList<>(); private final Random random = new Random(); + + Runnable reset = () -> mc.execute(() -> { + entitiesList.clear(); + x = 0; + y = 0; + z = 0; + }); + public VisualRange() { super(Addon.Snail, "Visual Range", "warns you when certain entities are within render distance"); } @Override public void onActivate() { - players = new ArrayList<>(); - if (executor.isShutdown() || executor.isTerminated()) { - executor = Executors.newSingleThreadExecutor(); - } + reset.run(); } @Override public void onDeactivate() { - players.clear(); - if (executor != null) { - executor.shutdown(); - } + reset.run(); } @EventHandler private void onTick(TickEvent.Post event) { - List soundList = sounds.get(); - for (Entity entity : mc.world.getEntities()) { - if (entity == mc.player) continue; - if (EntityUtils.isInRenderDistance(entity)) { - if (entities.get().contains(entity.getType()) && !players.contains(entity)) { - if (checkUuid.get() && entity.getUuid() != null) { - if (players.size() < maxAmount.get()) { - players.add(entity); - x = Math.round(entity.getX()); - y = Math.round(entity.getY()); - z = Math.round(entity.getZ()); - if (!soundList.isEmpty()) { - WorldUtils.playSound(soundList.get(random.nextInt(soundList.size())), 1.0f); + mc.execute(() -> { + if (mc.player == null || mc.world == null) return; + List soundList = sounds.get(); + for (Entity entity : mc.world.getEntities()) { + if (entity == mc.player) continue; + if (EntityUtils.isInRenderDistance(entity)) { + if (entities.get().contains(entity.getType()) && !entitiesList.contains(entity)) { + if (checkUuid.get() && entity.getUuid() != null) { + if (entitiesList.size() < maxAmount.get()) { + if (!soundList.isEmpty()) { + WorldUtils.playSound(soundList.get(random.nextInt(soundList.size())), 1.0f); + } + warning("Entity spotted %s", entity.getName().getString() + " at " + WorldUtils.getCoords((PlayerEntity) entity)); + entitiesList.add(entity); } - warning("Entity spotted %s", entity.getName().getString() + " at " + x + " " + y + " " + z); } } - } - } else { - if (checkUuid.get() && entity.getUuid() != null) { - double x = Math.round(entity.getX()); - double y = Math.round(entity.getY()); - double z = Math.round(entity.getZ()); - warning("Entity left %s", entity.getName().getString() + " last known position was " + x + " " + y + " " + z); - if (!soundList.isEmpty()) { - WorldUtils.playSound(soundList.get(random.nextInt(soundList.size())), 1.0f); + } else { + if (entities.get().contains(entity.getType()) && entitiesList.contains(entity)) { + warning("Entity left %s", entity.getName().getString() + " at " + WorldUtils.getCoords((PlayerEntity) entity)); + entitiesList.remove(entity); } - players.remove(entity); } } - } + }); } } \ No newline at end of file diff --git a/src/main/java/org/snail/plus/modules/combat/webAura.java b/src/main/java/org/snail/plus/modules/combat/webAura.java index 1c95005..d0564aa 100644 --- a/src/main/java/org/snail/plus/modules/combat/webAura.java +++ b/src/main/java/org/snail/plus/modules/combat/webAura.java @@ -217,6 +217,13 @@ public void onRender(Render3DEvent event) { pos.getY() + 1, pos.getZ() + 1); } + if (renderBoxOne == null) { + renderBoxOne = new Box(pos); + } + if (renderBoxTwo == null) { + renderBoxTwo = new Box(pos); + } + double offsetX = (renderBoxTwo.minX - renderBoxOne.minX) / Smoothness.get(); double offsetY = (renderBoxTwo.minY - renderBoxOne.minY) / Smoothness.get(); double offsetZ = (renderBoxTwo.minZ - renderBoxOne.minZ) / Smoothness.get(); diff --git a/src/main/java/org/snail/plus/utils/WorldUtils.java b/src/main/java/org/snail/plus/utils/WorldUtils.java index 038eb10..9a7f71b 100644 --- a/src/main/java/org/snail/plus/utils/WorldUtils.java +++ b/src/main/java/org/snail/plus/utils/WorldUtils.java @@ -59,7 +59,7 @@ public static String getName(PlayerEntity entity) { } public static String getCoords(PlayerEntity player) { - return "%s, %s, %s".formatted(player.getX(), player.getY(), player.getZ()); + return "%s, %s, %s".formatted(Math.round(player.getX()), Math.round(player.getY()), Math.round(player.getZ())); } public static void placeBlock(FindItemResult item, BlockPos pos, HandMode hand, DirectionMode directionMode, boolean packet, swapUtils.swapMode Mode, boolean rotate) {