Java Bukkit生成世界
我正在尝试生成一个我当前要生成为空的世界。这正是我想要的,但现在我想在每个玩家加入时为他们生成一个正方形或地。我想让它看起来像一个网格。这些方块无法连接。我可以用对角线的方式做,但我不知道如何把它做成网格Java Bukkit生成世界,java,minecraft,bukkit,Java,Minecraft,Bukkit,我正在尝试生成一个我当前要生成为空的世界。这正是我想要的,但现在我想在每个玩家加入时为他们生成一个正方形或地。我想让它看起来像一个网格。这些方块无法连接。我可以用对角线的方式做,但我不知道如何把它做成网格 for(int x = 0; x < 32; x++) { for(int z = 0; z < 32; z++) { Location l = new Location(getClashWorld(), x, 64, z); getCla
for(int x = 0; x < 32; x++) {
for(int z = 0; z < 32; z++) {
Location l = new Location(getClashWorld(), x, 64, z);
getClashWorld().getBlockAt(l).setType(Material.GRASS);
}
}
for(int x=0;x<32;x++){
对于(intz=0;z<32;z++){
位置l=新位置(getClashWorld(),x,64,z);
getClashWorld().getBlockAt(l).setType(Material.GRASS);
}
}
这就是我如何在世界上创建一块32x32的土地,我可以改变x和z,以及x<和z<来沿对角线移动它。我该如何将其制作成网格 试试这个:
final int w = 32;
final int h = 32;
int offset = 0;
for(int x = 0; x < w; x ++){
for(int y = 0; y < h; y ++){
if(((x + offset) & 1) == 0){
//generate block A
}else{
//generate block B
}
if(offset == 0)
offset = 1;
else
offset = 0;
}
}
final int w=32;
最终int h=32;
整数偏移=0;
对于(int x=0;x
这将生成一个网格。它检查您可以使用以下方法绘制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);
}
}
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);
}
}
}
}
并使其遍历希望绘图的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);
}
}
}
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
这会允许我只在需要时创建绘图,还是会同时生成所有绘图once@WilliamRandall我刚刚更新了我的答案,加入了如何在需要时创建新的绘图。好了,现在使用generate plot方法,有没有办法让它宽32个绘图,长无限?因为我不能限制情节的数量。你明白我说的吗?@WilliamRandall Yea,在上一个代码示例中,使用32而不是10,它将是32宽无限长你的方法可能非常低效。你应该改用。我的插件中有一个世界生成器,我只是不想要太多未使用的绘图
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