Merge pull request #1087 from cabaletta/ispassable-crash-fix
Fix isPassable crash
This commit is contained in:
commit
2b71b31cfa
@ -35,6 +35,7 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -132,10 +133,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
}
|
}
|
||||||
return block == Blocks.WATER || block == Blocks.FLOWING_WATER;
|
return block == Blocks.WATER || block == Blocks.FLOWING_WATER;
|
||||||
}
|
}
|
||||||
// every block that overrides isPassable with anything more complicated than a "return true;" or "return false;"
|
|
||||||
// has already been accounted for above
|
return block.isPassable(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z));
|
||||||
// therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null
|
|
||||||
return block.isPassable(null, BlockPos.ORIGIN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,10 +148,18 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
* @return Whether or not the block at the specified position
|
* @return Whether or not the block at the specified position
|
||||||
*/
|
*/
|
||||||
static boolean fullyPassable(CalculationContext context, int x, int y, int z) {
|
static boolean fullyPassable(CalculationContext context, int x, int y, int z) {
|
||||||
return fullyPassable(context.get(x, y, z));
|
return fullyPassable(
|
||||||
|
context.bsi.access,
|
||||||
|
context.bsi.isPassableBlockPos.setPos(x, y, z),
|
||||||
|
context.bsi.get0(x, y, z)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean fullyPassable(IBlockState state) {
|
static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) {
|
||||||
|
return fullyPassable(ctx.world(), pos, ctx.world().getBlockState(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean fullyPassable(IBlockAccess access, BlockPos pos, IBlockState state) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.AIR) { // early return for most common case
|
if (block == Blocks.AIR) { // early return for most common case
|
||||||
return true;
|
return true;
|
||||||
@ -174,7 +181,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
|
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
|
||||||
return block.isPassable(null, null);
|
return block.isPassable(access, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
|
static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
|
||||||
|
@ -114,7 +114,7 @@ public class MovementParkour extends Movement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IBlockState destInto = context.bsi.get0(destX, y, destZ);
|
IBlockState destInto = context.bsi.get0(destX, y, destZ);
|
||||||
if (!MovementHelper.fullyPassable(destInto)) {
|
if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) {
|
||||||
if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) {
|
if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) {
|
||||||
res.x = destX;
|
res.x = destX;
|
||||||
res.y = y + 1;
|
res.y = y + 1;
|
||||||
|
@ -466,7 +466,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
}
|
}
|
||||||
for (int y = next.getDest().y; y <= movement.getSrc().y + 1; y++) {
|
for (int y = next.getDest().y; y <= movement.getSrc().y + 1; y++) {
|
||||||
BlockPos chk = new BlockPos(next.getDest().x, y, next.getDest().z);
|
BlockPos chk = new BlockPos(next.getDest().x, y, next.getDest().z);
|
||||||
if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) {
|
if (!MovementHelper.fullyPassable(ctx, chk)) {
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,7 +491,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
}
|
}
|
||||||
// we are centered
|
// we are centered
|
||||||
BlockPos headBonk = current.getSrc().subtract(current.getDirection()).up(2);
|
BlockPos headBonk = current.getSrc().subtract(current.getDirection()).up(2);
|
||||||
if (MovementHelper.fullyPassable(ctx.world().getBlockState(headBonk))) {
|
if (MovementHelper.fullyPassable(ctx, headBonk)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// wait 0.3
|
// wait 0.3
|
||||||
@ -524,7 +524,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
if (x == 1) {
|
if (x == 1) {
|
||||||
chk = chk.add(current.getDirection());
|
chk = chk.add(current.getDirection());
|
||||||
}
|
}
|
||||||
if (!MovementHelper.fullyPassable(ctx.world().getBlockState(chk))) {
|
if (!MovementHelper.fullyPassable(ctx, chk)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ public class BlockStateInterface {
|
|||||||
|
|
||||||
private final Long2ObjectMap<Chunk> loadedChunks;
|
private final Long2ObjectMap<Chunk> loadedChunks;
|
||||||
private final WorldData worldData;
|
private final WorldData worldData;
|
||||||
|
protected final IBlockAccess world;
|
||||||
|
public final BlockPos.MutableBlockPos isPassableBlockPos;
|
||||||
|
public final IBlockAccess access;
|
||||||
|
|
||||||
private Chunk prev = null;
|
private Chunk prev = null;
|
||||||
private CachedRegion prevCached = null;
|
private CachedRegion prevCached = null;
|
||||||
@ -59,6 +63,7 @@ public class BlockStateInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
|
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
|
||||||
|
this.world = world;
|
||||||
this.worldData = worldData;
|
this.worldData = worldData;
|
||||||
Long2ObjectMap<Chunk> worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
|
Long2ObjectMap<Chunk> worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
|
||||||
if (copyLoadedChunks) {
|
if (copyLoadedChunks) {
|
||||||
@ -70,6 +75,8 @@ public class BlockStateInterface {
|
|||||||
if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
|
if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
this.isPassableBlockPos = new BlockPos.MutableBlockPos();
|
||||||
|
this.access = new BlockStateInterfaceAccessWrapper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean worldContainsLoadedChunk(int blockX, int blockZ) {
|
public boolean worldContainsLoadedChunk(int blockX, int blockZ) {
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.utils;
|
||||||
|
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
import net.minecraft.world.WorldType;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 11/5/2019
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
|
public final class BlockStateInterfaceAccessWrapper implements IBlockAccess {
|
||||||
|
|
||||||
|
private final BlockStateInterface bsi;
|
||||||
|
|
||||||
|
BlockStateInterfaceAccessWrapper(BlockStateInterface bsi) {
|
||||||
|
this.bsi = bsi;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TileEntity getTileEntity(BlockPos pos) {
|
||||||
|
throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCombinedLight(BlockPos pos, int lightValue) {
|
||||||
|
throw new UnsupportedOperationException("getCombinedLight not supported by BlockStateInterfaceAccessWrapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBlockState getBlockState(BlockPos pos) {
|
||||||
|
// BlockStateInterface#get0(BlockPos) btfo!
|
||||||
|
return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAirBlock(BlockPos pos) {
|
||||||
|
return this.bsi.get0(pos.getX(), pos.getY(), pos.getZ()).getMaterial() == Material.AIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Biome getBiome(BlockPos pos) {
|
||||||
|
throw new UnsupportedOperationException("getBiome not supported by BlockStateInterfaceAccessWrapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStrongPower(BlockPos pos, EnumFacing direction) {
|
||||||
|
throw new UnsupportedOperationException("getStrongPower not supported by BlockStateInterfaceAccessWrapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldType getWorldType() {
|
||||||
|
return this.bsi.world.getWorldType();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user