Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jab125 committed May 30, 2024
1 parent 6fba3bc commit e713363
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemStack> 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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<InteractionResultHolder<ItemStack>> 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();
}
}

}
1 change: 1 addition & 0 deletions neoforge/src/main/resources/architectury.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"MixinMinecraft"
],
"mixins": [
"neoforge.MixinBucketItem",
"neoforge.BucketItemAccessor",
"neoforge.LiquidBlockAccessor",
"neoforge.MixinChunkSerializer",
Expand Down

0 comments on commit e713363

Please sign in to comment.