Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02:00
Ursprung
2a05dd57ff
Commit
fb26e263cc
@ -121,10 +121,6 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
||||
|
||||
|
||||
private CompoundTag remapEnchantment(CompoundTag tag) {
|
||||
Tag javaEnchLvl = tag.get("lvl");
|
||||
if (!(javaEnchLvl instanceof ShortTag || javaEnchLvl instanceof IntTag))
|
||||
return null;
|
||||
|
||||
Tag javaEnchId = tag.get("id");
|
||||
if (!(javaEnchId instanceof StringTag))
|
||||
return null;
|
||||
@ -135,9 +131,12 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
||||
return null;
|
||||
}
|
||||
|
||||
Tag javaEnchLvl = tag.get("lvl");
|
||||
|
||||
CompoundTag bedrockTag = new CompoundTag("");
|
||||
bedrockTag.put(new ShortTag("id", (short) enchantment.ordinal()));
|
||||
bedrockTag.put(new ShortTag("lvl", ((Number) javaEnchLvl.getValue()).shortValue()));
|
||||
// If the tag cannot parse, Java Edition 1.18.2 sets to 0
|
||||
bedrockTag.put(new ShortTag("lvl", javaEnchLvl != null && javaEnchLvl.getValue() instanceof Number lvl ? lvl.shortValue() : 0));
|
||||
return bedrockTag;
|
||||
}
|
||||
|
||||
|
@ -29,21 +29,27 @@ import com.github.steveice10.opennbt.tag.builtin.*;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ItemUtils {
|
||||
private static Int2IntMap DYE_COLORS = null;
|
||||
|
||||
public static int getEnchantmentLevel(CompoundTag itemNBTData, String enchantmentId) {
|
||||
ListTag enchantments = (itemNBTData == null ? null : itemNBTData.get("Enchantments"));
|
||||
public static int getEnchantmentLevel(@Nullable CompoundTag itemNBTData, String enchantmentId) {
|
||||
if (itemNBTData == null) {
|
||||
return 0;
|
||||
}
|
||||
ListTag enchantments = itemNBTData.get("Enchantments");
|
||||
if (enchantments != null) {
|
||||
int enchantmentLevel = 0;
|
||||
for (Tag tag : enchantments) {
|
||||
CompoundTag enchantment = (CompoundTag) tag;
|
||||
StringTag enchantId = enchantment.get("id");
|
||||
if (enchantId.getValue().equals(enchantmentId)) {
|
||||
enchantmentLevel = (int) ((ShortTag) enchantment.get("lvl")).getValue();
|
||||
Tag lvl = enchantment.get("lvl");
|
||||
if (lvl != null && lvl.getValue() instanceof Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return enchantmentLevel;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren