Skip to content

Commit

Permalink
Small fixes and optimisations (#771)
Browse files Browse the repository at this point in the history
* fix == vs equals in map blend colour

* Optimised chunkVersion check

* Various simplifications

* Update chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java

Co-authored-by: Maik Marschner <[email protected]>
  • Loading branch information
NotStirred and leMaik authored Jan 14, 2021
1 parent 23cb133 commit 309950f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
5 changes: 2 additions & 3 deletions chunky/src/java/se/llbit/chunky/map/SurfaceLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import se.llbit.chunky.block.Vine;
import se.llbit.chunky.chunk.BlockPalette;
import se.llbit.chunky.chunk.ChunkData;
import se.llbit.chunky.resources.Texture;
import se.llbit.chunky.world.Biomes;
import se.llbit.chunky.world.Chunk;
import se.llbit.chunky.world.ChunkPosition;
Expand Down Expand Up @@ -80,7 +79,7 @@ public SurfaceLayer(int dim, ChunkData chunkData, BlockPalette palette) {

float[] color = new float[4];

for (; y >= minY && color[3] < 1.f; ) {
while (y >= minY && color[3] < 1.f) {
Block block = palette.get(chunkData.getBlockAt(x, y, z));
float[] blockColor = new float[4];
ColorUtil.getRGBAComponents(block.texture.getAvgColor(), blockColor);
Expand All @@ -97,7 +96,7 @@ public SurfaceLayer(int dim, ChunkData chunkData, BlockPalette palette) {
blockColor[3] = 1.f;// grass colors don't include alpha

y -= 1;
} else if (block.name == "minecraft:ice") {
} else if (block.name.equals("minecraft:ice")) {
color = blend(color, blockColor);
y -= 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,7 @@ public static boolean isValidSceneNameChar(char c) {
if (c < '\u0020') {
return false;
}
if (c > '\u007e' && c < '\u00a0') {
return false;
}
return true;
return c <= '\u007e' || c >= '\u00a0';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,9 @@ public void setOnChunksLoaded(Runnable onChunksLoaded) {
@Override public boolean pollSceneStateChange() {
if (scene.shouldRefresh() && (scene.getForceReset() || resetHandler.allowSceneRefresh())) {
return true;
} else if (scene.getMode() != storedScene.getMode()) {
return true;
} else {
return scene.getMode() != storedScene.getMode();
}
return false;
}

@Override public void withSceneProtected(Consumer<Scene> fun) {
Expand Down
9 changes: 4 additions & 5 deletions chunky/src/java/se/llbit/chunky/world/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,17 @@ private int[] extractHeightmapData(@NotNull Map<String, Tag> data, ChunkData chu
/** Detect Minecraft version that generated the chunk. */
private static String chunkVersion(@NotNull Map<String, Tag> data) {
Tag sections = data.get(LEVEL_SECTIONS);
String version = "?";
if (sections.isList()) {
version = "1.13";
for (SpecificTag section : sections.asList()) {
if (!section.get("Palette").isList()) {
if (!version.equals("?") && section.get("Blocks").isByteArray(SECTION_BYTES)) {
version = "1.12";
if (section.get("Blocks").isByteArray(SECTION_BYTES)) {
return "1.12";
}
}
}
return "1.13";
}
return version;
return "?";
}

private static void loadBlockData(@NotNull Map<String, Tag> data, @NotNull ChunkData chunkData,
Expand Down

0 comments on commit 309950f

Please sign in to comment.