Skip to content

Commit

Permalink
Head names now match the vanilla head names
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Feb 18, 2024
1 parent b08a6f5 commit 1ce9829
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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;
}
}
5 changes: 4 additions & 1 deletion src/client/resources/headed-rewritten.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"ChangeHeadNameMixin"
]
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/headed-rewritten/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"commands.headed-rewritten.headed-rewritten.set.item_is_not_a_head": "Item in player's hand is not a head",
"commands.headed-rewritten.headed-rewritten.set.invalid_nbt": "Invalid NBT",
"commands.headed-rewritten.headed-rewritten.set.success": "Set value of option %s to %s",
"argument.headed-rewritten.head_option.invalid": "Invalid head option %s"
"argument.headed-rewritten.head_option.invalid": "Invalid head option %s",
"block.minecraft.player_head.named_headed_rewritten": "%s Head"
}

0 comments on commit 1ce9829

Please sign in to comment.