diff --git a/gradle.properties b/gradle.properties index 1c0af94..5c7cde5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.19.3 yarn_mappings=1.19.3+build.2 loader_version=0.14.11 # Mod Properties -mod_version=1.2.1 +mod_version=1.2.2 maven_group=cmods archives_base_name=haxxor # Dependencies diff --git a/src/main/java/cmods/haxxor/client/FallDamageCancel.java b/src/main/java/cmods/haxxor/client/FallDamageCancel.java index 0dc0ac8..ae2b4b4 100644 --- a/src/main/java/cmods/haxxor/client/FallDamageCancel.java +++ b/src/main/java/cmods/haxxor/client/FallDamageCancel.java @@ -10,18 +10,17 @@ import java.util.Objects; public class FallDamageCancel { private static final HaxxorOptions options = HaxxorOptions.getInstance(); - private static final int triggerHeight = 6; + private static final int triggerHeight = 5; private static final float heightAdjust = 0.5f; public static void tick(MinecraftClient client) { - if (!options.cancel_fall_damage.get() || client.world == null || client.player == null || + if (!options.cancelFallDamage.get() || client.world == null || client.player == null || client.player.isCreative() || client.player.isOnGround() || client.player.getVelocity().getY() >= 0) return; BlockPos playerPos = client.player.getBlockPos(); - if (!client.world.getBlockState(playerPos.up()).isAir() || - !client.world.getBlockState(playerPos.up(2)).isAir()) { + if (!client.world.isSpaceEmpty(client.player.getBoundingBox().expand(0, heightAdjust, 0))) { return; } diff --git a/src/main/java/cmods/haxxor/client/FlyHack.java b/src/main/java/cmods/haxxor/client/FlyHack.java index 5ba7147..e3159b4 100644 --- a/src/main/java/cmods/haxxor/client/FlyHack.java +++ b/src/main/java/cmods/haxxor/client/FlyHack.java @@ -8,7 +8,7 @@ import java.util.Objects; public class FlyHack { - private static final HaxxorOptions.FlyHackOptions options = HaxxorOptions.getInstance().flyHack; + private static final HaxxorOptions options = HaxxorOptions.getInstance(); private static final int ticksToFirst = 40; private static final int waitTicks = 5; private static final float fallDist = 0.5f; @@ -19,9 +19,9 @@ public class FlyHack { if (client.player == null || client.world == null || client.player.isCreative()) return; - client.player.getAbilities().allowFlying = options.enabled.get(); + client.player.getAbilities().allowFlying = options.flyHackEnabled.get(); - if (!options.enabled.get() && client.player.getAbilities().flying) { + if (!options.flyHackEnabled.get() && client.player.getAbilities().flying) { client.player.getAbilities().flying = false; } diff --git a/src/main/java/cmods/haxxor/client/HaxxorClient.java b/src/main/java/cmods/haxxor/client/HaxxorClient.java index 5ccd9f0..913a359 100644 --- a/src/main/java/cmods/haxxor/client/HaxxorClient.java +++ b/src/main/java/cmods/haxxor/client/HaxxorClient.java @@ -57,7 +57,7 @@ public class HaxxorClient implements ClientModInitializer { private void tick(MinecraftClient client) { options.autoFarmer.enabled.set(auto_farm_key.isPressed()); - options.flyHack.enabled.set(fly_hack_key.isPressed()); + options.flyHackEnabled.set(fly_hack_key.isPressed()); AutoFarmer.tick(client); FlyHack.tick(client); diff --git a/src/main/java/cmods/haxxor/client/options/BooleanOption.java b/src/main/java/cmods/haxxor/client/options/BooleanOption.java index 2401635..b78be19 100644 --- a/src/main/java/cmods/haxxor/client/options/BooleanOption.java +++ b/src/main/java/cmods/haxxor/client/options/BooleanOption.java @@ -5,7 +5,7 @@ public class BooleanOption extends Option { super(default_value); } - public void toggle() { - value = !value; + public boolean toggle() { + return value = !value; } } diff --git a/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java b/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java index bf38438..c583094 100644 --- a/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java +++ b/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java @@ -2,6 +2,7 @@ package cmods.haxxor.client.options; import cmods.haxxor.client.AutoFarmer; import net.fabricmc.loader.api.FabricLoader; +import org.jetbrains.annotations.Nullable; import java.io.FileReader; import java.io.FileWriter; @@ -15,9 +16,10 @@ public final class HaxxorOptions { private final Path properties_file = FabricLoader.getInstance().getConfigDir().resolve("Haxxor.properties"); public final AutoFarmerOptions autoFarmer; - public final FlyHackOptions flyHack; + public final UIOptions uiOptions; - public BooleanOption cancel_fall_damage = new BooleanOption(true); + public BooleanOption flyHackEnabled = new BooleanOption(false); + public BooleanOption cancelFallDamage = new BooleanOption(true); public static HaxxorOptions getInstance() { @@ -29,7 +31,7 @@ public final class HaxxorOptions { private HaxxorOptions() { autoFarmer = new AutoFarmerOptions(); - flyHack = new FlyHackOptions(); + uiOptions = new UIOptions(); load(); } @@ -44,9 +46,10 @@ public final class HaxxorOptions { // Sub category properties autoFarmer.load(properties); + uiOptions.load(properties); // Top level properties - cancel_fall_damage.value = getBooleanProperty(properties, "cancel_fall_damage", cancel_fall_damage.value); + cancelFallDamage.value = getBooleanProperty(properties, "cancel_fall_damage", cancelFallDamage.value); } public void save() { @@ -54,9 +57,10 @@ public final class HaxxorOptions { // Sub category properties autoFarmer.save(properties); + uiOptions.save(properties); // Top level properties - properties.setProperty("cancel_fall_damage", cancel_fall_damage.value.toString()); + properties.setProperty("cancel_fall_damage", cancelFallDamage.value.toString()); try { properties.store(new FileWriter(properties_file.toFile()), "Haxxor Properties"); @@ -65,13 +69,13 @@ public final class HaxxorOptions { } } - private static boolean getBooleanProperty(Properties properties, String key, Boolean default_value) { + private static boolean getBooleanProperty(@Nullable Properties properties, String key, Boolean default_value) { if (properties == null) return default_value; return Boolean.parseBoolean(properties.getProperty(key, default_value.toString())); } - private static int getIntegerProperty(Properties properties, String key, Integer default_value) { + private static int getIntegerProperty(@Nullable Properties properties, String key, Integer default_value) { if (properties == null) return default_value; return Integer.parseInt(properties.getProperty(key, default_value.toString())); @@ -94,10 +98,11 @@ public final class HaxxorOptions { public final BooleanOption[] seeds_enabled = new BooleanOption[AutoFarmer.crops.length]; public final BooleanOption[] crops_enabled = new BooleanOption[AutoFarmer.crops.length]; + public AutoFarmerOptions() { } - private void load(Properties properties) { + private void load(@Nullable Properties properties) { move_seeds.value = getBooleanProperty(properties, PREFIX + "move_seeds", move_seeds.value); min_y.value = getIntegerProperty(properties, PREFIX + "min_y", min_y.value); max_y.value = getIntegerProperty(properties, PREFIX + "max_y", max_y.value); @@ -143,7 +148,30 @@ public final class HaxxorOptions { } } - public static class FlyHackOptions { - public BooleanOption enabled = new BooleanOption(false); + public static class UIOptions { + private final String PREFIX = "ui."; + + public BooleanOption enabled = new BooleanOption(true); + public BooleanOption show_coordinates = new BooleanOption(true); + public BooleanOption show_auto_farmer = new BooleanOption(true); + public BooleanOption show_fly_hack = new BooleanOption(true); + + + public UIOptions() { } + + + private void load(@Nullable Properties properties) { + enabled.value = getBooleanProperty(properties, PREFIX + "enabled", true); + show_coordinates.value = getBooleanProperty(properties, PREFIX + "show_coordinates", true); + show_auto_farmer.value = getBooleanProperty(properties, PREFIX + "show_auto_farmer", true); + show_fly_hack.value = getBooleanProperty(properties, PREFIX + "show_fly_hack", true); + } + + private void save(Properties properties) { + properties.setProperty(PREFIX + "enabled", enabled.value.toString()); + properties.setProperty(PREFIX + "show_coordinates", show_coordinates.value.toString()); + properties.setProperty(PREFIX + "show_auto_farmer", show_auto_farmer.value.toString()); + properties.setProperty(PREFIX + "show_fly_hack", show_fly_hack.value.toString()); + } } } diff --git a/src/main/java/cmods/haxxor/client/ui/FarmerOptionsScreen.java b/src/main/java/cmods/haxxor/client/ui/FarmerOptionsScreen.java index 36b6734..0a71425 100644 --- a/src/main/java/cmods/haxxor/client/ui/FarmerOptionsScreen.java +++ b/src/main/java/cmods/haxxor/client/ui/FarmerOptionsScreen.java @@ -4,7 +4,6 @@ import cmods.haxxor.client.HaxxorClient; import cmods.haxxor.client.options.HaxxorOptions; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.EmptyWidget; import net.minecraft.client.gui.widget.GridWidget; import net.minecraft.client.gui.widget.SimplePositioningWidget; import net.minecraft.client.util.math.MatrixStack; @@ -41,14 +40,17 @@ public class FarmerOptionsScreen extends Screen { button -> button.setMessage(HaxxorClient.toggleAutoFarmer() ? enabledText : disabledText)) .position(column1, startHeight).build()); - adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.farmer.edit_actions"), - button -> client.setScreen(new CropSelectScreen(this))) - .position(column2, startHeight).build()); + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.ui.show_farmer"), options.uiOptions.show_auto_farmer)); adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, Text.literal("Move Seeds"), options.autoFarmer.move_seeds)); - adder.add(new EmptyWidget(0, 0)); + adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.farmer.edit_actions"), + button -> client.setScreen(new CropSelectScreen(this))) + .position(column2, startHeight).build()); + +// adder.add(new EmptyWidget(0, 0)); adder.add(new IntegerAdjustWidget(Text.translatable("haxxor.options.farmer.min_y"), options.autoFarmer.min_y)); diff --git a/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java b/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java index 9b8398b..7e47782 100644 --- a/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java +++ b/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java @@ -35,7 +35,10 @@ public class HaxxorOptionsScreen extends Screen { button -> this.client.setScreen(new FarmerOptionsScreen(this))).build()); adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, - Text.translatable("haxxor.options.fall_damage"), options.cancel_fall_damage)); + Text.translatable("haxxor.options.fall_damage"), options.cancelFallDamage)); + + adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.ui"), + button -> this.client.setScreen(new UIOptionsScreen(this))).build()); adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent)) .width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement)); diff --git a/src/main/java/cmods/haxxor/client/ui/ToggleButton.java b/src/main/java/cmods/haxxor/client/ui/ToggleButton.java index 51f4553..05252c6 100644 --- a/src/main/java/cmods/haxxor/client/ui/ToggleButton.java +++ b/src/main/java/cmods/haxxor/client/ui/ToggleButton.java @@ -4,6 +4,7 @@ import cmods.haxxor.client.options.BooleanOption; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import org.apache.http.util.TextUtils; public class ToggleButton extends ButtonWidget { private final String name; @@ -20,7 +21,7 @@ public class ToggleButton extends ButtonWidget { public ToggleButton(int x, int y, int width, int height, Text name, BooleanOption option, NarrationSupplier narrationSupplier) { super(x, y, width, height, name, b -> {}, narrationSupplier); - this.name = name.getString() + ": "; + this.name = !TextUtils.isEmpty(name.getString()) ? name.getString() + ": " : ""; this.option = option; } diff --git a/src/main/java/cmods/haxxor/client/ui/UIOptionsScreen.java b/src/main/java/cmods/haxxor/client/ui/UIOptionsScreen.java new file mode 100644 index 0000000..e10cdec --- /dev/null +++ b/src/main/java/cmods/haxxor/client/ui/UIOptionsScreen.java @@ -0,0 +1,62 @@ +package cmods.haxxor.client.ui; + +import cmods.haxxor.client.options.HaxxorOptions; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.GridWidget; +import net.minecraft.client.gui.widget.SimplePositioningWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.Text; + +import static cmods.haxxor.client.ui.Constants.*; + +public class UIOptionsScreen extends Screen { + private final Screen parent; + private final HaxxorOptions options = HaxxorOptions.getInstance(); + + public UIOptionsScreen(Screen parent) { + super(Text.translatable("haxxor.options.ui.title")); + this.parent = parent; + } + + protected void init() { + if (client == null) + return; + + final int startHeight = (int) Math.floor(this.height * startHeight_multiplier); + + GridWidget grid = new GridWidget(); + grid.getMainPositioner().marginX(5).marginBottom(4).alignHorizontalCenter(); + GridWidget.Adder adder = grid.createAdder(2); + + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.ui.hud_enabled"), options.uiOptions.enabled)); + + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.ui.show_coordinates"), options.uiOptions.show_coordinates)); + + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.ui.show_farmer"), options.uiOptions.show_auto_farmer)); + + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.ui.show_fly_hack"), options.uiOptions.show_fly_hack)); + + adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(parent)) + .width(doneButtonWidth).build(), 2, adder.copyPositioner().marginTop(doneButtonRowIncrement)); + + grid.recalculateDimensions(); + SimplePositioningWidget.setPos(grid, 0, startHeight, this.width, this.height, 0.5f, 0.0f); + addDrawableChild(grid); + } + + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + this.renderBackground(matrices); + drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xffffff); + super.render(matrices, mouseX, mouseY, delta); + } + + public void removed() { + options.save(); + } +} diff --git a/src/main/java/cmods/haxxor/mixin/HudMixin.java b/src/main/java/cmods/haxxor/mixin/HudMixin.java index bed0ab9..7369947 100644 --- a/src/main/java/cmods/haxxor/mixin/HudMixin.java +++ b/src/main/java/cmods/haxxor/mixin/HudMixin.java @@ -9,6 +9,7 @@ import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -27,38 +28,53 @@ public abstract class HudMixin extends DrawableHelper { @Inject(at = @At("TAIL"), method = "render") private void render(MatrixStack matrices, float tickDelta, CallbackInfo callback) { - if (this.client.options.debugEnabled || this.client.isPaused() || client.player == null) - return; - HaxxorOptions options = HaxxorOptions.getInstance(); + + if (this.client.options.debugEnabled || this.client.isPaused() || client.player == null || + !options.uiOptions.enabled.get()) { + return; + } + TextRenderer textRenderer = this.getTextRenderer(); ArrayList lines = new ArrayList<>(); int x = 5; int y = 5; + int white = 0xffffff; int red = 0xff0000; int green = 0x00ff00; - if (options.autoFarmer.enabled.get()) { - lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled") - .append(Text.translatable("haxxor.state.on")), green, 0)); - } else { - lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled") - .append(Text.translatable("haxxor.state.off")), red, 0)); + if (options.uiOptions.show_coordinates.get()) { + BlockPos pos = client.player.getBlockPos(); + String coordinate_string = String.format("X: %d, Y: %d, Z: %d", pos.getX(), pos.getY(), pos.getZ()); + lines.add(new Line(Text.literal(coordinate_string), white, 0)); } - if (AutoFarmer.canFarm()) { - lines.add(new Line(Text.translatable("haxxor.actions.available"), green, 1)); - } - if (options.flyHack.enabled.get()) { - 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)); + if (options.uiOptions.show_auto_farmer.get()) { + if (options.autoFarmer.enabled.get()) { + lines.add(new Line(Text.translatable("haxxor.hud.auto_farm_enabled") + .append(Text.translatable("haxxor.state.on")), green, 0)); + } else { + 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 Line(Text.translatable("haxxor.actions.available"), green, 1)); + } + } + + if (options.uiOptions.show_fly_hack.get()) { + if (options.flyHackEnabled.get()) { + 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)); + } } diff --git a/src/main/resources/assets/haxxor/lang/en_us.json b/src/main/resources/assets/haxxor/lang/en_us.json index 0f0ef0d..301a3ee 100644 --- a/src/main/resources/assets/haxxor/lang/en_us.json +++ b/src/main/resources/assets/haxxor/lang/en_us.json @@ -12,7 +12,17 @@ "haxxor.options": "Haxxor", "haxxor.options.title": "Haxxor Options", + "haxxor.options.fall_damage": "Fall Damage Cancel", + "haxxor.options.fall_damage.title": "Fall Damage Cancel Options", + + "haxxor.options.ui": "UI", + "haxxor.options.ui.title": "UI Options", + "haxxor.options.ui.hud_enabled": "Show HUD", + "haxxor.options.ui.show_coordinates": "Show Coordinates", + "haxxor.options.ui.show_farmer": "Auto Farmer UI", + "haxxor.options.ui.show_fly_hack": "Fly Hack UI", + "haxxor.options.farmer": "Auto Farm", "haxxor.options.farmer.title": "Auto Farm Options", "haxxor.options.farmer.max_y": "Max Y Offset",