vanilla-fixes

Minecraft: Better than Adventure! mod that fixes some issues
git clone git://memoryshards.xyz/vanilla-fixes.git
Log | Files | Refs | README | LICENSE

commit 06591d3f2d9aed250e425c115114651d34d3cfb6
parent 86680cc17ca90ccb3517bfd52baa46aed7949f35
Author: Amb0s <ambos@disroot.org>
Date:   Fri, 11 Aug 2023 07:26:22 +0200

Added tweaks

- Fixed BTA! version display
- Added item durability and damage to the tooltip
- Reduced block hit delay
- Changed minecraft directories paths

Diffstat:
Asrc/main/java/turniplabs/vanillafixes/mixin/GlobalMixin.java | 15+++++++++++++++
Asrc/main/java/turniplabs/vanillafixes/mixin/GuiTooltipMixin.java | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/main/java/turniplabs/vanillafixes/mixin/MinecraftMixin.java | 29+++++++++++++++++++++++++++++
Asrc/main/java/turniplabs/vanillafixes/mixin/PlayerControllerMixin.java | 21+++++++++++++++++++++
Asrc/main/java/turniplabs/vanillafixes/mixin/SoundManagerMixin.java | 25+++++++++++++++++++++++++
Asrc/main/java/turniplabs/vanillafixes/mixin/ToolMaterialMixin.java | 19+++++++++++++++++++
Msrc/main/resources/vanillafixes.mixins.json | 30++++++++++++++++++------------
7 files changed, 207 insertions(+), 12 deletions(-)

diff --git a/src/main/java/turniplabs/vanillafixes/mixin/GlobalMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/GlobalMixin.java @@ -0,0 +1,15 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.core.Global; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = Global.class, remap = false) +final class GlobalMixin { + @Shadow + public static final String VERSION; + + static { + VERSION = "1.7.7.0"; + } +} diff --git a/src/main/java/turniplabs/vanillafixes/mixin/GuiTooltipMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/GuiTooltipMixin.java @@ -0,0 +1,80 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiTooltip; +import net.minecraft.core.item.ItemStack; +import net.minecraft.core.item.tool.ItemTool; +import net.minecraft.core.item.tool.ItemToolSword; +import net.minecraft.core.net.command.TextFormatting; +import net.minecraft.core.player.inventory.InventoryPlayer; +import net.minecraft.core.player.inventory.slot.Slot; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = GuiTooltip.class, remap = false) +final class GuiTooltipMixin extends Gui { + @Shadow + Minecraft mc; + + // Stores hovered inventory slot. + private Slot hoveredSlot; + + @Inject(method = "getTooltipText", at = @At("HEAD")) + private void getSlot(ItemStack itemStack, boolean showDescription, Slot slot, CallbackInfoReturnable cir) { + hoveredSlot = slot; + } + + @Redirect(method = "getTooltipText", at = @At(value = "INVOKE", + target = "Ljava/lang/StringBuilder;append(Ljava/lang/String;)Ljava/lang/StringBuilder;", ordinal = 2)) + private StringBuilder addStats(StringBuilder stringBuilder, String str) { + // The first calls to 'append' in the original method come from translateKey params. + // Target: text.append(itemName) + stringBuilder.append(str); + + // Gets player inventory. + InventoryPlayer inventory = mc.thePlayer.inventory; + + // Disables the unused option (just to be safe). + mc.gameSettings.showItemDurability.value = false; + + if (inventory.getHeldItemStack() == null && hoveredSlot != null && + hoveredSlot.hasStack() && hoveredSlot.getStack().getItemName() != null) { // If the slot isn't empty... + if (hoveredSlot.getStack().getItem() instanceof ItemToolSword || + hoveredSlot.getStack().getItem() instanceof ItemTool) { // If it's a sword or a tool... + + // Gets durability. + int toolDurability = hoveredSlot.getStack().getMaxDamage() - hoveredSlot.getStack() + .getItemDamageForDisplay(); + + // Gets damage. + int toolDamage = hoveredSlot.getStack().getItem().getDamageVsEntity(null); + + /* Formats durability display */ + String durabilityTooltip = (new StringBuilder()) + .append("Durability: ") + .append(toolDurability) + .append("/") + .append(hoveredSlot + .getStack() + .getMaxDamage()) + .toString(); + stringBuilder.append('\n').append(TextFormatting.LIGHT_GRAY + durabilityTooltip); + + /* Formats damage display */ + String damageTooltip = (new StringBuilder()) + .append("+") + .append(toolDamage) + .append(" Attack Damage") + .toString(); + stringBuilder.append('\n').append(TextFormatting.LIGHT_GRAY + damageTooltip); + } + } + + return stringBuilder; + } +} diff --git a/src/main/java/turniplabs/vanillafixes/mixin/MinecraftMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/MinecraftMixin.java @@ -0,0 +1,29 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.client.Minecraft; +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.io.File; + +@Mixin(value = Minecraft.class, remap = false) +final class MinecraftMixin { + @Shadow + private File mcDataDir; + @Shadow + private static File minecraftDir; + + @Shadow + public static File getAppDir(String s) { + return null; + } + + @Inject(method = "getMinecraftDir", at = @At("TAIL"), require = 0) + private void renameMinecraftdirectory(CallbackInfoReturnable<File> cir) { + minecraftDir = getAppDir("bta"); + mcDataDir = getAppDir("bta"); + } +} diff --git a/src/main/java/turniplabs/vanillafixes/mixin/PlayerControllerMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/PlayerControllerMixin.java @@ -0,0 +1,21 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.client.player.controller.PlayerController; +import org.objectweb.asm.Opcodes; +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.Redirect; + +@Mixin(value = PlayerController.class, remap = false) +final class PlayerControllerMixin { + @Shadow + protected int blockHitDelay; + + @Redirect(method = "mine", at = @At(value = "FIELD", + target = "Lnet/minecraft/client/player/controller/PlayerController;blockHitDelay:I", + opcode = Opcodes.PUTFIELD, ordinal = 3)) + private void changeBlockHitDelay(PlayerController instance, int value) { + blockHitDelay = 0; + } +} diff --git a/src/main/java/turniplabs/vanillafixes/mixin/SoundManagerMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/SoundManagerMixin.java @@ -0,0 +1,25 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.client.sound.SoundManager; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(value = SoundManager.class, remap = false) +final class SoundManagerMixin { + @ModifyArgs(method = "loadSoundSettings", at = @At(value = "INVOKE", + target = "Lnet/minecraft/client/sound/SoundManager;loadModAudio(Ljava/lang/String;Lnet/minecraft/client/sound/SoundPool;)V"), + require = 0) + private void renameMinecraftdirectory(Args args) { + if (args.get(0) == "minecraft-bta/resources/mod/sound") { + args.set(0, "bta/resources/mod/sound"); + } else if (args.get(0) == "minecraft-bta/resources/mod/streaming") { + args.set(0, "bta/resources/mod/streaming"); + } else if (args.get(0) == "minecraft-bta/resources/mod/music") { + args.set(0, "bta/resources/mod/music"); + } else { + args.set(0, "bta/resources/mod/cavemusic"); + } + } +} diff --git a/src/main/java/turniplabs/vanillafixes/mixin/ToolMaterialMixin.java b/src/main/java/turniplabs/vanillafixes/mixin/ToolMaterialMixin.java @@ -0,0 +1,19 @@ +package turniplabs.vanillafixes.mixin; + +import net.minecraft.core.item.material.ToolMaterial; +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.CallbackInfo; + +@Mixin(value = ToolMaterial.class, remap = false) +final class ToolMaterialMixin { + @Shadow + private int blockHitDelay; + + @Inject(method = "<init>", at = @At("RETURN"), require = 0) + private void changeBlockHitDelay(CallbackInfo ci) { + this.blockHitDelay = 0; + } +} diff --git a/src/main/resources/vanillafixes.mixins.json b/src/main/resources/vanillafixes.mixins.json @@ -1,15 +1,21 @@ { - "required": true, - "minVersion": "0.8", - "package": "turniplabs.vanillafixes.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - ], - "client": [ - "GuiMainMenuMixin", - "DisplayListMixin" - ], - "injectors": { - "defaultRequire": 1 + "required": true, + "minVersion": "0.8", + "package": "turniplabs.vanillafixes.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "GlobalMixin", + "GuiTooltipMixin", + "MinecraftMixin", + "PlayerControllerMixin", + "SoundManagerMixin", + "ToolMaterialMixin" + ], + "client": [ + "DisplayListMixin", + "GuiMainMenuMixin" + ], + "injectors": { + "defaultRequire": 1 } }