1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-27 16:02:17 +00:00

Fix two bugs with monitors on dedicated server (#45).

- ClientMonitors were being created on the server. This caused a crash
when TileMonitors unload and attempt to clean up their client side
buffers because the method to do that only exists on the client. We
don't have the split semantics of load and handleUpdateTag that forge
has, so our TileMonitor#load method has to do double duty and check if
the level is client side before doing client side stuff.
- Monitor contents were never sent to clients connected to a dedicated
server because MonitorWatcher was never initialized on the dedicated
server! (My bad...) To fix, I moved its initialization to the common
setup.
This commit is contained in:
Toad-Dev 2021-12-25 22:30:51 -08:00
parent cc08eced48
commit af6a240c09
4 changed files with 17 additions and 42 deletions

View File

@ -23,7 +23,6 @@ import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
@ -76,7 +75,6 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
public void onInitializeClient()
{
FrameInfo.init();
MonitorWatcher.init();
registerContainers();
// While turtles themselves are not transparent, their upgrades may be.

View File

@ -5,7 +5,7 @@
*/
package dan200.computercraft.fabric.mixin;
import dan200.computercraft.shared.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.fabric.events.ComputerCraftCustomEvents;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
@ -46,7 +46,7 @@ public class MixinChunkMap
@Inject( method = "playerLoadedChunk", at = @At( value = "HEAD" ) )
private void playerLoadedChunk( ServerPlayer serverPlayer, MutableObject<ClientboundLevelChunkWithLightPacket> mutableObject, LevelChunk levelChunk, CallbackInfo ci )
{
MonitorWatcher.onWatch( serverPlayer, levelChunk.getPos() );
ComputerCraftCustomEvents.SERVER_PLAYER_LOADED_CHUNK_EVENT.invoker().onServerPlayerLoadedChunk( serverPlayer, levelChunk.getPos() );
}
}

View File

@ -145,49 +145,24 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
width = nbt.getInt( NBT_WIDTH );
height = nbt.getInt( NBT_HEIGHT );
if( oldXIndex != xIndex || oldYIndex != yIndex )
if( level != null && level.isClientSide )
{
// If our index has changed then it's possible the origin monitor has changed. Thus
// we'll clear our cache. If we're the origin then we'll need to remove the glList as well.
if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy();
clientMonitor = null;
}
if( oldXIndex != xIndex || oldYIndex != yIndex )
{
// If our index has changed then it's possible the origin monitor has changed. Thus
// we'll clear our cache. If we're the origin then we'll need to remove the glList as well.
if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy();
clientMonitor = null;
}
if( xIndex == 0 && yIndex == 0 )
{
// If we're the origin terminal then create it.
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
if( xIndex == 0 && yIndex == 0 )
{
// If we're the origin terminal then create it.
if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
}
}
}
// @Override
// public final void handleUpdateTag( @Nonnull CompoundTag nbt )
// {
// super.handleUpdateTag( nbt );
//
// int oldXIndex = xIndex;
// int oldYIndex = yIndex;
//
// xIndex = nbt.getInt( NBT_X );
// yIndex = nbt.getInt( NBT_Y );
// width = nbt.getInt( NBT_WIDTH );
// height = nbt.getInt( NBT_HEIGHT );
//
// if( oldXIndex != xIndex || oldYIndex != yIndex )
// {
// // If our index has changed then it's possible the origin monitor has changed. Thus
// // we'll clear our cache. If we're the origin then we'll need to remove the glList as well.
// if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy();
// clientMonitor = null;
// }
//
// if( xIndex == 0 && yIndex == 0 )
// {
// // If we're the origin terminal then create it.
// if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
// }
// }
@Override
public void blockTick()
{

View File

@ -27,6 +27,7 @@ import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeriphera
import dan200.computercraft.shared.peripheral.generic.methods.InventoryMethods;
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.shared.turtle.FurnaceRefuelHandler;
import dan200.computercraft.shared.util.Config;
import dan200.computercraft.shared.util.TickScheduler;
@ -51,6 +52,7 @@ public final class ComputerCraftProxyCommon
public static void init()
{
NetworkHandler.setup();
MonitorWatcher.init();
registerProviders();
registerHandlers();