Game Development Reference
In-Depth Information
8. In the CubeWorld class, create this changeTerrain method that takes a
Vector3f parameter called coords and a CubeCell parameter called
blockToPlace as the input. The Coords parameters represent the location of
a CubeCell instance. The changeTerrain method returns a CubeCell in-
stance.
9. The first thing we will do is define a CubeCell field called changedBlock
where we store the incoming blockToPlace .
10. Then, do a check to make sure the supplied coordinate is within the bounds of the
terrainBlock array and then check whether changedBlock is null. If it is,
pick up the CubeCell instance from this location and populate changedB-
lock with the CubeCell instance. Then, set the location's CubeCell to null
as follows:
if(changedBlock == null){
changedBlock = terrainBlock[x][y][z];
terrainBlock[x][y][z] = null;
}
11. If instead the CubeCell instance at this location is null (we already know that
changedBlock is not null), set the CubeCell instance over here to
changedBlock and changedBlock to null. Also, call requestRefresh
on the CubeCell instance to force it to update the mesh, as follows:
else if(terrainBlock[x][y][z] == null){
terrainBlock[x][y][z] = changedBlock;
terrainBlock[x][y][z].requestRefresh();
changedBlock = null;
}
12. Finally, if there has been a change made, call generateGeometry and return
changedBlock to the calling method.
Search WWH ::




Custom Search