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
|
2018-09-17 22:11:40 +00:00
|
|
|
* 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
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-22 22:35:32 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +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;
|
2018-09-24 23:45:41 +00:00
|
|
|
import baritone.api.cache.ICachedWorld;
|
2018-12-03 22:49:16 +00:00
|
|
|
import baritone.api.cache.IContainerMemory;
|
2018-09-24 19:42:22 +00:00
|
|
|
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
|
|
|
|
*/
|
2018-09-24 19:42:22 +00:00
|
|
|
public class WorldData implements IWorldData {
|
|
|
|
|
2018-09-24 23:55:57 +00:00
|
|
|
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;
|
2018-11-10 03:24:02 +00:00
|
|
|
public final int dimension;
|
2018-08-22 22:35:32 +00:00
|
|
|
|
2018-11-10 03:24:02 +00:00
|
|
|
WorldData(Path directory, int dimension) {
|
2018-08-22 22:35:32 +00:00
|
|
|
this.directory = directory;
|
2018-11-10 03:24:02 +00:00
|
|
|
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"));
|
2018-11-10 03:24:02 +00:00
|
|
|
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
|
|
|
}
|
2018-09-24 19:42:22 +00:00
|
|
|
|
2018-09-24 23:45:41 +00:00
|
|
|
@Override
|
|
|
|
public ICachedWorld getCachedWorld() {
|
|
|
|
return this.cache;
|
|
|
|
}
|
|
|
|
|
2018-09-24 19:42:22 +00:00
|
|
|
@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
|
|
|
}
|