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) {
|
||||
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
|
||||
|
@ -23,6 +23,6 @@ open class CheckBoxInputPanel<out S : Screen> @JvmOverloads constructor(
|
||||
set(value) {}
|
||||
|
||||
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.TextInputPanel
|
||||
import ru.dbotthepony.mc.otm.menu.input.AbstractNetworkedInput
|
||||
import ru.dbotthepony.mc.otm.menu.input.NetworkedStringInput
|
||||
import ru.dbotthepony.mc.otm.milliTime
|
||||
|
||||
open class NetworkedStringInputPanel<out S : Screen>(
|
||||
@ -17,13 +16,13 @@ open class NetworkedStringInputPanel<out S : Screen>(
|
||||
height: Float = 11f,
|
||||
) : TextInputPanel<S>(screen, parent, x, y, width, height) {
|
||||
override var isActive: Boolean
|
||||
get() = backend.checkClient()
|
||||
get() = backend.check()
|
||||
set(value) {}
|
||||
|
||||
override fun onFocusChanged(new: Boolean, old: Boolean) {
|
||||
super.onFocusChanged(new, old)
|
||||
|
||||
if (new && !backend.checkClient()) {
|
||||
if (new && !backend.check()) {
|
||||
killFocus()
|
||||
}
|
||||
}
|
||||
@ -32,7 +31,7 @@ open class NetworkedStringInputPanel<out S : Screen>(
|
||||
|
||||
override fun onTextChanged(old: String, new: String) {
|
||||
lastChanges = milliTime + 1000L
|
||||
backend.clientInput(new)
|
||||
backend.input(new)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
|
@ -72,14 +72,6 @@ class DriveViewerMenu @JvmOverloads constructor(
|
||||
val matchTag = NetworkedBooleanInput(this)
|
||||
val matchNBT = NetworkedBooleanInput(this)
|
||||
|
||||
init {
|
||||
if (tile == null) {
|
||||
isWhitelist.isClient = true
|
||||
matchTag.isClient = true
|
||||
matchNBT.isClient = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun broadcastChanges() {
|
||||
super.broadcastChanges()
|
||||
|
||||
|
@ -12,7 +12,7 @@ class HoloSignMenu @JvmOverloads constructor(
|
||||
inventory: Inventory,
|
||||
tile: HoloSignBlockEntity? = null
|
||||
) : 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>
|
||||
get() = listOf()
|
||||
|
@ -35,7 +35,6 @@ class MatterBottlerMenu @JvmOverloads constructor(
|
||||
progressWidget = ProgressGaugeWidget(this)
|
||||
matterWidget = LevelGaugeWidget(this)
|
||||
workFlow = NetworkedBooleanInput(this)
|
||||
workFlow.asClient()
|
||||
} else {
|
||||
progressWidget = ProgressGaugeWidget(this) { tile.getWorkProgress() }
|
||||
matterWidget = LevelGaugeWidget(this, tile.matter)
|
||||
|
@ -24,7 +24,6 @@ class StorageBusMenu @JvmOverloads constructor(
|
||||
} else {
|
||||
busFilterSlots = addFilterSlots(StorageBusBlockEntity.MAX_FILTERS)
|
||||
busFilterState = NetworkedBooleanInput(this)
|
||||
busFilterState.asClient()
|
||||
}
|
||||
|
||||
addInventorySlots()
|
||||
|
@ -24,7 +24,6 @@ class StorageExporterMenu @JvmOverloads constructor(
|
||||
} else {
|
||||
busFilterSlots = addFilterSlots(StorageExporterBlockEntity.MAX_FILTERS)
|
||||
busFilterState = NetworkedBooleanInput(this)
|
||||
busFilterState.asClient()
|
||||
}
|
||||
|
||||
addInventorySlots()
|
||||
|
@ -24,7 +24,6 @@ class StorageImporterMenu @JvmOverloads constructor(
|
||||
} else {
|
||||
busFilterSlots = addFilterSlots(StorageImporterBlockEntity.MAX_FILTERS)
|
||||
busFilterState = NetworkedBooleanInput(this)
|
||||
busFilterState.asClient()
|
||||
}
|
||||
|
||||
addInventorySlots()
|
||||
|
@ -1,6 +1,5 @@
|
||||
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.menu.MatteryMenu
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
@ -9,15 +8,6 @@ abstract class AbstractNetworkedInput<V> {
|
||||
abstract val input: MatteryMenu.PlayerInput<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 consumer: ((V) -> Unit)? = null
|
||||
|
||||
@ -43,21 +33,14 @@ abstract class AbstractNetworkedInput<V> {
|
||||
return this
|
||||
}
|
||||
|
||||
fun input(newValue: V, ply: Player? = null) {
|
||||
if (isClient) {
|
||||
input.checkedInput(newValue, ply)
|
||||
} else {
|
||||
consumer?.invoke(newValue)
|
||||
}
|
||||
/**
|
||||
* shortcut to checked input of [input]
|
||||
*/
|
||||
fun input(newValue: V) {
|
||||
input.checkedInput(newValue, minecraft.player)
|
||||
}
|
||||
|
||||
fun clientInput(newValue: V) {
|
||||
if (isClient) {
|
||||
input.checkedInput(newValue, minecraft.player)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkClient(): Boolean {
|
||||
fun check(): Boolean {
|
||||
return input.allowSpectators || minecraft.player?.isSpectator == false
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class NetworkedBooleanInput(menu: MatteryMenu) : AbstractNetworkedInput<Boolean>
|
||||
with(state)
|
||||
}
|
||||
|
||||
fun switchValue(ply: Player? = null) {
|
||||
input(!value, ply)
|
||||
fun switchValue() {
|
||||
input(!value)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user