Add cactus and upgrade vegetation generation:

→ Now there are areas of different vegetation density
→ Removed Random out of Structures so it only depends on the seed
This commit is contained in:
IntegratedQuantum 2019-03-26 20:12:58 +01:00
parent 030c71b0a5
commit f3e7243ce2
3 changed files with 33 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import io.cubyz.api.Mod;
import io.cubyz.api.Registry;
import io.cubyz.blocks.Bedrock;
import io.cubyz.blocks.Block;
import io.cubyz.blocks.Cactus;
import io.cubyz.blocks.CoalOre;
import io.cubyz.blocks.DiamondOre;
import io.cubyz.blocks.Dirt;
@ -30,8 +31,9 @@ public class BaseMod {
// Normal:
static Bedrock bedrock;
static Grass grass;
static Cactus cactus;
static Dirt dirt;
static Grass grass;
static Ice ice;
static OakLeaves oakLeaves;
static OakLog oakLog;
@ -60,6 +62,7 @@ public class BaseMod {
// Normal
bedrock = new Bedrock();
cactus = new Cactus();
grass = new Grass();
dirt = new Dirt();
ice = new Ice();
@ -82,7 +85,7 @@ public class BaseMod {
water = new Water();
// Register
reg.registerAll(bedrock, grass, dirt, ice, oakLeaves, oakLog, sand, snow, stone, coal, diamond, emerald, gold, iron, ruby, water);
reg.registerAll(bedrock, cactus, dirt, grass, ice, oakLeaves, oakLog, sand, snow, stone, coal, diamond, emerald, gold, iron, ruby, water);
}
}

View File

@ -212,8 +212,8 @@ public class Chunk {
int incx = px == 0 ? 1 : -1;
int incy = py == 0 ? 1 : -1;
int temperature = (int)((2-map[px][py]+SEA_LEVEL/(float)World.WORLD_HEIGHT)*heatMap[px][py]*120) - 100;
if (temperature < 40 && map[px][py] * World.WORLD_HEIGHT >= SEA_LEVEL + 3 && value > 0.5f && ((int)((vegetation[px][py]-vegetation[px+incx][py+incy]) * 100000000) & 63) == 1) { // "&(2^n - 1)" is a faster way to do "%(2^n)"
Structures.generateTree(this, wx + px, (int) (map[px][py] * World.WORLD_HEIGHT) + 1, wy + py);
if (map[px][py] * World.WORLD_HEIGHT >= SEA_LEVEL + 4) {
Structures.generateVegetation(this, wx + px, (int) (map[px][py] * World.WORLD_HEIGHT) + 1, wy + py, value, temperature, (int)((vegetation[px][py]-vegetation[px+incx][py+incy]) * 100000000));
}
}
}

View File

@ -2,24 +2,26 @@ package io.cubyz.world;
import io.cubyz.api.CubzRegistries;
import io.cubyz.blocks.*;
import io.cubyz.modding.ModLoader;
import io.cubyz.world.*;
import java.util.Random;
import org.joml.*;
public class Structures {
// Serves to map the vegetation*10+x value to a chance for spawning that vegetation
private static int [] vegMap = {16383, 8191, 4095, 2047, 1023, 511, 255, 127, 127, 63, 63, 63, 31, 31, 31, 31, 31};
private static Random random = new Random();
public static void generateVegetation(Chunk ch, int x, int y, int z, float vegetation, float temperature, int rand) {
if(temperature < 40 && vegetation > 0.4F && (rand&vegMap[(int)(vegetation*5)+6]) == 1) {
generateTree(ch, x, y, z, (rand/1000&3));
} else if(temperature > 40 && (rand&vegMap[(int)(vegetation*10)]) == 1) {
generateCactus(ch, x, y, z, (rand/1000&3));
}
}
public static void generateTree(Chunk ch, int x, int y, int z) {
public static void generateTree(Chunk ch, int x, int y, int z, int height) {
//Instances
Block wood = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_log");
Block leaves = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_leaves");
//Position of the first block of wood
int height = 7 + random.nextInt(5);
height += 7;
for (int i = 0; i < height; i++) {
if (y + i < World.WORLD_HEIGHT) {
ch.addBlock(wood, x, y + i, z);
@ -39,4 +41,17 @@ public class Structures {
}
}
}
public static void generateCactus(Chunk ch, int x, int y, int z, int height) {
//Instances
Block cactus = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:cactus");
//Position of the first block of wood
height += 3;
for (int i = 0; i < height; i++) {
if (y + i < World.WORLD_HEIGHT) {
ch.addBlock(cactus, x, y + i, z);
}
}
}
}