Get rid of client/server fields in networked inputs
because they don't make sense anyway
This commit is contained in:
parent
feb1f8d9d6
commit
bbe4e0ccad
@ -35,7 +35,7 @@ class MatterBottlerScreen(menu: MatterBottlerMenu, inventory: Inventory, title:
|
|||||||
|
|
||||||
if (minecraft?.player?.isSpectator != true) {
|
if (minecraft?.player?.isSpectator != true) {
|
||||||
val mode = ButtonPanel(this, frame, 46f, 69f, 100f, 20f, TranslatableComponent("otm.matter_bottler.switch_mode"))
|
val mode = ButtonPanel(this, frame, 46f, 69f, 100f, 20f, TranslatableComponent("otm.matter_bottler.switch_mode"))
|
||||||
mode.bind { menu.workFlow.switchValue(minecraft?.player) }
|
mode.bind { menu.workFlow.switchValue() }
|
||||||
}
|
}
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
@ -23,6 +23,6 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
widget.input(!checked, minecraft.player)
|
widget.input(!checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.TextInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.TextInputPanel
|
||||||
import ru.dbotthepony.mc.otm.menu.input.AbstractNetworkedInput
|
import ru.dbotthepony.mc.otm.menu.input.AbstractNetworkedInput
|
||||||
import ru.dbotthepony.mc.otm.menu.input.NetworkedStringInput
|
|
||||||
import ru.dbotthepony.mc.otm.milliTime
|
import ru.dbotthepony.mc.otm.milliTime
|
||||||
|
|
||||||
open class NetworkedStringInputPanel<out S : Screen>(
|
open class NetworkedStringInputPanel<out S : Screen>(
|
||||||
@ -17,13 +16,13 @@ open class NetworkedStringInputPanel<out S : Screen>(
|
|||||||
height: Float = 11f,
|
height: Float = 11f,
|
||||||
) : TextInputPanel<S>(screen, parent, x, y, width, height) {
|
) : TextInputPanel<S>(screen, parent, x, y, width, height) {
|
||||||
override var isActive: Boolean
|
override var isActive: Boolean
|
||||||
get() = backend.checkClient()
|
get() = backend.check()
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
override fun onFocusChanged(new: Boolean, old: Boolean) {
|
override fun onFocusChanged(new: Boolean, old: Boolean) {
|
||||||
super.onFocusChanged(new, old)
|
super.onFocusChanged(new, old)
|
||||||
|
|
||||||
if (new && !backend.checkClient()) {
|
if (new && !backend.check()) {
|
||||||
killFocus()
|
killFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,7 +31,7 @@ open class NetworkedStringInputPanel<out S : Screen>(
|
|||||||
|
|
||||||
override fun onTextChanged(old: String, new: String) {
|
override fun onTextChanged(old: String, new: String) {
|
||||||
lastChanges = milliTime + 1000L
|
lastChanges = milliTime + 1000L
|
||||||
backend.clientInput(new)
|
backend.input(new)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
|
@ -72,14 +72,6 @@ class DriveViewerMenu @JvmOverloads constructor(
|
|||||||
val matchTag = NetworkedBooleanInput(this)
|
val matchTag = NetworkedBooleanInput(this)
|
||||||
val matchNBT = NetworkedBooleanInput(this)
|
val matchNBT = NetworkedBooleanInput(this)
|
||||||
|
|
||||||
init {
|
|
||||||
if (tile == null) {
|
|
||||||
isWhitelist.isClient = true
|
|
||||||
matchTag.isClient = true
|
|
||||||
matchNBT.isClient = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun broadcastChanges() {
|
override fun broadcastChanges() {
|
||||||
super.broadcastChanges()
|
super.broadcastChanges()
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class HoloSignMenu @JvmOverloads constructor(
|
|||||||
inventory: Inventory,
|
inventory: Inventory,
|
||||||
tile: HoloSignBlockEntity? = null
|
tile: HoloSignBlockEntity? = null
|
||||||
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
|
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
|
||||||
val text = if (tile != null) NetworkedStringInput(this, tile::text) else NetworkedStringInput(this).asClient()
|
val text = if (tile != null) NetworkedStringInput(this, tile::text) else NetworkedStringInput(this)
|
||||||
|
|
||||||
override val storageSlots: Collection<Slot>
|
override val storageSlots: Collection<Slot>
|
||||||
get() = listOf()
|
get() = listOf()
|
||||||
|
@ -35,7 +35,6 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
|||||||
progressWidget = ProgressGaugeWidget(this)
|
progressWidget = ProgressGaugeWidget(this)
|
||||||
matterWidget = LevelGaugeWidget(this)
|
matterWidget = LevelGaugeWidget(this)
|
||||||
workFlow = NetworkedBooleanInput(this)
|
workFlow = NetworkedBooleanInput(this)
|
||||||
workFlow.asClient()
|
|
||||||
} else {
|
} else {
|
||||||
progressWidget = ProgressGaugeWidget(this) { tile.getWorkProgress() }
|
progressWidget = ProgressGaugeWidget(this) { tile.getWorkProgress() }
|
||||||
matterWidget = LevelGaugeWidget(this, tile.matter)
|
matterWidget = LevelGaugeWidget(this, tile.matter)
|
||||||
|
@ -24,7 +24,6 @@ class StorageBusMenu @JvmOverloads constructor(
|
|||||||
} else {
|
} else {
|
||||||
busFilterSlots = addFilterSlots(StorageBusBlockEntity.MAX_FILTERS)
|
busFilterSlots = addFilterSlots(StorageBusBlockEntity.MAX_FILTERS)
|
||||||
busFilterState = NetworkedBooleanInput(this)
|
busFilterState = NetworkedBooleanInput(this)
|
||||||
busFilterState.asClient()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addInventorySlots()
|
addInventorySlots()
|
||||||
|
@ -24,7 +24,6 @@ class StorageExporterMenu @JvmOverloads constructor(
|
|||||||
} else {
|
} else {
|
||||||
busFilterSlots = addFilterSlots(StorageExporterBlockEntity.MAX_FILTERS)
|
busFilterSlots = addFilterSlots(StorageExporterBlockEntity.MAX_FILTERS)
|
||||||
busFilterState = NetworkedBooleanInput(this)
|
busFilterState = NetworkedBooleanInput(this)
|
||||||
busFilterState.asClient()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addInventorySlots()
|
addInventorySlots()
|
||||||
|
@ -24,7 +24,6 @@ class StorageImporterMenu @JvmOverloads constructor(
|
|||||||
} else {
|
} else {
|
||||||
busFilterSlots = addFilterSlots(StorageImporterBlockEntity.MAX_FILTERS)
|
busFilterSlots = addFilterSlots(StorageImporterBlockEntity.MAX_FILTERS)
|
||||||
busFilterState = NetworkedBooleanInput(this)
|
busFilterState = NetworkedBooleanInput(this)
|
||||||
busFilterState.asClient()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addInventorySlots()
|
addInventorySlots()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.dbotthepony.mc.otm.menu.input
|
package ru.dbotthepony.mc.otm.menu.input
|
||||||
|
|
||||||
import net.minecraft.world.entity.player.Player
|
|
||||||
import ru.dbotthepony.mc.otm.client.minecraft
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
import ru.dbotthepony.mc.otm.menu.MatteryMenu
|
||||||
import kotlin.reflect.KMutableProperty0
|
import kotlin.reflect.KMutableProperty0
|
||||||
@ -9,15 +8,6 @@ abstract class AbstractNetworkedInput<V> {
|
|||||||
abstract val input: MatteryMenu.PlayerInput<V>
|
abstract val input: MatteryMenu.PlayerInput<V>
|
||||||
abstract val value: V
|
abstract val value: V
|
||||||
|
|
||||||
var isClient = false
|
|
||||||
|
|
||||||
fun asClient(): AbstractNetworkedInput<V> {
|
|
||||||
isClient = true
|
|
||||||
supplier = null
|
|
||||||
consumer = null
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var supplier: (() -> V)? = null
|
var supplier: (() -> V)? = null
|
||||||
var consumer: ((V) -> Unit)? = null
|
var consumer: ((V) -> Unit)? = null
|
||||||
|
|
||||||
@ -43,21 +33,14 @@ abstract class AbstractNetworkedInput<V> {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun input(newValue: V, ply: Player? = null) {
|
/**
|
||||||
if (isClient) {
|
* shortcut to checked input of [input]
|
||||||
input.checkedInput(newValue, ply)
|
*/
|
||||||
} else {
|
fun input(newValue: V) {
|
||||||
consumer?.invoke(newValue)
|
input.checkedInput(newValue, minecraft.player)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clientInput(newValue: V) {
|
fun check(): Boolean {
|
||||||
if (isClient) {
|
|
||||||
input.checkedInput(newValue, minecraft.player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkClient(): Boolean {
|
|
||||||
return input.allowSpectators || minecraft.player?.isSpectator == false
|
return input.allowSpectators || minecraft.player?.isSpectator == false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class NetworkedBooleanInput(menu: MatteryMenu) : AbstractNetworkedInput<Boolean>
|
|||||||
with(state)
|
with(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun switchValue(ply: Player? = null) {
|
fun switchValue() {
|
||||||
input(!value, ply)
|
input(!value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user