|
| 1 | +/* |
| 2 | + * This program is free software; you can redistribute it and/or |
| 3 | + * modify it under the terms of the GNU Lesser General Public |
| 4 | + * License as published by the Free Software Foundation; either |
| 5 | + * version 3 of the License, or (at your option) any later version. |
| 6 | + * |
| 7 | + * This program is distributed in the hope that it will be useful, |
| 8 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 | + * Lesser General Public License for more details. |
| 11 | + * |
| 12 | + * You should have received a copy of the GNU Lesser General Public License |
| 13 | + * along with this program; if not, write to the Free Software Foundation, |
| 14 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 15 | + * |
| 16 | + * For more information, see the LICENSE file. |
| 17 | + */ |
| 18 | + |
| 19 | +package io.github.axolotlclient.oldanimations.mixin; |
| 20 | + |
| 21 | +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; |
| 22 | +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; |
| 23 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 24 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 25 | +import io.github.axolotlclient.oldanimations.OldAnimations; |
| 26 | +import io.github.axolotlclient.oldanimations.util.DebugComponents; |
| 27 | +import net.minecraft.client.Minecraft; |
| 28 | +import net.minecraft.client.gui.GuiElement; |
| 29 | +import net.minecraft.client.gui.overlay.DebugOverlay; |
| 30 | +import net.minecraft.client.render.TextRenderer; |
| 31 | +import org.objectweb.asm.Opcodes; |
| 32 | +import org.spongepowered.asm.mixin.Final; |
| 33 | +import org.spongepowered.asm.mixin.Mixin; |
| 34 | +import org.spongepowered.asm.mixin.Shadow; |
| 35 | +import org.spongepowered.asm.mixin.injection.At; |
| 36 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 37 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 38 | + |
| 39 | +import java.util.List; |
| 40 | + |
| 41 | +@Mixin(DebugOverlay.class) |
| 42 | +public abstract class DebugOverlayMixin { |
| 43 | + |
| 44 | + @Shadow |
| 45 | + @Final |
| 46 | + private TextRenderer textRenderer; |
| 47 | + |
| 48 | + @ModifyExpressionValue(method = "getGameInfo", at = @At(value = "CONSTANT", args = "stringValue=Minecraft 1.8.9 (")) |
| 49 | + private String axolotlclient$spoofDebugVersion(String original) { |
| 50 | + /* nostalgiaaaa */ |
| 51 | + return OldAnimations.isEnabled() && OldAnimations.getInstance().show1_7_10.get() ? "Minecraft 1.7.10 (" : original; |
| 52 | + } |
| 53 | + |
| 54 | + @WrapOperation(method = "getGameInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getGameVersion()Ljava/lang/String;")) |
| 55 | + private String axolotlclient$spoofDebugVersion2(Minecraft instance, Operation<String> original) { |
| 56 | + /* why does it show the game version twice!!?? */ |
| 57 | + return OldAnimations.isEnabled() && OldAnimations.getInstance().show1_7_10.get() ? "1.7.10" : original.call(instance); |
| 58 | + } |
| 59 | + |
| 60 | + @ModifyExpressionValue(method = "drawGameInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/overlay/DebugOverlay;getGameInfo()Ljava/util/List;")) |
| 61 | + private List<String> axolotlclient$replaceGameInfo(List<String> original) { |
| 62 | + return OldAnimations.isEnabled() && OldAnimations.getInstance().debugInfo.get() ? DebugComponents.getLeft() : original; |
| 63 | + } |
| 64 | + |
| 65 | + @Inject(method = "drawGameInfo", at = @At("TAIL"), remap = false) |
| 66 | + private void axolotlclient$addBottomLeftColumn(CallbackInfo ci) { |
| 67 | + if (OldAnimations.isEnabled() && OldAnimations.getInstance().debugInfo.get()) { |
| 68 | + /* renders the bottom left column of debug text, but in the greyish color just like 1.7 */ |
| 69 | + final int fontHeight = textRenderer.fontHeight - (OldAnimations.getInstance().debugTextSpacing.get() ? 1 : 0); |
| 70 | + int top = DebugComponents.getLeft().size() * 10 + 4 /* should be 64, just like 1.7 */; |
| 71 | + for (String msg : DebugComponents.getLeftBottom()) { |
| 72 | + if (msg == null) continue; |
| 73 | + if (!OldAnimations.getInstance().disableDebugBackground.get()) { |
| 74 | + GuiElement.fill(1, top - 1, 2 + textRenderer.getWidth(msg) + 1, top + fontHeight - 1, -1873784752); |
| 75 | + } |
| 76 | + textRenderer.draw(msg, 2, top, 14737632, OldAnimations.getInstance().debugTextShadow.get()); |
| 77 | + top += fontHeight; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @ModifyExpressionValue(method = "drawSystemInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/overlay/DebugOverlay;getSystemInfo()Ljava/util/List;")) |
| 83 | + private List<String> axolotlclient$replaceSystemInfo(List<String> original) { |
| 84 | + return OldAnimations.isEnabled() && OldAnimations.getInstance().debugInfo.get() ? DebugComponents.getRight() : original; |
| 85 | + } |
| 86 | + |
| 87 | + @WrapOperation(method = {"drawGameInfo", "drawSystemInfo"}, at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/client/render/TextRenderer;fontHeight:I")) |
| 88 | + private int axolotlclient$changeFontHeight(TextRenderer instance, Operation<Integer> original) { |
| 89 | + return OldAnimations.isEnabled() && OldAnimations.getInstance().debugTextSpacing.get() ? 10 : original.call(instance); |
| 90 | + } |
| 91 | + |
| 92 | + @WrapWithCondition(method = {"drawGameInfo", "drawSystemInfo"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/overlay/DebugOverlay;fill(IIIII)V")) |
| 93 | + private boolean axolotlclient$removeBackgroundRectangle(int left, int top, int right, int bottom, int color) { |
| 94 | + /* disable rendering the rectangular background, just like 1.7 */ |
| 95 | + return !OldAnimations.isEnabled() || !OldAnimations.getInstance().disableDebugBackground.get(); |
| 96 | + } |
| 97 | + |
| 98 | + @WrapOperation(method = "drawSystemInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/TextRenderer;draw(Ljava/lang/String;III)I")) |
| 99 | + private int axolotlclient$addTextShadow(TextRenderer instance, String text, int x, int y, int color, Operation<Integer> original) { |
| 100 | + /* uses the alternative drawString method which allows text shadows, just like in 1.7 */ |
| 101 | + return instance.draw(text, x, y, color, OldAnimations.isEnabled() && OldAnimations.getInstance().debugTextShadow.get()); |
| 102 | + } |
| 103 | + |
| 104 | + @WrapOperation(method = "drawGameInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/TextRenderer;draw(Ljava/lang/String;III)I")) |
| 105 | + private int axolotlclient$addTextShadow2(TextRenderer instance, String text, int x, int y, int color, Operation<Integer> original) { |
| 106 | + /* same as above redirect, but the text is white, just like in 1.7 */ |
| 107 | + int textColor = OldAnimations.isEnabled() && OldAnimations.getInstance().debugTextColorScheme.get() ? 16777215 : 0xE0E0E0; |
| 108 | + return instance.draw(text, x, y, textColor, OldAnimations.isEnabled() && OldAnimations.getInstance().debugTextShadow.get()); |
| 109 | + } |
| 110 | +} |
0 commit comments