Java Reference
In-Depth Information
Figure 3—Trapping a player in blocks
{-1, 0, 0},
{-1, 1, 0},
{0, 0, 1},
{0, 1, 1},
{0, 0, -1},
{0, 1, -1},
};
We'll use a simple for loop to go through this list of offsets. The first element
in the list is indexed at 0, and we'll go up to (but not including) the length of
the list. By using the length of the offsets list instead of sticking in a fixed
number like 10, we can more easily add extra blocks to the list if we ever
want to (remember, we're adding the playerX , playerY , and playerZ offsets from
the preceding code):
Stuck/src/stuck/Stuck.java
for ( int i = 0; i < offsets.length; i++) {
int x = offsets[i][0];
int y = offsets[i][1];
int z = offsets[i][2];
setBlockAt( new Location(x+playerX, y+playerY, z+playerZ),
BlockType.Stone);
}
 
 
 
Search WWH ::




Custom Search