mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-04-21 10:13:19 +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:
parent
81aaead032
commit
a95893b823
src/main/java/dan200/computercraft/shared
@ -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());
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user