45 lines
1.5 KiB
Kotlin
45 lines
1.5 KiB
Kotlin
package tf.bug.monadmachines.block
|
|
|
|
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry
|
|
import net.minecraft.entity.player.PlayerEntity
|
|
import net.minecraft.entity.player.PlayerInventory
|
|
import net.minecraft.inventory.Inventory
|
|
import net.minecraft.inventory.SimpleInventory
|
|
import net.minecraft.screen.ScreenHandler
|
|
import net.minecraft.screen.ScreenHandlerType
|
|
import net.minecraft.screen.slot.Slot
|
|
|
|
class ProgramWorkstationScreenHandler(syncId: Int, playerInventory: PlayerInventory, inventory: Inventory) : ScreenHandler(type, syncId) {
|
|
|
|
private val inventory: Inventory
|
|
|
|
init {
|
|
checkSize(inventory, 1)
|
|
this.inventory = inventory
|
|
inventory.onOpen(playerInventory.player)
|
|
|
|
for(m in 0..2) {
|
|
for(l in 0..8) {
|
|
addSlot(Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18))
|
|
}
|
|
}
|
|
}
|
|
|
|
companion object {
|
|
val type: ScreenHandlerType<ProgramWorkstationScreenHandler> =
|
|
ScreenHandlerRegistry.registerSimple(ProgramWorkstationBlock.id) { syncId: Int, playerInventory: PlayerInventory ->
|
|
ProgramWorkstationScreenHandler(
|
|
syncId,
|
|
playerInventory
|
|
)
|
|
}
|
|
}
|
|
|
|
constructor(syncId: Int, playerInventory: PlayerInventory) : this(syncId, playerInventory, SimpleInventory(1))
|
|
|
|
override fun canUse(player: PlayerEntity?): Boolean {
|
|
return this.inventory.canPlayerUse(player)
|
|
}
|
|
|
|
}
|