Testing if position collides with block

Discussion in 'Plugin Development' started by Colinus999, Jan 22, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    Colinus999

    Hello!
    I am developing a Class that simplifies RayCasting. Everything works fine but you can't cast a ray through stair pieces. That's because I am only getting the bounding box of the block:
    Get AxisAlignedBB (open)
    Code:
     // BlockPosition is the NMS Class similar to org.bukkit.block.Block
    private AxisAlignedBB getBBox(BlockPosition pos) {
        IBlockData data = world.getType(pos);
        Block block = data.getBlock();
        return new AxisAlignedBB((double)pos.getX()+block.B(), (double)pos.getY()+block.D(), (double)block.F(),
                (double)pos.getX()+block.C(), (double)pos.getY()+block.E(), (double)pos.getZ()+block.G());
    }

    The BoundingBox of a block is visible when looking at a block (the black wireframe surrounding the block).
    But the BoundingBox it not the collision box. In most cases it is, of course, but stairs have a more complex collision box. It is made out of multiple boxes.

    So my problem is:
    How do I get the full collision box / boxes of a block?
     
  2. Offline

    Colinus999

    I'm currently decompiling bukkit/spigot 1.8.8 and I found this code
    in Entity.class (net.minecraft.server):
    net.minecraft.server.v1_8_R3.Entity#checkBlockCollisions (open)

    Code:
    protected void checkBlockCollisions() {
        final BlockPosition blockposition = new BlockPosition(this.getBoundingBox().a + 0.001, this.getBoundingBox().b + 0.001, this.getBoundingBox().c + 0.001);
        final BlockPosition blockposition2 = new BlockPosition(this.getBoundingBox().d - 0.001, this.getBoundingBox().e - 0.001, this.getBoundingBox().f - 0.001);
        if (this.world.areChunksLoadedBetween(blockposition, blockposition2)) {
            for (int i = blockposition.getX(); i <= blockposition2.getX(); ++i) {
                for (int j = blockposition.getY(); j <= blockposition2.getY(); ++j) {
                    for (int k = blockposition.getZ(); k <= blockposition2.getZ(); ++k) {
                        final BlockPosition blockposition3 = new BlockPosition(i, j, k);
                        final IBlockData iblockdata = this.world.getType(blockposition3);
                        try {
                            iblockdata.getBlock().a(this.world, blockposition3, iblockdata, this);
                        }
                        catch (Throwable throwable) {
                            final CrashReport crashreport = CrashReport.a(throwable, "Colliding entity with block");
                            final CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block being collided with");
                            CrashReportSystemDetails.a(crashreportsystemdetails, blockposition3, iblockdata);
                            throw new ReportedException(crashreport);
                        }
                    }
                }
            }
        }
    }
    So I need to find the method Block#a-World,BlockPosition,IBlockData,Entity-:
    Code:
    a(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity)
    I could not find it and the code is hard to understand. Please help.
    Here is the formatted Block.java class: net.minecraft.server.v1_8_R3.Block
     
Thread Status:
Not open for further replies.

Share This Page