qwq
This commit is contained in:
parent
ec20c140d2
commit
05598164e9
@ -6,7 +6,7 @@ minecraft_version=1.21.4
|
||||
yarn_mappings=1.21.4+build.8
|
||||
loader_version=0.16.10
|
||||
# Mod Properties
|
||||
mod_version=1.14.514.003
|
||||
mod_version=1.14.514.005
|
||||
maven_group=org.branulf
|
||||
archives_base_name=Show_Enchants_from_fabrication
|
||||
# Dependencies
|
||||
|
@ -6,12 +6,14 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.ItemEnchantmentsComponent;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.tag.EnchantmentTags;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -40,8 +42,19 @@ public abstract class DrawContextMixin {
|
||||
at = @At("TAIL")
|
||||
)
|
||||
private void onRenderItemOverlay(TextRenderer renderer, ItemStack stack, int x, int y, String countLabel, CallbackInfo ci) {
|
||||
if (stack == null || stack.getItem() != Items.ENCHANTED_BOOK) return;
|
||||
if (stack == null) return;
|
||||
|
||||
// 处理附魔书
|
||||
if (stack.getItem() == Items.ENCHANTED_BOOK) {
|
||||
handleEnchantedBook(stack, renderer, x, y);
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理武器和工具
|
||||
handleWeaponsAndTools(stack, renderer, x, y);
|
||||
}
|
||||
|
||||
private void handleEnchantedBook(ItemStack stack, TextRenderer renderer, int x, int y) {
|
||||
ItemEnchantmentsComponent enchants = stack.get(DataComponentTypes.STORED_ENCHANTMENTS);
|
||||
if (enchants == null || enchants.isEmpty()) return;
|
||||
|
||||
@ -70,6 +83,79 @@ public abstract class DrawContextMixin {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleWeaponsAndTools(ItemStack stack, TextRenderer renderer, int x, int y) {
|
||||
ItemEnchantmentsComponent enchants = stack.get(DataComponentTypes.ENCHANTMENTS);
|
||||
if (enchants == null || enchants.isEmpty()) return;
|
||||
|
||||
List<RegistryEntry<Enchantment>> enchantments = Lists.newArrayList(enchants.getEnchantments());
|
||||
if (enchantments.isEmpty()) return;
|
||||
|
||||
// 优先显示武器的主要附魔
|
||||
RegistryEntry<Enchantment> primaryEnchant = findPrimaryEnchantment(enchantments);
|
||||
if (primaryEnchant == null) return;
|
||||
|
||||
String name = primaryEnchant.value().description().getString();
|
||||
String firstChar = getFirstVisibleChar(name);
|
||||
|
||||
if (firstChar.isEmpty()) {
|
||||
firstChar = getFallbackChar(primaryEnchant);
|
||||
}
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
matrices.push();
|
||||
matrices.translate(0, 0, 200);
|
||||
|
||||
int color = primaryEnchant.isIn(EnchantmentTags.CURSE) ? 0xFFFF5555 :
|
||||
primaryEnchant.isIn(EnchantmentTags.TREASURE) ? 0xFF55FFFF : 0xFFFF55FF;
|
||||
|
||||
this.drawText(renderer, Text.literal(firstChar), x + 2, y + 9, color, true);
|
||||
matrices.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private RegistryEntry<Enchantment> findPrimaryEnchantment(List<RegistryEntry<Enchantment>> enchantments) {
|
||||
// 武器
|
||||
for (RegistryEntry<Enchantment> entry : enchantments) {
|
||||
Optional<RegistryKey<Enchantment>> key = entry.getKey();
|
||||
if (key.isPresent()) {
|
||||
Identifier id = key.get().getValue();
|
||||
if (id.equals(Enchantments.SHARPNESS.getValue()) ||
|
||||
id.equals(Enchantments.SMITE.getValue()) ||
|
||||
id.equals(Enchantments.BANE_OF_ARTHROPODS.getValue())) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 工具
|
||||
for (RegistryEntry<Enchantment> entry : enchantments) {
|
||||
Optional<RegistryKey<Enchantment>> key = entry.getKey();
|
||||
if (key.isPresent()) {
|
||||
Identifier id = key.get().getValue();
|
||||
if (id.equals(Enchantments.SILK_TOUCH.getValue()) ||
|
||||
id.equals(Enchantments.FORTUNE.getValue())) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 杂七杂八
|
||||
for (RegistryEntry<Enchantment> entry : enchantments) {
|
||||
Optional<RegistryKey<Enchantment>> key = entry.getKey();
|
||||
if (key.isPresent()) {
|
||||
Identifier id = key.get().getValue();
|
||||
if (id.equals(Enchantments.RIPTIDE.getValue()) ||
|
||||
id.equals(Enchantments.LOYALTY.getValue()) ||
|
||||
id.equals(Enchantments.CHANNELING.getValue())) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private String getFirstVisibleChar(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return "";
|
||||
@ -109,8 +195,4 @@ public abstract class DrawContextMixin {
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
public void debug(String a) {
|
||||
System.out.println("Show E DEBUG: " + a);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user