diff --git a/cubyz-common/src/io/cubyz/api/base/BaseMod.java b/cubyz-common/src/io/cubyz/api/base/BaseMod.java index e8aa4b3c..453a233a 100644 --- a/cubyz-common/src/io/cubyz/api/base/BaseMod.java +++ b/cubyz-common/src/io/cubyz/api/base/BaseMod.java @@ -1,10 +1,11 @@ - package io.cubyz.api.base; +package io.cubyz.api.base; import io.cubyz.api.EventHandler; 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); } } diff --git a/cubyz-common/src/io/cubyz/world/Chunk.java b/cubyz-common/src/io/cubyz/world/Chunk.java index 9413b1dc..d4a3b30b 100644 --- a/cubyz-common/src/io/cubyz/world/Chunk.java +++ b/cubyz-common/src/io/cubyz/world/Chunk.java @@ -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)); } } } diff --git a/cubyz-common/src/io/cubyz/world/Structures.java b/cubyz-common/src/io/cubyz/world/Structures.java index 8f162d0b..1e3c8f31 100644 --- a/cubyz-common/src/io/cubyz/world/Structures.java +++ b/cubyz-common/src/io/cubyz/world/Structures.java @@ -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); @@ -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); + } + } + } } \ No newline at end of file