From bbe4e0ccad130605156a00a0170c70955f2aede7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 26 Jan 2023 21:50:50 +0700 Subject: [PATCH] Get rid of client/server fields in networked inputs because they don't make sense anyway --- .../otm/client/screen/MatterBottlerScreen.kt | 2 +- .../panels/buttons/CheckBoxInputPanel.kt | 2 +- .../panels/input/NetworkedStringInputPanel.kt | 7 ++--- .../mc/otm/menu/DriveViewerMenu.kt | 8 ----- .../dbotthepony/mc/otm/menu/HoloSignMenu.kt | 2 +- .../mc/otm/menu/MatterBottlerMenu.kt | 1 - .../dbotthepony/mc/otm/menu/StorageBusMenu.kt | 1 - .../mc/otm/menu/StorageExporterMenu.kt | 1 - .../mc/otm/menu/StorageImporterMenu.kt | 1 - .../otm/menu/input/AbstractNetworkedInput.kt | 29 ++++--------------- .../otm/menu/input/NetworkedBooleanInput.kt | 4 +-- 11 files changed, 14 insertions(+), 44 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatterBottlerScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatterBottlerScreen.kt index 89ea2cff7..60aa8c4c1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatterBottlerScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatterBottlerScreen.kt @@ -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 diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/CheckBoxInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/CheckBoxInputPanel.kt index 016d91545..7213bf4ff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/CheckBoxInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/buttons/CheckBoxInputPanel.kt @@ -23,6 +23,6 @@ open class CheckBoxInputPanel @JvmOverloads constructor( set(value) {} override fun onClick() { - widget.input(!checked, minecraft.player) + widget.input(!checked) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt index b21bd5682..3a88b7b05 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/panels/input/NetworkedStringInputPanel.kt @@ -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( @@ -17,13 +16,13 @@ open class NetworkedStringInputPanel( height: Float = 11f, ) : TextInputPanel(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( override fun onTextChanged(old: String, new: String) { lastChanges = milliTime + 1000L - backend.clientInput(new) + backend.input(new) } override fun tick() { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.kt index 56c538b55..cd32121ae 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/DriveViewerMenu.kt @@ -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() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/HoloSignMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/HoloSignMenu.kt index babf9e1d0..07e36ac5e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/HoloSignMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/HoloSignMenu.kt @@ -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 get() = listOf() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt index 4f19a8041..3f73cd46a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/MatterBottlerMenu.kt @@ -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) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageBusMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageBusMenu.kt index 1ba27a8b0..052ef14c7 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageBusMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageBusMenu.kt @@ -24,7 +24,6 @@ class StorageBusMenu @JvmOverloads constructor( } else { busFilterSlots = addFilterSlots(StorageBusBlockEntity.MAX_FILTERS) busFilterState = NetworkedBooleanInput(this) - busFilterState.asClient() } addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageExporterMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageExporterMenu.kt index adb914d72..eff1d2179 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageExporterMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageExporterMenu.kt @@ -24,7 +24,6 @@ class StorageExporterMenu @JvmOverloads constructor( } else { busFilterSlots = addFilterSlots(StorageExporterBlockEntity.MAX_FILTERS) busFilterState = NetworkedBooleanInput(this) - busFilterState.asClient() } addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageImporterMenu.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageImporterMenu.kt index 28372779a..bcce606d3 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageImporterMenu.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/StorageImporterMenu.kt @@ -24,7 +24,6 @@ class StorageImporterMenu @JvmOverloads constructor( } else { busFilterSlots = addFilterSlots(StorageImporterBlockEntity.MAX_FILTERS) busFilterState = NetworkedBooleanInput(this) - busFilterState.asClient() } addInventorySlots() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt index f37129057..eb15c3794 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/AbstractNetworkedInput.kt @@ -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 { abstract val input: MatteryMenu.PlayerInput abstract val value: V - var isClient = false - - fun asClient(): AbstractNetworkedInput { - isClient = true - supplier = null - consumer = null - return this - } - var supplier: (() -> V)? = null var consumer: ((V) -> Unit)? = null @@ -43,21 +33,14 @@ abstract class AbstractNetworkedInput { 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 } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt index 676636e0b..57a26fa77 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/menu/input/NetworkedBooleanInput.kt @@ -12,7 +12,7 @@ class NetworkedBooleanInput(menu: MatteryMenu) : AbstractNetworkedInput with(state) } - fun switchValue(ply: Player? = null) { - input(!value, ply) + fun switchValue() { + input(!value) } }