Jump to content

How to cancel Block Break Event if the block being broken is a specific block?


PixelDews

Recommended Posts

I want to cancel the event of the grass block being broken by the player, but I don't know how.

package com.pixeldews.unbreakableblock;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class ListenerClass {

	@SubscribeEvent
	public void onBlockBreak(BlockEvent.BreakEvent event) {
		PlayerEntity player = event.getPlayer();
		Block block = event.getState().getBlock();
		
		if (player != null) {
			if (block == Blocks.GRASS_BLOCK) {
				event.setCanceled(true);
			}
		}
		
	}
	
}

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.