Added a fly hack and fall damage cancel

This commit is contained in:
Cameron Reed 2022-12-08 21:43:33 -07:00
parent 1f2c68181e
commit 2b807d8428
9 changed files with 155 additions and 9 deletions

View File

@ -6,7 +6,7 @@ minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.10
# Mod Properties
mod_version=1.0.0
mod_version=1.1.0
maven_group=cmods
archives_base_name=haxxor
# Dependencies

View File

@ -0,0 +1,53 @@
package cmods.haxxor.client;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.BlockPos;
import java.util.Objects;
public class FallDamageCancel {
private static final HaxxorOptions options = HaxxorOptions.getInstance();
private static final int triggerHeight = 4;
private static final float heightAdjust = 0.5f;
// private static boolean triggered = false;
public static void tick(MinecraftClient client) {
if (!options.cancel_fall_damage || client.world == null || client.player == null)
return;
if (client.player.isOnGround()) {
// triggered = false;
return;
}
// if (triggered) {
// return;
// }
BlockPos playerPos = client.player.getBlockPos();
for (int i = 0; i < triggerHeight; i++) {
if (!client.world.getBlockState(playerPos.down(i)).isAir()) {
float totalFallDist = client.player.fallDistance + i;
if (totalFallDist >= client.player.getSafeFallDistance()) {
System.out.println("Attempting to negate fall damage");
sendPacket(client);
// triggered = true;
}
}
}
}
private static void sendPacket(MinecraftClient client) {
if (client.player == null)
return;
Objects.requireNonNull(client.getNetworkHandler()).sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(
client.player.getX(), client.player.getY() + heightAdjust, client.player.getZ(),
client.player.isOnGround()
));
}
}

View File

@ -0,0 +1,45 @@
package cmods.haxxor.client;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import java.util.Objects;
public class FlyHack {
private static final HaxxorOptions.FlyHackOptions options = HaxxorOptions.getInstance().flyHack;
private static final int ticksToFirst = 40;
private static final int waitTicks = 8;
private static final float fallDist = 0.5f;
private static int tickCounter = ticksToFirst;
public static void tick(MinecraftClient client) {
if (client.player == null || client.world == null || client.player.isCreative())
return;
client.player.getAbilities().allowFlying = options.enabled;
if (!options.enabled && client.player.getAbilities().flying) {
client.player.getAbilities().flying = false;
}
if (client.player.isOnGround() || !client.world.getBlockState(client.player.getBlockPos().down()).isAir()) {
tickCounter = ticksToFirst;
}
if (tickCounter-- <= 0 && !(client.player.getVelocity().getY() < 0)) {
fakeFall(client);
tickCounter = waitTicks;
}
}
public static void fakeFall(MinecraftClient client) {
if (client.player == null)
return;
Objects.requireNonNull(client.getNetworkHandler()).sendPacket(
new PlayerMoveC2SPacket.PositionAndOnGround(client.player.getX(), client.player.getY() - fallDist,
client.player.getZ(), false));
}
}

View File

@ -19,6 +19,7 @@ public class HaxxorClient implements ClientModInitializer {
public static String version = "Unknown";
private static StickyKeyBinding auto_farm_key;
private static StickyKeyBinding fly_hack_key;
private static final HaxxorOptions options = HaxxorOptions.getInstance();
@Override
@ -34,6 +35,13 @@ public class HaxxorClient implements ClientModInitializer {
() -> true
));
fly_hack_key = (StickyKeyBinding) KeyBindingHelper.registerKeyBinding(new StickyKeyBinding(
"key.haxxor.fly",
GLFW.GLFW_KEY_MINUS,
"category.haxxor.options",
() -> true
));
AutoFarmer.init();
ClientTickEvents.END_CLIENT_TICK.register(this::tick);
@ -47,7 +55,10 @@ public class HaxxorClient implements ClientModInitializer {
private void tick(MinecraftClient client) {
options.autoFarmer.enabled = auto_farm_key.isPressed();
options.flyHack.enabled = fly_hack_key.isPressed();
AutoFarmer.tick(client);
FlyHack.tick(client);
FallDamageCancel.tick(client);
}
}

View File

@ -6,6 +6,9 @@ public final class HaxxorOptions {
private static HaxxorOptions instance = null;
public final AutoFarmerOptions autoFarmer;
public final FlyHackOptions flyHack;
public boolean cancel_fall_damage = true;
public static HaxxorOptions getInstance() {
@ -17,6 +20,7 @@ public final class HaxxorOptions {
private HaxxorOptions() {
autoFarmer = new AutoFarmerOptions();
flyHack = new FlyHackOptions();
load();
}
@ -87,4 +91,8 @@ public final class HaxxorOptions {
}
}
}
public static class FlyHackOptions {
public boolean enabled;
}
}

View File

@ -1,6 +1,7 @@
package cmods.haxxor.client.ui;
import cmods.haxxor.client.HaxxorClient;
import cmods.haxxor.client.HaxxorOptions;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
@ -10,6 +11,7 @@ import net.minecraft.text.Text;
import static cmods.haxxor.client.ui.Constants.*;
public class HaxxorOptionsScreen extends Screen {
private final HaxxorOptions options = HaxxorOptions.getInstance();
private final Screen parent;
public HaxxorOptionsScreen(Screen parent) {
@ -22,6 +24,7 @@ public class HaxxorOptionsScreen extends Screen {
return;
final int column1 = this.width / 2 + column1_offset;
final int column2 = this.width / 2 + column2_offset;
final int startHeight = (int) Math.floor(this.height * startHeight_multiplier);
final int doneButtonX = this.width / 2 + doneButtonX_offset;
@ -29,6 +32,10 @@ public class HaxxorOptionsScreen extends Screen {
Text.translatable("haxxor.options.farmer"),
button -> this.client.setScreen(new FarmerOptionsScreen(this))));
this.addDrawableChild(new ToggleEnableButtonWidget(column2, startHeight, buttonWidth, buttonHeight,
Text.translatable("haxxor.options.fall_damage"), options.cancel_fall_damage,
(button, isEnabled) -> options.cancel_fall_damage = isEnabled));
this.addDrawableChild(new ButtonWidget(doneButtonX, startHeight + rowIncrement + doneButtonRowIncrement,
doneButtonWidth, buttonHeight, ScreenTexts.DONE, button -> this.client.setScreen(this.parent)));
}

View File

@ -0,0 +1,7 @@
package cmods.haxxor.client.ui;
import net.minecraft.text.Text;
public record Line(Text text, int color, int indent) {
}

View File

@ -2,7 +2,7 @@ package cmods.haxxor.mixin;
import cmods.haxxor.client.AutoFarmer;
import cmods.haxxor.client.HaxxorOptions;
import com.mojang.datafixers.util.Pair;
import cmods.haxxor.client.ui.Line;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
@ -32,7 +32,7 @@ public abstract class HudMixin extends DrawableHelper {
HaxxorOptions options = HaxxorOptions.getInstance();
TextRenderer textRenderer = this.getTextRenderer();
ArrayList<Pair<Text, Integer>> lines = new ArrayList<>();
ArrayList<Line> lines = new ArrayList<>();
int x = 5;
int y = 5;
@ -42,18 +42,29 @@ public abstract class HudMixin extends DrawableHelper {
if (options.autoFarmer.enabled) {
lines.add(new Pair<>(Text.translatable("haxxor.state.on"), green));
lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled")
.append(Text.translatable("haxxor.state.on")), green, 0));
} else {
lines.add(new Pair<>(Text.translatable("haxxor.state.off"), red));
lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled")
.append(Text.translatable("haxxor.state.off")), red, 0));
}
if (AutoFarmer.canFarm()) {
lines.add(new Pair<>(Text.translatable("haxxor.actions.available"), green));
lines.add(new Line(Text.translatable("haxxor.actions.available"), green, 1));
}
if (options.flyHack.enabled) {
lines.add(new Line(Text.translatable("haxxor.hud.fly_hack_enabled")
.append(Text.translatable("haxxor.state.on")), green, 0));
} else {
lines.add(new Line(Text.translatable("haxxor.hud.fly_hack_enabled")
.append(Text.translatable("haxxor.state.off")), red, 0));
}
for (Pair<Text, Integer> line: lines) {
DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.getFirst(), x, y, line.getSecond());
for (Line line: lines) {
DrawableHelper.drawTextWithShadow(matrices, textRenderer, line.text(), x + (5 * line.indent()), y,
line.color());
y += 10;
}
}

View File

@ -1,4 +1,7 @@
{
"haxxor.hud.auto_farm_enabled": "Auto Farm: ",
"haxxor.hud.fly_hack_enabled": "Fly Hack: ",
"haxxor.state.on": "On",
"haxxor.state.off": "Off",
"haxxor.state.enabled": "Enabled",
@ -9,6 +12,7 @@
"haxxor.options": "Haxxor",
"haxxor.options.title": "Haxxor Options",
"haxxor.options.fall_damage": "Fall Damage Cancel",
"haxxor.options.farmer": "Auto Farm",
"haxxor.options.farmer.title": "Auto Farm Options",
"haxxor.options.farmer.max_y": "Max Y Offset",
@ -22,5 +26,5 @@
"category.haxxor.options": "Haxxor",
"key.haxxor.auto_farm": "Auto Farm Toggle",
"key.haxxor.swap_items": "Swap Items"
"key.haxxor.fly": "Fly Hack Toggle"
}