1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-29 04:47:39 +00:00

Remove ClientComputer

Historically CC has maintained two computer registries; one on the
server (which runs the actual computer) and one on the client (which
stores the terminal and some small bits of additional data).

This means when a user opens the computer UI, we send the terminal
contents and store it in the client computer registry. We then send the
instance id alongside the "open container" packet, which is used to look
up the client computer (and thus terminal) in our client-side registry.

This patch makes the computer menu syncing behaviour more consistent
with vanilla. The initial terminal contents is sent alongside the "open
container" packet, and subsequent terminal changes apply /just/ to the
open container. Computer on/off state is synced via a vanilla
ContainerData/IIntArray.

Likewise, sending user input to the server now targets the open
container, rather than an arbitrary instance id.

The one remaining usage of ClientComputer is for pocket computers. For
these, we still need to sync the current on/off/blinking state and the
pocket computer light.

We don't need the full ClientComputer interface for this case (after
all, you can't send input to a pocket computer someone else is
holding!). This means we can tear out ClientComputer and
ClientComputerRegistry, replacing it with a much simpler
ClientPocketComputers store.

This in turn allows the following changes:

 - Remove IComputer, as we no longer need to abstract over client and
   server computers.

 - Likewise, we can merge ComputerRegistry into the server
   registry. This commit also cleans up the handling of instance IDs a
   little bit: ServerComputers are now responsible for generating their
   ID and adding/removing themselves from the registry.

 - As the client-side terminal will never be null, we can remove a whole
   bunch of null checks throughout the codebase.

 - As the terminal is available immediately, we don't need to explicitly
   pass in terminal sizes to the computer GUIs. This means we're no
   longer reliant on those config values on the client side!

 - Remove the "request computer state" packet. Pocket computers now
   store which players need to know the computer state, automatically
   sending data when a new player starts tracking the computer.
This commit is contained in:
Jonathan Coates
2022-10-21 18:17:42 +01:00
parent a9b74dc979
commit c49547b962
61 changed files with 1242 additions and 1440 deletions

View File

@@ -37,7 +37,6 @@ import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.container.ComputerContainerData;
import dan200.computercraft.shared.network.container.ContainerData;
import dan200.computercraft.shared.network.container.HeldItemContainerData;
import dan200.computercraft.shared.network.container.ViewComputerContainerData;
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
@@ -306,7 +305,7 @@ public final class Registry
() -> ContainerData.toType( ComputerContainerData::new, ComputerMenuWithoutInventory::new ) );
public static final RegistryObject<ContainerType<ContainerTurtle>> TURTLE = CONTAINERS.register( "turtle",
() -> ContainerData.toType( ComputerContainerData::new, ContainerTurtle::new ) );
() -> ContainerData.toType( ComputerContainerData::new, ContainerTurtle::ofMenuData ) );
public static final RegistryObject<ContainerType<ContainerDiskDrive>> DISK_DRIVE = CONTAINERS.register( "disk_drive",
() -> new ContainerType<>( ContainerDiskDrive::new ) );
@@ -318,7 +317,7 @@ public final class Registry
() -> ContainerData.toType( HeldItemContainerData::new, ContainerHeldItem::createPrintout ) );
public static final RegistryObject<ContainerType<ContainerViewComputer>> VIEW_COMPUTER = CONTAINERS.register( "view_computer",
() -> ContainerData.toType( ViewComputerContainerData::new, ContainerViewComputer::new ) );
() -> ContainerData.toType( ComputerContainerData::new, ContainerViewComputer::new ) );
}
@SubscribeEvent