Skip to content

Commit

Permalink
Fix issue issue in blockpalette.
Browse files Browse the repository at this point in the history
It wasn't correctly loading blocks with a non-zero default rotation.
  • Loading branch information
IntegratedQuantum committed Apr 30, 2022
1 parent 0a100c6 commit ba83134
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/cubyz/rendering/MainRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/cubyz/world/save/BlockPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/cubyz/world/save/Palette.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class Palette <T extends RegistryElement> {
private final HashMap<T, Integer> TToInt = new HashMap<T, Integer>();
private Object[] intToT = new Object[0];
private RegistryElement[] intToT = new RegistryElement[0];
private final WorldIO wio;
public Palette(JsonObject json, Registry<T> registry, WorldIO wio) {
this.wio = wio;
Expand All @@ -27,15 +27,15 @@ public Palette(JsonObject json, Registry<T> 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;
}
Expand Down

0 comments on commit ba83134

Please sign in to comment.