Skip to content

Commit

Permalink
0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Sep 25, 2020
1 parent b256d9d commit fff86dd
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 38 deletions.
32 changes: 11 additions & 21 deletions src/main/java/tk/valoeghese/fc0/client/render/model/ChunkMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,22 @@
import java.util.List;

public class ChunkMesh {
public ChunkMesh(ClientChunk chunk, byte[] tiles, byte[] meta, int x, int z) {
public ChunkMesh(ClientChunk chunk, int x, int z) {
this.x = x << 4;
this.z = z << 4;
this.transform = new Matrix4f().translate(this.x, 0, this.z);
this.tiles = tiles;
this.meta = meta;
this.chunk = chunk;
this.buildMesh();
}

private final int x;
private final int z;
private final Matrix4f transform;
private final byte[] tiles;
private final byte[] meta;
private final RenderedChunk chunk;
private ChunkMeshModel solid;
private ChunkMeshModel translucent;
private ChunkMeshModel water;

public void updateTile(int index, byte tile) {
this.tiles[index] = tile;
this.buildMesh();
}

public void buildMesh() {
public void buildMesh(byte[] tiles, byte[] metas) {
List<RenderedTileFace> faces = new ArrayList<>();
List<RenderedTileFace> waterFaces = new ArrayList<>();
List<RenderedTileFace> translucentFaces = new ArrayList<>();
Expand All @@ -46,29 +36,29 @@ public void buildMesh() {
for (int z = 0; z < 16; ++z) {
for (int y = 0; y < 128; ++y) {
if (this.chunk.renderHeight(y)) {
int tile = this.tiles[index(x, y, z)];
byte meta = this.meta[index(x, y, z)];
int tile = tiles[index(x, y, z)];
byte meta = metas[index(x, y, z)];
Tile instance = Tile.BY_ID[tile];
boolean waterLayer = instance == Tile.WATER;
List<RenderedTileFace> layer = waterLayer ? waterFaces : (instance.isTranslucent() ? translucentFaces : faces);

TileRenderer custom = instance.getCustomTileRenderer();

if (custom != null && instance.shouldRender()) {
custom.addFaces(instance, layer, this.tiles, this.chunk, x, y, z, meta);
custom.addFaces(instance, layer, tiles, this.chunk, x, y, z, meta);
} else if (instance.shouldRender() && instance.isCross()) {
layer.add(
new RenderedCrossTileFace(new Vector3f(x, y, z),
instance,
0.95f * this.chunk.getRenderLightingFactor(x, y, z),
meta));
} else if (instance.shouldRender() || waterLayer) {
Tile tileUp = y == 127 ? Tile.AIR : Tile.BY_ID[this.tiles[index(x, y + 1, z)]];
Tile tileDown = y == 0 ? Tile.AIR : Tile.BY_ID[this.tiles[index(x, y - 1, z)]];
Tile tileWest = x == 0 ? this.chunk.west(z, y) : Tile.BY_ID[this.tiles[index(x - 1, y, z)]];
Tile tileEast = x == 15 ? this.chunk.east(z, y) : Tile.BY_ID[this.tiles[index(x + 1, y, z)]];
Tile tileSouth = z == 0 ? this.chunk.south(x, y) : Tile.BY_ID[this.tiles[index(x, y, z - 1)]];
Tile tileNorth = z == 15 ? this.chunk.north(x, y) : Tile.BY_ID[this.tiles[index(x, y, z + 1)]];
Tile tileUp = y == 127 ? Tile.AIR : Tile.BY_ID[tiles[index(x, y + 1, z)]];
Tile tileDown = y == 0 ? Tile.AIR : Tile.BY_ID[tiles[index(x, y - 1, z)]];
Tile tileWest = x == 0 ? this.chunk.west(z, y) : Tile.BY_ID[tiles[index(x - 1, y, z)]];
Tile tileEast = x == 15 ? this.chunk.east(z, y) : Tile.BY_ID[tiles[index(x + 1, y, z)]];
Tile tileSouth = z == 0 ? this.chunk.south(x, y) : Tile.BY_ID[tiles[index(x, y, z - 1)]];
Tile tileNorth = z == 15 ? this.chunk.north(x, y) : Tile.BY_ID[tiles[index(x, y, z + 1)]];

if (!tileUp.isOpaque(waterLayer, instance)) {
layer.add(new RenderedTileFace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public void handleKeybinds() {
world.writeTile(pos, Tile.CACTUS.id);
} else {
world.writeTile(pos, tile.id);
world.writeMeta(pos.x, pos.y, pos.z, selectedItem.getMeta());
}

tile.onPlace(world, pos);
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/tk/valoeghese/fc0/client/world/ClientChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public ClientChunk(ChunkAccess parent, int x, int z, byte[] tiles, byte[] meta,
}

protected ChunkMesh mesh;
public boolean dirtyForRender = true;

@Override
public void writeMeta(int x, int y, int z, byte meta) {
Expand All @@ -24,8 +25,8 @@ public void writeMeta(int x, int y, int z, byte meta) {
return;
}

this.dirtyForRender = true;
super.writeMeta(x, y, z, meta);
this.rebuildMesh();
}

@Override
Expand All @@ -36,34 +37,34 @@ public void writeTile(int x, int y, int z, byte tile) {
return;
}

this.dirtyForRender = true;
super.writeTile(x, y, z, tile);
this.updateMesh(i, tile);

if (x == 0) {
ClientChunk chunk = (ClientChunk) this.getRenderChunk(this.x - 1, this.z);

if (chunk != null) {
chunk.rebuildMesh();
chunk.dirtyForRender = true;
}
} else if (x == 15) {
ClientChunk chunk = (ClientChunk) this.getRenderChunk(this.x + 1, this.z);

if (chunk != null) {
chunk.rebuildMesh();
chunk.dirtyForRender = true;
}
}

if (z == 0) {
ClientChunk chunk = (ClientChunk) this.getRenderChunk(this.x, this.z - 1);

if (chunk != null) {
chunk.rebuildMesh();
chunk.dirtyForRender = true;
}
} else if (z == 15) {
ClientChunk chunk = (ClientChunk) this.getRenderChunk(this.x, this.z + 1);

if (chunk != null) {
chunk.rebuildMesh();
chunk.dirtyForRender = true;
}
}
}
Expand Down Expand Up @@ -119,21 +120,24 @@ public Tile west(int z, int y) {

void rebuildMesh() {
if (this.mesh != null) {
this.mesh.buildMesh();
this.mesh.buildMesh(this.tiles, this.meta);
}
}

private void updateMesh(int index, byte tile) {
if (this.mesh != null) {
this.mesh.updateTile(index, tile);
private void lebronJames() {
if (this.dirtyForRender && this.mesh != null) {
this.dirtyForRender = false;
this.mesh.buildMesh(this.tiles, this.meta);
}
}

public ChunkMesh getOrCreateMesh() {
if (this.mesh == null) {
this.mesh = new ChunkMesh(this, this.tiles, this.meta, this.x, this.z);
this.mesh = new ChunkMesh(this, this.x, this.z);
}

this.lebronJames();

return this.mesh;
}

Expand All @@ -153,8 +157,8 @@ public void destroy() {
public void refreshLighting() {
super.refreshLighting();

if (this.status == ChunkLoadStatus.RENDER) { // Is this neccesary?
this.rebuildMesh(); // rebuild mesh to account for new lighting
if (this.status == ChunkLoadStatus.RENDER) { // Is this necessary?
this.dirtyForRender = true;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tk/valoeghese/fc0/client/world/ClientWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public List<ClientChunk> getChunksForRendering() {

@Override
protected void onChunkRemove(Chunk c) {
if (c.render) {
c.destroy();
c.destroy();

if (c.render) {
if (this.toAddToQueue.contains(c)) {
this.toAddForRendering.remove(c);
this.toAddToQueue.remove(c);
} else if (this.toAddForRendering.contains(c)) {
this.toAddForRendering.remove(c);
} else if (this.chunksForRendering.contains(c)) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tk/valoeghese/fc0/world/GameplayWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ public void addEntity(Entity entity) {

@Override
public void destroy() {
for (Chunk c : this.chunks.values()) {
c.destroy();
}

this.chunkSaveExecutor.shutdown();
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/tk/valoeghese/fc0/world/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ public final void move(Pos pos) {

// setters and adders etc.

@Override
public int damage(int amount) {
if (this.dev) {
return this.getHealth();
}

return super.damage(amount);
}

@Override
public void setPos(Pos pos) {
super.setPos(pos);
Expand Down
Binary file modified src/main/resources/assets/texture/font_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/data/language/en.gb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ keybind.jump=Jump
keybind.run=Run
keybind.destroy=Destroy
keybind.interact=Interact
keybind.respawn=Respawn
keybind.fov_up=FOV Up
keybind.fov_down=FOV Down

Expand Down

0 comments on commit fff86dd

Please sign in to comment.