public void setGrid(Grid<T> newGrid) {
    Grid<T> oldGrid = world.getGrid();
    Map<Location, T> occupants = new HashMap<Location, T>();
    for (Location loc : oldGrid.getOccupiedLocations())
        occupants.put(loc, world.remove(loc));
    
    world.setGrid(newGrid);
    for (Location loc : occupants.keySet()) {
        if (newGrid.isValid(loc))
            world.add(loc, occupants.get(loc));
    }
    
    display.setGrid(newGrid);
    repaint();
}