Jump to content

[SOLVED] Help with collisions


wannabeuk

Recommended Posts

Hi all,

I'm trying to create a block that is 2x1 (like a door) which has only three sides, allowing the player to walk inside it (like a booth). But I simply can't get my head around how to do the collisions. I've found a good example from a old mod (1.7) but i can't seem to work out how you would do this in 1.12. Does anyone know any uptodate examples or is willing to give me some pointers?

 

Thanks.

Edited by wannabeuk
spelling
Link to comment
Share on other sites

3 hours ago, wannabeuk said:

I'm trying to create a block that is 2x1 (like a door)

A door is actually too blocks(states). 

 

Also we cant help you if you dont post your code, preferably on git or some other code sharing site.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Thanks for the reply, I was aware it was two blocks it's just so much has changed since I last started modding that i was completely lost.

I've managed to get my block to place correctly so it's two high. Now i'm trying to work on collisions.

 

This is what i have :

 

static double AXIS_MIN_MIN = 0, AXIS_MIN_MAX = 0.1, AXIS_MAX_MIN = 0.9, AXIS_MAX_MAX = 1, AXIS_FLOOR_MIN = -0.01, AXIS_FLOOR_MAX = 0;

@Override
    public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) 
    {
        if(entityIn == null)
        {
            return;
        }
        
        List<AxisAlignedBB> axis = new ArrayList<AxisAlignedBB>();
        
        EnumFacing facing = worldIn.getBlockState(pos).getValue(FACING);
        
        int x = pos.getX();
        int y = pos.getY();
        int z = pos.getZ();
        
        //TODO : Work out how to do upper / lower block
        if(facing == EnumFacing.NORTH)
        {
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west
            
        }
        else if (facing == EnumFacing.SOUTH)
        {
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west
        }
        else if (facing == EnumFacing.EAST)
        {
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MIN_MIN, y, z), new BlockPos(x + AXIS_MIN_MAX, y + 1, z + 1))); // west
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south
        }
        else if (facing == EnumFacing.WEST)
        {
            axis.add(new AxisAlignedBB(new BlockPos(x + AXIS_MAX_MIN, y, z), new BlockPos(x + AXIS_MAX_MAX, y + 1, z + 1))); // east
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MIN_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MIN_MAX))); // north
            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south
        }

        for(AxisAlignedBB a : axis)
        {
            if(a != null && entityBox.intersects(a))
            {
                collidingBoxes.add(a);
            }
        }
    }

 

it seems to have no effect on the collisions so i'm not sure if my code is just wrong. or if i'm missing something

Link to comment
Share on other sites

43 minutes ago, wannabeuk said:

            axis.add(new AxisAlignedBB(new BlockPos(x, y, z + AXIS_MAX_MIN), new BlockPos(x + 1, y + 1, z + AXIS_MAX_MAX))); // south

Don't offset the boxes by the blockpos provided to you, the game will do that for you later. Apart from that your code should work, but here is an example of mine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.