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