Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Why does this explosion not damage the player / terrain?


Recommended Posts

Hey Modders,


I'm testing an idea of an ultra sensitive block that has to be harvested with silk touch else it will explode upon being harvested. For this, I created an event handler which subscribed to the harvest drop event and checks to see if the block was harvested with silk touch and if it isn't, it creates an explosion (Code below)


public void explosion(BlockEvent.HarvestDropsEvent event){

	if(event.block == Blocks.grass || event.block == Blocks.dirt){
		if(event.isSilkTouching == false){
			event.world.createExplosion(event.harvester, event.harvester.posX, event.harvester.posY, event.harvester.posZ, 10, false);


However, when I load up a newly generated world, I am able to mine up the block, and able to see the explosion but the terrain and the player are unaffected. Could you guys please tell me what I am missing? I've taken a look at the Creeper code as well as the TNT code and it looks to be the same (I've even tried throwing in the condition to check and see if the world is remote and it doesn't change anything)

Link to comment
Share on other sites

I'm noticing now that I am getting a pretty consistent crash with a Null Point Exception and after poking at it with a stick, it seems like the EntityPlayer is being set to null before getting passed to the create explosion.


Is there a way to make this more stable? I've thought about checking whether or not the event.Harvester is null before going to the create explosion, but is that the best way?

Link to comment
Share on other sites

One follow up question: When I implement the resulting explosion, it destroys the terrain but does not damage the player.


Is this because of the fact that I am implementing the create explosion in the event? Here's the updated code:


public void explosion(BlockEvent.BreakEvent event){
	Block block = event.block;
	EntityPlayer player = event.getPlayer();
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	int blockMetadata = event.blockMetadata;

	if (!world.isRemote)
		if((block == Blocks.grass || block == Blocks.dirt) && EnchantmentHelper.getSilkTouchModifier(player)!=true) {
			world.createExplosion(player, x, y, z, 3, true);


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.

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.