mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Add handling for inserting items directly into trinket slots
This commit is contained in:
parent
e02589d07b
commit
f45817bfd6
3 changed files with 44 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@
|
|||
"trinkets.MixinTrinketSurvivalSlot",
|
||||
"trinkets.MixinTrinketCreativeSlot",
|
||||
"trinkets.MixinTrinketItem",
|
||||
"trinkets.MixinTrinketInventory",
|
||||
"trinkets.MixinScreenHandler"
|
||||
],
|
||||
"client": [
|
||||
|
|
Loading…
Reference in a new issue