Fix dupe when shift-clicking crafting results out of terminal
This commit is contained in:
parent
5eb948802c
commit
ce511e62e1
|
@ -1,6 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.inventory.CraftingInventory
|
import net.minecraft.inventory.CraftingInventory
|
||||||
import net.minecraft.inventory.CraftingResultInventory
|
import net.minecraft.inventory.CraftingResultInventory
|
||||||
|
@ -94,6 +94,36 @@ class CraftingTerminalScreenHandler(
|
||||||
terminal.requestItemsForCrafting(maxAmount)
|
terminal.requestItemsForCrafting(maxAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||||
|
if (slotId == resultSlot.id && resultSlot.hasStack()) {
|
||||||
|
val craftingResult = resultSlot.stack
|
||||||
|
val originalResult = craftingResult.copy()
|
||||||
|
|
||||||
|
// todo: CraftingScreenHandler calls onCraft, but I don't think that's necessary because onStackChanged should handle it
|
||||||
|
craftingResult.item.onCraft(craftingResult, player.world, player)
|
||||||
|
|
||||||
|
if (!insertItem(craftingResult, playerSlotsStart, playerSlotsEnd, true)) {
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
}
|
||||||
|
resultSlot.onStackChanged(craftingResult, originalResult)
|
||||||
|
|
||||||
|
if (craftingResult.isEmpty) {
|
||||||
|
resultSlot.stack = ItemStack.EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
if (craftingResult.count == originalResult.count) {
|
||||||
|
return ItemStack.EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
val taken = resultSlot.onTakeItem(player, craftingResult)
|
||||||
|
player.dropItem(taken, false)
|
||||||
|
|
||||||
|
return originalResult
|
||||||
|
} else {
|
||||||
|
return super.transferSlot(player, slotId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RecipeType.CRAFTING wants a CraftingInventory, but we can't store a CraftingInventory on the BE without a screen handler, so...
|
// RecipeType.CRAFTING wants a CraftingInventory, but we can't store a CraftingInventory on the BE without a screen handler, so...
|
||||||
class CraftingInv(val handler: CraftingTerminalScreenHandler): CraftingInventory(handler, 3, 3) {
|
class CraftingInv(val handler: CraftingTerminalScreenHandler): CraftingInventory(handler, 3, 3) {
|
||||||
private val backing = handler.terminal.craftingInv
|
private val backing = handler.terminal.craftingInv
|
||||||
|
|
Loading…
Reference in New Issue