Skip to content

Commit

Permalink
fix: prevent displaying the last glass block after destroying oit in …
Browse files Browse the repository at this point in the history
…the chunk
  • Loading branch information
mouse0w0 committed Dec 8, 2023
1 parent 570fe46 commit fa947cb
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions client/src/main/java/engine/graphics/voxel/chunk/DrawableChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.joml.Vector3ic;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public final class DrawableChunk extends Geometry {

Expand All @@ -28,7 +30,6 @@ public final class DrawableChunk extends Geometry {

public DrawableChunk(ChunkRenderer renderer) {
this.renderer = renderer;
setBounds(boundingBox);
setTexture(VoxelGraphicsHelper.getVoxelTextureAtlas().getTexture());
setVisible(false);
}
Expand Down Expand Up @@ -77,18 +78,26 @@ public void finishBake(Map<RenderType, VertexDataBuffer> buffers) {
if (pieces == null) {
pieces = new HashMap<>();
}
buffers.forEach((type, vertexDataBuffer) -> {
pieces.computeIfAbsent(type, key -> {
var piece = new DrawableChunkPiece(key);
piece.setTexture(this.getTexture());
piece.setBounds(boundingBox);
DrawableChunk.this.addChild(piece);
return piece;
}).uploadData(vertexDataBuffer);
});

buffers.forEach((renderType, buffer) -> pieces.computeIfAbsent(renderType, this::createPiece).uploadData(buffer));

Set<RenderType> invisibleRenderTypes = new HashSet<>(pieces.keySet());
invisibleRenderTypes.removeAll(buffers.keySet());
for (RenderType invisibleRenderType : invisibleRenderTypes) {
pieces.get(invisibleRenderType).setVisible(false);
}

baking = false;
}

private DrawableChunkPiece createPiece(RenderType renderType) {
var piece = new DrawableChunkPiece(renderType);
piece.setTexture(getTexture());
piece.setBounds(boundingBox);
addChild(piece);
return piece;
}

public void terminateBake() {
baking = false;
}
Expand All @@ -98,21 +107,17 @@ public boolean isDisposed() {
}

private static class DrawableChunkPiece extends Geometry {
private final RenderType type;
private SingleBufMesh mesh;
private final SingleBufMesh mesh;

private DrawableChunkPiece(RenderType type) {
this.type = type;
mesh = SingleBufMesh.builder().setDynamic().drawMode(DrawMode.TRIANGLES).build();
setRenderType(type);
setMesh(mesh = SingleBufMesh.builder().setDynamic().drawMode(DrawMode.TRIANGLES).build());
setMesh(mesh);
}

public void uploadData(VertexDataBuffer buffer) {
mesh.uploadData(buffer);
}

public RenderType getType() {
return type;
setVisible(true);
}
}
}

0 comments on commit fa947cb

Please sign in to comment.