mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-10 14:25:59 +00:00
Fix computer and monitor syncing.
This commit is contained in:
@@ -61,7 +61,6 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer<TileMonitor>
|
||||
public void render( @Nonnull TileMonitor monitor, float partialTicks, @Nonnull MatrixStack transform, @Nonnull VertexConsumerProvider renderer, int lightmapCoord, int overlayLight )
|
||||
{
|
||||
// Render from the origin monitor
|
||||
// TODO Figure out why this is null.
|
||||
ClientMonitor originTerminal = monitor.getClientMonitor();
|
||||
|
||||
if( originTerminal == null ) return;
|
||||
|
@@ -7,6 +7,7 @@ package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.network.client.TerminalState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientTerminal implements ITerminal
|
||||
{
|
||||
@@ -56,6 +57,17 @@ public class ClientTerminal implements ITerminal
|
||||
}
|
||||
}
|
||||
|
||||
public void readDescription(CompoundTag nbt) {
|
||||
this.m_colour = nbt.getBoolean("colour");
|
||||
if (nbt.contains("terminal")) {
|
||||
CompoundTag terminal = nbt.getCompound("terminal");
|
||||
this.resizeTerminal(terminal.getInt("term_width"), terminal.getInt("term_height"));
|
||||
this.m_terminal.readFromNBT(terminal);
|
||||
} else {
|
||||
this.deleteTerminal();
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeTerminal( int width, int height )
|
||||
{
|
||||
if( m_terminal == null )
|
||||
|
@@ -7,6 +7,7 @@ package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.network.client.TerminalState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -82,4 +83,15 @@ public class ServerTerminal implements ITerminal
|
||||
{
|
||||
return new TerminalState( m_colour, m_terminal );
|
||||
}
|
||||
|
||||
public void writeDescription(CompoundTag nbt) {
|
||||
nbt.putBoolean("colour", this.m_colour);
|
||||
if (this.m_terminal != null) {
|
||||
CompoundTag terminal = new CompoundTag();
|
||||
terminal.putInt("term_width", this.m_terminal.getWidth());
|
||||
terminal.putInt("term_height", this.m_terminal.getHeight());
|
||||
this.m_terminal.writeToNBT(terminal);
|
||||
nbt.put("terminal", terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -80,15 +80,6 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final BlockEntityUpdateS2CPacket toUpdatePacket()
|
||||
{
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
writeDescription( nbt );
|
||||
return new BlockEntityUpdateS2CPacket( pos, 0, nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toClientTag(CompoundTag compoundTag) {
|
||||
writeDescription(compoundTag);
|
||||
@@ -99,13 +90,4 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie
|
||||
public void fromClientTag(CompoundTag compoundTag) {
|
||||
readDescription(compoundTag);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompoundTag toInitialChunkDataTag()
|
||||
{
|
||||
CompoundTag tag = super.toInitialChunkDataTag();
|
||||
writeDescription( tag );
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
@@ -121,6 +121,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
if( !getWorld().isClient && isUsable( player, false ) )
|
||||
{
|
||||
createServerComputer().turnOn();
|
||||
createServerComputer().sendTerminalState(player);
|
||||
new ComputerContainerData( createServerComputer() ).open( player, this );
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
|
@@ -34,8 +34,6 @@ public enum MonitorRenderer
|
||||
|
||||
/**
|
||||
* Render using VBOs.
|
||||
*
|
||||
* @see net.minecraft.client.renderer.vertex.VertexBuffer
|
||||
*/
|
||||
VBO;
|
||||
|
||||
|
@@ -244,6 +244,10 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
nbt.putInt( NBT_Y, m_yIndex );
|
||||
nbt.putInt( NBT_WIDTH, m_width );
|
||||
nbt.putInt( NBT_HEIGHT, m_height );
|
||||
|
||||
if (this.m_xIndex == 0 && this.m_yIndex == 0 && this.m_serverMonitor != null) {
|
||||
this.m_serverMonitor.writeDescription(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,6 +277,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
// If we're the origin terminal then create it.
|
||||
if( m_clientMonitor == null ) m_clientMonitor = new ClientMonitor( advanced, this );
|
||||
m_clientMonitor.readDescription(nbt);
|
||||
}
|
||||
|
||||
if( oldXIndex != m_xIndex || oldYIndex != m_yIndex ||
|
||||
|
@@ -156,6 +156,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
|
||||
if( !stop && computer != null )
|
||||
{
|
||||
computer.sendTerminalState(player);
|
||||
new ComputerContainerData( computer ).open( player, new ContainerPocketComputer.Factory( computer, stack, this, hand ) );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user