Get the block broke in ChangeBlockEvent.Break

Hi all,

I seach how to get the break block when a player break blocks. I want to prevent the player from being able to break the glass but he can break the other blocks (it depends on the game state). I use Flan’s mod, and the ammunition of their weapons can break glass (that’s cool but …). I think the entity is a Sand block. So I want to prevent this entity from breaking the glass.

How can i prevent the break block of only one block (glass) by player (left click) and prevent the break block when the entity is a Sand block ?

	@Listener
public void onBreak(ChangeBlockEvent.Break e) {
	if(main.isState(State.BUILD) || main.isState(State.FIGHT)) {
		//Prevent the break of block of glass
	}
	if(main.isState(State.WAIT) || main.isState(State.FINISH))
		e.setCancelled(true);
}

Thank you for your answers.

maxou54200.

The event may affect multiple blocks. For example if a player breaks one block of a bed they end up breaking both blocks instead. What you are looking for is e.getTransactions() which returns a list of each block transaction where you can get the original state and the resulting state.

What you can also do is print out each transaction available and the cause provided in the event to see what you can work with given the mod’s unique nature.

I don’t knew, i found a config file on flan’s mod, we can cancel the “BreakGlass”. But, when the game is in State State.WAIT, State.FINISH the event ChangeBlockEvent.Break is no cancelled, we can break block. How to fix it please ?

Thank you.