我想在“我的世界”中建立一个世界,然后用代码复制它,所以当世界产生的时候,它就建立了一个空旷的世界,从最底层开始,一个10层高的静水无限延伸,然后在精确的坐标下建造一个结构。大约0,0 (我不介意在结构本身上输入块)。我不太明白我是如何做到这一点的,我想要完全覆盖默认的world gen。这样做的目的是,一旦完成,我就可以把插件jar交给别人,他们可以把它放到插件文件夹中,一旦服务器启动,它就会生成这个世界(我还想在每次加载服务器时重新生成这个世界,而不是当插件重新加载时,因为我经常这样做)。我一直在寻找如何做这件事,但我一直很紧张。
更新
我从我所遵循的教程(watch?v=WsqTwUtubrg)中学到了这么多,但我不明白如何让它覆盖默认的生成。这是我的代码:
主要班:
public ChunkGenerator getDefaultWorldGenerator(String worldname, String id){
return new WorldGen(this);
}WorldGen类:
public class WorldGen extends ChunkGenerator {
Main plugin;
public WorldGen(Main instance){
plugin = instance;
}
public Location getFixedSpawnLocation(World world, Random random){return new Location(world, 0, 0, 0);}
public List<BlockPopulator> getDefaultPopulators(World world) {
return new ArrayList<BlockPopulator>();
}
public byte[][] generatorBlockSections(World world, Random random, int chunkX, int chunkY, BiomeGrid biomeGrid) {
byte[][] result = new byte[256 / 16][];
int x, y, z;
for (x = 0; x < 16; x++){
for (z = 0; z < 16; z++){
for (y = 0; y <= 9; y++){
setBlock(result, x, y, z, (byte) Material.STATIONARY_WATER.getId());
}
}
}
return result;
}
@Override
public short[][] generateExtBlockSections(World world, Random random, int chunkX, int chunkY, BiomeGrid biomes){
short[][] result = new short[256 / 16][];
int x, y, z;
for (x = 0; x < 16; x++){
for (z = 0; z < 16; z++){
for (y = 0; y <= 9; y++){
setBlock(result, x, y, z, (short) Material.STATIONARY_WATER.getId());
}
}
}
return result;
}
private void setBlock(byte[][] result, int x, int y, int z, byte blockId) {
if (result[y >> 4] == null){
result[y >> 4] = new byte[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blockId;
}
private void setBlock(short[][] result, int x, int y, int z, short blockId) {
if (result[y >> 4] == null){
result[y >> 4] = new short[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blockId;
}
}最终的结果是基本的平面世界生成(因为我在服务器属性中设置了它**应该将它设置为“默认”吗?)我还是不明白我该如何建造一座建筑。
发布于 2014-08-23 18:47:25
在bukkit.yml文件中,确保添加以下内容:
worlds:
world:
generator: ExamplePlugin将" world“改为”您的世界“,将"ExamplePlugin”替换为您的插件名称。在http://forums.bukkit.org/threads/the-always-up-to-date-definitive-guide-to-terrain-generation-part-one-prerequisites-and-setup.93982/有一个很好的教程系列。要构建自定义结构,您需要创建一个BlockPopulator的扩展,在该扩展中,您将覆盖populate()方法,使其如下所示:
public void populate(World world, Random rand, Chunk chunk) {
chunk.getBlockAt(0, 64, 0).setType(Material.STONE);
}这将将每个块中的块(0、64、0)设置为石头。若要生成块行,请使用for-循环。若要制作矩形或长方体,请使用嵌套的for-循环.世界一代变得越来越复杂,这就是为什么我建议研究像上面这样的教程。
https://stackoverflow.com/questions/23965733
复制相似问题