This commit is contained in:
Anuken
2021-09-23 19:44:42 -04:00
parent c8ab2bd1ba
commit 29242249bd
2 changed files with 26 additions and 0 deletions

View File

@@ -117,10 +117,30 @@ public class BlockRenderer{
lastCamY = lastCamX = -99; //invalidate camera position so blocks get updated
}
invalidateTile(event.tile);
recordIndex(event.tile);
});
}
public void invalidateTile(Tile tile){
int avgx = (int)(camera.position.x / tilesize);
int avgy = (int)(camera.position.y / tilesize);
int rangex = (int)(camera.width / tilesize / 2) + 3;
int rangey = (int)(camera.height / tilesize / 2) + 3;
if(Math.abs(avgx - tile.x) <= rangex && Math.abs(avgy - tile.y) <= rangey){
lastCamY = lastCamX = -99; //invalidate camera position so blocks get updated
}
}
public void removeFloorIndex(Tile tile){
if(indexFloor(tile)) floorTree.remove(tile);
}
public void addFloorIndex(Tile tile){
if(indexFloor(tile)) floorTree.insert(tile);
}
boolean indexBlock(Tile tile){
var block = tile.block();
return tile.isCenter() && block != Blocks.air && block.cacheLayer == CacheLayer.normal;