1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-28 15:08:47 +00:00

Send the terminal state to the pocket computer's player

As we only send the terminal to players using the GUI, the map interface
was never updated. We now will also send the terminal state to whoever
has the computer in their inventory.

This also marks the terminal as dirty when a new player picks the pocket
computer up, hopefully preventing any desync issues which might occur
then.

Fixes #42.
This commit is contained in:
SquidDev 2018-06-24 19:18:30 +01:00
parent 81aaead032
commit a95893b823
3 changed files with 27 additions and 3 deletions

View File

@ -54,6 +54,11 @@ public class ServerTerminal implements ITerminal
}
}
protected void markTerminalChanged()
{
m_terminalChanged = true;
}
public void update()
{
m_terminalChangedLastFrame = m_terminalChanged || (m_terminal != null && m_terminal.getChanged());

View File

@ -154,7 +154,7 @@ public class ServerComputer extends ServerTerminal
return packet;
}
private ComputerCraftPacket createTerminalPacket() {
protected ComputerCraftPacket createTerminalPacket() {
ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.ComputerTerminalChanged;
packet.m_dataInt = new int[] { getInstanceID() };
@ -465,7 +465,7 @@ public class ServerComputer extends ServerTerminal
}
}
private boolean isInteracting( EntityPlayer player )
protected boolean isInteracting( EntityPlayer player )
{
if( player == null ) return false;

View File

@ -8,6 +8,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -138,7 +139,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
{
if( this.m_upgrade == upgrade ) return;
synchronized (this)
synchronized( this )
{
ComputerCraft.Items.pocketComputer.setUpgrade( m_stack, upgrade );
if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty();
@ -156,6 +157,9 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
setPosition( entity.getPosition() );
}
// If a new entity has picked it up then rebroadcast the terminal to them
if( entity != m_entity && entity instanceof EntityPlayerMP ) markTerminalChanged();
m_entity = entity;
m_stack = stack;
@ -165,4 +169,19 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
invalidatePeripheral();
}
}
public void broadcastState( boolean force )
{
super.broadcastState( force );
if( (hasTerminalChanged() || force) && m_entity instanceof EntityPlayerMP )
{
// Broadcast the state to the current entity if they're not already interacting with it.
EntityPlayerMP player = (EntityPlayerMP) m_entity;
if( player.connection != null && !isInteracting( player ) )
{
ComputerCraft.sendToPlayer( player, createTerminalPacket() );
}
}
}
}