Add UI options and Coordinate UI
This commit is contained in:
parent
55425da586
commit
811e8fc6a3
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -5,7 +5,7 @@ public class BooleanOption extends Option<Boolean> {
|
||||
super(default_value);
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
value = !value;
|
||||
public boolean toggle() {
|
||||
return value = !value;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
62
src/main/java/cmods/haxxor/client/ui/UIOptionsScreen.java
Normal file
62
src/main/java/cmods/haxxor/client/ui/UIOptionsScreen.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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<Line> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user