Skip to content

Commit

Permalink
improved VisualRange.java
Browse files Browse the repository at this point in the history
- made sound appear when player left range

improved Threading
- added threading for FakePlayerMixin.java

improved thread safety by using synchronized method

fixed rotations in autoXP.java
  • Loading branch information
user93390 committed Nov 25, 2024
1 parent ae7101c commit c028f78
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 70 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings=1.21+build.9
loader_version=0.16.9

# Mod Properties
mod_version= 1.2.1
mod_version= 1.2.3
maven_group=org.snail
archives_base_name=Snail++

Expand Down
62 changes: 37 additions & 25 deletions src/main/java/org/snail/plus/mixins/FakePlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
import meteordevelopment.meteorclient.gui.widgets.containers.WVerticalList;
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.player.FakePlayer;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity;
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerManager;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.Direction;
import org.snail.plus.utils.PlayerMovement;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -34,15 +31,13 @@

@Mixin(FakePlayer.class)
public class FakePlayerMixin {
@Final
private SettingGroup sgGeneral;

@Unique
private final List<PlayerMovement> recordedMovements = new ArrayList<>();
@Final
private SettingGroup sgGeneral;
@Unique
private Setting<Boolean> loop = null;


@Unique
private boolean recording = false;
@Unique
Expand All @@ -67,11 +62,20 @@ private void onGetWidget(GuiTheme theme, CallbackInfoReturnable<WWidget> info) {
WButton start = wHorizontalList.add(theme.button("Start Recording")).widget();
WButton stop = wHorizontalList.add(theme.button("Stop Recording")).widget();
WButton play = wHorizontalList.add(theme.button("Play Recording")).widget();
WButton clear = wHorizontalList.add(theme.button("Clear all recordings")).widget();

start.action = () -> {
stopRecording();
startRecording();

};

clear.action = () -> {
stopRecording();
recordedMovements.clear();
stopLooping();
};

stop.action = this::stopRecording;
play.action = this::startLooping;

Expand All @@ -85,27 +89,35 @@ private void onGetWidget(GuiTheme theme, CallbackInfoReturnable<WWidget> info) {
@Unique
@EventHandler
private void onTick(TickEvent.Post event) {
for (FakePlayerEntity fakePlayer : FakePlayerManager.getFakePlayers()) {
for(PlayerEntity FakePlayer : mc.world.getPlayers()) {
if (FakePlayer == fakePlayer) {
if (recording) {
recordedMovements.add(new PlayerMovement(mc.player.getX(), mc.player.getY(), mc.player.getZ(), mc.player.getYaw(), mc.player.getPitch()));
}
if (looping && !recordedMovements.isEmpty()) {
PlayerMovement movement = recordedMovements.get(loopIndex);
FakePlayer.updatePosition(movement.x, movement.y, movement.z);
FakePlayer.setVelocity(mc.player.getVelocity().x, mc.player.getVelocity().y, mc.player.getVelocity().z);
loopIndex = (loopIndex + 1) % recordedMovements.size();
if (loopIndex == 0) {
if (loop.get()) {
startLooping();
} else {
stopLooping();
synchronized (this) {
mc.execute(() -> {
try {
for (FakePlayerEntity fakePlayer : FakePlayerManager.getFakePlayers()) {
for (PlayerEntity FakePlayer : mc.world.getPlayers()) {
if (FakePlayer == fakePlayer) {
if (recording) {
recordedMovements.add(new PlayerMovement(mc.player.getX(), mc.player.getY(), mc.player.getZ(), mc.player.getYaw(), mc.player.getPitch()));
}
if (looping && !recordedMovements.isEmpty()) {
PlayerMovement movement = recordedMovements.get(loopIndex);
FakePlayer.updatePosition(movement.x, movement.y, movement.z);
FakePlayer.setVelocity(mc.player.getVelocity().x, mc.player.getVelocity().y, mc.player.getVelocity().z);
loopIndex = (loopIndex + 1) % recordedMovements.size();
if (loopIndex == 0) {
if (loop.get()) {
startLooping();
} else {
stopLooping();
}
}
}
}
}
}
} catch (Exception e) {
ChatUtils.error("An error occurred while playing the recording.");
}
}
});
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/snail/plus/modules/chat/AutoEZ.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import org.snail.plus.Addon;
import org.snail.plus.utils.WorldUtils;
Expand Down Expand Up @@ -39,7 +40,7 @@ public class AutoEZ extends Module {
});

public AutoEZ() {
super(Addon.Snail, "Auto EZ+", "sends a custom message when a player you've killed dies");
super(Addon.Snail, "Auto EZ+", "sends a custom message when a player dies");
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/snail/plus/modules/chat/VisualRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class VisualRange extends Module {
private final List<Entity> entitiesList = new ArrayList<>();
private final Random random = new Random();


Runnable reset = () -> mc.execute(() -> {
entitiesList.clear();
x = 0;
Expand Down Expand Up @@ -83,16 +82,17 @@ private void onTick(TickEvent.Post event) {
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);
}
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);
}
}
}
} else {
if (entities.get().contains(entity.getType()) && entitiesList.contains(entity)) {
if (!soundList.isEmpty()) WorldUtils.playSound(soundList.get(random.nextInt(soundList.size())), 1.0f);

warning("Entity left %s", entity.getName().getString() + " at " + WorldUtils.getCoords((PlayerEntity) entity));
entitiesList.remove(entity);
}
Expand Down
66 changes: 39 additions & 27 deletions src/main/java/org/snail/plus/modules/combat/AutoAnchor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.explosion.Explosion;
import org.joml.Vector3d;
import org.snail.plus.Addon;
import org.snail.plus.utils.CombatUtils;
Expand Down Expand Up @@ -123,6 +124,12 @@ public class AutoAnchor extends Module {
.sliderRange(0.0, 36.0)
.build());

private final Setting<Boolean> strictDmg = sgDamage.add(new BoolSetting.Builder()
.name("strict damage")
.description("only place if the damage is exact. No exceptions.")
.defaultValue(false)
.build());

private final Setting<Double> pauseHealth = sgDamage.add(new DoubleSetting.Builder()
.name("pause health")
.description("Pauses the module when your health is below this value.")
Expand Down Expand Up @@ -310,6 +317,9 @@ private List<BlockPos> positions(PlayerEntity entity, BlockPos start) {
selfDamage = DamageUtils.bedDamage(mc.player, vec);
targetDamage = DamageUtils.bedDamage(entity, vec);

//immediately return false if self dmg or target dmg is bad
if (strictDmg.get() && selfDamage > maxSelfDamage.get() || targetDamage < minDamage.get()) return false;

if (!airPlace.get() && WorldUtils.isAir(pos.down(1))) return false;

if (selfDamage <= maxSelfDamage.get() && targetDamage >= minDamage.get() && WorldUtils.hitBoxCheck(pos, true) && WorldUtils.isAir(pos)) {
Expand All @@ -329,38 +339,40 @@ private List<BlockPos> positions(PlayerEntity entity, BlockPos start) {
@EventHandler
private void onTick(TickEvent.Post event) {
resetDamageValues.run();
try {
mc.executeTask(() -> {
if (updateEat()) return;
targetDamage = 0;
selfDamage = 0;
if (executor == null || executor.isShutdown() || executor.isTerminated()) {
executor = Executors.newSingleThreadExecutor();
}
executor.submit(() -> {
if (mc.world.getDimension().respawnAnchorWorks()) {
error("You are in the wrong dimension!");
return;
synchronized (this) {
try {
mc.executeSync(() -> {
if (updateEat()) return;
targetDamage = 0;
selfDamage = 0;
if (executor == null || executor.isShutdown() || executor.isTerminated()) {
executor = Executors.newSingleThreadExecutor();
}
long currentTime = System.currentTimeMillis();
if (currentTime - lastUpdateTime < (1000 / updateSpeed.get())) return;
executor.submit(() -> {
if (mc.world.getDimension().respawnAnchorWorks()) {
error("You are in the wrong dimension!");
return;
}
long currentTime = System.currentTimeMillis();
if (currentTime - lastUpdateTime < (1000 / updateSpeed.get())) return;

PlayerEntity player = CombatUtils.filter(mc.world.getPlayers(), targetMode.get(), range.get());
AnchorPos = positions(player, player.getBlockPos());
PlayerEntity player = CombatUtils.filter(mc.world.getPlayers(), targetMode.get(), range.get());
AnchorPos = positions(player, player.getBlockPos());

BestTarget = player;
BestTarget = player;

lock.lock();
try {
doBreak.run();
} finally {
lock.unlock();
}
lastUpdateTime = currentTime;
lock.lock();
try {
doBreak.run();
} finally {
lock.unlock();
}
lastUpdateTime = currentTime;
});
});
});
} catch (Exception e) {
error("An error occurred while updating the module: " + e.getMessage());
} catch (Exception e) {
error("An error occurred while updating the module: " + e.getMessage());
}
}
}

Expand Down
27 changes: 23 additions & 4 deletions src/main/java/org/snail/plus/modules/misc/autoXP.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import meteordevelopment.orbit.EventHandler;
import net.minecraft.item.Items;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import org.snail.plus.Addon;
import org.snail.plus.utils.MathUtils;
import org.snail.plus.utils.WorldUtils;
import org.snail.plus.utils.swapUtils;

Expand All @@ -23,6 +25,14 @@
public class autoXP extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();


private final Setting<Double> pitch = sgGeneral.add(new DoubleSetting.Builder()
.name("pitch")
.description("Pitch to look at when using XP bottles.")
.defaultValue(-90.0)
.sliderRange(-90.0, 90.0)
.build());

public final Setting<Double> pauseHealth = sgGeneral.add(new DoubleSetting.Builder()
.name("pause-health")
.description("Pauses when you go below a certain health.")
Expand All @@ -41,7 +51,8 @@ public class autoXP extends Module {
.description("the slot to move the xp to")
.defaultValue(0)
.sliderRange(0, 10)
.visible(() -> autoSwitch.get().equals(swapUtils.swapMode.silent) || autoSwitch.get().equals(swapUtils.swapMode.normal) || autoSwitch.get().equals(swapUtils.swapMode.Move))
.visible(() -> autoSwitch.get().equals(swapUtils.swapMode.silent) || autoSwitch.get().equals(swapUtils.swapMode.normal)
|| autoSwitch.get().equals(swapUtils.swapMode.Move))
.build());

private final Setting<WorldUtils.HandMode> handSwing = sgGeneral.add(new EnumSetting.Builder<WorldUtils.HandMode>()
Expand All @@ -50,6 +61,12 @@ public class autoXP extends Module {
.defaultValue(WorldUtils.HandMode.MainHand)
.build());

private final Setting<Boolean> pauseUse = sgGeneral.add(new BoolSetting.Builder()
.name("pause-use")
.description("Pause using xp bottles when using other items.")
.defaultValue(false)
.build());

private final Setting<Integer> cooldownTime = sgGeneral.add(new IntSetting.Builder()
.name("cooldown-time")
.description("Cooldown time between using XP bottles (in ticks).")
Expand Down Expand Up @@ -90,7 +107,7 @@ public class autoXP extends Module {
};

private final Runnable interact = () -> {
Rotations.rotate(mc.player.getYaw(), Rotations.getPitch(mc.player.getBlockPos().down(1)), this::interact);
interact();
mc.player.swingHand(WorldUtils.swingHand(handSwing.get()));
};

Expand All @@ -110,7 +127,8 @@ public void onDeactivate() {

@EventHandler
private void onTick(TickEvent.Post event) {
mc.executeSync(() -> {
mc.executeSync(() -> {
if (pauseUse.get() && mc.player.isUsingItem()) return;
if (autoDisable.get() && isArmorFullDurability()) {
toggle();
return;
Expand All @@ -128,7 +146,8 @@ private void onTick(TickEvent.Post event) {
if (currentTime - lastUseTime < cooldownTime.get() * 50) return;

slot = item.slot();
interact.run();
Rotations.rotate(mc.player.getYaw(), pitch.get(), 100, interact);

lastUseTime = currentTime;
});
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/org/snail/plus/modules/render/BurrowEsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ public void onDeactivate() {

@EventHandler
private void onTick(TickEvent.Pre event) {
synchronized (burrowedPlayers) {
burrowedPlayers.clear();
mc.world.getPlayers().stream()
.filter(player -> !(ignoreFriends.get() && Friends.get().isFriend(player)))
.filter(player -> CombatUtils.isBurrowed(player) && mc.player.distanceTo(player) <= range.get())
.limit(performance.get() ? maxPlayers.get() : Long.MAX_VALUE)
.forEach(burrowedPlayers::add);
}
mc.executeSync(() -> {
synchronized (this.burrowedPlayers) {
burrowedPlayers.clear();
mc.world.getPlayers().stream()
.filter(player -> !(ignoreFriends.get() && Friends.get().isFriend(player)))
.filter(player -> CombatUtils.isBurrowed(player) && mc.player.distanceTo(player) <= range.get())
.limit(performance.get() ? maxPlayers.get() : Long.MAX_VALUE)
.forEach(burrowedPlayers::add);
}
});
}

@EventHandler
Expand Down

0 comments on commit c028f78

Please sign in to comment.