Better compatibility for getting slots (fixes GH-2)
This commit is contained in:
parent
7489d030ad
commit
04a8538752
1 changed files with 24 additions and 0 deletions
24
src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java
Normal file
24
src/main/java/pm/c7/scout/mixin/DefaultedListMixin.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue