From 04a85387528d214f8403add0d4b817e7666cfc61 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sun, 17 Mar 2024 10:09:05 -0600 Subject: [PATCH] Better compatibility for getting slots (fixes GH-2) --- .../pm/c7/scout/mixin/DefaultedListMixin.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java diff --git a/src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java b/src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java new file mode 100644 index 0000000..84dd057 --- /dev/null +++ b/src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java @@ -0,0 +1,24 @@ +package pm.c7.scout.mixin; + +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 net.minecraft.util.collection.DefaultedList; +import pm.c7.scout.ScoutUtil; + +@Mixin(DefaultedList.class) +public class DefaultedListMixin { + @Inject(method = "get", at = @At("HEAD"), cancellable = true) + public void scout$fixIndexingSlots(int index, CallbackInfoReturnable cir) { + var playerScreenHandler = ScoutUtil.getPlayerScreenHandler(); + if (ScoutUtil.isBagSlot(index)) { + if (playerScreenHandler != null) { + cir.setReturnValue(ScoutUtil.getBagSlot(index, playerScreenHandler)); + } else { + cir.setReturnValue(null); + } + } + } +}