diff --git a/.gitignore b/.gitignore deleted file mode 100644 index be8b20003..000000000 --- a/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -### Java template -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -*.iml -*.idea - -# maven target directories -target/ - -# log directory -logs/ diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index 4579c9faa..19658b8ca 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -45,6 +45,7 @@ import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.Remapper; import org.geysermc.connector.utils.Toolbox; +import java.rmi.MarshalException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -75,34 +76,13 @@ public class ItemTranslator { } public BedrockItem getBedrockItem(ItemStack stack) { - for (Map.Entry javaItems : Toolbox.JAVA_ITEMS.entrySet()) { - if (javaItems.getValue().getId() != stack.getId()) - continue; - - JavaItem javaItem = javaItems.getValue(); - String identifier = getBedrockIdentifier(javaItem.getIdentifier()); - if (!Toolbox.BEDROCK_ITEMS.containsKey(identifier)) - continue; - - return Toolbox.BEDROCK_ITEMS.get(identifier); - } - - return new BedrockItem("minecraft:air", 0, 0); + Map m = Remapper.JAVA_TO_BEDROCK.get(stack.getId()); + return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data")); } public JavaItem getJavaItem(ItemData data) { - for (Map.Entry bedrockItems : Toolbox.BEDROCK_ITEMS.entrySet()) { - if (bedrockItems.getValue().getId() != data.getId()) - continue; - - String identifier = getJavaIdentifier(bedrockItems.getKey(), data.getDamage()); - if (!Toolbox.JAVA_ITEMS.containsKey(identifier)) - continue; - - return Toolbox.JAVA_ITEMS.get(identifier); - } - - return new JavaItem("minecraft:air", 0); + Map m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage()); + return new JavaItem((String) m.get("name"), (Integer) m.get("id")); } public String getBedrockIdentifier(String javaIdentifier) { @@ -122,7 +102,7 @@ public class ItemTranslator { return bedrockIdentifier; } - return Remapper.BEDROCK_TO_JAVA.get(bedrockIdentifier).get(data); + return (String) Remapper.BEDROCK_TO_JAVA.get(bedrockIdentifier).get(data).get("name"); } private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/RemapUtils.java b/connector/src/main/java/org/geysermc/connector/utils/RemapUtils.java index 480d8742d..f02b3b557 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/RemapUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/RemapUtils.java @@ -11,6 +11,8 @@ import java.util.List; import java.util.jar.JarEntry; class RemapUtils { + private static final String MINECRAFT = "minecraft:"; + static void start() { //colors Remapper.predicates.put((x) -> x.getF().contains("white"), (x, y) -> { @@ -51,12 +53,11 @@ class RemapUtils { } }); - //TODO: add stone support - /*Remapper.predicates.put((x) -> x.getF().contains("oak"), (x, y) -> { + Remapper.predicates.put((x) -> x.getF().contains("stone"), (x, y) -> { //System.out.println(x.getIdentifier()); - //if(customStoneIfNeeded(y)) return; + if(customStoneIfNeeded(y)) return; - if (y.getIdentifier().replaceAll("oak_", "") + if (y.getIdentifier().replaceAll("stone_", "") .equalsIgnoreCase(x.getIdentifier()) && x.getData() == 0) { for (WoodType woodType : WoodType.values()) { @@ -66,13 +67,13 @@ class RemapUtils { } } - });*/ + }); } private static boolean customColorIfNeeded(JavaItem j) { - if(j.getIdentifier().equalsIgnoreCase("minecraft:shulker_box")) { + if(j.getIdentifier().equalsIgnoreCase(MINECRAFT + "shulker_box")) { System.out.println(j.getIdentifier()); - Remapper.convertions.put(j, Arrays.asList(new BedrockItem("minecraft:undyed_shulker_box", 205, 0))); + Remapper.convertions.put(j, Arrays.asList(new BedrockItem(MINECRAFT + "undyed_shulker_box", 205, 0))); return true; } return false; @@ -80,8 +81,8 @@ class RemapUtils { private static boolean customWoodIfNeeded(JavaItem j) { for(WoodType t : WoodType.values()) { - if (j.getIdentifier().equalsIgnoreCase("minecraft:stripped_" + t.getName() +"_wood")) { - Remapper.convertions.put(j, Arrays.asList(new BedrockItem("minecraft:wood", 467, t.getId() + 8))); + if (j.getIdentifier().equalsIgnoreCase(MINECRAFT + "stripped_" + t.getName() +"_wood")) { + Remapper.convertions.put(j, Arrays.asList(new BedrockItem(MINECRAFT + "wood", 467, t.getId() + 8))); return false; } } @@ -89,6 +90,9 @@ class RemapUtils { } private static boolean customStoneIfNeeded(JavaItem j) { + if(j.getIdentifier().equalsIgnoreCase("")) { + + } return false; } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/Remapper.java b/connector/src/main/java/org/geysermc/connector/utils/Remapper.java index 4b5f4b211..9e0ebf0a7 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Remapper.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Remapper.java @@ -21,8 +21,11 @@ public class Remapper { private static List specials = new ArrayList<>(); - public static Map> BEDROCK_TO_JAVA = new HashMap<>(); - public static Map> JAVA_TO_BEDROCK = new HashMap<>(); + public static Map>> BEDROCK_TO_JAVA = new HashMap<>(); + public static Map> JAVA_TO_BEDROCK = new HashMap<>(); + + public static Map>> BEDROCK_TO_JAVA_BLOCKS = new HashMap<>(); + public static Map> JAVA_TO_BEDROCK_BLOCKS = new HashMap<>(); // Method to convert java to bedrock public static void addConversions(Map items1, Map java) { @@ -55,13 +58,26 @@ public class Remapper { for (BedrockItem item : entry.getValue()) { JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>()); BEDROCK_TO_JAVA.computeIfAbsent(item.getIdentifier(), (x) -> new HashMap<>()); + JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getId(), (x) -> new HashMap<>()); + BEDROCK_TO_JAVA.computeIfAbsent(item.getId(), (x) -> new HashMap<>()); Map map = JAVA_TO_BEDROCK.get(entry.getKey().getIdentifier()); + Map map2 = JAVA_TO_BEDROCK.get(entry.getKey().getId()); map.put("name", item.getIdentifier()); + map2.put("name", item.getIdentifier()); map.put("id", item.getId()); + map2.put("id", item.getId()); map.put("data", item.getData()); + map2.put("data", item.getData()); - BEDROCK_TO_JAVA.get(item.getIdentifier()).put(item.getData(), entry.getKey().getIdentifier()); + BEDROCK_TO_JAVA.get(item.getIdentifier()).computeIfAbsent(item.getData(), (x) -> new HashMap<>()); + BEDROCK_TO_JAVA.get(item.getId()).computeIfAbsent(item.getData(), (x) -> new HashMap<>()); + + BEDROCK_TO_JAVA.get(item.getIdentifier()).get(item.getData()).put("name", entry.getKey().getIdentifier()); + BEDROCK_TO_JAVA.get(item.getIdentifier()).get(item.getData()).put("id", entry.getKey().getId()); + + BEDROCK_TO_JAVA.get(item.getId()).get(item.getData()).put("name", entry.getKey().getIdentifier()); + BEDROCK_TO_JAVA.get(item.getId()).get(item.getData()).put("id", entry.getKey().getId()); } } @@ -69,6 +85,61 @@ public class Remapper { writeMappings(); } + public static void addConversions2(Map items1, Map java) { + convertions.clear(); + for (StoneType type : StoneType.values()) { + specials.add(type.getName()); + } + + for (Map.Entry javaItem : java.entrySet()) { + for (Map.Entry bedrockItem : items1.entrySet()) { + for (Predicate> predicate : predicates.keySet()) { + BiValue b = new BiValue<>(javaItem.getKey(), bedrockItem.getKey()); + BiValue b2 = new BiValue<>(javaItem.getKey().replaceAll("_", ""), bedrockItem.getKey().replaceAll("_", "")); + if (predicate.test(b) || predicate.test(b2)) { + predicates.get(predicate).accept(bedrockItem.getValue(), javaItem.getValue()); + } + } + } + } + + //for(BedrockItem item : ) + + 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()); + } + + for (Map.Entry> entry : convertions.entrySet()) { + for (BedrockItem item : entry.getValue()) { + JAVA_TO_BEDROCK_BLOCKS.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>()); + BEDROCK_TO_JAVA_BLOCKS.computeIfAbsent(item.getIdentifier(), (x) -> new HashMap<>()); + JAVA_TO_BEDROCK_BLOCKS.computeIfAbsent(entry.getKey().getId(), (x) -> new HashMap<>()); + BEDROCK_TO_JAVA_BLOCKS.computeIfAbsent(item.getId(), (x) -> new HashMap<>()); + Map map = JAVA_TO_BEDROCK_BLOCKS.get(entry.getKey().getIdentifier()); + Map map2 = JAVA_TO_BEDROCK_BLOCKS.get(entry.getKey().getId()); + + map.put("name", item.getIdentifier()); + map2.put("name", item.getIdentifier()); + map.put("id", item.getId()); + map2.put("id", item.getId()); + map.put("data", item.getData()); + map2.put("data", item.getData()); + + BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).computeIfAbsent(item.getData(), (x) -> new HashMap<>()); + BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).computeIfAbsent(item.getData(), (x) -> new HashMap<>()); + + BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).get(item.getData()).put("name", entry.getKey().getIdentifier()); + BEDROCK_TO_JAVA_BLOCKS.get(item.getIdentifier()).get(item.getData()).put("id", entry.getKey().getId()); + + BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).get(item.getData()).put("name", entry.getKey().getIdentifier()); + BEDROCK_TO_JAVA_BLOCKS.get(item.getId()).get(item.getData()).put("id", entry.getKey().getId()); + } + } + + writeMappings2(); + } + private static void writeMappings() { ObjectMapper mapper = new ObjectMapper(); ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); @@ -80,6 +151,17 @@ public class Remapper { } } + private static void writeMappings2() { + ObjectMapper mapper = new ObjectMapper(); + ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); + try { + writer.writeValue(new File("java_to_bedrock_blocks.json"), JAVA_TO_BEDROCK_BLOCKS); + writer.writeValue(new File("bedrock_to_java_blocks.json"), BEDROCK_TO_JAVA_BLOCKS); + } catch (Exception e) { + e.printStackTrace(); + } + } + private static boolean notSpecial(String key) { for (String spec : specials) { if (key.contains(spec)) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 1909d6c29..5369dac68 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -26,14 +26,12 @@ public class Toolbox { e.printStackTrace(); } + Map m = new HashMap<>(); + Map bedrockItems = new HashMap<>(); for (Map e : entries) { BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data")); - if (bedrockItem.getData() != 0) { - bedrockItems.put(bedrockItem.getIdentifier() + ":" + bedrockItem.getData(), bedrockItem); - } else { - bedrockItems.put(bedrockItem.getIdentifier(), bedrockItem); - } + m.put(bedrockItem.getIdentifier(), bedrockItem); } @@ -73,7 +71,7 @@ public class Toolbox { BEDROCK_ITEMS = bedrockItems; - InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json"); + InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java/java_items.json"); ObjectMapper javaItemMapper = new ObjectMapper(); Map javaItemList = new HashMap<>(); try { @@ -91,6 +89,29 @@ public class Toolbox { Remapper.addConversions(bedrockItems, javaItems); JAVA_ITEMS = javaItems; + + InputStream javaItemStream2 = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json"); + ObjectMapper javaItemMapper2 = new ObjectMapper(); + Map javaItemList2 = new HashMap<>(); + try { + javaItemList2 = javaItemMapper2.readValue(javaItemStream2, new TypeReference>(){}); + } catch (Exception ex) { + ex.printStackTrace(); + } + + Map javaItems2 = new HashMap(); + + for (String str : javaItemList2.keySet()) { + javaItems2.put(str, new JavaItem(str, (int) javaItemList2.get(str).get("protocol_id"))); + } + + JAVA_BLOCKS = javaItems2; + + BEDROCK_BLOCKS = m; + + Remapper.addConversions(bedrockItems, javaItems); + + Remapper.addConversions2(m, javaItems2); } public static final Collection ITEMS; @@ -100,5 +121,8 @@ public class Toolbox { public static final Map BEDROCK_ITEMS; public static final Map JAVA_ITEMS; + public static final Map BEDROCK_BLOCKS; + public static final Map JAVA_BLOCKS; + //public static final byte[] EMPTY_CHUNK; } \ No newline at end of file