Skip to content

Commit

Permalink
Eat the backpack with WrapOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Jan 4, 2025
1 parent 665910a commit f7a296d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/teacon/gimmeman/mixin/L2BackpackMixin.java
Original file line number Diff line number Diff line change
@@ -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<Void> 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")));
Expand Down

0 comments on commit f7a296d

Please sign in to comment.