mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 05:33:00 +00:00 
			
		
		
		
	Cherry pick several improvements from 1.13
- Move container opening (and gui handling) into a separate class
 - Move turtle/computer placement code onto the block
 - GUIs now use gui{Left,Top} instead of calculating it manually.
 - IPeripheralTile is now exposed in the API.
			
			
This commit is contained in:
		| @@ -28,15 +28,11 @@ import dan200.computercraft.core.computer.MainThread; | ||||
| 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.core.tracking.Tracking; | ||||
| import dan200.computercraft.shared.*; | ||||
| 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.computer.items.ItemCommandComputer; | ||||
| import dan200.computercraft.shared.computer.items.ItemComputer; | ||||
| @@ -44,24 +40,19 @@ import dan200.computercraft.shared.media.items.ItemDiskExpanded; | ||||
| import dan200.computercraft.shared.media.items.ItemDiskLegacy; | ||||
| import dan200.computercraft.shared.media.items.ItemPrintout; | ||||
| import dan200.computercraft.shared.media.items.ItemTreasureDisk; | ||||
| import dan200.computercraft.shared.network.NetworkHandler; | ||||
| import dan200.computercraft.shared.peripheral.common.BlockPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.common.ItemPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; | ||||
| import dan200.computercraft.shared.peripheral.modem.wired.BlockCable; | ||||
| import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull; | ||||
| import dan200.computercraft.shared.peripheral.modem.wired.ItemCable; | ||||
| import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem; | ||||
| import dan200.computercraft.shared.peripheral.modem.wireless.ItemAdvancedModem; | ||||
| import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork; | ||||
| import dan200.computercraft.shared.peripheral.printer.TilePrinter; | ||||
| import dan200.computercraft.shared.pocket.items.ItemPocketComputer; | ||||
| import dan200.computercraft.shared.pocket.peripherals.PocketModem; | ||||
| import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker; | ||||
| import dan200.computercraft.shared.proxy.ICCTurtleProxy; | ||||
| import dan200.computercraft.shared.proxy.IComputerCraftProxy; | ||||
| import dan200.computercraft.shared.turtle.blocks.BlockTurtle; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced; | ||||
| import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy; | ||||
| import dan200.computercraft.shared.turtle.items.ItemTurtleNormal; | ||||
| @@ -77,7 +68,6 @@ import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.server.MinecraftServer; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.IBlockAccess; | ||||
| import net.minecraft.world.World; | ||||
| @@ -109,16 +99,6 @@ public class ComputerCraft | ||||
| { | ||||
|     public static final String MOD_ID = "computercraft"; | ||||
|  | ||||
|     // GUI IDs | ||||
|     public static final int diskDriveGUIID = 100; | ||||
|     public static final int computerGUIID = 101; | ||||
|     public static final int printerGUIID = 102; | ||||
|     public static final int turtleGUIID = 103; | ||||
|     // ComputerCraftEdu uses ID 104 | ||||
|     public static final int printoutGUIID = 105; | ||||
|     public static final int pocketComputerGUIID = 106; | ||||
|     public static final int viewComputerGUIID = 110; | ||||
|  | ||||
|     // Configuration options | ||||
|     public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" }; | ||||
|     public static final String[] DEFAULT_HTTP_BLACKLIST = new String[] { | ||||
| @@ -268,12 +248,6 @@ public class ComputerCraft | ||||
|     ) | ||||
|     private static IComputerCraftProxy proxy; | ||||
|  | ||||
|     @SidedProxy( | ||||
|         clientSide = "dan200.computercraft.client.proxy.CCTurtleProxyClient", | ||||
|         serverSide = "dan200.computercraft.shared.proxy.CCTurtleProxyCommon" | ||||
|     ) | ||||
|     private static ICCTurtleProxy turtleProxy; | ||||
|  | ||||
|     @Mod.EventHandler | ||||
|     public void preInit( FMLPreInitializationEvent event ) | ||||
|     { | ||||
| @@ -282,18 +256,13 @@ public class ComputerCraft | ||||
|         // Load config | ||||
|         Config.load( event.getSuggestedConfigurationFile() ); | ||||
|  | ||||
|         // Setup network | ||||
|         NetworkHandler.setup(); | ||||
|  | ||||
|         proxy.preInit(); | ||||
|         turtleProxy.preInit(); | ||||
|     } | ||||
|  | ||||
|     @Mod.EventHandler | ||||
|     public void init( FMLInitializationEvent event ) | ||||
|     { | ||||
|         proxy.init(); | ||||
|         turtleProxy.init(); | ||||
|     } | ||||
|  | ||||
|     @Mod.EventHandler | ||||
| @@ -331,58 +300,6 @@ public class ComputerCraft | ||||
|         return "${version}"; | ||||
|     } | ||||
|  | ||||
|     public static void openDiskDriveGUI( EntityPlayer player, TileDiskDrive drive ) | ||||
|     { | ||||
|         BlockPos pos = drive.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, ComputerCraft.diskDriveGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openComputerGUI( EntityPlayer player, TileComputer computer ) | ||||
|     { | ||||
|         BlockPos pos = computer.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, ComputerCraft.computerGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openPrinterGUI( EntityPlayer player, TilePrinter printer ) | ||||
|     { | ||||
|         BlockPos pos = printer.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, ComputerCraft.printerGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle ) | ||||
|     { | ||||
|         BlockPos pos = turtle.getPos(); | ||||
|         player.openGui( instance, ComputerCraft.turtleGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openPrintoutGUI( EntityPlayer player, EnumHand hand ) | ||||
|     { | ||||
|         player.openGui( ComputerCraft.instance, ComputerCraft.printoutGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 ); | ||||
|     } | ||||
|  | ||||
|     public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand ) | ||||
|     { | ||||
|         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) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     private static File getBaseDir() | ||||
|     { | ||||
|         return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory(); | ||||
|   | ||||
| @@ -7,6 +7,7 @@ | ||||
| package dan200.computercraft.api.media; | ||||
|  | ||||
| import dan200.computercraft.api.filesystem.IMount; | ||||
| import net.minecraft.item.Item; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.util.SoundEvent; | ||||
| import net.minecraft.world.World; | ||||
| @@ -16,7 +17,9 @@ import javax.annotation.Nullable; | ||||
|  | ||||
| /** | ||||
|  * Represents an item that can be placed in a disk drive and used by a Computer. | ||||
|  * Implement this interface on your Item class to allow it to be used in the drive. | ||||
|  * | ||||
|  * Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register | ||||
|  * a {@link IMediaProvider}. | ||||
|  */ | ||||
| public interface IMedia | ||||
| { | ||||
|   | ||||
| @@ -23,7 +23,7 @@ public interface IMediaProvider | ||||
|      * Produce an IMedia implementation from an ItemStack. | ||||
|      * | ||||
|      * @param stack The stack from which to extract the media information. | ||||
|      * @return An IMedia implementation, or null if the item is not something you wish to handle | ||||
|      * @return An {@link IMedia} implementation, or {@code null} if the item is not something you wish to handle | ||||
|      * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) | ||||
|      */ | ||||
|     @Nullable | ||||
|   | ||||
| @@ -6,6 +6,7 @@ | ||||
|  | ||||
| package dan200.computercraft.api.peripheral; | ||||
|  | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| @@ -16,6 +17,8 @@ import javax.annotation.Nullable; | ||||
| /** | ||||
|  * This interface is used to create peripheral implementations for blocks. | ||||
|  * | ||||
|  * If you have a {@link TileEntity} which acts as a peripheral, you may alternatively implement {@link IPeripheralTile}. | ||||
|  * | ||||
|  * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) | ||||
|  */ | ||||
| @FunctionalInterface | ||||
|   | ||||
| @@ -0,0 +1,32 @@ | ||||
| /* | ||||
|  * This file is part of the public ComputerCraft API - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only. | ||||
|  * For help using the API, and posting your mods, visit the forums at computercraft.info. | ||||
|  */ | ||||
| package dan200.computercraft.api.peripheral; | ||||
|  | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
|  | ||||
| /** | ||||
|  * A {@link net.minecraft.tileentity.TileEntity} which may act as a peripheral. | ||||
|  * | ||||
|  * If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use | ||||
|  * {@link IPeripheralProvider}. | ||||
|  */ | ||||
| public interface IPeripheralTile | ||||
| { | ||||
|     /** | ||||
|      * Get the peripheral on the given {@code side}. | ||||
|      * | ||||
|      * @param side The side to get the peripheral from. | ||||
|      * @return A peripheral, or {@code null} if there is not a peripheral here. | ||||
|      * @see IPeripheralProvider#getPeripheral(World, BlockPos, EnumFacing) | ||||
|      */ | ||||
|     @Nullable | ||||
|     IPeripheral getPeripheral( @Nonnull EnumFacing side ); | ||||
| } | ||||
| @@ -19,7 +19,6 @@ import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| import net.minecraftforge.common.util.FakePlayer; | ||||
| import net.minecraftforge.event.world.BlockEvent; | ||||
| import net.minecraftforge.fml.common.eventhandler.Cancelable; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import java.util.Map; | ||||
| @@ -37,7 +36,6 @@ import java.util.Objects; | ||||
|  * Be aware that some events (such as {@link TurtleInventoryEvent}) do not necessarily interact | ||||
|  * with a block, simply objects within that block space. | ||||
|  */ | ||||
| @Cancelable | ||||
| public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
| { | ||||
|     private final World world; | ||||
| @@ -84,7 +82,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
|      * | ||||
|      * @see TurtleAction#DIG | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Dig extends TurtleBlockEvent | ||||
|     { | ||||
|         private final IBlockState block; | ||||
| @@ -142,7 +139,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
|      * | ||||
|      * @see TurtleAction#MOVE | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Move extends TurtleBlockEvent | ||||
|     { | ||||
|         public Move( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos ) | ||||
| @@ -156,7 +152,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
|      * | ||||
|      * @see TurtleAction#PLACE | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Place extends TurtleBlockEvent | ||||
|     { | ||||
|         private final ItemStack stack; | ||||
| @@ -188,7 +183,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
|      * | ||||
|      * @see TurtleAction#INSPECT | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Inspect extends TurtleBlockEvent | ||||
|     { | ||||
|         private final IBlockState state; | ||||
| @@ -229,7 +223,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent | ||||
|         /** | ||||
|          * Add new information to the inspection result. Note this will override fields with the same name. | ||||
|          * | ||||
|          * @param newData The data to add. Note all values should be convertable to Lua (see | ||||
|          * @param newData The data to add. Note all values should be convertible to Lua (see | ||||
|          *                {@link dan200.computercraft.api.peripheral.IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}). | ||||
|          */ | ||||
|         public void addData( @Nonnull Map<String, ?> newData ) | ||||
|   | ||||
| @@ -48,7 +48,6 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent | ||||
|      * | ||||
|      * @see TurtleAction#SUCK | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Suck extends TurtleInventoryEvent | ||||
|     { | ||||
|         public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler ) | ||||
| @@ -62,7 +61,6 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent | ||||
|      * | ||||
|      * @see TurtleAction#DROP | ||||
|      */ | ||||
|     @Cancelable | ||||
|     public static class Drop extends TurtleInventoryEvent | ||||
|     { | ||||
|         private final ItemStack stack; | ||||
|   | ||||
| @@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.client.render.TurtleModelLoader; | ||||
| import dan200.computercraft.shared.media.items.ItemDiskLegacy; | ||||
| import dan200.computercraft.shared.turtle.items.ItemTurtleBase; | ||||
| import dan200.computercraft.shared.util.Colour; | ||||
| import net.minecraft.client.Minecraft; | ||||
| import net.minecraft.client.renderer.ItemMeshDefinition; | ||||
| import net.minecraft.client.renderer.block.model.IBakedModel; | ||||
| @@ -117,7 +116,7 @@ public class ClientRegistry | ||||
|     public static void onItemColours( ColorHandlerEvent.Item event ) | ||||
|     { | ||||
|         event.getItemColors().registerItemColorHandler( | ||||
|             ( stack, layer ) -> layer == 0 ? 0xFFFFFF : ((ItemDiskLegacy) stack.getItem()).getColour( stack ), | ||||
|             ( stack, layer ) -> layer == 1 ? ((ItemDiskLegacy) stack.getItem()).getColour( stack ) : 0xFFFFFF, | ||||
|             ComputerCraft.Items.disk, ComputerCraft.Items.diskExpanded | ||||
|         ); | ||||
|  | ||||
| @@ -127,32 +126,18 @@ public class ClientRegistry | ||||
|                 case 0: | ||||
|                 default: | ||||
|                     return 0xFFFFFF; | ||||
|                 case 1: | ||||
|                 { | ||||
|                     // Frame colour | ||||
|                     int colour = ComputerCraft.Items.pocketComputer.getColour( stack ); | ||||
|                     return colour == -1 ? 0xFFFFFF : colour; | ||||
|                 } | ||||
|                 case 2: | ||||
|                 { | ||||
|                     // Light colour | ||||
|                     int colour = ComputerCraft.Items.pocketComputer.getLightState( stack ); | ||||
|                     return colour == -1 ? Colour.Black.getHex() : colour; | ||||
|                 } | ||||
|                 case 1: // Frame colour | ||||
|                     return ComputerCraft.Items.pocketComputer.getColour( stack ); | ||||
|                 case 2: // Light colour | ||||
|                     return ComputerCraft.Items.pocketComputer.getLightState( stack ); | ||||
|             } | ||||
|         }, ComputerCraft.Items.pocketComputer ); | ||||
|  | ||||
|         // Setup turtle colours | ||||
|         event.getItemColors().registerItemColorHandler( ( stack, tintIndex ) -> { | ||||
|             if( tintIndex == 0 ) | ||||
|             { | ||||
|                 ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem(); | ||||
|                 int colour = turtle.getColour( stack ); | ||||
|                 if( colour != -1 ) return colour; | ||||
|             } | ||||
|  | ||||
|             return 0xFFFFFF; | ||||
|         }, ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced ); | ||||
|         event.getItemColors().registerItemColorHandler( | ||||
|             ( stack, tintIndex ) -> tintIndex == 0 ? ((ItemTurtleBase) stack.getItem()).getColour( stack ) : 0xFFFFFF, | ||||
|             ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     private static void registerItemModel( Item item, int damage, String name ) | ||||
|   | ||||
| @@ -144,7 +144,7 @@ public class GuiComputer extends GuiContainer | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void drawScreen( int mouseX, int mouseY, float f ) | ||||
|     public void drawScreen( int mouseX, int mouseY, float partialTicks ) | ||||
|     { | ||||
|         // Work out where to draw | ||||
|         int startX = (width - m_terminal.getWidth()) / 2; | ||||
| @@ -156,7 +156,7 @@ public class GuiComputer extends GuiContainer | ||||
|         drawDefaultBackground(); | ||||
|  | ||||
|         // Draw terminal | ||||
|         m_terminal.draw( this.mc, startX, startY, mouseX, mouseY ); | ||||
|         m_terminal.draw( mc, startX, startY, mouseX, mouseY ); | ||||
|  | ||||
|         // Draw a border around the terminal | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
| @@ -164,20 +164,14 @@ public class GuiComputer extends GuiContainer | ||||
|         { | ||||
|             case Normal: | ||||
|             default: | ||||
|             { | ||||
|                 this.mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|                 mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|                 break; | ||||
|             } | ||||
|             case Advanced: | ||||
|             { | ||||
|                 this.mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); | ||||
|                 mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); | ||||
|                 break; | ||||
|             } | ||||
|             case Command: | ||||
|             { | ||||
|                 this.mc.getTextureManager().bindTexture( BACKGROUND_COMMAND ); | ||||
|                 mc.getTextureManager().bindTexture( BACKGROUND_COMMAND ); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 ); | ||||
|   | ||||
| @@ -25,7 +25,7 @@ public class GuiDiskDrive extends GuiContainer | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerForegroundLayer( int par1, int par2 ) | ||||
|     protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) | ||||
|     { | ||||
|         String title = m_container.getDiskDrive().getDisplayName().getUnformattedText(); | ||||
|         fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 ); | ||||
| @@ -33,13 +33,11 @@ public class GuiDiskDrive extends GuiContainer | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerBackgroundLayer( float f, int i, int j ) | ||||
|     protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) | ||||
|     { | ||||
|         GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|         this.mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|         int l = (width - xSize) / 2; | ||||
|         int i1 = (height - ySize) / 2; | ||||
|         drawTexturedModalRect( l, i1, 0, 0, xSize, ySize ); | ||||
|         mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|         drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -16,36 +16,30 @@ public class GuiPrinter extends GuiContainer | ||||
| { | ||||
|     private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" ); | ||||
|  | ||||
|     private final ContainerPrinter m_container; | ||||
|     private final ContainerPrinter container; | ||||
|  | ||||
|     public GuiPrinter( ContainerPrinter container ) | ||||
|     { | ||||
|         super( container ); | ||||
|         m_container = container; | ||||
|         this.container = container; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerForegroundLayer( int par1, int par2 ) | ||||
|     protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) | ||||
|     { | ||||
|         String title = m_container.getPrinter().getDisplayName().getUnformattedText(); | ||||
|         String title = 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 ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerBackgroundLayer( float f, int i, int j ) | ||||
|     protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) | ||||
|     { | ||||
|         GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|         this.mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|         int startX = (width - xSize) / 2; | ||||
|         int startY = (height - ySize) / 2; | ||||
|         drawTexturedModalRect( startX, startY, 0, 0, xSize, ySize ); | ||||
|         mc.getTextureManager().bindTexture( BACKGROUND ); | ||||
|         drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); | ||||
|  | ||||
|         boolean printing = m_container.isPrinting(); | ||||
|         if( printing ) | ||||
|         { | ||||
|             drawTexturedModalRect( startX + 34, startY + 21, 176, 0, 25, 45 ); | ||||
|         } | ||||
|         if( container.isPrinting() ) drawTexturedModalRect( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -29,6 +29,8 @@ public class GuiPrintout extends GuiContainer | ||||
|     { | ||||
|         super( container ); | ||||
|  | ||||
|         ySize = Y_SIZE; | ||||
|  | ||||
|         String[] text = ItemPrintout.getText( container.getStack() ); | ||||
|         m_text = new TextBuffer[text.length]; | ||||
|         for( int i = 0; i < m_text.length; i++ ) m_text[i] = new TextBuffer( text[i] ); | ||||
| @@ -73,41 +75,35 @@ public class GuiPrintout extends GuiContainer | ||||
|         int mouseWheelChange = Mouse.getEventDWheel(); | ||||
|         if( mouseWheelChange < 0 ) | ||||
|         { | ||||
|             // Up | ||||
|             // Scroll up goes to the next page | ||||
|             if( m_page < m_pages - 1 ) m_page++; | ||||
|         } | ||||
|         else if( mouseWheelChange > 0 ) | ||||
|         { | ||||
|             // Down | ||||
|             // Scroll down goes to the next page | ||||
|             if( m_page > 0 ) m_page--; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerForegroundLayer( int par1, int par2 ) | ||||
|     protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) | ||||
|     { | ||||
|         // Draw the printout | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|  | ||||
|         drawBorder( guiLeft, guiTop, zLevel, m_page, m_pages, m_book ); | ||||
|         drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerBackgroundLayer( float var1, int var2, int var3 ) | ||||
|     public void drawScreen( int mouseX, int mouseY, float partialTicks ) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void drawScreen( int mouseX, int mouseY, float f ) | ||||
|     { | ||||
|         // Draw background | ||||
|         // We must take the background further back in order to not overlap with our printed pages. | ||||
|         zLevel = zLevel - 1; | ||||
|         drawDefaultBackground(); | ||||
|         zLevel = zLevel + 1; | ||||
|  | ||||
|         // Draw the printout | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|  | ||||
|         int startY = (height - Y_SIZE) / 2; | ||||
|         int startX = (width - X_SIZE) / 2; | ||||
|  | ||||
|         drawBorder( startX, startY, zLevel, m_page, m_pages, m_book ); | ||||
|         drawText( startX + X_TEXT_MARGIN, startY + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); | ||||
|         super.drawScreen( mouseX, mouseY, partialTicks ); | ||||
|         renderHoveredToolTip( mouseX, mouseY ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -23,7 +23,7 @@ import java.io.IOException; | ||||
|  | ||||
| public class GuiTurtle extends GuiContainer | ||||
| { | ||||
|     private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/turtle.png" ); | ||||
|     private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle.png" ); | ||||
|     private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" ); | ||||
|  | ||||
|     private ContainerTurtle m_container; | ||||
| @@ -50,8 +50,8 @@ public class GuiTurtle extends GuiContainer | ||||
|         super.initGui(); | ||||
|         Keyboard.enableRepeatEvents( true ); | ||||
|         m_terminalGui = new WidgetTerminal( | ||||
|             (width - xSize) / 2 + 8, | ||||
|             (height - ySize) / 2 + 8, | ||||
|             guiLeft + 8, | ||||
|             guiTop + 8, | ||||
|             ComputerCraft.terminalWidth_turtle, | ||||
|             ComputerCraft.terminalHeight_turtle, | ||||
|             () -> m_computer, | ||||
| @@ -112,9 +112,6 @@ public class GuiTurtle extends GuiContainer | ||||
|  | ||||
|     protected void drawSelectionSlot( boolean advanced ) | ||||
|     { | ||||
|         int x = (width - xSize) / 2; | ||||
|         int y = (height - ySize) / 2; | ||||
|  | ||||
|         // Draw selection slot | ||||
|         int slot = m_container.getSelectedSlot(); | ||||
|         if( slot >= 0 ) | ||||
| @@ -122,13 +119,13 @@ public class GuiTurtle extends GuiContainer | ||||
|             GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|             int slotX = (slot % 4); | ||||
|             int slotY = (slot / 4); | ||||
|             this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND ); | ||||
|             drawTexturedModalRect( x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 ); | ||||
|             mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); | ||||
|             drawTexturedModalRect( guiLeft + m_container.m_turtleInvStartX - 2 + slotX * 18, guiTop + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void drawGuiContainerBackgroundLayer( float f, int mouseX, int mouseY ) | ||||
|     protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) | ||||
|     { | ||||
|         // Draw term | ||||
|         boolean advanced = (m_family == ComputerFamily.Advanced); | ||||
| @@ -136,10 +133,8 @@ public class GuiTurtle extends GuiContainer | ||||
|  | ||||
|         // Draw border/inventory | ||||
|         GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); | ||||
|         this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND ); | ||||
|         int x = (width - xSize) / 2; | ||||
|         int y = (height - ySize) / 2; | ||||
|         drawTexturedModalRect( x, y, 0, 0, xSize, ySize ); | ||||
|         mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); | ||||
|         drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); | ||||
|  | ||||
|         drawSelectionSlot( advanced ); | ||||
|     } | ||||
|   | ||||
| @@ -1,24 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.client.proxy; | ||||
|  | ||||
| import dan200.computercraft.client.render.TileEntityTurtleRenderer; | ||||
| import dan200.computercraft.shared.proxy.CCTurtleProxyCommon; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import net.minecraftforge.fml.client.registry.ClientRegistry; | ||||
|  | ||||
| public class CCTurtleProxyClient extends CCTurtleProxyCommon | ||||
| { | ||||
|     @Override | ||||
|     public void init() | ||||
|     { | ||||
|         super.init(); | ||||
|  | ||||
|         // Setup renderers | ||||
|         ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() ); | ||||
|     } | ||||
| } | ||||
| @@ -9,11 +9,13 @@ package dan200.computercraft.client.proxy; | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.client.render.TileEntityCableRenderer; | ||||
| import dan200.computercraft.client.render.TileEntityMonitorRenderer; | ||||
| import dan200.computercraft.client.render.TileEntityTurtleRenderer; | ||||
| import dan200.computercraft.shared.command.CommandCopy; | ||||
| 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.proxy.ComputerCraftProxyCommon; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import net.minecraftforge.client.ClientCommandHandler; | ||||
| import net.minecraftforge.event.world.WorldEvent; | ||||
| import net.minecraftforge.fml.client.registry.ClientRegistry; | ||||
| @@ -40,6 +42,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon | ||||
|         // Setup renderers | ||||
|         ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() ); | ||||
|         ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() ); | ||||
|         ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() ); | ||||
|     } | ||||
|  | ||||
|     @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT ) | ||||
|   | ||||
| @@ -12,6 +12,8 @@ import dan200.computercraft.shared.util.Palette; | ||||
| import net.minecraft.client.Minecraft; | ||||
| import net.minecraft.client.renderer.BufferBuilder; | ||||
| import net.minecraft.client.renderer.GlStateManager; | ||||
| import net.minecraft.client.renderer.GlStateManager.DestFactor; | ||||
| import net.minecraft.client.renderer.GlStateManager.SourceFactor; | ||||
| import net.minecraft.client.renderer.Tessellator; | ||||
| import net.minecraft.client.renderer.vertex.DefaultVertexFormats; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| @@ -73,6 +75,7 @@ public class PrintoutRenderer | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|         GlStateManager.enableBlend(); | ||||
|         GlStateManager.enableTexture2D(); | ||||
|         GlStateManager.tryBlendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); | ||||
|  | ||||
|         FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance(); | ||||
|  | ||||
| @@ -87,6 +90,7 @@ public class PrintoutRenderer | ||||
|         GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); | ||||
|         GlStateManager.enableBlend(); | ||||
|         GlStateManager.enableTexture2D(); | ||||
|         GlStateManager.tryBlendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); | ||||
|  | ||||
|         Minecraft.getMinecraft().getTextureManager().bindTexture( BG ); | ||||
|  | ||||
|   | ||||
| @@ -78,7 +78,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void renderTurtleAt( TileTurtle turtle, double posX, double posY, double posZ, float f, int i ) | ||||
|     private void renderTurtleAt( TileTurtle turtle, double posX, double posY, double posZ, float partialTicks, int i ) | ||||
|     { | ||||
|         // Render the label | ||||
|         String label = turtle.createProxy().getLabel(); | ||||
| @@ -93,15 +93,13 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt | ||||
|             setLightmapDisabled( false ); | ||||
|         } | ||||
|  | ||||
|         IBlockState state = turtle.getWorld().getBlockState( turtle.getPos() ); | ||||
|         GlStateManager.pushMatrix(); | ||||
|         try | ||||
|         { | ||||
|             IBlockState state = turtle.getWorld().getBlockState( turtle.getPos() ); | ||||
|             // Setup the transform | ||||
|             Vec3d offset; | ||||
|             float yaw; | ||||
|             offset = turtle.getRenderOffset( f ); | ||||
|             yaw = turtle.getRenderYaw( f ); | ||||
|             Vec3d offset = turtle.getRenderOffset( partialTicks ); | ||||
|             float yaw = turtle.getRenderYaw( partialTicks ); | ||||
|             GlStateManager.translate( posX + offset.x, posY + offset.y, posZ + offset.z ); | ||||
|  | ||||
|             // Render the turtle | ||||
| @@ -146,8 +144,8 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt | ||||
|             } | ||||
|  | ||||
|             // Render the upgrades | ||||
|             renderUpgrade( state, turtle, TurtleSide.Left, f ); | ||||
|             renderUpgrade( state, turtle, TurtleSide.Right, f ); | ||||
|             renderUpgrade( state, turtle, TurtleSide.Left, partialTicks ); | ||||
|             renderUpgrade( state, turtle, TurtleSide.Right, partialTicks ); | ||||
|         } | ||||
|         finally | ||||
|         { | ||||
|   | ||||
| @@ -20,6 +20,7 @@ import dan200.computercraft.shared.command.framework.*; | ||||
| import dan200.computercraft.shared.command.text.TableBuilder; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import net.minecraft.command.CommandBase; | ||||
| import net.minecraft.command.CommandException; | ||||
| import net.minecraft.command.ICommandSender; | ||||
| @@ -258,7 +259,7 @@ public final class CommandComputerCraft extends CommandDelegate | ||||
|                 } | ||||
|  | ||||
|                 ServerComputer computer = ComputerSelector.getComputer( arguments.get( 0 ) ); | ||||
|                 ComputerCraft.openComputerGUI( (EntityPlayerMP) sender, computer ); | ||||
|                 Containers.openComputerGUI( (EntityPlayerMP) sender, computer ); | ||||
|             } | ||||
|  | ||||
|             @Nonnull | ||||
|   | ||||
| @@ -8,6 +8,7 @@ package dan200.computercraft.shared.computer.blocks; | ||||
|  | ||||
| import dan200.computercraft.shared.common.BlockDirectional; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.items.IComputerItem; | ||||
| import dan200.computercraft.shared.util.DirectionUtil; | ||||
| import net.minecraft.block.material.Material; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| @@ -141,4 +142,23 @@ public abstract class BlockComputerBase extends BlockDirectional | ||||
|  | ||||
|         return super.removedByPlayer( state, world, pos, player, willHarvest ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack ) | ||||
|     { | ||||
|         super.onBlockPlacedBy( world, pos, state, placer, stack ); | ||||
|  | ||||
|         TileEntity tile = world.getTileEntity( pos ); | ||||
|         if( !world.isRemote && tile instanceof IComputerTile && stack.getItem() instanceof IComputerItem ) | ||||
|         { | ||||
|             IComputerTile computer = (IComputerTile) tile; | ||||
|             IComputerItem item = (IComputerItem) stack.getItem(); | ||||
|  | ||||
|             int id = item.getComputerID( stack ); | ||||
|             if( id != -1 ) computer.setComputerID( id ); | ||||
|  | ||||
|             String label = item.getLabel( stack ); | ||||
|             if( label != null ) computer.setLabel( label ); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks; | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| @@ -60,7 +61,7 @@ public class TileComputer extends TileComputerBase | ||||
|     @Override | ||||
|     public void openGUI( EntityPlayer player ) | ||||
|     { | ||||
|         ComputerCraft.openComputerGUI( player, this ); | ||||
|         Containers.openComputerGUI( player, this ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -78,7 +79,7 @@ public class TileComputer extends TileComputerBase | ||||
|         updateBlock(); | ||||
|     } | ||||
|  | ||||
|     public boolean isUseableByPlayer( EntityPlayer player ) | ||||
|     public boolean isUsableByPlayer( EntityPlayer player ) | ||||
|     { | ||||
|         return isUsable( player, false ); | ||||
|     } | ||||
|   | ||||
| @@ -7,6 +7,8 @@ | ||||
| package dan200.computercraft.shared.computer.blocks; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.BundledRedstone; | ||||
| import dan200.computercraft.shared.Peripherals; | ||||
| import dan200.computercraft.shared.common.IDirectionalTile; | ||||
| @@ -28,9 +30,10 @@ import net.minecraft.util.ITickable; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
| import java.util.Objects; | ||||
|  | ||||
| public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable | ||||
| public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable, IPeripheralTile | ||||
| { | ||||
|     private int m_instanceID = -1; | ||||
|     private int m_computerID = -1; | ||||
| @@ -495,4 +498,11 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT | ||||
|         } | ||||
|         copy.m_instanceID = -1; | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return new ComputerPeripheral( "computer", createProxy() ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -29,7 +29,7 @@ public class ContainerComputer extends Container implements IContainerComputer | ||||
|     @Override | ||||
|     public boolean canInteractWith( @Nonnull EntityPlayer player ) | ||||
|     { | ||||
|         return computer.isUseableByPlayer( player ); | ||||
|         return computer.isUsableByPlayer( player ); | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|   | ||||
| @@ -7,20 +7,13 @@ | ||||
| package dan200.computercraft.shared.computer.items; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.shared.computer.blocks.IComputerTile; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.creativetab.CreativeTabs; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.NonNullList; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
| @@ -82,39 +75,6 @@ public class ItemComputer extends ItemComputerBase | ||||
|         list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ) ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean placeBlockAt( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState ) | ||||
|     { | ||||
|         if( super.placeBlockAt( stack, player, world, pos, side, hitX, hitY, hitZ, newState ) ) | ||||
|         { | ||||
|             TileEntity tile = world.getTileEntity( pos ); | ||||
|             if( tile instanceof IComputerTile ) | ||||
|             { | ||||
|                 IComputerTile computer = (IComputerTile) tile; | ||||
|                 setupComputerAfterPlacement( stack, computer ); | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     private void setupComputerAfterPlacement( @Nonnull ItemStack stack, IComputerTile computer ) | ||||
|     { | ||||
|         // Set ID | ||||
|         int id = getComputerID( stack ); | ||||
|         if( id >= 0 ) | ||||
|         { | ||||
|             computer.setComputerID( id ); | ||||
|         } | ||||
|  | ||||
|         // Set Label | ||||
|         String label = getLabel( stack ); | ||||
|         if( label != null ) | ||||
|         { | ||||
|             computer.setLabel( label ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Nonnull | ||||
|     @Override | ||||
|     public String getTranslationKey( @Nonnull ItemStack stack ) | ||||
| @@ -123,17 +83,11 @@ public class ItemComputer extends ItemComputerBase | ||||
|         { | ||||
|             case Normal: | ||||
|             default: | ||||
|             { | ||||
|                 return "tile.computercraft:computer"; | ||||
|             } | ||||
|             case Advanced: | ||||
|             { | ||||
|                 return "tile.computercraft:advanced_computer"; | ||||
|             } | ||||
|             case Command: | ||||
|             { | ||||
|                 return "tile.computercraft:command_computer"; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -162,10 +116,6 @@ public class ItemComputer extends ItemComputerBase | ||||
|     @Override | ||||
|     public ComputerFamily getFamily( int damage ) | ||||
|     { | ||||
|         if( (damage & 0x4000) != 0 ) | ||||
|         { | ||||
|             return ComputerFamily.Advanced; | ||||
|         } | ||||
|         return ComputerFamily.Normal; | ||||
|         return (damage & 0x4000) == 0 ? ComputerFamily.Normal : ComputerFamily.Advanced; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ package dan200.computercraft.shared.integration.mcmp; | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.ComputerCraftAPI; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.common.IPeripheralTile; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.peripheral.modem.wireless.TileAdvancedModem; | ||||
| import dan200.computercraft.shared.peripheral.modem.wireless.TileWirelessModem; | ||||
| import mcmultipart.api.addon.IMCMPAddon; | ||||
|   | ||||
| @@ -1,28 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.media.common; | ||||
|  | ||||
| import dan200.computercraft.api.media.IMedia; | ||||
| import dan200.computercraft.api.media.IMediaProvider; | ||||
| import dan200.computercraft.shared.media.items.RecordMedia; | ||||
| import net.minecraft.item.Item; | ||||
| import net.minecraft.item.ItemRecord; | ||||
| import net.minecraft.item.ItemStack; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
|  | ||||
| public class DefaultMediaProvider implements IMediaProvider | ||||
| { | ||||
|     @Override | ||||
|     public IMedia getMedia( @Nonnull ItemStack stack ) | ||||
|     { | ||||
|         Item item = stack.getItem(); | ||||
|         if( item instanceof IMedia ) return (IMedia) item; | ||||
|         if( item instanceof ItemRecord ) return RecordMedia.INSTANCE; | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -7,6 +7,7 @@ | ||||
| package dan200.computercraft.shared.media.items; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import net.minecraft.client.util.ITooltipFlag; | ||||
| import net.minecraft.creativetab.CreativeTabs; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| @@ -91,7 +92,7 @@ public class ItemPrintout extends Item | ||||
|     { | ||||
|         if( !world.isRemote ) | ||||
|         { | ||||
|             ComputerCraft.openPrintoutGUI( player, hand ); | ||||
|             Containers.openPrintoutGUI( player, hand ); | ||||
|         } | ||||
|         return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) ); | ||||
|     } | ||||
|   | ||||
| @@ -17,7 +17,7 @@ import javax.annotation.Nonnull; | ||||
| /** | ||||
|  * An implementation of IMedia for ItemRecord's | ||||
|  */ | ||||
| public class RecordMedia implements IMedia | ||||
| public final class RecordMedia implements IMedia | ||||
| { | ||||
|     public static final RecordMedia INSTANCE = new RecordMedia(); | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,233 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.network; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.client.gui.*; | ||||
| import dan200.computercraft.core.terminal.Terminal; | ||||
| import dan200.computercraft.shared.command.ContainerViewComputer; | ||||
| 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.ServerComputer; | ||||
| import dan200.computercraft.shared.computer.inventory.ContainerComputer; | ||||
| import dan200.computercraft.shared.media.inventory.ContainerHeldItem; | ||||
| import dan200.computercraft.shared.media.items.ItemPrintout; | ||||
| import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; | ||||
| import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; | ||||
| import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; | ||||
| 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.turtle.blocks.TileTurtle; | ||||
| import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| import net.minecraftforge.fml.common.network.IGuiHandler; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
|  | ||||
| public class Containers implements IGuiHandler | ||||
| { | ||||
|     public static final Containers INSTANCE = new Containers(); | ||||
|  | ||||
|     private static final int DISK_DRIVE = 100; | ||||
|     private static final int COMPUTER = 101; | ||||
|     private static final int PRINTER = 102; | ||||
|     private static final int TURTLE = 103; | ||||
|     private static final int PRINTOUT = 105; | ||||
|     private static final int POCKET_COMPUTER = 106; | ||||
|     private static final int VIEW_COMPUTER = 110; | ||||
|  | ||||
|     private Containers() | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public static void openDiskDriveGUI( EntityPlayer player, TileDiskDrive drive ) | ||||
|     { | ||||
|         BlockPos pos = drive.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, DISK_DRIVE, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openComputerGUI( EntityPlayer player, TileComputer computer ) | ||||
|     { | ||||
|         BlockPos pos = computer.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, COMPUTER, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openPrinterGUI( EntityPlayer player, TilePrinter printer ) | ||||
|     { | ||||
|         BlockPos pos = printer.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, PRINTER, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle ) | ||||
|     { | ||||
|         BlockPos pos = turtle.getPos(); | ||||
|         player.openGui( ComputerCraft.instance, TURTLE, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() ); | ||||
|     } | ||||
|  | ||||
|     public static void openPrintoutGUI( EntityPlayer player, EnumHand hand ) | ||||
|     { | ||||
|         player.openGui( ComputerCraft.instance, PRINTOUT, player.getEntityWorld(), hand.ordinal(), 0, 0 ); | ||||
|     } | ||||
|  | ||||
|     public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand ) | ||||
|     { | ||||
|         player.openGui( ComputerCraft.instance, POCKET_COMPUTER, 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, VIEW_COMPUTER, player.getEntityWorld(), | ||||
|             computer.getInstanceID(), family.ordinal(), (width & 0xFFFF) << 16 | (height & 0xFFFF) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Object getServerGuiElement( int id, EntityPlayer player, World world, int x, int y, int z ) | ||||
|     { | ||||
|         BlockPos pos = new BlockPos( x, y, z ); | ||||
|         switch( id ) | ||||
|         { | ||||
|             case DISK_DRIVE: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 if( tile instanceof TileDiskDrive ) | ||||
|                 { | ||||
|                     TileDiskDrive drive = (TileDiskDrive) tile; | ||||
|                     return new ContainerDiskDrive( player.inventory, drive ); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case COMPUTER: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 if( tile instanceof TileComputer ) | ||||
|                 { | ||||
|                     TileComputer computer = (TileComputer) tile; | ||||
|                     return new ContainerComputer( computer ); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case PRINTER: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 if( tile instanceof TilePrinter ) | ||||
|                 { | ||||
|                     TilePrinter printer = (TilePrinter) tile; | ||||
|                     return new ContainerPrinter( player.inventory, printer ); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case TURTLE: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 if( tile instanceof TileTurtle ) | ||||
|                 { | ||||
|                     TileTurtle turtle = (TileTurtle) tile; | ||||
|                     return new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getServerComputer() ); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|             case PRINTOUT: | ||||
|                 return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.MAIN_HAND ); | ||||
|             case POCKET_COMPUTER: | ||||
|                 return new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND ); | ||||
|             case VIEW_COMPUTER: | ||||
|             { | ||||
|                 ServerComputer computer = ComputerCraft.serverComputerRegistry.get( x ); | ||||
|                 return computer == null ? null : new ContainerViewComputer( computer ); | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @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 ); | ||||
|         switch( id ) | ||||
|         { | ||||
|             case DISK_DRIVE: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 return tile instanceof TileDiskDrive ? new GuiDiskDrive( new ContainerDiskDrive( player.inventory, (TileDiskDrive) tile ) ) : null; | ||||
|             } | ||||
|             case COMPUTER: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 return tile instanceof TileComputer ? new GuiComputer( (TileComputer) tile ) : null; | ||||
|             } | ||||
|             case PRINTER: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 return tile instanceof TilePrinter ? new GuiPrinter( new ContainerPrinter( player.inventory, (TilePrinter) tile ) ) : null; | ||||
|             } | ||||
|             case TURTLE: | ||||
|             { | ||||
|                 TileEntity tile = world.getTileEntity( pos ); | ||||
|                 if( tile instanceof TileTurtle ) | ||||
|                 { | ||||
|                     TileTurtle turtle = (TileTurtle) tile; | ||||
|                     return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess() ) ); | ||||
|                 } | ||||
|                 return null; | ||||
|             } | ||||
|             case PRINTOUT: | ||||
|             { | ||||
|                 ContainerHeldItem container = new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND ); | ||||
|                 return container.getStack().getItem() instanceof ItemPrintout ? new GuiPrintout( container ) : null; | ||||
|             } | ||||
|             case POCKET_COMPUTER: | ||||
|             { | ||||
|                 ContainerPocketComputer container = new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND ); | ||||
|                 return container.getStack().getItem() instanceof ItemPocketComputer ? new GuiPocketComputer( container ) : null; | ||||
|             } | ||||
|             case VIEW_COMPUTER: | ||||
|             { | ||||
|                 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(); | ||||
|                 } | ||||
|  | ||||
|                 ContainerViewComputer container = new ContainerViewComputer( computer ); | ||||
|                 return new GuiComputer( container, family, computer, width, height ); | ||||
|             } | ||||
|             default: | ||||
|                 return null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -29,35 +29,23 @@ public final class NetworkHandler | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     private static final int COMPUTER_ACTION_SERVER_MESSAGE = 0; | ||||
|     private static final int QUEUE_EVENT_SERVER_MESSAGE = 1; | ||||
|     private static final int REQUEST_COMPUTER_SERVER_MESSAGE = 2; | ||||
|     private static final int KEY_EVENT_SERVER_MESSAGE = 3; | ||||
|     private static final int MOUSE_EVENT_SERVER_MESSAGE = 4; | ||||
|  | ||||
|     private static final int CHAT_TABLE_CLIENT_MESSAGE = 10; | ||||
|     private static final int COMPUTER_DATA_CLIENT_MESSAGE = 11; | ||||
|     private static final int COMPUTER_DELETED_CLIENT_MESSAGE = 12; | ||||
|     private static final int COMPUTER_TERMINAL_CLIENT_MESSAGE = 13; | ||||
|     private static final int PLAY_RECORD_CLIENT_MESSAGE = 14; | ||||
|  | ||||
|     public static void setup() | ||||
|     { | ||||
|         network = NetworkRegistry.INSTANCE.newSimpleChannel( ComputerCraft.MOD_ID ); | ||||
|  | ||||
|         // Server messages | ||||
|         registerMainThread( NetworkHandler.COMPUTER_ACTION_SERVER_MESSAGE, Side.SERVER, ComputerActionServerMessage::new ); | ||||
|         registerMainThread( NetworkHandler.QUEUE_EVENT_SERVER_MESSAGE, Side.SERVER, QueueEventServerMessage::new ); | ||||
|         registerMainThread( NetworkHandler.REQUEST_COMPUTER_SERVER_MESSAGE, Side.SERVER, RequestComputerMessage::new ); | ||||
|         registerMainThread( NetworkHandler.KEY_EVENT_SERVER_MESSAGE, Side.SERVER, KeyEventServerMessage::new ); | ||||
|         registerMainThread( NetworkHandler.MOUSE_EVENT_SERVER_MESSAGE, Side.SERVER, MouseEventServerMessage::new ); | ||||
|         registerMainThread( 0, Side.SERVER, ComputerActionServerMessage::new ); | ||||
|         registerMainThread( 1, Side.SERVER, QueueEventServerMessage::new ); | ||||
|         registerMainThread( 2, Side.SERVER, RequestComputerMessage::new ); | ||||
|         registerMainThread( 3, Side.SERVER, KeyEventServerMessage::new ); | ||||
|         registerMainThread( 4, Side.SERVER, MouseEventServerMessage::new ); | ||||
|  | ||||
|         // Client messages | ||||
|         registerMainThread( NetworkHandler.PLAY_RECORD_CLIENT_MESSAGE, Side.CLIENT, PlayRecordClientMessage::new ); | ||||
|         registerMainThread( NetworkHandler.COMPUTER_DATA_CLIENT_MESSAGE, Side.CLIENT, ComputerDataClientMessage::new ); | ||||
|         registerMainThread( NetworkHandler.COMPUTER_TERMINAL_CLIENT_MESSAGE, Side.CLIENT, ComputerTerminalClientMessage::new ); | ||||
|         registerMainThread( NetworkHandler.COMPUTER_DELETED_CLIENT_MESSAGE, Side.CLIENT, ComputerDeletedClientMessage::new ); | ||||
|         registerMainThread( NetworkHandler.CHAT_TABLE_CLIENT_MESSAGE, Side.CLIENT, ChatTableClientMessage::new ); | ||||
|         registerMainThread( 14, Side.CLIENT, PlayRecordClientMessage::new ); | ||||
|         registerMainThread( 11, Side.CLIENT, ComputerDataClientMessage::new ); | ||||
|         registerMainThread( 13, Side.CLIENT, ComputerTerminalClientMessage::new ); | ||||
|         registerMainThread( 12, Side.CLIENT, ComputerDeletedClientMessage::new ); | ||||
|         registerMainThread( 10, Side.CLIENT, ChatTableClientMessage::new ); | ||||
|     } | ||||
|  | ||||
|     public static void sendToPlayer( EntityPlayer player, IMessage packet ) | ||||
|   | ||||
| @@ -11,7 +11,6 @@ import dan200.computercraft.api.lua.LuaException; | ||||
| import dan200.computercraft.api.peripheral.IComputerAccess; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import net.minecraft.tileentity.TileEntityCommandBlock; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
|  | ||||
| @@ -64,9 +63,8 @@ public class CommandBlockPeripheral implements IPeripheral | ||||
|                 final String command = getString( arguments, 0 ); | ||||
|                 context.issueMainThreadTask( () -> | ||||
|                 { | ||||
|                     BlockPos pos = m_commandBlock.getPos(); | ||||
|                     m_commandBlock.getCommandBlockLogic().setCommand( command ); | ||||
|                     m_commandBlock.getWorld().markBlockRangeForRenderUpdate( pos, pos ); | ||||
|                     m_commandBlock.getCommandBlockLogic().updateCommand(); | ||||
|                     return null; | ||||
|                 } ); | ||||
|                 return null; | ||||
|   | ||||
| @@ -1,32 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.commandblock; | ||||
|  | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralProvider; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.tileentity.TileEntityCommandBlock; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
|  | ||||
| public class CommandBlockPeripheralProvider implements IPeripheralProvider | ||||
| { | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         TileEntity tile = world.getTileEntity( pos ); | ||||
|         if( tile instanceof TileEntityCommandBlock ) | ||||
|         { | ||||
|             TileEntityCommandBlock commandBlock = (TileEntityCommandBlock) tile; | ||||
|             return new CommandBlockPeripheral( commandBlock ); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -1,55 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.common; | ||||
|  | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralProvider; | ||||
| import dan200.computercraft.shared.computer.blocks.ComputerPeripheral; | ||||
| import dan200.computercraft.shared.computer.blocks.TileComputerBase; | ||||
| import dan200.computercraft.shared.turtle.blocks.TileTurtle; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
|  | ||||
| public class DefaultPeripheralProvider implements IPeripheralProvider | ||||
| { | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         TileEntity tile = world.getTileEntity( pos ); | ||||
|         if( tile != null ) | ||||
|         { | ||||
|             // Handle our peripherals | ||||
|             if( tile instanceof IPeripheralTile ) | ||||
|             { | ||||
|                 IPeripheralTile peripheralTile = (IPeripheralTile) tile; | ||||
|                 return peripheralTile.getPeripheral( side ); | ||||
|             } | ||||
|  | ||||
|             // Handle our computers | ||||
|             if( tile instanceof TileComputerBase ) | ||||
|             { | ||||
|                 TileComputerBase computerTile = (TileComputerBase) tile; | ||||
|                 if( tile instanceof TileTurtle ) | ||||
|                 { | ||||
|                     if( !((TileTurtle) tile).hasMoved() ) | ||||
|                     { | ||||
|                         return new ComputerPeripheral( "turtle", computerTile.createProxy() ); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return new ComputerPeripheral( "computer", computerTile.createProxy() ); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
| @@ -6,10 +6,7 @@ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.common; | ||||
|  | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import net.minecraft.util.EnumFacing; | ||||
|  | ||||
| public interface IPeripheralTile | ||||
| @Deprecated | ||||
| public interface IPeripheralTile extends dan200.computercraft.api.peripheral.IPeripheralTile | ||||
| { | ||||
|     IPeripheral getPeripheral( EnumFacing side ); | ||||
| } | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
|  | ||||
| package dan200.computercraft.shared.peripheral.common; | ||||
|  | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.common.IDirectionalTile; | ||||
| import dan200.computercraft.shared.common.TileGeneric; | ||||
| import dan200.computercraft.shared.peripheral.PeripheralType; | ||||
| @@ -46,12 +46,6 @@ public abstract class TilePeripheralBase extends TileGeneric implements IPeriphe | ||||
|         return getBlock().getPeripheralType( getBlockState() ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     { | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String getLabel() | ||||
|     { | ||||
|   | ||||
| @@ -13,6 +13,7 @@ import dan200.computercraft.api.media.IMedia; | ||||
| import dan200.computercraft.api.peripheral.IComputerAccess; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.shared.MediaProviders; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import dan200.computercraft.shared.peripheral.PeripheralType; | ||||
| import dan200.computercraft.shared.peripheral.common.BlockPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; | ||||
| @@ -112,7 +113,7 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor | ||||
|             // Open the GUI | ||||
|             if( !getWorld().isRemote ) | ||||
|             { | ||||
|                 ComputerCraft.openDiskDriveGUI( player, this ); | ||||
|                 Containers.openDiskDriveGUI( player, this ); | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| @@ -343,7 +344,7 @@ public class TileDiskDrive extends TilePeripheralBase implements DefaultInventor | ||||
|     // IPeripheralTile implementation | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return new DiskDrivePeripheral( this ); | ||||
|     } | ||||
|   | ||||
| @@ -12,10 +12,10 @@ import dan200.computercraft.api.ComputerCraftAPI; | ||||
| import dan200.computercraft.api.network.wired.IWiredElement; | ||||
| import dan200.computercraft.api.network.wired.IWiredNode; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.command.CommandCopy; | ||||
| import dan200.computercraft.shared.common.TileGeneric; | ||||
| import dan200.computercraft.shared.peripheral.PeripheralType; | ||||
| import dan200.computercraft.shared.peripheral.common.IPeripheralTile; | ||||
| import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory; | ||||
| import dan200.computercraft.shared.peripheral.modem.ModemState; | ||||
| import dan200.computercraft.shared.util.TickScheduler; | ||||
| @@ -451,7 +451,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return !m_destroyed && getPeripheralType() != PeripheralType.Cable && side == getDirection() ? m_modem : null; | ||||
|     } | ||||
|   | ||||
| @@ -11,9 +11,9 @@ import dan200.computercraft.api.ComputerCraftAPI; | ||||
| import dan200.computercraft.api.network.wired.IWiredElement; | ||||
| import dan200.computercraft.api.network.wired.IWiredNode; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.command.CommandCopy; | ||||
| import dan200.computercraft.shared.common.TileGeneric; | ||||
| import dan200.computercraft.shared.peripheral.common.IPeripheralTile; | ||||
| import dan200.computercraft.shared.peripheral.modem.ModemState; | ||||
| import dan200.computercraft.shared.util.TickScheduler; | ||||
| import dan200.computercraft.shared.wired.CapabilityWiredElement; | ||||
| @@ -383,7 +383,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         if( m_destroyed ) return null; | ||||
|  | ||||
|   | ||||
| @@ -7,8 +7,8 @@ | ||||
| package dan200.computercraft.shared.peripheral.modem.wireless; | ||||
|  | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.shared.common.TileGeneric; | ||||
| import dan200.computercraft.shared.peripheral.common.IPeripheralTile; | ||||
| import dan200.computercraft.shared.peripheral.modem.ModemPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.modem.ModemState; | ||||
| import dan200.computercraft.shared.util.TickScheduler; | ||||
| @@ -154,7 +154,7 @@ public abstract class TileWirelessModemBase extends TileGeneric implements IPeri | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return !destroyed && side == getDirection() ? modem : null; | ||||
|     } | ||||
|   | ||||
| @@ -9,12 +9,12 @@ package dan200.computercraft.shared.peripheral.monitor; | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.peripheral.IComputerAccess; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.core.terminal.Terminal; | ||||
| import dan200.computercraft.shared.common.ServerTerminal; | ||||
| import dan200.computercraft.shared.common.TileGeneric; | ||||
| import dan200.computercraft.shared.peripheral.PeripheralType; | ||||
| import dan200.computercraft.shared.peripheral.common.BlockPeripheral; | ||||
| import dan200.computercraft.shared.peripheral.common.IPeripheralTile; | ||||
| import dan200.computercraft.shared.peripheral.common.ITilePeripheral; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| @@ -163,7 +163,7 @@ public class TileMonitor extends TileGeneric implements ITilePeripheral, IPeriph | ||||
|     // IPeripheralTile implementation | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         createServerMonitor(); // Ensure the monitor is created before doing anything else. | ||||
|  | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.core.terminal.Terminal; | ||||
| import dan200.computercraft.shared.media.items.ItemPrintout; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import dan200.computercraft.shared.peripheral.PeripheralType; | ||||
| import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; | ||||
| import dan200.computercraft.shared.util.DefaultSidedInventory; | ||||
| @@ -79,7 +80,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven | ||||
|         { | ||||
|             if( !getWorld().isRemote ) | ||||
|             { | ||||
|                 ComputerCraft.openPrinterGUI( player, this ); | ||||
|                 Containers.openPrinterGUI( player, this ); | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| @@ -339,7 +340,7 @@ public class TilePrinter extends TilePeripheralBase implements DefaultSidedInven | ||||
|     // IPeripheralTile implementation | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return new PrinterPeripheral( this ); | ||||
|     } | ||||
|   | ||||
| @@ -13,6 +13,7 @@ import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.util.math.Vec3d; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
|  | ||||
| public class TileSpeaker extends TilePeripheralBase | ||||
| @@ -38,7 +39,7 @@ public class TileSpeaker extends TilePeripheralBase | ||||
|     // IPeripheralTile implementation | ||||
|  | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( EnumFacing side ) | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return m_peripheral; | ||||
|     } | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import dan200.computercraft.shared.computer.core.ClientComputer; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import dan200.computercraft.shared.computer.items.IComputerItem; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import dan200.computercraft.shared.pocket.apis.PocketAPI; | ||||
| import dan200.computercraft.shared.pocket.core.PocketServerComputer; | ||||
| import dan200.computercraft.shared.util.StringUtil; | ||||
| @@ -188,7 +189,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             if( !stop ) ComputerCraft.openPocketComputerGUI( player, hand ); | ||||
|             if( !stop ) Containers.openPocketComputerGUI( player, hand ); | ||||
|         } | ||||
|         return new ActionResult<>( EnumActionResult.SUCCESS, stack ); | ||||
|     } | ||||
|   | ||||
| @@ -1,29 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.proxy; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.shared.turtle.core.TurtlePlayer; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraftforge.fml.common.registry.EntityRegistry; | ||||
|  | ||||
| public class CCTurtleProxyCommon implements ICCTurtleProxy | ||||
| { | ||||
|     @Override | ||||
|     public void preInit() | ||||
|     { | ||||
|         EntityRegistry.registerModEntity( | ||||
|             new ResourceLocation( ComputerCraft.MOD_ID, "turtle_player" ), TurtlePlayer.class, "turtle_player", | ||||
|             0, ComputerCraft.instance, Integer.MAX_VALUE, Integer.MAX_VALUE, false | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void init() | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -8,41 +8,33 @@ package dan200.computercraft.shared.proxy; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.ComputerCraftAPI; | ||||
| import dan200.computercraft.client.gui.*; | ||||
| import dan200.computercraft.api.media.IMedia; | ||||
| import dan200.computercraft.api.peripheral.IPeripheralTile; | ||||
| import dan200.computercraft.core.computer.MainThread; | ||||
| import dan200.computercraft.shared.Config; | ||||
| import dan200.computercraft.shared.command.CommandComputerCraft; | ||||
| import dan200.computercraft.shared.command.ContainerViewComputer; | ||||
| import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; | ||||
| import dan200.computercraft.shared.computer.blocks.TileComputer; | ||||
| import dan200.computercraft.shared.computer.core.*; | ||||
| import dan200.computercraft.shared.computer.inventory.ContainerComputer; | ||||
| 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.datafix.Fixes; | ||||
| import dan200.computercraft.shared.integration.charset.IntegrationCharset; | ||||
| import dan200.computercraft.shared.media.common.DefaultMediaProvider; | ||||
| import dan200.computercraft.shared.media.inventory.ContainerHeldItem; | ||||
| import dan200.computercraft.shared.media.items.ItemPrintout; | ||||
| import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheralProvider; | ||||
| import dan200.computercraft.shared.peripheral.common.DefaultPeripheralProvider; | ||||
| import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; | ||||
| import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; | ||||
| import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; | ||||
| 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.turtle.blocks.TileTurtle; | ||||
| import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; | ||||
| import dan200.computercraft.shared.media.items.RecordMedia; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import dan200.computercraft.shared.network.NetworkHandler; | ||||
| import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheral; | ||||
| import dan200.computercraft.shared.turtle.core.TurtlePlayer; | ||||
| import dan200.computercraft.shared.util.CreativeTabMain; | ||||
| import dan200.computercraft.shared.wired.CapabilityWiredElement; | ||||
| import net.minecraft.command.CommandHandler; | ||||
| import net.minecraft.creativetab.CreativeTabs; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Container; | ||||
| import net.minecraft.item.Item; | ||||
| import net.minecraft.item.ItemRecord; | ||||
| import net.minecraft.server.MinecraftServer; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
| import net.minecraft.tileentity.TileEntityCommandBlock; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraftforge.event.entity.player.PlayerContainerEvent; | ||||
| import net.minecraftforge.fml.client.event.ConfigChangedEvent; | ||||
| import net.minecraftforge.fml.common.FMLCommonHandler; | ||||
| @@ -51,10 +43,8 @@ import net.minecraftforge.fml.common.Mod; | ||||
| import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||||
| import net.minecraftforge.fml.common.gameevent.TickEvent; | ||||
| import net.minecraftforge.fml.common.network.FMLNetworkEvent; | ||||
| import net.minecraftforge.fml.common.network.IGuiHandler; | ||||
| import net.minecraftforge.fml.common.network.NetworkRegistry; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import net.minecraftforge.fml.common.registry.EntityRegistry; | ||||
| import pl.asie.charset.ModCharset; | ||||
|  | ||||
| public class ComputerCraftProxyCommon implements IComputerCraftProxy | ||||
| @@ -62,15 +52,21 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy | ||||
|     @Override | ||||
|     public void preInit() | ||||
|     { | ||||
|         // Creative tab | ||||
|         NetworkHandler.setup(); | ||||
|  | ||||
|         ComputerCraft.mainCreativeTab = new CreativeTabMain( CreativeTabs.getNextID() ); | ||||
|  | ||||
|         EntityRegistry.registerModEntity( | ||||
|             new ResourceLocation( ComputerCraft.MOD_ID, "turtle_player" ), TurtlePlayer.class, "turtle_player", | ||||
|             0, ComputerCraft.instance, Integer.MAX_VALUE, Integer.MAX_VALUE, false | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void init() | ||||
|     { | ||||
|         registerProviders(); | ||||
|         NetworkRegistry.INSTANCE.registerGuiHandler( ComputerCraft.instance, new GuiHandler() ); | ||||
|         NetworkRegistry.INSTANCE.registerGuiHandler( ComputerCraft.instance, Containers.INSTANCE ); | ||||
|  | ||||
|         Fixes.register( FMLCommonHandler.instance().getDataFixer() ); | ||||
|         if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register(); | ||||
| @@ -86,162 +82,31 @@ public class ComputerCraftProxyCommon implements IComputerCraftProxy | ||||
|     private void registerProviders() | ||||
|     { | ||||
|         // Register peripheral providers | ||||
|         ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() ); | ||||
|         if( ComputerCraft.enableCommandBlock ) | ||||
|         { | ||||
|             ComputerCraftAPI.registerPeripheralProvider( new CommandBlockPeripheralProvider() ); | ||||
|         } | ||||
|         ComputerCraftAPI.registerPeripheralProvider( ( world, pos, side ) -> { | ||||
|             TileEntity tile = world.getTileEntity( pos ); | ||||
|             return tile instanceof IPeripheralTile ? ((IPeripheralTile) tile).getPeripheral( side ) : null; | ||||
|         } ); | ||||
|  | ||||
|         ComputerCraftAPI.registerPeripheralProvider( ( world, pos, side ) -> { | ||||
|             TileEntity tile = world.getTileEntity( pos ); | ||||
|             return ComputerCraft.enableCommandBlock && tile instanceof TileEntityCommandBlock ? new CommandBlockPeripheral( (TileEntityCommandBlock) tile ) : null; | ||||
|         } ); | ||||
|  | ||||
|         // Register bundled power providers | ||||
|         ComputerCraftAPI.registerBundledRedstoneProvider( new DefaultBundledRedstoneProvider() ); | ||||
|  | ||||
|         // Register media providers | ||||
|         ComputerCraftAPI.registerMediaProvider( new DefaultMediaProvider() ); | ||||
|         ComputerCraftAPI.registerMediaProvider( stack -> { | ||||
|             Item item = stack.getItem(); | ||||
|             if( item instanceof IMedia ) return (IMedia) item; | ||||
|             if( item instanceof ItemRecord ) return RecordMedia.INSTANCE; | ||||
|             return null; | ||||
|         } ); | ||||
|  | ||||
|         // Register network providers | ||||
|         CapabilityWiredElement.register(); | ||||
|     } | ||||
|  | ||||
|     public class GuiHandler implements IGuiHandler | ||||
|     { | ||||
|         private GuiHandler() | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         @Override | ||||
|         public Object getServerGuiElement( int id, EntityPlayer player, World world, int x, int y, int z ) | ||||
|         { | ||||
|             BlockPos pos = new BlockPos( x, y, z ); | ||||
|             switch( id ) | ||||
|             { | ||||
|                 case ComputerCraft.diskDriveGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     if( tile instanceof TileDiskDrive ) | ||||
|                     { | ||||
|                         TileDiskDrive drive = (TileDiskDrive) tile; | ||||
|                         return new ContainerDiskDrive( player.inventory, drive ); | ||||
|                     } | ||||
|                     break; | ||||
|                 } | ||||
|                 case ComputerCraft.computerGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     if( tile instanceof TileComputer ) | ||||
|                     { | ||||
|                         TileComputer computer = (TileComputer) tile; | ||||
|                         return new ContainerComputer( computer ); | ||||
|                     } | ||||
|                     break; | ||||
|                 } | ||||
|                 case ComputerCraft.printerGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     if( tile instanceof TilePrinter ) | ||||
|                     { | ||||
|                         TilePrinter printer = (TilePrinter) tile; | ||||
|                         return new ContainerPrinter( player.inventory, printer ); | ||||
|                     } | ||||
|                     break; | ||||
|                 } | ||||
|                 case ComputerCraft.turtleGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     if( tile instanceof TileTurtle ) | ||||
|                     { | ||||
|                         TileTurtle turtle = (TileTurtle) tile; | ||||
|                         return new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getServerComputer() ); | ||||
|                     } | ||||
|                     break; | ||||
|                 } | ||||
|                 case ComputerCraft.printoutGUIID: | ||||
|                 { | ||||
|                     return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.MAIN_HAND ); | ||||
|                 } | ||||
|                 case ComputerCraft.pocketComputerGUIID: | ||||
|                 { | ||||
|                     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; | ||||
|         } | ||||
|  | ||||
|         @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 ); | ||||
|             switch( id ) | ||||
|             { | ||||
|                 case ComputerCraft.diskDriveGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     return tile instanceof TileDiskDrive ? new GuiDiskDrive( new ContainerDiskDrive( player.inventory, (TileDiskDrive) tile ) ) : null; | ||||
|                 } | ||||
|                 case ComputerCraft.computerGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     return tile instanceof TileComputer ? new GuiComputer( (TileComputer) tile ) : null; | ||||
|                 } | ||||
|                 case ComputerCraft.printerGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     return tile instanceof TilePrinter ? new GuiPrinter( new ContainerPrinter( player.inventory, (TilePrinter) tile ) ) : null; | ||||
|                 } | ||||
|                 case ComputerCraft.turtleGUIID: | ||||
|                 { | ||||
|                     TileEntity tile = world.getTileEntity( pos ); | ||||
|                     if( tile instanceof TileTurtle ) | ||||
|                     { | ||||
|                         TileTurtle turtle = (TileTurtle) tile; | ||||
|                         return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess() ) ); | ||||
|                     } | ||||
|                     return null; | ||||
|                 } | ||||
|                 case ComputerCraft.printoutGUIID: | ||||
|                 { | ||||
|                     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: | ||||
|                 { | ||||
|                     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: | ||||
|                 { | ||||
|                     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(); | ||||
|                     } | ||||
|  | ||||
|                     ContainerViewComputer container = new ContainerViewComputer( computer ); | ||||
|                     return new GuiComputer( container, family, computer, width, height ); | ||||
|                 } | ||||
|                 default: | ||||
|                     return null; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID ) | ||||
|     public final static class ForgeHandlers | ||||
|     { | ||||
|   | ||||
| @@ -1,14 +0,0 @@ | ||||
| /* | ||||
|  * This file is part of ComputerCraft - http://www.computercraft.info | ||||
|  * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. | ||||
|  * Send enquiries to dratcliffe@gmail.com | ||||
|  */ | ||||
|  | ||||
| package dan200.computercraft.shared.proxy; | ||||
|  | ||||
| public interface ICCTurtleProxy | ||||
| { | ||||
|     void preInit(); | ||||
|  | ||||
|     void init(); | ||||
| } | ||||
| @@ -7,9 +7,12 @@ | ||||
| package dan200.computercraft.shared.turtle.blocks; | ||||
|  | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.turtle.TurtleSide; | ||||
| import dan200.computercraft.shared.computer.blocks.BlockComputerBase; | ||||
| import dan200.computercraft.shared.computer.blocks.TileComputerBase; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.turtle.core.TurtleBrain; | ||||
| import dan200.computercraft.shared.turtle.items.ITurtleItem; | ||||
| import dan200.computercraft.shared.turtle.items.TurtleItemFactory; | ||||
| import dan200.computercraft.shared.util.DirectionUtil; | ||||
| import net.minecraft.block.material.Material; | ||||
| @@ -25,6 +28,7 @@ import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumBlockRenderType; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraft.util.math.AxisAlignedBB; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.util.math.Vec3d; | ||||
| @@ -174,12 +178,40 @@ public class BlockTurtle extends BlockComputerBase | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack itemstack ) | ||||
|     public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase player, @Nonnull ItemStack stack ) | ||||
|     { | ||||
|         super.onBlockPlacedBy( world, pos, state, player, stack ); | ||||
|  | ||||
|         TileEntity tile = world.getTileEntity( pos ); | ||||
|         if( tile instanceof TileTurtle && player instanceof EntityPlayer ) | ||||
|         if( !world.isRemote && tile instanceof TileTurtle ) | ||||
|         { | ||||
|             ((TileTurtle) tile).setOwningPlayer( ((EntityPlayer) player).getGameProfile() ); | ||||
|             TileTurtle turtle = (TileTurtle) tile; | ||||
|  | ||||
|             if( player instanceof EntityPlayer ) | ||||
|             { | ||||
|                 ((TileTurtle) tile).setOwningPlayer( ((EntityPlayer) player).getGameProfile() ); | ||||
|             } | ||||
|  | ||||
|             if( stack.getItem() instanceof ITurtleItem ) | ||||
|             { | ||||
|                 ITurtleItem item = (ITurtleItem) stack.getItem(); | ||||
|  | ||||
|                 // Set Upgrades | ||||
|                 for( TurtleSide side : TurtleSide.values() ) | ||||
|                 { | ||||
|                     turtle.getAccess().setUpgrade( side, item.getUpgrade( stack, side ) ); | ||||
|                 } | ||||
|  | ||||
|                 turtle.getAccess().setFuelLevel( item.getFuelLevel( stack ) ); | ||||
|  | ||||
|                 // Set colour | ||||
|                 int colour = item.getColour( stack ); | ||||
|                 if( colour != -1 ) turtle.getAccess().setColour( colour ); | ||||
|  | ||||
|                 // Set overlay | ||||
|                 ResourceLocation overlay = item.getOverlay( stack ); | ||||
|                 if( overlay != null ) ((TurtleBrain) turtle.getAccess()).setOverlay( overlay ); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // Set direction | ||||
|   | ||||
| @@ -8,13 +8,16 @@ package dan200.computercraft.shared.turtle.blocks; | ||||
|  | ||||
| import com.mojang.authlib.GameProfile; | ||||
| import dan200.computercraft.ComputerCraft; | ||||
| import dan200.computercraft.api.peripheral.IPeripheral; | ||||
| import dan200.computercraft.api.turtle.ITurtleAccess; | ||||
| import dan200.computercraft.api.turtle.ITurtleUpgrade; | ||||
| import dan200.computercraft.api.turtle.TurtleSide; | ||||
| import dan200.computercraft.shared.computer.blocks.ComputerPeripheral; | ||||
| import dan200.computercraft.shared.computer.blocks.ComputerProxy; | ||||
| import dan200.computercraft.shared.computer.blocks.TileComputerBase; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.core.ServerComputer; | ||||
| import dan200.computercraft.shared.network.Containers; | ||||
| import dan200.computercraft.shared.turtle.apis.TurtleAPI; | ||||
| import dan200.computercraft.shared.turtle.core.TurtleBrain; | ||||
| import dan200.computercraft.shared.util.DefaultInventory; | ||||
| @@ -209,7 +212,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default | ||||
|     @Override | ||||
|     public void openGUI( EntityPlayer player ) | ||||
|     { | ||||
|         ComputerCraft.openTurtleGUI( player, this ); | ||||
|         Containers.openTurtleGUI( player, this ); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -560,7 +563,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default | ||||
|         return isUsable( player, false ); | ||||
|     } | ||||
|  | ||||
|     public void onInventoryDefinitelyChanged() | ||||
|     private void onInventoryDefinitelyChanged() | ||||
|     { | ||||
|         super.markDirty(); | ||||
|         m_inventoryChanged = true; | ||||
| @@ -618,6 +621,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default | ||||
|         copy.m_moveState = MoveState.MOVED; | ||||
|     } | ||||
|  | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public IPeripheral getPeripheral( @Nonnull EnumFacing side ) | ||||
|     { | ||||
|         return hasMoved() ? null : new ComputerPeripheral( "turtle", createProxy() ); | ||||
|     } | ||||
|  | ||||
|     public IItemHandlerModifiable getItemHandler() | ||||
|     { | ||||
|         return m_itemHandler; | ||||
|   | ||||
| @@ -12,20 +12,11 @@ import dan200.computercraft.api.turtle.TurtleSide; | ||||
| import dan200.computercraft.shared.TurtleUpgrades; | ||||
| import dan200.computercraft.shared.computer.core.ComputerFamily; | ||||
| import dan200.computercraft.shared.computer.items.ItemComputerBase; | ||||
| import dan200.computercraft.shared.turtle.blocks.ITurtleTile; | ||||
| import dan200.computercraft.shared.turtle.core.TurtleBrain; | ||||
| import dan200.computercraft.shared.util.StringUtil; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.creativetab.CreativeTabs; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.NonNullList; | ||||
| import net.minecraft.util.ResourceLocation; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraft.world.World; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
| @@ -66,63 +57,6 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean placeBlockAt( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState ) | ||||
|     { | ||||
|         if( super.placeBlockAt( stack, player, world, pos, side, hitX, hitY, hitZ, newState ) ) | ||||
|         { | ||||
|             TileEntity tile = world.getTileEntity( pos ); | ||||
|             if( tile instanceof ITurtleTile ) | ||||
|             { | ||||
|                 ITurtleTile turtle = (ITurtleTile) tile; | ||||
|                 setupTurtleAfterPlacement( stack, turtle ); | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public void setupTurtleAfterPlacement( @Nonnull ItemStack stack, ITurtleTile turtle ) | ||||
|     { | ||||
|         // Set ID | ||||
|         int id = getComputerID( stack ); | ||||
|         if( id >= 0 ) | ||||
|         { | ||||
|             turtle.setComputerID( id ); | ||||
|         } | ||||
|  | ||||
|         // Set Label | ||||
|         String label = getLabel( stack ); | ||||
|         if( label != null ) | ||||
|         { | ||||
|             turtle.setLabel( label ); | ||||
|         } | ||||
|  | ||||
|         // Set Upgrades | ||||
|         for( TurtleSide side : TurtleSide.values() ) | ||||
|         { | ||||
|             turtle.getAccess().setUpgrade( side, getUpgrade( stack, side ) ); | ||||
|         } | ||||
|  | ||||
|         // Set Fuel level | ||||
|         int fuelLevel = getFuelLevel( stack ); | ||||
|         turtle.getAccess().setFuelLevel( fuelLevel ); | ||||
|  | ||||
|         // Set colour | ||||
|         int colour = getColour( stack ); | ||||
|         if( colour != -1 ) | ||||
|         { | ||||
|             turtle.getAccess().setColour( colour ); | ||||
|         } | ||||
|  | ||||
|         // Set overlay | ||||
|         ResourceLocation overlay = getOverlay( stack ); | ||||
|         if( overlay != null ) | ||||
|         { | ||||
|             ((TurtleBrain) turtle.getAccess()).setOverlay( overlay ); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Nonnull | ||||
|     @Override | ||||
|     public String getTranslationKey( @Nonnull ItemStack stack ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 SquidDev
					SquidDev