waypoints rough start
This commit is contained in:
parent
1251b515fa
commit
7996cfe0a5
@ -23,6 +23,9 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.BitSet;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
@ -50,8 +53,14 @@ public final class CachedWorld implements IBlockTypeAccess {
|
||||
|
||||
private final LinkedBlockingQueue<Chunk> toPack = new LinkedBlockingQueue<>();
|
||||
|
||||
public CachedWorld(String directory) {
|
||||
this.directory = directory;
|
||||
CachedWorld(Path directory) {
|
||||
if (!Files.exists(directory)) {
|
||||
try {
|
||||
Files.createDirectories(directory);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
this.directory = directory.toString();
|
||||
System.out.println("Cached world directory: " + directory);
|
||||
// Insert an invalid region element
|
||||
cachedRegions.put(0, null);
|
||||
new PackerThread().start();
|
||||
|
36
src/main/java/baritone/chunk/Waypoints.java
Normal file
36
src/main/java/baritone/chunk/Waypoints.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Waypoints {
|
||||
private final Path directory;
|
||||
|
||||
Waypoints(Path directory) {
|
||||
this.directory = directory;
|
||||
if (!Files.exists(directory)) {
|
||||
try {
|
||||
Files.createDirectories(directory);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
System.out.println("Would save waypoints to " + directory);
|
||||
}
|
||||
}
|
42
src/main/java/baritone/chunk/WorldData.java
Normal file
42
src/main/java/baritone/chunk/WorldData.java
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.chunk;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class WorldData {
|
||||
public final CachedWorld cache;
|
||||
public final Waypoints waypoints;
|
||||
//public final MapData map;
|
||||
public final Path directory;
|
||||
|
||||
WorldData(Path directory) {
|
||||
this.directory = directory;
|
||||
this.cache = new CachedWorld(directory.resolve("cache"));
|
||||
this.waypoints = new Waypoints(directory.resolve("waypoints"));
|
||||
}
|
||||
|
||||
void onClose() {
|
||||
new Thread() {
|
||||
public void run() {
|
||||
System.out.println("Started saving the world in a new thread");
|
||||
cache.save();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
@ -17,9 +17,10 @@
|
||||
|
||||
package baritone.chunk;
|
||||
|
||||
import baritone.utils.Helper;
|
||||
import baritone.Baritone;
|
||||
import baritone.launch.mixins.accessor.IAnvilChunkLoader;
|
||||
import baritone.launch.mixins.accessor.IChunkProviderServer;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
@ -36,53 +37,60 @@ import java.util.function.Consumer;
|
||||
* @author Brady
|
||||
* @since 8/4/2018 11:06 AM
|
||||
*/
|
||||
public enum CachedWorldProvider implements Helper {
|
||||
public enum WorldProvider implements Helper {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private final Map<String, CachedWorld> singlePlayerWorldCache = new HashMap<>();
|
||||
private final Map<Path, WorldData> worldCache = new HashMap<>();
|
||||
|
||||
private CachedWorld currentWorld;
|
||||
private WorldData currentWorld;
|
||||
|
||||
public final CachedWorld getCurrentWorld() {
|
||||
public final WorldData getCurrentWorld() {
|
||||
return this.currentWorld;
|
||||
}
|
||||
|
||||
public final void initWorld(WorldClient world) {
|
||||
IntegratedServer integratedServer;
|
||||
if ((integratedServer = mc.getIntegratedServer()) != null) {
|
||||
|
||||
WorldServer localServerWorld = integratedServer.getWorld(world.provider.getDimensionType().getId());
|
||||
int dimensionID = world.provider.getDimensionType().getId();
|
||||
File directory;
|
||||
IntegratedServer integratedServer = mc.getIntegratedServer();
|
||||
if (integratedServer != null) {
|
||||
WorldServer localServerWorld = integratedServer.getWorld(dimensionID);
|
||||
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
|
||||
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
|
||||
directory = loader.getChunkSaveLocation();
|
||||
|
||||
Path dir = new File(new File(loader.getChunkSaveLocation(), "region"), "cache").toPath();
|
||||
if (!Files.exists(dir)) {
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
} catch (IOException ignored) {}
|
||||
if (!directory.getParentFile().getName().equals("saves")) {
|
||||
// subdirectory of the main save directory for this world
|
||||
directory = directory.getParentFile();
|
||||
}
|
||||
|
||||
this.currentWorld = this.singlePlayerWorldCache.computeIfAbsent(dir.toString(), CachedWorld::new);
|
||||
directory = new File(directory, "baritone");
|
||||
|
||||
} else {
|
||||
//remote
|
||||
directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP);
|
||||
}
|
||||
// TODO: Store server worlds
|
||||
directory = new File(directory, "DIM" + dimensionID);
|
||||
Path dir = directory.toPath();
|
||||
if (!Files.exists(dir)) {
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
System.out.println("Baritone world data dir: " + dir);
|
||||
this.currentWorld = this.worldCache.computeIfAbsent(dir, WorldData::new);
|
||||
}
|
||||
|
||||
public final void closeWorld() {
|
||||
CachedWorld world = this.currentWorld;
|
||||
WorldData world = this.currentWorld;
|
||||
this.currentWorld = null;
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
new Thread() {
|
||||
public void run() {
|
||||
System.out.println("Started saving the world in a new thread");
|
||||
world.save();
|
||||
}
|
||||
}.start();
|
||||
world.onClose();
|
||||
}
|
||||
|
||||
public final void ifWorldLoaded(Consumer<CachedWorld> currentWorldConsumer) {
|
||||
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
|
||||
if (this.currentWorld != null)
|
||||
currentWorldConsumer.accept(this.currentWorld);
|
||||
}
|
@ -35,7 +35,7 @@
|
||||
package baritone.event;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.chunk.CachedWorldProvider;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.event.events.*;
|
||||
import baritone.event.events.type.EventState;
|
||||
import baritone.event.listener.IGameEventListener;
|
||||
@ -113,9 +113,9 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
|
||||
if (Baritone.settings().chunkCaching.get()) {
|
||||
if (isPostPopulate || isPreUnload) {
|
||||
CachedWorldProvider.INSTANCE.ifWorldLoaded(world -> {
|
||||
WorldProvider.INSTANCE.ifWorldLoaded(world -> {
|
||||
Chunk chunk = mc.world.getChunk(event.getX(), event.getZ());
|
||||
world.queueForPacking(chunk);
|
||||
world.cache.queueForPacking(chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -126,7 +126,7 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
@Override
|
||||
public final void onRenderPass(RenderEvent event) {
|
||||
/*
|
||||
CachedWorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> {
|
||||
WorldProvider.INSTANCE.ifWorldLoaded(world -> world.forEachRegion(region -> region.forEachChunk(chunk -> {
|
||||
drawChunkLine(region.getX() * 512 + chunk.getX() * 16, region.getZ() * 512 + chunk.getZ() * 16, event.getPartialTicks());
|
||||
})));
|
||||
*/
|
||||
@ -137,7 +137,7 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
||||
@Override
|
||||
public final void onWorldEvent(WorldEvent event) {
|
||||
if (Baritone.settings().chunkCaching.get()) {
|
||||
CachedWorldProvider cache = CachedWorldProvider.INSTANCE;
|
||||
WorldProvider cache = WorldProvider.INSTANCE;
|
||||
|
||||
switch (event.getState()) {
|
||||
case PRE:
|
||||
|
@ -18,7 +18,7 @@
|
||||
package baritone.pathing.calc;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.chunk.CachedWorldProvider;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||
import baritone.pathing.calc.openset.IOpenSet;
|
||||
import baritone.pathing.goals.Goal;
|
||||
@ -113,8 +113,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
|
||||
boolean isPositionCached = false;
|
||||
if (cache) {
|
||||
if (CachedWorldProvider.INSTANCE.getCurrentWorld() != null) {
|
||||
if (CachedWorldProvider.INSTANCE.getCurrentWorld().getBlock(dest) != null) {
|
||||
if (WorldProvider.INSTANCE.getCurrentWorld() != null) {
|
||||
if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) {
|
||||
isPositionCached = true;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.chunk.CachedWorld;
|
||||
import baritone.chunk.CachedWorldProvider;
|
||||
import baritone.chunk.WorldProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
@ -43,7 +43,7 @@ public class BlockStateInterface implements Helper {
|
||||
}
|
||||
}
|
||||
if (Baritone.settings().chunkCaching.get()) {
|
||||
CachedWorld world = CachedWorldProvider.INSTANCE.getCurrentWorld();
|
||||
CachedWorld world = WorldProvider.INSTANCE.getCurrentWorld().cache;
|
||||
if (world != null) {
|
||||
IBlockState type = world.getBlock(pos);
|
||||
if (type != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user