Skip to content

Commit

Permalink
Merge branch 'master' into feature/mcee
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Jul 15, 2020
2 parents e85aec1 + 16c8a4e commit ad2c4fc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/nukkitx/proxypass/ProxyPass.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NBTOutputStream;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.nbt.tag.Tag;
import com.nukkitx.protocol.bedrock.BedrockClient;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v363.Bedrock_v363;
import com.nukkitx.protocol.bedrock.v407.Bedrock_v407;
import com.nukkitx.proxypass.network.ProxyBedrockEventHandler;
import io.netty.util.ResourceLeakDetector;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -70,6 +70,7 @@ public class ProxyPass {
private Path dataDir;

public static void main(String[] args) {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
ProxyPass proxy = new ProxyPass();
try {
proxy.boot();
Expand Down Expand Up @@ -154,17 +155,17 @@ public void shutdown() {
}
}

public void saveNBT(String dataName, Tag<?> dataTag) {
public void saveNBT(String dataName, Object dataTag) {
Path path = dataDir.resolve(dataName + ".dat");
try (OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
NBTOutputStream nbtOutputStream = NbtUtils.createNetworkWriter(outputStream)){
nbtOutputStream.write(dataTag);
nbtOutputStream.writeTag(dataTag);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public Tag<?> loadNBT(String dataName) {
public Object loadNBT(String dataName) {
Path path = dataDir.resolve(dataName + ".dat");
try (InputStream inputStream = Files.newInputStream(path);
NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(inputStream)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.nimbusds.jwt.SignedJWT;
import com.nukkitx.nbt.stream.LittleEndianDataOutputStream;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag;
import com.nukkitx.nbt.NBTOutputStream;
import com.nukkitx.nbt.NbtList;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.nbt.util.stream.LittleEndianDataOutputStream;
import com.nukkitx.protocol.bedrock.BedrockClientSession;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
Expand Down Expand Up @@ -68,25 +69,25 @@ public boolean handle(ServerToClientHandshakePacket packet) {
}

public boolean handle(AvailableEntityIdentifiersPacket packet) {
proxy.saveNBT("entity_identifiers", packet.getTag());
proxy.saveNBT("entity_identifiers", packet.getIdentifiers());
return false;
}

public boolean handle(BiomeDefinitionListPacket packet) {
proxy.saveNBT("biome_definitions", packet.getTag());
proxy.saveNBT("biome_definitions", packet.getDefinitions());
return false;
}

public boolean handle(StartGamePacket packet) {
Map<String, Integer> legacyBlocks = new HashMap<>();
for (CompoundTag entry : packet.getBlockPalette().getValue()) {
for (NbtMap entry : packet.getBlockPalette()) {
legacyBlocks.putIfAbsent(entry.getCompound("block").getString("name"), (int) entry.getShort("id"));
}

proxy.saveJson("legacy_block_ids.json", sortMap(legacyBlocks));
List<CompoundTag> palette = new ArrayList<>(packet.getBlockPalette().getValue());
List<NbtMap> palette = new ArrayList<>(packet.getBlockPalette());
palette.sort(Comparator.comparingInt(value -> value.getShort("id")));
proxy.saveNBT("runtime_block_states", new ListTag<>("", CompoundTag.class, palette));
proxy.saveNBT("runtime_block_states", new NbtList<>(NbtType.COMPOUND, palette));
BlockPaletteUtils.convertToJson(proxy, palette);

List<DataEntry> itemData = new ArrayList<>();
Expand Down Expand Up @@ -125,12 +126,12 @@ private void dumpCreativeItems(ItemData[] contents) {
int id = data.getId();
Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage();

CompoundTag tag = data.getTag();
NbtMap tag = data.getTag();
String tagData = null;
if (tag != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianDataOutputStream(byteArrayOutputStream))) {
stream.write(tag);
stream.writeTag(tag);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.nukkitx.proxypass.network.bedrock.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.nukkitx.nbt.TagType;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtType;
import com.nukkitx.proxypass.ProxyPass;
import lombok.Value;

Expand All @@ -13,23 +13,23 @@

public class BlockPaletteUtils {

public static void convertToJson(ProxyPass proxy, List<CompoundTag> tags) {
public static void convertToJson(ProxyPass proxy, List<NbtMap> tags) {

List<Entry> palette = new ArrayList<>(tags.size());

for (CompoundTag tag : tags) {
for (NbtMap tag : tags) {
int id = tag.getShort("id");
CompoundTag blockTag = tag.getCompound("block");
NbtMap blockTag = tag.getCompound("block");
String name = blockTag.getString("name");

Map<String, BlockState> states = new LinkedHashMap<>();

blockTag.getCompound("states").getValue().forEach((key, value) -> {
states.put(key, new BlockState(value.getValue(), TagType.byClass(value.getClass()).getId()));
blockTag.getCompound("states").forEach((key, value) -> {
states.put(key, new BlockState(value, NbtType.byClass(value.getClass()).getId()));
});

Integer meta = null;
if (tag.contains("meta")) {
if (tag.containsKey("meta")) {
meta = (int) tag.getShort("meta");
}
palette.add(new Entry(id, meta, name, states));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.nukkitx.proxypass.network.bedrock.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.nukkitx.nbt.NBTOutputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.inventory.*;
import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket;
import com.nukkitx.proxypass.ProxyPass;
Expand Down Expand Up @@ -111,11 +111,11 @@ private static Item[] writeItemArray(ItemData[] inputs, boolean output) {
return outputs.toArray(new Item[0]);
}

private static String nbtToBase64(CompoundTag tag) {
private static String nbtToBase64(NbtMap tag) {
if (tag != null) {
ByteArrayOutputStream tagStream = new ByteArrayOutputStream();
try (NBTOutputStream writer = NbtUtils.createWriterLE(tagStream)) {
writer.write(tag);
writer.writeTag(tag);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit ad2c4fc

Please sign in to comment.