我试图创建一个我现在生成的世界来清空。这就是我想要的,但现在我想为每个玩家加入时产生一个正方形或土地。我想让它看起来像一个网格。方块不会连接。我可以用对角线方式做到这一点,但我不知道如何将它变成网格。
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);
}
}
这就是我如何在世界上创建一个32x32的土地,我可以改变x和z以及x&lt;和z&lt;对角移动它。我怎么把它变成网格?
答案 0 :(得分:1)
您可以使用以下方式制作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
循环
for(int z = 0; z < 32; z++)
让它迭代你希望情节所在的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
答案 1 :(得分:0)
试试这个:
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;
}
}
那应该生成一个网格。它会检查