Port ingame hud changes

This commit is contained in:
FlorianMichael 2024-04-27 00:48:37 +02:00
parent 5ef8d1bae4
commit 7fc46c4854
3 changed files with 90 additions and 4 deletions

View File

@ -48,8 +48,7 @@ import java.util.concurrent.CompletableFuture;
* - Older versions don't clamp positions when teleporting (Is this important?) * - Older versions don't clamp positions when teleporting (Is this important?)
* *
* TODO | Port * TODO | Port
* - Readd MixinCustomPayloadS2CPacket, MixinInGameHud * - Readd MixinCustomPayloadS2CPacket
* - Test bedrock transfer
* - Readd item fixes: MixinItemStack, MixinDrawContext, MixinPacketByteBuf * - Readd item fixes: MixinItemStack, MixinDrawContext, MixinPacketByteBuf
*/ */
public class ViaFabricPlus { public class ViaFabricPlus {

View File

@ -0,0 +1,86 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* 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 <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.screen.hud;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
@Mixin(InGameHud.class)
public abstract class MixinInGameHud {
// Removing newer elements
@Inject(method = {"renderMountJumpBar", "renderMountHealth"}, at = @At("HEAD"), cancellable = true)
private void removeMountJumpBar(CallbackInfo ci) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
ci.cancel();
}
}
@Inject(method = "getHeartCount", at = @At("HEAD"), cancellable = true)
private void removeHungerBar(LivingEntity entity, CallbackInfoReturnable<Integer> cir) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
cir.setReturnValue(1);
}
}
// Moving down all remaining elements
@ModifyExpressionValue(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;getScaledWindowHeight()I"), require = 0)
private int moveHealthDown(int value) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return value + 6;
} else {
return value;
}
}
@ModifyArgs(method = "renderArmor", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), require = 0)
private static void moveArmorPositions(Args args, @Local(argsOnly = true) DrawContext context) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
final int x = args.get(1);
final int y = args.get(2);
args.set(1, context.getScaledWindowWidth() - x - 9);
args.set(2, y + 9);
}
}
@ModifyArg(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"), slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", ordinal = 2),
to = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;pop()V")), index = 1, require = 0)
private int moveAir(int value, @Local(argsOnly = true) DrawContext context) {
if (VisualSettings.global().removeNewerHudElements.isEnabled()) {
return context.getScaledWindowWidth() - value - 9;
} else {
return value;
}
}
}

View File

@ -124,6 +124,7 @@
"fixes.minecraft.item.MixinItemGroups", "fixes.minecraft.item.MixinItemGroups",
"fixes.minecraft.item.MixinItemPlacementContext", "fixes.minecraft.item.MixinItemPlacementContext",
"fixes.minecraft.item.MixinItemRenderer", "fixes.minecraft.item.MixinItemRenderer",
"fixes.minecraft.item.MixinItemStack",
"fixes.minecraft.item.MixinShovelItem", "fixes.minecraft.item.MixinShovelItem",
"fixes.minecraft.item.MixinSwordItem", "fixes.minecraft.item.MixinSwordItem",
"fixes.minecraft.network.MixinChatMessageC2SPacket", "fixes.minecraft.network.MixinChatMessageC2SPacket",
@ -149,6 +150,7 @@
"fixes.minecraft.screen.MixinScreen", "fixes.minecraft.screen.MixinScreen",
"fixes.minecraft.screen.MixinStructureBlockScreen_1", "fixes.minecraft.screen.MixinStructureBlockScreen_1",
"fixes.minecraft.screen.hud.MixinChatHud", "fixes.minecraft.screen.hud.MixinChatHud",
"fixes.minecraft.screen.hud.MixinInGameHud",
"fixes.minecraft.screen.screenhandler.MixinAbstractFurnaceScreenHandler", "fixes.minecraft.screen.screenhandler.MixinAbstractFurnaceScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot", "fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot",
"fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler", "fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler",
@ -191,8 +193,7 @@
"viabedrock.MixinBedrockProtocol", "viabedrock.MixinBedrockProtocol",
"viabedrock.MixinJoinPackets", "viabedrock.MixinJoinPackets",
"vialegacy.MixinExtensionProtocolMetadataStorage", "vialegacy.MixinExtensionProtocolMetadataStorage",
"vialegacy.MixinViaLegacyConfig", "vialegacy.MixinViaLegacyConfig"
"fixes.minecraft.item.MixinItemStack"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1