From 4c8404d30616583b2eef0c44f7aebadcf2f12b89 Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 16 May 2024 03:52:34 +0200 Subject: [PATCH] refactor: combined Bulldozer and YouInjectButton mixin into one mixin each Signed-off-by: moonleay --- .../moonleay/gimbal/mixin/BulldozerMixin.java | 59 +++++++++---- .../gimbal/mixin/BulldozerMixin2.java | 52 ------------ .../gimbal/mixin/YouInjectButtonMixin.java | 85 +++++++++++++------ .../gimbal/mixin/YouInjectButtonMixin2.java | 66 -------------- src/main/resources/gimbal.mixins.json | 8 +- 5 files changed, 106 insertions(+), 164 deletions(-) delete mode 100644 src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin2.java delete mode 100644 src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin2.java diff --git a/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin.java b/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin.java index a89604a..df682c2 100644 --- a/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin.java +++ b/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin.java @@ -20,9 +20,13 @@ package net.moonleay.gimbal.mixin; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.moonleay.gimbal.client.editor.ClientEditor; import net.moonleay.gimbal.editor.state.mode.Capability; import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -32,30 +36,49 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Objects; -@Mixin(MinecraftClient.class) public abstract class BulldozerMixin { - @Shadow protected int attackCooldown; + @Mixin(MinecraftClient.class) + public static abstract class MinecraftClientMixin { + @Shadow + @Nullable + public ClientPlayerEntity player; + @Shadow + protected int attackCooldown; - @Shadow - @Nullable - public ClientPlayerEntity player; - - @Inject(method = "doAttack", at = @At(value = "HEAD")) - private void func(CallbackInfoReturnable cir) { - if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !Objects.requireNonNull(this.player).isCreative()) { - return; + @Inject(method = "doAttack", at = @At(value = "HEAD")) + private void func(CallbackInfoReturnable cir) { + if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !Objects.requireNonNull(this.player).isCreative()) { + return; + } + this.attackCooldown = 0; + } + + @Inject(method = "handleBlockBreaking", at = @At(value = "HEAD")) + private void func2(boolean breaking, CallbackInfo ci) { + if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !breaking || !Objects.requireNonNull(this.player).isCreative()) { + return; + } + this.attackCooldown = 0; } - this.attackCooldown = 0; } - @Inject(method = "handleBlockBreaking", at = @At(value = "HEAD")) - private void func2(boolean breaking, CallbackInfo ci) { - if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !breaking || !Objects.requireNonNull(this.player).isCreative()) { - return; + @Mixin(ClientPlayerInteractionManager.class) + public static abstract class ClientPlayerInteractionManagerMixin { + + @Shadow + private int blockBreakingCooldown; + + @Shadow + @Final + private MinecraftClient client; + + @Inject(method = "updateBlockBreakingProgress", at = @At("HEAD")) + private void func(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !Objects.requireNonNull(this.client.player).isCreative()) { + return; + } + this.blockBreakingCooldown = 0; } - this.attackCooldown = 0; } - - } diff --git a/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin2.java b/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin2.java deleted file mode 100644 index 19f1378..0000000 --- a/src/main/java/net/moonleay/gimbal/mixin/BulldozerMixin2.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Gimbal - * Copyright (C) 2024 moonleay - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.moonleay.gimbal.mixin; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.moonleay.gimbal.client.editor.ClientEditor; -import net.moonleay.gimbal.editor.state.mode.Capability; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Objects; - -@Mixin(ClientPlayerInteractionManager.class) -public class BulldozerMixin2 { - - @Shadow private int blockBreakingCooldown; - - @Shadow - @Final - private MinecraftClient client; - - @Inject(method = "updateBlockBreakingProgress", at = @At("HEAD")) - private void func(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { - if (!ClientEditor.INSTANCE.shouldClient(Capability.BULLDOZER) || !Objects.requireNonNull(this.client.player).isCreative()) { - return; - } - this.blockBreakingCooldown = 0; - } -} diff --git a/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin.java b/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin.java index f86f610..efa2a9c 100644 --- a/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin.java +++ b/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin.java @@ -20,6 +20,7 @@ package net.moonleay.gimbal.mixin; import net.minecraft.client.gui.screen.GameMenuScreen; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.client.gui.widget.TexturedButtonWidget; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -33,35 +34,71 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(GameMenuScreen.class) // What is my purpose? -public class YouInjectButtonMixin extends Screen { +public class YouInjectButtonMixin { // Go my god. - @Unique - private static final Identifier GIMBAL_TEXTURE = new Identifier(BuildConstants.modId, "textures/gimbal_options_texture_button.png"); + @Mixin(TitleScreen.class) + public static abstract class TitleScreenMixin extends Screen { - protected YouInjectButtonMixin(Text title) { - super(title); + @Unique + private static final Identifier GIMBAL_TEXTURE = new Identifier(BuildConstants.modId, "textures/gimbal_options_texture_button.png"); + + protected TitleScreenMixin(Text title) { + super(title); + } + + @Inject(method = "init", at = @At(value = "RETURN")) + private void func(CallbackInfo ci) { + int l = this.height / 4 + 48; + this.addDrawableChild( + new TexturedButtonWidget( + this.width / 2 - 124 - 24, + l + 72 + 12, + 20, + 20, + 0, + 0, + 20, + GIMBAL_TEXTURE, + 20, + 40, + button -> this.client.setScreen(new GimbalSettingsGui(this, ClientMain.CONFIG)), + Text.translatable(TranslationKeys.Gui.Config.SCREEN_NAME) + ) + ); + } } - @Inject(method = "initWidgets", at = @At(value = "RETURN")) - private void func(CallbackInfo ci) { - this.addDrawableChild( - new TexturedButtonWidget( - this.width / 2 - 124, - this.height / 4 + 96 + -16, - 20, - 20, - 0, - 0, - 20, - GIMBAL_TEXTURE, - 20, - 40, - button -> this.client.setScreen(new GimbalSettingsGui(this, ClientMain.CONFIG)), - Text.translatable(TranslationKeys.Gui.Config.SCREEN_NAME) - ) - ); + + @Mixin(GameMenuScreen.class) + public static abstract class GameMenuScreenMixin extends Screen { + @Unique + private static final Identifier GIMBAL_TEXTURE = new Identifier(BuildConstants.modId, "textures/gimbal_options_texture_button.png"); + + protected GameMenuScreenMixin(Text title) { + super(title); + } + + @Inject(method = "initWidgets", at = @At(value = "RETURN")) + private void func(CallbackInfo ci) { + this.addDrawableChild( + new TexturedButtonWidget( + this.width / 2 - 124, + this.height / 4 + 96 + -16, + 20, + 20, + 0, + 0, + 20, + GIMBAL_TEXTURE, + 20, + 40, + button -> this.client.setScreen(new GimbalSettingsGui(this, ClientMain.CONFIG)), + Text.translatable(TranslationKeys.Gui.Config.SCREEN_NAME) + ) + ); + } } + } diff --git a/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin2.java b/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin2.java deleted file mode 100644 index b25789d..0000000 --- a/src/main/java/net/moonleay/gimbal/mixin/YouInjectButtonMixin2.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Gimbal - * Copyright (C) 2024 moonleay - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.moonleay.gimbal.mixin; - -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.TitleScreen; -import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.moonleay.gimbal.build.BuildConstants; -import net.moonleay.gimbal.client.ClientMain; -import net.moonleay.gimbal.client.screen.GimbalSettingsGui; -import net.moonleay.gimbal.constants.TranslationKeys; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TitleScreen.class) -public class YouInjectButtonMixin2 extends Screen { - - @Unique - private static final Identifier GIMBAL_TEXTURE = new Identifier(BuildConstants.modId, "textures/gimbal_options_texture_button.png"); - - protected YouInjectButtonMixin2(Text title) { - super(title); - } - - @Inject(method = "init", at = @At(value = "RETURN")) - private void func(CallbackInfo ci) { - int l = this.height / 4 + 48; - this.addDrawableChild( - new TexturedButtonWidget( - this.width / 2 - 124 - 24, - l + 72 + 12, - 20, - 20, - 0, - 0, - 20, - GIMBAL_TEXTURE, - 20, - 40, - button -> this.client.setScreen(new GimbalSettingsGui(this, ClientMain.CONFIG)), - Text.translatable(TranslationKeys.Gui.Config.SCREEN_NAME) - ) - ); - } -} diff --git a/src/main/resources/gimbal.mixins.json b/src/main/resources/gimbal.mixins.json index 479b9ab..b383149 100644 --- a/src/main/resources/gimbal.mixins.json +++ b/src/main/resources/gimbal.mixins.json @@ -11,13 +11,13 @@ "ReplaceStateUpdaterMixin" ], "client": [ - "BulldozerMixin", - "BulldozerMixin2", + "BulldozerMixin$ClientPlayerInteractionManagerMixin", + "BulldozerMixin$MinecraftClientMixin", "HudMixin", "NoClipCameraFixMixin", "NormalModeMixin", - "YouInjectButtonMixin", - "YouInjectButtonMixin2" + "YouInjectButtonMixin$GameMenuScreenMixin", + "YouInjectButtonMixin$TitleScreenMixin" ], "injectors": { "defaultRequire": 1