Do you want to know if any part of the player is in your block, or if the head is in your block? The reason is that for things like water pushing an entity it checks for any part, but for things like changing the view when underwater or for suffocating a person it checks for the head.
/**
* Checks if the entity's head is inside a block
*/
public static boolean isEntityHeadInsideBlock(Entity entity, Block block)
{
double eyePosY = entity.posY + entity.getEyeHeight();
BlockPos pos = new BlockPos(entity.posX, eyePosY, entity.posZ);
IBlockState iBlockState = entity.world.getBlockState(pos);
return (block == ModBlocks.MY_SPECIAL_BLOCK);
}
Of course you should change the "ModBlocks.MY_SPECIAL_BLOCK" to whatever block you want to check. The code simply adds the eyeheight to the entity position and checks for the type of block at that position.
I want to detect players who enters in my block
Github if necessary -> https://github.com/Dadoum/Bomb-mod
Do you want to know if any part of the player is in your block, or if the head is in your block? The reason is that for things like water pushing an entity it checks for any part, but for things like changing the view when underwater or for suffocating a person it checks for the head.
Head in block
Something like this should work:
Of course you should change the "ModBlocks.MY_SPECIAL_BLOCK" to whatever block you want to check. The code simply adds the eyeheight to the entity position and checks for the type of block at that position.
Sorry, but i'm a noob where I put it and where I call it ?