mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-28 18:04:47 +00:00
Add support for viewing arbitrary computers in a GUI
Important terminal (such as terminal size) is packed into the the coordinate fields.
This commit is contained in:
parent
4e9034f910
commit
04590befb3
@ -23,12 +23,15 @@ import dan200.computercraft.core.apis.AddressPredicate;
|
||||
import dan200.computercraft.core.filesystem.ComboMount;
|
||||
import dan200.computercraft.core.filesystem.FileMount;
|
||||
import dan200.computercraft.core.filesystem.JarMount;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.command.CommandComputer;
|
||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
||||
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||
@ -108,6 +111,7 @@ public class ComputerCraft
|
||||
// ComputerCraftEdu uses ID 104
|
||||
public static final int printoutGUIID = 105;
|
||||
public static final int pocketComputerGUIID = 106;
|
||||
public static final int viewComputerGUIID = 110;
|
||||
|
||||
// Configuration options
|
||||
private static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
||||
@ -519,6 +523,24 @@ public class ComputerCraft
|
||||
player.openGui( ComputerCraft.instance, ComputerCraft.pocketComputerGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 );
|
||||
}
|
||||
|
||||
public static void openComputerGUI( EntityPlayer player, ServerComputer computer )
|
||||
{
|
||||
ComputerFamily family = computer.getFamily();
|
||||
int width = 0, height = 0;
|
||||
Terminal terminal = computer.getTerminal();
|
||||
if( terminal != null )
|
||||
{
|
||||
width = terminal.getWidth();
|
||||
height = terminal.getHeight();
|
||||
}
|
||||
|
||||
// Pack useful terminal information into the various coordinate bits.
|
||||
// These are extracted in ComputerCraftProxyCommon.getClientGuiElement
|
||||
player.openGui( ComputerCraft.instance, ComputerCraft.viewComputerGUIID, player.getEntityWorld(),
|
||||
computer.getInstanceID(), family.ordinal(), (width & 0xFFFF) << 16 | (height & 0xFFFF)
|
||||
);
|
||||
}
|
||||
|
||||
public static File getBaseDir()
|
||||
{
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getFile(".");
|
||||
|
@ -33,7 +33,7 @@ public class GuiComputer extends GuiContainer
|
||||
private final int m_termHeight;
|
||||
private WidgetTerminal m_terminal;
|
||||
|
||||
protected GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
|
||||
public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
|
||||
{
|
||||
super( container );
|
||||
m_family = family;
|
||||
|
@ -12,10 +12,12 @@ import dan200.computercraft.client.render.ItemPocketRenderer;
|
||||
import dan200.computercraft.client.render.RenderOverlayCable;
|
||||
import dan200.computercraft.client.render.TileEntityCableRenderer;
|
||||
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||
import dan200.computercraft.shared.command.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.ComputerState;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||
@ -364,6 +366,13 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family )
|
||||
{
|
||||
ContainerViewComputer container = new ContainerViewComputer( computer );
|
||||
return new GuiComputer( container, family, computer, width, height );
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldDir( World world )
|
||||
{
|
||||
|
@ -8,6 +8,8 @@ package dan200.computercraft.server.proxy;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
@ -97,6 +99,12 @@ public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getWorldDir( World world )
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.core.computer.MainThread;
|
||||
import dan200.computercraft.shared.command.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.common.ColourableRecipe;
|
||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
@ -17,10 +18,7 @@ import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.core.*;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
@ -184,6 +182,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
@Override
|
||||
public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
|
||||
|
||||
@Override
|
||||
public abstract Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family );
|
||||
|
||||
@Override
|
||||
public abstract File getWorldDir( World world );
|
||||
|
||||
@ -553,6 +554,11 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
{
|
||||
return new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
|
||||
}
|
||||
case ComputerCraft.viewComputerGUIID:
|
||||
{
|
||||
ServerComputer computer = ComputerCraft.serverComputerRegistry.get( x );
|
||||
return computer == null ? null : new ContainerViewComputer( computer );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -611,6 +617,27 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
{
|
||||
return getPocketComputerGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
|
||||
}
|
||||
case ComputerCraft.viewComputerGUIID:
|
||||
{
|
||||
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( x );
|
||||
|
||||
// We extract some terminal information from the various coordinate flags.
|
||||
// See ComputerCraft.openComputerGUI for how they are packed.
|
||||
ComputerFamily family = ComputerFamily.values()[ y ];
|
||||
int width = (z >> 16) & 0xFFFF, height = z & 0xFF;
|
||||
|
||||
if( computer == null )
|
||||
{
|
||||
computer = new ClientComputer( x );
|
||||
ComputerCraft.clientComputerRegistry.add( x, computer );
|
||||
}
|
||||
else if( computer.getTerminal() != null )
|
||||
{
|
||||
width = computer.getTerminal().getWidth();
|
||||
height = computer.getTerminal().getHeight();
|
||||
}
|
||||
return getComputerGUI( computer, width, height, family );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
package dan200.computercraft.shared.proxy;
|
||||
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
import dan200.computercraft.shared.network.ComputerCraftPacket;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||
@ -42,6 +44,7 @@ public interface IComputerCraftProxy
|
||||
Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
|
||||
Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
|
||||
Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
|
||||
Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family );
|
||||
|
||||
File getWorldDir( World world );
|
||||
void handlePacket( ComputerCraftPacket packet, EntityPlayer player );
|
||||
|
Loading…
Reference in New Issue
Block a user