Compare commits
No commits in common. "05598164e9eba3a6b56b550853a8623d2647b2e5" and "d25ceaf3dd7290f6881cb23210c40f1f759911d7" have entirely different histories.
05598164e9
...
d25ceaf3dd
@ -1 +0,0 @@
|
|||||||
由于[Fabrication](https://github.com/FalsehoodMC/Fabrication)迟迟不不更新,但是我又想要里面的显示附魔的功能,所有我就翻了那个项目的显示附魔书的部分代码,并扒出来放到了这个单独的mod
|
|
@ -6,7 +6,7 @@ minecraft_version=1.21.4
|
|||||||
yarn_mappings=1.21.4+build.8
|
yarn_mappings=1.21.4+build.8
|
||||||
loader_version=0.16.10
|
loader_version=0.16.10
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.14.514.005
|
mod_version=1.14.514.003
|
||||||
maven_group=org.branulf
|
maven_group=org.branulf
|
||||||
archives_base_name=Show_Enchants_from_fabrication
|
archives_base_name=Show_Enchants_from_fabrication
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -6,14 +6,12 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.ItemEnchantmentsComponent;
|
import net.minecraft.component.type.ItemEnchantmentsComponent;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.Enchantments;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
import net.minecraft.registry.tag.EnchantmentTags;
|
import net.minecraft.registry.tag.EnchantmentTags;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@ -42,19 +40,8 @@ public abstract class DrawContextMixin {
|
|||||||
at = @At("TAIL")
|
at = @At("TAIL")
|
||||||
)
|
)
|
||||||
private void onRenderItemOverlay(TextRenderer renderer, ItemStack stack, int x, int y, String countLabel, CallbackInfo ci) {
|
private void onRenderItemOverlay(TextRenderer renderer, ItemStack stack, int x, int y, String countLabel, CallbackInfo ci) {
|
||||||
if (stack == null) return;
|
if (stack == null || stack.getItem() != Items.ENCHANTED_BOOK) 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);
|
ItemEnchantmentsComponent enchants = stack.get(DataComponentTypes.STORED_ENCHANTMENTS);
|
||||||
if (enchants == null || enchants.isEmpty()) return;
|
if (enchants == null || enchants.isEmpty()) return;
|
||||||
|
|
||||||
@ -83,79 +70,6 @@ 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) {
|
private String getFirstVisibleChar(String str) {
|
||||||
if (str == null || str.isEmpty()) {
|
if (str == null || str.isEmpty()) {
|
||||||
return "";
|
return "";
|
||||||
@ -195,4 +109,8 @@ public abstract class DrawContextMixin {
|
|||||||
}
|
}
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void debug(String a) {
|
||||||
|
System.out.println("Show E DEBUG: " + a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user