Implemented custom chunk generators and block populators
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package org.bukkit.craftbukkit.generator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.server.Chunk;
|
||||
import net.minecraft.server.IChunkProvider;
|
||||
import net.minecraft.server.IProgressUpdate;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldServer;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public class CustomChunkGenerator implements InternalChunkGenerator {
|
||||
private final ChunkGenerator generator;
|
||||
private final WorldServer world;
|
||||
private final long seed;
|
||||
private final Random random;
|
||||
|
||||
public CustomChunkGenerator(World world, long seed, ChunkGenerator generator) {
|
||||
this.world = (WorldServer)world;
|
||||
this.seed = seed;
|
||||
this.generator = generator;
|
||||
|
||||
this.random = new Random(seed);
|
||||
}
|
||||
|
||||
public boolean isChunkLoaded(int x, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Chunk getOrCreateChunk(int x, int z) {
|
||||
random.setSeed((long)x * 341873128712L + (long)z * 132897987541L);
|
||||
byte[] types = generator.generate(world.getWorld(), random, x, z);
|
||||
|
||||
Chunk chunk = new Chunk(world, types, x, z);
|
||||
|
||||
chunk.b();
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void getChunkAt(IChunkProvider icp, int i, int i1) {
|
||||
// Nothing!
|
||||
}
|
||||
|
||||
public boolean saveChunks(boolean bln, IProgressUpdate ipu) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean unloadChunks() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean b() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] generate(org.bukkit.World world, Random random, int x, int z) {
|
||||
return generator.generate(world, random, x, z);
|
||||
}
|
||||
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return getOrCreateChunk(x, z);
|
||||
}
|
||||
|
||||
public boolean canSpawn(org.bukkit.World world, int x, int z) {
|
||||
return generator.canSpawn(world, x, z);
|
||||
}
|
||||
|
||||
public List<BlockPopulator> getDefaultPopulators(org.bukkit.World world) {
|
||||
return generator.getDefaultPopulators(world);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
package org.bukkit.craftbukkit.generator;
|
||||
|
||||
import net.minecraft.server.IChunkProvider;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public interface InternalChunkGenerator extends ChunkGenerator, IChunkProvider {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.bukkit.craftbukkit.generator;
|
||||
|
||||
import net.minecraft.server.World;
|
||||
|
||||
/**
|
||||
* This class is useless. Just fyi.
|
||||
*/
|
||||
public class NetherChunkGenerator extends NormalChunkGenerator {
|
||||
public NetherChunkGenerator(World world, long seed) {
|
||||
super(world, seed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.bukkit.craftbukkit.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import net.minecraft.server.ChunkProviderGenerate;
|
||||
import net.minecraft.server.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public class NormalChunkGenerator extends ChunkProviderGenerate implements InternalChunkGenerator {
|
||||
public NormalChunkGenerator(World world, long seed) {
|
||||
super(world, seed);
|
||||
}
|
||||
|
||||
public byte[] generate(org.bukkit.World world, Random random, int x, int z) {
|
||||
throw new UnsupportedOperationException("Not supported.");
|
||||
}
|
||||
|
||||
public boolean canSpawn(org.bukkit.World world, int x, int z) {
|
||||
return ((CraftWorld)world).getHandle().worldProvider.a(x, z);
|
||||
}
|
||||
|
||||
public List<BlockPopulator> getDefaultPopulators(org.bukkit.World world) {
|
||||
return new ArrayList<BlockPopulator>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.bukkit.craftbukkit.generator;
|
||||
|
||||
import net.minecraft.server.World;
|
||||
|
||||
/**
|
||||
* This class is useless. Just fyi.
|
||||
*/
|
||||
public class SkyLandsChunkGenerator extends NormalChunkGenerator {
|
||||
public SkyLandsChunkGenerator(World world, long seed) {
|
||||
super(world, seed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user