Skip to content

Commit

Permalink
Merge pull request #27 from RickyTheRacc/code-cleanup
Browse files Browse the repository at this point in the history
* Remove Enums Class

* Change Javadocs to Comments

* Remove General Comments

* Move Variables

* Use PlayerUtils in Center Command

* Use .noSlider()

* Optimize ToggleCommandMixin

* Organize AxisViewer

* Cleanup HIGUtils

* Separate Modules into Categories

* Make AFKLogout Settings Clearer

* Standardize Event Function Names
  • Loading branch information
machiecodes authored Jul 20, 2024
1 parent 9cd7f47 commit 80f6b81
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 252 deletions.
8 changes: 3 additions & 5 deletions src/main/java/me/redcarlos/higtools/commands/Center.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import net.minecraft.command.CommandSource;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.MathHelper;
Expand All @@ -14,11 +16,7 @@ public Center() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.executes(context -> {
double x = MathHelper.floor(mc.player.getX()) + 0.5;
double z = MathHelper.floor(mc.player.getZ()) + 0.5;
mc.player.setPosition(x, mc.player.getY(), z);
mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(mc.player.getX(), mc.player.getY(), mc.player.getZ(), mc.player.isOnGround()));

PlayerUtils.centerPlayer();
return SINGLE_SUCCESS;
});
}
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/me/redcarlos/higtools/mixins/ToggleCommandMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Arrays;

@SuppressWarnings("unchecked")
@Mixin(value = ToggleCommand.class, remap = false)
public abstract class ToggleCommandMixin extends Command {
public ToggleCommandMixin(String name, String description, String... aliases) {
super(name, description, aliases);
}

/**
* Borers & HighwayBuilder
*/
@Unique
private final List<Class<? extends Module>> borerClasses = List.of(
HighwayBuilderPlus.class,
private final Class<? extends Module>[] borerModules = new Class[]{
AxisBorer.class,
NegNegBorer.class,
NegPosBorer.class,
PosNegBorer.class,
PosPosBorer.class
);
};

/**
* HighwayTools Modules
*/
@Unique
private final List<Class<? extends Module>> higToolsClasses = List.of(
private final Class<? extends Module>[] otherModules = new Class[]{
HighwayTools.class,
AutoCenter.class,
AutoLog.class,
AutoWalkHig.class,
Expand All @@ -52,18 +47,24 @@ public ToggleCommandMixin(String name, String description, String... aliases) {
LiquidFillerHig.class,
RotationLock.class,
SafeWalk.class,
ScaffoldPlus.class
);
ScaffoldPlus.class,
HighwayBuilderPlus.class
};

@Inject(method = "build", at = @At("HEAD"))
private void inject(LiteralArgumentBuilder<CommandSource> builder, CallbackInfo ci) {
builder.then(literal("higtools").then(literal("off").executes(context -> {
Modules modules = Modules.get();

if (modules.get(HighwayTools.class).isActive()) modules.get(HighwayTools.class).toggle();
Arrays.stream(borerModules).forEach(module -> {
if (!modules.get(module).isActive()) return;
modules.get(module).toggle();
});

borerClasses.stream().filter(borer -> modules.get(borer).isActive()).forEach(borer -> modules.get(borer).toggle());
higToolsClasses.stream().filter(higTool -> modules.get(higTool).isActive()).forEach(higTool -> modules.get(higTool).toggle());
Arrays.stream(otherModules).forEach(module -> {
if (!modules.get(module).isActive()) return;
modules.get(module).toggle();
});

return SINGLE_SUCCESS;
})));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onDeactivate() {

@Override
@EventHandler
public void tick(TickEvent.Pre event) {
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
// Previous floored block position of player
BlockPos prevBlockPos = playerPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,20 @@
import static me.redcarlos.higtools.utils.HIGUtils.*;

public abstract class BorerModule extends Module {
/**
* Preserve 2 block tall tunnel for speed bypass
*/
protected final ArrayList<BlockPos> blackList = new ArrayList<>();
/**
* Last time packets were sent
*/
protected long lastUpdateTime = 0;
/**
* Floored block position of player
*/
protected BlockPos playerPos = BlockPos.ORIGIN;
protected int packets = 0;
private final SettingGroup sgGeneral = settings.getDefaultGroup();

protected final Setting<PosNegBorer.Shape> mode = sgGeneral.add(new EnumSetting.Builder<PosNegBorer.Shape>()
.name("shape")
.description("Which shape to dig.")
.defaultValue(Shape.HIGHWAY)
.build()
);

protected final Setting<Integer> extForward;
protected final Setting<Integer> extBackward;
protected final Setting<Integer> xOffset;
protected final Setting<Integer> zOffset;

protected final Setting<Integer> keepY = sgGeneral.add(new IntSetting.Builder()
.name("keepY")
.description("Keeps a specific Y level when digging.")
Expand All @@ -49,13 +39,29 @@ public abstract class BorerModule extends Module {
.sliderRange(-1, 255)
.build()
);

protected final Setting<Boolean> jumping = sgGeneral.add(new BoolSetting.Builder()
.name("jumping")
.description("Send more or less packs.")
.defaultValue(false)
.build()
);

/**
* Preserve 2 block tall tunnel for speed bypass
*/
protected final ArrayList<BlockPos> blackList = new ArrayList<>();
/**
* Last time packets were sent
*/
protected long lastUpdateTime = 0;
/**
* Floored block position of player
*/
protected BlockPos playerPos = BlockPos.ORIGIN;

protected int packets = 0;

protected BorerModule(String name, String description, int extForwards, int extBackwards, int xOffset, int zOffset) {
super(HIGTools.BORERS, name, description);

Expand Down Expand Up @@ -95,7 +101,7 @@ protected BorerModule(String name, String description, int extForwards, int extB
}

@EventHandler
public abstract void tick(TickEvent.Pre event);
public abstract void onTick(TickEvent.Pre event);

protected void getBlacklistedBlockPoses() {
if (mc.player == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onDeactivate() {

@Override
@EventHandler
public void tick(TickEvent.Pre event) {
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
// Previous floored block position of player
BlockPos prevBlockPos = playerPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onDeactivate() {

@Override
@EventHandler
public void tick(TickEvent.Pre event) {
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
// Previous floored block position of player
BlockPos prevBlockPos = playerPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onDeactivate() {

@Override
@EventHandler
public void tick(TickEvent.Pre event) {
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
// Previous floored block position of player
BlockPos prevBlockPos = playerPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onDeactivate() {

@Override
@EventHandler
public void tick(TickEvent.Pre event) {
public void onTick(TickEvent.Pre event) {
if (mc.player == null || mc.world == null) return;
// Previous floored block position of player
BlockPos prevBlockPos = playerPos;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/redcarlos/higtools/modules/main/AfkLogout.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ public class AfkLogout extends Module {

private final Setting<Integer> xCoords = sgGeneral.add(new IntSetting.Builder()
.name("x-coord")
.description("The X coordinate at which to log out.")
.description("The X coordinate at which to log out (world border is at +/- 29999983).")
.defaultValue(1000)
.range(-29999983, 29999983)
.sliderRange(-29999983, 29999983)
.noSlider()
.build()
);

private final Setting<Integer> zCoords = sgGeneral.add(new IntSetting.Builder()
.name("z-coord")
.description("The Z coordinate at which to log out.")
.description("The Z coordinate at which to log out (world border is at +/- 29999983).")
.defaultValue(1000)
.range(-29999983, 29999983)
.sliderRange(-29999983, 29999983)
.noSlider()
.build()
);

private final Setting<Integer> radius = sgGeneral.add(new IntSetting.Builder()
.name("radius")
.description("The radius from the exact coordinates it will log you out.")
.description("Log out when you are this far away from the coordinates.")
.defaultValue(64)
.min(0)
.sliderRange(0, 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public void onActivate() {
}

@EventHandler
public void motions(TickEvent.Pre event) {
public void onPreTick(TickEvent.Pre event) {
check();
}

@EventHandler
public void motions(TickEvent.Post event) {
public void onPostTick(TickEvent.Post event) {
check();
}

Expand Down
92 changes: 46 additions & 46 deletions src/main/java/me/redcarlos/higtools/modules/main/AxisViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import meteordevelopment.orbit.EventHandler;

Expand All @@ -13,9 +14,8 @@ public class AxisViewer extends Module {
private final SettingGroup sgNether = settings.createGroup("Nether");
private final SettingGroup sgEnd = settings.createGroup("End");

/**
* Overworld
*/
// Overworld

private final Setting<AxisType> overworldAxisTypes = sgOverworld.add(new EnumSetting.Builder<AxisType>()
.name("render")
.description("Which axis to display.")
Expand All @@ -41,9 +41,8 @@ public class AxisViewer extends Module {
.build()
);

/**
* Nether
*/
// Nether

private final Setting<AxisType> netherAxisTypes = sgNether.add(new EnumSetting.Builder<AxisType>()
.name("render")
.description("Which axis to display.")
Expand All @@ -69,9 +68,8 @@ public class AxisViewer extends Module {
.build()
);

/**
* End
*/
// End

private final Setting<AxisType> endAxisTypes = sgEnd.add(new EnumSetting.Builder<AxisType>()
.name("render")
.description("Which axis to display.")
Expand Down Expand Up @@ -102,60 +100,62 @@ public AxisViewer() {
}

@EventHandler
private void onRender(Render3DEvent event) {
private void onRender3D(Render3DEvent event) {
if (mc.options.hudHidden) return;

AxisType axisType;
int y;
Color lineColor;

switch (PlayerUtils.getDimension()) {
case Overworld -> {
if (overworldAxisTypes.get() == AxisType.Both) {
drawLines(event, true, true, overworldY.get(), overworldColor.get());
} else if (overworldAxisTypes.get() == AxisType.Axis) {
drawLines(event, true, false, overworldY.get(), overworldColor.get());
} else if (overworldAxisTypes.get() == AxisType.Diagonals) {
drawLines(event, false, true, overworldY.get(), overworldColor.get());
}
axisType = overworldAxisTypes.get();
y = overworldY.get();
lineColor = overworldColor.get();
}
case Nether -> {
if (netherAxisTypes.get() == AxisType.Both) {
drawLines(event, true, true, netherY.get(), netherColor.get());
} else if (netherAxisTypes.get() == AxisType.Axis) {
drawLines(event, true, false, netherY.get(), netherColor.get());
} else if (netherAxisTypes.get() == AxisType.Diagonals) {
drawLines(event, false, true, netherY.get(), netherColor.get());
}
axisType = netherAxisTypes.get();
y = netherY.get();
lineColor = netherColor.get();
}
case End -> {
if (endAxisTypes.get() == AxisType.Both) {
drawLines(event, true, true, endY.get(), endColor.get());
} else if (endAxisTypes.get() == AxisType.Axis) {
drawLines(event, true, false, endY.get(), endColor.get());
} else if (endAxisTypes.get() == AxisType.Diagonals) {
drawLines(event, false, true, endY.get(), endColor.get());
}
axisType = endAxisTypes.get();
y = endY.get();
lineColor = endColor.get();
}
default -> throw new IllegalStateException("Unexpected value: " + PlayerUtils.getDimension());
}
}

// Todo : Render lines block per block to prevent render culling breaking rendering
private void drawLines(Render3DEvent event, boolean axis, boolean diags, int y, SettingColor color) {
if (axis) {
event.renderer.line(0, y, 0, 0, y, 30_000_000, color); // Z+
event.renderer.line(0, y, 0, 30_000_000, y, 0, color); // X+
event.renderer.line(0, y, 0, 0, y, -30_000_000, color); // -Z
event.renderer.line(0, y, 0, -30_000_000, y, 0, color); // -X
// TODO: Fix to be unaffected by render culling

if (axisType.cardinals()) {
event.renderer.line(0, y, 0, 0, y, 30_000_000, lineColor); // Z+
event.renderer.line(0, y, 0, 30_000_000, y, 0, lineColor); // X+
event.renderer.line(0, y, 0, 0, y, -30_000_000, lineColor); // -Z
event.renderer.line(0, y, 0, -30_000_000, y, 0, lineColor); // -X
}

if (diags) {
event.renderer.line(0, y, 0, 30_000_000, y, 30_000_000, color); // ++
event.renderer.line(0, y, 0, 30_000_000, y, -30_000_000, color); // +-
event.renderer.line(0, y, 0, -30_000_000, y, 30_000_000, color); // -+
event.renderer.line(0, y, 0, -30_000_000, y, -30_000_000, color); // --
if (axisType.diagonals()) {
event.renderer.line(0, y, 0, 30_000_000, y, 30_000_000, lineColor); // ++
event.renderer.line(0, y, 0, 30_000_000, y, -30_000_000, lineColor); // +-
event.renderer.line(0, y, 0, -30_000_000, y, 30_000_000, lineColor); // -+
event.renderer.line(0, y, 0, -30_000_000, y, -30_000_000, lineColor); // --
}

}

public enum AxisType {
Both,
Axis,
Cardinals,
Diagonals,
None
None;

boolean cardinals() {
return this == Both || this == Cardinals;
}

boolean diagonals() {
return this == Both || this == Diagonals;
}
}
}
Loading

0 comments on commit 80f6b81

Please sign in to comment.