Geyser/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java

85 lines
2.3 KiB
Java
Raw Normal View History

2019-07-11 22:39:28 +00:00
package org.geysermc.connector.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.network.VarInts;
2019-07-17 01:05:10 +00:00
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
2019-07-11 22:39:28 +00:00
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.InputStream;
2019-07-17 01:05:10 +00:00
import java.util.*;
2019-07-11 22:39:28 +00:00
public class Toolbox {
static {
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("cached_pallete.json");
ObjectMapper mapper = new ObjectMapper();
ArrayList<LinkedHashMap<String, Object>> entries = new ArrayList<>();
try {
entries = mapper.readValue(stream, ArrayList.class);
} catch (Exception e) {
e.printStackTrace();
}
ByteBuf b = Unpooled.buffer();
VarInts.writeInt(b, entries.size());
for (Map<String, Object> e : entries) {
BedrockUtils.writeString(b, (String) e.get("name"));
b.writeShortLE((Integer) e.get("data"));
}
CACHED_PALLETE = b;
2019-07-17 01:05:10 +00:00
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("items.json");
if (stream2 == null) {
throw new AssertionError("Items Table not found");
}
ObjectMapper mapper2 = new ObjectMapper();
ArrayList<HashMap> s = new ArrayList<>();
try {
s = mapper2.readValue(stream2, ArrayList.class);
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<StartGamePacket.ItemEntry> l = new ArrayList<>();
for(HashMap e : s) {
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), ((Integer) e.get("id")).shortValue()));
}
ITEMS = l;
2019-07-19 00:11:58 +00:00
/*ByteBuf serializer;
2019-07-17 01:05:10 +00:00
serializer = Unpooled.buffer();
serializer.writeShortLE(1);
2019-07-19 00:11:58 +00:00
GeyserUtils.writeVarIntByteArray(serializer, (chunkdata) -> {
GeyserUtils.writeEmptySubChunk(chunkdata);
2019-07-17 01:05:10 +00:00
chunkdata.writeZero(512);
chunkdata.writeZero(256);
chunkdata.writeByte(0);
});
2019-07-19 00:11:58 +00:00
EMPTY_CHUNK = GeyserUtils.readAllBytes(serializer);*/
2019-07-17 01:05:10 +00:00
2019-07-11 22:39:28 +00:00
}
2019-07-17 01:05:10 +00:00
public static final Collection<StartGamePacket.ItemEntry> ITEMS;
2019-07-11 22:39:28 +00:00
public static final ByteBuf CACHED_PALLETE;
2019-07-19 00:11:58 +00:00
//public static final byte[] EMPTY_CHUNK;
2019-07-17 01:05:10 +00:00
2019-07-11 22:39:28 +00:00
}