From b2542289f0af1c176e9ed55fba7e9768a067bb62 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 1 May 2017 17:07:32 +0100 Subject: [PATCH 01/38] Require the player to be interacting with the computer when typing Packets will be discarded if the sending player is not currently interacting with the appropriate computer. This ensures players cannot control other people's computers. This is enforced by checking if the current container is a "computer container", and this container holds the correct computer. --- .../proxy/ComputerCraftProxyClient.java | 3 +- .../computer/core/IContainerComputer.java | 20 +++++++++++ .../shared/computer/core/ServerComputer.java | 12 +++++++ .../computer/inventory/ContainerComputer.java | 12 +++++++ .../shared/network/ComputerCraftPacket.java | 8 +++++ .../inventory/ContainerPocketComputer.java | 35 +++++++++++++++++++ .../pocket/items/ItemPocketComputer.java | 10 ++++++ .../proxy/ComputerCraftProxyCommon.java | 5 +-- .../turtle/inventory/ContainerTurtle.java | 19 ++++++++++ 9 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java create mode 100644 src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 58ce252e5..f6a438eb5 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -20,6 +20,7 @@ import dan200.computercraft.shared.network.ComputerCraftPacket; import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.peripheral.printer.TilePrinter; +import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon; import dan200.computercraft.shared.turtle.blocks.TileTurtle; @@ -325,7 +326,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon @Override public Object getPocketComputerGUI( EntityPlayer player, EnumHand hand ) { - ContainerHeldItem container = new ContainerHeldItem( player, hand ); + ContainerPocketComputer container = new ContainerPocketComputer( player, hand ); if( container.getStack() != null && container.getStack().getItem() instanceof ItemPocketComputer ) { return new GuiPocketComputer( container ); diff --git a/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java new file mode 100644 index 000000000..67f13f7d9 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java @@ -0,0 +1,20 @@ +package dan200.computercraft.shared.computer.core; + +import javax.annotation.Nullable; + +/** + * An instance of {@link net.minecraft.inventory.Container} which provides a computer. You should implement this + * if you provide custom computers/GUIs to interact with them. + */ +public interface IContainerComputer +{ + /** + * Get the computer you are interacting with. + * + * This will only be called on the server. + * + * @return The computer you are interacting with. + */ + @Nullable + IComputer getComputer(); +} diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java index 5f1c0ba17..4161afb7d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -20,6 +20,7 @@ import dan200.computercraft.shared.network.ComputerCraftPacket; import dan200.computercraft.shared.network.INetworkedThing; import dan200.computercraft.shared.util.NBTUtil; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -351,6 +352,17 @@ public class ServerComputer extends ServerTerminal @Override public void handlePacket( ComputerCraftPacket packet, EntityPlayer sender ) { + // Allow Computer/Tile updates as they may happen at any time. + if (packet.requiresContainer()) { + if (sender == null) return; + + Container container = sender.openContainer; + if (!(container instanceof IContainerComputer)) return; + + IComputer computer = ((IContainerComputer) container).getComputer(); + if (computer != this) return; + } + // Receive packets sent from the client to the server switch( packet.m_packetType ) { diff --git a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java index 4ff378a1c..d99c4ca8a 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java @@ -7,10 +7,15 @@ package dan200.computercraft.shared.computer.inventory; import dan200.computercraft.shared.computer.blocks.TileComputer; +import dan200.computercraft.shared.computer.core.IComputer; +import dan200.computercraft.shared.computer.core.IContainerComputer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import javax.annotation.Nullable; + public class ContainerComputer extends Container + implements IContainerComputer { private TileComputer m_computer; @@ -24,4 +29,11 @@ public class ContainerComputer extends Container { return m_computer.isUseableByPlayer( player ); } + + @Nullable + @Override + public IComputer getComputer() + { + return m_computer.getServerComputer(); + } } diff --git a/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java b/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java index 9b3ca1693..fdb16f8d9 100644 --- a/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java +++ b/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java @@ -224,4 +224,12 @@ public class ComputerCraftPacket } } } + + /** + * Determine whether this packet requires the player to be interacting with the + * target. + */ + public boolean requiresContainer() { + return m_packetType != RequestComputerUpdate && m_packetType != RequestTileEntityUpdate; + } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java new file mode 100644 index 000000000..2ec110ef3 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java @@ -0,0 +1,35 @@ +package dan200.computercraft.shared.pocket.inventory; + +import dan200.computercraft.shared.computer.core.IComputer; +import dan200.computercraft.shared.computer.core.IContainerComputer; +import dan200.computercraft.shared.media.inventory.ContainerHeldItem; +import dan200.computercraft.shared.pocket.items.ItemPocketComputer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; + +import javax.annotation.Nullable; + +public class ContainerPocketComputer extends ContainerHeldItem + implements IContainerComputer +{ + public ContainerPocketComputer( EntityPlayer player, EnumHand hand ) + { + super( player, hand ); + } + + @Nullable + @Override + public IComputer getComputer() + { + ItemStack stack = getStack(); + if( stack != null && stack.getItem() instanceof ItemPocketComputer ) + { + return ((ItemPocketComputer) stack.getItem()).getServerComputer( stack ); + } + else + { + return null; + } + } +} diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index 484c9ecdc..1e9371667 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -279,6 +279,16 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia return computer; } + public ServerComputer getServerComputer( ItemStack stack ) + { + int instanceID = getInstanceID( stack ); + if( instanceID >= 0 ) + { + return ComputerCraft.serverComputerRegistry.get( instanceID ); + } + return null; + } + public ClientComputer createClientComputer( ItemStack stack ) { int instanceID = getInstanceID( stack ); diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 4bafb6f5d..d51ac0393 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -42,6 +42,7 @@ import dan200.computercraft.shared.peripheral.modem.TileWirelessModem; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; 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.pocket.items.PocketComputerItemFactory; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; @@ -540,7 +541,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy if (tile != null && tile instanceof TileTurtle) { TileTurtle turtle = (TileTurtle) tile; - return new ContainerTurtle( player.inventory, turtle.getAccess() ); + return new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getServerComputer() ); } break; } @@ -550,7 +551,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy } case ComputerCraft.pocketComputerGUIID: { - return new ContainerHeldItem( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND ); + return new ContainerPocketComputer( player, x == 0 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND ); } } return null; diff --git a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java index 7c869215c..780144989 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java @@ -7,6 +7,8 @@ package dan200.computercraft.shared.turtle.inventory; import dan200.computercraft.api.turtle.ITurtleAccess; +import dan200.computercraft.shared.computer.core.IComputer; +import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.core.TurtleBrain; import net.minecraft.entity.player.EntityPlayer; @@ -16,7 +18,10 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import javax.annotation.Nullable; + public class ContainerTurtle extends Container + implements IContainerComputer { private static final int PROGRESS_ID_SELECTED_SLOT = 0; @@ -24,6 +29,7 @@ public class ContainerTurtle extends Container public final int m_turtleInvStartX; protected ITurtleAccess m_turtle; + private IComputer m_computer; private int m_selectedSlot; protected ContainerTurtle( IInventory playerInventory, ITurtleAccess turtle, int playerInvStartY, int turtleInvStartX ) @@ -71,6 +77,12 @@ public class ContainerTurtle extends Container this( playerInventory, turtle, 134, 175 ); } + public ContainerTurtle( IInventory playerInventory, ITurtleAccess turtle, IComputer computer ) + { + this( playerInventory, turtle ); + m_computer = computer; + } + public int getSelectedSlot() { return m_selectedSlot; @@ -178,4 +190,11 @@ public class ContainerTurtle extends Container } return null; } + + @Nullable + @Override + public IComputer getComputer() + { + return m_computer; + } } From 02ce111d9e484431742f38e5bff80bf7adad21dc Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 1 May 2017 21:43:24 +0100 Subject: [PATCH 02/38] Invert side when checking connectivity The side marks the direction relative to the wire, rather than the side of the block it is attempting to connect to. Therefore needs to be flipped. Closes #149 --- .../shared/computer/blocks/TileComputerBase.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 2da5f2a43..d75959d3d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -22,10 +22,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.EnumFacing; public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable @@ -143,7 +143,8 @@ public abstract class TileComputerBase extends TileGeneric @Override public boolean getRedstoneConnectivity( EnumFacing side ) { - int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) ); + if( side == null ) return false; + int localDir = remapLocalSide( DirectionUtil.toLocal( this, side.getOpposite() ) ); return !isRedstoneBlockedOnSide( localDir ); } From 876df6829407258c69118b9260e8c66267077574 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 1 May 2017 22:39:18 +0100 Subject: [PATCH 03/38] Rotate modem models 180 degrees Or pi radians. Or tau/2 radians. This ensures the main modem texture is facing towards the screen. --- .../computercraft/models/block/modem.json | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/computercraft/models/block/modem.json b/src/main/resources/assets/computercraft/models/block/modem.json index 552b746fc..6e5a3bcdd 100644 --- a/src/main/resources/assets/computercraft/models/block/modem.json +++ b/src/main/resources/assets/computercraft/models/block/modem.json @@ -16,5 +16,37 @@ "east": { "uv": [ 13, 2, 16, 14 ], "texture": "#front" } } } - ] + ], + "display": { + "gui": { + "rotation": [ 30, 45, 0 ], + "translation": [ 3.2, -2, 0], + "scale":[ 0.75, 0.75, 0.75 ] + }, + "ground": { + "rotation": [ 0, 0, 0 ], + "translation": [ 0, 3, 0], + "scale":[ 0.25, 0.25, 0.25 ] + }, + "fixed": { + "rotation": [ 0, 0, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.5, 0.5, 0.5 ] + }, + "thirdperson_righthand": { + "rotation": [ 75, 180, 0 ], + "translation": [ 0, 2.5, 0], + "scale": [ 0.375, 0.375, 0.375 ] + }, + "firstperson_righthand": { + "rotation": [ 0, 45, 0 ], + "translation": [ 0, 0, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + }, + "firstperson_lefthand": { + "rotation": [ 0, 45, 0 ], + "translation": [ 0, 0, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + } + } } From 2d0690e6255023d86a618cd1f605248392261d3e Mon Sep 17 00:00:00 2001 From: Lignum Date: Tue, 2 May 2017 00:05:42 +0200 Subject: [PATCH 04/38] Add file descriptor limit --- .../dan200/computercraft/ComputerCraft.java | 1 + .../core/filesystem/FileSystem.java | 79 +++++++++---------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 633f7abfd..7a6092d60 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -123,6 +123,7 @@ public class ComputerCraft public static int computerSpaceLimit = 1000 * 1000; public static int floppySpaceLimit = 125 * 1000; + public static int maximumFilesOpen = 128; // Blocks and Items public static class Blocks diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 31446be0d..7692bacc0 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -290,8 +290,8 @@ public class FileSystem } } - private Map m_mounts = new HashMap(); - private Set m_openFiles = new HashSet(); + private final Map m_mounts = new HashMap(); + private final Set m_openFiles = new HashSet(); public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException { @@ -649,6 +649,33 @@ public class FileSystem } } } + + private synchronized IMountedFile openFile( IMountedFile file ) throws FileSystemException + { + synchronized( m_openFiles ) + { + if( m_openFiles.size() >= 4 ) + { + throw new FileSystemException("Too many files already open"); + } + + m_openFiles.add( file ); + return file; + } + } + + private synchronized void closeFile( IMountedFile file, Closeable handle ) throws IOException + { + synchronized( m_openFiles ) + { + m_openFiles.remove( file ); + + if( handle != null ) + { + handle.close(); + } + } + } public synchronized IMountedFileNormal openForRead( String path ) throws FileSystemException { @@ -684,11 +711,7 @@ public class FileSystem @Override public void close() throws IOException { - synchronized( m_openFiles ) - { - m_openFiles.remove( this ); - reader.close(); - } + closeFile( this, reader ); } @Override @@ -697,11 +720,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - synchronized( m_openFiles ) - { - m_openFiles.add( file ); - } - return file; + return (IMountedFileNormal) openFile( file ); } return null; } @@ -744,11 +763,7 @@ public class FileSystem @Override public void close() throws IOException { - synchronized( m_openFiles ) - { - m_openFiles.remove( this ); - writer.close(); - } + closeFile( this, writer ); } @Override @@ -757,11 +772,7 @@ public class FileSystem writer.flush(); } }; - synchronized( m_openFiles ) - { - m_openFiles.add( file ); - } - return file; + return (IMountedFileNormal) openFile( file ); } return null; } @@ -790,11 +801,7 @@ public class FileSystem @Override public void close() throws IOException { - synchronized( m_openFiles ) - { - m_openFiles.remove( this ); - stream.close(); - } + closeFile( this, stream ); } @Override @@ -803,11 +810,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - synchronized( m_openFiles ) - { - m_openFiles.add( file ); - } - return file; + return (IMountedFileBinary) openFile( file ); } return null; } @@ -836,11 +839,7 @@ public class FileSystem @Override public void close() throws IOException { - synchronized( m_openFiles ) - { - m_openFiles.remove( this ); - stream.close(); - } + closeFile( this, stream ); } @Override @@ -849,11 +848,7 @@ public class FileSystem stream.flush(); } }; - synchronized( m_openFiles ) - { - m_openFiles.add( file ); - } - return file; + return (IMountedFileBinary) openFile( file ); } return null; } From 2a1e110a656ca090228fbbd33702921d426ffda8 Mon Sep 17 00:00:00 2001 From: Lignum Date: Tue, 2 May 2017 00:17:16 +0200 Subject: [PATCH 05/38] Make the file descriptor limit configurable --- src/main/java/dan200/computercraft/ComputerCraft.java | 4 ++++ .../java/dan200/computercraft/core/filesystem/FileSystem.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 7a6092d60..9035a30fc 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -242,6 +242,10 @@ public class ComputerCraft prop.setComment( "The disk space limit for floppy disks, in bytes" ); floppySpaceLimit = prop.getInt(); + prop = config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen); + prop.setComment( "How many files a computer can have open at the same time" ); + maximumFilesOpen = prop.getInt(); + prop = config.get(Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel); prop.setComment( "Set whether Turtles require fuel to move" ); turtlesNeedFuel = prop.getBoolean( turtlesNeedFuel ); diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 7692bacc0..03d61eb10 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -6,6 +6,7 @@ package dan200.computercraft.core.filesystem; +import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; @@ -654,7 +655,7 @@ public class FileSystem { synchronized( m_openFiles ) { - if( m_openFiles.size() >= 4 ) + if( m_openFiles.size() >= ComputerCraft.maximumFilesOpen ) { throw new FileSystemException("Too many files already open"); } From 6ff9db89cc510097ac60379862f23973101bdbed Mon Sep 17 00:00:00 2001 From: Lignum Date: Tue, 2 May 2017 00:44:33 +0200 Subject: [PATCH 06/38] Fix file handle leak --- .../core/filesystem/FileSystem.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 03d61eb10..55b542165 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -651,12 +651,20 @@ public class FileSystem } } - private synchronized IMountedFile openFile( IMountedFile file ) throws FileSystemException + private synchronized IMountedFile openFile( IMountedFile file, Closeable handle ) throws FileSystemException { synchronized( m_openFiles ) { if( m_openFiles.size() >= ComputerCraft.maximumFilesOpen ) { + if( handle != null ) + { + try { + handle.close(); + } catch ( IOException ignored ) { + // shrug + } + } throw new FileSystemException("Too many files already open"); } @@ -721,7 +729,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - return (IMountedFileNormal) openFile( file ); + return (IMountedFileNormal) openFile( file, reader ); } return null; } @@ -773,7 +781,7 @@ public class FileSystem writer.flush(); } }; - return (IMountedFileNormal) openFile( file ); + return (IMountedFileNormal) openFile( file, writer ); } return null; } @@ -811,7 +819,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - return (IMountedFileBinary) openFile( file ); + return (IMountedFileBinary) openFile( file, stream ); } return null; } @@ -849,7 +857,7 @@ public class FileSystem stream.flush(); } }; - return (IMountedFileBinary) openFile( file ); + return (IMountedFileBinary) openFile( file, stream ); } return null; } From c537c4fa782d3499323972bd93ee45973124e880 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 2 May 2017 02:12:51 +0100 Subject: [PATCH 07/38] Swap from builtin/generated to item/generated This model has more sane defaults, meaning items are scaled to the appropriate size. --- .../models/item/advanced_pocket_computer_blinking.json | 2 +- .../models/item/advanced_pocket_computer_blinking_modem_on.json | 2 +- .../computercraft/models/item/advanced_pocket_computer_off.json | 2 +- .../computercraft/models/item/advanced_pocket_computer_on.json | 2 +- .../models/item/advanced_pocket_computer_on_modem_on.json | 2 +- src/main/resources/assets/computercraft/models/item/book.json | 2 +- src/main/resources/assets/computercraft/models/item/disk.json | 2 +- .../assets/computercraft/models/item/diskExpanded.json | 2 +- src/main/resources/assets/computercraft/models/item/pages.json | 2 +- .../assets/computercraft/models/item/pocketComputer.json | 2 +- .../computercraft/models/item/pocket_computer_blinking.json | 2 +- .../models/item/pocket_computer_blinking_modem_on.json | 2 +- .../assets/computercraft/models/item/pocket_computer_on.json | 2 +- .../computercraft/models/item/pocket_computer_on_modem_on.json | 2 +- .../resources/assets/computercraft/models/item/printout.json | 2 +- .../assets/computercraft/models/item/treasureDisk.json | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json index 252819731..44d6ba418 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerBlinkAdvanced" } diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking_modem_on.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking_modem_on.json index 4ec4087a2..e7a01ae0b 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking_modem_on.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_blinking_modem_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerBlinkAdvanced", "layer1": "computercraft:items/pocketComputerModemLight" diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json index 89e50ed27..d5ef8c064 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_off.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerAdvanced" } diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json index a780c1341..5edc838c8 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerOnAdvanced" } diff --git a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on_modem_on.json b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on_modem_on.json index 36c773dee..da39d266c 100644 --- a/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on_modem_on.json +++ b/src/main/resources/assets/computercraft/models/item/advanced_pocket_computer_on_modem_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerOnAdvanced", "layer1": "computercraft:items/pocketComputerModemLight" diff --git a/src/main/resources/assets/computercraft/models/item/book.json b/src/main/resources/assets/computercraft/models/item/book.json index cdd2a3443..2ac563ec5 100644 --- a/src/main/resources/assets/computercraft/models/item/book.json +++ b/src/main/resources/assets/computercraft/models/item/book.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/book" } diff --git a/src/main/resources/assets/computercraft/models/item/disk.json b/src/main/resources/assets/computercraft/models/item/disk.json index 6ec1c6e27..6ba840c1c 100644 --- a/src/main/resources/assets/computercraft/models/item/disk.json +++ b/src/main/resources/assets/computercraft/models/item/disk.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/diskFrame", "layer1": "computercraft:items/diskColour" diff --git a/src/main/resources/assets/computercraft/models/item/diskExpanded.json b/src/main/resources/assets/computercraft/models/item/diskExpanded.json index 6ec1c6e27..6ba840c1c 100644 --- a/src/main/resources/assets/computercraft/models/item/diskExpanded.json +++ b/src/main/resources/assets/computercraft/models/item/diskExpanded.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/diskFrame", "layer1": "computercraft:items/diskColour" diff --git a/src/main/resources/assets/computercraft/models/item/pages.json b/src/main/resources/assets/computercraft/models/item/pages.json index 8f5ad1bd3..3994128f6 100644 --- a/src/main/resources/assets/computercraft/models/item/pages.json +++ b/src/main/resources/assets/computercraft/models/item/pages.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pageBundle" } diff --git a/src/main/resources/assets/computercraft/models/item/pocketComputer.json b/src/main/resources/assets/computercraft/models/item/pocketComputer.json index a6d6af9e9..a37fe6157 100644 --- a/src/main/resources/assets/computercraft/models/item/pocketComputer.json +++ b/src/main/resources/assets/computercraft/models/item/pocketComputer.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputer" } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json index 4beee93d1..2600d8049 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerBlink" } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking_modem_on.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking_modem_on.json index 811a959be..47a53343b 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking_modem_on.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_blinking_modem_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerBlink", "layer1": "computercraft:items/pocketComputerModemLight" diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json index 462ace6c0..6c7c827ea 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerOn" } diff --git a/src/main/resources/assets/computercraft/models/item/pocket_computer_on_modem_on.json b/src/main/resources/assets/computercraft/models/item/pocket_computer_on_modem_on.json index fa22de8bb..a08912c00 100644 --- a/src/main/resources/assets/computercraft/models/item/pocket_computer_on_modem_on.json +++ b/src/main/resources/assets/computercraft/models/item/pocket_computer_on_modem_on.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/pocketComputerOn", "layer1": "computercraft:items/pocketComputerModemLight" diff --git a/src/main/resources/assets/computercraft/models/item/printout.json b/src/main/resources/assets/computercraft/models/item/printout.json index cf7bd84ed..39027619e 100644 --- a/src/main/resources/assets/computercraft/models/item/printout.json +++ b/src/main/resources/assets/computercraft/models/item/printout.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/page" } diff --git a/src/main/resources/assets/computercraft/models/item/treasureDisk.json b/src/main/resources/assets/computercraft/models/item/treasureDisk.json index 6ec1c6e27..6ba840c1c 100644 --- a/src/main/resources/assets/computercraft/models/item/treasureDisk.json +++ b/src/main/resources/assets/computercraft/models/item/treasureDisk.json @@ -1,5 +1,5 @@ { - "parent": "builtin/generated", + "parent": "item/generated", "textures": { "layer0": "computercraft:items/diskFrame", "layer1": "computercraft:items/diskColour" From ba761a15b6dc56f9d2cf52b48c85fb52e185015f Mon Sep 17 00:00:00 2001 From: SquidDev Date: Tue, 2 May 2017 14:04:48 +0100 Subject: [PATCH 08/38] Send termination signals unless the computer is off If a shutdown has been queued, then the abort message was not set. This allowed for programs to run for a significantly longer period of time. --- src/main/java/dan200/computercraft/core/computer/Computer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/core/computer/Computer.java b/src/main/java/dan200/computercraft/core/computer/Computer.java index 6b3840e8f..847d49d1c 100644 --- a/src/main/java/dan200/computercraft/core/computer/Computer.java +++ b/src/main/java/dan200/computercraft/core/computer/Computer.java @@ -285,7 +285,7 @@ public class Computer { synchronized( this ) { - if( m_state == State.Running ) + if( m_state != State.Off && m_machine != null ) { if( hard ) { From 994dcd9f5859146e43a3c0988aeb8b50ae10d5e3 Mon Sep 17 00:00:00 2001 From: Lignum Date: Tue, 2 May 2017 18:29:50 +0200 Subject: [PATCH 09/38] Localise the maximumFilesOpen setting --- src/main/resources/assets/computercraft/lang/en_US.lang | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/assets/computercraft/lang/en_US.lang b/src/main/resources/assets/computercraft/lang/en_US.lang index 0c0098a58..98361fac9 100644 --- a/src/main/resources/assets/computercraft/lang/en_US.lang +++ b/src/main/resources/assets/computercraft/lang/en_US.lang @@ -56,3 +56,4 @@ gui.computercraft:config.turtle_fuel_limit=Turtle fuel limit gui.computercraft:config.advanced_turtle_fuel_limit=Advanced Turtle fuel limit gui.computercraft:config.turtles_obey_block_protection=Turtles obey block protection gui.computercraft:config.turtles_can_push=Turtles can push entities +gui.computercraft:config.maximum_files_open=Maximum files open per computer From bd8769f3002357cc4365066db040f2d2a8e9e33a Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Tue, 2 May 2017 23:40:31 +0200 Subject: [PATCH 10/38] Fix compilation error --- .../computercraft/shared/turtle/items/ItemTurtleBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java index 617a1836c..8ce4ca1cf 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java @@ -24,7 +24,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.translation.I18n;; +import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import java.util.ArrayList; From 5284b145f86faa5c2e717e0fce4d6779d9bccc75 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Wed, 3 May 2017 11:14:39 +0200 Subject: [PATCH 11/38] Handle tile entity changes --- .../shared/common/BlockGeneric.java | 15 +++++- .../shared/common/TileGeneric.java | 4 ++ .../computer/blocks/TileComputerBase.java | 51 +++++++++++++++---- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java index 0df9032ca..560c40dea 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java @@ -46,7 +46,7 @@ public abstract class BlockGeneric extends Block implements public final void dropBlockAsItemWithChance( World world, BlockPos pos, IBlockState state, float chance, int fortune ) { } - + @Override public final List getDrops( IBlockAccess world, BlockPos pos, IBlockState state, int fortune ) { @@ -107,7 +107,7 @@ public abstract class BlockGeneric extends Block implements { Block.spawnAsEntity( world, pos, stack ); } - + @Override public final void breakBlock( World world, BlockPos pos, IBlockState newState ) { @@ -162,6 +162,17 @@ public abstract class BlockGeneric extends Block implements } } + @Override + public final void onNeighborChange( IBlockAccess world, BlockPos pos, BlockPos neighbour ) + { + TileEntity tile = world.getTileEntity( pos ); + if( tile instanceof TileGeneric ) + { + TileGeneric generic = (TileGeneric)tile; + generic.onNeighbourTileEntityChange( neighbour ); + } + } + @Override public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side ) { diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index 2e86ec148..a8709b73a 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -95,6 +95,10 @@ public abstract class TileGeneric extends TileEntity { } + public void onNeighbourTileEntityChange( BlockPos neighbour ) + { + } + public boolean isSolidOnSide( int side ) { return true; diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 2da5f2a43..990b09cd9 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -196,6 +196,12 @@ public abstract class TileComputerBase extends TileGeneric updateInput(); } + @Override + public void onNeighbourTileEntityChange( BlockPos neighbour ) + { + updateInput( neighbour ); + } + @Override public void update() { @@ -307,6 +313,21 @@ public abstract class TileComputerBase extends TileGeneric return localSide; } + private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset ) + { + EnumFacing offsetSide = dir.getOpposite(); + int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) ); + if( !isRedstoneBlockedOnSide( localDir ) ) + { + computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) ); + computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) ); + } + if( !isPeripheralBlockedOnSide( localDir ) ) + { + computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) ); + } + } + public void updateInput() { if( worldObj == null || worldObj.isRemote ) @@ -315,6 +336,24 @@ public abstract class TileComputerBase extends TileGeneric } // Update redstone and peripherals + ServerComputer computer = getServerComputer(); + if( computer != null ) + { + BlockPos pos = computer.getPosition(); + for( EnumFacing dir : EnumFacing.VALUES ) + { + updateSideInput( computer, dir, pos.offset( dir ) ); + } + } + } + + public void updateInput( BlockPos neighbour ) + { + if( worldObj == null || worldObj.isRemote ) + { + return; + } + ServerComputer computer = getServerComputer(); if( computer != null ) { @@ -322,16 +361,10 @@ public abstract class TileComputerBase extends TileGeneric for( EnumFacing dir : EnumFacing.VALUES ) { BlockPos offset = pos.offset( dir ); - EnumFacing offsetSide = dir.getOpposite(); - int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) ); - if( !isRedstoneBlockedOnSide( localDir ) ) + if ( offset.equals( neighbour ) ) { - computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) ); - computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) ); - } - if( !isPeripheralBlockedOnSide( localDir ) ) - { - computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) ); + updateSideInput( computer, dir, offset ); + break; } } } From 4eb4bb933f33f93e309a4c5860f871ea00eb6bc3 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Wed, 3 May 2017 16:03:47 +0200 Subject: [PATCH 12/38] Different fix for shadow turtles --- .../shared/turtle/blocks/TileTurtle.java | 66 +++++++++++++++---- .../shared/turtle/core/TurtleBrain.java | 62 ++++++++++------- 2 files changed, 93 insertions(+), 35 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 31f42e4e9..67acc879a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -46,12 +46,19 @@ public class TileTurtle extends TileComputerBase public static final int INVENTORY_HEIGHT = 4; // Members - + + enum MoveState + { + NOT_MOVED, + IN_PROGRESS, + MOVED + } + private ItemStack[] m_inventory; private ItemStack[] m_previousInventory; private boolean m_inventoryChanged; private TurtleBrain m_brain; - private boolean m_moved; + private MoveState m_moveState; public TileTurtle() { @@ -59,12 +66,12 @@ public class TileTurtle extends TileComputerBase m_previousInventory = new ItemStack[ getSizeInventory() ]; m_inventoryChanged = false; m_brain = createBrain(); - m_moved = false; + m_moveState = MoveState.NOT_MOVED; } public boolean hasMoved() { - return m_moved; + return m_moveState == MoveState.MOVED; } protected TurtleBrain createBrain() @@ -276,6 +283,41 @@ public class TileTurtle extends TileComputerBase } } + @Override + public void onNeighbourChange() + { + if ( m_moveState == MoveState.NOT_MOVED ) + { + super.onNeighbourChange(); + } + } + + @Override + public void onNeighbourTileEntityChange(BlockPos neighbour) + { + if ( m_moveState == MoveState.NOT_MOVED ) + { + super.onNeighbourTileEntityChange( neighbour ); + } + } + + public void notifyMoveStart() + { + if (m_moveState == MoveState.NOT_MOVED) + { + m_moveState = MoveState.IN_PROGRESS; + } + } + + public void notifyMoveEnd() + { + // MoveState.MOVED is final + if (m_moveState == MoveState.IN_PROGRESS) + { + m_moveState = MoveState.NOT_MOVED; + } + } + @Override public void readFromNBT( NBTTagCompound nbttagcompound ) { @@ -401,7 +443,7 @@ public class TileTurtle extends TileComputerBase } // IInventory - + @Override public int getSizeInventory() { @@ -431,7 +473,7 @@ public class TileTurtle extends TileComputerBase return result; } } - + @Override public ItemStack decrStackSize( int slot, int count ) { @@ -447,13 +489,13 @@ public class TileTurtle extends TileComputerBase { return null; } - + if( stack.stackSize <= count ) { setInventorySlotContents( slot, null ); return stack; } - + ItemStack part = stack.splitStack( count ); onInventoryDefinitelyChanged(); return part; @@ -496,7 +538,7 @@ public class TileTurtle extends TileComputerBase } } } - + @Override public String getName() { @@ -550,7 +592,7 @@ public class TileTurtle extends TileComputerBase public void openInventory( EntityPlayer player ) { } - + @Override public void closeInventory( EntityPlayer player ) { @@ -561,7 +603,7 @@ public class TileTurtle extends TileComputerBase { return true; } - + @Override public void markDirty() { @@ -664,6 +706,6 @@ public class TileTurtle extends TileComputerBase m_inventoryChanged = copy.m_inventoryChanged; m_brain = copy.m_brain; m_brain.setOwner( this ); - copy.m_moved = true; + copy.m_moveState = MoveState.MOVED; } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 1c440d06f..737f96868 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -495,6 +495,7 @@ public class TurtleBrain implements ITurtleAccess // Cache info about the old turtle (so we don't access this after we delete ourselves) World oldWorld = getWorld(); + TileTurtle oldOwner = m_owner; BlockPos oldPos = m_owner.getPos(); Block oldBlock = m_owner.getBlock(); @@ -504,36 +505,51 @@ public class TurtleBrain implements ITurtleAccess return true; } - // Create a new turtle - if( world.isBlockLoaded( pos ) && world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) ) + if ( !world.isBlockLoaded( pos ) ) { - Block block = world.getBlockState( pos ).getBlock(); - if( block == oldBlock ) + return false; + } + + oldOwner.notifyMoveStart(); + + try + { + // Create a new turtle + if( world.setBlockState( pos, oldBlock.getDefaultState(), 0 ) ) { - TileEntity newTile = world.getTileEntity( pos ); - if( newTile != null && newTile instanceof TileTurtle ) + Block block = world.getBlockState( pos ).getBlock(); + if( block == oldBlock ) { - // Copy the old turtle state into the new turtle - TileTurtle newTurtle = (TileTurtle)newTile; - newTurtle.setWorldObj( world ); - newTurtle.setPos( pos ); - newTurtle.transferStateFrom( m_owner ); - newTurtle.createServerComputer().setWorld( world ); - newTurtle.createServerComputer().setPosition( pos ); + TileEntity newTile = world.getTileEntity( pos ); + if( newTile != null && newTile instanceof TileTurtle ) + { + // Copy the old turtle state into the new turtle + TileTurtle newTurtle = (TileTurtle)newTile; + newTurtle.setWorldObj( world ); + newTurtle.setPos( pos ); + newTurtle.transferStateFrom( oldOwner ); + newTurtle.createServerComputer().setWorld( world ); + newTurtle.createServerComputer().setPosition( pos ); - // Remove the old turtle - oldWorld.setBlockToAir( oldPos ); + // Remove the old turtle + oldWorld.setBlockToAir( oldPos ); - // Make sure everybody knows about it - newTurtle.updateBlock(); - newTurtle.updateInput(); - newTurtle.updateOutput(); - return true; + // Make sure everybody knows about it + newTurtle.updateBlock(); + newTurtle.updateInput(); + newTurtle.updateOutput(); + return true; + } } - } - // Something went wrong, remove the newly created turtle - world.setBlockToAir( pos ); + // Something went wrong, remove the newly created turtle + world.setBlockToAir( pos ); + } + } + finally + { + // whatever happens, unblock old turtle in case it's still in world + oldOwner.notifyMoveEnd(); } return false; From 7e5970673f1caa54bbf61649f3b4b3f37bceafb4 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 16:30:22 +0100 Subject: [PATCH 13/38] Ensure GPS coordinates are numbers Fixes #138 --- src/main/resources/assets/computercraft/lua/rom/apis/gps | 2 +- src/main/resources/assets/computercraft/lua/rom/apis/vector | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps b/src/main/resources/assets/computercraft/lua/rom/apis/gps index 9f7cb5fd0..5fabbd0dd 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps @@ -103,7 +103,7 @@ function locate( _nTimeout, _bDebug ) local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position - if type(tMessage) == "table" and #tMessage == 3 then + if type(tMessage) == "table" and #tMessage == 3 and type(tMessage[1]) == "number" and type(tMessage[2]) == "number" and type(tMessage[3]) == "number" then local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance } if _bDebug then print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) ) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/vector b/src/main/resources/assets/computercraft/lua/rom/apis/vector index e5d1a981a..29b10e500 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/vector +++ b/src/main/resources/assets/computercraft/lua/rom/apis/vector @@ -76,9 +76,9 @@ local vmetatable = { function new( x, y, z ) local v = { - x = x or 0, - y = y or 0, - z = z or 0 + x = type(x) == "number" and x or 0, + y = type(y) == "number" and y or 0, + z = type(z) == "number" and z or 0 } setmetatable( v, vmetatable ) return v From a021a072b506dcfeae0390c8de0dbefa7a90f231 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 17:28:54 +0100 Subject: [PATCH 14/38] Allow turtle upgrades to act as tools and peripherals This may be useful when you want your tool to also provide additional methods. For instance, a pickaxe could provide methods to check whether it can break the block in front. --- .../api/turtle/TurtleUpgradeType.java | 18 ++++++++++++++++++ .../shared/proxy/CCTurtleProxyCommon.java | 2 +- .../shared/turtle/blocks/TileTurtle.java | 2 +- .../shared/turtle/core/TurtleBrain.java | 2 +- .../shared/turtle/core/TurtleToolCommand.java | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java index d86982368..4a6ea5a50 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -24,4 +24,22 @@ public enum TurtleUpgradeType * and can be interacted with the peripheral API (Such as the modem on Wireless Turtles). */ Peripheral, + + /** + * An upgrade which provides both a tool and a peripheral. This can be used when you wish + * your upgrade to also provide methods. For example, a pickaxe could provide methods + * determining whether it can break the given block or not. + */ + Both, + ; + + public boolean isTool() + { + return this == Tool || this == Both; + } + + public boolean isPeripheral() + { + return this == Peripheral || this == Both; + } } diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index f6c26650e..cdad31e62 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -126,7 +126,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy { if( family == ComputerFamily.Beginners ) { - return upgrade.getType() == TurtleUpgradeType.Tool; + return upgrade.getType().isTool(); } else { diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 31f42e4e9..04ba6f5dc 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -649,7 +649,7 @@ public class TileTurtle extends TileComputerBase case 5: upgrade = getUpgrade( TurtleSide.Left ); break; default: return false; } - if( upgrade != null && upgrade.getType() == TurtleUpgradeType.Peripheral ) + if( upgrade != null && upgrade.getType().isPeripheral() ) { return true; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 1c440d06f..72333e4dd 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -950,7 +950,7 @@ public class TurtleBrain implements ITurtleAccess { ITurtleUpgrade upgrade = getUpgrade( side ); IPeripheral peripheral = null; - if( upgrade != null && upgrade.getType() == TurtleUpgradeType.Peripheral ) + if( upgrade != null && upgrade.getType().isPeripheral() ) { peripheral = upgrade.createPeripheral( this, side ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleToolCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleToolCommand.java index 4469b3939..83a78c567 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleToolCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleToolCommand.java @@ -31,7 +31,7 @@ public class TurtleToolCommand implements ITurtleCommand if( !m_side.isPresent() || m_side.get() == side ) { ITurtleUpgrade upgrade = turtle.getUpgrade( side ); - if( upgrade != null && upgrade.getType() == TurtleUpgradeType.Tool ) + if( upgrade != null && upgrade.getType().isTool() ) { TurtleCommandResult result = upgrade.useTool( turtle, side, m_verb, m_direction.toWorldDir( turtle ) ); if( result.isSuccess() ) From 67eecd4b1c277195d8e0fc1e0bd62f2c125c94aa Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 18:21:14 +0100 Subject: [PATCH 15/38] Use tonumber instead of checking type --- src/main/resources/assets/computercraft/lua/rom/apis/vector | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/vector b/src/main/resources/assets/computercraft/lua/rom/apis/vector index 29b10e500..2fd2fbdb6 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/vector +++ b/src/main/resources/assets/computercraft/lua/rom/apis/vector @@ -76,9 +76,9 @@ local vmetatable = { function new( x, y, z ) local v = { - x = type(x) == "number" and x or 0, - y = type(y) == "number" and y or 0, - z = type(z) == "number" and z or 0 + x = tonumber(x) or 0, + y = tonumber(y) or 0, + z = tonumber(z) or 0 } setmetatable( v, vmetatable ) return v From 6b6829e22bcc34427c687d0d382efb2933914816 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 18:39:32 +0100 Subject: [PATCH 16/38] Use tonumber when validating message format --- src/main/resources/assets/computercraft/lua/rom/apis/gps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/gps b/src/main/resources/assets/computercraft/lua/rom/apis/gps index 5fabbd0dd..eede2679a 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/gps +++ b/src/main/resources/assets/computercraft/lua/rom/apis/gps @@ -103,7 +103,7 @@ function locate( _nTimeout, _bDebug ) local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position - if type(tMessage) == "table" and #tMessage == 3 and type(tMessage[1]) == "number" and type(tMessage[2]) == "number" and type(tMessage[3]) == "number" then + if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance } if _bDebug then print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) ) From 72dfb0e7cc9844a35406f06781b5273303e59f2a Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 3 May 2017 22:27:38 +0100 Subject: [PATCH 17/38] Sort the result of FileSystem.list This ensures fs.list and fs.find always return the same result. For some reason, the ComputerCraft jar was being packaged differently on some platforms, causing files to appear in a different order. As computers depend on the colors API being loaded before colours, we need to ensure that they are loaded in a consistent order. --- .../java/dan200/computercraft/core/filesystem/FileSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 31446be0d..46ca3dc74 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -10,7 +10,6 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import java.io.*; -import java.nio.charset.Charset; import java.util.*; import java.util.regex.Pattern; @@ -441,6 +440,7 @@ public class FileSystem // Return list String[] array = new String[ list.size() ]; list.toArray(array); + Arrays.sort( array ); return array; } From bd14223ea86e607bfe5e3cbeb02d33542c0c2ec9 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Thu, 4 May 2017 10:49:41 +0100 Subject: [PATCH 18/38] Manually specify the number of values to unpack table.unpack will often stop at the first nil value, meaning some event arguments may be discarded. By storing the number of arguments through table.pack, and then using that count when unpacking, we can ensure all values are returned/resumed with. --- src/main/resources/assets/computercraft/lua/bios.lua | 8 ++++---- .../assets/computercraft/lua/rom/apis/parallel | 6 +++--- .../computercraft/lua/rom/programs/advanced/multishell | 10 +++++----- .../assets/computercraft/lua/rom/programs/monitor | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/resources/assets/computercraft/lua/bios.lua b/src/main/resources/assets/computercraft/lua/bios.lua index 5b4a10f52..3218f6d64 100644 --- a/src/main/resources/assets/computercraft/lua/bios.lua +++ b/src/main/resources/assets/computercraft/lua/bios.lua @@ -175,11 +175,11 @@ function os.pullEventRaw( sFilter ) end function os.pullEvent( sFilter ) - local eventData = { os.pullEventRaw( sFilter ) } + local eventData = table.pack( os.pullEventRaw( sFilter ) ) if eventData[1] == "terminate" then error( "Terminated", 0 ) end - return table.unpack( eventData ) + return table.unpack( eventData, 1, eventData.n ) end -- Install globals @@ -550,13 +550,13 @@ end -- Install the rest of the OS api function os.run( _tEnv, _sPath, ... ) - local tArgs = { ... } + local tArgs = table.pack( ... ) local tEnv = _tEnv setmetatable( tEnv, { __index = _G } ) local fnFile, err = loadfile( _sPath, tEnv ) if fnFile then local ok, err = pcall( function() - fnFile( table.unpack( tArgs ) ) + fnFile( table.unpack( tArgs, 1, tArgs.n ) ) end ) if not ok then if err and err ~= "" then diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/parallel b/src/main/resources/assets/computercraft/lua/rom/apis/parallel index db63a3ec5..5c2d06faf 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/parallel +++ b/src/main/resources/assets/computercraft/lua/rom/apis/parallel @@ -14,13 +14,13 @@ local function runUntilLimit( _routines, _limit ) local living = count local tFilters = {} - local eventData = {} + local eventData = { n = 0 } while true do for n=1,count do local r = _routines[n] if r then if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then - local ok, param = coroutine.resume( r, table.unpack(eventData) ) + local ok, param = coroutine.resume( r, table.unpack( eventData, 1, eventData.n ) ) if not ok then error( param, 0 ) else @@ -46,7 +46,7 @@ local function runUntilLimit( _routines, _limit ) end end end - eventData = { os.pullEventRaw() } + eventData = table.pack( os.pullEventRaw() ) end end diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell index cf73b35bd..15c58cb4f 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell +++ b/src/main/resources/assets/computercraft/lua/rom/programs/advanced/multishell @@ -47,7 +47,7 @@ local function resumeProcess( nProcess, sEvent, ... ) end local function launchProcess( tProgramEnv, sProgramPath, ... ) - local tProgramArgs = { ... } + local tProgramArgs = table.pack( ... ) local nProcess = #tProcesses + 1 local tProcess = {} tProcess.sTitle = fs.getName( sProgramPath ) @@ -57,7 +57,7 @@ local function launchProcess( tProgramEnv, sProgramPath, ... ) tProcess.window = window.create( parentTerm, 1, 1, w, h, false ) end tProcess.co = coroutine.create( function() - os.run( tProgramEnv, sProgramPath, table.unpack( tProgramArgs ) ) + os.run( tProgramEnv, sProgramPath, table.unpack( tProgramArgs, 1, tProgramArgs.n ) ) if not tProcess.bInteracted then term.setCursorBlink( false ) print( "Press any key to continue" ) @@ -222,7 +222,7 @@ redrawMenu() -- Run processes while #tProcesses > 0 do -- Get the event - local tEventData = { os.pullEventRaw() } + local tEventData = table.pack( os.pullEventRaw() ) local sEvent = tEventData[1] if sEvent == "term_resize" then -- Resize event @@ -233,7 +233,7 @@ while #tProcesses > 0 do elseif sEvent == "char" or sEvent == "key" or sEvent == "key_up" or sEvent == "paste" or sEvent == "terminate" then -- Keyboard event -- Passthrough to current process - resumeProcess( nCurrentProcess, table.unpack( tEventData ) ) + resumeProcess( nCurrentProcess, table.unpack( tEventData, 1, tEventData.n ) ) if cullProcess( nCurrentProcess ) then setMenuVisible( #tProcesses >= 2 ) redrawMenu() @@ -280,7 +280,7 @@ while #tProcesses > 0 do -- Passthrough to all processes local nLimit = #tProcesses -- Storing this ensures any new things spawned don't get the event for n=1,nLimit do - resumeProcess( n, table.unpack( tEventData ) ) + resumeProcess( n, table.unpack( tEventData, 1, tEventData.n ) ) end if cullProcesses() then setMenuVisible( #tProcesses >= 2 ) diff --git a/src/main/resources/assets/computercraft/lua/rom/programs/monitor b/src/main/resources/assets/computercraft/lua/rom/programs/monitor index bf123516d..2cb47ada4 100644 --- a/src/main/resources/assets/computercraft/lua/rom/programs/monitor +++ b/src/main/resources/assets/computercraft/lua/rom/programs/monitor @@ -43,13 +43,13 @@ end local ok, param = pcall( function() local sFilter = resume() while coroutine.status( co ) ~= "dead" do - local tEvent = { os.pullEventRaw() } + local tEvent = table.pack( os.pullEventRaw() ) if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then - sFilter = resume( table.unpack( tEvent ) ) + sFilter = resume( table.unpack( tEvent, 1, tEvent.n ) ) end if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then if tEvent[1] == "monitor_touch" and tEvent[2] == sName then - sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3 ) ) + sFilter = resume( "mouse_click", 1, table.unpack( tEvent, 3, tEvent.n ) ) end end if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then From a57eb141136de7fabc9b8d14af4a75cd5b45e80a Mon Sep 17 00:00:00 2001 From: Daniel Ratcliffe Date: Thu, 4 May 2017 21:14:28 +0100 Subject: [PATCH 19/38] Added windows setup script --- gradlew.bat | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.bat | 7 +++++ 2 files changed, 97 insertions(+) create mode 100644 gradlew.bat create mode 100644 setup.bat diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..02808bd10 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-d64 -Xmx2048m" + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/setup.bat b/setup.bat new file mode 100644 index 000000000..a46aebd45 --- /dev/null +++ b/setup.bat @@ -0,0 +1,7 @@ +echo "Setting up IntelliJ development environment with gradle..." +rmdir /s /q .\build +call gradlew.bat --stacktrace setupDecompWorkspace --refresh-dependencies +call gradlew.bat --stacktrace cleanIdea idea + +echo "Done." +pause \ No newline at end of file From 30d191df0b2ff287c28cc6bab8c11a763baad0e7 Mon Sep 17 00:00:00 2001 From: Lignum Date: Thu, 4 May 2017 23:00:02 +0200 Subject: [PATCH 20/38] Avoid casts with generic type args --- .../computercraft/core/filesystem/FileSystem.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 55b542165..0c1b3a461 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -651,7 +651,7 @@ public class FileSystem } } - private synchronized IMountedFile openFile( IMountedFile file, Closeable handle ) throws FileSystemException + private synchronized T openFile(T file, Closeable handle) throws FileSystemException { synchronized( m_openFiles ) { @@ -729,7 +729,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - return (IMountedFileNormal) openFile( file, reader ); + return openFile( file, reader ); } return null; } @@ -781,7 +781,7 @@ public class FileSystem writer.flush(); } }; - return (IMountedFileNormal) openFile( file, writer ); + return openFile( file, writer ); } return null; } @@ -819,7 +819,7 @@ public class FileSystem throw new UnsupportedOperationException(); } }; - return (IMountedFileBinary) openFile( file, stream ); + return openFile( file, stream ); } return null; } @@ -857,7 +857,7 @@ public class FileSystem stream.flush(); } }; - return (IMountedFileBinary) openFile( file, stream ); + return openFile( file, stream ); } return null; } From 8abff95441b87df733df839eca6c373513e0487b Mon Sep 17 00:00:00 2001 From: Daniel Ratcliffe Date: Thu, 4 May 2017 22:01:32 +0100 Subject: [PATCH 21/38] Peripherals no longer break turtle<->redstone connectivity I can't think of a good reason for this feature tbh --- .../dan200/computercraft/shared/turtle/blocks/TileTurtle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index f368b59af..f37afecda 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -376,7 +376,7 @@ public class TileTurtle extends TileComputerBase @Override protected boolean isRedstoneBlockedOnSide( int localSide ) { - return hasPeripheralUpgradeOnSide( localSide ); + return false; } // IDirectionalTile From 933bdcc6b7e1d11037214d522641ccee3ec49a06 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Thu, 4 May 2017 22:24:39 +0100 Subject: [PATCH 22/38] Make monitor text glow in the dark --- .../computercraft/client/render/TileEntityMonitorRenderer.java | 2 ++ src/main/resources/assets/computercraft/lua/rom/help/changelog | 1 + src/main/resources/assets/computercraft/lua/rom/help/whatsnew | 1 + 3 files changed, 4 insertions(+) diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index fffdc7b68..3aa900d04 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -104,6 +104,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer Date: Thu, 4 May 2017 23:38:24 +0200 Subject: [PATCH 23/38] Use GlStateManager where necessary, replace GL_QUADS with GL_TRIANGLE_STRIP --- .../proxy/ComputerCraftProxyClient.java | 3 +- .../render/TileEntityMonitorRenderer.java | 60 +++++++++---------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index f6a438eb5..0897cdecd 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -27,6 +27,7 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.entity.TurtleVisionCamera; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; @@ -256,7 +257,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon @Override public void deleteDisplayLists( int list, int range ) { - GL11.glDeleteLists( list, range ); + GlStateManager.glDeleteLists( list, range ); } @Override diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index fffdc7b68..9b0129a46 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -11,7 +11,6 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.common.ClientTerminal; -import dan200.computercraft.shared.common.ITerminal; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.DirectionUtil; @@ -21,11 +20,8 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL11; public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer @@ -111,7 +107,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer Date: Thu, 4 May 2017 23:39:12 +0200 Subject: [PATCH 24/38] Add ".idea" to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1aa8828b3..21b37972c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ deploy *.ipr *.iws *.iml +.idea .gradle luaj-2.0.3/lib luaj-2.0.3/*.jar From 2d5d5e3a9e1b5b7a1c29a3861158fd4caf387e18 Mon Sep 17 00:00:00 2001 From: Lignum Date: Thu, 4 May 2017 23:43:05 +0200 Subject: [PATCH 25/38] Use GL_TRIANGLES in FixedWidthFontRenderer --- .../client/gui/FixedWidthFontRenderer.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 91838519d..7c1e3969f 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -35,19 +35,23 @@ public class FixedWidthFontRenderer int column = index % 16; int row = index / 16; Colour colour = Colour.values()[ 15 - color ]; + renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) ((row + 1) * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (double) ((column + 1) * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y, 0.0 ).tex( (double) (column * FONT_WIDTH) / 256.0, (double) (row * FONT_HEIGHT ) / 256.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); } private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width ) { Colour colour = Colour.values()[ 15 - color ]; + renderer.pos( x, y, 0.0 ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).tex( 1.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y, 0.0 ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); } private boolean isGreyScale( int colour ) @@ -60,7 +64,7 @@ public class FixedWidthFontRenderer // Draw the quads Tessellator tessellator = Tessellator.getInstance(); VertexBuffer renderer = tessellator.getBuffer(); - renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); + renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR ); if( leftMarginSize > 0.0 ) { int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) ); @@ -96,7 +100,7 @@ public class FixedWidthFontRenderer // Draw the quads Tessellator tessellator = Tessellator.getInstance(); VertexBuffer renderer = tessellator.getBuffer(); - renderer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR ); + renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR ); for( int i = 0; i < s.length(); i++ ) { // Switch colour From 7e71045c7b2a1e7136ea9e70ff9327715c4fc207 Mon Sep 17 00:00:00 2001 From: Lignum Date: Thu, 4 May 2017 23:49:08 +0200 Subject: [PATCH 26/38] Remove texture coordinates from text background part --- .../client/gui/FixedWidthFontRenderer.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 7c1e3969f..12335f9f5 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -8,6 +8,7 @@ package dan200.computercraft.client.gui; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Colour; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.texture.TextureManager; @@ -46,12 +47,12 @@ public class FixedWidthFontRenderer private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width ) { Colour colour = Colour.values()[ 15 - color ]; - renderer.pos( x, y, 0.0 ).tex( 0.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y, 0.0 ).tex( 1.0, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( 0.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); - renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).tex( 1.0, 1.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + width, y, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); + renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).color( colour.getR(), colour.getG(), colour.getB(), 1.0f ).endVertex(); } private boolean isGreyScale( int colour ) @@ -64,7 +65,7 @@ public class FixedWidthFontRenderer // Draw the quads Tessellator tessellator = Tessellator.getInstance(); VertexBuffer renderer = tessellator.getBuffer(); - renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR ); + renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR ); if( leftMarginSize > 0.0 ) { int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) ); @@ -92,7 +93,9 @@ public class FixedWidthFontRenderer } drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH ); } + GlStateManager.disableTexture2D(); tessellator.draw(); + GlStateManager.enableTexture2D(); } public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale ) From 4e3def39e096aaf53089e90efd56a45bc226ce3b Mon Sep 17 00:00:00 2001 From: Lignum Date: Thu, 4 May 2017 23:53:43 +0200 Subject: [PATCH 27/38] Render terminal cursor in a less awkward way The previous way seemed weird enough to seem to have had a purpose, but I can't tell. Revert this if it turns out that there was. --- .../client/gui/widgets/WidgetTerminal.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java index 9eb6ddbb4..0d7add8e9 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -407,23 +407,22 @@ public class WidgetTerminal extends Widget TextBuffer colour = terminal.getTextColourLine( line ); TextBuffer backgroundColour = terminal.getBackgroundColourLine( line ); fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale ); - if( tblink && ty == line ) - { - if( tx >= 0 && tx < tw ) - { - TextBuffer cursor = new TextBuffer( '_', 1 ); - TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 ); - fontRenderer.drawString( - cursor, - x + FixedWidthFontRenderer.FONT_WIDTH * tx, - y, - cursorColour, null, - 0, 0, - greyscale - ); - } - } - y = y + FixedWidthFontRenderer.FONT_HEIGHT; + y += FixedWidthFontRenderer.FONT_HEIGHT; + } + + if( tblink ) + { + TextBuffer cursor = new TextBuffer( '_', 1 ); + TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 ); + + fontRenderer.drawString( + cursor, + x + FixedWidthFontRenderer.FONT_WIDTH * tx, + startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty, + cursorColour, null, + 0, 0, + greyscale + ); } } } From 4b8493baaba883957cad874efc89437db7a61800 Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 00:08:10 +0200 Subject: [PATCH 28/38] Terminal cursor bounds checking --- .../dan200/computercraft/client/gui/widgets/WidgetTerminal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java index 0d7add8e9..7325c9944 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -410,7 +410,7 @@ public class WidgetTerminal extends Widget y += FixedWidthFontRenderer.FONT_HEIGHT; } - if( tblink ) + if( tblink && tx >= 0 && ty >= 0 && tx < tw && ty < th ) { TextBuffer cursor = new TextBuffer( '_', 1 ); TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 ); From 2436d813e62ebff05e0985893f9ad3074c550900 Mon Sep 17 00:00:00 2001 From: Daniel Ratcliffe Date: Thu, 4 May 2017 22:15:26 +0100 Subject: [PATCH 29/38] Treat a maximumFilesOpen values of 0 as unlimited --- src/main/java/dan200/computercraft/ComputerCraft.java | 2 +- .../java/dan200/computercraft/core/filesystem/FileSystem.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index e3ff343ff..710094ecd 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -263,7 +263,7 @@ public class ComputerCraft Config.turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" ); Config.maximumFilesOpen = Config.config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen); - Config.maximumFilesOpen.setComment( "How many files a computer can have open at the same time" ); + Config.maximumFilesOpen.setComment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." ); Config.turtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit ); Config.turtleFuelLimit.setComment( "The fuel limit for Turtles" ); diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 281840dd8..0ba626dc9 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -655,7 +655,8 @@ public class FileSystem { synchronized( m_openFiles ) { - if( m_openFiles.size() >= ComputerCraft.maximumFilesOpen ) + if( ComputerCraft.maximumFilesOpen > 0 && + m_openFiles.size() >= ComputerCraft.maximumFilesOpen ) { if( handle != null ) { From 42f2235d45e1c478543d6a630fbe34aa1b4881c4 Mon Sep 17 00:00:00 2001 From: Daniel Ratcliffe Date: Thu, 4 May 2017 23:45:27 +0100 Subject: [PATCH 30/38] Made the black colour on monitors, terminals, block and item graphics darker 0x111111 is now used throughout, previously there was quite a bit of variance --- .../computercraft/shared/util/Colour.java | 2 +- .../textures/blocks/advMonitor15.png | Bin 414 -> 416 bytes .../textures/blocks/commandComputerFront.png | Bin 484 -> 503 bytes .../blocks/commandComputerFrontBlink.png | Bin 615 -> 633 bytes .../textures/blocks/commandComputerFrontOn.png | Bin 507 -> 525 bytes .../textures/blocks/computerFront.png | Bin 297 -> 421 bytes .../textures/blocks/computerFrontAdvanced.png | Bin 455 -> 456 bytes .../textures/blocks/computerFrontBlink.png | Bin 467 -> 501 bytes .../blocks/computerFrontBlinkAdvanced.png | Bin 534 -> 534 bytes .../textures/blocks/computerFrontOn.png | Bin 304 -> 439 bytes .../textures/blocks/computerFrontOnAdvanced.png | Bin 477 -> 475 bytes .../computercraft/textures/blocks/monitor15.png | Bin 278 -> 381 bytes .../textures/items/pocketComputer.png | Bin 216 -> 216 bytes .../textures/items/pocketComputerAdvanced.png | Bin 219 -> 219 bytes .../textures/items/pocketComputerBlink.png | Bin 264 -> 264 bytes .../items/pocketComputerBlinkAdvanced.png | Bin 266 -> 266 bytes .../textures/items/pocketComputerOn.png | Bin 240 -> 240 bytes .../textures/items/pocketComputerOnAdvanced.png | Bin 242 -> 243 bytes 18 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/shared/util/Colour.java b/src/main/java/dan200/computercraft/shared/util/Colour.java index b154046b8..957735324 100644 --- a/src/main/java/dan200/computercraft/shared/util/Colour.java +++ b/src/main/java/dan200/computercraft/shared/util/Colour.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.util; public enum Colour { - Black( 0x191919 ), + Black( 0x111111 ), Red( 0xcc4c4c ), Green( 0x57A64E ), Brown( 0x7f664c ), diff --git a/src/main/resources/assets/computercraft/textures/blocks/advMonitor15.png b/src/main/resources/assets/computercraft/textures/blocks/advMonitor15.png index d507568fb73a3ba61c6e3915f871c3129ce85ced..ca44e6714d7eeb13d32e13d7b6ee120cf2b47488 100644 GIT binary patch delta 323 zcmV-J0lfa61E2$tQ4Zk+1QsS3o>#sQ0003kkzW~q+ya@%2Ox)#Q*aa_4zTxFX#=hR zrx=Z7d#1ap2-@0}&?e2#DyXMlrT=BO+l83{;O>|i5rMk{a6BFvh5<9f%s8D+EX%@X zv!Rqi0{HdzK!~B@L^47GkpL7b=dAN!4ip}rf0M>>gv-L+{VOec|MP^qqbViOg;uF1 z=6Obc*XuP%^FC36oHII26BgPI==hgxW2h1rBog8gA<|z<2arHHIQw9;sA)N zj7G9O(_K{rZGp5RX?|8gJ^d>EFT33?%nSf`$IOTb+#P`9@yIX?m>Fiq>2zXQ7B-s= zr4$mtzvp{G3>7Dm5fX?5pintyodM;1MZHdlt33+rJ9)M z8C|b`*C5UNLbef` z1MeSy5U&Li3Bta!As+bQKo^GRQrmi3$T=e@`~5zqY5J=3k8aKAy6(R&)c1V?0??R@ Tx)$|a00000NkvXXu0mjfq>Pb! diff --git a/src/main/resources/assets/computercraft/textures/blocks/commandComputerFront.png b/src/main/resources/assets/computercraft/textures/blocks/commandComputerFront.png index 6d0a9971f4baf96734264338026c2b4ac00c687f..fe963f37343090158069dcad992319fa5923fb89 100644 GIT binary patch delta 410 zcmV;L0cHN=1NQ@vBo78+OGiWi{{a60|De66laV1F3gHC=79%Xel)m7RNi2U`Nkl=KX)Qiio>Eef1Xq^Yz{9gB50^)CoI?O<-Z~JtFo5?*l{} zW1zQPVcP(3t(A)H2~#bR;D|KgJz?G2adlqWfRsIko@cw7Ba{vGU delta 417 zcmV;S0bc(11LOmcBqa%ONLh0L01FcU01FcV0GgZ_00007bV*G`2j2k|5ilI1xGB7m zTP%NCNkl(-8|^U?;S>kc< z&!cztHlCcH>vz!9JjfQnXmTUlwse zPzDz*Gk1vIEv{yhfTVN?NjYe0t(kds{qyDRZ)LO~^`wz>YSbDH-!`2}c$5R$is;Ic zrCwh>j^_8r)dYGr$(LV$SX83@J+5XoGXP=&0p3SZB?3ibDFFTf;e)a$^N1c#00000 LNkvXXu0mjf6jZzE diff --git a/src/main/resources/assets/computercraft/textures/blocks/commandComputerFrontBlink.png b/src/main/resources/assets/computercraft/textures/blocks/commandComputerFrontBlink.png index 874750a52febefe8eb3754777d29f437b33846f7..0f52fd8117002b0b3fdd3b6615662c3efcd9e567 100644 GIT binary patch delta 532 zcmV+v0_*+f1o;GzBo78+OGiWi{{a60|De66laV1F3gHC=798qxCp_D`>rsSFb9S@07?IWrNTQje!Rcn?D8wiz1Rm@? z1kFSV%%xIlWylGug~eh)HRyl6)6LNsnCHTfB8RVDqA^BFDcpbZoNf5<;wj6V5W$JV z2*A}j}E_~0@VUqJkUL`n*+55dYPGZBw4}I66yrj zP>FaNIM~09)xyboB1de{>tp2I*Y8MFqE&vZCvqNeHy|JZ!s+WKRYHJZ6*)b;oSZI<5mO0f_hk+SRc)EArqX_HS*~-GnYGlZYIrLdEBJ*5860_2(VCcJs} zm_<&A;KZ&6;M?)>l?5^PAQ36^jF|zjyIfvbQsxFBAl4ep^?ZZf)IfujRl=JL!XhIMdsuC*Bc8yeRxZoXQY4B z#@$<68w+mVyg|Sbb3;`(7MLg=1Z}OcE{zut@3B4PU+0O6ctZt76G{WcNJ&Y#<8-|y zVgxrNX=0EWqH?k>XwLKzLQKp=LQE{w(XPYYIXL{xqoc2=K(&At4>S*K=RmE2RwgFx zNmj75fI5QBs6;$<93I@kYTk|S*BP9J&qsM4G0Mahvxy71ht-E@EA0nN7w|zCIksVkRUK99N`(r2sS(2eXHtT z#QLHC{+Dy;_4y-Vo?Dz`zCJ8tRu2qW9nzYCQ}a-Y?w*B3SOI!^{tTLhX|-y#mYlrW zIF8lPd+#19w60c?T)ls%B4U4LPhP&k|N8p&)h;Jygp>ime!o8sBoAO=Yt7vOOw)AS zSnD8S?;Wk)E=<#O46G{vE~QY)w+qKF4JCPi-6IQQL(5tZi}74LBy9nOV;nM{?eh08 zAGd%X-#+!$*lK@x?_>+OfA^(d*eX=RrV{8iXY6G_;h6xVZfJ{OY$ds*_q!4?4|MD|K5}9g>@; z9qIya$`YwuUOez>H-{w)^lXsNzy7eOc>Q}=axM`L5EBTn){`m`$SX?%@DCSPyGbqu R?1BIQ002ovPDHLkV1n9%!&(3U delta 431 zcmV;g0Z{&p1p5P!Bqa%ONLh0L01FcU01FcV0GgZ_00007bV*G`2j2k|5imA*1K?_r zTQz?@YZXBh#_{L8%*^g3F}2}BY7s>6lO$jju(Y&IWpA60V8F&SVx`zw*jU+#osiPX zkh{BQX3nulf8Bro<9X=y=`&%TS{!7)-OXcG4-8oy(wc!&^H7TJo`pqN0XjQ<4$Z=} zShZS9PF`&s$Li?4cMla>7Ar}v-@j84F|&WOi%a~kk8fUWa$-hE836pgx!DgS4`5+y z&D{Zq(Ue Z_y_R1yC~Sx#l!#r002ovPDHLkV1k`@#1R5;6>lRb{|Fc5~Hj2)whf-((9prWFq=P=Yc z10@IG5}YhbVX!^pEmlOktKCmucsh@)cmCdK4u?ZkRRGKkRez<{ikSfrW2EnUR25a_ z@pzC@Vzb#$O2Gr1PA9zg{6J@|r|UYF zVrD#_Ph`Db^9~^da?Z#!O{A0-3&a=!kkxASZAkx1*LBod5mlv>vRI&$Lf`iY@aGEu zh4-GOX^`!9%YSaSTP(2O@A2M$Rv;p8wJ?q&!kc*S5s^jwowofQ4~eAuvh#cK`i_oK`i{f zEGNq>`yOsFQ(Oi!$?+ye(=?4#Ri!G+Qt~{PEXyQKQ&kv-(siBKJYrE4NnO`c6onWr z)^(L_+itZi%b(|Yo;4pSAdX`VJ|7P!0l=-n5@c5Z&Um@D;C}<4hWVHzNtEUaplt;( z2ww+55QyQEF%X|2wr%?c_&Q)e%s7s69EUUDx-RMa{tYIi)&6X)bdLLUdyG~E_h**ojxJ5L=jNl1vH+=;~hFKa);Q#;t diff --git a/src/main/resources/assets/computercraft/textures/blocks/computerFrontAdvanced.png b/src/main/resources/assets/computercraft/textures/blocks/computerFrontAdvanced.png index 0dd1d91beb73838e377da029b14c6bc327b533b2..cfa052d984c0843aede5300f6ee83d0648689a1b 100644 GIT binary patch delta 384 zcmV-`0e}9-1IPoAQGekD1QsYas|Bvd00041NklkLm z$V?&vNn|Df<2cfF9T7o9aJgKV=b78vTb5;^0(|}a8d>0;sDB8VFcX-=>b{cei3Aqj ze)vJ{`ySl{FHWD>!ms=HWF}r~#Y$roLcKzK)Kmo5TftY>YYms}R5K@ryZ&;F- zuf72A^ZPq?yB)QZg6V=O;p#Ai!oUmzEEBb)D7gRj21&#?(OSdK=d*@k_`A;kBO)lJ eJi2pVEB^rUIKWSwf6f{J0000Z?Y=@ delta 383 zcmV-_0f7F<1IGi9QGeeA0tzZMM0)4U00040NklggQL<9iSG|~4x?vA^2xm;M5g~Q>%x~>#}j~`wjb5aVFg?~(#2`s_pz7pH<09IbV z{YDvv0o^!vckgN8>z9{A1gVsQ@pwa=5cDo&t zngzC2B$3>mlpfKZu+aBC2_Qv#fmUH=q~r0(?d_9h!Q=iZrIf9JeA8awVi<<2K&gEO z(?UvV`^v)k`FQKyzX_WmR)}pcOd>O*%S|<4 z=l1~o`22>h>nJ&AOczW6SBD|w24)yw5vT@P&i7BRkc3Y&wN~tWK5HDuzw7)z+?|~B dgS(Wr%0JjEz%FnE`{4ip002ovPDHLkV1k!Bw(bA` diff --git a/src/main/resources/assets/computercraft/textures/blocks/computerFrontBlink.png b/src/main/resources/assets/computercraft/textures/blocks/computerFrontBlink.png index 7689310eaa1a67fa9452dfbbcdb0dc4197769da1..f8942c64c1add8a8167e48bba9c940c610eb260c 100644 GIT binary patch delta 475 zcmV<10VMv@1N8%tB!32COGiWi{{a60|De66lK=n!32;bRa{vGf6951U69E94oEQKA z00(qQO+^Rc1q2o(0#O4c=l}o#f=NU{R7l6|lrfI#Fcd`(wquBpKuVK_B~Ve((X$xp ztbvjRunG2s6lEk6$It%7DAxQDFvHg`xsoOO$-aKizVA-9+kb5m5ddP0hzKbqVvGPd z=cwx%5kW+_-EMgASuU4^5HJAy{T^cs_u#$9TASC-If|kH;BvWO+O}mF22Q6Fui$Vv z5Mx9cV<^iKfa~@8Yl0Xfecz+z^LY+dRrPBUYc0btpt`QZd!I9?sw&T)kvZo8Fw^NY zKhk*k`}`itvVSC{gc1=#2)v3A0(D)ZfQMiB48|BHlL>0ITCrZQUnbaWHW*_*Gf+zX zQweR`^7_dyB`Bpnr5t1Ad_F(??@`j*jo#)fN}hNfw- z)>0G&Mr%z70i_h)d$iWM6TiOCc**g2B*vICnCy1D)Kqm{*7rS#2wLmEVk5EY`yQ=z z9snt&-2WdRA1oFNX0sVZQ6M5X=dyO*e(=N(e!}Pn>X9G(gts5O{oud)!5^&DKl-$l R8MXib002ovPDHLkV1iFq)BgYf delta 441 zcmV;q0Y?7y1JeVLB!2{RLP=Bz2nYy#2xN!=00D|gL_t(YiS3j)O6 z!va!JQPI(}0+x~`AXY-pX4pmql8NK7Z^4V-kKkUAUdfRnIhOr-?3wvS>-9Q`2mmog zM1+(QF-8EKb5vD@h#(@|Za2L5%;$4L2pE9vc8f8FM|khC)_>-I=Nv^*0B|~;Fm2n? z_dUns@u9#ocDo%hMwBszvMd2OpU*D~#2D$i4mF)l^JHDuFN;`f>H8jaxm@tx=LqV$ z&g1XIoO1w}@pzmcY1sVl_z`7Ul2Ss62qA=*!v2#G0##L^fTt<^4r2_X(FnCzELbj= zZwsteD~vJs2!E7PZwrJFXxo$SX z2ui7ZE$=MKVz!A~@%A?R@;;8$bAo!4K3k jKlq7{AAJ1azxu%!23J2ckR(kK00000NkvXXu0mjfP_WN2 diff --git a/src/main/resources/assets/computercraft/textures/blocks/computerFrontBlinkAdvanced.png b/src/main/resources/assets/computercraft/textures/blocks/computerFrontBlinkAdvanced.png index 58bdb26bd67dbf07395ad5799c01b942233b37cc..4c555b3a512f8186751f12e71c9d02ace27e5592 100644 GIT binary patch delta 463 zcmV;=0WkiS1eOGlQGekD1QsJEB0*RF0004_Nkl4E;KzV{kb+luJyju_5?f}-d;eK@zy zal75lL<9g;MMN+&R26`>ZKc3+3svx1577ch{&YKE{ai34p`l@L&S(BYofFSF6>0SeE6(Nfc5_ z_@-%4+^nE1%Xxo_%t8PlE*1;S+^pbNHK*XFY56?D$hj~Rs;bHZ3-0XuND`cL`0aK} z`RM9wf~&_*h<`C=1xEM>2})hpnZWt;3A7#X-e>m=;oH}Dlf6G|Hk>GC1}IK?OcG-^ z0E&r_QX=LL1{9g@hsCO|LB(pA%x$ukbmI&zDOs8Ft7YbY|j7jcx1g^vs^AI ziUJX#ZChf@kMGh4C;H&tG){*5zxBa=xb(rL5B_T(dZ7ItV5kW*aolf+9&t|h>7zQH1`+u7kmm=;oIH2(cT|68%`860~9A6CW+zH z1B!`|QX=LLdK4M&hsNOL|JDch;nD|}KKQSF@Et1CZ|?eCg$w`y002ovPDHLk FV1oV}-30&u diff --git a/src/main/resources/assets/computercraft/textures/blocks/computerFrontOn.png b/src/main/resources/assets/computercraft/textures/blocks/computerFrontOn.png index ba657ff3afe05732a2a405636fcf470810047735..3ac15489762d92a776db2a1e863fd541ff5916ff 100644 GIT binary patch delta 413 zcmV;O0b>5J0=EN@B!32COGiWi{{a60|De66lK=n!32;bRa{vGf6951U69E94oEQKA z00(qQO+^Rc1q2o(5Td$Npa1{?L`g(JR5;6>lQE7mF${&jaWX+83Z!YK;RsYzbo3mC zdd@(}0k{PBLK;mGNaAFR7192`c2}^ki)Ft&+t1Bzw=1d&K!45|Ri%_d&KUsjJ;N}d zs;DaW`<)O1tJR8>5*FZaIAE>iJA@E$&egZ~p0;fPxL&W=X_|;Jaz3AV2gl=)oHJsr zrRzEXZnxXZ1UY9Oj|Z|`E^Dyw`5F1aaZ-2;#!; z%WyJu@I4%uDqMCgK(j+&1Y5Qd=!pO1%=0N~bO2{J*RUjaDd<9~Vt3vhu@Lw`&ZMM`sZ zz_ArTBhC(f6*ZpciQ$*gkULGR>-r72>wx(%ec#KrZO(w>IHYacH(=j)X8<)i2X_HD z&`GpM_$Ct3)gD7=x~}^qu&(Q>j?g)oI4c(keH;wKa9Lnw_pFn1o;skDkPuC|5{ds~ bw&n%a9Ne~5(hkVV00000NkvXXu0mjfK}CSd diff --git a/src/main/resources/assets/computercraft/textures/blocks/computerFrontOnAdvanced.png b/src/main/resources/assets/computercraft/textures/blocks/computerFrontOnAdvanced.png index ef9bf9429333b5694df860647969f08d0de2f511..bf38005c9a812c6c41e9418fd8a0f2ffd36a730b 100644 GIT binary patch delta 355 zcmV-p0i6Eb1KR_TQ4Zk+1QsJQIGclm0004KkzW-a%PMRW@F|3VMP5KG1Q9HJAuD@( z?X0ZrF6b-VcLADWxIWP8~Sdw24?}-RfDFw?FfaCFaGa%;`!!VFGo6SWHnx?rK5);%~ zNqyhrDp!N1X>J0jtN=*s^%_Z6gIi-$MH0!~N$ClTqmj04Nq+z-wEX=f%#5_#?YO^x zwixiVeNHK5HXz?EH*nE)-36eud`{3SPeY0>IDj?^vx?l$3~cPHokPcNm}@(--5$xjp|CWQb1002ovPDHLkV1hU* BqMiT% delta 357 zcmV-r0h<2X1Kk6VQ4Ze(0tzW3n}Y#f0004MkzW-b3kusTI6|v8f`7l1fD~H(eiCLzYTK6E z+b4?wkDDE(l-YoMv)sT%*L7!r(()M`M^Z}jDhubw&$oXkY=)R1=DRS7%z#bJM;h2+He8>ZmtvwHx(e|pVowW8#lF`Y04oEe6Y8<=5$MW7mF zIp03ML=t`+sI@6#hr>aA-(Sx8e{pwm&j0jMnl1kTd3(t&Lh?3f00000NkvXXu0mjf D@ZP2; diff --git a/src/main/resources/assets/computercraft/textures/blocks/monitor15.png b/src/main/resources/assets/computercraft/textures/blocks/monitor15.png index 066a338d8cc98f3f2369b903d9e0c838500e7cda..705ada40228546297d560f7c56baac347c3b5b74 100644 GIT binary patch delta 354 zcmV-o0iFJq0{sGzB!32COGiWi{{a60|De66lK=n!32;bRa{vGf6951U69E94oEQKA z00(qQO+^Rc1q2o&9g|AF+5i9n3Q0skR5;6>k};0LKnz7+CeEOUf-((9prWFq&tY;H zPQV>FS(IX6VtckgAg#orOD%Ac>2xY)27tR`W|UHJcYgp~=d;6#?k`9ueUaIcH*w?>VJJ(=-6wZZ~8cN9K9va=EaCVHj|Cf{4(zElY8C9*+lM zyWO&e7$fsM6Q*e*=e$^uQUV}sHk)5Z`Y&zUQc5A18LGNipsI9TM*#k;@EamRRaJ!j ze$U}>SS&amk6VbyGeHPp)e7S{5?G0d5JGqgUVp!Yob&S!N-3*qj4{$Q4N})Ns>=0x z{g~u+pI1|=io3rPROj=#Ow+`-Rm_aKu0M)@0A0|Bb`@~XdjJ3c07*qoM6N<$f|m1^ Ar2qf` delta 250 zcmVJPx~^4KRY_44lIOW(S*D7jNV=|*yNdz!{J02tELM$aBY}X{t0=0AnkFAbcH! zVJL=QMj$>RwrzU>d>ybKW*kS^_uUzAo~QJEe*uo;a0bw$d*BPefo`Jj2=uUoW*7#g zc{`Y3XpStg8K)-eBfFvOyLU|K~&$GMd3khVdV;R}^N&o-=07*qoM6N<$g4Ks@ Ag8%>k diff --git a/src/main/resources/assets/computercraft/textures/items/pocketComputer.png b/src/main/resources/assets/computercraft/textures/items/pocketComputer.png index ddff06ab89683df3df221d63415ec96f8188370b..f066cc2f4f34f67a914f335010da2f97833bc3dc 100644 GIT binary patch delta 117 zcmcb?c!P0*mf?Q}AY8C_`D6wL2F?PH$YKTtZeb8+WSBKa0w~B{;_2(k{*aYLOhxi` z+8dUM(FTfhj8eJc&RSYpYSgHC9ZtBykR_dvl;jk^yi2O5WJAJ1rip7LL@f721s-(wUP;4%El zT&q7Z+CVYJB3~}<>_<;ejT$wt!wFXyvZND|lAHpVcS-e>7*yUenYczmM9fpP_|@mc RFF-RGJYD@<);T3K0RZf0B%S~O diff --git a/src/main/resources/assets/computercraft/textures/items/pocketComputerAdvanced.png b/src/main/resources/assets/computercraft/textures/items/pocketComputerAdvanced.png index b1e4c5a7f5e4c61faa1d7fd51b8706a66e9980f7..d262102d8b87e63ece0a2227b74ef4b793a15fff 100644 GIT binary patch delta 78 zcmcc3c$;xTAlE}y7BLlTKDMGB^8K;Y@>=d#Wzp$P!6tR2Y! diff --git a/src/main/resources/assets/computercraft/textures/items/pocketComputerBlink.png b/src/main/resources/assets/computercraft/textures/items/pocketComputerBlink.png index b285d5ee4efe2239045ab30553bb34f0ace1162e..23ad6b40ec4faf5c2807a3fe4e78d381fb13c074 100644 GIT binary patch delta 126 zcmeBR>R_6nW%!=~2p8;KKAC}mfwRCPvY3H^TNs2H8D`Cq01C2~c>21sKV)SQQ&Gyw zWmT9MZJ;#AD3vSjtfi%;MvYod*S)>f?pwk)NGYhOxNK3hhy~It6W2zopr03m55_5c6? delta 126 zcmeBR>R_6nWmwAqgk5ton;94wI14-?iy0WWg+Z8+Vb&Z8pdfpRr>`sfJw|acJzXbT z=}!}*4U}Rm^5x>re)ROzs8P%5lC!IH+7iA&NSCIpW%!=~2p8;KKAC}mfwRCPvY3H^TNs2H8D`Cq01C2~c>21sKV)SQQ!$u% zr6glww1Lu=vKt-YpD!~1)2LC)>AJVK+I>s-1}Oy<6_+iF7O_B@W#U>XmUZ#xmrXpa aEmCe}eOLbO;oCsN7(8A5T-G@yGywooV=K@A delta 126 zcmeBT>SCIpWmwAqgk5ton;94wI14-?iy0WWg+Z8+Vb&Z8pdfpRr>`sfJw|aceGP4& zdo~lJ4V1ooxYZl}xi5E}MvYodmz-Ut)0XfJQVROY&RY~MVu3XC#I;f^esg`7OgybE YGONkDN~Z6?KA>R?p00i_>zopr00-G8Z~y=R diff --git a/src/main/resources/assets/computercraft/textures/items/pocketComputerOn.png b/src/main/resources/assets/computercraft/textures/items/pocketComputerOn.png index 906eee04355414afafec6e82b9786bd07046a4a2..4addbc205325a7f68acdc4d66ace3938856f30ca 100644 GIT binary patch delta 161 zcmeys_owc;I)TmL*>AJVK+I>s-1}Oy<6_+iF7O^0DCbz~XCe4OjY%^xe z5V+E?j!jusCt^c`S)7KRUK$V|6G&IQ)^P7$+^rO~E=GoAR=Fu06Wy)??PKtC^>bP0 Hl+XkK^*%NN delta 161 zcmeys_21s-(wUP;N{j5 znR;hpv_Wc&MZR3z*^i!{8Z~M;U2=AnPFun^NGa$mJ8x06hy~Fzxivm9X*TR)n=xaC zz?Ft|Y|64e^UQk9;xzR1(t!AwK)T|!hI{woZl$PoF*2y-$Q9ploAeE6AA_f>pUXO@ GgeCxSu`{Fq diff --git a/src/main/resources/assets/computercraft/textures/items/pocketComputerOnAdvanced.png b/src/main/resources/assets/computercraft/textures/items/pocketComputerOnAdvanced.png index 2e0bcde8fbc2ba5d4e660fc1f9397bbe5f852de6..4915ccec885e93eaf6ea846c18dc40389f40bb85 100644 GIT binary patch delta 129 zcmeyw_?dA+Am2k)7BLmgzx(g3U|?Wqm>92OiM)N;D+?X7m-623u7 zK}E%7i=ss=h@Q!<@rg;ZVHX=m=V^f}4eQvHWn=cw^Oe@Wabr!whK-SpiszixFuM1- hB#5RvZf||Zz%cu$G^g_mF+rdm44$rjF6*2UngB!UG3)>U delta 128 zcmey&_=#~sAm2SkaRF|@MxE0N3=9nQ6XSK#zkImW8~(X3cb!I!T27aoU8U2O@C{N5 z`pV8*6fI&w^h|DzPfVH(yVy87h0CmVN%fQzyvk9^-II{Kx#{4sG}bl??u~3RmO_o8 fb6D?+?P6w#*O7YhRq5kFpcM?Bu6{1-oD!M<>{KrE From 09215daa03d7ccfa342d2508274805f3c575ff58 Mon Sep 17 00:00:00 2001 From: Daniel Ratcliffe Date: Fri, 5 May 2017 00:52:26 +0100 Subject: [PATCH 31/38] FileSystem uses a WeakHashMap to store it's open file handles This means if lua code forgets to free a handle, the java GC will still be able to collect the stream (andclose the file in the finaliser in the process) --- .../core/filesystem/FileSystem.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 0ba626dc9..71344f562 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -11,6 +11,7 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import java.io.*; +import java.lang.ref.WeakReference; import java.util.*; import java.util.regex.Pattern; @@ -291,7 +292,7 @@ public class FileSystem } private final Map m_mounts = new HashMap(); - private final Set m_openFiles = new HashSet(); + private final WeakHashMap m_openFiles = new WeakHashMap(); public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException { @@ -308,18 +309,15 @@ public class FileSystem // Close all dangling open files synchronized( m_openFiles ) { - while( m_openFiles.size() > 0 ) + for(IMountedFile file : m_openFiles.keySet()) { - IMountedFile file = m_openFiles.iterator().next(); - try - { + try { file.close(); - } - catch( IOException e ) - { - m_openFiles.remove( file ); + } catch (IOException e) { + // Ignore } } + m_openFiles.clear(); } } @@ -669,7 +667,7 @@ public class FileSystem throw new FileSystemException("Too many files already open"); } - m_openFiles.add( file ); + m_openFiles.put( file, null ); return file; } } @@ -679,7 +677,6 @@ public class FileSystem synchronized( m_openFiles ) { m_openFiles.remove( file ); - if( handle != null ) { handle.close(); From 7b07921a73bf5730b79a102b58ce7aa126d88519 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 5 May 2017 14:56:15 +0100 Subject: [PATCH 32/38] General improvements to the documentation - Add documentation for all undocumented methods and enums. - Use @code, @link and @see where appropriate. - Fix spelling in a couple of cases. --- .../computercraft/api/ComputerCraftAPI.java | 92 +++++++----- .../computercraft/api/filesystem/IMount.java | 48 +++--- .../api/filesystem/IWritableMount.java | 43 ++++-- .../computercraft/api/lua/ILuaContext.java | 80 +++++++--- .../computercraft/api/lua/ILuaObject.java | 24 ++- .../computercraft/api/lua/ILuaTask.java | 17 +++ .../computercraft/api/lua/LuaException.java | 9 +- .../computercraft/api/media/IMedia.java | 26 ++-- .../api/media/IMediaProvider.java | 6 +- .../api/peripheral/IComputerAccess.java | 142 ++++++++++++------ .../api/peripheral/IPeripheral.java | 131 +++++++++------- .../api/peripheral/IPeripheralProvider.java | 8 +- .../ITurtlePermissionProvider.java | 22 ++- .../redstone/IBundledRedstoneProvider.java | 9 +- .../api/turtle/ITurtleAccess.java | 142 ++++++++++++++---- .../api/turtle/ITurtleCommand.java | 19 ++- .../api/turtle/ITurtleUpgrade.java | 72 +++++---- .../api/turtle/TurtleAnimation.java | 65 ++++++++ .../api/turtle/TurtleCommandResult.java | 45 ++++++ .../computercraft/api/turtle/TurtleSide.java | 4 +- .../api/turtle/TurtleUpgradeType.java | 17 +-- .../computercraft/api/turtle/TurtleVerb.java | 17 ++- 22 files changed, 742 insertions(+), 296 deletions(-) diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index 49471e552..de538fad2 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -8,13 +8,16 @@ package dan200.computercraft.api; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; +import dan200.computercraft.api.media.IMedia; import dan200.computercraft.api.media.IMediaProvider; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralProvider; import dan200.computercraft.api.permissions.ITurtlePermissionProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.turtle.ITurtleUpgrade; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.lang.reflect.Method; @@ -52,12 +55,16 @@ public final class ComputerCraftAPI } /** - * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
- * Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
- * @param world The world for which the save dir should be created. This should be the serverside world object. + * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number. + * + * Use in conjunction with createSaveDirMount() to create a unique place for your peripherals or media items to store files. + * + * @param world The world for which the save dir should be created. This should be the server side world object. * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk" - * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
- * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing. + * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason. + * + * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now + * available for writing. * @see #createSaveDirMount(World, String, long) */ public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) @@ -73,21 +80,23 @@ public final class ComputerCraftAPI } return -1; } - + /** - * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
- * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the - * users save directory onto a computers file system.
- * @param world The world for which the save dir can be found. This should be the serverside world object. - * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
- * Use createUniqueNumberedSaveDir() to create a new numbered folder to use. - * @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes. + * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it. + * + * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the + * users save directory onto a computers file system. + * + * @param world The world for which the save dir can be found. This should be the server side world object. + * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42". + * Use createUniqueNumberedSaveDir() to create a new numbered folder to use. + * @param capacity The amount of data that can be stored in the directory before it fills up, in bytes. * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() * to mount this on a Computers' file system. * @see #createUniqueNumberedSaveDir(World, String) - * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) - * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) - * @see dan200.computercraft.api.filesystem.IMount + * @see IComputerAccess#mount(String, IMount) + * @see IComputerAccess#mountWritable(String, IWritableMount) + * @see IMount * @see IWritableMount */ public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) @@ -103,19 +112,24 @@ public final class ComputerCraftAPI } return null; } - + /** - * Creates a file system mount to a resource folder, and returns it.
- * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.
- * The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.
+ * Creates a file system mount to a resource folder, and returns it. + * + * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder + * onto a computer's file system. + * + * The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain + * resources with the same domain and path. + * * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class - * @param domain The domain under which to look for resources. eg: "mymod" - * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" - * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() - * to mount this on a Computers' file system. - * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) - * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, IWritableMount) - * @see dan200.computercraft.api.filesystem.IMount + * @param domain The domain under which to look for resources. eg: "mymod" + * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" + * @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or + * IComputerAccess.mountWritable() to mount this on a Computers' file system. + * @see IComputerAccess#mount(String, IMount) + * @see IComputerAccess#mountWritable(String, IWritableMount) + * @see IMount */ public static IMount createResourceMount( Class modClass, String domain, String subPath ) { @@ -130,9 +144,10 @@ public final class ComputerCraftAPI } return null; } - + /** - * Registers a peripheral handler to convert blocks into IPeripheral implementations. + * Registers a peripheral handler to convert blocks into {@link IPeripheral} implementations. + * * @see dan200.computercraft.api.peripheral.IPeripheral * @see dan200.computercraft.api.peripheral.IPeripheralProvider */ @@ -153,6 +168,7 @@ public final class ComputerCraftAPI * Registers a new turtle turtle for use in ComputerCraft. After calling this, * users should be able to craft Turtles with your new turtle. It is recommended to call * this during the load() method of your mod. + * * @see dan200.computercraft.api.turtle.ITurtleUpgrade */ public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) @@ -173,6 +189,7 @@ public final class ComputerCraftAPI /** * Registers a bundled redstone handler to provide bundled redstone output for blocks + * * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider */ public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) @@ -190,9 +207,10 @@ public final class ComputerCraftAPI /** * If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output. - * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider + * * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. + * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider */ public static int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) { @@ -209,7 +227,8 @@ public final class ComputerCraftAPI } /** - * Registers a media handler to provide IMedia implementations for Items + * Registers a media handler to provide {@link IMedia} implementations for Items + * * @see dan200.computercraft.api.media.IMediaProvider */ public static void registerMediaProvider( IMediaProvider handler ) @@ -227,6 +246,7 @@ public final class ComputerCraftAPI /** * Registers a permission handler to restrict where turtles can move or build + * * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider */ public static void registerPermissionProvider( ITurtlePermissionProvider handler ) @@ -245,7 +265,7 @@ public final class ComputerCraftAPI // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. // Reflection is used here so you can develop your mod without decompiling ComputerCraft and including // it in your solution, and so your mod won't crash if ComputerCraft is installed. - + private static void findCC() { if( !ccSearched ) { @@ -300,9 +320,9 @@ public final class ComputerCraftAPI System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." ); return null; } - } - - private static boolean ccSearched = false; + } + + private static boolean ccSearched = false; private static Class computerCraft = null; private static Method computerCraft_getVersion = null; private static Method computerCraft_createUniqueNumberedSaveDir = null; diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java index d26537d61..7df0fdf9b 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -6,52 +6,66 @@ package dan200.computercraft.api.filesystem; +import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.peripheral.IComputerAccess; +import net.minecraft.world.World; + import java.io.IOException; import java.io.InputStream; import java.util.List; /** - * Represents a read only part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount(). - * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves! - * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) - * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) - * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, IMount) + * Represents a read only part of a virtual filesystem that can be mounted onto a computer using + * {@link IComputerAccess#mount(String, IMount)} + * + * Ready made implementations of this interface can be created using + * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or + * {@link ComputerCraftAPI#createResourceMount(Class, String, String)}, or you're free to implement it yourselves! + * + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @see IComputerAccess#mount(String, IMount) * @see IWritableMount */ public interface IMount { /** * Returns whether a file with a given path exists or not. + * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" - * @return true if the file exists, false otherwise + * @return If the file exists. */ public boolean exists( String path ) throws IOException; /** * Returns whether a file with a given path is a directory or not. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" - * @return true if the file exists and is a directory, false otherwise + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms". + * @return If the file exists and is a directory */ public boolean isDirectory( String path ) throws IOException; /** * Returns the file names of all the files in a directory. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" - * @param contents A list of strings. Add all the file names to this list + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms". + * @param contents A list of strings. Add all the file names to this list. */ public void list( String path, List contents ) throws IOException; /** * Returns the size of a file with a given path, in bytes - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" - * @return the size of the file, in bytes + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". + * @return The size of the file, in bytes. */ public long getSize( String path ) throws IOException; - + /** - * Opens a file with a given path, and returns an inputstream representing it's contents. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" - * @return a stream representing the contents of the file + * Opens a file with a given path, and returns an {@link InputStream} representing its contents. + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". + * @return A stream representing the contents of the file. */ - public InputStream openForRead( String path ) throws IOException; + public InputStream openForRead( String path ) throws IOException; } diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java index 429b73fdc..2bc32d4d5 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -6,47 +6,62 @@ package dan200.computercraft.api.filesystem; +import dan200.computercraft.api.ComputerCraftAPI; +import dan200.computercraft.api.peripheral.IComputerAccess; +import net.minecraft.world.World; + import java.io.IOException; import java.io.OutputStream; /** - * Represents a part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to. - * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves! - * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) - * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IMount) - * @see dan200.computercraft.api.filesystem.IMount + * Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)} + * or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to. + * + * Ready made implementations of this interface can be created using + * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to implement it yourselves! + * + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see IComputerAccess#mount(String, IMount) + * @see IComputerAccess#mountWritable(String, IWritableMount) + * @see IMount */ public interface IWritableMount extends IMount { /** * Creates a directory at a given path inside the virtual file system. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms" + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms". */ public void makeDirectory( String path ) throws IOException; /** * Deletes a directory at a given path inside the virtual file system. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms" + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms". */ public void delete( String path ) throws IOException; /** - * Opens a file with a given path, and returns an outputstream for writing to it. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * Opens a file with a given path, and returns an {@link OutputStream} for writing to it. + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @return a stream for writing to */ public OutputStream openForWrite( String path ) throws IOException; /** - * Opens a file with a given path, and returns an outputstream for appending to it. - * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" - * @return a stream for writing to + * Opens a file with a given path, and returns an {@link OutputStream} for appending to it. + * + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". + * @return A stream for writing to. */ public OutputStream openForAppend( String path ) throws IOException; /** - * Get the ammount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero. - * @return The ammount of free space, in bytes. + * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the + * mount, and write operations should fail once it reaches zero. + * + * @return The amount of free space, in bytes. */ public long getRemainingSpace() throws IOException; } diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java index 9c5a7168f..503fd6cec 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java @@ -7,52 +7,84 @@ package dan200.computercraft.api.lua; /** - * An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods - * that allow the peripheral call to wait for events before returning, just like in lua. - * This is very useful if you need to signal work to be performed on the main thread, and don't want to return - * until the work has been completed. + * An interface passed to peripherals and {@link ILuaObject}s by computers or turtles, providing methods + * that allow the peripheral call to wait for events before returning, just like in lua. This is very useful if you need + * to signal work to be performed on the main thread, and don't want to return until the work has been completed. */ public interface ILuaContext { /** - * Wait for an event to occur on the computercraft, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua. - * @param filter A specific event to wait for, or null to wait for any event - * @return An object array containing the name of the event that occurred, and any event parameters - * @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here. - * Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended. - * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + * Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly + * equivalent to {@code os.pullEvent()} in lua. + * + * @param filter A specific event to wait for, or null to wait for any event. + * @return An object array containing the name of the event that occurred, and any event parameters. + * @throws LuaException If the user presses CTRL+T to terminate the current program while pullEvent() is + * waiting for an event, a "Terminated" exception will be thrown here. + * + * Do not attempt to catch this exception. You should use {@link #pullEventRaw(String)} + * should you wish to disable termination. + * @throws InterruptedException If the user shuts down or reboots the computer while pullEvent() is waiting for an + * event, InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. */ public Object[] pullEvent( String filter ) throws LuaException, InterruptedException; - + /** - * The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua. - * @param filter A specific event to wait for, or null to wait for any event - * @return An object array containing the name of the event that occurred, and any event parameters - * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + * The same as {@link #pullEvent(String)}, except "terminated" events are ignored. Only use this if you want to + * prevent program termination, which is not recommended. This method is exactly equivalent to + * {@code os.pullEventRaw()} in lua. + * + * @param filter A specific event to wait for, or null to wait for any event. + * @return An object array containing the name of the event that occurred, and any event parameters. + * @throws InterruptedException If the user shuts down or reboots the computer while pullEventRaw() is waiting for + * an event, InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. * @see #pullEvent(String) */ public Object[] pullEventRaw( String filter ) throws InterruptedException; - + /** - * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events. + * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to + * {@code coroutine.yield()} in lua. Use {@code pullEvent()} if you wish to wait for events. + * * @param arguments An object array containing the arguments to pass to coroutine.yield() * @return An object array containing the return values from coroutine.yield() - * @throws InterruptedException If the user shuts down or reboots the computercraft the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, + * InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. * @see #pullEvent(String) */ public Object[] yield( Object[] arguments ) throws InterruptedException; /** - * TODO: Document me - * @param task - * @return + * Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete. + * This should be used when you need to interact with the world in a thread-safe manner. + * + * Note that the return values of your task are handled as events, meaning more complex objects such as maps or + * {@link ILuaObject} will not preserve their identities. + * + * @param task The task to execute on the main thread. + * @return The objects returned by {@code task}. + * @throws LuaException If the task could not be queued, or if the task threw an exception. + * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, + * InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. */ public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException; /** - * TODO: Document me - * @param task - * @return + * Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to + * complete. This should be used when you need to interact with the world in a thread-safe manner but do not care + * about the result or you wish to run asynchronously. + * + * When the task has finished, it will enqueue a {@code task_completed} event, which takes the task id, a success + * value and the return values, or an error message if it failed. If you need to wait on this event, it may be + * better to use {@link #executeMainThreadTask(ILuaTask)}. + * + * @param task The task to execute on the main thread. + * @return The "id" of the task. This will be the first argument to the {@code task_completed} event. + * @throws LuaException If the task could not be queued. */ public long issueMainThreadTask( ILuaTask task ) throws LuaException; } diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java index 4f8954fd4..ac5162be2 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -6,21 +6,35 @@ package dan200.computercraft.api.lua; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; + /** - * An interface for representing custom objects returned by IPeripheral.callMethod() calls. + * An interface for representing custom objects returned by {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])} + * calls. + * * Return objects implementing this interface to expose objects with methods to lua. */ public interface ILuaObject { /** - * Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation. - * @see dan200.computercraft.api.peripheral.IPeripheral#getMethodNames() + * Get the names of the methods that this object implements. This works the same as {@link IPeripheral#getMethodNames()}. + * See that method for detailed documentation. + * + * @see IPeripheral#getMethodNames() */ public String[] getMethodNames(); /** - * Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation. - * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[]) + * Called when a user calls one of the methods that this object implements. This works the same as + * {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}}. See that method for detailed + * documentation. + * + * @throws LuaException If the task could not be queued, or if the task threw an exception. + * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, + * InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state.w + * @see IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[]) */ public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; } diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java index fa7df1634..65a389bba 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java @@ -6,7 +6,24 @@ package dan200.computercraft.api.lua; +/** + * A task which can be executed via {@link ILuaContext#executeMainThreadTask(ILuaTask)} or + * {@link ILuaContext#issueMainThreadTask(ILuaTask)}. This will be run on the main thread, at the beginning of the + * next tick. + * + * @see ILuaContext#executeMainThreadTask(ILuaTask) + * @see ILuaContext#issueMainThreadTask(ILuaTask) + */ public interface ILuaTask { + /** + * Execute this task. + * + * @return The arguments to add to the {@code task_completed} event. These will be returned by + * {@link ILuaContext#executeMainThreadTask(ILuaTask)}. + * @throws LuaException If you throw any exception from this function, a lua error will be raised with the + * same message as your exception. Use this to throw appropriate errors if the wrong + * arguments are supplied to your method. + */ public Object[] execute() throws LuaException; } diff --git a/src/main/java/dan200/computercraft/api/lua/LuaException.java b/src/main/java/dan200/computercraft/api/lua/LuaException.java index 75741d1e4..bbb860090 100644 --- a/src/main/java/dan200/computercraft/api/lua/LuaException.java +++ b/src/main/java/dan200/computercraft/api/lua/LuaException.java @@ -7,10 +7,11 @@ package dan200.computercraft.api.lua; /** - * An exception representing an error in Lua, like that raised by the error() function + * An exception representing an error in Lua, like that raised by the {@code error()} function. */ public class LuaException extends Exception { + private static final long serialVersionUID = -6136063076818512651L; private final int m_level; public LuaException() @@ -29,6 +30,12 @@ public class LuaException extends Exception m_level = level; } + /** + * The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so + * on. + * + * @return The level to raise the error at. + */ public int getLevel() { return m_level; diff --git a/src/main/java/dan200/computercraft/api/media/IMedia.java b/src/main/java/dan200/computercraft/api/media/IMedia.java index 39bb2cefb..286489ca3 100644 --- a/src/main/java/dan200/computercraft/api/media/IMedia.java +++ b/src/main/java/dan200/computercraft/api/media/IMedia.java @@ -18,22 +18,26 @@ import net.minecraft.world.World; public interface IMedia { /** - * Get a string representing the label of this item. Will be called vi disk.getLabel() in lua. - * @param stack The itemstack to inspect - * @return The label. ie: "Dan's Programs" + * Get a string representing the label of this item. Will be called via {@code disk.getLabel()} in lua. + * + * @param stack The itemstack to inspect. + * @return The label. ie: "Dan's Programs". */ public String getLabel( ItemStack stack ); /** - * Set a string representing the label of this item. Will be called vi disk.setLabel() in lua. + * Set a string representing the label of this item. Will be called vi {@code disk.setLabel()} in lua. + * * @param stack The itemstack to modify. * @param label The string to set the label to. * @return true if the label was updated, false if the label may not be modified. */ public boolean setLabel( ItemStack stack, String label ); - + /** - * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathon Coulton - Still Alive" + * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: + * "Jonathon Coulton - Still Alive" + * * @param stack The itemstack to inspect. * @return The name, or null if this item does not represent an item with audio. */ @@ -41,16 +45,20 @@ public interface IMedia /** * If this disk represents an item with audio (like a record), get the resource name of the audio track to play. + * * @param stack The itemstack to inspect. * @return The name, or null if this item does not represent an item with audio. */ public SoundEvent getAudio( ItemStack stack ); - + /** - * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computercraft while the media is in the disk drive. + * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will + * be mounted onto the filesystem of the computer while the media is in the disk drive. + * * @param stack The itemstack to inspect. * @param world The world in which the item and disk drive reside. - * @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable() + * @return The mount, or null if this item does not represent an item with data. If the mount returned also + * implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable() * @see dan200.computercraft.api.filesystem.IMount * @see dan200.computercraft.api.filesystem.IWritableMount * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long) diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java index 3abe1d49f..e2aa60661 100644 --- a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -9,15 +9,17 @@ package dan200.computercraft.api.media; import net.minecraft.item.ItemStack; /** - * This interface is used to provide IMedia implementations for ItemStack + * This interface is used to provide {@link IMedia} implementations for {@link ItemStack}. + * * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) */ public interface IMediaProvider { /** * Produce an IMedia implementation from an ItemStack. - * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) + * * @return an IMedia implementation, or null if the item is not something you wish to handle + * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) */ public IMedia getMedia( ItemStack stack ); } diff --git a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java index 498881a92..4429c74c7 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -6,8 +6,10 @@ package dan200.computercraft.api.peripheral; +import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; +import net.minecraft.world.World; /** * The interface passed to peripherals by computers or turtles, providing methods @@ -17,30 +19,50 @@ import dan200.computercraft.api.filesystem.IWritableMount; public interface IComputerAccess { /** - * Mount a mount onto the computers' file system in a read only mode.
- * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. - * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface. - * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. - * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) - * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) - * @see #mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) + * Mount a mount onto the computer's file system in a read only mode. + * + * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computer. + * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a + * file in the desired location. Store this value if you wish to unmount the mount later. + * @throws RuntimeException If the peripheral has been detached. + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mount(String, IMount, String) + * @see #mountWritable(String, IWritableMount) * @see #unmount(String) - * @see dan200.computercraft.api.filesystem.IMount + * @see IMount */ public String mount( String desiredLocation, IMount mount ); /** - * TODO: Document me + * Mount a mount onto the computer's file system in a read only mode. + * + * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computer. + * @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}. + * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a + * file in the desired location. Store this value if you wish to unmount the mount later. + * @throws RuntimeException If the peripheral has been detached. + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mount(String, IMount) + * @see #mountWritable(String, IWritableMount) + * @see #unmount(String) + * @see IMount */ public String mount( String desiredLocation, IMount mount, String driveName ); /** - * Mount a mount onto the computers' file system in a writable mode.
- * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. - * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface. - * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. - * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) - * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * Mount a mount onto the computer's file system in a writable mode. + * + * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computer. + * @return The location on the computer's file system where you the mount mounted, or null if there was already a + * file in the desired location. Store this value if you wish to unmount the mount later. + * @throws RuntimeException If the peripheral has been detached. + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see ComputerCraftAPI#createResourceMount(Class, String, String) * @see #mount(String, IMount) * @see #unmount(String) * @see IMount @@ -48,55 +70,81 @@ public interface IComputerAccess public String mountWritable( String desiredLocation, IWritableMount mount ); /** - * TODO: Document me + * Mount a mount onto the computer's file system in a writable mode. + * + * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computer. + * @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}. + * @return The location on the computer's file system where you the mount mounted, or null if there was already a + * file in the desired location. Store this value if you wish to unmount the mount later. + * @throws RuntimeException If the peripheral has been detached. + * @see ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mount(String, IMount) + * @see #unmount(String) + * @see IMount */ public String mountWritable( String desiredLocation, IWritableMount mount, String driveName ); /** - * Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().
- * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to - * access it. All directories mounted by a mount or mountWritable are automatically unmounted when the peripheral - * is attached if they have not been explicitly unmounted. - * @param location The desired location in the computers file system of the directory to unmount. - * This must be the location of a directory previously mounted by mount() or mountWritable(), as - * indicated by their return value. - * @see #mount(String, IMount) - * @see #mountWritable(String, IWritableMount) + * Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)} + * or {@link #mountWritable(String, IWritableMount)}. + * + * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be + * able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the + * peripheral is attached if they have not been explicitly unmounted. + * + * Note that you cannot unmount another peripheral's mounts. + * + * @param location The desired location in the computers file system of the directory to unmount. + * This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or + * {@link #mountWritable(String, IWritableMount)}, as indicated by their return value. + * @throws RuntimeException If the peripheral has been detached. + * @throws RuntimeException If the mount does not exist, or was mounted by another peripheral. + * @see #mount(String, IMount) + * @see #mountWritable(String, IWritableMount) */ public void unmount( String location ); - - /** - * Returns the numerical ID of this computercraft.
- * This is the same number obtained by calling os.getComputerID() or running the "id" program from lua, - * and is guarunteed unique. This number will be positive. - * @return The identifier. - */ - public int getID(); /** - * Causes an event to be raised on this computercraft, which the computercraft can respond to by calling - * os.pullEvent(). This can be used to notify the computercraft when things happen in the world or to + * Returns the numerical ID of this computer. + * + * This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua, + * and is guaranteed unique. This number will be positive. + * + * @return The identifier. + */ + public int getID(); + + /** + * Causes an event to be raised on this computer, which the computer can respond to by calling + * {@code os.pullEvent()}. This can be used to notify the computer when things happen in the world or to * this peripheral. - * @param event A string identifying the type of event that has occurred, this will be - * returned as the first value from os.pullEvent(). It is recommended that you - * you choose a name that is unique, and recognisable as originating from your - * peripheral. eg: If your peripheral type is "button", a suitable event would be - * "button_pressed". - * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will - * be supplied as extra return values to os.pullEvent(). Objects in the array will be converted - * to lua data types in the same fashion as the return values of IPeripheral.callMethod().
- * You may supply null to indicate that no arguments are to be supplied. + * + * @param event A string identifying the type of event that has occurred, this will be + * returned as the first value from {@code os.pullEvent()}. It is recommended that you + * you choose a name that is unique, and recognisable as originating from your + * peripheral. eg: If your peripheral type is "button", a suitable event would be + * "button_pressed". + * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will + * be supplied as extra return values to os.pullEvent(). Objects in the array will be converted + * to lua data types in the same fashion as the return values of IPeripheral.callMethod(). + * + * You may supply {@code null} to indicate that no arguments are to be supplied. + * @throws RuntimeException If the peripheral has been detached. * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod */ public void queueEvent( String event, Object[] arguments ); /** - * Get a string, unique to the computercraft, by which the computercraft refers to this peripheral. + * Get a string, unique to the computer, by which the computer refers to this peripheral. * For directly attached peripherals this will be "left","right","front","back",etc, but * for peripherals attached remotely it will be different. It is good practice to supply - * this string when raising events to the computercraft, so that the computercraft knows from + * this string when raising events to the computer, so that the computer knows from * which peripheral the event came. - * @return A string unique to the computercraft, but not globally. + * + * @return A string unique to the computer, but not globally. + * @throws RuntimeException If the peripheral has been detached. */ public String getAttachmentName(); } diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java index 063767bbe..a790886c8 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -10,89 +10,108 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; /** - * The interface that defines a peripheral. See IPeripheralProvider for how to associate blocks with peripherals. + * The interface that defines a peripheral. See {@link IPeripheralProvider} for how to associate blocks with peripherals. */ public interface IPeripheral { /** * Should return a string that uniquely identifies this type of peripheral. - * This can be queried from lua by calling peripheral.getType() - * @return A string identifying the type of peripheral. + * This can be queried from lua by calling {@code peripheral.getType()} + * + * @return A string identifying the type of peripheral. */ public String getType(); - + /** - * Should return an array of strings that identify the methods that this + * Should return an array of strings that identify the methods that this * peripheral exposes to Lua. This will be called once before each attachment, * and should not change when called multiple times. - * @return An array of strings representing method names. - * @see #callMethod + * + * @return An array of strings representing method names. + * @see #callMethod */ public String[] getMethodNames(); - + /** - * This is called when a lua program on an attached computercraft calls peripheral.call() with - * one of the methods exposed by getMethodNames().
- *
+ * This is called when a lua program on an attached computer calls {@code peripheral.call()} with + * one of the methods exposed by {@link #getMethodNames()}. + * * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe - * when interacting with minecraft objects. - * @param computer The interface to the computercraft that is making the call. Remember that multiple - * computers can be attached to a peripheral at once. - * @param context The context of the currently running lua thread. This can be used to wait for events - * or otherwise yield. - * @param method An integer identifying which of the methods from getMethodNames() the computercraft - * wishes to call. The integer indicates the index into the getMethodNames() table - * that corresponds to the string passed into peripheral.call() - * @param arguments An array of objects, representing the arguments passed into peripheral.call().
- * Lua values of type "string" will be represented by Object type String.
- * Lua values of type "number" will be represented by Object type Double.
- * Lua values of type "boolean" will be represented by Object type Boolean.
- * Lua values of any other type will be represented by a null object.
- * This array will be empty if no arguments are passed. - * @return An array of objects, representing values you wish to return to the lua program.
- * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.
- * All other types will be converted to nil.
- * You may return null to indicate no values should be returned. - * @throws Exception If you throw any exception from this function, a lua error will be raised with the - * same message as your exception. Use this to throw appropriate errors if the wrong - * arguments are supplied to your method. - * @see #getMethodNames + * when interacting with Minecraft objects. + * + * @param computer The interface to the computer that is making the call. Remember that multiple + * computers can be attached to a peripheral at once. + * @param context The context of the currently running lua thread. This can be used to wait for events + * or otherwise yield. + * @param method An integer identifying which of the methods from getMethodNames() the computercraft + * wishes to call. The integer indicates the index into the getMethodNames() table + * that corresponds to the string passed into peripheral.call() + * @param arguments An array of objects, representing the arguments passed into {@code peripheral.call()}.
+ * Lua values of type "string" will be represented by Object type String.
+ * Lua values of type "number" will be represented by Object type Double.
+ * Lua values of type "boolean" will be represented by Object type Boolean.
+ * Lua values of type "table" will be represented by Object type Map.
+ * Lua values of any other type will be represented by a null object.
+ * This array will be empty if no arguments are passed. + * @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats, + * Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types + * will be converted to nil. + * + * You may return null to indicate no values should be returned. + * @throws LuaException If you throw any exception from this function, a lua error will be raised with the + * same message as your exception. Use this to throw appropriate errors if the wrong + * arguments are supplied to your method. + * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, + * InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. + * @see #getMethodNames */ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; - + /** - * Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral. - * This will occur when a peripheral is placed next to an active computercraft, when a computercraft is turned on next to a peripheral, - * or when a turtle travels into a square next to a peripheral. - * Between calls to attach() and detach(), the attached computercraft can make method calls on the peripheral using peripheral.call(). - * This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment - * occurs.
- *
+ * Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral. + * + * This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a + * peripheral, or when a turtle travels into a square next to a peripheral. + * + * Between calls to attach() and detach(), the attached computer can make method calls on the peripheral using + * {@code peripheral.call()}. This method can be used to keep track of which computers are attached to the + * peripheral, or to take action when attachment occurs. + * * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe - * when interacting with minecraft objects. - * @param computer The interface to the computercraft that is being attached. Remember that multiple - * computers can be attached to a peripheral at once. - * @see #detach + * when interacting with Minecraft objects. + * + * @param computer The interface to the computer that is being attached. Remember that multiple + * computers can be attached to a peripheral at once. + * @see #detach */ public void attach( IComputerAccess computer ); /** - * Is called when a computercraft is detaching from the peripheral. - * This will occur when a computercraft shuts down, when the peripheral is removed while attached to computers, - * or when a turtle moves away from a square attached to a peripheral. - * This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment - * occurs.
- *
+ * Is called when a computer is detaching from the peripheral. + * + * This will occur when a computer shuts down, when the peripheral is removed while attached to computers, + * or when a turtle moves away from a square attached to a peripheral. This method can be used to keep track of + * which computers are attached to the peripheral, or to take action when detachment + * occurs. + * * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe - * when interacting with minecraft objects. - * @param computer The interface to the computercraft that is being detached. Remember that multiple - * computers can be attached to a peripheral at once. - * @see #detach + * when interacting with Minecraft objects. + * + * @param computer The interface to the computer that is being detached. Remember that multiple + * computers can be attached to a peripheral at once. + * @see #detach */ public void detach( IComputerAccess computer ); /** - * TODO: Document me + * Determine whether this peripheral is equivalent to another one. + * + * The minimal example should at least check whether they are the same object. However, you may wish to check if + * they point to the same block or tile entity. + * + * @param other The peripheral to compare against. This may be {@code null}. + * @return Whether these peripherals are equivalent. */ public boolean equals( IPeripheral other ); } diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index 6ac05be64..6e7dd6735 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -6,20 +6,22 @@ package dan200.computercraft.api.peripheral; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; /** - * This interface is used to create peripheral implementations for blocks + * This interface is used to create peripheral implementations for blocks. + * * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) */ public interface IPeripheralProvider { /** * Produce an peripheral implementation from a block location. + * + * @return A peripheral, or {@code null} if there is not a peripheral here you'd like to handle. * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) - * @return a peripheral, or null if there is not a peripheral here you'd like to handle. */ public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ); } diff --git a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java index ed6fdb197..32567ca0d 100644 --- a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java +++ b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -10,11 +10,31 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; /** - * This interface is used to restrict where turtles can move or build + * This interface is used to restrict where turtles can move or build. + * + * Turtles will call these methods before attempting to perform an action, allowing them to be cancelled. + * * @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider) */ public interface ITurtlePermissionProvider { + /** + * Determine whether a block can be entered by a turtle. + * + * @param world The world the block exists in + * @param pos The location of the block. + * @return Whether the turtle can move into this block. + */ public boolean isBlockEnterable( World world, BlockPos pos ); + + /** + * Determine whether a block can be modified by a turtle. + * + * This includes breaking and placing blocks. + * + * @param world The world the block exists in + * @param pos The location of the block. + * @return Whether the turtle can modify this block. + */ public boolean isBlockEditable( World world, BlockPos pos ); } diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java index 30216b2fb..14220b0a4 100644 --- a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -6,20 +6,23 @@ package dan200.computercraft.api.redstone; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; /** - * This interface is used to provide bundled redstone output for blocks + * This interface is used to provide bundled redstone output for blocks. + * * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) */ public interface IBundledRedstoneProvider { /** * Produce an bundled redstone output from a block location. + * + * @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to + * handle this block. * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) - * @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block */ public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java index 802ddb22a..fc54c5317 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -11,114 +11,179 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; /** * The interface passed to turtle by turtles, providing methods that they can call. - * This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade. + * + * This should not be implemented by your classes. Do not interact with turtles except via this interface and + * {@link ITurtleUpgrade}. */ public interface ITurtleAccess { /** * Returns the world in which the turtle resides. + * * @return the world in which the turtle resides. */ public World getWorld(); /** * Returns a vector containing the integer co-ordinates at which the turtle resides. + * * @return a vector containing the integer co-ordinates at which the turtle resides. */ public BlockPos getPosition(); /** - * TODO: Document me + * Attempt to move this turtle to a new position. + * + * This will preserve the turtle's internal state, such as it's inventory, computer and upgrades. It should + * be used before playing a movement animation using {@link #playAnimation(TurtleAnimation)}. + * + * @param world The new world to move it to + * @param pos The new position to move it to. + * @return Whether the movement was successful. It may fail if the block was not loaded or the block placement + * was cancelled. Note this will not check + * {@link dan200.computercraft.api.permissions.ITurtlePermissionProvider#isBlockEnterable(World, BlockPos)}. + * @throws UnsupportedOperationException When attempting to teleport on the client side. */ public boolean teleportTo( World world, BlockPos pos ); /** * Returns a vector containing the floating point co-ordinates at which the turtle is rendered. * This will shift when the turtle is moving. - * @param f The subframe fraction - * @return a vector containing the floating point co-ordinates at which the turtle resides. + * + * @param f The subframe fraction. + * @return A vector containing the floating point co-ordinates at which the turtle resides. + * @see #getVisualYaw(float) */ public Vec3d getVisualPosition( float f ); /** - * TODO: Document me + * Returns the yaw the turtle is facing when it is rendered. + * + * @param f The subframe fraction. + * @return The yaw the turtle is facing. + * @see #getVisualPosition(float) */ public float getVisualYaw( float f ); /** * Returns the world direction the turtle is currently facing. - * @return the world direction the turtle is currently facing. + * + * @return The world direction the turtle is currently facing. + * @see #setDirection(EnumFacing) */ public EnumFacing getDirection(); /** - * TODO: Document me + * Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to + * call {@link #playAnimation(TurtleAnimation)} to do so. + * + * @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west). + * @see #getDirection() */ public void setDirection( EnumFacing dir ); /** - * TODO: Document me + * Get the currently selected slot in the turtle's inventory. + * + * @return An integer representing the current slot. + * @see #getInventory() + * @see #setSelectedSlot(int) */ public int getSelectedSlot(); /** - * TODO: Document me + * Set the currently selected slot in the turtle's inventory. + * + * @param slot The slot to set. This must be greater or equal to 0 and less than the inventory size. Otherwise no + * action will be taken. + * @throws UnsupportedOperationException When attempting to change the slot on the client side. + * @see #getInventory() + * @see #getSelectedSlot() */ public void setSelectedSlot( int slot ); /** * Sets the colour of the turtle, as if the player had dyed it with a dye item. - * @param dyeColour 0-15 to dye the turtle one of the 16 standard minecraft colours, or -1 to remove the dye from the turtle. + * + * @param dyeColour 0-15 to dye the turtle one of the 16 standard Minecraft colours, or -1 to remove the dye from the turtle. + * @see #getDyeColour() */ public void setDyeColour( int dyeColour ); /** * Gets the colour the turtle has been dyed. - * @return 0-15 if the turtle has been dyed one of the 16 standard minecraft colours, -1 if the turtle is clean. + * + * @return 0-15 if the turtle has been dyed one of the 16 standard Minecraft colours, -1 if the turtle is clean. + * @see #getDyeColour() */ public int getDyeColour(); /** - * TODO: Document me + * Get the inventory of this turtle + * + * @return This turtle's inventory */ public IInventory getInventory(); /** - * TODO: Document me + * Determine whether this turtle will require fuel when performing actions. + * + * @return Whether this turtle needs fuel. + * @see #getFuelLevel() + * @see #setFuelLevel(int) */ public boolean isFuelNeeded(); /** - * TODO: Document me + * Get the current fuel level of this turtle. + * + * @return The turtle's current fuel level. + * @see #isFuelNeeded() + * @see #setFuelLevel(int) */ public int getFuelLevel(); /** - * TODO: Document me + * Set the fuel level to a new value. It is generally preferred to use {@link #consumeFuel(int)}} or {@link #addFuel(int)} + * instead. + * + * @param fuel The new amount of fuel. This must be between 0 and the fuel limit. + * @see #getFuelLevel() + * @see #getFuelLimit() + * @see #addFuel(int) + * @see #consumeFuel(int) */ public void setFuelLevel( int fuel ); /** - * TODO: Document me + * Get the maximum amount of fuel a turtle can hold. + * + * @return The turtle's fuel limit. */ public int getFuelLimit(); /** * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. - * @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number - * greater than the current fuel level of the turtle. + * + * @param fuel The amount of fuel to consume. + * @return Whether the turtle was able to consume the amount of fuel specified. Will return false if you supply a number + * greater than the current fuel level of the turtle. No fuel will be consumed if {@code false} is returned. + * @throws UnsupportedOperationException When attempting to consume fuel on the client side. */ public boolean consumeFuel( int fuel ); /** - * TODO: Document me + * Increase the turtle's fuel level by the given amount. + * + * @param fuel The amount to refuel with. + * @throws UnsupportedOperationException When attempting to refuel on the client side. */ public void addFuel( int fuel ); @@ -128,42 +193,67 @@ public interface ITurtleAccess * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. + * * @param command an object which will execute the custom command when its point in the queue is reached * @return the objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. + * @throws UnsupportedOperationException When attempting to execute a command on the client side. * @see ITurtleCommand */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException; /** - * TODO: Document me + * Start playing a specific animation. This will prevent other turtle commands from executing until + * it is finished. + * + * @param animation The animation to play. + * @throws UnsupportedOperationException When attempting to execute play an animation on the client side. + * @see TurtleAnimation */ public void playAnimation( TurtleAnimation animation ); /** * Returns the turtle on the specified side of the turtle, if there is one. - * @return the turtle on the specified side of the turtle, if there is one. + * + * @return The upgrade on the specified side of the turtle, if there is one. + * @see #setUpgrade(TurtleSide, ITurtleUpgrade) */ public ITurtleUpgrade getUpgrade( TurtleSide side ); /** - * TODO: Document me + * Set the upgrade for a given side, resetting peripherals and clearing upgrade specific data. + * + * @param side The side to set the upgrade on. + * @param upgrade The upgrade to set, may be {@code null} to clear. + * @see #getUpgrade(TurtleSide) */ public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ); /** * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. - * @return the peripheral created by the upgrade on the specified side of the turtle, if there is one. + * + * @return The peripheral created by the upgrade on the specified side of the turtle, {@code null} if none exists. */ public IPeripheral getPeripheral( TurtleSide side ); /** - * TODO: Document me + * Get an upgrade-specific NBT compound, which can be used to store arbitrary data. + * + * This will be persisted across turtle restarts and chunk loads, as well as being synced to the client. You must + * call {@link #updateUpgradeNBTData(TurtleSide)} after modifying it. + * + * @param side The side to get the upgrade data for. + * @return The upgrade-specific data. + * @see #updateUpgradeNBTData(TurtleSide) */ public NBTTagCompound getUpgradeNBTData( TurtleSide side ); /** - * TODO: Document me + * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the + * client and persisted. + * + * @param side The side to mark dirty. + * @see #updateUpgradeNBTData(TurtleSide) */ public void updateUpgradeNBTData( TurtleSide side ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java index c4454881e..b75a910ca 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -6,20 +6,27 @@ package dan200.computercraft.api.turtle; +import dan200.computercraft.api.lua.ILuaContext; + /** - * An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand - * @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) + * An interface for objects executing custom turtle commands, used with {@link ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand)}. + * + * @see ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand) */ public interface ITurtleCommand { /** * Will be called by the turtle on the main thread when it is time to execute the custom command. + * * The handler should either perform the work of the command, and return success, or return * failure with an error message to indicate the command cannot be executed at this time. - * @param turtle access to the turtle for whom the command was issued - * @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage ) - * @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) - * @see dan200.computercraft.api.turtle.TurtleCommandResult + * + * @param turtle Access to the turtle for whom the command was issued. + * @return A result, indicating whether this action succeeded or not. + * @see ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand) + * @see TurtleCommandResult#success() + * @see TurtleCommandResult#failure(String) + * @see TurtleCommandResult */ public TurtleCommandResult execute( ITurtleAccess turtle ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 25188f606..93a9d2e59 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -6,8 +6,10 @@ package dan200.computercraft.api.turtle; +import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; @@ -21,7 +23,8 @@ import javax.vecmath.Matrix4f; /** * The primary interface for defining an update for Turtles. A turtle update * can either be a new tool, or a new peripheral. - * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + * + * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ public interface ITurtleUpgrade { @@ -29,7 +32,8 @@ public interface ITurtleUpgrade * Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem" or "my_mod:my_upgrade". * You should use a unique resource domain to ensure this upgrade is uniquely identified. * The turtle will fail registration if an already used ID is specified. - * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + * + * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ public ResourceLocation getUpgradeID(); @@ -38,71 +42,83 @@ public interface ITurtleUpgrade * for backwards compatibility with pre-1.76 worlds. If your upgrade was * not released for older ComputerCraft versions, you can return -1 here. * The turtle will fail registration if an already used positive ID is specified. - * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + * + * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ public int getLegacyUpgradeID(); /** - * Return a String to describe this type of turtle in turtle item names. + * Return an unlocalised string to describe this type of turtle in turtle item names. + * * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". - */ + */ public String getUnlocalisedAdjective(); /** * Return whether this turtle adds a tool or a peripheral to the turtle. + * * @see TurtleUpgradeType for the differences between the two. - */ + */ public TurtleUpgradeType getType(); - + /** * Return an item stack representing the type of item that a turtle must be crafted * with to create a turtle which holds this upgrade. This item stack is also used - * to determine the upgrade given by turtle.equip() + * to determine the upgrade given by {@code turtle.equip()} */ public ItemStack getCraftingItem(); /** - * Will only be called for peripheral upgrades. Creates a peripheral for a turtle - * being placed using this upgrade. The peripheral created will be stored - * for the lifetime of the upgrade, will have update() called once-per-tick, and will be - * attached, detached and have methods called in the same manner as a Computer peripheral. + * Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade. + * + * The peripheral created will be stored for the lifetime of the upgrade and will be passed as an argument to + * {@link #update(ITurtleAccess, TurtleSide)}. It will be attached, detached and have methods called in the same + * manner as a Computer peripheral. * * @param turtle Access to the turtle that the peripheral is being created for. - * @param side Which side of the turtle (left or right) that the upgrade resides on. - * @return The newly created peripheral. You may return null if this upgrade is a Tool + * @param side Which side of the turtle (left or right) that the upgrade resides on. + * @return The newly created peripheral. You may return {@code null} if this upgrade is a Tool * and this method is not expected to be called. - */ + */ public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); /** * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called * by the turtle, and the tool is required to do some work. - * @param turtle Access to the turtle that the tool resides on. - * @param side Which side of the turtle (left or right) the tool resides on. - * @param verb Which action (dig or attack) the turtle is being called on to perform. + * + * @param turtle Access to the turtle that the tool resides on. + * @param side Which side of the turtle (left or right) the tool resides on. + * @param verb Which action (dig or attack) the turtle is being called on to perform. * @param direction Which world direction the action should be performed in, relative to the turtles - * position. This will either be up, down, or the direction the turtle is facing, depending on - * whether dig, digUp or digDown was called. - * @return Whether the turtle was able to perform the action, and hence whether the turtle.dig() - * or turtle.attack() lua method should return true. If true is returned, the tool will perform - * a swinging animation. You may return null if this turtle is a Peripheral - * and this method is not expected to be called. + * position. This will either be up, down, or the direction the turtle is facing, depending on + * whether dig, digUp or digDown was called. + * @return Whether the turtle was able to perform the action, and hence whether the {@code turtle.dig()} + * or {@code turtle.attack()} lua method should return true. If true is returned, the tool will perform + * a swinging animation. You may return {@code null} if this turtle is a Peripheral and this method is not expected + * to be called. */ public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction ); /** * Called to obtain the model to be used when rendering a turtle peripheral. + * + * This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)}, + * {@link net.minecraft.client.renderer.block.model.ModelManager#getModel(ModelResourceLocation)} or any other + * source. + * * @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models! - * @param side Which side of the turtle (left or right) the upgrade resides on. - * @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning a transformation of null has the same effect as the identify matrix. + * @param side Which side of the turtle (left or right) the upgrade resides on. + * @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning + * a transformation of {@code null} has the same effect as the identify matrix. */ - @SideOnly( Side.CLIENT ) + @SideOnly(Side.CLIENT) public Pair getModel( ITurtleAccess turtle, TurtleSide side ); /** * Called once per tick for each turtle which has the upgrade equipped. + * * @param turtle Access to the turtle that the upgrade resides on. - * @param side Which side of the turtle (left or right) the upgrade resides on. + * @param side Which side of the turtle (left or right) the upgrade resides on. */ public void update( ITurtleAccess turtle, TurtleSide side ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java index e720335a0..a93a1ea05 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -6,17 +6,82 @@ package dan200.computercraft.api.turtle; +/** + * An animation a turtle will play between executing commands. + * + * Each animation takes 8 ticks to complete unless otherwise specified. + * + * @see ITurtleAccess#playAnimation(TurtleAnimation) + */ public enum TurtleAnimation { + /** + * An animation which does nothing. This takes no time to complete. + * + * @see #Wait + * @see #ShortWait + */ None, + + /** + * Make the turtle move forward. Note that the animation starts from the block behind it, and + * moves into this one. + */ MoveForward, + + /** + * Make the turtle move backwards. Note that the animation starts from the block in front it, and + * moves into this one. + */ MoveBack, + + /** + * Make the turtle move backwards. Note that the animation starts from the block above it, and + * moves into this one. + */ MoveUp, + + /** + * Make the turtle move backwards. Note that the animation starts from the block below it, and + * moves into this one. + */ MoveDown, + + /** + * Turn the turtle to the left. Note that the animation starts with the turtle facing right, and + * the turtle turns to face in the current direction. + */ TurnLeft, + + /** + * Turn the turtle to the left. Note that the animation starts with the turtle facing right, and + * the turtle turns to face in the current direction. + */ TurnRight, + + /** + * Swing the tool on the left. + */ SwingLeftTool, + + /** + * Swing the tool on the right. + */ SwingRightTool, + + /** + * Wait until the animation has finished, performing no movement. + * + * @see #ShortWait + * @see #None + */ Wait, + + /** + * Wait until the animation has finished, performing no movement. This takes 4 ticks to complete. + * + * @see #Wait + * @see #None + */ ShortWait, } diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java index 09c528827..df0b84c50 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -6,16 +6,35 @@ package dan200.computercraft.api.turtle; +import net.minecraft.util.EnumFacing; + +/** + * Used to indicate the result of executing a turtle command. + * + * @see ITurtleCommand#execute(ITurtleAccess) + * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) + */ public final class TurtleCommandResult { private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null ); private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null ); + /** + * Create a successful command result with no result. + * + * @return A successful command result with no values. + */ public static TurtleCommandResult success() { return success( null ); } + /** + * Create a successful command result with the given result values. + * + * @param results The results of executing this command. + * @return A successful command result with the given values. + */ public static TurtleCommandResult success( Object[] results ) { if( results == null || results.length == 0 ) @@ -28,11 +47,22 @@ public final class TurtleCommandResult } } + /** + * Create a failed command result with no error message. + * + * @return A failed command result with no message. + */ public static TurtleCommandResult failure() { return failure( null ); } + /** + * Create a failed command result with an error message. + * + * @param errorMessage The error message to provide. + * @return A failed command result with a message. + */ public static TurtleCommandResult failure( String errorMessage ) { if( errorMessage == null ) @@ -56,16 +86,31 @@ public final class TurtleCommandResult m_results = results; } + /** + * Determine whether the command executed successfully. + * + * @return If the command was successful. + */ public boolean isSuccess() { return m_success; } + /** + * Get the error message of this command result. + * + * @return The command's error message, or {@code null} if it was a success. + */ public String getErrorMessage() { return m_errorMessage; } + /** + * Get the resulting values of this command result. + * + * @return The command's result, or {@code null} if it was a failure. + */ public Object[] getResults() { return m_results; diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java index d7c75cf59..94947fa9e 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java @@ -12,12 +12,12 @@ package dan200.computercraft.api.turtle; public enum TurtleSide { /** - * The turtles left side (where the pickaxe usually is on a Wireless Mining Turtle) + * The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle) */ Left, /** - * The turtles right side (where the modem usually is on a Wireless Mining Turtle) + * The turtle's right side (where the modem usually is on a Wireless Mining Turtle) */ Right, } diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java index 4a6ea5a50..be1bf92b5 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -7,21 +7,21 @@ package dan200.computercraft.api.turtle; /** - * An enum representing the two different types of turtle that an ITurtleUpgrade - * implementation can add to a turtle. - * @see ITurtleUpgrade + * An enum representing the different types of turtle that an {@link ITurtleUpgrade} implementation can add to a turtle. + * + * @see ITurtleUpgrade#getType() */ public enum TurtleUpgradeType { /** - * A tool is rendered as an item on the side of the turtle, and responds to the turtle.dig() - * and turtle.attack() methods (Such as pickaxe or sword on Mining and Melee turtles). + * A tool is rendered as an item on the side of the turtle, and responds to the {@code turtle.dig()} + * and {@code turtle.attack()} methods (Such as pickaxe or sword on Mining and Melee turtles). */ Tool, - + /** * A peripheral adds a special peripheral which is attached to the side of the turtle, - * and can be interacted with the peripheral API (Such as the modem on Wireless Turtles). + * and can be interacted with the {@code peripheral} API (Such as the modem on Wireless Turtles). */ Peripheral, @@ -30,8 +30,7 @@ public enum TurtleUpgradeType * your upgrade to also provide methods. For example, a pickaxe could provide methods * determining whether it can break the given block or not. */ - Both, - ; + Both,; public boolean isTool() { diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java index 174e2599c..5c24e77e6 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -6,21 +6,24 @@ package dan200.computercraft.api.turtle; +import net.minecraft.util.EnumFacing; + /** - * An enum representing the two different actions that an ITurtleUpgrade of type - * Tool may be called on to perform by a turtle. - * @see ITurtleUpgrade - * @see ITurtleUpgrade#useTool + * An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by + * a turtle. + * + * @see ITurtleUpgrade#getType() + * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) */ public enum TurtleVerb { /** - * The turtle called turtle.dig(), turtle.digUp() or turtle.digDown() + * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()} */ Dig, - + /** - * The turtle called turtle.attack(), turtle.attackUp() or turtle.attackDown() + * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()} */ Attack, } From 76e926c0907a6945bc4aeb99c5b70f6b0adc5b01 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 5 May 2017 16:07:18 +0100 Subject: [PATCH 33/38] Document several undocumented arguments and exceptions --- .../computercraft/api/ComputerCraftAPI.java | 16 ++++++++++++---- .../computercraft/api/filesystem/IMount.java | 5 +++++ .../api/filesystem/IWritableMount.java | 7 ++++++- .../api/filesystem/package-info.java | 2 +- .../computercraft/api/lua/ILuaObject.java | 11 +++++++++++ .../api/media/IMediaProvider.java | 3 ++- .../api/peripheral/IPeripheralProvider.java | 3 +++ .../redstone/IBundledRedstoneProvider.java | 3 +++ .../api/turtle/ITurtleAccess.java | 19 +++++++++++++++---- .../api/turtle/ITurtleUpgrade.java | 9 ++++++++- 10 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index de538fad2..318a395f9 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -123,8 +123,8 @@ public final class ComputerCraftAPI * resources with the same domain and path. * * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class - * @param domain The domain under which to look for resources. eg: "mymod" - * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" + * @param domain The domain under which to look for resources. eg: "mymod". + * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles". * @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or * IComputerAccess.mountWritable() to mount this on a Computers' file system. * @see IComputerAccess#mount(String, IMount) @@ -148,6 +148,7 @@ public final class ComputerCraftAPI /** * Registers a peripheral handler to convert blocks into {@link IPeripheral} implementations. * + * @param handler The peripheral provider to register. * @see dan200.computercraft.api.peripheral.IPeripheral * @see dan200.computercraft.api.peripheral.IPeripheralProvider */ @@ -169,6 +170,7 @@ public final class ComputerCraftAPI * users should be able to craft Turtles with your new turtle. It is recommended to call * this during the load() method of your mod. * + * @param upgrade The turtle upgrade to register. * @see dan200.computercraft.api.turtle.ITurtleUpgrade */ public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) @@ -188,8 +190,9 @@ public final class ComputerCraftAPI } /** - * Registers a bundled redstone handler to provide bundled redstone output for blocks + * Registers a bundled redstone handler to provide bundled redstone output for blocks. * + * @param handler The bundled redstone provider to register. * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider */ public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) @@ -208,6 +211,9 @@ public final class ComputerCraftAPI /** * If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output. * + * @param world The world this block is in. + * @param pos The position this block is at. + * @param side The side to extract the bundled redstone output from. * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider @@ -229,6 +235,7 @@ public final class ComputerCraftAPI /** * Registers a media handler to provide {@link IMedia} implementations for Items * + * @param handler The media provider to register. * @see dan200.computercraft.api.media.IMediaProvider */ public static void registerMediaProvider( IMediaProvider handler ) @@ -245,8 +252,9 @@ public final class ComputerCraftAPI } /** - * Registers a permission handler to restrict where turtles can move or build + * Registers a permission handler to restrict where turtles can move or build. * + * @param handler The turtle permission provider to register. * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider */ public static void registerPermissionProvider( ITurtlePermissionProvider handler ) diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java index 7df0fdf9b..6734b0ab2 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -34,6 +34,7 @@ public interface IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" * @return If the file exists. + * @throws IOException If an error occurs when checking the existence of the file. */ public boolean exists( String path ) throws IOException; @@ -42,6 +43,7 @@ public interface IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms". * @return If the file exists and is a directory + * @throws IOException If an error occurs when checking whether the file is a directory. */ public boolean isDirectory( String path ) throws IOException; @@ -50,6 +52,7 @@ public interface IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms". * @param contents A list of strings. Add all the file names to this list. + * @throws IOException If the file was not a directory, or could not be listed. */ public void list( String path, List contents ) throws IOException; @@ -58,6 +61,7 @@ public interface IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @return The size of the file, in bytes. + * @throws IOException If the file does not exist, or its size could not be determined. */ public long getSize( String path ) throws IOException; @@ -66,6 +70,7 @@ public interface IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @return A stream representing the contents of the file. + * @throws IOException If the file does not exist, or could not be opened. */ public InputStream openForRead( String path ) throws IOException; } diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java index 2bc32d4d5..8d7148692 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -31,6 +31,7 @@ public interface IWritableMount extends IMount * Creates a directory at a given path inside the virtual file system. * * @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms". + * @throws IOException If the directory already exists or could not be created. */ public void makeDirectory( String path ) throws IOException; @@ -38,6 +39,7 @@ public interface IWritableMount extends IMount * Deletes a directory at a given path inside the virtual file system. * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms". + * @throws IOException If the file does not exist or could not be deleted. */ public void delete( String path ) throws IOException; @@ -45,7 +47,8 @@ public interface IWritableMount extends IMount * Opens a file with a given path, and returns an {@link OutputStream} for writing to it. * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". - * @return a stream for writing to + * @return A stream for writing to + * @throws IOException If the file could not be opened for writing. */ public OutputStream openForWrite( String path ) throws IOException; @@ -54,6 +57,7 @@ public interface IWritableMount extends IMount * * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram". * @return A stream for writing to. + * @throws IOException If the file could not be opened for writing. */ public OutputStream openForAppend( String path ) throws IOException; @@ -62,6 +66,7 @@ public interface IWritableMount extends IMount * mount, and write operations should fail once it reaches zero. * * @return The amount of free space, in bytes. + * @throws IOException If the remaining space could not be computed. */ public long getRemainingSpace() throws IOException; } diff --git a/src/main/java/dan200/computercraft/api/filesystem/package-info.java b/src/main/java/dan200/computercraft/api/filesystem/package-info.java index dc0fb7927..92011b7ff 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/package-info.java +++ b/src/main/java/dan200/computercraft/api/filesystem/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java index ac5162be2..e3d7db6fa 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -21,6 +21,7 @@ public interface ILuaObject * Get the names of the methods that this object implements. This works the same as {@link IPeripheral#getMethodNames()}. * See that method for detailed documentation. * + * @return The method names this object provides. * @see IPeripheral#getMethodNames() */ public String[] getMethodNames(); @@ -30,6 +31,16 @@ public interface ILuaObject * {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}}. See that method for detailed * documentation. * + * @param context The context of the currently running lua thread. This can be used to wait for events + * or otherwise yield. + * @param method An integer identifying which of the methods from getMethodNames() the computercraft + * wishes to call. The integer indicates the index into the getMethodNames() table + * that corresponds to the string passed into peripheral.call() + * @param arguments The arguments for this method. See {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])} + * the possible values and conversion rules. + * @return An array of objects, representing the values you wish to return to the Lua program. + * See {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])} for the valid values and + * conversion rules. * @throws LuaException If the task could not be queued, or if the task threw an exception. * @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, * InterruptedException will be thrown. This exception must not be caught or diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java index e2aa60661..82f3b3e48 100644 --- a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -18,7 +18,8 @@ public interface IMediaProvider /** * Produce an IMedia implementation from an ItemStack. * - * @return an IMedia implementation, or null if the item is not something you wish to handle + * @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 * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) */ public IMedia getMedia( ItemStack stack ); diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index 6e7dd6735..20f440e69 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -20,6 +20,9 @@ public interface IPeripheralProvider /** * Produce an peripheral implementation from a block location. * + * @param world The world the block is in. + * @param pos The position the block is at. + * @param side The side to get the peripheral from. * @return A peripheral, or {@code null} if there is not a peripheral here you'd like to handle. * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) */ diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java index 14220b0a4..d5a2e201f 100644 --- a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -20,6 +20,9 @@ public interface IBundledRedstoneProvider /** * Produce an bundled redstone output from a block location. * + * @param world The world this block is in. + * @param pos The position this block is at. + * @param side The side to extract the bundled redstone output from. * @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to * handle this block. * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java index fc54c5317..444279059 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -112,7 +112,8 @@ public interface ITurtleAccess /** * Sets the colour of the turtle, as if the player had dyed it with a dye item. * - * @param dyeColour 0-15 to dye the turtle one of the 16 standard Minecraft colours, or -1 to remove the dye from the turtle. + * @param dyeColour 0-15 to dye the turtle one of the 16 standard Minecraft dye colours, or -1 to remove + * the dye from the turtle. * @see #getDyeColour() */ public void setDyeColour( int dyeColour ); @@ -120,7 +121,8 @@ public interface ITurtleAccess /** * Gets the colour the turtle has been dyed. * - * @return 0-15 if the turtle has been dyed one of the 16 standard Minecraft colours, -1 if the turtle is clean. + * @return 0-15 if the turtle has been dyed one of the 16 standard Minecraft dye colours, -1 if the turtle + * is clean. * @see #getDyeColour() */ public int getDyeColour(); @@ -194,11 +196,18 @@ public interface ITurtleAccess * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. * - * @param command an object which will execute the custom command when its point in the queue is reached - * @return the objects the command returned when executed. you should probably return these to the player + * @param context The Lua context to pull events from. + * @param command An object which will execute the custom command when its point in the queue is reached + * @return The objects the command returned when executed. you should probably return these to the player * unchanged if called from a peripheral method. * @throws UnsupportedOperationException When attempting to execute a command on the client side. + * @throws LuaException If the user presses CTRL+T to terminate the current program while {@code executeCommand()} is + * waiting for an event, a "Terminated" exception will be thrown here. + * @throws InterruptedException If the user shuts down or reboots the computer while pullEvent() is waiting for an + * event, InterruptedException will be thrown. This exception must not be caught or + * intercepted, or the computer will leak memory and end up in a broken state. * @see ITurtleCommand + * @see ILuaContext#pullEvent(String) */ public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException; @@ -215,6 +224,7 @@ public interface ITurtleAccess /** * Returns the turtle on the specified side of the turtle, if there is one. * + * @param side The side to get the upgrade from. * @return The upgrade on the specified side of the turtle, if there is one. * @see #setUpgrade(TurtleSide, ITurtleUpgrade) */ @@ -232,6 +242,7 @@ public interface ITurtleAccess /** * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. * + * @param side The side to get the peripheral from. * @return The peripheral created by the upgrade on the specified side of the turtle, {@code null} if none exists. */ public IPeripheral getPeripheral( TurtleSide side ); diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 93a9d2e59..5d4419b10 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -33,6 +33,7 @@ public interface ITurtleUpgrade * You should use a unique resource domain to ensure this upgrade is uniquely identified. * The turtle will fail registration if an already used ID is specified. * + * @return The unique ID for this upgrade. * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ public ResourceLocation getUpgradeID(); @@ -43,6 +44,7 @@ public interface ITurtleUpgrade * not released for older ComputerCraft versions, you can return -1 here. * The turtle will fail registration if an already used positive ID is specified. * + * @return The legacy ID, or -1 if is needed. * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ public int getLegacyUpgradeID(); @@ -51,13 +53,16 @@ public interface ITurtleUpgrade * Return an unlocalised string to describe this type of turtle in turtle item names. * * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". + * + * @return The localisation key for this upgrade's adjective. */ public String getUnlocalisedAdjective(); /** * Return whether this turtle adds a tool or a peripheral to the turtle. * - * @see TurtleUpgradeType for the differences between the two. + * @return The type of upgrade this is. + * @see TurtleUpgradeType for the differences between them. */ public TurtleUpgradeType getType(); @@ -65,6 +70,8 @@ public interface ITurtleUpgrade * Return an item stack representing the type of item that a turtle must be crafted * with to create a turtle which holds this upgrade. This item stack is also used * to determine the upgrade given by {@code turtle.equip()} + * + * @return The item stack to craft with, or {@code null} if it cannot be crafted. */ public ItemStack getCraftingItem(); From 0cdd0ea21afa25e2b3e369dfe9c138fadec3cf7c Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 5 May 2017 16:16:09 +0100 Subject: [PATCH 34/38] Change license headers to block comments This means they do not get picked up by Javadoc and friends --- src/main/java/dan200/computercraft/api/ComputerCraftAPI.java | 2 +- src/main/java/dan200/computercraft/api/filesystem/IMount.java | 2 +- .../dan200/computercraft/api/filesystem/IWritableMount.java | 2 +- src/main/java/dan200/computercraft/api/lua/ILuaContext.java | 2 +- src/main/java/dan200/computercraft/api/lua/ILuaObject.java | 2 +- src/main/java/dan200/computercraft/api/lua/ILuaTask.java | 2 +- src/main/java/dan200/computercraft/api/lua/LuaException.java | 2 +- src/main/java/dan200/computercraft/api/lua/package-info.java | 2 +- src/main/java/dan200/computercraft/api/media/IMedia.java | 2 +- .../java/dan200/computercraft/api/media/IMediaProvider.java | 2 +- src/main/java/dan200/computercraft/api/media/package-info.java | 2 +- src/main/java/dan200/computercraft/api/package-info.java | 2 +- .../dan200/computercraft/api/peripheral/IComputerAccess.java | 2 +- .../java/dan200/computercraft/api/peripheral/IPeripheral.java | 2 +- .../computercraft/api/peripheral/IPeripheralProvider.java | 2 +- .../java/dan200/computercraft/api/peripheral/package-info.java | 2 +- .../api/permissions/ITurtlePermissionProvider.java | 2 +- .../java/dan200/computercraft/api/permissions/package-info.java | 2 +- .../computercraft/api/redstone/IBundledRedstoneProvider.java | 2 +- .../java/dan200/computercraft/api/redstone/package-info.java | 2 +- .../java/dan200/computercraft/api/turtle/ITurtleAccess.java | 2 +- .../java/dan200/computercraft/api/turtle/ITurtleCommand.java | 2 +- .../java/dan200/computercraft/api/turtle/ITurtleUpgrade.java | 2 +- .../java/dan200/computercraft/api/turtle/TurtleAnimation.java | 2 +- .../dan200/computercraft/api/turtle/TurtleCommandResult.java | 2 +- src/main/java/dan200/computercraft/api/turtle/TurtleSide.java | 2 +- .../java/dan200/computercraft/api/turtle/TurtleUpgradeType.java | 2 +- src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java | 2 +- src/main/java/dan200/computercraft/api/turtle/package-info.java | 2 +- 29 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index 318a395f9..c88bde40e 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java index 6734b0ab2..d5869d3e8 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java index 8d7148692..a1173167f 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java index 503fd6cec..16ce1d8d6 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java index e3d7db6fa..6da7ea720 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java index 65a389bba..88e3ee035 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/LuaException.java b/src/main/java/dan200/computercraft/api/lua/LuaException.java index bbb860090..90038d164 100644 --- a/src/main/java/dan200/computercraft/api/lua/LuaException.java +++ b/src/main/java/dan200/computercraft/api/lua/LuaException.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/lua/package-info.java b/src/main/java/dan200/computercraft/api/lua/package-info.java index 0d418d3c3..1b5c4168e 100644 --- a/src/main/java/dan200/computercraft/api/lua/package-info.java +++ b/src/main/java/dan200/computercraft/api/lua/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/media/IMedia.java b/src/main/java/dan200/computercraft/api/media/IMedia.java index 286489ca3..b6eee6414 100644 --- a/src/main/java/dan200/computercraft/api/media/IMedia.java +++ b/src/main/java/dan200/computercraft/api/media/IMedia.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java index 82f3b3e48..5b0188e04 100644 --- a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/media/package-info.java b/src/main/java/dan200/computercraft/api/media/package-info.java index 856053bb4..89811800c 100644 --- a/src/main/java/dan200/computercraft/api/media/package-info.java +++ b/src/main/java/dan200/computercraft/api/media/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/package-info.java b/src/main/java/dan200/computercraft/api/package-info.java index 1ed08dddb..b8ac2bcdf 100644 --- a/src/main/java/dan200/computercraft/api/package-info.java +++ b/src/main/java/dan200/computercraft/api/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java index 4429c74c7..964f48480 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java index a790886c8..bd9311dd7 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index 20f440e69..51fde616b 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/peripheral/package-info.java b/src/main/java/dan200/computercraft/api/peripheral/package-info.java index 7536867b6..46862eeaf 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/package-info.java +++ b/src/main/java/dan200/computercraft/api/peripheral/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java index 32567ca0d..7ce60290d 100644 --- a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java +++ b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/permissions/package-info.java b/src/main/java/dan200/computercraft/api/permissions/package-info.java index 84bb7a169..1c26a5962 100755 --- a/src/main/java/dan200/computercraft/api/permissions/package-info.java +++ b/src/main/java/dan200/computercraft/api/permissions/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java index d5a2e201f..8447f0016 100644 --- a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/redstone/package-info.java b/src/main/java/dan200/computercraft/api/redstone/package-info.java index 292873e90..dac464a2e 100644 --- a/src/main/java/dan200/computercraft/api/redstone/package-info.java +++ b/src/main/java/dan200/computercraft/api/redstone/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java index 444279059..efe0202fd 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java index b75a910ca..1e7827827 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index 5d4419b10..8020235f0 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java index a93a1ea05..201e81195 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java index df0b84c50..c72dd9fab 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java index 94947fa9e..b66029452 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java index be1bf92b5..6958298c7 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java index 5c24e77e6..03c2c88c2 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. diff --git a/src/main/java/dan200/computercraft/api/turtle/package-info.java b/src/main/java/dan200/computercraft/api/turtle/package-info.java index 695335638..178e7168f 100644 --- a/src/main/java/dan200/computercraft/api/turtle/package-info.java +++ b/src/main/java/dan200/computercraft/api/turtle/package-info.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of the public ComputerCraft API - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. 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. From 4b95ed5d536ac25a47d81b3a2d8504352e427348 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 5 May 2017 16:53:49 +0100 Subject: [PATCH 35/38] Do not reset redstone inputs when adding peripherals As of 8abff95441b87df733df839eca6c373513e0487b, peripherals no longer block redstone input. As this is no longer the case, redstone levels should not be reset. --- .../dan200/computercraft/shared/turtle/core/TurtleBrain.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 726498f9b..6f9071cb7 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -977,15 +977,11 @@ public class TurtleBrain implements ITurtleAccess if( !m_peripherals.containsKey( side ) ) { serverComputer.setPeripheral( dir, peripheral ); - serverComputer.setRedstoneInput( dir, 0 ); - serverComputer.setBundledRedstoneInput( dir, 0 ); m_peripherals.put( side, peripheral ); } else if( !m_peripherals.get( side ).equals( peripheral ) ) { serverComputer.setPeripheral( dir, peripheral ); - serverComputer.setRedstoneInput( dir, 0 ); - serverComputer.setBundledRedstoneInput( dir, 0 ); m_peripherals.remove( side ); m_peripherals.put( side, peripheral ); } From b0ac48b9a3bc81ecf487ec64edc396a05de3afae Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 19:11:59 +0200 Subject: [PATCH 36/38] Use some sweet tricks to have a weak set to store open files --- .../dan200/computercraft/core/filesystem/FileSystem.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index 71344f562..cca6a01a2 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -11,7 +11,6 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import java.io.*; -import java.lang.ref.WeakReference; import java.util.*; import java.util.regex.Pattern; @@ -292,7 +291,7 @@ public class FileSystem } private final Map m_mounts = new HashMap(); - private final WeakHashMap m_openFiles = new WeakHashMap(); + private final Set m_openFiles = Collections.newSetFromMap( new WeakHashMap() ); public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException { @@ -309,7 +308,7 @@ public class FileSystem // Close all dangling open files synchronized( m_openFiles ) { - for(IMountedFile file : m_openFiles.keySet()) + for(IMountedFile file : m_openFiles) { try { file.close(); From 988e9f10dbb453137eed82273b5eb64bd91d4262 Mon Sep 17 00:00:00 2001 From: Lignum Date: Fri, 5 May 2017 19:13:52 +0200 Subject: [PATCH 37/38] Fix compiler error --- .../java/dan200/computercraft/core/filesystem/FileSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java index cca6a01a2..86309ce97 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystem.java @@ -666,7 +666,7 @@ public class FileSystem throw new FileSystemException("Too many files already open"); } - m_openFiles.put( file, null ); + m_openFiles.add( file ); return file; } } From c7f5d039b2c8f478cc8e8250b26a1e762dc53f5d Mon Sep 17 00:00:00 2001 From: SquidDev Date: Sat, 6 May 2017 15:31:06 +0100 Subject: [PATCH 38/38] Use IBlockState instead of Block methods There was a crash in RedstoneUtil when redstone state was changing next to a full block due to the incorrect state being passed. By using IBlockState methods we ensure that this cannot happen again. The old IBlockState methods were also deprecated, so this reduces the warning count a little. I've also moved string translation into StringUtils, to reduce the number of deprecation warnings from there. --- .../proxy/ComputerCraftProxyClient.java | 1 - .../shared/computer/apis/CommandAPI.java | 2 +- .../pocket/items/ItemPocketComputer.java | 8 ++-- .../proxy/ComputerCraftProxyCommon.java | 8 +--- .../turtle/core/TurtleInspectCommand.java | 2 +- .../shared/turtle/items/ItemTurtleBase.java | 20 ++++----- .../shared/turtle/upgrades/TurtleHoe.java | 3 +- .../shared/turtle/upgrades/TurtleShovel.java | 3 +- .../shared/turtle/upgrades/TurtleSword.java | 3 +- .../shared/turtle/upgrades/TurtleTool.java | 2 +- .../shared/util/RedstoneUtil.java | 42 +++++++------------ .../computercraft/shared/util/StringUtil.java | 18 ++++++++ .../computercraft/shared/util/WorldUtil.java | 11 +---- 13 files changed, 57 insertions(+), 66 deletions(-) diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 0897cdecd..eb3366d1e 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -412,7 +412,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon private void registerForgeHandlers() { ForgeHandlers handlers = new ForgeHandlers(); - FMLCommonHandler.instance().bus().register( handlers ); MinecraftForge.EVENT_BUS.register( handlers ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java index c98b11fca..189855231 100644 --- a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -119,7 +119,7 @@ public class CommandAPI implements ILuaAPI table.put( "metadata", metadata ); Map stateTable = new HashMap(); - for( Object o : block.getActualState( state, world, pos ).getProperties().entrySet() ) + for( Object o : state.getActualState( world, pos ).getProperties().entrySet() ) { ImmutableMap.Entry entry = (ImmutableMap.Entry)o; String propertyName = entry.getKey().getName(); diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index 1e9371667..1044cbe37 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -18,6 +18,7 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.pocket.apis.PocketAPI; import dan200.computercraft.shared.pocket.peripherals.PocketModemPeripheral; +import dan200.computercraft.shared.util.StringUtil; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @@ -30,7 +31,6 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundEvent; -import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import java.util.List; @@ -200,14 +200,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia boolean modem = getHasModem( stack ); if( modem ) { - return I18n.translateToLocalFormatted( + return StringUtil.translateToLocalFormatted( baseString + ".upgraded.name", - I18n.translateToLocal( "upgrade.computercraft:wireless_modem.adjective" ) + StringUtil.translateToLocal( "upgrade.computercraft:wireless_modem.adjective" ) ); } else { - return I18n.translateToLocal( baseString + ".name" ); + return StringUtil.translateToLocal( baseString + ".name" ); } } diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 242c4150c..d6037bc10 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -48,10 +48,7 @@ import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import dan200.computercraft.shared.util.Colour; -import dan200.computercraft.shared.util.CreativeTabMain; -import dan200.computercraft.shared.util.ImpostorRecipe; -import dan200.computercraft.shared.util.ImpostorShapelessRecipe; +import dan200.computercraft.shared.util.*; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -68,7 +65,6 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.IThreadListener; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.translation.I18n; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; @@ -130,7 +126,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy { ItemRecord record = (ItemRecord) item; String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" ); - return I18n.translateToLocal( key ); + return StringUtil.translateToLocal( key ); } return null; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java index 0562f91f1..6c1abb8cb 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java @@ -57,7 +57,7 @@ public class TurtleInspectCommand implements ITurtleCommand table.put( "metadata", metadata ); Map stateTable = new HashMap(); - for( Object o : block.getActualState( state, world, newPosition ).getProperties().entrySet() ) + for( Object o : state.getActualState( world, newPosition ).getProperties().entrySet() ) { ImmutableMap.Entry entry = (ImmutableMap.Entry)o; String propertyName = entry.getKey().getName(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java index 8ce4ca1cf..af4585d90 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java @@ -14,6 +14,7 @@ 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.Colour; +import dan200.computercraft.shared.util.StringUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; @@ -21,10 +22,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.translation.I18n; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import java.util.ArrayList; @@ -142,29 +142,29 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right ); if( left != null && right != null ) { - return I18n.translateToLocalFormatted( + return StringUtil.translateToLocalFormatted( baseString + ".upgraded_twice.name", - I18n.translateToLocal( right.getUnlocalisedAdjective() ), - I18n.translateToLocal( left.getUnlocalisedAdjective() ) + StringUtil.translateToLocal( right.getUnlocalisedAdjective() ), + StringUtil.translateToLocal( left.getUnlocalisedAdjective() ) ); } else if( left != null ) { - return I18n.translateToLocalFormatted( + return StringUtil.translateToLocalFormatted( baseString + ".upgraded.name", - I18n.translateToLocal( left.getUnlocalisedAdjective() ) + StringUtil.translateToLocal( left.getUnlocalisedAdjective() ) ); } else if( right != null ) { - return I18n.translateToLocalFormatted( + return StringUtil.translateToLocalFormatted( baseString + ".upgraded.name", - I18n.translateToLocal( right.getUnlocalisedAdjective() ) + StringUtil.translateToLocal( right.getUnlocalisedAdjective() ) ); } else { - return I18n.translateToLocal( baseString + ".name" ); + return StringUtil.translateToLocal( baseString + ".name" ); } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java index ab3b523d9..5fa690098 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java @@ -34,8 +34,7 @@ public class TurtleHoe extends TurtleTool if( super.canBreakBlock( world, pos ) ) { IBlockState state = world.getBlockState( pos ); - Block block = state.getBlock(); - Material material = block.getMaterial( state ); + Material material = state.getMaterial( ); return material == Material.PLANTS || material == Material.CACTUS || diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java index 067ae062d..9f9d65398 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java @@ -26,8 +26,7 @@ public class TurtleShovel extends TurtleTool if( super.canBreakBlock( world, pos ) ) { IBlockState state = world.getBlockState( pos ); - Block block = state.getBlock(); - Material material = block.getMaterial( state ); + Material material = state.getMaterial( ); return material == Material.GROUND || material == Material.SAND || diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java index ef10e099e..818766729 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java @@ -26,8 +26,7 @@ public class TurtleSword extends TurtleTool if( super.canBreakBlock( world, pos ) ) { IBlockState state = world.getBlockState( pos ); - Block block = state.getBlock(); - Material material = block.getMaterial( state ); + Material material = state.getMaterial( ); return material == Material.PLANTS || material == Material.LEAVES || diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index 87bbefd1a..ec90134b6 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -136,7 +136,7 @@ public class TurtleTool implements ITurtleUpgrade { IBlockState state = world.getBlockState( pos ); Block block = state.getBlock(); - if( block.isAir( state, world, pos ) || block == Blocks.BEDROCK || block.getBlockHardness( state, world, pos ) <= -1.0F ) + if( block.isAir( state, world, pos ) || block == Blocks.BEDROCK || state.getBlockHardness( world, pos ) <= -1.0F ) { return false; } diff --git a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java index 1b09d4dd2..1a99f300d 100644 --- a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java @@ -11,43 +11,33 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; -import net.minecraft.world.IBlockAccess; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class RedstoneUtil { - private static Block getBlock( IBlockAccess world, BlockPos pos ) - { - if( pos.getY() >= 0 ) - { - return world.getBlockState( pos ).getBlock(); - } - return null; - } - public static int getRedstoneOutput( World world, BlockPos pos, EnumFacing side ) { int power = 0; - Block block = getBlock( world, pos ); - if( block != null && block != Blocks.AIR ) + IBlockState state = world.getBlockState( pos ); + Block block = state.getBlock(); + if( block != Blocks.AIR ) { - IBlockState state = world.getBlockState( pos ); if( block == Blocks.REDSTONE_WIRE ) { if( side != EnumFacing.UP ) { - power = ((Integer)state.getValue( BlockRedstoneWire.POWER )).intValue(); + power = state.getValue( BlockRedstoneWire.POWER ); } else { power = 0; } } - else if( block.canProvidePower( state ) ) + else if( state.canProvidePower( ) ) { - power = block.getWeakPower( state, world, pos, side.getOpposite() ); + power = state.getWeakPower( world, pos, side.getOpposite() ); } if( block.isNormalCube( state, world, pos ) ) { @@ -56,10 +46,10 @@ public class RedstoneUtil if( testSide != side ) { BlockPos testPos = pos.offset( testSide ); - Block neighbour = getBlock( world, testPos ); - if( neighbour != null && neighbour.canProvidePower( state ) ) + IBlockState neighbour = world.getBlockState( testPos ); + if( neighbour.canProvidePower( ) ) { - power = Math.max( power, neighbour.getStrongPower( state, world, testPos, testSide.getOpposite() ) ); + power = Math.max( power, neighbour.getStrongPower( world, testPos, testSide.getOpposite() ) ); } } } @@ -81,15 +71,15 @@ public class RedstoneUtil public static void propogateRedstoneOutput( World world, BlockPos pos, EnumFacing side ) { // Propogate ordinary output - Block block = getBlock( world, pos ); + IBlockState block = world.getBlockState( pos ); BlockPos neighbourPos = pos.offset( side ); - Block neighbour = getBlock( world, neighbourPos ); - if( neighbour != null && neighbour != Blocks.AIR ) + IBlockState neighbour = world.getBlockState( neighbourPos ); + if( neighbour.getBlock() != Blocks.AIR ) { - world.notifyBlockOfStateChange( neighbourPos, block ); - if( neighbour.isNormalCube( world.getBlockState( neighbourPos ), world, neighbourPos ) ) + world.notifyBlockOfStateChange( neighbourPos, block.getBlock() ); + if( neighbour.getBlock().isNormalCube( neighbour, world, neighbourPos ) ) { - world.notifyNeighborsOfStateExcept( neighbourPos, neighbour, side.getOpposite() ); + world.notifyNeighborsOfStateExcept( neighbourPos, neighbour.getBlock(), side.getOpposite() ); } } } diff --git a/src/main/java/dan200/computercraft/shared/util/StringUtil.java b/src/main/java/dan200/computercraft/shared/util/StringUtil.java index d1522c388..66e66a5c1 100644 --- a/src/main/java/dan200/computercraft/shared/util/StringUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/StringUtil.java @@ -23,4 +23,22 @@ public class StringUtil return builder.toString(); } + + /** + * Translates a Stat name + */ + @SuppressWarnings("deprecation") + public static String translateToLocal( String key ) + { + return net.minecraft.util.text.translation.I18n.translateToLocal( key ); + } + + /** + * Translates a Stat name with format args + */ + @SuppressWarnings("deprecation") + public static String translateToLocalFormatted( String key, Object... format ) + { + return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, format ); + } } diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index 56df94c61..dccde1b57 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -27,16 +27,7 @@ public class WorldUtil public static boolean isLiquidBlock( World world, BlockPos pos ) { - if( isBlockInWorld( world, pos ) ) - { - IBlockState state = world.getBlockState( pos ); - Block block = state.getBlock(); - if( block != null ) - { - return block.getMaterial( state ).isLiquid(); - } - } - return false; + return isBlockInWorld( world, pos ) && world.getBlockState( pos ).getMaterial().isLiquid(); } public static BlockPos moveCoords( BlockPos pos, EnumFacing dir )