Skip to content

Commit

Permalink
improved VisualRange.java
Browse files Browse the repository at this point in the history
- fixed entity checks

improved AutoEZ.java
- fixed major thingy
  • Loading branch information
user93390 committed Nov 24, 2024
1 parent 94d7ed8 commit ae7101c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 68 deletions.
57 changes: 28 additions & 29 deletions src/main/java/org/snail/plus/modules/chat/AutoEZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,8 +21,8 @@ public class AutoEZ extends Module {

private final Setting<List<String>> 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<Boolean> dm = sgGeneral.add(new BoolSetting.Builder()
Expand All @@ -32,50 +31,50 @@ 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");
}

@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<String> 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<PlayerEntity> 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);
}
}
}
}
71 changes: 33 additions & 38 deletions src/main/java/org/snail/plus/modules/chat/VisualRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -39,70 +38,66 @@ public class VisualRange extends Module {
private final Setting<Integer> 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<List<SoundEvent>> sounds = sgVisualRange.add(new SoundEventListSetting.Builder()
.name("sounds")
.description("Sounds to play when a player is spotted")
.build());
public double x, y, z;
private List<Entity> players;
private ExecutorService executor = Executors.newSingleThreadExecutor();
private final List<Entity> 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<SoundEvent> 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<SoundEvent> 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);
}
}
}
});
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/snail/plus/modules/combat/webAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/snail/plus/utils/WorldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ae7101c

Please sign in to comment.