diff --git a/neoforge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java b/neoforge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java index 54ab242c..524f7f82 100644 --- a/neoforge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java +++ b/neoforge/src/main/java/dev/architectury/event/forge/EventHandlerImplCommon.java @@ -36,6 +36,7 @@ import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.common.util.TriState; import net.neoforged.neoforge.event.CommandEvent; import net.neoforged.neoforge.event.LootTableLoadEvent; import net.neoforged.neoforge.event.RegisterCommandsEvent; @@ -247,20 +248,6 @@ public static void event(FarmlandTrampleEvent event) { } } - @SubscribeEvent(priority = EventPriority.HIGH) - public static void event(FillBucketEvent event) { - ItemStack oldItem = event.getEmptyBucket(); - CompoundEventResult result = PlayerEvent.FILL_BUCKET.invoker().fill(event.getEntity(), event.getLevel(), oldItem, event.getTarget()); - if (result.interruptsFurtherEvaluation()) { - event.setCanceled(true); - event.setFilledBucket(result.object()); - - if (result.value() != null) { - event.setResult(result.value() ? Event.Result.ALLOW : Event.Result.DENY); - } - } - } - // TODO: Hook ourselves when mixin is available // @SubscribeEvent(priority = EventPriority.HIGH) // public static void event(EnteringChunk event) { @@ -294,20 +281,20 @@ public static void event(ItemSmeltedEvent event) { } @SubscribeEvent(priority = EventPriority.HIGH) - public static void event(EntityItemPickupEvent event) { + public static void event(ItemEntityPickupEvent.Pre event) { // 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()); + var result = PlayerEvent.PICKUP_ITEM_PRE.invoker().canPickup(event.getPlayer(), event.getItemEntity(), event.getItemEntity().getItem()); if (result.isFalse()) { - event.setCanceled(true); + event.setCanPickup(TriState.FALSE); } else if (result.isTrue()) { - event.setResult(Event.Result.ALLOW); + event.setCanPickup(TriState.TRUE); } } @SubscribeEvent(priority = EventPriority.HIGH) - public static void event(ItemPickupEvent event) { - PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(event.getEntity(), event.getOriginalEntity(), event.getStack()); + public static void event(ItemEntityPickupEvent.Post event) { + PlayerEvent.PICKUP_ITEM_POST.invoker().pickup(event.getPlayer(), event.getItemEntity(), event.getCurrentStack()); } @SubscribeEvent(priority = EventPriority.HIGH) @@ -340,8 +327,8 @@ public static void eventPlayerInteractEvent(PlayerInteractEvent.RightClickBlock if (result.isPresent()) { event.setCanceled(true); event.setCancellationResult(result.asMinecraft()); - event.setUseBlock(Event.Result.DENY); - event.setUseItem(Event.Result.DENY); + event.setUseBlock(TriState.FALSE); + event.setUseItem(TriState.FALSE); } } @@ -360,8 +347,8 @@ public static void eventPlayerInteractEvent(PlayerInteractEvent.LeftClickBlock e EventResult result = InteractionEvent.LEFT_CLICK_BLOCK.invoker().click(event.getEntity(), event.getHand(), event.getPos(), event.getFace()); if (result.isPresent()) { event.setCanceled(true); - event.setUseBlock(result.value() ? Event.Result.ALLOW : Event.Result.DENY); - event.setUseItem(result.value() ? Event.Result.ALLOW : Event.Result.DENY); + event.setUseBlock(result.value() ? TriState.TRUE : TriState.FALSE); + event.setUseItem(result.value() ? TriState.TRUE : TriState.FALSE); } } diff --git a/neoforge/src/main/java/dev/architectury/mixin/forge/neoforge/MixinBucketItem.java b/neoforge/src/main/java/dev/architectury/mixin/forge/neoforge/MixinBucketItem.java new file mode 100644 index 00000000..b9231ea4 --- /dev/null +++ b/neoforge/src/main/java/dev/architectury/mixin/forge/neoforge/MixinBucketItem.java @@ -0,0 +1,57 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.mixin.forge.neoforge; + +import dev.architectury.event.events.common.PlayerEvent; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BucketItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(BucketItem.class) +public class MixinBucketItem { + + @Inject( + method = "use", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/phys/BlockHitResult;getType()Lnet/minecraft/world/phys/HitResult$Type;", + ordinal = 0 + ), + locals = LocalCapture.CAPTURE_FAILHARD, + cancellable = true + ) + public void fillBucket(Level level, Player player, InteractionHand hand, CallbackInfoReturnable> cir, ItemStack stack, BlockHitResult target) { + var result = PlayerEvent.FILL_BUCKET.invoker().fill(player, level, stack, target); + if (result.interruptsFurtherEvaluation() && result.value() != null) { + cir.setReturnValue(result.asMinecraft()); + cir.cancel(); + } + } + +} diff --git a/neoforge/src/main/resources/architectury.mixins.json b/neoforge/src/main/resources/architectury.mixins.json index 8ec3b2ed..022ae408 100644 --- a/neoforge/src/main/resources/architectury.mixins.json +++ b/neoforge/src/main/resources/architectury.mixins.json @@ -10,6 +10,7 @@ "MixinMinecraft" ], "mixins": [ + "neoforge.MixinBucketItem", "neoforge.BucketItemAccessor", "neoforge.LiquidBlockAccessor", "neoforge.MixinChunkSerializer",