baritone/src/main/java/baritone/cache/WorldData.java

82 lines
2.6 KiB
Java
Raw Normal View History

2018-08-22 22:35:32 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-22 22:35:32 +00:00
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2018-08-22 22:35:32 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-22 22:35:32 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-09-11 17:28:03 +00:00
package baritone.cache;
2018-08-22 22:35:32 +00:00
2018-09-16 21:14:50 +00:00
import baritone.Baritone;
import baritone.api.cache.ICachedWorld;
2018-12-03 22:49:16 +00:00
import baritone.api.cache.IContainerMemory;
import baritone.api.cache.IWaypointCollection;
import baritone.api.cache.IWorldData;
2018-09-16 21:14:50 +00:00
2018-12-04 01:20:56 +00:00
import java.io.IOException;
2018-08-22 22:35:32 +00:00
import java.nio.file.Path;
2018-08-22 23:56:05 +00:00
/**
* Data about a world, from baritone's point of view. Includes cached chunks, waypoints, and map data.
*
* @author leijurv
*/
public class WorldData implements IWorldData {
public final CachedWorld cache;
2018-12-04 01:58:37 +00:00
private final WaypointCollection waypoints;
2018-12-03 22:49:16 +00:00
private final ContainerMemory containerMemory;
2018-08-22 22:35:32 +00:00
//public final MapData map;
public final Path directory;
public final int dimension;
2018-08-22 22:35:32 +00:00
WorldData(Path directory, int dimension) {
2018-08-22 22:35:32 +00:00
this.directory = directory;
this.cache = new CachedWorld(directory.resolve("cache"), dimension);
2018-12-04 01:58:37 +00:00
this.waypoints = new WaypointCollection(directory.resolve("waypoints"));
2018-12-03 22:49:16 +00:00
this.containerMemory = new ContainerMemory(directory.resolve("containers"));
this.dimension = dimension;
2018-08-22 22:35:32 +00:00
}
2018-10-09 04:51:19 +00:00
public void onClose() {
2018-11-06 04:01:46 +00:00
Baritone.getExecutor().execute(() -> {
2018-09-16 21:14:50 +00:00
System.out.println("Started saving the world in a new thread");
cache.save();
});
2018-12-04 01:20:56 +00:00
Baritone.getExecutor().execute(() -> {
System.out.println("Started saving saved containers in a new thread");
try {
containerMemory.save();
} catch (IOException e) {
e.printStackTrace();
System.out.println("Failed to save saved containers");
}
});
2018-08-22 22:35:32 +00:00
}
@Override
public ICachedWorld getCachedWorld() {
return this.cache;
}
@Override
public IWaypointCollection getWaypoints() {
return this.waypoints;
}
2018-12-03 22:49:16 +00:00
@Override
public IContainerMemory getContainerMemory() {
return this.containerMemory;
}
2018-08-22 22:35:32 +00:00
}