Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 06:50:09 +01:00
Code cleanups and update ItemTranslator to work with new mappings
Dieser Commit ist enthalten in:
Ursprung
8c2897dbec
Commit
3784ba7baa
@ -43,12 +43,6 @@
|
||||
<version>1.0.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class CommonItem {
|
||||
JavaItem java;
|
||||
|
||||
BedrockItem bedrock;
|
||||
private JavaItem java;
|
||||
private BedrockItem bedrock;
|
||||
}
|
||||
|
@ -1,26 +1,30 @@
|
||||
package org.geysermc.connector.network.translators.item;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum DyeColor {
|
||||
white,
|
||||
orange,
|
||||
magenta,
|
||||
light_blue,
|
||||
yellow,
|
||||
lime,
|
||||
pink,
|
||||
gray,
|
||||
light_gray,
|
||||
cyan,
|
||||
purple,
|
||||
blue,
|
||||
brown,
|
||||
green,
|
||||
red,
|
||||
black;
|
||||
|
||||
public final int id;
|
||||
WHITE,
|
||||
ORANGE,
|
||||
MAGENTA,
|
||||
LIGHT_BLUE,
|
||||
YELLOW,
|
||||
LIME,
|
||||
PINK,
|
||||
GRAY,
|
||||
LIGHT_GRAY,
|
||||
CYAN,
|
||||
PURPLE,
|
||||
BLUE,
|
||||
BROWN,
|
||||
GREEN,
|
||||
RED,
|
||||
BLACK;
|
||||
|
||||
DyeColor() {
|
||||
this.id = ordinal();
|
||||
@Getter
|
||||
private final int id = ordinal();
|
||||
|
||||
public String getName() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
import org.geysermc.connector.utils.Remapper;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -50,68 +50,6 @@ import java.util.Map;
|
||||
|
||||
public class ItemTranslator {
|
||||
|
||||
private static Map<String, String> identifiers = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
// Key: java translation
|
||||
// Value: bedrock translation
|
||||
identifiers.put("grass_block", "grass");
|
||||
identifiers.put("granite", "stone:1");
|
||||
identifiers.put("polished_granite", "stone:2");
|
||||
identifiers.put("diorite", "stone:3");
|
||||
identifiers.put("polished_diorite", "stone:4");
|
||||
identifiers.put("andesite", "stone:5");
|
||||
identifiers.put("polished_andesite", "stone:6");
|
||||
|
||||
identifiers.put("oak_log", "log");
|
||||
identifiers.put("spruce_log", "log:1");
|
||||
identifiers.put("birch_log", "log:2");
|
||||
identifiers.put("jungle_log", "log:3");
|
||||
identifiers.put("acacia_log", "log:4");
|
||||
identifiers.put("dark_oak_log", "log:5");
|
||||
|
||||
identifiers.put("oak_planks", "planks");
|
||||
identifiers.put("spruce_planks", "planks:1");
|
||||
identifiers.put("birch_planks", "planks:2");
|
||||
identifiers.put("jungle_planks", "planks:3");
|
||||
identifiers.put("acacia_planks", "planks:4");
|
||||
identifiers.put("dark_oak_planks", "planks:5");
|
||||
|
||||
identifiers.put("white_wool", "wool");
|
||||
identifiers.put("orange_wool", "wool:1");
|
||||
identifiers.put("magenta_wool", "wool:2");
|
||||
identifiers.put("light_blue_wool", "wool:3");
|
||||
identifiers.put("yellow_wool", "wool:4");
|
||||
identifiers.put("lime_wool", "wool:5");
|
||||
identifiers.put("pink_wool", "wool:6");
|
||||
identifiers.put("gray_wool", "wool:7");
|
||||
identifiers.put("light_gray_wool", "wool:8");
|
||||
identifiers.put("cyan_wool", "wool:9");
|
||||
identifiers.put("purple_wool", "wool:10");
|
||||
identifiers.put("blue_wool", "wool:11");
|
||||
identifiers.put("brown_wool", "wool:12");
|
||||
identifiers.put("green_wool", "wool:13");
|
||||
identifiers.put("red_wool", "wool:14");
|
||||
identifiers.put("black_wool", "wool:15");
|
||||
|
||||
identifiers.put("white_carpet", "carpet");
|
||||
identifiers.put("orange_carpet", "carpet:1");
|
||||
identifiers.put("magenta_carpet", "carpet:2");
|
||||
identifiers.put("light_blue_carpet", "carpet:3");
|
||||
identifiers.put("yellow_carpet", "carpet:4");
|
||||
identifiers.put("lime_carpet", "carpet:5");
|
||||
identifiers.put("pink_carpet", "carpet:6");
|
||||
identifiers.put("gray_carpet", "carpet:7");
|
||||
identifiers.put("light_gray_carpet", "carpet:8");
|
||||
identifiers.put("cyan_carpet", "carpet:9");
|
||||
identifiers.put("purple_carpet", "carpet:10");
|
||||
identifiers.put("blue_carpet", "carpet:11");
|
||||
identifiers.put("brown_carpet", "carpet:12");
|
||||
identifiers.put("green_carpet", "carpet:13");
|
||||
identifiers.put("red_carpet", "carpet:14");
|
||||
identifiers.put("black_carpet", "carpet:15");
|
||||
}
|
||||
|
||||
public ItemStack translateToJava(ItemData data) {
|
||||
JavaItem javaItem = getJavaItem(data);
|
||||
|
||||
@ -140,7 +78,7 @@ public class ItemTranslator {
|
||||
continue;
|
||||
|
||||
JavaItem javaItem = javaItems.getValue();
|
||||
String identifier = getBedrockIdentifier(javaItem.getIdentifier().replace("minecraft:", ""));
|
||||
String identifier = getBedrockIdentifier(javaItem.getIdentifier());
|
||||
if (!Toolbox.BEDROCK_ITEMS.containsKey(identifier))
|
||||
continue;
|
||||
|
||||
@ -155,7 +93,7 @@ public class ItemTranslator {
|
||||
if (bedrockItems.getValue().getId() != data.getId())
|
||||
continue;
|
||||
|
||||
String identifier = getJavaIdentifier(bedrockItems.getKey().replace("minecraft:", ""));
|
||||
String identifier = getJavaIdentifier(bedrockItems.getKey(), data.getDamage());
|
||||
if (!Toolbox.JAVA_ITEMS.containsKey(identifier))
|
||||
continue;
|
||||
|
||||
@ -166,20 +104,23 @@ public class ItemTranslator {
|
||||
}
|
||||
|
||||
public String getBedrockIdentifier(String javaIdentifier) {
|
||||
if (!identifiers.containsKey(javaIdentifier))
|
||||
return "minecraft:" + javaIdentifier;
|
||||
|
||||
return "minecraft:" + identifiers.get(javaIdentifier);
|
||||
if (!Remapper.JAVA_TO_BEDROCK.containsKey(javaIdentifier)) {
|
||||
return javaIdentifier;
|
||||
}
|
||||
|
||||
public String getJavaIdentifier(String bedrockIdentifier) {
|
||||
for (Map.Entry<String, String> entry : identifiers.entrySet()) {
|
||||
if (entry.getValue().equals(bedrockIdentifier)) {
|
||||
return "minecraft:" + entry.getKey();
|
||||
}
|
||||
if ((int) Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("data") > 0) {
|
||||
return Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("name") + ":" + Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("data");
|
||||
}
|
||||
|
||||
return "minecraft:" + bedrockIdentifier;
|
||||
return (String) Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("name");
|
||||
}
|
||||
|
||||
public String getJavaIdentifier(String bedrockIdentifier, int data) {
|
||||
if (!Remapper.BEDROCK_TO_JAVA.containsKey(bedrockIdentifier)) {
|
||||
return bedrockIdentifier;
|
||||
}
|
||||
|
||||
return Remapper.BEDROCK_TO_JAVA.get(bedrockIdentifier).get(data);
|
||||
}
|
||||
|
||||
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
||||
|
@ -1,24 +1,21 @@
|
||||
package org.geysermc.connector.network.translators.item;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum StoneType {
|
||||
stone,
|
||||
granite,
|
||||
polished_granite,
|
||||
diorite,
|
||||
polished_diorite,
|
||||
andesite,
|
||||
polished_andesite;
|
||||
|
||||
public final String name;
|
||||
public final int id;
|
||||
STONE,
|
||||
GRANITE,
|
||||
POLISHED_GRANITE,
|
||||
DIORITE,
|
||||
POLISHED_DIORITE,
|
||||
ANDESITE,
|
||||
POLISHED_ANDESITE;
|
||||
|
||||
StoneType(String name) {
|
||||
this.id = ordinal();
|
||||
this.name = name;
|
||||
}
|
||||
@Getter
|
||||
private final int id = ordinal();
|
||||
|
||||
StoneType() {
|
||||
this.name = name();
|
||||
this.id = ordinal();
|
||||
public String getName() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,20 @@
|
||||
package org.geysermc.connector.network.translators.item;
|
||||
|
||||
public enum WoodType {
|
||||
oak,
|
||||
spruce,
|
||||
birch,
|
||||
jungle,
|
||||
acacia,
|
||||
dark_oak;
|
||||
import lombok.Getter;
|
||||
|
||||
public final int id = ordinal();
|
||||
public enum WoodType {
|
||||
|
||||
OAK,
|
||||
SPRUCE,
|
||||
BIRCH,
|
||||
JUNGLE,
|
||||
ACACIA,
|
||||
DARK_OAK;
|
||||
|
||||
@Getter
|
||||
private final int id = ordinal();
|
||||
|
||||
public String getName() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -3,98 +3,89 @@ package org.geysermc.connector.utils;
|
||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import org.geysermc.api.events.Listener;
|
||||
import org.geysermc.connector.network.translators.item.*;
|
||||
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||
import org.geysermc.connector.network.translators.item.DyeColor;
|
||||
import org.geysermc.connector.network.translators.item.JavaItem;
|
||||
import org.geysermc.connector.network.translators.item.StoneType;
|
||||
import org.geysermc.connector.network.translators.item.WoodType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class Remapper {
|
||||
|
||||
private static List<String> specials = new ArrayList<>();
|
||||
|
||||
//Method to convert java to bedrock
|
||||
static void convert(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
|
||||
public static Map<String, Map<Integer, String>> BEDROCK_TO_JAVA = new HashMap<>();
|
||||
public static Map<String, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>();
|
||||
|
||||
for(StoneType type : StoneType.values()) {
|
||||
specials.add(type.name);
|
||||
// Method to convert java to bedrock
|
||||
public static void addConversions(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
|
||||
for (StoneType type : StoneType.values()) {
|
||||
specials.add(type.getName());
|
||||
}
|
||||
|
||||
Map<JavaItem, List<BedrockItem>> convertions = new HashMap<>();
|
||||
|
||||
for(Map.Entry<String, JavaItem> entry2 : java.entrySet()) {
|
||||
for (Map.Entry<String, BedrockItem> entry1 : items1.entrySet()) {
|
||||
if (!tool(entry2.getValue().getIdentifier())) {
|
||||
if (entry2.getKey().contains("white_")) {
|
||||
String stripped = entry2.getKey().replaceAll("white_", "").replaceAll("terracotta", "stained_hardened_clay");
|
||||
if (stripped.equalsIgnoreCase(entry1.getKey()) && entry1.getValue().getData() == 0) {
|
||||
for (Map.Entry<String, JavaItem> javaItem : java.entrySet()) {
|
||||
for (Map.Entry<String, BedrockItem> bedrockItem : items1.entrySet()) {
|
||||
if (tool(javaItem.getValue().getIdentifier()))
|
||||
continue;
|
||||
|
||||
if (javaItem.getKey().contains("white_")) {
|
||||
String stripped = javaItem.getKey().replaceAll("white_", "").replaceAll("terracotta", "stained_hardened_clay");
|
||||
|
||||
if (!stripped.equalsIgnoreCase(bedrockItem.getKey()) || bedrockItem.getValue().getData() != 0)
|
||||
continue;
|
||||
|
||||
for (DyeColor dyeColor : DyeColor.values()) {
|
||||
JavaItem j = java.get(entry2.getValue().getIdentifier().replaceAll("white_", dyeColor.name() + "_"));
|
||||
|
||||
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("white_", dyeColor.getName() + "_"));
|
||||
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
||||
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), dyeColor.getId()));
|
||||
}
|
||||
} else if (javaItem.getKey().contains("oak_")) {
|
||||
String stripped = javaItem.getKey().replaceAll("oak_", "").replaceAll("terracotta", "stained_hardened_clay");
|
||||
|
||||
if (!stripped.equalsIgnoreCase(bedrockItem.getKey()) || bedrockItem.getValue().getData() != 0)
|
||||
continue;
|
||||
|
||||
convertions.get(j).add(new BedrockItem(entry1.getValue().getIdentifier(), entry1.getValue().getId(), dyeColor.id));
|
||||
}
|
||||
}
|
||||
} else if (entry2.getKey().contains("oak_")) {
|
||||
String stripped = entry2.getKey().replaceAll("oak_", "").replaceAll("terracotta", "stained_hardened_clay");
|
||||
if (stripped.equalsIgnoreCase(entry1.getKey()) && entry1.getValue().getData() == 0) {
|
||||
for (WoodType woodType : WoodType.values()) {
|
||||
JavaItem j = java.get(entry2.getValue().getIdentifier().replaceAll("oak_", woodType.name() + "_"));
|
||||
|
||||
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("oak_", woodType.getName() + "_"));
|
||||
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
||||
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), woodType.getId()));
|
||||
}
|
||||
} else if (!javaItem.getKey().contains("stairs")) {
|
||||
if (!javaItem.getKey().startsWith("minecraft:stone_") || !bedrockItem.getValue().getIdentifier().equalsIgnoreCase(javaItem.getKey().replace("stone_", "")) || bedrockItem.getValue().getData() != 0)
|
||||
continue;
|
||||
|
||||
convertions.get(j).add(new BedrockItem(entry1.getValue().getIdentifier(), entry1.getValue().getId(), woodType.id));
|
||||
}
|
||||
}
|
||||
} else if (!entry2.getKey().contains("stairs")) {
|
||||
if (entry2.getKey().startsWith("minecraft:stone_") && entry1.getValue().getIdentifier().equalsIgnoreCase(entry2.getKey().replace("stone_", "")) && entry1.getValue().getData() == 0) {
|
||||
for (StoneType stoneType : StoneType.values()) {
|
||||
JavaItem j = java.get(entry2.getValue().getIdentifier().replaceAll("stone_", stoneType.name() + "_"));
|
||||
|
||||
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("stone_", stoneType.getName() + "_"));
|
||||
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
||||
|
||||
convertions.get(j).add(new BedrockItem(entry1.getValue().getIdentifier(), entry1.getValue().getId(), stoneType.id));
|
||||
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), stoneType.getId()));
|
||||
}
|
||||
} else if (entry2.getKey().equalsIgnoreCase("minecraft:stone") && entry1.getKey().equalsIgnoreCase("minecraft:stone")) {
|
||||
} else if (javaItem.getKey().equalsIgnoreCase("minecraft:stone") && bedrockItem.getKey().equalsIgnoreCase("minecraft:stone")) {
|
||||
for (StoneType stoneType : StoneType.values()) {
|
||||
JavaItem j = java.get(entry2.getValue().getIdentifier().replaceAll("stone", stoneType.name()));
|
||||
|
||||
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("stone", stoneType.getName()));
|
||||
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
||||
|
||||
convertions.get(j).add(new BedrockItem(entry1.getValue().getIdentifier(), entry1.getValue().getId(), stoneType.id));
|
||||
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), stoneType.getId()));
|
||||
}
|
||||
}
|
||||
} else if (entry1.getValue().getIdentifier().equalsIgnoreCase(entry2.getKey()) && notSpecial(entry2.getKey())) {
|
||||
JavaItem j = entry2.getValue();
|
||||
|
||||
} else if (bedrockItem.getValue().getIdentifier().equalsIgnoreCase(javaItem.getKey()) && notSpecial(javaItem.getKey())) {
|
||||
JavaItem j = javaItem.getValue();
|
||||
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
||||
|
||||
convertions.get(j).add(entry1.getValue());
|
||||
}
|
||||
convertions.get(j).add(bedrockItem.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for(BedrockItem item : )
|
||||
|
||||
for(DyeColor dyeColor : DyeColor.values()) {
|
||||
JavaItem j = java.get("minecraft:white_shulker_box".replaceAll("white_", dyeColor.name() + "_"));
|
||||
|
||||
System.out.println(j.getIdentifier() + " " + convertions.get(j).get(0).getIdentifier() + ":" + convertions.get(j).get(0).getData());
|
||||
for (DyeColor dyeColor : DyeColor.values()) {
|
||||
JavaItem j = java.get("minecraft:white_shulker_box".replaceAll("white_", dyeColor.getName() + "_"));
|
||||
// System.out.println(j.getIdentifier() + " " + convertions.get(j).get(0).getIdentifier() + ":" + convertions.get(j).get(0).getData());
|
||||
}
|
||||
|
||||
|
||||
Map<String, Map<Integer, String>> BEDROCK_TO_JAVA = new HashMap<>();
|
||||
|
||||
Map<String, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>();
|
||||
|
||||
for(Map.Entry<JavaItem, List<BedrockItem>> entry : convertions.entrySet()) {
|
||||
|
||||
for(BedrockItem item : entry.getValue()) {
|
||||
if(entry.getKey().getIdentifier().contains("shul")) {
|
||||
System.out.println(entry.getKey().getIdentifier());
|
||||
}
|
||||
Objects.requireNonNull(entry.getKey(), item.getIdentifier());
|
||||
for (Map.Entry<JavaItem, List<BedrockItem>> entry : convertions.entrySet()) {
|
||||
for (BedrockItem item : entry.getValue()) {
|
||||
JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>());
|
||||
BEDROCK_TO_JAVA.computeIfAbsent(item.getIdentifier(), (x) -> new HashMap<>());
|
||||
Map<String, Object> map = JAVA_TO_BEDROCK.get(entry.getKey().getIdentifier());
|
||||
@ -107,11 +98,15 @@ public class Remapper {
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment this for updated mappings
|
||||
// writeMappings();
|
||||
}
|
||||
|
||||
private static void writeMappings() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
|
||||
try {
|
||||
writer.writeValue(new File("java_to_bedrock.json"), JAVA_TO_BEDROCK);
|
||||
|
||||
writer.writeValue(new File("bedrock_to_java.json"), BEDROCK_TO_JAVA);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -119,8 +114,8 @@ public class Remapper {
|
||||
}
|
||||
|
||||
private static boolean notSpecial(String key) {
|
||||
for(String spec : specials) {
|
||||
if(key.contains(spec)) {
|
||||
for (String spec : specials) {
|
||||
if (key.contains(spec)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ public class Toolbox {
|
||||
for (String str : javaItemList.keySet()) {
|
||||
javaItems.put(str, new JavaItem(str, (int) javaItemList.get(str).get("protocol_id")));
|
||||
}
|
||||
//Uncomment when you need new re-mappings!
|
||||
//Remapper.convert(bedrockItems, javaItems);
|
||||
|
||||
Remapper.addConversions(bedrockItems, javaItems);
|
||||
|
||||
JAVA_ITEMS = javaItems;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren