Hey,
I did have a look on it and I changed it on how I would do it.
Some general things: Your Block Array is public, why ?
Do you really need to extend the Terrain Class ? I mean, is there gonna be anything else that is extending the Terrain class ? If yes, it´s completely fine, else you can just take the variables and the methods of it to the Layer class.
So, here´s your snippet of the code:
[spoiler]
private Block[][] switchBlock(Block[][] map){
int currentX, currentY;
for(currentX = 0; currentX < getWidth(); currentX++){
for(currentY = 0; currentY < getHeight(); currentY++){
if(map[currentX][currentY].getType() == BlockType.WATER){
int finalX, finalY;
int tempX = -1;
int tempY = -1;
if(currentX == 0) tempX = 0;
if(currentY == 0) tempY = 0;
for(finalX = tempX; finalX <= 1; finalX++){
for(finalY = tempY; finalY <= 1; finalY++){
if(map[finalX][finalY].getType() != BlockType.WATER){
if(map[finalX][finalY].getType() != BlockType.GRASS_1){
map[finalX][finalY] = blockList.get(1);
}
}
}
}
}
}
}
return map;
}
[/spoiler]
And here´s mine:
Please be aware that I did not any check of being in bounds so 4 Blocks won´t be checked. This code was not written in a editor so there might be some errors in spelling, also I don´t know your Block class so I did just call the methods as I thought the might be named.
Should work for you
[spoiler]
//Can be a void, no need to return the map
private void switchBlock(Block[][] map){
//No need to predefine the variables
//Set currX and currY to 1 because I would have to do a check for being inside the layer else. This will change all block except the upper left, upper right, lower left and lower right ones.
for(int currentX = 1; currentX < getWidth() - 1; currentX++){
for(int currentY = 1; currentY < getHeight() - 1; currentY++){
Block block = map[currentX][currentY];
if(block.getType() == BlockType.WATER){
if(map[currentX + 1][currentY].getType() != BlockType.WATER)map[currentX + 1][currentY].setType(BlockType.GRASS);
if(map[currentX - 1][currentY].getType() != BlockType.WATER)map[currentX - 1][currentY].setType(BlockType.GRASS);
if(map[currentX][currentY + 1].getType() != BlockType.WATER)map[currentX][currentY + 1].setType(BlockType.GRASS);
if(map[currentX][currentY - 1].getType() != BlockType.WATER)map[currentX][currentY - 1].setType(BlockType.GRASS);
}
}
}
}
[/spoiler]
EDIT: Why do you set the block to blockList(1) ? Just create a enum with all the BlockTypes and render the block according to the type he has.
If you need some help with your project, I´m happy to help you, just send me a message and we can get in touch.
Best regards,
Major_Sauce