Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +01:00
Reduce nesting in item nbt translators
Dieser Commit ist enthalten in:
Ursprung
6dabc22d22
Commit
56d84c24d3
@ -46,7 +46,9 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("display")) {
|
||||
if (!itemTag.contains("display")) {
|
||||
return;
|
||||
}
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag.contains("Name")) {
|
||||
StringTag nameTag = displayTag.get("Name");
|
||||
@ -69,11 +71,12 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
||||
displayTag.put(new ListTag("Lore", lore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("display")) {
|
||||
if (!itemTag.contains("display")) {
|
||||
return;
|
||||
}
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag.contains("Name")) {
|
||||
StringTag nameTag = displayTag.get("Name");
|
||||
@ -90,7 +93,6 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
||||
displayTag.put(new ListTag("Lore", lore));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toJavaMessage(StringTag tag) {
|
||||
String message = tag.getValue();
|
||||
|
@ -42,7 +42,9 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("pages")) {
|
||||
if (!itemTag.contains("pages")) {
|
||||
return;
|
||||
}
|
||||
List<Tag> pages = new ArrayList<>();
|
||||
ListTag pagesTag = itemTag.get("pages");
|
||||
for (Tag tag : pagesTag.getValue()) {
|
||||
@ -60,11 +62,12 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
||||
itemTag.remove("pages");
|
||||
itemTag.put(new ListTag("pages", pages));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("pages")) {
|
||||
if (!itemTag.contains("pages")) {
|
||||
return;
|
||||
}
|
||||
List<Tag> pages = new ArrayList<>();
|
||||
ListTag pagesTag = itemTag.get("pages");
|
||||
for (Tag tag : pagesTag.getValue()) {
|
||||
@ -80,5 +83,4 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
||||
itemTag.remove("pages");
|
||||
itemTag.put(new ListTag("pages", pages));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,9 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("StoredEnchantments")) {
|
||||
if (!itemTag.contains("StoredEnchantments")) {
|
||||
return;
|
||||
}
|
||||
Tag enchTag = itemTag.get("StoredEnchantments");
|
||||
if (enchTag instanceof ListTag) {
|
||||
enchTag = new ListTag("Enchantments", ((ListTag) enchTag).getValue());
|
||||
@ -45,11 +47,12 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
||||
itemTag.put(enchTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("Enchantments")) {
|
||||
if (!itemTag.contains("Enchantments")) {
|
||||
return;
|
||||
}
|
||||
Tag enchTag = itemTag.get("Enchantments");
|
||||
if (enchTag instanceof ListTag) {
|
||||
enchTag = new ListTag("StoredEnchantments", ((ListTag) enchTag).getValue());
|
||||
@ -57,7 +60,6 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
||||
itemTag.put(enchTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(ItemEntry itemEntry) {
|
||||
|
@ -73,7 +73,10 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("ench")) {
|
||||
if (!itemTag.contains("ench")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ListTag enchantmentTag = itemTag.get("ench");
|
||||
List<Tag> enchantments = new ArrayList<>();
|
||||
List<Tag> storedEnchantments = new ArrayList<>();
|
||||
@ -115,7 +118,6 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
||||
}
|
||||
itemTag.remove("ench");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CompoundTag remapEnchantment(CompoundTag tag) {
|
||||
|
@ -38,7 +38,9 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
||||
|
||||
@Override
|
||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("display")) {
|
||||
if (!itemTag.contains("display")) {
|
||||
return;
|
||||
}
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag.contains("color")) {
|
||||
IntTag color = displayTag.get("color");
|
||||
@ -48,11 +50,12 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||
if (itemTag.contains("customColor")) {
|
||||
if (!itemTag.contains("customColor")) {
|
||||
return;
|
||||
}
|
||||
IntTag color = itemTag.get("customColor");
|
||||
CompoundTag displayTag = itemTag.get("display");
|
||||
if (displayTag == null) {
|
||||
@ -61,7 +64,6 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
||||
displayTag.put(color);
|
||||
itemTag.remove("customColor");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(ItemEntry itemEntry) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren