public Materials getMaterials(boolean withRight, boolean withTop) { Materials materials = new Materials(); entities .values() .stream() .forEach( (entity) -> { materials.put(entity.getMaterials()); }); if (withRight) { for (int i = 0; i < Constants.FLOORS_LIMIT; i++) { Wall wall = map.getTile(this, 1, 0).getVerticalWall(i); Wall fence = map.getTile(this, 1, 0).getVerticalFence(i); if (wall != null) { materials.put(wall.getMaterials()); } if (fence != null) { materials.put(fence.getMaterials()); } } } if (withTop) { for (int i = 0; i < Constants.FLOORS_LIMIT; i++) { Wall wall = map.getTile(this, 0, 1).getHorizontalWall(i); Wall fence = map.getTile(this, 0, 1).getHorizontalFence(i); if (wall != null) { materials.put(wall.getMaterials()); } if (fence != null) { materials.put(fence.getMaterials()); } } } return materials; }