Merge pull request #4048 from babbaj/elytra
don't send the whole chunk for small changes
This commit is contained in:
@@ -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;
|
||||
@@ -67,6 +69,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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user