mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
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:
parent
030c71b0a5
commit
f3e7243ce2
@ -1,10 +1,11 @@
|
|||||||
package io.cubyz.api.base;
|
package io.cubyz.api.base;
|
||||||
|
|
||||||
import io.cubyz.api.EventHandler;
|
import io.cubyz.api.EventHandler;
|
||||||
import io.cubyz.api.Mod;
|
import io.cubyz.api.Mod;
|
||||||
import io.cubyz.api.Registry;
|
import io.cubyz.api.Registry;
|
||||||
import io.cubyz.blocks.Bedrock;
|
import io.cubyz.blocks.Bedrock;
|
||||||
import io.cubyz.blocks.Block;
|
import io.cubyz.blocks.Block;
|
||||||
|
import io.cubyz.blocks.Cactus;
|
||||||
import io.cubyz.blocks.CoalOre;
|
import io.cubyz.blocks.CoalOre;
|
||||||
import io.cubyz.blocks.DiamondOre;
|
import io.cubyz.blocks.DiamondOre;
|
||||||
import io.cubyz.blocks.Dirt;
|
import io.cubyz.blocks.Dirt;
|
||||||
@ -30,8 +31,9 @@ public class BaseMod {
|
|||||||
|
|
||||||
// Normal:
|
// Normal:
|
||||||
static Bedrock bedrock;
|
static Bedrock bedrock;
|
||||||
static Grass grass;
|
static Cactus cactus;
|
||||||
static Dirt dirt;
|
static Dirt dirt;
|
||||||
|
static Grass grass;
|
||||||
static Ice ice;
|
static Ice ice;
|
||||||
static OakLeaves oakLeaves;
|
static OakLeaves oakLeaves;
|
||||||
static OakLog oakLog;
|
static OakLog oakLog;
|
||||||
@ -60,6 +62,7 @@ public class BaseMod {
|
|||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
bedrock = new Bedrock();
|
bedrock = new Bedrock();
|
||||||
|
cactus = new Cactus();
|
||||||
grass = new Grass();
|
grass = new Grass();
|
||||||
dirt = new Dirt();
|
dirt = new Dirt();
|
||||||
ice = new Ice();
|
ice = new Ice();
|
||||||
@ -82,7 +85,7 @@ public class BaseMod {
|
|||||||
water = new Water();
|
water = new Water();
|
||||||
|
|
||||||
// Register
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -212,8 +212,8 @@ public class Chunk {
|
|||||||
int incx = px == 0 ? 1 : -1;
|
int incx = px == 0 ? 1 : -1;
|
||||||
int incy = py == 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;
|
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)"
|
if (map[px][py] * World.WORLD_HEIGHT >= SEA_LEVEL + 4) {
|
||||||
Structures.generateTree(this, wx + px, (int) (map[px][py] * World.WORLD_HEIGHT) + 1, wy + py);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,26 @@ package io.cubyz.world;
|
|||||||
|
|
||||||
import io.cubyz.api.CubzRegistries;
|
import io.cubyz.api.CubzRegistries;
|
||||||
import io.cubyz.blocks.*;
|
import io.cubyz.blocks.*;
|
||||||
import io.cubyz.modding.ModLoader;
|
|
||||||
import io.cubyz.world.*;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.joml.*;
|
|
||||||
|
|
||||||
public class Structures {
|
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
|
//Instances
|
||||||
Block wood = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_log");
|
Block wood = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_log");
|
||||||
Block leaves = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_leaves");
|
Block leaves = CubzRegistries.BLOCK_REGISTRY.getByID("cubyz:oak_leaves");
|
||||||
|
|
||||||
//Position of the first block of wood
|
//Position of the first block of wood
|
||||||
int height = 7 + random.nextInt(5);
|
height += 7;
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
if (y + i < World.WORLD_HEIGHT) {
|
if (y + i < World.WORLD_HEIGHT) {
|
||||||
ch.addBlock(wood, x, y + i, z);
|
ch.addBlock(wood, x, y + i, z);
|
||||||
@ -38,5 +40,18 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user