Fix crash when opening Inserter/Redstone Emitter GUI in non-dev env
This commit is contained in:
parent
84e2c6d6e9
commit
2466923d96
|
@ -19,6 +19,7 @@ import net.shadowfacts.phycon.init.PhyBlockEntities
|
|||
import net.shadowfacts.phycon.packet.*
|
||||
import net.shadowfacts.phycon.util.ActivationMode
|
||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
||||
import net.shadowfacts.phycon.util.GhostInv
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
|
@ -27,7 +28,8 @@ import kotlin.math.min
|
|||
class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
||||
ItemStackPacketHandler,
|
||||
ActivationController.ActivatableDevice,
|
||||
ClientConfigurableDevice {
|
||||
ClientConfigurableDevice,
|
||||
GhostInv {
|
||||
|
||||
companion object {
|
||||
val SLEEP_TIME = 40L
|
||||
|
@ -40,6 +42,9 @@ class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
|||
private var inventory: ItemInsertable? = null
|
||||
private var currentRequest: PendingExtractRequest? = null
|
||||
var stackToExtract: ItemStack = ItemStack.EMPTY
|
||||
override var ghostSlotStack: ItemStack
|
||||
get() = stackToExtract
|
||||
set(value) { stackToExtract = value }
|
||||
var amountToExtract = 1
|
||||
override val controller = ActivationController(SLEEP_TIME, this)
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class InserterScreenHandler(
|
|||
|
||||
init {
|
||||
// fake slot
|
||||
addSlot(GhostSlot(inserter::stackToExtract, 31, 20))
|
||||
addSlot(GhostSlot(inserter, 31, 20))
|
||||
|
||||
// player inv
|
||||
for (y in 0 until 3) {
|
||||
|
|
|
@ -13,19 +13,24 @@ import net.shadowfacts.phycon.packet.DeviceRemovedPacket
|
|||
import net.shadowfacts.phycon.packet.ReadInventoryPacket
|
||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
||||
import net.shadowfacts.phycon.util.GhostInv
|
||||
import kotlin.math.round
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EMITTER),
|
||||
ClientConfigurableDevice {
|
||||
ClientConfigurableDevice,
|
||||
GhostInv {
|
||||
|
||||
private val inventoryCache = mutableMapOf<IPAddress, GroupedItemInvView>()
|
||||
var cachedEmittedPower: Int = 0
|
||||
private set
|
||||
|
||||
var stackToMonitor: ItemStack = ItemStack.EMPTY
|
||||
override var ghostSlotStack: ItemStack
|
||||
get() = stackToMonitor
|
||||
set(value) { stackToMonitor = value }
|
||||
var maxAmount = 64
|
||||
var mode = Mode.ANALOG
|
||||
set(value) {
|
||||
|
|
|
@ -36,7 +36,7 @@ class RedstoneEmitterScreenHandler(
|
|||
|
||||
init {
|
||||
// fake slot
|
||||
addSlot(GhostSlot(emitter::stackToMonitor, 31, 20))
|
||||
addSlot(GhostSlot(emitter, 31, 20))
|
||||
|
||||
// player inv
|
||||
for (y in 0 until 3) {
|
||||
|
|
|
@ -4,12 +4,11 @@ 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) {
|
||||
class GhostSlot(inv: net.shadowfacts.phycon.util.GhostInv, x: Int, y: Int): Slot(GhostInv(inv), 0, x, y) {
|
||||
|
||||
override fun canInsert(stack: ItemStack) = false
|
||||
|
||||
|
@ -18,17 +17,17 @@ class GhostSlot(prop: KMutableProperty<ItemStack>, x: Int, y: Int): Slot(GhostIn
|
|||
|
||||
override fun canTakeItems(player: PlayerEntity) = false
|
||||
|
||||
class GhostInv(private val prop: KMutableProperty<ItemStack>): Inventory {
|
||||
private class GhostInv(private val inv: net.shadowfacts.phycon.util.GhostInv): Inventory {
|
||||
override fun clear() {
|
||||
prop.setter.call(ItemStack.EMPTY)
|
||||
inv.ghostSlotStack = ItemStack.EMPTY
|
||||
}
|
||||
|
||||
override fun size() = 1
|
||||
|
||||
override fun isEmpty() = prop.getter.call().isEmpty
|
||||
override fun isEmpty() = inv.ghostSlotStack.isEmpty
|
||||
|
||||
override fun getStack(i: Int): ItemStack {
|
||||
return if (i == 0) prop.getter.call()
|
||||
return if (i == 0) inv.ghostSlotStack
|
||||
else ItemStack.EMPTY
|
||||
}
|
||||
|
||||
|
@ -43,3 +42,7 @@ class GhostSlot(prop: KMutableProperty<ItemStack>, x: Int, y: Int): Slot(GhostIn
|
|||
override fun canPlayerUse(playerEntity: PlayerEntity?) = true
|
||||
}
|
||||
}
|
||||
|
||||
interface GhostInv {
|
||||
var ghostSlotStack: ItemStack
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue