Search in sources :

Example 1 with ProxyPass

use of com.nukkitx.proxypass.ProxyPass in project ProxyPass by CloudburstMC.

the class BlockPaletteUtils method convertToJson.

public static void convertToJson(ProxyPass proxy, List<NbtMap> tags) {
    List<NbtMap> palette = new ArrayList<>(tags);
    palette.sort((o1, o2) -> {
        int compare = Integer.compare(o1.getShort("id"), o2.getShort("id"));
        if (compare == 0) {
            NbtMap states1 = o1.getCompound("block").getCompound("states");
            NbtMap states2 = o2.getCompound("block").getCompound("states");
            for (Map.Entry<String, Object> entry : states1.entrySet()) {
                Object bs2 = states2.get(entry.getKey());
                compare = ((Comparable) entry.getValue()).compareTo(bs2);
                if (compare != 0) {
                    break;
                }
            }
        }
        return compare;
    });
    proxy.saveMojangson("runtime_block_states.mojangson", NbtMap.builder().putList("palette", NbtType.COMPOUND, palette).build());
    // Get all block states
    Map<String, Set<Object>> blockTraits = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (NbtMap tag : tags) {
        NbtMap map = tag.getCompound("block").getCompound("states");
        map.forEach((trait, value) -> {
            blockTraits.computeIfAbsent(trait, s -> new HashSet<>()).add(value);
        });
    }
    proxy.saveJson("block_traits.json", blockTraits);
}
Also used : NbtMap(com.nukkitx.nbt.NbtMap) java.util(java.util) NbtType(com.nukkitx.nbt.NbtType) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) ProxyPass(com.nukkitx.proxypass.ProxyPass) Value(lombok.Value) NbtMap(com.nukkitx.nbt.NbtMap) NbtMap(com.nukkitx.nbt.NbtMap)

Aggregations

JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 NbtMap (com.nukkitx.nbt.NbtMap)1 NbtType (com.nukkitx.nbt.NbtType)1 ProxyPass (com.nukkitx.proxypass.ProxyPass)1 java.util (java.util)1 Value (lombok.Value)1