2023-03-15 21:52:13 +00:00
|
|
|
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-11-06 20:12:32 +00:00
|
|
|
package dan200.computercraft.shared.network.client;
|
|
|
|
|
|
|
|
import dan200.computercraft.shared.command.text.TableBuilder;
|
|
|
|
import dan200.computercraft.shared.computer.core.ComputerState;
|
|
|
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
|
|
|
import dan200.computercraft.shared.computer.upload.UploadResult;
|
2024-03-15 18:25:57 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.speaker.EncodedAudio;
|
2022-11-06 20:12:32 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.sounds.SoundEvent;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The context under which clientbound packets are evaluated.
|
|
|
|
*/
|
|
|
|
public interface ClientNetworkContext {
|
|
|
|
void handleChatTable(TableBuilder table);
|
|
|
|
|
|
|
|
void handleComputerTerminal(int containerId, TerminalState terminal);
|
|
|
|
|
2024-04-25 17:19:34 +00:00
|
|
|
void handleMonitorData(BlockPos pos, @Nullable TerminalState terminal);
|
2022-11-06 20:12:32 +00:00
|
|
|
|
|
|
|
void handlePlayRecord(BlockPos pos, @Nullable SoundEvent sound, @Nullable String name);
|
|
|
|
|
2024-04-25 17:19:34 +00:00
|
|
|
void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, @Nullable TerminalState terminal);
|
2022-11-06 20:12:32 +00:00
|
|
|
|
Replace integer instance IDs with UUIDs
Here's a fun bug you can try at home:
- Create a new world
- Spawn in a pocket computer, turn it on, and place it in a chest.
- Reload the world - the pocket computer in the chest should now be
off.
- Spawn in a new pocket computer, and turn it on. The computer in chest
will also appear to be on!
This bug has been present since pocket computers were added (27th March,
2024).
When a pocket computer is added to a player's inventory, it is assigned
a unique *per-session* "instance id" , which is used to find the
associated computer. Note the "per-session" there - these ids will be
reused if you reload the world (or restart the server).
In the above bug, we see the following:
- The first pocket computer is assigned an instance id of 0.
- After reloading, the second pocket computer is assigned an instance
id of 0.
- If the first pocket computer was in our inventory, it'd be ticked and
assigned a new instance id. However, because it's in an inventory, it
keeps its old one.
- Both computers look up their client-side computer state and get the
same value, meaning the first pocket computer mirrors the second!
To fix this, we now ensure instance ids are entirely unique (not just
per-session). Rather than sequentially assigning an int, we now use a
random UUID (we probably could get away with a random long, but this
feels more idiomatic).
This has a couple of user-visible changes:
- /computercraft no longer lists instance ids outside of dumping an
individual computer.
- The @c[instance=...] selector uses UUIDs. We still use int instance
ids for the legacy selector, but that'll be removed in a later MC
version.
- Pocket computers now store a UUID rather than an int.
Related to this change (I made this change first, but then they got
kinda mixed up together), we now only create PocketComputerData when
receiving server data. This makes the code a little uglier in some
places (the data may now be null), but means we don't populate the
client-side pocket computer map with computers the server doesn't know
about.
2024-03-17 12:21:21 +00:00
|
|
|
void handlePocketComputerDeleted(UUID instanceId);
|
2022-11-06 20:12:32 +00:00
|
|
|
|
2024-03-15 18:25:57 +00:00
|
|
|
void handleSpeakerAudio(UUID source, SpeakerPosition.Message position, float volume, EncodedAudio audio);
|
2022-11-06 20:12:32 +00:00
|
|
|
|
|
|
|
void handleSpeakerMove(UUID source, SpeakerPosition.Message position);
|
|
|
|
|
|
|
|
void handleSpeakerPlay(UUID source, SpeakerPosition.Message position, ResourceLocation sound, float volume, float pitch);
|
|
|
|
|
|
|
|
void handleSpeakerStop(UUID source);
|
|
|
|
|
2022-11-09 18:58:31 +00:00
|
|
|
void handleUploadResult(int containerId, UploadResult result, @Nullable Component errorMessage);
|
2022-11-06 20:12:32 +00:00
|
|
|
}
|