broken code
parent
3fa830fa03
commit
85ecd4e098
|
@ -5,9 +5,9 @@ import org.joml.Vector3f;
|
|||
import com.github.halotroop.litecraft.world.Chunk;
|
||||
import com.github.hydos.ginger.engine.elements.objects.RenderObject;
|
||||
|
||||
public class BlockEntity extends RenderObject
|
||||
public class BlockInstance extends RenderObject
|
||||
{
|
||||
public BlockEntity(Block block, Vector3f position)
|
||||
public BlockInstance(Block block, Vector3f position)
|
||||
{ super(block.model, position, 0, 0, 0, new Vector3f(1f, 1f, 1f)); }
|
||||
|
||||
public void processCulling(Chunk chunk)
|
|
@ -23,14 +23,14 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
{ return (x & MAX_POS) | ((y & MAX_POS) << POS_SHIFT) | ((z & MAX_POS) << DOUBLE_SHIFT); }
|
||||
|
||||
private final Block[] blocks = new Block[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
private BlockEntity[] blockEntities = new BlockEntity[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
private BlockInstance[] blockEntities = new BlockInstance[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
private boolean render = false;
|
||||
public final int chunkX, chunkY, chunkZ;
|
||||
public final int chunkStartX, chunkStartY, chunkStartZ;
|
||||
private boolean fullyGenerated = false;
|
||||
public final int dimension;
|
||||
private boolean dirty = true;
|
||||
private BlockEntity[] renderedBlocks;
|
||||
private BlockInstance[] renderedBlocks;
|
||||
|
||||
public Chunk(int chunkX, int chunkY, int chunkZ, int dimension)
|
||||
{
|
||||
|
@ -57,7 +57,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
return blocks[index(x, y, z)];
|
||||
}
|
||||
|
||||
public BlockEntity getBlockEntity(int x, int y, int z)
|
||||
public BlockInstance getBlockEntity(int x, int y, int z)
|
||||
{
|
||||
if (x > CHUNK_SIZE || y > CHUNK_SIZE || z > CHUNK_SIZE || x < 0 || y < 0 || z < 0)
|
||||
{ throw new RuntimeException("Block [" + x + ", " + y + ", " + z + ", " + "] out of chunk bounds!"); }
|
||||
|
@ -71,14 +71,14 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
if (dirty)
|
||||
{
|
||||
dirty = false;
|
||||
renderedBlocks = new BlockEntity[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
renderedBlocks = new BlockInstance[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
for (int x = 0; x < CHUNK_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < CHUNK_SIZE; y++)
|
||||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; z++)
|
||||
{
|
||||
BlockEntity block = getBlockEntity(x, y, z);
|
||||
BlockInstance block = getBlockEntity(x, y, z);
|
||||
if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1)
|
||||
{
|
||||
renderedBlocks[index(x, y, z)] = block;
|
||||
|
@ -111,18 +111,15 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
else if (z < 0) z = 0;
|
||||
this.blocks[index(x, y, z)] = block;
|
||||
if (this.render)
|
||||
{ this.blockEntities[index(x, y, z)] = new BlockEntity(block, new Vector3f(this.chunkStartX + x, this.chunkStartY + y, this.chunkStartZ + z)); }
|
||||
{ this.blockEntities[index(x, y, z)] = new BlockInstance(block, new Vector3f(this.chunkStartX + x, this.chunkStartY + y, this.chunkStartZ + z)); }
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public void setRender(boolean render)
|
||||
{
|
||||
if (render && !this.render) // if it has been changed to true
|
||||
{
|
||||
for (int x = 0; x < CHUNK_SIZE; ++x)
|
||||
{
|
||||
for (int y = 0; y < CHUNK_SIZE; ++y)
|
||||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; ++z)
|
||||
{
|
||||
Block block = this.blocks[index(x, y, z)];
|
||||
|
@ -130,17 +127,14 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
|||
System.out.println(index(x, y, z));
|
||||
}
|
||||
|
||||
if (block.isVisible()) this.blockEntities[index(x, y, z)] = new BlockEntity(block,
|
||||
this.blockEntities[index(x, y, z)] = new BlockInstance(block,
|
||||
new Vector3f(
|
||||
this.chunkStartX + x,
|
||||
this.chunkStartY + y,
|
||||
this.chunkStartZ + z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.render) // else if it has been changed to false
|
||||
{ blockEntities = new BlockEntity[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE]; }
|
||||
blockEntities = new BlockInstance[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
|
||||
this.render = render;
|
||||
dirty = true;
|
||||
}
|
||||
|
|
|
@ -27,21 +27,6 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
private final int dimension;
|
||||
public Player player;
|
||||
|
||||
public int findAir(int x, int z)
|
||||
{
|
||||
int y = SEA_LEVEL;
|
||||
int attemptsRemaining = 255;
|
||||
|
||||
while (attemptsRemaining --> 0)
|
||||
{
|
||||
// DO NOT CHANGE TO y++
|
||||
if (this.getBlock(x, ++y, z) == Blocks.AIR)
|
||||
return y;
|
||||
}
|
||||
|
||||
return -1; // if it fails, returns -1
|
||||
}
|
||||
|
||||
// This will likely become the main public constructor after we add dynamic chunkloading
|
||||
private World(long seed, Dimension<?> dim, LitecraftSave save)
|
||||
{
|
||||
|
@ -55,7 +40,13 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
}
|
||||
|
||||
public void spawnPlayer()
|
||||
{ this.spawnPlayer(0, 0, -3); }
|
||||
{
|
||||
int y = this.findAir(0, 0);
|
||||
if (y == -1)
|
||||
y = 300; // yeet
|
||||
|
||||
this.spawnPlayer(0, y, -3);
|
||||
}
|
||||
|
||||
public Player spawnPlayer(float x, float y, float z)
|
||||
{
|
||||
|
@ -73,11 +64,26 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
System.out.println("Generating world!");
|
||||
for (int i = (0 - (size / 2)); i < (size / 2); i++)
|
||||
for (int k = (0 - (size / 2)); k < (size / 2); k++)
|
||||
for (int y = -2; y < 0; ++y)
|
||||
for (int y = -2; y < 2; ++y)
|
||||
this.loadChunk(i, y, k).setRender(true);
|
||||
System.out.println("Generated world in " + (System.currentTimeMillis() - time) + " milliseconds");
|
||||
}
|
||||
|
||||
public int findAir(int x, int z)
|
||||
{
|
||||
int y = SEA_LEVEL;
|
||||
int attemptsRemaining = 255;
|
||||
|
||||
while (attemptsRemaining --> 0)
|
||||
{
|
||||
// DO NOT CHANGE TO y++
|
||||
if (this.getBlock(x, ++y, z) == Blocks.AIR)
|
||||
return y;
|
||||
}
|
||||
|
||||
return -1; // if it fails, returns -1
|
||||
}
|
||||
|
||||
public Chunk getChunk(int chunkX, int chunkY, int chunkZ)
|
||||
{
|
||||
Chunk chunk = this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos ->
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.joml.Matrix4f;
|
|||
import org.lwjgl.opengl.*;
|
||||
|
||||
import com.github.halotroop.litecraft.Litecraft;
|
||||
import com.github.halotroop.litecraft.types.block.BlockEntity;
|
||||
import com.github.halotroop.litecraft.types.block.BlockInstance;
|
||||
import com.github.halotroop.litecraft.world.Chunk;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
import com.github.hydos.ginger.engine.api.GingerRegister;
|
||||
|
@ -61,21 +61,20 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render(BlockEntity[] renderList)
|
||||
public void render(BlockInstance[] renderList)
|
||||
{
|
||||
shader.start();
|
||||
shader.loadSkyColour(Window.getColour());
|
||||
shader.loadViewMatrix(GingerRegister.getInstance().game.data.camera);
|
||||
TexturedModel model = renderList[0].getModel();
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
{ GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE); }
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
|
||||
//
|
||||
for (int x = 0; x < CHUNK_SIZE; x++)
|
||||
{
|
||||
for (int y = 0; y < CHUNK_SIZE; y++)
|
||||
{
|
||||
for (int z = 0; z < CHUNK_SIZE; z++)
|
||||
{
|
||||
BlockEntity entity = renderList[Chunk.index(x, y, z)];
|
||||
BlockInstance entity = renderList[Chunk.index(x, y, z)];
|
||||
if (entity != null && entity.getModel() != null)
|
||||
{
|
||||
prepTexture(entity.getModel().getTexture(), entity.getModel().getTexture().getTextureID());
|
||||
|
@ -83,10 +82,8 @@ public class BlockRenderer extends Renderer implements WorldGenConstants
|
|||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GingerRegister.getInstance().wireframe)
|
||||
{ GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL); }
|
||||
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
|
||||
shader.stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.*;
|
|||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.BlockEntity;
|
||||
import com.github.halotroop.litecraft.types.block.BlockInstance;
|
||||
import com.github.hydos.ginger.engine.api.GingerRegister;
|
||||
import com.github.hydos.ginger.engine.elements.objects.RenderObject;
|
||||
import com.github.hydos.ginger.engine.io.Window;
|
||||
|
@ -84,7 +84,7 @@ public class ObjectRenderer extends Renderer
|
|||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
public void render(List<BlockEntity> renderList)
|
||||
public void render(List<BlockInstance> renderList)
|
||||
{
|
||||
prepare();
|
||||
shader.start();
|
||||
|
|
Loading…
Reference in New Issue