diff --git a/src/main/java/cmods/haxxor/HaxxorModule.java b/src/main/java/cmods/haxxor/HaxxorModule.java index e23de6a..55a90ff 100644 --- a/src/main/java/cmods/haxxor/HaxxorModule.java +++ b/src/main/java/cmods/haxxor/HaxxorModule.java @@ -9,6 +9,7 @@ import cmods.haxxor.client.AutoFarmer; import cmods.haxxor.client.options.HaxxorOptions; import cmods.haxxor.client.ui.ElevatorOptionsScreen; import cmods.haxxor.client.ui.FarmerOptionsScreen; +import cmods.haxxor.client.ui.GlowOptionsScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; @@ -39,6 +40,9 @@ public class HaxxorModule extends Module { optionButtons.add(((screen, client) -> ButtonWidget.builder(Text.translatable("haxxor.options.elevator"), button -> client.setScreen(new ElevatorOptionsScreen(screen))).build())); + optionButtons.add(((screen, client) -> ButtonWidget.builder(Text.translatable("haxxor.options.glow"), + button -> client.setScreen(new GlowOptionsScreen(screen))).build())); + optionButtons.add((screen, client) -> new ToggleButton(0, 0, buttonWidth, buttonHeight, Text.translatable("haxxor.options.fall_damage"), options.cancelFallDamage)); diff --git a/src/main/java/cmods/haxxor/client/HaxxorClient.java b/src/main/java/cmods/haxxor/client/HaxxorClient.java index bec12e8..de47bc7 100644 --- a/src/main/java/cmods/haxxor/client/HaxxorClient.java +++ b/src/main/java/cmods/haxxor/client/HaxxorClient.java @@ -22,6 +22,7 @@ public class HaxxorClient implements ClientModInitializer { private static StickyKeyBinding auto_farm_key; private static StickyKeyBinding fly_hack_key; + private static StickyKeyBinding glow_key; private static final HaxxorOptions options = HaxxorOptions.getInstance(); @Override @@ -46,6 +47,13 @@ public class HaxxorClient implements ClientModInitializer { () -> true )); + glow_key = (StickyKeyBinding) KeyBindingHelper.registerKeyBinding(new StickyKeyBinding( + "key.haxxor.glow", + -1, + "category.haxxor.options", + () -> true + )); + AutoFarmer.init(); Elevator.init(); @@ -59,9 +67,17 @@ public class HaxxorClient implements ClientModInitializer { return options.autoFarmer.enabled.get(); } + public static boolean toggleGlow() { + glow_key.setPressed(true); + options.glow.enabled.set(glow_key.isPressed()); + + return options.glow.enabled.get(); + } + private void tick(MinecraftClient client) { options.autoFarmer.enabled.set(auto_farm_key.isPressed()); options.flyHackEnabled.set(fly_hack_key.isPressed()); + options.glow.enabled.set(glow_key.isPressed()); AutoFarmer.tick(client); Elevator.tick(client); diff --git a/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java b/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java index 0d6a777..cdf94c9 100644 --- a/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java +++ b/src/main/java/cmods/haxxor/client/options/HaxxorOptions.java @@ -19,6 +19,7 @@ public final class HaxxorOptions extends ModuleOptions { public final AutoFarmerOptions autoFarmer; public final UIOptions uiOptions; public final ElevatorOptions elevatorOptions; + public final GlowOptions glow; public final BooleanOption flyHackEnabled = new BooleanOption(false); public final BooleanOption cancelFallDamage = new BooleanOption(true); @@ -36,6 +37,7 @@ public final class HaxxorOptions extends ModuleOptions { autoFarmer = new AutoFarmerOptions(); uiOptions = new UIOptions(); elevatorOptions = new ElevatorOptions(); + glow = new GlowOptions(); } public void load(@Nullable Properties properties) { @@ -43,6 +45,7 @@ public final class HaxxorOptions extends ModuleOptions { autoFarmer.load(properties); uiOptions.load(properties); elevatorOptions.load(properties); + glow.load(properties); // Top level properties cancelFallDamage.value = getBooleanProperty(properties, "cancel_fall_damage", cancelFallDamage.value); @@ -53,6 +56,7 @@ public final class HaxxorOptions extends ModuleOptions { autoFarmer.save(properties); uiOptions.save(properties); elevatorOptions.save(properties); + glow.save(properties); // Top level properties properties.setProperty("cancel_fall_damage", cancelFallDamage.value.toString()); @@ -172,4 +176,21 @@ public final class HaxxorOptions extends ModuleOptions { properties.setProperty(PREFIX + "max_tp_down", max_tp_down.value.toString()); } } + + public static class GlowOptions { + private final String PREFIX = MODULE_PREFIX + "glow."; + + public final BooleanOption enabled = new BooleanOption(false); + public final BooleanOption include_non_living = new BooleanOption(false); + + GlowOptions() { } + + private void load(@Nullable Properties properties) { + include_non_living.value = getBooleanProperty(properties, PREFIX + "include_non_living", include_non_living.value); + } + + private void save(Properties properties) { + properties.setProperty(PREFIX + "include_non_living", include_non_living.value.toString()); + } + } } diff --git a/src/main/java/cmods/haxxor/client/ui/GlowOptionsScreen.java b/src/main/java/cmods/haxxor/client/ui/GlowOptionsScreen.java new file mode 100644 index 0000000..ddf312c --- /dev/null +++ b/src/main/java/cmods/haxxor/client/ui/GlowOptionsScreen.java @@ -0,0 +1,67 @@ +package cmods.haxxor.client.ui; + +import cmods.cmods.client.options.CmodsOptions; +import cmods.cmods.client.ui.ToggleButton; +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.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.cmods.client.ui.Constants.*; + +public class GlowOptionsScreen extends Screen { + private final Screen parent; + private final CmodsOptions global_options = CmodsOptions.getInstance(); + private final HaxxorOptions.GlowOptions options = HaxxorOptions.getInstance().glow; + + public GlowOptionsScreen(Screen parent) { + super(Text.translatable("haxxor.options.glow.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(ButtonWidget.builder( + Text.translatable("haxxor.options.glow.enabled", options.enabled.get() ? + Text.translatable("haxxor.state.enabled") : + Text.translatable("haxxor.state.disabled")), + button -> button.setMessage( + Text.translatable("haxxor.options.glow.enabled", HaxxorClient.toggleGlow() ? + Text.translatable("haxxor.state.enabled") : + Text.translatable("haxxor.state.disabled")) + )).build()); + + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, + Text.translatable("haxxor.options.glow.include_non_living"), options.include_non_living)); + + 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() { + global_options.save(); + } +} diff --git a/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java b/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java index 93309a6..b108473 100644 --- a/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java +++ b/src/main/java/cmods/haxxor/client/ui/HaxxorOptionsScreen.java @@ -43,6 +43,9 @@ public class HaxxorOptionsScreen extends Screen { adder.add(ButtonWidget.builder(Text.translatable("haxxor.options.elevator"), button -> this.client.setScreen(new ElevatorOptionsScreen(this))).build()); + adder.add((ButtonWidget.builder(Text.translatable("haxxor.options.glow"), + button -> client.setScreen(new GlowOptionsScreen(this))).build())); + adder.add(new ToggleButton(0, 0, buttonWidth, buttonHeight, Text.translatable("haxxor.options.fall_damage"), options.cancelFallDamage)); diff --git a/src/main/java/cmods/haxxor/mixin/GlobalGlow.java b/src/main/java/cmods/haxxor/mixin/GlobalGlow.java new file mode 100644 index 0000000..76a6dec --- /dev/null +++ b/src/main/java/cmods/haxxor/mixin/GlobalGlow.java @@ -0,0 +1,20 @@ +package cmods.haxxor.mixin; + +import cmods.haxxor.client.options.HaxxorOptions; +import net.minecraft.entity.LivingEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(LivingEntity.class) +public class GlobalGlow { + private static final HaxxorOptions options = HaxxorOptions.getInstance(); + + @Inject(method = "isGlowing()Z", at = @At("RETURN"), cancellable = true) + private void isGlowingOverride(CallbackInfoReturnable cir) { + if (options.glow.enabled.get()) { + cir.setReturnValue(true); + } + } +} diff --git a/src/main/java/cmods/haxxor/mixin/GlobalGlowAll.java b/src/main/java/cmods/haxxor/mixin/GlobalGlowAll.java new file mode 100644 index 0000000..d65c643 --- /dev/null +++ b/src/main/java/cmods/haxxor/mixin/GlobalGlowAll.java @@ -0,0 +1,20 @@ +package cmods.haxxor.mixin; + +import cmods.haxxor.client.options.HaxxorOptions; +import net.minecraft.entity.Entity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Entity.class) +public class GlobalGlowAll { + private static final HaxxorOptions options = HaxxorOptions.getInstance(); + + @Inject(method = "isGlowing()Z", at = @At("RETURN"), cancellable = true) + private void isGlowingOverride(CallbackInfoReturnable cir) { + if (options.glow.enabled.get() && options.glow.include_non_living.get()) { + cir.setReturnValue(true); + } + } +} diff --git a/src/main/resources/assets/haxxor/lang/en_us.json b/src/main/resources/assets/haxxor/lang/en_us.json index 343486a..cd4702d 100644 --- a/src/main/resources/assets/haxxor/lang/en_us.json +++ b/src/main/resources/assets/haxxor/lang/en_us.json @@ -19,6 +19,11 @@ "haxxor.options.fall_damage": "Fall Damage Cancel", "haxxor.options.fall_damage.title": "Fall Damage Cancel Options", + "haxxor.options.glow": "Glow", + "haxxor.options.glow.title": "Glow Options", + "haxxor.options.glow.enabled": "Glow: %s", + "haxxor.options.glow.include_non_living": "Include Non-Living", + "haxxor.options.ui": "UI", "haxxor.options.ui.title": "UI Options", "haxxor.options.ui.hud_enabled": "Show HUD", @@ -45,8 +50,9 @@ "haxxor.options.elevator.max_tp_down": "Max Tp Down", "category.haxxor.options": "Haxxor", - "key.haxxor.auto_farm": "Auto Farm Toggle", - "key.haxxor.fly": "Fly Hack Toggle", + "key.haxxor.auto_farm": "Auto Farm", + "key.haxxor.fly": "Fly Hack", + "key.haxxor.glow": "Global Glow", "key.haxxor.elevator.up": "Teleport Up", "key.haxxor.elevator.down": "Teleport Down" } \ No newline at end of file diff --git a/src/main/resources/haxxor.mixins.json b/src/main/resources/haxxor.mixins.json index 92c623a..c76c07c 100644 --- a/src/main/resources/haxxor.mixins.json +++ b/src/main/resources/haxxor.mixins.json @@ -4,6 +4,8 @@ "package": "cmods.haxxor.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "GlobalGlow", + "GlobalGlowAll" ], "client": [], "injectors": {