[SOLVED] On Collided With Block BUG

Started by Kane on

Topic category: Troubleshooting, bugs, and solutions

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[SOLVED] On Collided With Block BUG
Wed, 08/23/2017 - 15:17 (edited)

I'm trying to make that when a player collides with a certain block and has in hand a certain item, something happens.

But it doesn't work, I get these errors 

Have the method changed?

Please repair it

Edited by Kane on Wed, 08/23/2017 - 15:17
Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Field inventory is only in
Wed, 08/23/2017 - 10:29

Field inventory is only in type EntityPlayer (and its children). You have to check if the entity is an instance of EntityPlayer and if so, you need to cast the entity to EntityPlayer.
Also, you can check EntityLivingBase instead of EntityPlayer and then use getActiveItemStack() for getting the held ItemStack ( or getHeldItem() in older versions)

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Field inventory is only in
Wed, 08/23/2017 - 11:19

@#1 Yeah I've already tried to check if the entity is istanceof EntityPlayer, but I'm writing "wrong" or in the wrong place

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:Field inventory is only in
Wed, 08/23/2017 - 13:10

@#1 I tried this, but I get same errors
[spoiler]

if (entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) entity;

[/spoiler]

Last seen on 17:17, 10. Jan 2024
Joined Aug 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
As always - telling something
Wed, 08/23/2017 - 13:48

As always - telling something without seeing the whole code is actually quite hard. However, because you say that you have got the very same error I personally guess that you are still using the entity variable instead of the player variable when getting the inventory.

Last seen on 12:58, 23. Sep 2019
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
RE:As always - telling something
Wed, 08/23/2017 - 15:16

@#2 Yeah sorry, but thanks to your comment I solved it just checking for the player as I wrote above and replacing entity in [spoiler]if (entity.inventory.getCurrentItem() != null && entity.inventory.getCurrentItem().getItem() == mcreator_animaLuciferiSwordTool.block)[/spoiler] with player

Thanks a lot