Add every registered Ore automatically to the chunk generation

This commit is contained in:
IntegratedQuantum 2019-03-31 21:39:40 +02:00
parent f7c07b4285
commit cfb0d63955
2 changed files with 10 additions and 9 deletions

View File

@ -34,15 +34,8 @@ public class Chunk {
private static Ore [] ores;
private static float [] oreChances;
private static int [] oreHeights;
static {
ArrayList<Ore> oress = new ArrayList<>();
oress.add((Ore) br.getByID("cubyz:coal_ore"));
oress.add((Ore) br.getByID("cubyz:iron_ore"));
oress.add((Ore) br.getByID("cubyz:ruby_ore"));
oress.add((Ore) br.getByID("cubyz:gold_ore"));
oress.add((Ore) br.getByID("cubyz:diamond_ore"));
oress.add((Ore) br.getByID("cubyz:emerald_ore"));
ores = oress.toArray(new Ore[0]);
public static void init(Ore [] ores) {
oreChances = new float[ores.length+1];
oreHeights = new int[ores.length];
for(int i = 0; i < ores.length; i++) {
@ -65,6 +58,7 @@ public class Chunk {
for(int i = 0; i < ores.length; i++) {
oreChances[i+1] = oreChances[i] + ores[i].getChance();
}
Chunk.ores = ores;
}
// Liquids:

View File

@ -12,6 +12,7 @@ import io.cubyz.api.CubzRegistries;
import io.cubyz.api.IRegistryElement;
import io.cubyz.blocks.Block;
import io.cubyz.blocks.BlockInstance;
import io.cubyz.blocks.Ore;
import io.cubyz.entity.Entity;
import io.cubyz.entity.Player;
import io.cubyz.save.WorldIO;
@ -203,6 +204,7 @@ public class LocalWorld extends World {
Random r = new Random();
int ID = 0;
seed = r.nextInt();
ArrayList<Ore> ores = new ArrayList<Ore>();
blocks = new Block[CubzRegistries.BLOCK_REGISTRY.registered().length];
for (IRegistryElement ire : CubzRegistries.BLOCK_REGISTRY.registered()) {
Block b = (Block) ire;
@ -219,7 +221,12 @@ public class LocalWorld extends World {
b.ID = ID;
ID++;
}
try {
ores.add((Ore)b);
}
catch(Exception e) {}
}
Chunk.init(ores.toArray(new Ore[ores.size()]));
}
@Override