Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +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
|
@Override
|
||||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("display")) {
|
if (!itemTag.contains("display")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CompoundTag displayTag = itemTag.get("display");
|
CompoundTag displayTag = itemTag.get("display");
|
||||||
if (displayTag.contains("Name")) {
|
if (displayTag.contains("Name")) {
|
||||||
StringTag nameTag = displayTag.get("Name");
|
StringTag nameTag = displayTag.get("Name");
|
||||||
@ -69,11 +71,12 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
|||||||
displayTag.put(new ListTag("Lore", lore));
|
displayTag.put(new ListTag("Lore", lore));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("display")) {
|
if (!itemTag.contains("display")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CompoundTag displayTag = itemTag.get("display");
|
CompoundTag displayTag = itemTag.get("display");
|
||||||
if (displayTag.contains("Name")) {
|
if (displayTag.contains("Name")) {
|
||||||
StringTag nameTag = displayTag.get("Name");
|
StringTag nameTag = displayTag.get("Name");
|
||||||
@ -90,7 +93,6 @@ public class BasicItemTranslator extends NbtItemStackTranslator {
|
|||||||
displayTag.put(new ListTag("Lore", lore));
|
displayTag.put(new ListTag("Lore", lore));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private String toJavaMessage(StringTag tag) {
|
private String toJavaMessage(StringTag tag) {
|
||||||
String message = tag.getValue();
|
String message = tag.getValue();
|
||||||
|
@ -42,7 +42,9 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("pages")) {
|
if (!itemTag.contains("pages")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<Tag> pages = new ArrayList<>();
|
List<Tag> pages = new ArrayList<>();
|
||||||
ListTag pagesTag = itemTag.get("pages");
|
ListTag pagesTag = itemTag.get("pages");
|
||||||
for (Tag tag : pagesTag.getValue()) {
|
for (Tag tag : pagesTag.getValue()) {
|
||||||
@ -60,11 +62,12 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
|||||||
itemTag.remove("pages");
|
itemTag.remove("pages");
|
||||||
itemTag.put(new ListTag("pages", pages));
|
itemTag.put(new ListTag("pages", pages));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("pages")) {
|
if (!itemTag.contains("pages")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<Tag> pages = new ArrayList<>();
|
List<Tag> pages = new ArrayList<>();
|
||||||
ListTag pagesTag = itemTag.get("pages");
|
ListTag pagesTag = itemTag.get("pages");
|
||||||
for (Tag tag : pagesTag.getValue()) {
|
for (Tag tag : pagesTag.getValue()) {
|
||||||
@ -81,4 +84,3 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
|
|||||||
itemTag.put(new ListTag("pages", pages));
|
itemTag.put(new ListTag("pages", pages));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -37,7 +37,9 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("StoredEnchantments")) {
|
if (!itemTag.contains("StoredEnchantments")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Tag enchTag = itemTag.get("StoredEnchantments");
|
Tag enchTag = itemTag.get("StoredEnchantments");
|
||||||
if (enchTag instanceof ListTag) {
|
if (enchTag instanceof ListTag) {
|
||||||
enchTag = new ListTag("Enchantments", ((ListTag) enchTag).getValue());
|
enchTag = new ListTag("Enchantments", ((ListTag) enchTag).getValue());
|
||||||
@ -45,11 +47,12 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
|||||||
itemTag.put(enchTag);
|
itemTag.put(enchTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("Enchantments")) {
|
if (!itemTag.contains("Enchantments")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Tag enchTag = itemTag.get("Enchantments");
|
Tag enchTag = itemTag.get("Enchantments");
|
||||||
if (enchTag instanceof ListTag) {
|
if (enchTag instanceof ListTag) {
|
||||||
enchTag = new ListTag("StoredEnchantments", ((ListTag) enchTag).getValue());
|
enchTag = new ListTag("StoredEnchantments", ((ListTag) enchTag).getValue());
|
||||||
@ -57,7 +60,6 @@ public class EnchantedBookTranslator extends NbtItemStackTranslator {
|
|||||||
itemTag.put(enchTag);
|
itemTag.put(enchTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptItem(ItemEntry itemEntry) {
|
public boolean acceptItem(ItemEntry itemEntry) {
|
||||||
|
@ -73,7 +73,10 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("ench")) {
|
if (!itemTag.contains("ench")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ListTag enchantmentTag = itemTag.get("ench");
|
ListTag enchantmentTag = itemTag.get("ench");
|
||||||
List<Tag> enchantments = new ArrayList<>();
|
List<Tag> enchantments = new ArrayList<>();
|
||||||
List<Tag> storedEnchantments = new ArrayList<>();
|
List<Tag> storedEnchantments = new ArrayList<>();
|
||||||
@ -115,7 +118,6 @@ public class EnchantmentTranslator extends NbtItemStackTranslator {
|
|||||||
}
|
}
|
||||||
itemTag.remove("ench");
|
itemTag.remove("ench");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private CompoundTag remapEnchantment(CompoundTag tag) {
|
private CompoundTag remapEnchantment(CompoundTag tag) {
|
||||||
|
@ -38,7 +38,9 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToBedrock(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("display")) {
|
if (!itemTag.contains("display")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CompoundTag displayTag = itemTag.get("display");
|
CompoundTag displayTag = itemTag.get("display");
|
||||||
if (displayTag.contains("color")) {
|
if (displayTag.contains("color")) {
|
||||||
IntTag color = displayTag.get("color");
|
IntTag color = displayTag.get("color");
|
||||||
@ -48,11 +50,12 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
|
||||||
if (itemTag.contains("customColor")) {
|
if (!itemTag.contains("customColor")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
IntTag color = itemTag.get("customColor");
|
IntTag color = itemTag.get("customColor");
|
||||||
CompoundTag displayTag = itemTag.get("display");
|
CompoundTag displayTag = itemTag.get("display");
|
||||||
if (displayTag == null) {
|
if (displayTag == null) {
|
||||||
@ -61,7 +64,6 @@ public class LeatherArmorTranslator extends NbtItemStackTranslator {
|
|||||||
displayTag.put(color);
|
displayTag.put(color);
|
||||||
itemTag.remove("customColor");
|
itemTag.remove("customColor");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptItem(ItemEntry itemEntry) {
|
public boolean acceptItem(ItemEntry itemEntry) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren