BlockStateOctreeInterface

This commit is contained in:
Brady
2023-07-13 14:28:51 -05:00
parent 4399b7c2fb
commit 29bf046aa8
3 changed files with 63 additions and 8 deletions

View File

@@ -110,6 +110,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private final int[] nextTickBoostCounter;
private BlockStateInterface bsi;
private BlockStateOctreeInterface boi;
private BlockPos destination;
private final ExecutorService solverExecutor;
@@ -299,7 +300,8 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
// not loaded yet?
return;
}
if (!passable(ctx.world().getBlockState(path.get(rangeStartIncl)), false)) {
final BetterBlockPos rangeStart = path.get(rangeStartIncl);
if (!ElytraBehavior.this.passable(rangeStart.x, rangeStart.y, rangeStart.z, false)) {
// we're in a wall
return; // previous iterations of this function SHOULD have fixed this by now :rage_cat:
}
@@ -575,7 +577,9 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
return;
}
// ctx AND context???? :DDD
this.bsi = new BlockStateInterface(ctx);
this.boi = new BlockStateOctreeInterface(context);
this.pathManager.tick();
final int playerNear = this.pathManager.getNear();
@@ -1250,12 +1254,12 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
}
private boolean passable(int x, int y, int z, boolean ignoreLava) {
return passable(this.bsi.get0(x, y, z), ignoreLava);
}
private static boolean passable(IBlockState state, boolean ignoreLava) {
Material mat = state.getMaterial();
return mat == Material.AIR || (ignoreLava && mat == Material.LAVA);
if (ignoreLava) {
final Material mat = this.bsi.get0(x, y, z).getMaterial();
return mat == Material.AIR || mat == Material.LAVA;
} else {
return !this.boi.get0(x, y, z);
}
}
private void tickInventoryTransactions() {

View File

@@ -0,0 +1,50 @@
/*
* 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
* 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.behavior.elytra;
import dev.babbaj.pathfinder.NetherPathfinder;
import dev.babbaj.pathfinder.Octree;
/**
* @author Brady
*/
public final class BlockStateOctreeInterface {
private final long context;
private long chunkPtr;
private int prevChunkX;
private int prevChunkZ;
public BlockStateOctreeInterface(final NetherPathfinderContext context) {
this.context = context.context;
}
public boolean get0(final int x, final int y, final int z) {
if (y < 0 || y >= 128) {
return false;
}
final int chunkX = x >> 4;
final int chunkZ = z >> 4;
if (chunkX != this.prevChunkX || chunkZ != this.prevChunkZ || this.chunkPtr == 0) {
this.prevChunkX = chunkX;
this.prevChunkZ = chunkZ;
this.chunkPtr = NetherPathfinder.getOrCreateChunk(this.context, chunkX, chunkZ);
}
return Octree.getBlock(this.chunkPtr, x & 0xF, y & 0x7F, z & 0xF);
}
}

View File

@@ -46,7 +46,8 @@ public final class NetherPathfinderContext {
private static final IBlockState AIR_BLOCK_STATE = Blocks.AIR.getDefaultState();
private final long context;
// Visible for access in BlockStateOctreeInterface
final long context;
private final long seed;
private final ExecutorService executor;