Made it so that blocks stay in unloaded chunks. Also added the stuff needed for scene2d.ui
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
//https://www.redblobgames.com/maps/terrain-from-noise/
|
||||
package Collector.Dimension;
|
||||
|
||||
import com.github.czyzby.kiwi.util.tuple.immutable.Pair;
|
||||
import com.github.czyzby.kiwi.util.tuple.immutable.Triple;
|
||||
import Collector.OpenSimplexNoise;
|
||||
|
||||
@@ -11,34 +10,37 @@ import static Collector.Dimension.BlockMaterials.materials;
|
||||
import static Collector.Restrictions.*;
|
||||
|
||||
public class Chunks {
|
||||
public static HashMap<Triple<Integer, Integer, Integer>, Block> blocks = new HashMap<>();
|
||||
public static HashMap<Pair<Integer, Integer>, Block> buildings = new HashMap<>();
|
||||
public static HashMap<Triple<Integer, Integer, Integer>, Block> loadedChunks = new HashMap<>();
|
||||
public static HashMap<Triple<Integer, Integer,Integer>, Block> savedChunks = new HashMap<>();
|
||||
public static OpenSimplexNoise gen1 = new OpenSimplexNoise(SEED + 1);
|
||||
public static OpenSimplexNoise gen2 = new OpenSimplexNoise(SEED);
|
||||
|
||||
public static void create() {
|
||||
int i = 10;
|
||||
setBlock(3 + i, 2, "wall");
|
||||
setBlock(4 + i, 2, "wall");
|
||||
setBlock(3 + i, 3, "roof");
|
||||
setBlock(4 + i, 3, "roof");
|
||||
setBlock(3 + i, 2,1,"wall");
|
||||
setBlock(4 + i, 2,1,"wall");
|
||||
setBlock(3 + i, 3,1, "roof");
|
||||
setBlock(4 + i, 3,1,"roof");
|
||||
}
|
||||
|
||||
public static void setBlock(int x, int y, String name) {
|
||||
buildings.put(new Pair<>(x, y), materials.get(name));
|
||||
public static void setBlock(int x, int y,int z, String name) {
|
||||
loadedChunks.put(new Triple<>(x, y, z), materials.get(name));
|
||||
savedChunks.put(new Triple<>(x, y, z), materials.get(name));
|
||||
}
|
||||
|
||||
public static void placeBlock(int x, int y, String name){
|
||||
Triple<Integer, Integer, Integer> triple = new Triple<>(x, y, 1);
|
||||
if(Chunks.blocks.get(triple).getName().equals("air")) {
|
||||
Chunks.blocks.replace(triple, Chunks.blocks.get(triple), materials.get(name));
|
||||
if(Chunks.loadedChunks.get(triple).getName().equals("air")) {
|
||||
Chunks.loadedChunks.replace(triple, Chunks.loadedChunks.get(triple), materials.get(name));
|
||||
Chunks.savedChunks.replace(triple, Chunks.savedChunks.get(triple), materials.get(name));
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeBlock(int x, int y){
|
||||
Triple<Integer, Integer, Integer> triple = new Triple<>(x, y, 1);
|
||||
if(!Chunks.blocks.get(triple).getName().equals("air")) {
|
||||
Chunks.blocks.replace(triple, Chunks.blocks.get(triple), materials.get("air"));
|
||||
if(!Chunks.loadedChunks.get(triple).getName().equals("air")) {
|
||||
Chunks.loadedChunks.replace(triple, Chunks.loadedChunks.get(triple), materials.get("air"));
|
||||
Chunks.savedChunks.replace(triple, Chunks.savedChunks.get(triple), materials.get("air"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,14 +53,14 @@ public class Chunks {
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.remove(new Triple<>(i, j, 0), getTerrain(i, j));
|
||||
loadedChunks.remove(new Triple<>(i, j, 0), getTerrain(i, j));
|
||||
}
|
||||
}
|
||||
//Second Layer
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int j = startY; j != endY; j++) {
|
||||
Triple<Integer,Integer,Integer> triple = new Triple<>(i, j,1);
|
||||
blocks.remove(triple, blocks.get(triple));
|
||||
loadedChunks.remove(triple, loadedChunks.get(triple));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +74,14 @@ public class Chunks {
|
||||
//Going from start of selected chunk to end of selected chunk in x and y
|
||||
for (int i = startX; i != endX; i++) {
|
||||
for (int j = startY; j != endY; j++) {
|
||||
blocks.put(new Triple<>(i, j, 0), getTerrain(i, j));
|
||||
Triple<Integer, Integer, Integer> triple = new Triple<>(i, j, 0);
|
||||
if(savedChunks.get(triple) != null){
|
||||
loadedChunks.put(triple,savedChunks.get(triple));
|
||||
}
|
||||
else {
|
||||
loadedChunks.put(triple, getTerrain(i, j));
|
||||
savedChunks.put(triple, getTerrain(i,j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +89,14 @@ public class Chunks {
|
||||
for (int i = startX; i != endX; i++){
|
||||
for (int j = startY; j != endY; j++) {
|
||||
Triple<Integer,Integer,Integer> triple = new Triple<>(i, j,1);
|
||||
blocks.put(triple, getBuildings(i,j));
|
||||
loadedChunks.put(triple, getBlocks(i,j,1));
|
||||
savedChunks.put(triple, getBlocks(i,j,1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Block getBuildings(int x, int y) {
|
||||
return buildings.getOrDefault(new Pair<>(x, y), new Block("air"));
|
||||
public static Block getBlocks(int x, int y, int z) {
|
||||
return savedChunks.getOrDefault(new Triple<>(x, y, z), new Block("air"));
|
||||
}
|
||||
|
||||
public static double noise1(double nx, double ny) {
|
||||
@@ -176,7 +186,7 @@ public class Chunks {
|
||||
}
|
||||
|
||||
public static Boolean isEmpty(int x, int y){
|
||||
return blocks.get(new Triple<>(x * 8, y * 8,0)) == null;
|
||||
return loadedChunks.get(new Triple<>(x * 8, y * 8,0)) == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ public class WorldRenderer implements Restrictions {
|
||||
}
|
||||
|
||||
public void drawWorld(Batch batch, int layer) {
|
||||
for (Iterator<Triple<Integer, Integer, Integer>> iterator = Chunks.blocks.keySet().iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<Triple<Integer, Integer, Integer>> iterator = Chunks.loadedChunks.keySet().iterator(); iterator.hasNext(); ) {
|
||||
Triple<Integer, Integer, Integer> chunkpair = iterator.next();
|
||||
if (chunkpair.getThird() == layer) {
|
||||
batch.draw(
|
||||
BlockMaterials.textures.get(Chunks.blocks.get(chunkpair).getName()),
|
||||
BlockMaterials.textures.get(Chunks.loadedChunks.get(chunkpair).getName()),
|
||||
chunkpair.getFirst() << TILE_SHIFT,
|
||||
chunkpair.getSecond() << TILE_SHIFT
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user