add support for fire

This commit is contained in:
Lukas 2020-09-07 08:50:42 +02:00
parent 885357f0b1
commit d7004942ad
6 changed files with 92 additions and 44 deletions

View File

@ -79,14 +79,14 @@ public class World {
public void setChunk(ChunkLocation location, Chunk chunk) {
chunks.put(location, chunk);
MainWindow.getRenderer().prepareChunk(location, chunk);
MainWindow.getRenderer().queueChunk(location, chunk);
}
public void setChunks(HashMap<ChunkLocation, Chunk> chunkMap) {
for (Map.Entry<ChunkLocation, Chunk> set : chunkMap.entrySet()) {
chunks.put(set.getKey(), set.getValue());
}
MainWindow.getRenderer().prepareChunkBulk(chunkMap);
MainWindow.getRenderer().queueChunkBulk(chunkMap);
}
public boolean isHardcore() {

View File

@ -20,10 +20,10 @@ import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.render.blockModels.BlockModelLoader;
import de.bixilon.minosoft.render.blockModels.Face.Face;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import javafx.util.Pair;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import static de.bixilon.minosoft.render.blockModels.Face.RenderConstants.faceDir;
import static org.lwjgl.opengl.GL11.*;
@ -32,21 +32,41 @@ public class WorldRenderer {
private final HashMap<BlockPosition, HashSet<Face>> faces;
private BlockModelLoader modelLoader;
private LinkedBlockingQueue<Pair<ChunkLocation, Chunk>> queuedChunks;
Thread chunkLoadThread;
public WorldRenderer() {
faces = new HashMap<>();
}
public void init() {
queuedChunks = new LinkedBlockingQueue<>();
chunkLoadThread = new Thread(() -> {
while (true) {
try {
Pair<ChunkLocation, Chunk> current = queuedChunks.take();
prepareChunk(current.getKey(), current.getValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
chunkLoadThread.setName(String.format("%d/ChunkLoading", 0)); // TODO: connection ID
chunkLoadThread.start();
modelLoader = new BlockModelLoader();
Log.info("Finished loading textures");
}
public void prepareChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
public void queueChunkBulk(HashMap<ChunkLocation, Chunk> chunks) {
for (Map.Entry<ChunkLocation, Chunk> set : chunks.entrySet()) {
prepareChunk(set.getKey(), set.getValue());
queueChunk(set.getKey(), set.getValue());
}
}
public void queueChunk(ChunkLocation location, Chunk chunk) {
queuedChunks.add(new Pair<>(location, chunk));
}
public void prepareChunk(ChunkLocation location, Chunk chunk) {
int xOffset = location.getX() * 16;
int zOffset = location.getZ() * 16;
@ -61,8 +81,9 @@ public class WorldRenderer {
}
public void prepareBlock(BlockPosition position, Block block) {
if (block.equals(Blocks.nullBlock))
if (block.equals(Blocks.nullBlock)) {
faces.put(position, null);
}
HashMap<FaceOrientation, Boolean> adjacentBlocks = new HashMap<>();
for (FaceOrientation orientation : FaceOrientation.values()) {

View File

@ -134,7 +134,7 @@ public class BlockModel {
}
}
private void applyConfigurationTextures(HashSet<SubBlock> subBlocks, String mod, TextureLoader loader) {
public static void applyConfigurationTextures(HashSet<SubBlock> subBlocks, String mod, TextureLoader loader) {
for (SubBlock subBlock : subBlocks) {
subBlock.applyTextures(mod, loader);
}

View File

@ -20,7 +20,9 @@ import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.BlockRotation;
import de.bixilon.minosoft.render.blockModels.Face.Face;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
import de.bixilon.minosoft.render.texture.TextureLoader;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -74,4 +76,28 @@ public class FireModel extends BlockModel {
public boolean isFull() {
return false;
}
@Override
public HashSet<String> getAllTextures() {
HashSet<String> result = new HashSet<>();
result.addAll(getTextures(floor));
result.addAll(getTextures(side));
result.addAll(getTextures(up));
return result;
}
private HashSet<String> getTextures(HashSet<SubBlock> subBlocks) {
HashSet<String> result = new HashSet<>();
for (SubBlock subBlock : subBlocks) {
result.addAll(subBlock.getTextures());
}
return result;
}
@Override
public void applyTextures(String mod, TextureLoader loader) {
applyConfigurationTextures(floor, mod, loader);
applyConfigurationTextures(side, mod, loader);
applyConfigurationTextures(up, mod, loader);
}
}

View File

@ -139,7 +139,8 @@ public class SubBlock {
public HashSet<Face> getFacesSimple(BlockRotation rotation) {
HashSet<Face> result = new HashSet<>();
for (FaceOrientation orientation : FaceOrientation.values()) {
result.add(prepareFace(orientation, rotation, new HashMap<>()));
result.add(new Face(textureCoordinates.get(orientation), uv.get(orientation),
cuboid.getFacePositions(orientation, rotation)));
}
return result;
}

View File

@ -445,38 +445,6 @@
}
]
},
"sticky_piston": {
"states": [
{
"properties": {
"extended": "true"
},
"blockModel": "piston_extended"
},
{
"properties": {
"extended": "false"
},
"blockModel": "sticky_piston"
}
]
},
"piston": {
"states": [
{
"properties": {
"extended": "true"
},
"blockModel": "piston_extended"
},
{
"properties": {
"extended": "false"
},
"blockModel": "piston"
}
]
},
"cobweb": {
"blockModel": "cobweb"
},
@ -662,11 +630,43 @@
},
"fire": {
"type": "fire",
"floor": "fire_floor_0",
"floor": "fire_floor0",
"side": "fire_side0",
"up": "fire_up_0"
"up": "fire_up0"
}
},
"sticky_piston": {
"states": [
{
"properties": {
"extended": "true"
},
"blockModel": "piston_extended"
},
{
"properties": {
"extended": "false"
},
"blockModel": "sticky_piston"
}
]
},
"piston": {
"states": [
{
"properties": {
"extended": "true"
},
"blockModel": "piston_extended"
},
{
"properties": {
"extended": "false"
},
"blockModel": "piston"
}
]
},
"tinted_textures": {
"block/grass_block_top": [0,1,0],
"block/grass": [0,1,0]