Add handling for inserting items directly into trinket slots

This commit is contained in:
Sollace 2022-09-21 17:12:01 +02:00
parent e02589d07b
commit f45817bfd6
3 changed files with 44 additions and 0 deletions

View file

@ -52,6 +52,16 @@ abstract class MixinScreenHandler {
return sender.isEmpty() || (canApply(currentSlot) && (currentSlot.getStack().getCount() + sender.getCount()) <= currentSlot.getMaxItemCount(sender));
}
@Redirect(method = "canInsertItemIntoSlot",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;getMaxCount()I"
)
)
private static int onCanInsertItemIntoSlot(ItemStack sender, @Nullable Slot slot) {
return canApply(slot) ? slot.getMaxItemCount(sender) : sender.getMaxCount();
}
private static boolean canApply(Slot slot) {
return slot instanceof TrinketSlot;
}

View file

@ -0,0 +1,33 @@
package com.minelittlepony.unicopia.mixin.trinkets;
import org.spongepowered.asm.mixin.*;
import com.minelittlepony.unicopia.trinkets.TrinketsDelegateImpl;
import dev.emi.trinkets.api.*;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
@Mixin(TrinketInventory.class)
abstract class MixinTrinketInventory implements Inventory {
@Override
public boolean isValid(int slot, ItemStack stack) {
ItemStack existingStack = getStack(slot);
SlotReference ref = new SlotReference((TrinketInventory)(Object)this, slot);
int max = Math.min(
existingStack.isEmpty() ? 64 : TrinketsDelegateImpl.getMaxCount(existingStack, ref, existingStack.getMaxCount()),
stack.isEmpty() ? 64 : TrinketsDelegateImpl.getMaxCount(stack, ref, stack.getMaxCount())
);
int combinedCount = stack.getCount();
if (ItemStack.canCombine(existingStack, stack)) {
combinedCount += existingStack.getCount();
}
return combinedCount <= max;
}
}

View file

@ -36,6 +36,7 @@
"trinkets.MixinTrinketSurvivalSlot",
"trinkets.MixinTrinketCreativeSlot",
"trinkets.MixinTrinketItem",
"trinkets.MixinTrinketInventory",
"trinkets.MixinScreenHandler"
],
"client": [