diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 3fd27aec..6a935c21 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -35,8 +35,8 @@ "icon": "icon.png", "depends": { "minecraft": "~1.20.6-", - "fabricloader": ">=0.15.6", - "fabric-api": ">=0.98.0" + "fabricloader": ">=0.15.11", + "fabric-api": ">=0.99.0" }, "breaks": { "optifabric": "<1.13.0" diff --git a/gradle.properties b/gradle.properties index 923dde32..57f89d40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,12 +14,12 @@ base_version=12.1 maven_group=dev.architectury version_suffix= -fabric_loader_version=0.15.10 -fabric_api_version=0.98.0+1.20.6 +fabric_loader_version=0.15.11 +fabric_api_version=0.99.0+1.20.6 mod_menu_version=10.0.0-beta.1 -forge_version=50.0.0 -neoforge_version=20.6.70-beta +forge_version=50.0.31 +neoforge_version=20.6.98-beta # Set to empty if not snapshots neoforge_pr= 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/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 1bbf3dc1..93221e3d 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -24,7 +24,7 @@ side = "BOTH" [[dependencies.architectury]] modId = "neoforge" type = "required" -versionRange = "[20.6.70-beta,)" +versionRange = "[20.6.98-beta,)" ordering = "NONE" side = "BOTH" 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",