Implements #10 and an attempt to unspaghettify Confuse

This commit is contained in:
StormyBytes
2021-06-15 08:17:31 +07:00
parent 351f067ee1
commit f4b30da469

View File

@@ -1,27 +1,28 @@
package cloudburst.rejects.modules; package cloudburst.rejects.modules;
import java.util.Random;
import cloudburst.rejects.MeteorRejectsAddon; import cloudburst.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.entity.SortPriority;
import meteordevelopment.meteorclient.utils.entity.TargetUtils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext; import net.minecraft.world.RaycastContext;
import meteordevelopment.orbit.EventHandler; import java.util.Random;
import meteordevelopment.meteorclient.events.render.Render3DEvent;
import meteordevelopment.meteorclient.events.world.TickEvent; // Too much much spaghetti!
import meteordevelopment.meteorclient.settings.BoolSetting; // -StormyBytes
import meteordevelopment.meteorclient.settings.EnumSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.render.RenderUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
public class Confuse extends Module { public class Confuse extends Module {
@@ -39,6 +40,7 @@ public class Confuse extends Module {
.description("Mode") .description("Mode")
.build() .build()
); );
private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder() private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
.name("delay") .name("delay")
.description("Delay") .description("Delay")
@@ -47,6 +49,22 @@ public class Confuse extends Module {
.sliderMax(20) .sliderMax(20)
.build() .build()
); );
private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder()
.name("radius")
.description("Range to confuse opponents")
.defaultValue(6)
.min(0).sliderMax(10)
.build()
);
private final Setting<SortPriority> priority = sgGeneral.add(new EnumSetting.Builder<SortPriority>()
.name("priority")
.description("Targetting priority")
.defaultValue(SortPriority.LowestHealth)
.build()
);
private final Setting<Integer> circleSpeed = sgGeneral.add(new IntSetting.Builder() private final Setting<Integer> circleSpeed = sgGeneral.add(new IntSetting.Builder()
.name("circle-speed") .name("circle-speed")
.description("Circle mode speed") .description("Circle mode speed")
@@ -55,17 +73,28 @@ public class Confuse extends Module {
.sliderMax(180) .sliderMax(180)
.build() .build()
); );
private final Setting<Boolean> moveThroughBlocks = sgGeneral.add(new BoolSetting.Builder() private final Setting<Boolean> moveThroughBlocks = sgGeneral.add(new BoolSetting.Builder()
.name("move-through-blocks") .name("move-through-blocks")
.defaultValue(false) .defaultValue(false)
.build() .build()
); );
private final Setting<Boolean> budgetGraphics = sgGeneral.add(new BoolSetting.Builder() private final Setting<Boolean> budgetGraphics = sgGeneral.add(new BoolSetting.Builder()
.name("budget-graphics") .name("budget-graphics")
.defaultValue(false) .defaultValue(false)
.build() .build()
); );
private final Setting<SettingColor> circleColor = sgGeneral.add(new ColorSetting.Builder()
.name("circle-color")
.description("Color for circle rendering")
.defaultValue(new SettingColor(0, 255, 0))
.visible(budgetGraphics::get)
.build()
);
int delayWaited = 0; int delayWaited = 0;
double circleProgress = 0; double circleProgress = 0;
double addition = 0.0; double addition = 0.0;
@@ -85,50 +114,45 @@ public class Confuse extends Module {
@EventHandler @EventHandler
private void onTick(TickEvent.Pre event) { private void onTick(TickEvent.Pre event) {
// Delay
delayWaited++; delayWaited++;
if (delayWaited < delay.get()) return; if (delayWaited < delay.get()) return;
delayWaited = 0; delayWaited = 0;
assert mc.player != null;
Vec3d sel1 = mc.player.getPos().add(-4, -4, -4);
Vec3d sel2 = sel1.add(8, 8, 8); // Targetting
Box selector = new Box(sel1, sel2); target = TargetUtils.get(entity -> {
assert mc.world != null; if (entity.getUuid() == mc.player.getUuid()) return false;
for (Entity e : mc.world.getEntities()) { if (!entity.isAlive() || !entity.isAttackable()) return false;
if (e.getUuid() == mc.player.getUuid()) continue; return PlayerUtils.distanceTo(entity) <= range.get();
if (!e.isAlive() }, priority.get());
|| !e.isAttackable()) continue;
if (e.getBoundingBox().intersects(selector)) {
target = e;
break;
}
}
if (target == null) return; if (target == null) return;
if (!target.isAlive()) { if (!target.isAlive()) {
target = null; target = null;
return; return;
} }
Vec3d entityPos = target.getPos(); Vec3d entityPos = target.getPos();
Vec3d playerPos = mc.player.getPos(); Vec3d playerPos = mc.player.getPos();
if (playerPos.distanceTo(entityPos) > 6) {
target = null;
return;
}
Random r = new Random(); Random r = new Random();
BlockHitResult hit; BlockHitResult hit;
int halfRange = range.get() / 2;
switch (mode.get()) { switch (mode.get()) {
case RandomTP: case RandomTP:
double x = r.nextDouble() * 6 - 3; double x = r.nextDouble() * range.get() - halfRange;
double y = 0; double y = 0;
double z = r.nextDouble() * 6 - 3; double z = r.nextDouble() * range.get() - halfRange;
Vec3d addend = new Vec3d(x, y, z); Vec3d addend = new Vec3d(x, y, z);
Vec3d goal = entityPos.add(addend); Vec3d goal = entityPos.add(addend);
if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() != Blocks.AIR) { if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() != Blocks.AIR) {
goal = new Vec3d(x, playerPos.y, z); goal = new Vec3d(x, playerPos.y, z);
} }
if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() == Blocks.AIR) { if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() == Blocks.AIR) {
hit = mc.world.raycast(new RaycastContext( hit = mc.world.raycast(new RaycastContext(mc.player.getPos(),goal, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
mc.player.getPos(),goal, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player
));
if (!moveThroughBlocks.get() && hit.isInsideBlock()) { if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
delayWaited = (int) (delay.get() - 1); delayWaited = (int) (delay.get() - 1);
break; break;
@@ -138,19 +162,19 @@ public class Confuse extends Module {
delayWaited = (int) (delay.get() - 1); delayWaited = (int) (delay.get() - 1);
} }
break; break;
case Switch: case Switch:
Vec3d diff = entityPos.subtract(playerPos); Vec3d diff = entityPos.subtract(playerPos);
Vec3d diff1 = new Vec3d(clamp(diff.x, -3, 3), clamp(diff.y, -3, 3), clamp(diff.z, -3, 3)); Vec3d diff1 = new Vec3d(Utils.clamp(diff.x, -halfRange, halfRange), Utils.clamp(diff.y, -halfRange, halfRange), Utils.clamp(diff.z, -halfRange, halfRange));
Vec3d goal2 = entityPos.add(diff1); Vec3d goal2 = entityPos.add(diff1);
hit = mc.world.raycast(new RaycastContext( hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), goal2, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
mc.player.getPos(), goal2, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player
));
if (!moveThroughBlocks.get() && hit.isInsideBlock()) { if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
delayWaited = (int) (delay.get() - 1); delayWaited = (int) (delay.get() - 1);
break; break;
} }
mc.player.updatePosition(goal2.x, goal2.y, goal2.z); mc.player.updatePosition(goal2.x, goal2.y, goal2.z);
break; break;
case Circle: case Circle:
delay.set(0); delay.set(0);
circleProgress += circleSpeed.get(); circleProgress += circleSpeed.get();
@@ -159,9 +183,7 @@ public class Confuse extends Module {
double sin = Math.sin(rad) * 3; double sin = Math.sin(rad) * 3;
double cos = Math.cos(rad) * 3; double cos = Math.cos(rad) * 3;
Vec3d current = new Vec3d(entityPos.x + sin, playerPos.y, entityPos.z + cos); Vec3d current = new Vec3d(entityPos.x + sin, playerPos.y, entityPos.z + cos);
hit = mc.world.raycast(new RaycastContext( hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), current, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
mc.player.getPos(), current, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player
));
if (!moveThroughBlocks.get() && hit.isInsideBlock()) if (!moveThroughBlocks.get() && hit.isInsideBlock())
break; break;
mc.player.updatePosition(current.x, current.y, current.z); mc.player.updatePosition(current.x, current.y, current.z);
@@ -179,7 +201,7 @@ public class Confuse extends Module {
if (addition > 360) addition = 0; if (addition > 360) addition = 0;
for (int i = 0; i < 360; i += flag ? 7 : 1) { for (int i = 0; i < 360; i += flag ? 7 : 1) {
Color c1; Color c1;
if (flag) c1 = new Color(0, 255, 0); if (flag) c1 = circleColor.get();
else { else {
double rot = (255.0 * 3) * (((((double) i) + addition) % 360) / 360.0); double rot = (255.0 * 3) * (((((double) i) + addition) % 360) / 360.0);
int seed = (int) Math.floor(rot / 255.0); int seed = (int) Math.floor(rot / 255.0);
@@ -198,8 +220,4 @@ public class Confuse extends Module {
last = c; last = c;
} }
} }
public static double clamp(double val, double min, double max) {
return Math.max(min, Math.min(max, val));
}
} }