-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Head names now match the vanilla head names
- Loading branch information
1 parent
b08a6f5
commit 1ce9829
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/client/java/net/pedroricardo/mixin/client/ChangeHeadNameMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.pedroricardo.mixin.client; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.mojang.authlib.GameProfile; | ||
import com.mojang.authlib.minecraft.MinecraftProfileTexture; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.SkullItem; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.nbt.NbtHelper; | ||
import net.minecraft.text.Text; | ||
import net.pedroricardo.content.TextureToHeadMap; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(SkullItem.class) | ||
public class ChangeHeadNameMixin { | ||
@ModifyReturnValue(method = "getName", at = @At(value = "RETURN", ordinal = 0)) | ||
private Text headedrewritten$getCorrectName(Text original, @Local(ordinal = 0) ItemStack stack, @Local(ordinal = 0) String string) { | ||
NbtCompound nbt = stack.getNbt(); | ||
if (nbt == null || !nbt.contains("SkullOwner", NbtElement.COMPOUND_TYPE)) return original; | ||
GameProfile gameProfile = NbtHelper.toGameProfile(nbt.getCompound("SkullOwner")); | ||
if (gameProfile != null && gameProfile.getProperties().containsKey("textures") && MinecraftClient.getInstance().getSkinProvider().getTextures(gameProfile).containsKey(MinecraftProfileTexture.Type.SKIN) && TextureToHeadMap.contains(MinecraftClient.getInstance().getSkinProvider().getTextures(gameProfile).get(MinecraftProfileTexture.Type.SKIN).getUrl())) { | ||
return Text.translatable(((SkullItem)(Object)this).getTranslationKey() + ".named_headed_rewritten", string); | ||
} | ||
return original; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,8 @@ | |
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
}, | ||
"mixins": [ | ||
"ChangeHeadNameMixin" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters