2019-07-31 00:10:27 +00:00
|
|
|
package org.geysermc.connector.utils;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectWriter;
|
2019-07-31 19:59:23 +00:00
|
|
|
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;
|
2019-07-31 00:10:27 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class Remapper {
|
2019-07-31 19:59:23 +00:00
|
|
|
|
2019-07-31 00:10:27 +00:00
|
|
|
private static List<String> specials = new ArrayList<>();
|
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
public static Map<String, Map<Integer, String>> BEDROCK_TO_JAVA = new HashMap<>();
|
|
|
|
public static Map<String, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>();
|
2019-07-31 00:10:27 +00:00
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
// 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());
|
2019-07-31 00:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Map<JavaItem, List<BedrockItem>> convertions = new HashMap<>();
|
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
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(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;
|
2019-07-31 00:10:27 +00:00
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
for (WoodType woodType : WoodType.values()) {
|
|
|
|
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("oak_", woodType.getName() + "_"));
|
2019-07-31 00:10:27 +00:00
|
|
|
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
2019-07-31 19:59:23 +00:00
|
|
|
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;
|
2019-07-31 00:10:27 +00:00
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
for (StoneType stoneType : StoneType.values()) {
|
|
|
|
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("stone_", stoneType.getName() + "_"));
|
|
|
|
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
|
|
|
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), stoneType.getId()));
|
|
|
|
}
|
|
|
|
} else if (javaItem.getKey().equalsIgnoreCase("minecraft:stone") && bedrockItem.getKey().equalsIgnoreCase("minecraft:stone")) {
|
|
|
|
for (StoneType stoneType : StoneType.values()) {
|
|
|
|
JavaItem j = java.get(javaItem.getValue().getIdentifier().replaceAll("stone", stoneType.getName()));
|
|
|
|
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
|
|
|
|
convertions.get(j).add(new BedrockItem(bedrockItem.getValue().getIdentifier(), bedrockItem.getValue().getId(), stoneType.getId()));
|
2019-07-31 00:10:27 +00:00
|
|
|
}
|
2019-07-31 19:59:23 +00:00
|
|
|
} 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(bedrockItem.getValue());
|
2019-07-31 00:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//for(BedrockItem item : )
|
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
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());
|
2019-07-31 00:10:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
for (Map.Entry<JavaItem, List<BedrockItem>> entry : convertions.entrySet()) {
|
|
|
|
for (BedrockItem item : entry.getValue()) {
|
2019-07-31 00:10:27 +00:00
|
|
|
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());
|
|
|
|
|
|
|
|
map.put("name", item.getIdentifier());
|
|
|
|
map.put("id", item.getId());
|
|
|
|
map.put("data", item.getData());
|
|
|
|
|
|
|
|
BEDROCK_TO_JAVA.get(item.getIdentifier()).put(item.getData(), entry.getKey().getIdentifier());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 19:59:23 +00:00
|
|
|
// Uncomment this for updated mappings
|
|
|
|
// writeMappings();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void writeMappings() {
|
2019-07-31 00:10:27 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean notSpecial(String key) {
|
2019-07-31 19:59:23 +00:00
|
|
|
for (String spec : specials) {
|
|
|
|
if (key.contains(spec)) {
|
2019-07-31 00:10:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean tool(String s) {
|
|
|
|
return s.contains("shovel") || s.contains("sword") || s.contains("axe") || s.contains("pickaxe") || s.contains("spade") || s.contains("hoe");
|
|
|
|
}
|
|
|
|
}
|