finish basic chunk
parent
7cf3b8a219
commit
e61ad114ca
src/main/java/com/github/halotroop/litecraft
types/block
world
|
@ -19,14 +19,15 @@ public class Block
|
||||||
public final TexturedModel model;
|
public final TexturedModel model;
|
||||||
public final boolean visible;
|
public final boolean visible;
|
||||||
|
|
||||||
|
public static final Block AIR = new Block((TexturedModel) null, new Properties().visible(false));
|
||||||
public static final Block GRASS = new Block("block/cubes/soil/gravel.png", new Properties());
|
public static final Block GRASS = new Block("block/cubes/soil/gravel.png", new Properties());
|
||||||
public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties());
|
public static final Block DIRT = new Block("block/cubes/soil/dirt.png", new Properties());
|
||||||
|
|
||||||
public static class Properties { // add properties to this builder!
|
public static class Properties { // add properties to this builder!
|
||||||
private boolean visible = false;
|
private boolean visible = false;
|
||||||
|
|
||||||
public Properties visible(boolean invisible) {
|
public Properties visible(boolean visible) {
|
||||||
this.visible = invisible;
|
this.visible = visible;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ package com.github.halotroop.litecraft.world;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.github.halotroop.litecraft.types.block.*;
|
import com.github.halotroop.litecraft.types.block.Block;
|
||||||
|
import com.github.halotroop.litecraft.types.block.BlockEntity;
|
||||||
import com.github.hydos.ginger.engine.math.vectors.Vector3f;
|
import com.github.hydos.ginger.engine.math.vectors.Vector3f;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap;
|
||||||
|
@ -14,13 +15,19 @@ public class Chunk
|
||||||
public Chunk(int chunkX, int chunkY, int chunkZ)
|
public Chunk(int chunkX, int chunkY, int chunkZ)
|
||||||
{
|
{
|
||||||
this.chunkX = chunkX;
|
this.chunkX = chunkX;
|
||||||
|
this.chunkY = chunkY;
|
||||||
|
this.chunkZ = chunkZ;
|
||||||
|
this.chunkStartX = chunkX << 3;
|
||||||
|
this.chunkStartY = chunkY << 3;
|
||||||
|
this.chunkStartZ = chunkZ << 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Long2ObjectMap<Block> blocks = new Long2ObjectArrayMap<>();
|
private final Long2ObjectMap<Block> blocks = new Long2ObjectArrayMap<>();
|
||||||
private final List<BlockEntity> blockEntities = new ArrayList<>();
|
private final List<BlockEntity> blockEntities = new ArrayList<>();
|
||||||
private boolean render = false;
|
private boolean render = false;
|
||||||
|
|
||||||
public final int chunkX;
|
public final int chunkX, chunkY, chunkZ;
|
||||||
|
private final int chunkStartX, chunkStartY, chunkStartZ;
|
||||||
|
|
||||||
public void setBlock(int x, int y, int z, Block block)
|
public void setBlock(int x, int y, int z, Block block)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +40,10 @@ public class Chunk
|
||||||
|
|
||||||
long hash = posHash(x, y, z);
|
long hash = posHash(x, y, z);
|
||||||
this.blocks.put(hash, block);
|
this.blocks.put(hash, block);
|
||||||
|
|
||||||
|
if (this.render) {
|
||||||
|
this.blockEntities.add(new BlockEntity(block, new Vector3f(this.chunkStartX + x, this.chunkStartY + y, this.chunkStartZ + z)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getBlock(int x, int y, int z)
|
public Block getBlock(int x, int y, int z)
|
||||||
|
@ -40,14 +51,27 @@ public class Chunk
|
||||||
long hash = posHash(x, y, z);
|
long hash = posHash(x, y, z);
|
||||||
return this.blocks.get(hash);
|
return this.blocks.get(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRender(boolean render)
|
public void setRender(boolean render)
|
||||||
{
|
{
|
||||||
if (render && !this.render) // if it has been changed to true
|
if (render && !this.render) // if it has been changed to true
|
||||||
{
|
{
|
||||||
this.blocks.forEach((coord, block) -> {
|
for (int x = 0; x < 8; ++x)
|
||||||
if (block.visible) this.blockEntities.add(new BlockEntity(block, new Vector3f(0,0,0)));
|
{
|
||||||
});
|
for (int y = 0; y < 8; ++y)
|
||||||
|
{
|
||||||
|
for (int z = 0; z < 8; ++z)
|
||||||
|
{
|
||||||
|
long hash = posHash(x, y, z);
|
||||||
|
Block block = this.blocks.get(hash);
|
||||||
|
if (block.visible) this.blockEntities.add(new BlockEntity(block,
|
||||||
|
new Vector3f(
|
||||||
|
this.chunkStartX + x,
|
||||||
|
this.chunkStartY + y,
|
||||||
|
this.chunkStartZ + z)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (this.render) // else if it has been changed to false
|
else if (this.render) // else if it has been changed to false
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue