tcr/java/src/game/worldgen/GeneratorDebug.java
2025-05-04 20:27:55 +02:00

59 lines
1.5 KiB
Java
Executable file

package game.worldgen;
import java.util.List;
import game.block.Block;
import game.collect.Lists;
import game.init.BlockRegistry;
import game.util.ExtMath;
import game.world.State;
import game.world.WorldServer;
public class GeneratorDebug implements ChunkGenerator
{
private static final List<State> STATES = Lists.<State>newArrayList();
private static final int XSTRETCH;
private static final int ZSTRETCH;
static {
for(Block block : BlockRegistry.REGISTRY) {
STATES.addAll(block.getValidStates());
}
XSTRETCH = ExtMath.ceilf(ExtMath.sqrtf((float)STATES.size()));
ZSTRETCH = ExtMath.ceilf((float)STATES.size() / (float)XSTRETCH);
}
public static State getState(int x, int z) {
State state = null;
if(x > 0 && z > 0 && x % 2 != 0 && z % 2 != 0) {
x = x / 2;
z = z / 2;
if(x <= XSTRETCH && z <= ZSTRETCH) {
int idx = ExtMath.absi(x * XSTRETCH + z);
if(idx < STATES.size()) {
state = STATES.get(idx);
}
}
}
return state;
}
public int getMaximumHeight() {
return 72;
}
public void generateChunk(WorldServer world, int x, int z, ChunkPrimer primer)
{
for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) {
int sx = x * 16 + bx;
int sz = z * 16 + bz;
// primer.set(bx, 60, bz, Blocks.glass.getDefaultState());
State state = getState(sx, sz);
if(state != null) {
primer.set(bx, 1, bz, state);
}
}
}
}
}