Jump to content

[1.11.2] Prevent mobs from passing/seeing through a block


Recommended Posts

I am trying to figure out how to make a block where some mobs can pass through it where others cannot.

 

Unless someone knows of a better way, I am guessing I have to handle this somehow with this method:

public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entity)
{
	if(entity instanceof EntityMob)
	{
		// do something here
	}
}

 

I don't have a very good understanding of EnumFacing if that has to be used and would have to need some explanation on how to use it here.

 

I would also like to make this block so all mobs (not just a select few) cannot see through it. It seems if a block is passable in any way, a mob can see through it. Can I prevent them from seeing through a passable block?

Link to comment
Share on other sites

Thanks! So with your suggestion I came up with this and it seems to work as desired:

@Override //Depreciated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_)
{
	if(!(entity instanceof TamablePokemon) && !(entity instanceof EntityPlayer))
	{
		AxisAlignedBB axisalignedbb = state.getBoundingBox(worldIn, pos).offset(pos);

		if (entityBox.intersectsWith(axisalignedbb))
		{
			collidingBoxes.add(axisalignedbb);
		}
	}
}

 

Should I be at all concerned that this Method is marked as Depreciated? Like, it getting removed in a future update?

Link to comment
Share on other sites

1 hour ago, FuzzyAcornIndustries said:

Should I be at all concerned that this Method is marked as Depreciated? Like, it getting removed in a future update?

Basically not really. The method is marked deprecated which means do not call this method. You should still override it to get the desired behavior.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

4 minutes ago, Draco18s said:

Basically not really. The method is marked deprecated which means do not call this method. You should still override it to get the desired behavior.

Thanks, I was hoping that was the case rather than it was a warning assuring it was gonna be removed. I'm trying to think ahead for scalability into future updates.

Link to comment
Share on other sites

The functionailiy will continue to exist as Minecraft evolves, but it is possible that the method does get removed and placed somewhere else. It will depend on how Mojang continues to work with the IBlockState format.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.