From f7a296d7ba90d269ff448dbbf597242de8c27804 Mon Sep 17 00:00:00 2001 From: zbx1425 Date: Sat, 4 Jan 2025 16:37:36 +0800 Subject: [PATCH] Eat the backpack with WrapOperation --- gradle.properties | 2 +- .../org/teacon/gimmeman/mixin/L2BackpackMixin.java | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2d1dfc3..a836fba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G loom.platform = neoforge # Mod properties -mod_version = 0.1.1 +mod_version = 0.1.2 maven_group = org.teacon archives_name = gimmeman diff --git a/src/main/java/org/teacon/gimmeman/mixin/L2BackpackMixin.java b/src/main/java/org/teacon/gimmeman/mixin/L2BackpackMixin.java index 67d0b45..c2c3bc8 100644 --- a/src/main/java/org/teacon/gimmeman/mixin/L2BackpackMixin.java +++ b/src/main/java/org/teacon/gimmeman/mixin/L2BackpackMixin.java @@ -1,24 +1,27 @@ package org.teacon.gimmeman.mixin; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.xkmc.l2backpack.events.StartUpGiveItemEvents; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet; import net.neoforged.neoforge.event.tick.PlayerTickEvent; 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.CallbackInfo; import org.teacon.gimmeman.GiveMeMan; @Mixin(StartUpGiveItemEvents.class) public class L2BackpackMixin { - @Inject(method = "onPlayerTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;placeItemBackInInventory(Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) - private static void afterBackpackGiven(PlayerTickEvent.Post event, CallbackInfo ci) { + @WrapOperation(method = "onPlayerTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;placeItemBackInInventory(Lnet/minecraft/world/item/ItemStack;)V")) + private static void beforeBackpackGiven(Inventory instance, ItemStack arg, Operation original, PlayerTickEvent.Post event) { if (!(event.getEntity() instanceof ServerPlayer player)) return; LootTable lootTable = player.server.reloadableRegistries().getLootTable( ResourceKey.create(Registries.LOOT_TABLE, GiveMeMan.id("startup_items")));