Skip to content

Commit

Permalink
More world types (#11)
Browse files Browse the repository at this point in the history
* Added Retro Worldtype API

* Abstract decorator code slightly

* Bug Fixes

* Woods World type

* Paradise Support

* Floating Worldtype Support

* added Hell WorldType

* Tree Fix

* Update OverworldInitialization.java
  • Loading branch information
UselessBullets authored Nov 10, 2023
1 parent b244700 commit 9ad6e66
Show file tree
Hide file tree
Showing 33 changed files with 1,073 additions and 221 deletions.
131 changes: 0 additions & 131 deletions src/main/java/useless/terrainapi/TerrainInitialization.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/useless/terrainapi/TerrainMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;
import useless.terrainapi.api.TerrainAPI;
import useless.terrainapi.config.ConfigManager;
import useless.terrainapi.initialization.TerrainInitialization;


public class TerrainMain implements ModInitializer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package useless.terrainapi.generation;

import net.minecraft.core.block.Block;
import net.minecraft.core.block.BlockSand;
import net.minecraft.core.world.World;
import net.minecraft.core.world.biome.Biome;
import net.minecraft.core.world.chunk.Chunk;
Expand All @@ -17,6 +18,8 @@ public abstract class ChunkDecoratorAPI implements ChunkDecorator {
public final int maxY;
public final int rangeY;
public final float oreHeightModifier;
public long chunkSeed;
protected Parameters parameterBase;
protected ChunkDecoratorAPI(World world) {
this.world = world;

Expand All @@ -26,8 +29,31 @@ protected ChunkDecoratorAPI(World world) {
this.oreHeightModifier = (float)rangeY / 128.0f;
}
@Override
public void decorate(Chunk chunk){
int chunkX = chunk.xPosition;
int chunkZ = chunk.zPosition;

int xCoord = chunkX * 16;
int zCoord = chunkZ * 16;
int yCoord = this.world.getHeightValue(xCoord + 16, zCoord + 16);

Biome biome = this.world.getBlockBiome(xCoord + 16, yCoord, zCoord + 16);

Random random = new Random(this.world.getRandomSeed());
long l1 = random.nextLong() / 2L * 2L + 1L;
long l2 = random.nextLong() / 2L * 2L + 1L;
chunkSeed = (long)chunkX * l1 + (long)chunkZ * l2 ^ this.world.getRandomSeed();
random.setSeed(chunkSeed);
parameterBase = new Parameters(biome, random, chunk, this);

BlockSand.fallInstantly = true;

decorateAPI();

BlockSand.fallInstantly = false;
}
@ApiStatus.Internal
public abstract void decorate(Chunk chunk);
public abstract void decorateAPI();
@ApiStatus.Internal
public abstract void generateStructures(Biome biome, Chunk chunk, Random random);
@ApiStatus.Internal
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/useless/terrainapi/generation/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.core.world.biome.Biome;
import net.minecraft.core.world.chunk.Chunk;
import net.minecraft.core.world.generate.chunk.ChunkDecorator;

import java.util.Random;

Expand All @@ -13,13 +12,13 @@ public class Parameters {
public Biome biome;
public Random random;
public Chunk chunk;
public ChunkDecorator decorator;
public ChunkDecoratorAPI decorator;
public Object[] customParameters = new Object[0];
public Parameters(Biome biome, Random random, Chunk chunk, ChunkDecorator chunkDecorator, Object[] customParameters){
public Parameters(Biome biome, Random random, Chunk chunk, ChunkDecoratorAPI chunkDecorator, Object[] customParameters){
this(biome, random, chunk, chunkDecorator);
this.customParameters = customParameters;
}
public Parameters(Biome biome, Random random, Chunk chunk, ChunkDecorator chunkDecorator){
public Parameters(Biome biome, Random random, Chunk chunk, ChunkDecoratorAPI chunkDecorator){
this.biome = biome;
this.random = random;
this.chunk = chunk;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package useless.terrainapi.generation.floating.api;

import net.minecraft.core.world.World;
import net.minecraft.core.world.generate.MapGenCaves;
import net.minecraft.core.world.generate.chunk.perlin.ChunkGeneratorPerlin;
import net.minecraft.core.world.generate.chunk.perlin.overworld.SurfaceGeneratorOverworld;
import net.minecraft.core.world.generate.chunk.perlin.paradise.TerrainGeneratorParadise;
import useless.terrainapi.generation.overworld.api.ChunkDecoratorOverworldAPI;

public class ChunkGeneratorFloatingAPI extends ChunkGeneratorPerlin {
public ChunkGeneratorFloatingAPI(World world) {
super(world, new ChunkDecoratorOverworldAPI(world), new TerrainGeneratorParadise(world), new SurfaceGeneratorOverworld(world), new MapGenCaves(false));
}
}
10 changes: 10 additions & 0 deletions src/main/java/useless/terrainapi/generation/hell/HellConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package useless.terrainapi.generation.hell;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import useless.terrainapi.config.OreConfig;

public class HellConfig extends OreConfig {
@SerializedName("Inverse Leaves Probability") @Expose
public int invLeavesProbability = 1234;
}
141 changes: 141 additions & 0 deletions src/main/java/useless/terrainapi/generation/hell/HellFunctions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package useless.terrainapi.generation.hell;

import net.minecraft.core.block.Block;
import net.minecraft.core.world.generate.feature.WorldFeature;
import net.minecraft.core.world.generate.feature.WorldFeatureLabyrinth;
import net.minecraft.core.world.generate.feature.WorldFeatureLake;
import net.minecraft.core.world.generate.feature.WorldFeatureLiquid;
import net.minecraft.core.world.generate.feature.tree.WorldFeatureTree;
import net.minecraft.core.world.generate.feature.tree.WorldFeatureTreeFancy;
import org.jetbrains.annotations.Nullable;
import useless.terrainapi.generation.Parameters;
import useless.terrainapi.generation.hell.api.ChunkDecoratorOverworldHellAPI;

import java.util.Random;

public class HellFunctions {
public static HellConfig hellConfig = ChunkDecoratorOverworldHellAPI.hellConfig;
/**Vanilla labyrinth generation code
* @param parameters Parameters Container
* @return null
*/
@Nullable
public static Void generateLabyrinths(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
for (int i = 0; i < 1; ++i) {
int xPos = x + parameters.random.nextInt(16) + 8;
int zPos = z + parameters.random.nextInt(16) + 8;
int yPos = parameters.decorator.world.getHeightValue(xPos, zPos) - (parameters.random.nextInt(2) + 2);
if (parameters.random.nextInt(10) == 0) {
yPos -= parameters.random.nextInt(10) + 30;
}
if (parameters.random.nextInt(512) != 0) continue;
Random lRand = parameters.chunk.getChunkRandom(75644760L);
new WorldFeatureLabyrinth().generate(parameters.decorator.world, lRand, xPos, yPos, zPos);
}
return null;
}

/**Vanilla random fluid generation code, takes two custom parameters (int)Chances and (int)BlockID
* @param parameters Parameters Container
* @return null
*/
public static Void generateRandomFluid(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
int chances = (int) parameters.customParameters[0];
int fluidId = (int) parameters.customParameters[1];
for (int i = 0; i < chances; ++i) {
int blockX = x + parameters.random.nextInt(16) + 8;
int blockY = parameters.decorator.minY + parameters.random.nextInt(parameters.random.nextInt(parameters.decorator.rangeY - 8) + 8);
int blockZ = z + parameters.random.nextInt(16) + 8;
new WorldFeatureLiquid(fluidId).generate(parameters.decorator.world, parameters.random, blockX, blockY, blockZ);
}
return null;
}

/**Vanilla lava lake generation code
* @param parameters Parameters Container
* @return null
*/
@Nullable
public static Void generateLavaLakeFeature(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
if (parameters.random.nextInt(32) == 0) {
int xf = x + parameters.random.nextInt(16) + 8;
int yf = parameters.decorator.minY + parameters.random.nextInt(parameters.decorator.rangeY);
int zf = z + parameters.random.nextInt(16) + 8;
if (yf < parameters.decorator.minY + parameters.decorator.rangeY / 2 || parameters.random.nextInt(10) == 0) {
new WorldFeatureLake(Block.fluidLavaStill.id).generate(parameters.decorator.world, parameters.random, xf, yf, zf);
}
}
return null;
}
/**Vanilla obsidian lava lake generation code
* @param parameters Parameters Container
* @return null
*/
@Nullable
public static Void generateObsidianLakeFeature(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
if (parameters.random.nextInt(16) == 0) {
int j1 = x + parameters.random.nextInt(16) + 8;
int i5 = parameters.decorator.minY + parameters.random.nextInt(parameters.decorator.rangeY - 16) + 8;
int j8 = z + parameters.random.nextInt(16) + 8;
if (i5 < parameters.decorator.minY + parameters.decorator.rangeY / 2 || parameters.random.nextInt(10) == 0) {
if (parameters.random.nextInt(4) == 0) {
new WorldFeatureLake(Block.obsidian.id).generate(parameters.decorator.world, parameters.random, j1, i5, j8);
} else {
new WorldFeatureLake(Block.fluidLavaStill.id).generate(parameters.decorator.world, parameters.random, j1, i5, j8);
}
}
}
return null;
}

/**Vanilla tree feature generator
* @param parameters Parameters Container
* @return Tree feature as specified by Biome#getRandomWorldGenForTrees
*/
public static WorldFeature getTreeFeature(Parameters parameters){
boolean hasLeaves = parameters.random.nextInt(hellConfig.invLeavesProbability) == 0;
WorldFeature tree = parameters.random.nextInt(10) == 0 ? new WorldFeatureTreeFancy(hasLeaves ? Block.leavesOak.id : 0, Block.logOak.id) : new WorldFeatureTree(hasLeaves ? Block.leavesOak.id : 0, Block.logOak.id, 4);
tree.func_517_a(1.0, 1.0, 1.0);
return tree;
}

/**Vanilla tree density
* @param parameters Parameters Container
* @return treeDensityOverride if applicable, otherwise returns the biome's tree density from OverworldConfig's tree density hashmap
*/
public static Integer getTreeDensity(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
double d = 0.5;
ChunkDecoratorOverworldHellAPI decoratorHell = (ChunkDecoratorOverworldHellAPI) parameters.decorator;
int treeDensity = (int)((decoratorHell.treeDensityNoise.get((double)x * d, (double)z * d) / 8.0 + parameters.random.nextDouble() * 4.0 + 4.0) / 3.0);
if (parameters.random.nextInt(10) == 0) {
++treeDensity;
}
return treeDensity/2;
}

/**Vanilla hell tree generator
* @param parameters Parameters Container, takes two custom parameters getTreeFeature function and getTreeDensity function
* @return null
*/
public static Void generateTrees(Parameters parameters){
int x = parameters.chunk.xPosition * 16;
int z = parameters.chunk.zPosition * 16;
for (int i = 0; i < getTreeDensity(parameters); i++) {
int xf = x + parameters.random.nextInt(16) + 8;
int zf = z + parameters.random.nextInt(16) + 8;
int yf = parameters.decorator.world.getHeightValue(xf, zf);
getTreeFeature(parameters).generate(parameters.decorator.world, parameters.random, xf, yf, zf);
}
return null;
}
}
Loading

0 comments on commit 9ad6e66

Please sign in to comment.