PhysicalConnectivity/src/main/kotlin/net/shadowfacts/phycon/util/GhostSlot.kt

46 lines
1.1 KiB
Kotlin
Raw Normal View History

2021-03-01 03:01:45 +00:00
package net.shadowfacts.phycon.util
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import kotlin.reflect.KMutableProperty
/**
* @author shadowfacts
*/
class GhostSlot(prop: KMutableProperty<ItemStack>, x: Int, y: Int): Slot(GhostInv(prop), 0, x, y) {
override fun canInsert(stack: ItemStack) = false
override fun setStack(itemStack: ItemStack?) {
}
override fun canTakeItems(player: PlayerEntity) = false
class GhostInv(private val prop: KMutableProperty<ItemStack>): Inventory {
override fun clear() {
prop.setter.call(ItemStack.EMPTY)
}
override fun size() = 1
override fun isEmpty() = prop.getter.call().isEmpty
override fun getStack(i: Int): ItemStack {
return if (i == 0) prop.getter.call()
else ItemStack.EMPTY
}
override fun removeStack(i: Int, j: Int) = ItemStack.EMPTY
override fun removeStack(i: Int) = ItemStack.EMPTY
override fun setStack(i: Int, itemStack: ItemStack) {}
override fun markDirty() {}
override fun canPlayerUse(playerEntity: PlayerEntity?) = true
}
}