remap fixes

This commit is contained in:
EOT3000 2019-08-07 19:08:48 -04:00
parent cadd779f43
commit d22861d61b
5 changed files with 134 additions and 76 deletions

32
.gitignore vendored
View file

@ -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/

View file

@ -45,6 +45,7 @@ import org.geysermc.connector.utils.MessageUtils;
import org.geysermc.connector.utils.Remapper; import org.geysermc.connector.utils.Remapper;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
import java.rmi.MarshalException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -75,34 +76,13 @@ public class ItemTranslator {
} }
public BedrockItem getBedrockItem(ItemStack stack) { public BedrockItem getBedrockItem(ItemStack stack) {
for (Map.Entry<String, JavaItem> javaItems : Toolbox.JAVA_ITEMS.entrySet()) { Map<String, Object> m = Remapper.JAVA_TO_BEDROCK.get(stack.getId());
if (javaItems.getValue().getId() != stack.getId()) return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
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);
} }
public JavaItem getJavaItem(ItemData data) { public JavaItem getJavaItem(ItemData data) {
for (Map.Entry<String, BedrockItem> bedrockItems : Toolbox.BEDROCK_ITEMS.entrySet()) { Map<String, Object> m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage());
if (bedrockItems.getValue().getId() != data.getId()) return new JavaItem((String) m.get("name"), (Integer) m.get("id"));
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);
} }
public String getBedrockIdentifier(String javaIdentifier) { public String getBedrockIdentifier(String javaIdentifier) {
@ -122,7 +102,7 @@ public class ItemTranslator {
return bedrockIdentifier; 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) { private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {

View file

@ -11,6 +11,8 @@ import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
class RemapUtils { class RemapUtils {
private static final String MINECRAFT = "minecraft:";
static void start() { static void start() {
//colors //colors
Remapper.predicates.put((x) -> x.getF().contains("white"), (x, y) -> { 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("stone"), (x, y) -> {
/*Remapper.predicates.put((x) -> x.getF().contains("oak"), (x, y) -> {
//System.out.println(x.getIdentifier()); //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) { .equalsIgnoreCase(x.getIdentifier()) && x.getData() == 0) {
for (WoodType woodType : WoodType.values()) { for (WoodType woodType : WoodType.values()) {
@ -66,13 +67,13 @@ class RemapUtils {
} }
} }
});*/ });
} }
private static boolean customColorIfNeeded(JavaItem j) { 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()); 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 true;
} }
return false; return false;
@ -80,8 +81,8 @@ class RemapUtils {
private static boolean customWoodIfNeeded(JavaItem j) { private static boolean customWoodIfNeeded(JavaItem j) {
for(WoodType t : WoodType.values()) { for(WoodType t : WoodType.values()) {
if (j.getIdentifier().equalsIgnoreCase("minecraft:stripped_" + t.getName() +"_wood")) { if (j.getIdentifier().equalsIgnoreCase(MINECRAFT + "stripped_" + t.getName() +"_wood")) {
Remapper.convertions.put(j, Arrays.asList(new BedrockItem("minecraft:wood", 467, t.getId() + 8))); Remapper.convertions.put(j, Arrays.asList(new BedrockItem(MINECRAFT + "wood", 467, t.getId() + 8)));
return false; return false;
} }
} }
@ -89,6 +90,9 @@ class RemapUtils {
} }
private static boolean customStoneIfNeeded(JavaItem j) { private static boolean customStoneIfNeeded(JavaItem j) {
if(j.getIdentifier().equalsIgnoreCase("")) {
}
return false; return false;
} }
} }

View file

@ -21,8 +21,11 @@ public class Remapper {
private static List<String> specials = new ArrayList<>(); private static List<String> specials = new ArrayList<>();
public static Map<String, Map<Integer, String>> BEDROCK_TO_JAVA = new HashMap<>(); public static Map<Object, Map<Integer, Map<String, Object>>> BEDROCK_TO_JAVA = new HashMap<>();
public static Map<String, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>(); public static Map<Object, Map<String, Object>> JAVA_TO_BEDROCK = new HashMap<>();
public static Map<Object, Map<Integer, Map<String, Object>>> BEDROCK_TO_JAVA_BLOCKS = new HashMap<>();
public static Map<Object, Map<String, Object>> JAVA_TO_BEDROCK_BLOCKS = new HashMap<>();
// Method to convert java to bedrock // Method to convert java to bedrock
public static void addConversions(Map<String, BedrockItem> items1, Map<String, JavaItem> java) { public static void addConversions(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
@ -55,13 +58,26 @@ public class Remapper {
for (BedrockItem item : entry.getValue()) { for (BedrockItem item : entry.getValue()) {
JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>()); JAVA_TO_BEDROCK.computeIfAbsent(entry.getKey().getIdentifier(), (x) -> new HashMap<>());
BEDROCK_TO_JAVA.computeIfAbsent(item.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<String, Object> map = JAVA_TO_BEDROCK.get(entry.getKey().getIdentifier()); Map<String, Object> map = JAVA_TO_BEDROCK.get(entry.getKey().getIdentifier());
Map<String, Object> map2 = JAVA_TO_BEDROCK.get(entry.getKey().getId());
map.put("name", item.getIdentifier()); map.put("name", item.getIdentifier());
map2.put("name", item.getIdentifier());
map.put("id", item.getId()); map.put("id", item.getId());
map2.put("id", item.getId());
map.put("data", item.getData()); 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(); writeMappings();
} }
public static void addConversions2(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
convertions.clear();
for (StoneType type : StoneType.values()) {
specials.add(type.getName());
}
for (Map.Entry<String, JavaItem> javaItem : java.entrySet()) {
for (Map.Entry<String, BedrockItem> bedrockItem : items1.entrySet()) {
for (Predicate<BiValue<String, String>> predicate : predicates.keySet()) {
BiValue<String, String> b = new BiValue<>(javaItem.getKey(), bedrockItem.getKey());
BiValue<String, String> 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<JavaItem, List<BedrockItem>> 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<String, Object> map = JAVA_TO_BEDROCK_BLOCKS.get(entry.getKey().getIdentifier());
Map<String, Object> 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() { private static void writeMappings() {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); 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) { private static boolean notSpecial(String key) {
for (String spec : specials) { for (String spec : specials) {
if (key.contains(spec)) { if (key.contains(spec)) {

View file

@ -26,14 +26,12 @@ public class Toolbox {
e.printStackTrace(); e.printStackTrace();
} }
Map<String, BedrockItem> m = new HashMap<>();
Map<String, BedrockItem> bedrockItems = new HashMap<>(); Map<String, BedrockItem> bedrockItems = new HashMap<>();
for (Map<String, Object> e : entries) { for (Map<String, Object> e : entries) {
BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data")); BedrockItem bedrockItem = new BedrockItem((String) e.get("name"), (int) e.get("id"), (int) e.get("data"));
if (bedrockItem.getData() != 0) { m.put(bedrockItem.getIdentifier(), bedrockItem);
bedrockItems.put(bedrockItem.getIdentifier() + ":" + bedrockItem.getData(), bedrockItem);
} else {
bedrockItems.put(bedrockItem.getIdentifier(), bedrockItem);
}
} }
@ -73,7 +71,7 @@ public class Toolbox {
BEDROCK_ITEMS = bedrockItems; 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(); ObjectMapper javaItemMapper = new ObjectMapper();
Map<String, HashMap> javaItemList = new HashMap<>(); Map<String, HashMap> javaItemList = new HashMap<>();
try { try {
@ -91,6 +89,29 @@ public class Toolbox {
Remapper.addConversions(bedrockItems, javaItems); Remapper.addConversions(bedrockItems, javaItems);
JAVA_ITEMS = javaItems; JAVA_ITEMS = javaItems;
InputStream javaItemStream2 = Toolbox.class.getClassLoader().getResourceAsStream("java/java_blocks.json");
ObjectMapper javaItemMapper2 = new ObjectMapper();
Map<String, HashMap> javaItemList2 = new HashMap<>();
try {
javaItemList2 = javaItemMapper2.readValue(javaItemStream2, new TypeReference<Map<String, HashMap>>(){});
} catch (Exception ex) {
ex.printStackTrace();
}
Map<String, JavaItem> javaItems2 = new HashMap<String, JavaItem>();
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<StartGamePacket.ItemEntry> ITEMS; public static final Collection<StartGamePacket.ItemEntry> ITEMS;
@ -100,5 +121,8 @@ public class Toolbox {
public static final Map<String, BedrockItem> BEDROCK_ITEMS; public static final Map<String, BedrockItem> BEDROCK_ITEMS;
public static final Map<String, JavaItem> JAVA_ITEMS; public static final Map<String, JavaItem> JAVA_ITEMS;
public static final Map<String, BedrockItem> BEDROCK_BLOCKS;
public static final Map<String, JavaItem> JAVA_BLOCKS;
//public static final byte[] EMPTY_CHUNK; //public static final byte[] EMPTY_CHUNK;
} }