Carry On

Carry On

112M Downloads

How to distinguish pick up events from break events?

hammertater opened this issue ยท 3 comments

commented

Using carryon-1.16.3-1.15.1.7, attempting to pick up a block with CarryOn triggers a BreakEvent:

private static boolean handleProtections(ServerPlayerEntity player, World world, BlockPos pos, BlockState state)
{
boolean breakable = true;
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
breakable = false;
return breakable;
}

This is fine, but I'm not sure how to distinguish CarryOn pickup attempts from normal block break attempts. What about defining an event that extends the normal BreakEvent? Something like

class PickUpEvent extends BlockEvent.BreakEvent {
    public PickUpEvent(World world, BlockPos pos, BlockState state, PlayerEntity player) {
        super(world, pos, state, player);
    }
}

then post the event with

BlockEvent.BreakEvent event = new PickUpEvent(world, pos, state, player); 
MinecraftForge.EVENT_BUS.post(event); 

so that other mods can check for this event with

public static void onBreakEvent(BlockEvent.BreakEvent event) {
    if (event instanceof PickUpEvent) {
        ...
    }
}

or maybe there's a better way of doing this.

For context - someone using my TreeChop mod and CarryOn at the same time noticed a conflict of our BreakEvent behaviors (https://www.curseforge.com/minecraft/mc-mods/treechop?comment=60). A hacky fix from my end is to disable TreeChop during RightClickBlock events (when CarryOn posts BreakEvents), but I'm worried that this might cause unexpected conflicts with other mods.

commented

Yeah sure, I can wrap the event in a PickUp event

commented

Works great, thanks!

commented

Great to hear!