您可以通過使用使土地32x32的情節:
int y = 64;
for(int x = 0; x < 32; x++){
for(int z = 0; z < 32; z++){
Location location = new Location(world, x, y, z);
location.getBlock().setType(Material.GRASS);
}
}
所以,你可以通過做一個4x4網格:
int y = 64; //the position on the y axis that this plot will be created
for(int xTimes = 0; xTimes < 4; xTimes++){//xTimes < 4 makes it so this will create 4 plots on the x axis
for(int zTimes = 0; zTimes < 4; zTimes++){//zTimes < 4 makes it so this will create 4 plots on the z axis
//create the plot of land
for(int x = 0; x < 32; x++){//x < 32 makes it so this will create a plot 32 long
for(int z = 0; z < 32; z++){//z < 32 makes it so this will create a plot 32 wide
//get the x and z locations for the plot
//multiplying the below values by 64 makes it so there will be a 32x32 gap between each plot
//(below multiplication value - plot size = gap), so the gap will be 64 - 32 = 32 blocks
int xPos = x + (xTimes * 64);
int zPos = z + (zTimes * 64);
//get the location for the block, and then set the block to grass (or set it to whatever you want)
Location location = new Location(world, xPos, y, zPos);
location.getBlock().setType(Material.GRASS);
}
}
}
}
如果你想使積有幾塊更深,你可以只添加一個for
環路下面
,並使其循環ŧ通過y
值你想要的情節。例如,如果你想要的地塊爲4塊高,從y = 60
去y = 64
,你可以使用:
for(int y = 60; y <= 64; y++)
如果你想,當你需要,你可以用它來創建地塊:
public void generatePlot(int xTime, int zTime){
for(int x = 0; x < 32; x++){
for(int z = 0; z < 32; z++){
int xPos = x + (xTime * 64);
int zPos = z + (zTime * 64);
Location location = new Location(world, xPos, y, zPos);
location.getBlock().setType(Material.GRASS);
}
}
}
然後,您可以保存繪圖創建次數的記錄,並相應地生成新繪圖。例如,如果您想要在x軸上有10個圖,則可以使用:
int plotsCreated = 100; //load this from a configuration file, or something
int xTime = plotsCreated % 10;
int yTime = Math.floor(plotsCreated/10);
generatePlot(xTime, yTime);
plotsCreated++;
//save the new plotsCreated variable somewhere
您的方法可能非常低效。您應該使用[世界發電機](https://bukkit.org/threads/how-to-create-custom-world-generators.79066/)。 – 2015-04-06 10:15:29
我在我的插件中有一個世界發電機我只是不想要大量未使用的地塊 – 2015-04-06 16:42:42