-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite networking system to fix environment error on servers
- Loading branch information
1 parent
3e70ace
commit 22a9206
Showing
19 changed files
with
154 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
Common/src/main/kotlin/gay/object/hexdebug/networking/HexDebugMessageCompanion.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Common/src/main/kotlin/gay/object/hexdebug/networking/handler/ClientMessageHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package gay.`object`.hexdebug.networking.handler | ||
|
||
import at.petrak.hexcasting.api.casting.eval.ExecutionClientView | ||
import dev.architectury.networking.NetworkManager.PacketContext | ||
import gay.`object`.hexdebug.adapter.proxy.DebugProxyClient | ||
import gay.`object`.hexdebug.config.DebuggerDisplayMode | ||
import gay.`object`.hexdebug.config.HexDebugConfig | ||
import gay.`object`.hexdebug.gui.SplicingTableMenu | ||
import gay.`object`.hexdebug.gui.SplicingTableScreen | ||
import gay.`object`.hexdebug.items.ItemDebugger | ||
import gay.`object`.hexdebug.items.ItemDebugger.DebugState | ||
import gay.`object`.hexdebug.items.ItemEvaluator | ||
import gay.`object`.hexdebug.items.ItemEvaluator.EvalState | ||
import gay.`object`.hexdebug.networking.msg.* | ||
import net.minecraft.network.chat.Component | ||
|
||
fun HexDebugMessageS2C.applyOnClient(ctx: PacketContext) { | ||
when (this) { | ||
is MsgDebugAdapterProxy -> { | ||
DebugProxyClient.instance?.consume(content) | ||
} | ||
|
||
is MsgDebuggerStateS2C -> { | ||
ItemDebugger.debugState = debuggerState | ||
if (debuggerState == DebugState.NOT_DEBUGGING) { | ||
ItemEvaluator.evalState = EvalState.DEFAULT | ||
} | ||
} | ||
|
||
is MsgEvaluatorStateS2C -> { | ||
ItemEvaluator.evalState = evalState | ||
} | ||
|
||
is MsgPrintDebuggerStatusS2C -> { | ||
val config = HexDebugConfig.get().client | ||
val shouldPrint = when (config.debuggerDisplayMode) { | ||
DebuggerDisplayMode.DISABLED -> false | ||
DebuggerDisplayMode.NOT_CONNECTED -> !isConnected | ||
DebuggerDisplayMode.ENABLED -> true | ||
} | ||
|
||
if (shouldPrint) { | ||
ctx.player.displayClientMessage( | ||
Component.translatable( | ||
"text.hexdebug.debugger_stopped", | ||
if (config.showDebugClientLineNumber) line else index, | ||
iota, | ||
), | ||
true, | ||
) | ||
} | ||
} | ||
|
||
is MsgSplicingTableNewDataS2C -> { | ||
SplicingTableMenu.getInstance(ctx.player)?.also { menu -> | ||
menu.clientView = data | ||
SplicingTableScreen.getInstance()?.updateButtons() | ||
} | ||
} | ||
|
||
is MsgSplicingTableNewSelectionS2C -> { | ||
SplicingTableScreen.getInstance()?.selection = selection | ||
} | ||
|
||
is MsgSplicingTableNewStaffPatternS2C -> { | ||
val info = ExecutionClientView(false, resolutionType, listOf(), null) | ||
SplicingTableScreen.getInstance()?.guiSpellcasting?.recvServerUpdate(info, index) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Common/src/main/kotlin/gay/object/hexdebug/networking/handler/ServerMessageHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gay.`object`.hexdebug.networking.handler | ||
|
||
import dev.architectury.networking.NetworkManager.PacketContext | ||
import gay.`object`.hexdebug.adapter.DebugAdapterManager | ||
import gay.`object`.hexdebug.gui.SplicingTableMenu | ||
import gay.`object`.hexdebug.networking.msg.* | ||
import net.minecraft.server.level.ServerPlayer | ||
|
||
fun HexDebugMessageC2S.applyOnServer(ctx: PacketContext) { | ||
val player = ctx.player as ServerPlayer | ||
when (this) { | ||
is MsgDebugAdapterProxy -> { | ||
DebugAdapterManager[ctx.player]?.launcher?.handleMessage(content) | ||
} | ||
|
||
is MsgSplicingTableActionC2S -> { | ||
val menu = SplicingTableMenu.getInstance(ctx.player) ?: return | ||
val newSelection = menu.table.runAction(action, ctx.player as? ServerPlayer, selection) | ||
MsgSplicingTableNewSelectionS2C(newSelection).sendToPlayer(ctx.player as ServerPlayer) | ||
} | ||
|
||
is MsgSplicingTableGetDataC2S -> { | ||
SplicingTableMenu.getInstance(ctx.player)?.sendData(ctx.player as ServerPlayer) | ||
} | ||
|
||
is MsgSplicingTableNewStaffPatternC2S -> { | ||
val menu = SplicingTableMenu.getInstance(player) ?: return | ||
val (newSelection, resolutionType) = menu.table.drawPattern(player, pattern, index, selection) | ||
MsgSplicingTableNewSelectionS2C(newSelection).sendToPlayer(player) | ||
MsgSplicingTableNewStaffPatternS2C(resolutionType, index).sendToPlayer(player) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Common/src/main/kotlin/gay/object/hexdebug/networking/msg/MsgDebugAdapterProxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gay.`object`.hexdebug.networking.msg | ||
|
||
import net.minecraft.network.FriendlyByteBuf | ||
|
||
data class MsgDebugAdapterProxy(val content: String) : HexDebugMessageC2S, HexDebugMessageS2C { | ||
companion object : HexDebugMessageCompanion<MsgDebugAdapterProxy> { | ||
override val type = MsgDebugAdapterProxy::class.java | ||
|
||
override fun decode(buf: FriendlyByteBuf) = MsgDebugAdapterProxy( | ||
buf.readUtf(), | ||
) | ||
|
||
override fun MsgDebugAdapterProxy.encode(buf: FriendlyByteBuf) { | ||
buf.writeUtf(content) | ||
} | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
Common/src/main/kotlin/gay/object/hexdebug/networking/msg/MsgDebugAdapterProxyC2S.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
Common/src/main/kotlin/gay/object/hexdebug/networking/msg/MsgDebugAdapterProxyS2C.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.