1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-04 23:40:00 +00:00

Move GUI constructors into the main GUI handler

We use @SideOnly to ensure classes aren't loaded on dedicated servers.

Also a tiny bit of cleanup to change several GUIs just to accept
containers.
This commit is contained in:
SquidDev 2018-12-29 17:13:10 +00:00
parent 929f23fd2d
commit 27aaec9a82
11 changed files with 50 additions and 215 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
/build
/out
/run
/run-*
*.ipr
*.iws
*.iml

View File

@ -7,29 +7,27 @@
package dan200.computercraft.client.gui;
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
public class GuiDiskDrive extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/diskdrive.png" );
private TileDiskDrive m_diskDrive;
private final ContainerDiskDrive m_container;
public GuiDiskDrive( InventoryPlayer inventoryplayer, TileDiskDrive diskDrive )
public GuiDiskDrive( ContainerDiskDrive container )
{
super( new ContainerDiskDrive( inventoryplayer, diskDrive ) );
m_diskDrive = diskDrive;
super( container );
m_container = container;
}
@Override
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
{
String title = m_diskDrive.getDisplayName().getUnformattedText();
String title = m_container.getDiskDrive().getDisplayName().getUnformattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
}

View File

@ -7,31 +7,27 @@
package dan200.computercraft.client.gui;
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
public class GuiPrinter extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
private TilePrinter m_printer;
private ContainerPrinter m_container;
private final ContainerPrinter m_container;
public GuiPrinter( InventoryPlayer inventoryplayer, TilePrinter printer )
public GuiPrinter( ContainerPrinter container )
{
super( new ContainerPrinter( inventoryplayer, printer ) );
m_printer = printer;
m_container = (ContainerPrinter) inventorySlots;
super( container );
m_container = container;
}
@Override
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
{
String title = m_printer.getDisplayName().getUnformattedText();
String title = m_container.getPrinter().getDisplayName().getUnformattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
}

View File

@ -7,7 +7,6 @@
package dan200.computercraft.client.gui;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@ -16,9 +15,7 @@ import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@ -29,27 +26,18 @@ public class GuiTurtle extends GuiContainer
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/turtle.png" );
private static final ResourceLocation backgroundAdvanced = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
protected World m_world;
protected ContainerTurtle m_container;
private ContainerTurtle m_container;
protected final ComputerFamily m_family;
protected final ITurtleAccess m_turtle;
protected final ClientComputer m_computer;
protected WidgetTerminal m_terminalGui;
private final ComputerFamily m_family;
private final ClientComputer m_computer;
private WidgetTerminal m_terminalGui;
public GuiTurtle( World world, InventoryPlayer inventoryplayer, TileTurtle turtle )
{
this( world, turtle, new ContainerTurtle( inventoryplayer, turtle.getAccess() ) );
}
protected GuiTurtle( World world, TileTurtle turtle, ContainerTurtle container )
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
{
super( container );
m_world = world;
m_container = container;
m_family = turtle.getFamily();
m_turtle = turtle.getAccess();
m_computer = turtle.getClientComputer();
xSize = 254;

View File

@ -9,26 +9,14 @@ package dan200.computercraft.client.proxy;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.ClientTableFormatter;
import dan200.computercraft.client.FrameInfo;
import dan200.computercraft.client.gui.*;
import dan200.computercraft.client.render.*;
import dan200.computercraft.shared.command.CommandCopy;
import dan200.computercraft.shared.command.ContainerViewComputer;
import dan200.computercraft.shared.command.text.TableBuilder;
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.media.inventory.ContainerHeldItem;
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.media.items.ItemPrintout;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
@ -36,11 +24,8 @@ import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
@ -169,59 +154,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} );
}
@Override
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
{
return new GuiDiskDrive( inventory, drive );
}
@Override
public Object getComputerGUI( TileComputer computer )
{
return new GuiComputer( computer );
}
@Override
public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer )
{
return new GuiPrinter( inventory, printer );
}
@Override
public Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle )
{
return new GuiTurtle( turtle.getWorld(), inventory, turtle );
}
@Override
public Object getPrintoutGUI( EntityPlayer player, EnumHand hand )
{
ContainerHeldItem container = new ContainerHeldItem( player, hand );
if( container.getStack().getItem() instanceof ItemPrintout )
{
return new GuiPrintout( container );
}
return null;
}
@Override
public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
ContainerPocketComputer container = new ContainerPocketComputer( player, hand );
if( container.getStack().getItem() instanceof ItemPocketComputer )
{
return new GuiPocketComputer( container );
}
return null;
}
@Override
public Object getComputerGUI( ClientComputer 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 )
{

View File

@ -6,19 +6,7 @@
package dan200.computercraft.server.proxy;
import dan200.computercraft.shared.command.text.TableBuilder;
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.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
@ -26,61 +14,9 @@ import java.io.File;
public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
{
@Override
public Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle )
{
return null;
}
@Override
public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive )
{
return null;
}
@Override
public Object getComputerGUI( TileComputer computer )
{
return null;
}
@Override
public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer )
{
return null;
}
@Override
public Object getPrintoutGUI( EntityPlayer player, EnumHand hand )
{
return null;
}
@Override
public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand )
{
return null;
}
@Override
public Object getComputerGUI( ClientComputer computer, int width, int height, ComputerFamily family )
{
return null;
}
@Override
public File getWorldDir( World world )
{
return DimensionManager.getWorld( 0 ).getSaveHandler().getWorldDirectory();
}
@Override
public void playRecordClient( BlockPos pos, SoundEvent record, String info )
{
}
@Override
public void showTableClient( TableBuilder table )
{
}
}

View File

@ -37,6 +37,11 @@ public class ContainerDiskDrive extends Container
}
}
public TileDiskDrive getDiskDrive()
{
return m_diskDrive;
}
@Override
public boolean canInteractWith( @Nonnull EntityPlayer player )
{

View File

@ -62,6 +62,11 @@ public class ContainerPrinter extends Container
return m_lastPrinting;
}
public TilePrinter getPrinter()
{
return m_printer;
}
@Override
public void addListener( IContainerListener crafting )
{

View File

@ -14,9 +14,9 @@ import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.PocketUpgrades;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.items.IComputerItem;
import dan200.computercraft.shared.pocket.apis.PocketAPI;

View File

@ -9,6 +9,7 @@ package dan200.computercraft.shared.proxy;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.client.gui.*;
import dan200.computercraft.core.computer.MainThread;
import dan200.computercraft.shared.PocketUpgrades;
import dan200.computercraft.shared.command.CommandComputerCraft;
@ -94,6 +95,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.registries.IForgeRegistry;
import pl.asie.charset.ModCharset;
@ -490,6 +492,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
}
@Override
@SideOnly( Side.CLIENT )
public Object getClientGuiElement( int id, EntityPlayer player, World world, int x, int y, int z )
{
BlockPos pos = new BlockPos( x, y, z );
@ -498,32 +501,17 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
case ComputerCraft.diskDriveGUIID:
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileDiskDrive )
{
TileDiskDrive drive = (TileDiskDrive) tile;
return getDiskDriveGUI( player.inventory, drive );
}
break;
return tile instanceof TileDiskDrive ? new GuiDiskDrive( new ContainerDiskDrive( player.inventory, (TileDiskDrive) tile ) ) : null;
}
case ComputerCraft.computerGUIID:
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputer )
{
TileComputer computer = (TileComputer) tile;
return getComputerGUI( computer );
}
break;
return tile instanceof TileComputer ? new GuiComputer( (TileComputer) tile ) : null;
}
case ComputerCraft.printerGUIID:
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TilePrinter )
{
TilePrinter printer = (TilePrinter) tile;
return getPrinterGUI( player.inventory, printer );
}
break;
return tile instanceof TilePrinter ? new GuiPrinter( new ContainerPrinter( player.inventory, (TilePrinter) tile ) ) : null;
}
case ComputerCraft.turtleGUIID:
{
@ -531,17 +519,19 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
if( tile instanceof TileTurtle )
{
TileTurtle turtle = (TileTurtle) tile;
return getTurtleGUI( player.inventory, turtle );
return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess() ) );
}
break;
return null;
}
case ComputerCraft.printoutGUIID:
{
return getPrintoutGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
ContainerHeldItem container = new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
return container.getStack().getItem() instanceof ItemPrintout ? new GuiPrintout( container ) : null;
}
case ComputerCraft.pocketComputerGUIID:
{
return getPocketComputerGUI( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
ContainerPocketComputer container = new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND );
return container.getStack().getItem() instanceof ItemPocketComputer ? new GuiPocketComputer( container ) : null;
}
case ComputerCraft.viewComputerGUIID:
{
@ -562,10 +552,13 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
width = computer.getTerminal().getWidth();
height = computer.getTerminal().getHeight();
}
return getComputerGUI( computer, width, height, family );
ContainerViewComputer container = new ContainerViewComputer( computer );
return new GuiComputer( container, family, computer, width, height );
}
default:
return null;
}
return null;
}
// Event handlers

View File

@ -7,16 +7,7 @@
package dan200.computercraft.shared.proxy;
import dan200.computercraft.shared.command.text.TableBuilder;
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.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -31,23 +22,13 @@ public interface IComputerCraftProxy
void initServer( MinecraftServer server );
Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );
Object getComputerGUI( TileComputer computer );
Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer );
Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
Object getComputerGUI( ClientComputer computer, int width, int height, ComputerFamily family );
File getWorldDir( World world );
void playRecordClient( BlockPos pos, SoundEvent record, String info );
default void playRecordClient( BlockPos pos, SoundEvent record, String info )
{
}
void showTableClient( TableBuilder table );
default void showTableClient( TableBuilder table )
{
}
}