Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Mod Name under the Item's Name in Item / Block Stat GUI #465

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ public enum Mixins {
.addMixinClasses("minecraft.MixinMinecraft_FixDuplicateSounds")
.setApplyIf(() -> FixesConfig.fixDuplicateSounds)),

ADD_MOD_ITEM_STATS(new Builder("Add stats for modded items").addMixinClasses("fml.MixinGameRegistry")
.addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.addModItemStats).setPhase(Phase.EARLY)
.setSide(Side.BOTH)),
ADD_MOD_ITEM_STATS(new Builder("Add stats for modded items")
.addMixinClasses("fml.MixinGameRegistry", "minecraft.MixinStats").addTargetedMod(TargetedMod.VANILLA)
.setApplyIf(() -> TweaksConfig.addModItemStats).setPhase(Phase.EARLY).setSide(Side.BOTH)),

ADD_MOD_ENTITY_STATS(new Builder("Add stats for modded entities").addMixinClasses("minecraft.MixinStatList")
.addTargetedMod(TargetedMod.VANILLA).setApplyIf(() -> TweaksConfig.addModEntityStats).setPhase(Phase.EARLY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class MixinItemReed {
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/world/World;getBlock(III)Lnet/minecraft/block/Block;"),
ordinal = 0,
remap = false)
ordinal = 0)
private Block onItemUseWithIsReplaceable(Block original, @Local(ordinal = 0, argsOnly = true) World world,
@Local(ordinal = 0, argsOnly = true) int x, @Local(ordinal = 1, argsOnly = true) int y,
@Local(ordinal = 2, argsOnly = true) int z) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ public class MixinSoundManager {
@ModifyArg(
method = "setSoundCategoryVolume",
at = @At(
remap = false,
value = "INVOKE",
target = "Lnet/minecraft/client/audio/SoundManager$SoundSystemStarterThread;setMasterVolume(F)V"),
index = 0,
remap = false)
index = 0)
public float hodgepodge$modifySetMasterVolumeArg(float volume) {
return (float) Math.pow(volume, 2);
}

@ModifyArg(
method = "setSoundCategoryVolume",
at = @At(
remap = false,
value = "INVOKE",
target = "Lnet/minecraft/client/audio/SoundManager$SoundSystemStarterThread;setVolume(Ljava/lang/String;F)V"),
index = 1,
remap = false)
index = 1)
private float hodgepodge$modifySetCategoryVolumeArg(float volume) {
return (float) Math.pow(volume, 2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.item.Item;
import net.minecraft.util.EnumChatFormatting;

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.At.Shift;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;

import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;

@Mixin(targets = "net.minecraft.client.gui.achievement.GuiStats$Stats")
public class MixinStats {

@Shadow(aliases = "field_148214_q", remap = false)
@Final
GuiStats this$0; // enclosing instance

@ModifyExpressionValue(
at = @At(
target = "Lnet/minecraft/client/gui/FontRenderer;getStringWidth(Ljava/lang/String;)I",
value = "INVOKE"),
method = "func_148213_a")
private int hodgepodge$max(int original, @Local Item item, @Share("modName") LocalRef<String> modNameRef) {
UniqueIdentifier ui = GameRegistry.findUniqueIdentifierFor(item);
if (ui == null) {
return original;
}
ModContainer mod = Loader.instance().getIndexedModList().get(ui.modId);
String modName = null;
if (mod != null) {
modName = mod.getName();
}
if (modName == null) {
modName = "Minecraft";
}
modNameRef.set(modName);
return Math.max(original, this.this$0.fontRendererObj.getStringWidth(modName));
}

@ModifyConstant(constant = @Constant(intValue = 8), method = "func_148213_a")
private int hodgepodge$extendBottom(int original) {
return original + 10;
}

@Inject(
at = @At(
shift = Shift.AFTER,
target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;III)I",
value = "INVOKE"),
method = "func_148213_a")
private void hodgepodge$drawModName(CallbackInfo ci, @Local(ordinal = 2) int k, @Local(ordinal = 3) int l,
@Share("modName") LocalRef<String> modNameRef) {
String modName = modNameRef.get();
if (modName == null) {
return;
}
this.this$0.fontRendererObj.drawStringWithShadow(
EnumChatFormatting.BLUE.toString() + EnumChatFormatting.ITALIC + modName,
k,
l + 10,
-1);
}

}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/hodgepodge_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public net.minecraft.client.Minecraft field_110446_Y # fileAssets
public net.minecraft.client.Minecraft field_110449_ao # defaultResourcePacks
public net.minecraft.client.gui.FontRenderer func_78282_e(Ljava/lang/String;)Ljava/lang/String; # getFormatFromString(String) String
public net.minecraft.client.gui.GuiNewChat field_146252_h # chatLines
public net.minecraft.client.gui.GuiScreen field_146289_q # fontRendererObj
public net.minecraft.client.model.ModelBat field_82895_a # batHead
public net.minecraft.client.model.ModelBlaze field_78105_b # blazeHead
public net.minecraft.client.model.ModelDragon field_78221_a # head
Expand Down