#[1.21.5] Fail to load custom binary data after build

4 messages · Page 1 of 1 (latest)

urban dove
#

Hi, I'm trying to read a custom binary data saved at resources/data/<mode-id>/5.bin, which is build by myself with a python script. It consists of a series of 7-byte-length data. I'm now using IdentifiableResourceReloadListener to read the file and build a struct based on the data. Everything's good when I test it in IDE using runClient launch task, but after I build the jar file and add it to a new Minecraft game, the obtained struct is totally confusing.

Here are my code to load the data:

// public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager manager, Executor prepareExecutor, Executor applyExecutor)
...
try (InputStream stream = manager.open(Identifier.of(MyMod.MOD_ID, "5.bin"))) {
    byte[] item_buffer = new byte[7];
    List<Solution> s = new ArrayList<>();
    while (stream.read(item_buffer) != -1) {
        List<DyeColor> colors = new ArrayList<>();
        int total = item_buffer[3];
        for (int i = 4; i < 7; i++) {
            int idx = (item_buffer[i] & 0xF0) >> 4;
            colors.add(DyeColor.byIndex(idx));
            if (colors.size() == total) {
                break;
            }
            idx = (item_buffer[i] & 0x0F) >> 0;
            colors.add(DyeColor.byIndex(idx));
            if (colors.size() == total) {
                break;
            }
        }
        s.add(new Solution(new Vec3i(item_buffer[0] & 0xff, item_buffer[1] & 0xff, item_buffer[2] & 0xff), colors));
    }
    root = buildTree(s, new ArrayList<Integer>(IntStream.range(0, s.size()).boxed().toList()), 0).get();
} catch (Exception e) {
    e.printStackTrace();
}
...
midnight hedge
urban dove
# midnight hedge can i ask what you’re doing specifically? this seems like a really roundabout wa...

thank you for your reply, I'm new to modding and trying to make a in-game beacon color calculator, since it's hard for me to directly calculate the suitable sequence of stained glasses, I made a python script to do a search and save all non-repeated color-glasses pairs in a binary file and then load it into the game to use. So far I can't be sure the problem is with the file reading, but I'll appreciate it if you could introduce me a better way to load the file on the client side

midnight hedge