From ba83134c69fac71fc62323d30f1d38049b3057c3 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sat, 30 Apr 2022 16:19:20 +0200 Subject: [PATCH] Fix issue issue in blockpalette. It wasn't correctly loading blocks with a non-zero default rotation. --- src/cubyz/rendering/MainRenderer.java | 4 +--- src/cubyz/world/save/BlockPalette.java | 6 +++--- src/cubyz/world/save/Palette.java | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cubyz/rendering/MainRenderer.java b/src/cubyz/rendering/MainRenderer.java index 94ed2f7e..53057b42 100644 --- a/src/cubyz/rendering/MainRenderer.java +++ b/src/cubyz/rendering/MainRenderer.java @@ -234,10 +234,8 @@ public void render() { light.setDirection(light.getDirection().mul(0.1f*Cubyz.world.getGlobalLighting()/light.getDirection().length())); Window.setClearColor(clearColor); render(ambient, light, worldSpatialList, playerPosition); - + // Update meshes: - // The meshes need to be updated after everything is rendered. Otherwise the vbos get corrupted on some hardware. - // See https://cdn.discordapp.com/attachments/574185221939789855/931591596175147038/unknown.png for an example. do { // A do while loop is used so even when the framerate is low at least one mesh gets updated per frame. ChunkMesh mesh = Meshes.getNextQueuedMesh(); if (mesh == null) break; diff --git a/src/cubyz/world/save/BlockPalette.java b/src/cubyz/world/save/BlockPalette.java index 98a26dc9..82afbade 100644 --- a/src/cubyz/world/save/BlockPalette.java +++ b/src/cubyz/world/save/BlockPalette.java @@ -14,7 +14,7 @@ public BlockPalette(JsonObject json, WorldIO wio) { this.wio = wio; if (json == null) return; for (String key : json.map.keySet()) { - int t = Blocks.getByID(key); + int t = Blocks.getByID(key) & Blocks.TYPE_MASK; TToInt.put(t, json.getInt(key, 0)); } intToT = new int[TToInt.size()]; @@ -24,8 +24,8 @@ public BlockPalette(JsonObject json, WorldIO wio) { } public JsonObject save() { JsonObject json = new JsonObject(); - for (Integer t : TToInt.keySet()) { - json.put(Blocks.id(t).toString(), TToInt.get(t)); + for(int index = 0; index < intToT.length; index++) { + json.put(Blocks.id(intToT[index]).toString(), index); } return json; } diff --git a/src/cubyz/world/save/Palette.java b/src/cubyz/world/save/Palette.java index 849f9b41..a0e8c050 100644 --- a/src/cubyz/world/save/Palette.java +++ b/src/cubyz/world/save/Palette.java @@ -14,7 +14,7 @@ public class Palette { private final HashMap TToInt = new HashMap(); - private Object[] intToT = new Object[0]; + private RegistryElement[] intToT = new RegistryElement[0]; private final WorldIO wio; public Palette(JsonObject json, Registry registry, WorldIO wio) { this.wio = wio; @@ -27,15 +27,15 @@ public Palette(JsonObject json, Registry registry, WorldIO wio) { Logger.warning("A block with ID " + key + " is used in world but isn't available."); } } - intToT = new Object[TToInt.size()]; + intToT = new RegistryElement[TToInt.size()]; for(T t : TToInt.keySet()) { intToT[TToInt.get(t)] = t; } } public JsonObject save() { JsonObject json = new JsonObject(); - for (T t : TToInt.keySet()) { - json.put(t.getRegistryID().toString(), TToInt.get(t)); + for(int index = 0; index < intToT.length; index++) { + json.put(intToT[index].getRegistryID().toString(), index); } return json; }