add re-mappings

This commit is contained in:
EOT3000 2019-07-29 22:25:13 -04:00
parent f7f424db9a
commit 66bc2753f7
6 changed files with 5762 additions and 2 deletions

View file

@ -0,0 +1,10 @@
package org.geysermc.connector.network.translators.item;
import lombok.Getter;
@Getter
public class CommonItem {
JavaItem java;
BedrockItem bedrock;
}

View file

@ -0,0 +1,26 @@
package org.geysermc.connector.network.translators.item;
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;
DyeColor() {
this.id = ordinal();
}
}

View file

@ -34,4 +34,14 @@ public class JavaItem {
private String identifier; private String identifier;
private int id; private int id;
@Override
public int hashCode() {
return id & identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof JavaItem && ((JavaItem) obj).id == this.id && ((JavaItem) obj).identifier.equals(this.identifier));
}
} }

View file

@ -1,17 +1,23 @@
package org.geysermc.connector.utils; package org.geysermc.connector.utils;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.nukkitx.network.VarInts; import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v361.BedrockUtils; import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.apache.logging.log4j.core.util.Patterns;
import org.geysermc.connector.network.translators.item.BedrockItem; 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.JavaItem;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
public class Toolbox { public class Toolbox {
@ -26,7 +32,7 @@ public class Toolbox {
e.printStackTrace(); e.printStackTrace();
} }
Map<String, BedrockItem> bedrockItems = new HashMap<String, BedrockItem>(); 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) { if (bedrockItem.getData() != 0) {
@ -36,6 +42,7 @@ public class Toolbox {
} }
} }
ByteBuf b = Unpooled.buffer(); ByteBuf b = Unpooled.buffer();
VarInts.writeUnsignedInt(b, entries.size()); VarInts.writeUnsignedInt(b, entries.size());
for (Map<String, Object> e : entries) { for (Map<String, Object> e : entries) {
@ -74,7 +81,7 @@ public class Toolbox {
InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java_items.json"); InputStream javaItemStream = Toolbox.class.getClassLoader().getResourceAsStream("java_items.json");
ObjectMapper javaItemMapper = new ObjectMapper(); ObjectMapper javaItemMapper = new ObjectMapper();
Map<String, HashMap> javaItemList = new HashMap<String, HashMap>(); Map<String, HashMap> javaItemList = new HashMap<>();
try { try {
javaItemList = javaItemMapper.readValue(javaItemStream, new TypeReference<Map<String, HashMap>>(){}); javaItemList = javaItemMapper.readValue(javaItemStream, new TypeReference<Map<String, HashMap>>(){});
} catch (Exception ex) { } catch (Exception ex) {
@ -86,10 +93,79 @@ public class Toolbox {
for (String str : javaItemList.keySet()) { for (String str : javaItemList.keySet()) {
javaItems.put(str, new JavaItem(str, (int) javaItemList.get(str).get("protocol_id"))); javaItems.put(str, new JavaItem(str, (int) javaItemList.get(str).get("protocol_id")));
} }
//Uncomment when you need new re-mappings!
//convert(bedrockItems, javaItems);
JAVA_ITEMS = javaItems; JAVA_ITEMS = javaItems;
} }
//Method to convert java to bedrock
private static void convert(Map<String, BedrockItem> items1, Map<String, JavaItem> java) {
Map<JavaItem, List<BedrockItem>> convertions = new HashMap<>();
for(Map.Entry<String, JavaItem> entry2 : java.entrySet()) {
for (Map.Entry<String, BedrockItem> entry1 : items1.entrySet()) {
if (entry1.getValue().getIdentifier().equalsIgnoreCase(entry2.getKey())) {
JavaItem j = entry2.getValue();
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
convertions.get(j).add(entry1.getValue());
} else {
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(DyeColor dyeColor : DyeColor.values()) {
JavaItem j = java.get(entry2.getValue().getIdentifier().replaceAll("white_", dyeColor.name() + "_"));
convertions.computeIfAbsent(j, (x) -> new ArrayList<>());
convertions.get(j).add(new BedrockItem(entry1.getValue().getIdentifier(), entry1.getValue().getId(), dyeColor.id));
}
}
}
}
}
}
for(DyeColor dyeColor : DyeColor.values()) {
JavaItem j = java.get("minecraft:white_wool".replaceAll("white_", dyeColor.name() + "_"));
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()) {
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());
}
}
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();
}
}
public static final Collection<StartGamePacket.ItemEntry> ITEMS; public static final Collection<StartGamePacket.ItemEntry> ITEMS;
public static final ByteBuf CACHED_PALLETE; public static final ByteBuf CACHED_PALLETE;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff