Better compatibility for getting slots (fixes GH-2)

This commit is contained in:
Cynthia Foxwell 2024-03-17 10:09:05 -06:00
parent 7489d030ad
commit 04a8538752
1 changed files with 24 additions and 0 deletions

View File

@ -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<Object> cir) {
var playerScreenHandler = ScoutUtil.getPlayerScreenHandler();
if (ScoutUtil.isBagSlot(index)) {
if (playerScreenHandler != null) {
cir.setReturnValue(ScoutUtil.getBagSlot(index, playerScreenHandler));
} else {
cir.setReturnValue(null);
}
}
}
}