13
0
geforkt von Mirrors/Paper

Implemented custom chunk generators and block populators

By: Dinnerbone <dinnerbone@dinnerbone.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2011-06-06 14:52:02 +01:00
Ursprung f9895d3ca5
Commit 6777cdd241
7 geänderte Dateien mit 165 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -1,10 +1,12 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import org.bukkit.generator.ChunkGenerator;
import com.avaje.ebean.config.DataSourceConfig; import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.SQLitePlatform; import com.avaje.ebean.config.dbplatform.SQLitePlatform;
import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation; import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
import net.minecraft.server.IWorldAccess; import net.minecraft.server.IWorldAccess;
import org.bukkit.World.Environment;
import org.bukkit.command.*; import org.bukkit.command.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
@ -54,6 +56,7 @@ import org.bukkit.craftbukkit.command.ServerCommandListener;
import org.bukkit.scheduler.BukkitWorker; import org.bukkit.scheduler.BukkitWorker;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
public final class CraftServer implements Server { public final class CraftServer implements Server {
@ -349,6 +352,14 @@ public final class CraftServer implements Server {
} }
public World createWorld(String name, World.Environment environment, long seed) { public World createWorld(String name, World.Environment environment, long seed) {
return createWorld(name, environment, seed, null);
}
public World createWorld(String name, Environment environment, ChunkGenerator generator) {
return createWorld(name, environment, (new Random()).nextLong(), generator);
}
public World createWorld(String name, Environment environment, long seed, ChunkGenerator generator) {
File folder = new File(name); File folder = new File(name);
World world = getWorld(name); World world = getWorld(name);
@ -367,7 +378,7 @@ public final class CraftServer implements Server {
} }
int dimension = 200 + console.worlds.size(); int dimension = 200 + console.worlds.size();
WorldServer internal = new WorldServer(console, new ServerNBTManager(new File("."), name, true), name, dimension, seed, environment); WorldServer internal = new WorldServer(console, new ServerNBTManager(new File("."), name, true), name, dimension, seed, environment, generator);
internal.z = console.worlds.get(0).z; internal.z = console.worlds.get(0).z;
internal.tracker = new EntityTracker(console, dimension); internal.tracker = new EntityTracker(console, dimension);
@ -376,6 +387,12 @@ public final class CraftServer implements Server {
internal.setSpawnFlags(true, true); internal.setSpawnFlags(true, true);
console.worlds.add(internal); console.worlds.add(internal);
if (generator != null) {
internal.getWorld().getPopulators().addAll(generator.getDefaultPopulators(internal.getWorld()));
}
pluginManager.callEvent(new WorldInitEvent(internal.getWorld()));
short short1 = 196; short short1 = 196;
long i = System.currentTimeMillis(); long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) { for (int j = -short1; j <= short1; j += 16) {

Datei anzeigen

@ -20,9 +20,11 @@ import org.bukkit.Chunk;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.TreeType; import org.bukkit.TreeType;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
public class CraftWorld implements World { public class CraftWorld implements World {
private final WorldServer world; private final WorldServer world;
@ -30,13 +32,16 @@ public class CraftWorld implements World {
private final CraftServer server; private final CraftServer server;
private final ChunkProviderServer provider; private final ChunkProviderServer provider;
private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>(); private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
private final ChunkGenerator generator;
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
private static final Random rand = new Random(); private static final Random rand = new Random();
public CraftWorld(WorldServer world) { public CraftWorld(WorldServer world, ChunkGenerator gen) {
this.world = world; this.world = world;
this.server = world.getServer(); this.server = world.getServer();
this.provider = world.chunkProviderServer; this.provider = world.chunkProviderServer;
this.generator = gen;
environment = Environment.getEnvironment(world.worldProvider.dimension); environment = Environment.getEnvironment(world.worldProvider.dimension);
@ -463,6 +468,14 @@ public class CraftWorld implements World {
return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4); return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
} }
public ChunkGenerator getGenerator() {
return generator;
}
public List<BlockPopulator> getPopulators() {
return populators;
}
private final class ChunkCoordinate { private final class ChunkCoordinate {
public final int x; public final int x;
public final int z; public final int z;

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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 {
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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>();
}
}

Datei anzeigen

@ -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);
}
}