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

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);
}
}
}
}