Jump to content

Make a block only collidable for a specific entity


MosquitoFRA

Recommended Posts

In fact, I'm not used to this method. I found an example:

public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, under);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, middle);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, top);
    }

 

So what do I have to do with these information?

Link to comment
Share on other sites

public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn)

     if(entity.projectiles)

    {   super.addCollisionBoxToList(pos, entityBox, collidingBoxes, under);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, middle);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, top);
    }

Is it like this?

Link to comment
Share on other sites

That does not even compile, your method body is missing the curly braces.

entity is also not a local variable, field or anything else. Assuming you meant entityIn, you would need a null check before accessing any fields or methods on it. Assuming you added that, projectiles is still not a field that exists on the Entity class.

 

So, no, nothing about what you posted makes sense.

Link to comment
Share on other sites

For the entity, it's entityLiving (I think it's for projectiles).
And I don't know to do this null check

     { if(EntityLiving)

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, under);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, middle);

        super.addCollisionBoxToList(pos, entityBox, collidingBoxes, top);
    }

 

Edited by MosquitoFRA
Link to comment
Share on other sites

What diesieben was trying to say is that you should learn how to check if an entity is of a given instance or has some particular properties defined in the entity class. I'm pretty sure that the entity class itself has no "projectiles" property, and even if it does i don't think it's a boolean by the name. That being said, you should do something like this (assuming you are using Forge 1.12.2)

 

@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
  if(entityIn instanceof EntityPlayer) {
    // Do stuff
  }
}

 

In this case you check if the entity that collides with the block is a player. If so then you can do whatever you want (like adding the collision box). 

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

On 11/4/2018 at 5:29 PM, JimiIT92 said:

...


@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
  if(entityIn instanceof EntityPlayer) {
    // Do stuff
  }
}

...

And now you've just give him the code which he can copy-paste without learning anything from it.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

@Override
          public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
               if(entityIn instanceof EntityPlayer) {
                         public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
               return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
                    }
               }
          }

I have this but it doesn't work

Edited by MosquitoFRA
Link to comment
Share on other sites

Learn java. Just the basics, 5 minutes of learning java and you will understand how horribly wrong that is on every level

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

@Override
          public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState) {
               if(entityIn instanceof EntityPlayer) {
                         getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
               return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
                    }
               }
          }

I tried this but it didn't work

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
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.



×
×
  • Create New...

Important Information

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