mirror of https://github.com/cabaletta/baritone
don't send the whole chunk for small changes
This commit is contained in:
parent
96a64b454e
commit
dc53a95bef
|
@ -31,16 +31,16 @@ import java.util.Set;
|
|||
*/
|
||||
public final class BlockChangeEvent {
|
||||
|
||||
private final Set<ChunkPos> affectedChunks;
|
||||
private final ChunkPos chunk;
|
||||
private final List<Pair<BlockPos, IBlockState>> blocks;
|
||||
|
||||
public BlockChangeEvent(ChunkPos pos, List<Pair<BlockPos, IBlockState>> blocks) {
|
||||
this.affectedChunks = Collections.singleton(pos);
|
||||
this.chunk = pos;
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public Set<ChunkPos> getAffectedChunks() {
|
||||
return this.affectedChunks;
|
||||
public ChunkPos getChunkPos() {
|
||||
return this.chunk;
|
||||
}
|
||||
|
||||
public List<Pair<BlockPos, IBlockState>> getBlocks() {
|
||||
|
|
|
@ -394,9 +394,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
|||
|
||||
@Override
|
||||
public void onBlockChange(BlockChangeEvent event) {
|
||||
event.getAffectedChunks().stream()
|
||||
.map(pos -> ctx.world().getChunk(pos.x, pos.z))
|
||||
.forEach(this.context::queueForPacking);
|
||||
this.context.queueBlockUpdate(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package baritone.behavior.elytra;
|
||||
|
||||
import baritone.api.event.events.BlockChangeEvent;
|
||||
import baritone.utils.accessor.IBitArray;
|
||||
import baritone.utils.accessor.IBlockStateContainer;
|
||||
import dev.babbaj.pathfinder.NetherPathfinder;
|
||||
|
@ -26,6 +27,7 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BitArray;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.chunk.BlockStateContainer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
@ -65,6 +67,20 @@ public final class NetherPathfinderContext {
|
|||
});
|
||||
}
|
||||
|
||||
public void queueBlockUpdate(BlockChangeEvent event) {
|
||||
this.executor.execute(() -> {
|
||||
ChunkPos chunkPos = event.getChunkPos();
|
||||
long ptr = NetherPathfinder.getChunkPointer(this.context, chunkPos.x, chunkPos.z);
|
||||
if (ptr == 0) return; // this shouldn't ever happen
|
||||
event.getBlocks().forEach(pair -> {
|
||||
BlockPos pos = pair.first();
|
||||
if (pos.getY() >= 128) return;
|
||||
boolean isSolid = pair.second() != AIR_BLOCK_STATE;
|
||||
Octree.setBlock(ptr, pos.getX() & 15, pos.getY(), pos.getZ() & 15, isSolid);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<PathSegment> pathFindAsync(final BlockPos src, final BlockPos dst) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final PathSegment segment = NetherPathfinder.pathFind(
|
||||
|
|
|
@ -28,6 +28,7 @@ import baritone.cache.CachedChunk;
|
|||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
|
@ -117,9 +118,8 @@ public final class GameEventHandler implements IEventBus, Helper {
|
|||
if (keepingTrackOf) {
|
||||
baritone.getWorldProvider().ifWorldLoaded(worldData -> {
|
||||
final World world = baritone.getPlayerContext().world();
|
||||
event.getAffectedChunks().stream()
|
||||
.map(pos -> world.getChunk(pos.x, pos.z))
|
||||
.forEach(worldData.getCachedWorld()::queueForPacking);
|
||||
ChunkPos pos = event.getChunkPos();
|
||||
worldData.getCachedWorld().queueForPacking(world.getChunk(pos.x, pos.z));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue