Search in sources :

Example 1 with WallBlock

use of net.minecraft.block.WallBlock in project ChocolateQuestRepoured by TeamChocoQuest.

the class PathNavigateGroundCQR method getPathFinder.

@Override
protected PathFinder getPathFinder() {
    this.nodeProcessor = new WalkNodeProcessor() {

        @Override
        public PathNodeType getPathNodeType(IBlockAccess p_193577_1_, int x, int y, int z, int xSize, int ySize, int zSize, boolean canOpenDoorsIn, boolean canEnterDoorsIn, EnumSet<PathNodeType> p_193577_10_, PathNodeType p_193577_11_, BlockPos p_193577_12_) {
            for (int i = 0; i < xSize; ++i) {
                for (int j = 0; j < ySize; ++j) {
                    for (int k = 0; k < zSize; ++k) {
                        int l = i + x;
                        int i1 = j + y;
                        int j1 = k + z;
                        PathNodeType pathnodetype = this.getPathNodeType(p_193577_1_, l, i1, j1);
                        if (pathnodetype == PathNodeType.DOOR_WOOD_CLOSED && canOpenDoorsIn && canEnterDoorsIn) {
                            pathnodetype = PathNodeType.WALKABLE;
                        }
                        // TODO better method for calculating the facing from which the door will be entered
                        if (pathnodetype == PathNodeType.DOOR_IRON_CLOSED && canOpenDoorsIn && canEnterDoorsIn && EntityAIOpenCloseDoor.canMoveThroughDoor(p_193577_1_, new BlockPos(l, i1, j1), Direction.getFacingFromVector(l - p_193577_12_.getX(), i1 - p_193577_12_.getY(), j1 - p_193577_12_.getZ()).getOpposite(), true)) {
                            pathnodetype = PathNodeType.WALKABLE;
                        }
                        if (pathnodetype == PathNodeType.DOOR_OPEN && !canEnterDoorsIn) {
                            pathnodetype = PathNodeType.BLOCKED;
                        }
                        if (pathnodetype == PathNodeType.RAIL && !(p_193577_1_.getBlockState(p_193577_12_).getBlock() instanceof AbstractRailBlock) && !(p_193577_1_.getBlockState(p_193577_12_.down()).getBlock() instanceof AbstractRailBlock)) {
                            pathnodetype = PathNodeType.FENCE;
                        }
                        if (i == 0 && j == 0 && k == 0) {
                            p_193577_11_ = pathnodetype;
                        }
                        p_193577_10_.add(pathnodetype);
                    }
                }
            }
            return p_193577_11_;
        }

        @Override
        protected PathNodeType getPathNodeTypeRaw(IBlockAccess p_189553_1_, int p_189553_2_, int p_189553_3_, int p_189553_4_) {
            BlockPos blockpos = new BlockPos(p_189553_2_, p_189553_3_, p_189553_4_);
            BlockState iblockstate = p_189553_1_.getBlockState(blockpos);
            Block block = iblockstate.getBlock();
            Material material = iblockstate.getMaterial();
            PathNodeType type = block.getAiPathNodeType(iblockstate, p_189553_1_, blockpos, this.currentEntity);
            if (type != null) {
                return type;
            }
            if (material == Material.AIR) {
                return PathNodeType.OPEN;
            } else if (block != Blocks.TRAPDOOR && block != Blocks.IRON_TRAPDOOR && block != Blocks.WATERLILY) {
                if (block == Blocks.FIRE) {
                    return PathNodeType.DAMAGE_FIRE;
                } else if (block == Blocks.CACTUS) {
                    return PathNodeType.DAMAGE_CACTUS;
                } else if (block instanceof DoorBlock && material == Material.WOOD && !iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_WOOD_CLOSED;
                } else if (block instanceof DoorBlock && material == Material.IRON && !iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_IRON_CLOSED;
                } else if (block instanceof DoorBlock && iblockstate.getActualState(p_189553_1_, blockpos).getValue(DoorBlock.OPEN)) {
                    return PathNodeType.DOOR_OPEN;
                } else if (block instanceof AbstractRailBlock) {
                    return PathNodeType.RAIL;
                } else if (!(block instanceof FenceBlock) && !(block instanceof WallBlock) && (!(block instanceof FenceGateBlock) || iblockstate.getValue(FenceGateBlock.OPEN).booleanValue())) {
                    if (material == Material.WATER) {
                        return PathNodeType.WATER;
                    } else if (material == Material.LAVA) {
                        return PathNodeType.LAVA;
                    } else {
                        return block.isPassable(p_189553_1_, blockpos) ? PathNodeType.OPEN : PathNodeType.BLOCKED;
                    }
                } else {
                    return PathNodeType.FENCE;
                }
            } else {
                return PathNodeType.TRAPDOOR;
            }
        }
    };
    this.nodeProcessor.setCanEnterDoors(true);
    this.pathFinder = new PathFinder(this.nodeProcessor);
    return this.pathFinder;
}
Also used : IBlockAccess(net.minecraft.world.IBlockAccess) PathNodeType(net.minecraft.pathfinding.PathNodeType) Material(net.minecraft.block.material.Material) PathFinder(net.minecraft.pathfinding.PathFinder) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) PathPoint(net.minecraft.pathfinding.PathPoint) WalkNodeProcessor(net.minecraft.pathfinding.WalkNodeProcessor) FenceBlock(net.minecraft.block.FenceBlock) BlockState(net.minecraft.block.BlockState) WallBlock(net.minecraft.block.WallBlock) DoorBlock(net.minecraft.block.DoorBlock) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) FenceBlock(net.minecraft.block.FenceBlock) WallBlock(net.minecraft.block.WallBlock) BlockPos(net.minecraft.util.math.BlockPos) DoorBlock(net.minecraft.block.DoorBlock)

Aggregations

AbstractRailBlock (net.minecraft.block.AbstractRailBlock)1 BlockState (net.minecraft.block.BlockState)1 DoorBlock (net.minecraft.block.DoorBlock)1 FenceBlock (net.minecraft.block.FenceBlock)1 WallBlock (net.minecraft.block.WallBlock)1 Material (net.minecraft.block.material.Material)1 PathFinder (net.minecraft.pathfinding.PathFinder)1 PathNodeType (net.minecraft.pathfinding.PathNodeType)1 PathPoint (net.minecraft.pathfinding.PathPoint)1 WalkNodeProcessor (net.minecraft.pathfinding.WalkNodeProcessor)1 BlockPos (net.minecraft.util.math.BlockPos)1 IBlockAccess (net.minecraft.world.IBlockAccess)1