How can I detect if there is a certain type of block between an entity and a player?

Started by ImCloud13 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can I detect if there is a certain type of block between an entity and a player?

Hello, I need to check if there is a certain type of block or not between an entity and a player. Someone else asked a similar question before but the only answer is a dead link, so that's no help. Please let me know if you have any ideas, thank you!

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you want it to check from…
Tue, 09/30/2025 - 06:05

If you want it to check from the entities' feet,

world.getBlockState(world.clip(new ClipContext(entity1.position(), entity2.position(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getBlockPos())

 

If you want it to check from the entities' eyes,

world.getBlockState(world.clip(new ClipContext(entity1.getEyePosition(), entity2.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getBlockPos())