Fix Item pickup not being cancellable on Forge (#301)

(cherry picked from commit 128141a99d)
This commit is contained in:
Max
2022-07-20 23:22:38 +08:00
committed by shedaniel
parent db58d101e4
commit 2f5d4444c8

View File

@@ -295,7 +295,14 @@ public class EventHandlerImplCommon {
@SubscribeEvent(priority = EventPriority.HIGH)
public static void event(EntityItemPickupEvent event) {
PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getEntity(), event.getItem(), event.getItem().getItem());
// note: this event is weird, cancel is equivalent to denying the pickup,
// and setting the result to ALLOW will pick it up without adding it to the player's inventory
var result = PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getEntity(), event.getItem(), event.getItem().getItem());
if (result.isFalse()) {
event.setCanceled(true);
} else if (result.isTrue()) {
event.setResult(Event.Result.ALLOW);
}
}
@SubscribeEvent(priority = EventPriority.HIGH)