diff --git a/build.gradle b/build.gradle index 8f54cb981..a31b6f92f 100644 --- a/build.gradle +++ b/build.gradle @@ -83,3 +83,8 @@ processResources } } +gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xlint" + } +} diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index d7f5edf80..1e279a93b 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -74,18 +74,23 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /////////////// // UNIVERSAL // /////////////// @Mod( - modid = "ComputerCraft", name = "ComputerCraft", version = "${version}", + modid = ComputerCraft.MOD_ID, name = "ComputerCraft", version = "${version}", guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory" ) public class ComputerCraft { + public static final String MOD_ID = "ComputerCraft"; + // GUI IDs public static final int diskDriveGUIID = 100; public static final int computerGUIID = 101; @@ -209,7 +214,7 @@ public class ComputerCraft private static final Map pocketUpgrades = new HashMap(); // Implementation - @Mod.Instance( value = "ComputerCraft" ) + @Mod.Instance( value = ComputerCraft.MOD_ID ) public static ComputerCraft instance; @SidedProxy( clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient", serverSide = "dan200.computercraft.server.proxy.ComputerCraftProxyServer" ) @@ -509,9 +514,8 @@ public class ComputerCraft } } - for( int i=0; i it = peripheralProviders.iterator(); - while( it.hasNext() ) + for( IPeripheralProvider peripheralProvider : peripheralProviders ) { try { - IPeripheralProvider handler = it.next(); - IPeripheral peripheral = handler.getPeripheral( world, pos, side ); + IPeripheral peripheral = peripheralProvider.getPeripheral( world, pos, side ); if( peripheral != null ) { return peripheral; @@ -620,13 +621,11 @@ public class ComputerCraft // Try the handlers in order: int combinedSignal = -1; - Iterator it = bundledRedstoneProviders.iterator(); - while( it.hasNext() ) + for( IBundledRedstoneProvider bundledRedstoneProvider : bundledRedstoneProviders ) { try { - IBundledRedstoneProvider handler = it.next(); - int signal = handler.getBundledRedstoneOutput( world, pos, side ); + int signal = bundledRedstoneProvider.getBundledRedstoneOutput( world, pos, side ); if( signal >= 0 ) { if( combinedSignal < 0 ) @@ -652,13 +651,11 @@ public class ComputerCraft if( stack != null ) { // Try the handlers in order: - Iterator it = mediaProviders.iterator(); - while( it.hasNext() ) + for( IMediaProvider mediaProvider : mediaProviders ) { try { - IMediaProvider handler = it.next(); - IMedia media = handler.getMedia( stack ); + IMedia media = mediaProvider.getMedia( stack ); if( media != null ) { return media; @@ -722,7 +719,7 @@ public class ComputerCraft } } - public static IMount createResourceMount( Class modClass, String domain, String subPath ) + public static IMount createResourceMount( Class modClass, String domain, String subPath ) { // Start building list of mounts List mounts = new ArrayList(); @@ -760,11 +757,11 @@ public class ComputerCraft if( resourcePackDir.exists() && resourcePackDir.isDirectory() ) { String[] resourcePacks = resourcePackDir.list(); - for( int i=0; i modClass ) { String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath(); int bangIndex = path.indexOf( "!" ); @@ -831,7 +828,7 @@ public class ComputerCraft return file; } - private static File getDebugCodeDir( Class modClass ) + private static File getDebugCodeDir( Class modClass ) { String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath(); int bangIndex = path.indexOf("!"); diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index c4194f5b2..84747f644 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -21,6 +21,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.lang.reflect.Method; /** @@ -36,6 +38,7 @@ public final class ComputerCraftAPI return computerCraft != null; } + @Nonnull public static String getInstalledVersion() { findCC(); @@ -50,6 +53,7 @@ public final class ComputerCraftAPI return ""; } + @Nonnull public static String getAPIVersion() { return "${version}"; @@ -68,7 +72,7 @@ public final class ComputerCraftAPI * available for writing. * @see #createSaveDirMount(World, String, long) */ - public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) + public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath ) { findCC(); if( computerCraft_createUniqueNumberedSaveDir != null ) @@ -100,7 +104,8 @@ public final class ComputerCraftAPI * @see IMount * @see IWritableMount */ - public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) + @Nullable + public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity ) { findCC(); if( computerCraft_createSaveDirMount != null ) @@ -132,7 +137,8 @@ public final class ComputerCraftAPI * @see IComputerAccess#mountWritable(String, IWritableMount) * @see IMount */ - public static IMount createResourceMount( Class modClass, String domain, String subPath ) + @Nullable + public static IMount createResourceMount( @Nonnull Class modClass, @Nonnull String domain, @Nonnull String subPath ) { findCC(); if( computerCraft_createResourceMount != null ) @@ -153,7 +159,7 @@ public final class ComputerCraftAPI * @see dan200.computercraft.api.peripheral.IPeripheral * @see dan200.computercraft.api.peripheral.IPeripheralProvider */ - public static void registerPeripheralProvider( IPeripheralProvider handler ) + public static void registerPeripheralProvider( @Nonnull IPeripheralProvider handler ) { findCC(); if ( computerCraft_registerPeripheralProvider != null) @@ -174,7 +180,7 @@ public final class ComputerCraftAPI * @param upgrade The turtle upgrade to register. * @see dan200.computercraft.api.turtle.ITurtleUpgrade */ - public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) + public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade ) { if( upgrade != null ) { @@ -196,7 +202,7 @@ public final class ComputerCraftAPI * @param handler The bundled redstone provider to register. * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider */ - public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) + public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider handler ) { findCC(); if( computerCraft_registerBundledRedstoneProvider != null ) @@ -219,7 +225,7 @@ public final class ComputerCraftAPI * 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 ) + public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) { findCC(); if( computerCraft_getDefaultBundledRedstoneOutput != null ) @@ -239,7 +245,7 @@ public final class ComputerCraftAPI * @param handler The media provider to register. * @see dan200.computercraft.api.media.IMediaProvider */ - public static void registerMediaProvider( IMediaProvider handler ) + public static void registerMediaProvider( @Nonnull IMediaProvider handler ) { findCC(); if( computerCraft_registerMediaProvider != null ) @@ -258,7 +264,7 @@ public final class ComputerCraftAPI * @param handler The turtle permission provider to register. * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider */ - public static void registerPermissionProvider( ITurtlePermissionProvider handler ) + public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider handler ) { findCC(); if( computerCraft_registerPermissionProvider != null ) @@ -271,7 +277,8 @@ public final class ComputerCraftAPI } } - public static void registerPocketUpgrade(IPocketUpgrade upgrade) { + public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade ) + { findCC(); if(computerCraft_registerPocketUpgrade != null) { try { @@ -291,36 +298,36 @@ public final class ComputerCraftAPI if( !ccSearched ) { try { computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" ); - computerCraft_getVersion = findCCMethod( "getVersion", new Class[]{ + computerCraft_getVersion = findCCMethod( "getVersion", new Class[]{ } ); - computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{ + computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{ World.class, String.class } ); - computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] { + computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] { World.class, String.class, Long.TYPE } ); - computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] { + computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] { Class.class, String.class, String.class } ); - computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class[] { + computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class[] { IPeripheralProvider.class } ); - computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class[] { + computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class[] { ITurtleUpgrade.class } ); - computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class[] { + computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class[] { IBundledRedstoneProvider.class } ); - computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] { + computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] { World.class, BlockPos.class, EnumFacing.class } ); - computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] { + computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] { IMediaProvider.class } ); - computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class[] { + computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class[] { ITurtlePermissionProvider.class } ); - computerCraft_registerPocketUpgrade = findCCMethod( "registerPocketUpgrade", new Class[] { + computerCraft_registerPocketUpgrade = findCCMethod( "registerPocketUpgrade", new Class[] { IPocketUpgrade.class } ); } catch( Exception e ) { @@ -331,7 +338,7 @@ public final class ComputerCraftAPI } } - private static Method findCCMethod( String name, Class[] args ) + private static Method findCCMethod( String name, Class[] args ) { try { if( computerCraft != null ) @@ -346,7 +353,7 @@ public final class ComputerCraftAPI } private static boolean ccSearched = false; - private static Class computerCraft = null; + private static Class computerCraft = null; private static Method computerCraft_getVersion = null; private static Method computerCraft_createUniqueNumberedSaveDir = null; private static Method computerCraft_createSaveDirMount = null; diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java index d5869d3e8..32e063743 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -10,6 +10,7 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.peripheral.IComputerAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -36,7 +37,7 @@ public interface IMount * @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; + boolean exists( @Nonnull String path ) throws IOException; /** * Returns whether a file with a given path is a directory or not. @@ -45,7 +46,7 @@ public interface IMount * @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; + boolean isDirectory( @Nonnull String path ) throws IOException; /** * Returns the file names of all the files in a directory. @@ -54,7 +55,7 @@ public interface IMount * @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; + void list( @Nonnull String path, @Nonnull List contents ) throws IOException; /** * Returns the size of a file with a given path, in bytes @@ -63,7 +64,7 @@ public interface IMount * @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; + long getSize( @Nonnull String path ) throws IOException; /** * Opens a file with a given path, and returns an {@link InputStream} representing its contents. @@ -72,5 +73,6 @@ public interface IMount * @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; + @Nonnull + InputStream openForRead( @Nonnull 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 a1173167f..3f4bc68e3 100644 --- a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -10,6 +10,7 @@ import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.peripheral.IComputerAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.OutputStream; @@ -33,7 +34,7 @@ public interface IWritableMount extends IMount * @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; + void makeDirectory( @Nonnull String path ) throws IOException; /** * Deletes a directory at a given path inside the virtual file system. @@ -41,7 +42,7 @@ public interface IWritableMount extends IMount * @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; + void delete( @Nonnull String path ) throws IOException; /** * Opens a file with a given path, and returns an {@link OutputStream} for writing to it. @@ -50,7 +51,8 @@ public interface IWritableMount extends IMount * @return A stream for writing to * @throws IOException If the file could not be opened for writing. */ - public OutputStream openForWrite( String path ) throws IOException; + @Nonnull + OutputStream openForWrite( @Nonnull String path ) throws IOException; /** * Opens a file with a given path, and returns an {@link OutputStream} for appending to it. @@ -59,7 +61,8 @@ public interface IWritableMount extends IMount * @return A stream for writing to. * @throws IOException If the file could not be opened for writing. */ - public OutputStream openForAppend( String path ) throws IOException; + @Nonnull + OutputStream openForAppend( @Nonnull String path ) throws IOException; /** * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the @@ -68,5 +71,5 @@ public interface IWritableMount extends IMount * @return The amount of free space, in bytes. * @throws IOException If the remaining space could not be computed. */ - public long getRemainingSpace() throws IOException; + 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 16ce1d8d6..5f4c74218 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java @@ -6,6 +6,9 @@ package dan200.computercraft.api.lua; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * 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 @@ -28,7 +31,8 @@ public interface ILuaContext * 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; + @Nonnull + Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException; /** * The same as {@link #pullEvent(String)}, except "terminated" events are ignored. Only use this if you want to @@ -42,7 +46,8 @@ public interface ILuaContext * intercepted, or the computer will leak memory and end up in a broken state. * @see #pullEvent(String) */ - public Object[] pullEventRaw( String filter ) throws InterruptedException; + @Nonnull + Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException; /** * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to @@ -55,7 +60,8 @@ public interface ILuaContext * intercepted, or the computer will leak memory and end up in a broken state. * @see #pullEvent(String) */ - public Object[] yield( Object[] arguments ) throws InterruptedException; + @Nonnull + Object[] yield( @Nullable Object[] arguments ) throws InterruptedException; /** * Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete. @@ -71,7 +77,8 @@ public interface ILuaContext * 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; + @Nullable + Object[] executeMainThreadTask( @Nonnull ILuaTask task ) throws LuaException, InterruptedException; /** * Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to @@ -86,5 +93,5 @@ public interface ILuaContext * @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; + long issueMainThreadTask( @Nonnull 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 6da7ea720..8e40d75a7 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -9,6 +9,9 @@ package dan200.computercraft.api.lua; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * An interface for representing custom objects returned by {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])} * calls. @@ -24,7 +27,8 @@ public interface ILuaObject * @return The method names this object provides. * @see IPeripheral#getMethodNames() */ - public String[] getMethodNames(); + @Nonnull + String[] getMethodNames(); /** * Called when a user calls one of the methods that this object implements. This works the same as @@ -47,5 +51,6 @@ public interface ILuaObject * 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; + @Nullable + Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull 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 88e3ee035..0b31fb428 100644 --- a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java +++ b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java @@ -6,6 +6,8 @@ package dan200.computercraft.api.lua; +import javax.annotation.Nullable; + /** * 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 @@ -25,5 +27,6 @@ public interface ILuaTask * 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; + @Nullable + 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 90038d164..4f07e6e64 100644 --- a/src/main/java/dan200/computercraft/api/lua/LuaException.java +++ b/src/main/java/dan200/computercraft/api/lua/LuaException.java @@ -6,6 +6,8 @@ package dan200.computercraft.api.lua; +import javax.annotation.Nullable; + /** * An exception representing an error in Lua, like that raised by the {@code error()} function. */ @@ -19,12 +21,12 @@ public class LuaException extends Exception this( "error", 1 ); } - public LuaException( String message ) + public LuaException( @Nullable String message ) { this( message, 1 ); } - public LuaException( String message, int level ) + public LuaException( @Nullable String message, int level ) { super( message ); m_level = level; diff --git a/src/main/java/dan200/computercraft/api/media/IMedia.java b/src/main/java/dan200/computercraft/api/media/IMedia.java index b6eee6414..e35cffc9b 100644 --- a/src/main/java/dan200/computercraft/api/media/IMedia.java +++ b/src/main/java/dan200/computercraft/api/media/IMedia.java @@ -11,6 +11,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.SoundEvent; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Represents an item that can be placed in a disk drive and used by a Computer. * Implement this interface on your Item class to allow it to be used in the drive. @@ -23,7 +26,8 @@ public interface IMedia * @param stack The itemstack to inspect. * @return The label. ie: "Dan's Programs". */ - public String getLabel( ItemStack stack ); + @Nullable + String getLabel( @Nonnull ItemStack stack ); /** * Set a string representing the label of this item. Will be called vi {@code disk.setLabel()} in lua. @@ -32,7 +36,7 @@ public interface IMedia * @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 ); + boolean setLabel( @Nonnull ItemStack stack, @Nullable String label ); /** * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: @@ -41,7 +45,8 @@ public interface IMedia * @param stack The itemstack to inspect. * @return The name, or null if this item does not represent an item with audio. */ - public String getAudioTitle( ItemStack stack ); + @Nullable + String getAudioTitle( @Nonnull ItemStack stack ); /** * If this disk represents an item with audio (like a record), get the resource name of the audio track to play. @@ -49,7 +54,8 @@ public interface IMedia * @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 ); + @Nullable + SoundEvent getAudio( @Nonnull ItemStack stack ); /** * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will @@ -64,5 +70,6 @@ public interface IMedia * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long) * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) */ - public IMount createDataMount( ItemStack stack, World world ); + @Nullable + IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ); } diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java index 5b0188e04..0a9cdcaa5 100644 --- a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -8,6 +8,9 @@ package dan200.computercraft.api.media; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * This interface is used to provide {@link IMedia} implementations for {@link ItemStack}. * @@ -22,5 +25,6 @@ public interface 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 ); + @Nullable + IMedia getMedia( @Nonnull 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 964f48480..1caab9033 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -11,6 +11,9 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * The interface passed to peripherals by computers or turtles, providing methods * that they can call. This should not be implemented by your classes. Do not interact @@ -33,7 +36,8 @@ public interface IComputerAccess * @see #unmount(String) * @see IMount */ - public String mount( String desiredLocation, IMount mount ); + @Nullable + String mount( @Nonnull String desiredLocation, @Nonnull IMount mount ); /** * Mount a mount onto the computer's file system in a read only mode. @@ -51,7 +55,8 @@ public interface IComputerAccess * @see #unmount(String) * @see IMount */ - public String mount( String desiredLocation, IMount mount, String driveName ); + @Nullable + String mount( @Nonnull String desiredLocation, @Nonnull IMount mount, @Nonnull String driveName ); /** * Mount a mount onto the computer's file system in a writable mode. @@ -67,7 +72,8 @@ public interface IComputerAccess * @see #unmount(String) * @see IMount */ - public String mountWritable( String desiredLocation, IWritableMount mount ); + @Nullable + String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount ); /** * Mount a mount onto the computer's file system in a writable mode. @@ -84,7 +90,7 @@ public interface IComputerAccess * @see #unmount(String) * @see IMount */ - public String mountWritable( String desiredLocation, IWritableMount mount, String driveName ); + String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount, @Nonnull String driveName ); /** * Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)} @@ -104,7 +110,7 @@ public interface IComputerAccess * @see #mount(String, IMount) * @see #mountWritable(String, IWritableMount) */ - public void unmount( String location ); + void unmount( @Nullable String location ); /** * Returns the numerical ID of this computer. @@ -114,7 +120,7 @@ public interface IComputerAccess * * @return The identifier. */ - public int getID(); + int getID(); /** * Causes an event to be raised on this computer, which the computer can respond to by calling @@ -134,7 +140,7 @@ public interface IComputerAccess * @throws RuntimeException If the peripheral has been detached. * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod */ - public void queueEvent( String event, Object[] arguments ); + void queueEvent( @Nonnull String event, @Nullable Object[] arguments ); /** * Get a string, unique to the computer, by which the computer refers to this peripheral. @@ -146,5 +152,6 @@ public interface IComputerAccess * @return A string unique to the computer, but not globally. * @throws RuntimeException If the peripheral has been detached. */ - public String getAttachmentName(); + @Nonnull + 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 bd9311dd7..8dc11655d 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -9,6 +9,9 @@ package dan200.computercraft.api.peripheral; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * The interface that defines a peripheral. See {@link IPeripheralProvider} for how to associate blocks with peripherals. */ @@ -20,7 +23,8 @@ public interface IPeripheral * * @return A string identifying the type of peripheral. */ - public String getType(); + @Nonnull + String getType(); /** * Should return an array of strings that identify the methods that this @@ -30,7 +34,8 @@ public interface IPeripheral * @return An array of strings representing method names. * @see #callMethod */ - public String[] getMethodNames(); + @Nonnull + String[] getMethodNames(); /** * This is called when a lua program on an attached computer calls {@code peripheral.call()} with @@ -66,7 +71,8 @@ public interface IPeripheral * 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; + @Nullable + Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException; /** * Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral. @@ -85,7 +91,7 @@ public interface IPeripheral * computers can be attached to a peripheral at once. * @see #detach */ - public void attach( IComputerAccess computer ); + void attach( @Nonnull IComputerAccess computer ); /** * Is called when a computer is detaching from the peripheral. @@ -102,7 +108,7 @@ public interface IPeripheral * computers can be attached to a peripheral at once. * @see #detach */ - public void detach( IComputerAccess computer ); + void detach( @Nonnull IComputerAccess computer ); /** * Determine whether this peripheral is equivalent to another one. @@ -113,5 +119,5 @@ public interface IPeripheral * @param other The peripheral to compare against. This may be {@code null}. * @return Whether these peripherals are equivalent. */ - public boolean equals( IPeripheral other ); + boolean equals( @Nullable 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 51fde616b..8df256961 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -10,6 +10,9 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * This interface is used to create peripheral implementations for blocks. * @@ -26,5 +29,6 @@ public interface IPeripheralProvider * @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) */ - public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ); + @Nullable + IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull 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 7ce60290d..ee2373819 100644 --- a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java +++ b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -9,6 +9,8 @@ package dan200.computercraft.api.permissions; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import javax.annotation.Nonnull; + /** * This interface is used to restrict where turtles can move or build. * @@ -25,7 +27,7 @@ public interface ITurtlePermissionProvider * @param pos The location of the block. * @return Whether the turtle can move into this block. */ - public boolean isBlockEnterable( World world, BlockPos pos ); + boolean isBlockEnterable( @Nonnull World world, @Nonnull BlockPos pos ); /** * Determine whether a block can be modified by a turtle. @@ -36,5 +38,5 @@ public interface ITurtlePermissionProvider * @param pos The location of the block. * @return Whether the turtle can modify this block. */ - public boolean isBlockEditable( World world, BlockPos pos ); + boolean isBlockEditable( @Nonnull World world, @Nonnull 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 8447f0016..8a940c4b1 100644 --- a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -10,6 +10,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import javax.annotation.Nonnull; + /** * This interface is used to provide bundled redstone output for blocks. * @@ -27,5 +29,5 @@ public interface IBundledRedstoneProvider * handle this block. * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) */ - public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ); + int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull 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 efe0202fd..0b00b6945 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -16,6 +16,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * The interface passed to turtle by turtles, providing methods that they can call. * @@ -29,14 +32,16 @@ public interface ITurtleAccess * * @return the world in which the turtle resides. */ - public World getWorld(); + @Nonnull + 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(); + @Nonnull + BlockPos getPosition(); /** * Attempt to move this turtle to a new position. @@ -51,7 +56,7 @@ public interface ITurtleAccess * {@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 ); + boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos ); /** * Returns a vector containing the floating point co-ordinates at which the turtle is rendered. @@ -61,7 +66,8 @@ public interface ITurtleAccess * @return A vector containing the floating point co-ordinates at which the turtle resides. * @see #getVisualYaw(float) */ - public Vec3d getVisualPosition( float f ); + @Nonnull + Vec3d getVisualPosition( float f ); /** * Returns the yaw the turtle is facing when it is rendered. @@ -70,7 +76,7 @@ public interface ITurtleAccess * @return The yaw the turtle is facing. * @see #getVisualPosition(float) */ - public float getVisualYaw( float f ); + float getVisualYaw( float f ); /** * Returns the world direction the turtle is currently facing. @@ -78,7 +84,8 @@ public interface ITurtleAccess * @return The world direction the turtle is currently facing. * @see #setDirection(EnumFacing) */ - public EnumFacing getDirection(); + @Nonnull + EnumFacing getDirection(); /** * Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to @@ -87,7 +94,7 @@ public interface ITurtleAccess * @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 ); + void setDirection( @Nonnull EnumFacing dir ); /** * Get the currently selected slot in the turtle's inventory. @@ -96,7 +103,7 @@ public interface ITurtleAccess * @see #getInventory() * @see #setSelectedSlot(int) */ - public int getSelectedSlot(); + int getSelectedSlot(); /** * Set the currently selected slot in the turtle's inventory. @@ -107,7 +114,7 @@ public interface ITurtleAccess * @see #getInventory() * @see #getSelectedSlot() */ - public void setSelectedSlot( int slot ); + void setSelectedSlot( int slot ); /** * Sets the colour of the turtle, as if the player had dyed it with a dye item. @@ -116,7 +123,7 @@ public interface ITurtleAccess * the dye from the turtle. * @see #getDyeColour() */ - public void setDyeColour( int dyeColour ); + void setDyeColour( int dyeColour ); /** * Gets the colour the turtle has been dyed. @@ -125,14 +132,15 @@ public interface ITurtleAccess * is clean. * @see #getDyeColour() */ - public int getDyeColour(); + int getDyeColour(); /** * Get the inventory of this turtle * * @return This turtle's inventory */ - public IInventory getInventory(); + @Nonnull + IInventory getInventory(); /** * Determine whether this turtle will require fuel when performing actions. @@ -141,7 +149,7 @@ public interface ITurtleAccess * @see #getFuelLevel() * @see #setFuelLevel(int) */ - public boolean isFuelNeeded(); + boolean isFuelNeeded(); /** * Get the current fuel level of this turtle. @@ -150,7 +158,7 @@ public interface ITurtleAccess * @see #isFuelNeeded() * @see #setFuelLevel(int) */ - public int getFuelLevel(); + int getFuelLevel(); /** * Set the fuel level to a new value. It is generally preferred to use {@link #consumeFuel(int)}} or {@link #addFuel(int)} @@ -162,14 +170,14 @@ public interface ITurtleAccess * @see #addFuel(int) * @see #consumeFuel(int) */ - public void setFuelLevel( int fuel ); + void setFuelLevel( int fuel ); /** * Get the maximum amount of fuel a turtle can hold. * * @return The turtle's fuel limit. */ - public int getFuelLimit(); + int getFuelLimit(); /** * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. @@ -179,7 +187,7 @@ public interface ITurtleAccess * 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 ); + boolean consumeFuel( int fuel ); /** * Increase the turtle's fuel level by the given amount. @@ -187,7 +195,7 @@ public interface ITurtleAccess * @param fuel The amount to refuel with. * @throws UnsupportedOperationException When attempting to refuel on the client side. */ - public void addFuel( int fuel ); + void addFuel( int fuel ); /** * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed @@ -209,7 +217,8 @@ public interface ITurtleAccess * @see ITurtleCommand * @see ILuaContext#pullEvent(String) */ - public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException; + @Nonnull + Object[] executeCommand( @Nonnull ILuaContext context, @Nonnull ITurtleCommand command ) throws LuaException, InterruptedException; /** * Start playing a specific animation. This will prevent other turtle commands from executing until @@ -219,7 +228,7 @@ public interface ITurtleAccess * @throws UnsupportedOperationException When attempting to execute play an animation on the client side. * @see TurtleAnimation */ - public void playAnimation( TurtleAnimation animation ); + void playAnimation( @Nonnull TurtleAnimation animation ); /** * Returns the turtle on the specified side of the turtle, if there is one. @@ -228,7 +237,8 @@ public interface ITurtleAccess * @return The upgrade on the specified side of the turtle, if there is one. * @see #setUpgrade(TurtleSide, ITurtleUpgrade) */ - public ITurtleUpgrade getUpgrade( TurtleSide side ); + @Nullable + ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side ); /** * Set the upgrade for a given side, resetting peripherals and clearing upgrade specific data. @@ -237,7 +247,7 @@ public interface ITurtleAccess * @param upgrade The upgrade to set, may be {@code null} to clear. * @see #getUpgrade(TurtleSide) */ - public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ); + void setUpgrade( @Nonnull TurtleSide side, @Nullable ITurtleUpgrade upgrade ); /** * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. @@ -245,7 +255,8 @@ public interface ITurtleAccess * @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 ); + @Nullable + IPeripheral getPeripheral( @Nonnull TurtleSide side ); /** * Get an upgrade-specific NBT compound, which can be used to store arbitrary data. @@ -257,7 +268,8 @@ public interface ITurtleAccess * @return The upgrade-specific data. * @see #updateUpgradeNBTData(TurtleSide) */ - public NBTTagCompound getUpgradeNBTData( TurtleSide side ); + @Nonnull + NBTTagCompound getUpgradeNBTData( @Nullable TurtleSide side ); /** * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the @@ -266,5 +278,5 @@ public interface ITurtleAccess * @param side The side to mark dirty. * @see #updateUpgradeNBTData(TurtleSide) */ - public void updateUpgradeNBTData( TurtleSide side ); + void updateUpgradeNBTData( @Nonnull 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 1e7827827..e873900bb 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -8,6 +8,8 @@ package dan200.computercraft.api.turtle; import dan200.computercraft.api.lua.ILuaContext; +import javax.annotation.Nonnull; + /** * An interface for objects executing custom turtle commands, used with {@link ITurtleAccess#executeCommand(ILuaContext, ITurtleCommand)}. * @@ -28,5 +30,6 @@ public interface ITurtleCommand * @see TurtleCommandResult#failure(String) * @see TurtleCommandResult */ - public TurtleCommandResult execute( ITurtleAccess turtle ); + @Nonnull + TurtleCommandResult execute( @Nonnull 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 8020235f0..b1b3fb5b9 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -17,6 +17,8 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.vecmath.Matrix4f; @@ -36,7 +38,8 @@ public interface ITurtleUpgrade * @return The unique ID for this upgrade. * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ - public ResourceLocation getUpgradeID(); + @Nonnull + ResourceLocation getUpgradeID(); /** * Gets a numerical identifier representing this type of turtle upgrade, @@ -47,7 +50,7 @@ public interface ITurtleUpgrade * @return The legacy ID, or -1 if is needed. * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade) */ - public int getLegacyUpgradeID(); + int getLegacyUpgradeID(); /** * Return an unlocalised string to describe this type of turtle in turtle item names. @@ -56,7 +59,8 @@ public interface ITurtleUpgrade * * @return The localisation key for this upgrade's adjective. */ - public String getUnlocalisedAdjective(); + @Nonnull + String getUnlocalisedAdjective(); /** * Return whether this turtle adds a tool or a peripheral to the turtle. @@ -64,7 +68,8 @@ public interface ITurtleUpgrade * @return The type of upgrade this is. * @see TurtleUpgradeType for the differences between them. */ - public TurtleUpgradeType getType(); + @Nonnull + TurtleUpgradeType getType(); /** * Return an item stack representing the type of item that a turtle must be crafted @@ -73,7 +78,8 @@ public interface ITurtleUpgrade * * @return The item stack to craft with, or {@code null} if it cannot be crafted. */ - public ItemStack getCraftingItem(); + @Nullable + ItemStack getCraftingItem(); /** * Will only be called for peripheral upgrades. Creates a peripheral for a turtle being placed using this upgrade. @@ -87,7 +93,8 @@ public interface ITurtleUpgrade * @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 ); + @Nullable + IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ); /** * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called @@ -104,7 +111,8 @@ public interface ITurtleUpgrade * 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 ); + @Nonnull + TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ); /** * Called to obtain the model to be used when rendering a turtle peripheral. @@ -119,7 +127,8 @@ public interface ITurtleUpgrade * a transformation of {@code null} has the same effect as the identify matrix. */ @SideOnly(Side.CLIENT) - public Pair getModel( ITurtleAccess turtle, TurtleSide side ); + @Nonnull + Pair getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side ); /** * Called once per tick for each turtle which has the upgrade equipped. @@ -127,5 +136,5 @@ public interface ITurtleUpgrade * @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. */ - public void update( ITurtleAccess turtle, TurtleSide side ); + void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java index c72dd9fab..e89d8b993 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -8,6 +8,9 @@ package dan200.computercraft.api.turtle; import net.minecraft.util.EnumFacing; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + /** * Used to indicate the result of executing a turtle command. * @@ -24,6 +27,7 @@ public final class TurtleCommandResult * * @return A successful command result with no values. */ + @Nonnull public static TurtleCommandResult success() { return success( null ); @@ -35,7 +39,8 @@ public final class TurtleCommandResult * @param results The results of executing this command. * @return A successful command result with the given values. */ - public static TurtleCommandResult success( Object[] results ) + @Nonnull + public static TurtleCommandResult success( @Nullable Object[] results ) { if( results == null || results.length == 0 ) { @@ -52,6 +57,7 @@ public final class TurtleCommandResult * * @return A failed command result with no message. */ + @Nonnull public static TurtleCommandResult failure() { return failure( null ); @@ -63,7 +69,8 @@ public final class TurtleCommandResult * @param errorMessage The error message to provide. * @return A failed command result with a message. */ - public static TurtleCommandResult failure( String errorMessage ) + @Nonnull + public static TurtleCommandResult failure( @Nullable String errorMessage ) { if( errorMessage == null ) { @@ -101,6 +108,7 @@ public final class TurtleCommandResult * * @return The command's error message, or {@code null} if it was a success. */ + @Nullable public String getErrorMessage() { return m_errorMessage; @@ -111,6 +119,7 @@ public final class TurtleCommandResult * * @return The command's result, or {@code null} if it was a failure. */ + @Nullable public Object[] getResults() { return m_results; diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 2cead24f8..bffa311a3 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 6df2721ed..ef42aa498 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java b/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java index d7df2a233..28d8d9bc3 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java @@ -18,7 +18,7 @@ public class GuiConfigCC extends GuiConfig { public GuiConfigCC( GuiScreen parentScreen ) { - super( parentScreen, getConfigElements(), "ComputerCraft", false, false, "ComputerCraft" ); + super( parentScreen, getConfigElements(), ComputerCraft.MOD_ID, false, false, "ComputerCraft" ); } private static List getConfigElements() diff --git a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java index 51f5f554e..f2089553e 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java index 9e8b169d7..54cdb382c 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java index 053505d0d..db9d9a422 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java index f37747324..af571ab6e 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,7 +15,6 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; import java.io.IOException; diff --git a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java index c326e3cb0..61c3f83e3 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/MousePos.java b/src/main/java/dan200/computercraft/client/gui/widgets/MousePos.java index 40b1b2287..746c6cf7e 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/MousePos.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/MousePos.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java b/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java index 7a60779c0..3c5a76cc1 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,13 +11,10 @@ import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.*; -import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; public abstract class Widget extends Gui { @@ -269,9 +266,8 @@ public abstract class Widget extends Gui FontRenderer fontRenderer = mc.fontRendererObj; int width = 0; - for( int i=0; i info = new ArrayList( 1 ); recordStack.getItem().addInformation( recordStack, null, info, false ); if( info.size() > 0 ) { - return info.get(0).toString(); + return info.get( 0 ); } else { return super.getRecordInfo( recordStack ); } @@ -401,7 +404,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon { ComputerCraft.clientComputerRegistry.add( instanceID, new ClientComputer( instanceID ) ); } - ComputerCraft.clientComputerRegistry.get( instanceID ).handlePacket( packet, (EntityPlayer) player ); + ComputerCraft.clientComputerRegistry.get( instanceID ).handlePacket( packet, player ); break; } case ComputerCraftPacket.ComputerDeleted: @@ -519,7 +522,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon } @Override - public int getColorFromItemstack(ItemStack stack, int layer) + public int getColorFromItemstack( @Nonnull ItemStack stack, int layer) { return layer == 0 ? 0xFFFFFF : disk.getColor(stack); } diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index fe5c0cd46..6af4bbf4d 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -25,6 +25,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL11; +import javax.annotation.Nonnull; + public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer { public TileEntityMonitorRenderer() @@ -32,7 +34,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer m_generalQuads; - private List m_faceQuads[]; + private List[] m_faceQuads; public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform ) { @@ -39,6 +40,7 @@ public class TurtleMultiModel implements IBakedModel m_faceQuads = new List[6]; } + @Nonnull @Override public List getQuads( IBlockState state, EnumFacing side, long rand ) { @@ -107,18 +109,22 @@ public class TurtleMultiModel implements IBakedModel return m_baseModel.isBuiltInRenderer(); } + @Nonnull @Override public TextureAtlasSprite getParticleTexture() { return m_baseModel.getParticleTexture(); } + @Nonnull @Override + @Deprecated public ItemCameraTransforms getItemCameraTransforms() { return m_baseModel.getItemCameraTransforms(); } + @Nonnull @Override public ItemOverrideList getOverrides() { @@ -134,9 +140,8 @@ public class TurtleMultiModel implements IBakedModel else { List output = new ArrayList( input.size() ); - for( int i=0; i(); m_overrides = new ItemOverrideList( new ArrayList() ) { + @Nonnull @Override - public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) + public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, ItemStack stack, @Nonnull World world, @Nonnull EntityLivingBase entity) { ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem(); ComputerFamily family = turtle.getFamily( stack ); @@ -127,6 +127,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload }; } + @Nonnull @Override public ItemOverrideList getOverrides() { @@ -134,7 +135,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload } @Override - public void onResourceManagerReload( IResourceManager resourceManager ) + public void onResourceManagerReload( @Nonnull IResourceManager resourceManager ) { m_cachedModels.clear(); } @@ -173,6 +174,7 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload // These should not be called: + @Nonnull @Override public List getQuads( IBlockState state, EnumFacing facing, long rand ) { @@ -197,13 +199,16 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload return getDefaultModel().isBuiltInRenderer(); } + @Nonnull @Override public TextureAtlasSprite getParticleTexture() { return getDefaultModel().getParticleTexture(); } + @Nonnull @Override + @Deprecated public ItemCameraTransforms getItemCameraTransforms() { return getDefaultModel().getItemCameraTransforms(); diff --git a/src/main/java/dan200/computercraft/core/apis/BitAPI.java b/src/main/java/dan200/computercraft/core/apis/BitAPI.java index b3a2cfdea..bbf8148c2 100644 --- a/src/main/java/dan200/computercraft/core/apis/BitAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/BitAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,6 +9,8 @@ package dan200.computercraft.core.apis; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; +import javax.annotation.Nonnull; + // Contributed by Nia // Based on LuaBit (http://luaforge.net/projects/bit) @@ -68,6 +70,7 @@ public class BitAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { return new String[] { @@ -77,7 +80,7 @@ public class BitAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { Object a = args.length>0?args[0]:null; Object b = args.length>1?args[1]:null; diff --git a/src/main/java/dan200/computercraft/core/apis/BufferAPI.java b/src/main/java/dan200/computercraft/core/apis/BufferAPI.java index 546f7037b..e7cf9acb8 100644 --- a/src/main/java/dan200/computercraft/core/apis/BufferAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/BufferAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,6 +11,8 @@ import dan200.computercraft.api.lua.ILuaObject; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.terminal.TextBuffer; +import javax.annotation.Nonnull; + public class BufferAPI implements ILuaAPI { private static class BufferLuaObject implements ILuaObject @@ -22,6 +24,7 @@ public class BufferAPI implements ILuaAPI m_buffer = buffer; } + @Nonnull @Override public String[] getMethodNames() { @@ -35,7 +38,7 @@ public class BufferAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { @@ -165,6 +168,7 @@ public class BufferAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -174,7 +178,7 @@ public class BufferAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { diff --git a/src/main/java/dan200/computercraft/core/apis/FSAPI.java b/src/main/java/dan200/computercraft/core/apis/FSAPI.java index e244353a9..bd0968bde 100644 --- a/src/main/java/dan200/computercraft/core/apis/FSAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/FSAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,7 @@ import dan200.computercraft.core.filesystem.FileSystemException; import dan200.computercraft.core.filesystem.IMountedFileBinary; import dan200.computercraft.core.filesystem.IMountedFileNormal; +import javax.annotation.Nonnull; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -54,6 +55,7 @@ public class FSAPI implements ILuaAPI m_fileSystem = null; } + @Nonnull @Override public String[] getMethodNames() { @@ -78,7 +80,7 @@ public class FSAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -122,7 +124,7 @@ public class FSAPI implements ILuaAPI throw new LuaException( "Expected string" ); } String path = (String)args[0]; - return new Object[]{ m_fileSystem.getName( path ) }; + return new Object[]{ FileSystem.getName( path ) }; } case 3: { @@ -357,7 +359,7 @@ public class FSAPI implements ILuaAPI throw new LuaException( "Expected string" ); } String path = (String)args[0]; - return new Object[]{ m_fileSystem.getDirectory( path ) }; + return new Object[]{ FileSystem.getDirectory( path ) }; } default: { @@ -370,6 +372,7 @@ public class FSAPI implements ILuaAPI private static Object[] wrapBufferedReader( final IMountedFileNormal reader ) { return new Object[] { new ILuaObject() { + @Nonnull @Override public String[] getMethodNames() { @@ -381,7 +384,7 @@ public class FSAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -439,6 +442,7 @@ public class FSAPI implements ILuaAPI private static Object[] wrapBufferedWriter( final IMountedFileNormal writer ) { return new Object[] { new ILuaObject() { + @Nonnull @Override public String[] getMethodNames() { @@ -451,7 +455,7 @@ public class FSAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -521,6 +525,7 @@ public class FSAPI implements ILuaAPI return new Object[] { new ILuaObject() { + @Nonnull @Override public String[] getMethodNames() { return new String[] { @@ -530,7 +535,7 @@ public class FSAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args) throws LuaException { + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args) throws LuaException { switch( method ) { case 0: @@ -572,6 +577,7 @@ public class FSAPI implements ILuaAPI return new Object[] { new ILuaObject() { + @Nonnull @Override public String[] getMethodNames() { return new String[] { @@ -582,7 +588,7 @@ public class FSAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args) throws LuaException { + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args) throws LuaException { switch( method ) { case 0: diff --git a/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java b/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java index fd9b5de26..768afd017 100644 --- a/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/HTTPAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,14 +10,15 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.ILuaObject; import dan200.computercraft.api.lua.LuaException; +import javax.annotation.Nonnull; import java.io.BufferedReader; import java.io.IOException; import java.util.*; public class HTTPAPI implements ILuaAPI { - private IAPIEnvironment m_apiEnvironment; - private List m_httpRequests; + private final IAPIEnvironment m_apiEnvironment; + private final List m_httpRequests; public HTTPAPI( IAPIEnvironment environment ) { @@ -72,6 +73,7 @@ public class HTTPAPI implements ILuaAPI private static ILuaObject wrapBufferedReader( final BufferedReader reader, final int responseCode, final Map responseHeaders ) { return new ILuaObject() { + @Nonnull @Override public String[] getMethodNames() { @@ -85,7 +87,7 @@ public class HTTPAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -155,15 +157,15 @@ public class HTTPAPI implements ILuaAPI { synchronized( m_httpRequests ) { - Iterator it = m_httpRequests.iterator(); - while( it.hasNext() ) { - HTTPRequest r = it.next(); + for( HTTPRequest r : m_httpRequests ) + { r.cancel(); } m_httpRequests.clear(); } } + @Nonnull @Override public String[] getMethodNames() { @@ -174,7 +176,7 @@ public class HTTPAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -199,7 +201,7 @@ public class HTTPAPI implements ILuaAPI Map headers = null; if( args.length >= 3 && args[2] instanceof Map ) { - Map table = (Map)args[2]; + Map table = (Map)args[2]; headers = new HashMap( table.size() ); for( Object key : table.keySet() ) { diff --git a/src/main/java/dan200/computercraft/core/apis/HTTPRequest.java b/src/main/java/dan200/computercraft/core/apis/HTTPRequest.java index 68177f218..b7f816ad7 100644 --- a/src/main/java/dan200/computercraft/core/apis/HTTPRequest.java +++ b/src/main/java/dan200/computercraft/core/apis/HTTPRequest.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -18,12 +18,6 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; -class HTTPRequestException extends Exception { - public HTTPRequestException( String s ) { - super( s ); - } -} - public class HTTPRequest { public static URL checkURL( String urlString ) throws HTTPRequestException @@ -49,9 +43,8 @@ public class HTTPRequest boolean allowed = false; String whitelistString = ComputerCraft.http_whitelist; String[] allowedURLs = whitelistString.split( ";" ); - for( int i=0; i it = m_mounts.iterator(); - while( it.hasNext() ) { - m_fileSystem.unmount( it.next() ); + for( String m_mount : m_mounts ) + { + m_fileSystem.unmount( m_mount ); } m_mounts.clear(); } @@ -118,13 +119,13 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange // IComputerAccess implementation @Override - public String mount( String desiredLoc, IMount mount ) + public String mount( @Nonnull String desiredLoc, @Nonnull IMount mount ) { return mount( desiredLoc, mount, m_side ); } @Override - public synchronized String mount( String desiredLoc, IMount mount, String driveName ) + public synchronized String mount( @Nonnull String desiredLoc, @Nonnull IMount mount, @Nonnull String driveName ) { if( !m_attached ) { @@ -132,7 +133,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } // Mount the location - String location = null; + String location; synchronized( m_fileSystem ) { location = findFreeLocation( desiredLoc ); @@ -153,13 +154,13 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } @Override - public String mountWritable( String desiredLoc, IWritableMount mount ) + public String mountWritable( @Nonnull String desiredLoc, @Nonnull IWritableMount mount ) { return mountWritable( desiredLoc, mount, m_side ); } @Override - public synchronized String mountWritable( String desiredLoc, IWritableMount mount, String driveName ) + public synchronized String mountWritable( @Nonnull String desiredLoc, @Nonnull IWritableMount mount, @Nonnull String driveName ) { if( !m_attached ) { @@ -167,7 +168,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } // Mount the location - String location = null; + String location; synchronized( m_fileSystem ) { location = findFreeLocation( desiredLoc ); @@ -215,7 +216,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } @Override - public synchronized void queueEvent( final String event, final Object[] arguments ) + public synchronized void queueEvent( @Nonnull final String event, final Object[] arguments ) { if( !m_attached ) { throw new RuntimeException( "You are not attached to this Computer" ); @@ -223,6 +224,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange m_environment.queueEvent( event, arguments ); } + @Nonnull @Override public synchronized String getAttachmentName() { @@ -233,9 +235,9 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } } - private IAPIEnvironment m_environment; + private final IAPIEnvironment m_environment; private FileSystem m_fileSystem; - private PeripheralWrapper[] m_peripherals; + private final PeripheralWrapper[] m_peripherals; private boolean m_running; public PeripheralAPI( IAPIEnvironment _environment ) @@ -372,6 +374,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } } + @Nonnull @Override public String[] getMethodNames() { @@ -384,7 +387,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException, InterruptedException { switch( method ) { @@ -467,15 +470,14 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange int side = parseSide( args ); if( side >= 0 ) { - PeripheralWrapper p = null; + PeripheralWrapper p; synchronized( m_peripherals ) { p = m_peripherals[ side ]; } if( p != null ) { - Object[] results = p.call( context, methodName, methodArgs ); - return results; + return p.call( context, methodName, methodArgs ); } } throw new LuaException( "No peripheral attached" ); diff --git a/src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java b/src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java index 25f79f729..adb68a2d1 100644 --- a/src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,7 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.core.computer.Computer; +import javax.annotation.Nonnull; import java.util.HashMap; import java.util.Map; @@ -45,6 +46,7 @@ public class RedstoneAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -67,7 +69,7 @@ public class RedstoneAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { @@ -89,7 +91,7 @@ public class RedstoneAPI implements ILuaAPI throw new LuaException( "Expected string, boolean" ); } int side = parseSide( args ); - boolean output = ((Boolean)args[1]).booleanValue(); + boolean output = (Boolean) args[ 1 ]; m_environment.setOutput( side, output ? 15 : 0 ); return null; } diff --git a/src/main/java/dan200/computercraft/core/apis/TermAPI.java b/src/main/java/dan200/computercraft/core/apis/TermAPI.java index 3d4b53e0d..1d3f2ada6 100644 --- a/src/main/java/dan200/computercraft/core/apis/TermAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/TermAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,6 +17,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import javax.annotation.Nonnull; + public class TermAPI implements ILuaAPI { private final Terminal m_terminal; @@ -51,6 +53,7 @@ public class TermAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -117,7 +120,7 @@ public class TermAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException { switch( method ) { diff --git a/src/main/java/dan200/computercraft/core/computer/Computer.java b/src/main/java/dan200/computercraft/core/computer/Computer.java index 847d49d1c..9c84e71f2 100644 --- a/src/main/java/dan200/computercraft/core/computer/Computer.java +++ b/src/main/java/dan200/computercraft/core/computer/Computer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,7 +21,6 @@ import dan200.computercraft.core.terminal.Terminal; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; public class Computer @@ -30,7 +29,7 @@ public class Computer "bottom", "top", "back", "front", "right", "left", }; - private static enum State + private enum State { Off, Starting, @@ -187,26 +186,26 @@ public class Computer private boolean m_blinking; private ILuaMachine m_machine; - private List m_apis; - private APIEnvironment m_apiEnvironment; + private final List m_apis; + private final APIEnvironment m_apiEnvironment; - private Terminal m_terminal; + private final Terminal m_terminal; private FileSystem m_fileSystem; private IWritableMount m_rootMount; - private int[] m_internalOutput; - private int[] m_internalBundledOutput; + private final int[] m_internalOutput; + private final int[] m_internalBundledOutput; private boolean m_internalOutputChanged; - private int[] m_externalOutput; - private int[] m_externalBundledOutput; + private final int[] m_externalOutput; + private final int[] m_externalBundledOutput; private boolean m_externalOutputChanged; - private int[] m_input; - private int[] m_bundledInput; + private final int[] m_input; + private final int[] m_bundledInput; private boolean m_inputChanged; - private IPeripheral[] m_peripherals; + private final IPeripheral[] m_peripherals; public Computer( IComputerEnvironment environment, Terminal terminal, int id ) { @@ -370,10 +369,8 @@ public class Computer // Advance our APIs synchronized( m_apis ) { - Iterator it = m_apis.iterator(); - while( it.hasNext() ) + for(ILuaAPI api : m_apis) { - ILuaAPI api = it.next(); api.advance( _dt ); } } @@ -628,10 +625,8 @@ public class Computer ILuaMachine machine = new LuaJLuaMachine( this ); // Add the APIs - Iterator it = m_apis.iterator(); - while( it.hasNext() ) + for(ILuaAPI api : m_apis) { - ILuaAPI api = it.next(); machine.addAPI( api ); api.startup(); } @@ -794,10 +789,8 @@ public class Computer // Shutdown our APIs synchronized( m_apis ) { - Iterator it = m_apis.iterator(); - while( it.hasNext() ) + for(ILuaAPI api : m_apis) { - ILuaAPI api = it.next(); api.shutdown(); } } diff --git a/src/main/java/dan200/computercraft/core/computer/ComputerThread.java b/src/main/java/dan200/computercraft/core/computer/ComputerThread.java index c9adedc20..49d739c95 100644 --- a/src/main/java/dan200/computercraft/core/computer/ComputerThread.java +++ b/src/main/java/dan200/computercraft/core/computer/ComputerThread.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,14 +13,14 @@ import java.util.concurrent.LinkedBlockingQueue; public class ComputerThread { - private static Object m_lock; + private static final Object m_lock; private static Thread m_thread; - private static WeakHashMap > m_computerTasks; - private static ArrayList > m_computerTasksActive; - private static ArrayList > m_computerTasksPending; - private static Object m_defaultQueue; - private static Object m_monitor; + private static final WeakHashMap > m_computerTasks; + private static final ArrayList > m_computerTasksActive; + private static final ArrayList > m_computerTasksPending; + private static final Object m_defaultQueue; + private static final Object m_monitor; private static boolean m_running; private static boolean m_stopped; diff --git a/src/main/java/dan200/computercraft/core/computer/IComputerEnvironment.java b/src/main/java/dan200/computercraft/core/computer/IComputerEnvironment.java index 8e740b21a..2451ca140 100644 --- a/src/main/java/dan200/computercraft/core/computer/IComputerEnvironment.java +++ b/src/main/java/dan200/computercraft/core/computer/IComputerEnvironment.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,13 +10,13 @@ import dan200.computercraft.api.filesystem.IWritableMount; public interface IComputerEnvironment { - public int getDay(); - public double getTimeOfDay(); - public boolean isColour(); - public long getComputerSpaceLimit(); - public String getHostString(); + int getDay(); + double getTimeOfDay(); + boolean isColour(); + long getComputerSpaceLimit(); + String getHostString(); - public int assignNewID(); - public IWritableMount createSaveDirMount( String subPath, long capacity ); - public IMount createResourceMount( String domain, String subPath ); + int assignNewID(); + IWritableMount createSaveDirMount( String subPath, long capacity ); + IMount createResourceMount( String domain, String subPath ); } diff --git a/src/main/java/dan200/computercraft/core/computer/ITask.java b/src/main/java/dan200/computercraft/core/computer/ITask.java index 30b0d69ca..76dfcc17d 100644 --- a/src/main/java/dan200/computercraft/core/computer/ITask.java +++ b/src/main/java/dan200/computercraft/core/computer/ITask.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,6 @@ package dan200.computercraft.core.computer; public interface ITask { - public Computer getOwner(); - public void execute(); + Computer getOwner(); + void execute(); } diff --git a/src/main/java/dan200/computercraft/core/computer/MainThread.java b/src/main/java/dan200/computercraft/core/computer/MainThread.java index 3ffca8497..7868f150c 100644 --- a/src/main/java/dan200/computercraft/core/computer/MainThread.java +++ b/src/main/java/dan200/computercraft/core/computer/MainThread.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java index b02494f22..d80fd9c75 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ComboMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,7 @@ package dan200.computercraft.core.filesystem; import dan200.computercraft.api.filesystem.IMount; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -27,7 +28,7 @@ public class ComboMount implements IMount // IMount implementation @Override - public boolean exists( String path ) throws IOException + public boolean exists( @Nonnull String path ) throws IOException { for( int i=m_parts.length-1; i>=0; --i ) { @@ -41,7 +42,7 @@ public class ComboMount implements IMount } @Override - public boolean isDirectory( String path ) throws IOException + public boolean isDirectory( @Nonnull String path ) throws IOException { for( int i=m_parts.length-1; i>=0; --i ) { @@ -55,7 +56,7 @@ public class ComboMount implements IMount } @Override - public void list( String path, List contents ) throws IOException + public void list( @Nonnull String path, @Nonnull List contents ) throws IOException { // Combine the lists from all the mounts List foundFiles = null; @@ -83,9 +84,8 @@ public class ComboMount implements IMount { // We found multiple directories, so filter for duplicates Set seen = new HashSet(); - for( int i=0; i=0; --i ) { @@ -112,8 +112,9 @@ public class ComboMount implements IMount throw new IOException( "No such file" ); } + @Nonnull @Override - public InputStream openForRead( String path ) throws IOException + public InputStream openForRead( @Nonnull String path ) throws IOException { for( int i=m_parts.length-1; i>=0; --i ) { diff --git a/src/main/java/dan200/computercraft/core/filesystem/EmptyMount.java b/src/main/java/dan200/computercraft/core/filesystem/EmptyMount.java index 4239762b5..1b5cd5664 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/EmptyMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/EmptyMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,7 @@ package dan200.computercraft.core.filesystem; import dan200.computercraft.api.filesystem.IMount; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -21,30 +22,31 @@ public class EmptyMount implements IMount // IMount implementation @Override - public boolean exists( String path ) throws IOException + public boolean exists( @Nonnull String path ) throws IOException { return path.isEmpty(); } @Override - public boolean isDirectory( String path ) throws IOException + public boolean isDirectory( @Nonnull String path ) throws IOException { return path.isEmpty(); } @Override - public void list( String path, List contents ) throws IOException + public void list( @Nonnull String path, @Nonnull List contents ) throws IOException { } @Override - public long getSize( String path ) throws IOException + public long getSize( @Nonnull String path ) throws IOException { return 0; } + @Nonnull @Override - public InputStream openForRead( String path ) throws IOException + public InputStream openForRead( @Nonnull String path ) throws IOException { return null; } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java index 704702c03..3852cb000 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,7 @@ package dan200.computercraft.core.filesystem; import dan200.computercraft.api.filesystem.IWritableMount; +import javax.annotation.Nonnull; import java.io.*; import java.util.List; @@ -39,14 +40,14 @@ public class FileMount implements IWritableMount } @Override - public void write( byte[] b ) throws IOException + public void write( @Nonnull byte[] b ) throws IOException { count( b.length ); m_innerStream.write( b ); } @Override - public void write( byte[] b, int off, int len ) throws IOException + public void write( @Nonnull byte[] b, int off, int len ) throws IOException { count( len ); m_innerStream.write( b, off, len ); @@ -94,7 +95,7 @@ public class FileMount implements IWritableMount // IMount implementation @Override - public boolean exists( String path ) throws IOException + public boolean exists( @Nonnull String path ) throws IOException { if( !created() ) { @@ -108,7 +109,7 @@ public class FileMount implements IWritableMount } @Override - public boolean isDirectory( String path ) throws IOException + public boolean isDirectory( @Nonnull String path ) throws IOException { if( !created() ) { @@ -122,7 +123,7 @@ public class FileMount implements IWritableMount } @Override - public void list( String path, List contents ) throws IOException + public void list( @Nonnull String path, @Nonnull List contents ) throws IOException { if( !created() ) { @@ -153,7 +154,7 @@ public class FileMount implements IWritableMount } @Override - public long getSize( String path ) throws IOException + public long getSize( @Nonnull String path ) throws IOException { if( !created() ) { @@ -180,8 +181,9 @@ public class FileMount implements IWritableMount throw new IOException( "No such file" ); } + @Nonnull @Override - public InputStream openForRead( String path ) throws IOException + public InputStream openForRead( @Nonnull String path ) throws IOException { if( created() ) { @@ -197,7 +199,7 @@ public class FileMount implements IWritableMount // IWritableMount implementation @Override - public void makeDirectory( String path ) throws IOException + public void makeDirectory( @Nonnull String path ) throws IOException { create(); File file = getRealPath( path ); @@ -236,7 +238,7 @@ public class FileMount implements IWritableMount } @Override - public void delete( String path ) throws IOException + public void delete( @Nonnull String path ) throws IOException { if( path.length() == 0 ) { @@ -259,9 +261,9 @@ public class FileMount implements IWritableMount if( file.isDirectory() ) { String[] children = file.list(); - for( int i=0; i it = m_mounts.values().iterator(); - while( it.hasNext() ) { - MountWrapper otherMount = it.next(); - if( getDirectory( otherMount.getLocation() ).equals( path ) ) { + for( MountWrapper otherMount : m_mounts.values() ) + { + if( getDirectory( otherMount.getLocation() ).equals( path ) ) + { list.add( getName( otherMount.getLocation() ) ); } } @@ -445,9 +445,8 @@ public class FileSystem private void findIn( String dir, List matches, Pattern wildPattern ) throws FileSystemException { String[] list = list( dir ); - for( int i=0; i= 32 && Arrays.binarySearch( specialChars, c ) < 0 && (allowWildcards || c != '*') ) { - cleanName.append((char)c); + cleanName.append( c ); } } path = cleanName.toString(); @@ -918,30 +917,42 @@ public class FileSystem // Collapse the string into its component parts, removing ..'s String[] parts = path.split("/"); Stack outputParts = new Stack(); - for( int n=0; n= 255) { + else + { + outputParts.push( ".." ); + } + } + else if( part.length() >= 255 ) + { // If part length > 255 and it is the last part - outputParts.push( part.substring(0, 255) ); - } else { + outputParts.push( part.substring( 0, 255 ) ); + } + else + { // Anything else we add to the stack - outputParts.push(part); + outputParts.push( part ); } } diff --git a/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java b/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java index cbf970ebf..5f75b64f1 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java +++ b/src/main/java/dan200/computercraft/core/filesystem/FileSystemException.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -7,6 +7,8 @@ package dan200.computercraft.core.filesystem; public class FileSystemException extends Exception { + private static final long serialVersionUID = -2500631644868104029L; + FileSystemException( String s ) { super( s ); } diff --git a/src/main/java/dan200/computercraft/core/filesystem/IMountedFile.java b/src/main/java/dan200/computercraft/core/filesystem/IMountedFile.java index 58a5b43c6..1d01febc8 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/IMountedFile.java +++ b/src/main/java/dan200/computercraft/core/filesystem/IMountedFile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,5 +9,5 @@ package dan200.computercraft.core.filesystem; import java.io.IOException; public interface IMountedFile { - public void close() throws IOException; + void close() throws IOException; } diff --git a/src/main/java/dan200/computercraft/core/filesystem/IMountedFileBinary.java b/src/main/java/dan200/computercraft/core/filesystem/IMountedFileBinary.java index a382203dc..f6581e881 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/IMountedFileBinary.java +++ b/src/main/java/dan200/computercraft/core/filesystem/IMountedFileBinary.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,8 +9,8 @@ package dan200.computercraft.core.filesystem; import java.io.IOException; public interface IMountedFileBinary extends IMountedFile { - public int read() throws IOException; - public void write(int i) throws IOException; - public void close() throws IOException; - public void flush() throws IOException; + int read() throws IOException; + void write( int i ) throws IOException; + void close() throws IOException; + void flush() throws IOException; } diff --git a/src/main/java/dan200/computercraft/core/filesystem/IMountedFileNormal.java b/src/main/java/dan200/computercraft/core/filesystem/IMountedFileNormal.java index 78a02961a..c8b956b0d 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/IMountedFileNormal.java +++ b/src/main/java/dan200/computercraft/core/filesystem/IMountedFileNormal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,8 +9,8 @@ package dan200.computercraft.core.filesystem; import java.io.IOException; public interface IMountedFileNormal extends IMountedFile { - public String readLine() throws IOException; - public void write(String s, int off, int len, boolean newLine) throws IOException; - public void close() throws IOException; - public void flush() throws IOException; + String readLine() throws IOException; + void write( String s, int off, int len, boolean newLine ) throws IOException; + void close() throws IOException; + void flush() throws IOException; } diff --git a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java index c82085a63..a7a77e03a 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/JarMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/JarMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,7 @@ package dan200.computercraft.core.filesystem; import dan200.computercraft.api.filesystem.IMount; +import javax.annotation.Nonnull; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -53,10 +54,7 @@ public class JarMount implements IMount public void list( List contents ) { - for( String child : m_children.keySet() ) - { - contents.add( child ); - } + contents.addAll( m_children.keySet() ); } public void insertChild( FileInZip child ) @@ -178,14 +176,14 @@ public class JarMount implements IMount // IMount implementation @Override - public boolean exists( String path ) throws IOException + public boolean exists( @Nonnull String path ) throws IOException { FileInZip file = m_root.getFile( path ); return file != null; } @Override - public boolean isDirectory( String path ) throws IOException + public boolean isDirectory( @Nonnull String path ) throws IOException { FileInZip file = m_root.getFile( path ); if( file != null ) @@ -196,7 +194,7 @@ public class JarMount implements IMount } @Override - public void list( String path, List contents ) throws IOException + public void list( @Nonnull String path, @Nonnull List contents ) throws IOException { FileInZip file = m_root.getFile( path ); if( file != null && file.isDirectory() ) @@ -210,7 +208,7 @@ public class JarMount implements IMount } @Override - public long getSize( String path ) throws IOException + public long getSize( @Nonnull String path ) throws IOException { FileInZip file = m_root.getFile( path ); if( file != null ) @@ -220,8 +218,9 @@ public class JarMount implements IMount throw new IOException( "No such file" ); } + @Nonnull @Override - public InputStream openForRead( String path ) throws IOException + public InputStream openForRead( @Nonnull String path ) throws IOException { FileInZip file = m_root.getFile( path ); if( file != null && !file.isDirectory() ) diff --git a/src/main/java/dan200/computercraft/core/filesystem/SubMount.java b/src/main/java/dan200/computercraft/core/filesystem/SubMount.java index fecdbd7dd..8da2836ea 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/SubMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/SubMount.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,7 @@ package dan200.computercraft.core.filesystem; import dan200.computercraft.api.filesystem.IMount; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -26,31 +27,32 @@ public class SubMount implements IMount // IMount implementation @Override - public boolean exists( String path ) throws IOException + public boolean exists( @Nonnull String path ) throws IOException { return m_parent.exists( getFullPath( path ) ); } @Override - public boolean isDirectory( String path ) throws IOException + public boolean isDirectory( @Nonnull String path ) throws IOException { return m_parent.isDirectory( getFullPath( path ) ); } @Override - public void list( String path, List contents ) throws IOException + public void list( @Nonnull String path, @Nonnull List contents ) throws IOException { m_parent.list( getFullPath( path ), contents ); } @Override - public long getSize( String path ) throws IOException + public long getSize( @Nonnull String path ) throws IOException { return m_parent.getSize( getFullPath( path ) ); } + @Nonnull @Override - public InputStream openForRead( String path ) throws IOException + public InputStream openForRead( @Nonnull String path ) throws IOException { return m_parent.openForRead( getFullPath( path ) ); } diff --git a/src/main/java/dan200/computercraft/core/lua/ILuaMachine.java b/src/main/java/dan200/computercraft/core/lua/ILuaMachine.java index 45a5f3644..798884678 100644 --- a/src/main/java/dan200/computercraft/core/lua/ILuaMachine.java +++ b/src/main/java/dan200/computercraft/core/lua/ILuaMachine.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,17 +12,17 @@ import java.io.OutputStream; public interface ILuaMachine { - public void addAPI( ILuaAPI api ); + void addAPI( ILuaAPI api ); - public void loadBios( InputStream bios ); - public void handleEvent( String eventName, Object[] arguments ); - public void softAbort( String abortMessage ); - public void hardAbort( String abortMessage ); + void loadBios( InputStream bios ); + void handleEvent( String eventName, Object[] arguments ); + void softAbort( String abortMessage ); + void hardAbort( String abortMessage ); - public boolean saveState( OutputStream output ); - public boolean restoreState( InputStream input ); + boolean saveState( OutputStream output ); + boolean restoreState( InputStream input ); - public boolean isFinished(); + boolean isFinished(); - public void unload(); + void unload(); } diff --git a/src/main/java/dan200/computercraft/core/lua/LuaJLuaMachine.java b/src/main/java/dan200/computercraft/core/lua/LuaJLuaMachine.java index 16cefb4b8..ccc9d3d20 100644 --- a/src/main/java/dan200/computercraft/core/lua/LuaJLuaMachine.java +++ b/src/main/java/dan200/computercraft/core/lua/LuaJLuaMachine.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,10 +21,10 @@ import org.luaj.vm2.lib.VarArgFunction; import org.luaj.vm2.lib.ZeroArgFunction; import org.luaj.vm2.lib.jse.JsePlatform; +import javax.annotation.Nonnull; import java.io.*; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.Iterator; import java.util.Map; public class LuaJLuaMachine implements ILuaMachine @@ -128,9 +128,9 @@ public class LuaJLuaMachine implements ILuaMachine // Add the methods of an API to the global table LuaTable table = wrapLuaObject( api ); String[] names = api.getNames(); - for( int i=0; i pair : ((Map) object).entrySet() ) { - Map.Entry pair = (Map.Entry)it.next(); LuaValue key = toValue( pair.getKey() ); LuaValue value = toValue( pair.getValue() ); if( !key.isnil() && !value.isnil() ) @@ -558,8 +551,7 @@ public class LuaJLuaMachine implements ILuaMachine } else if( object instanceof ILuaObject ) { - LuaValue table = wrapLuaObject( (ILuaObject)object ); - return table; + return wrapLuaObject( (ILuaObject)object ); } else { @@ -627,7 +619,7 @@ public class LuaJLuaMachine implements ILuaMachine { return m_objectsInProgress.get( value ); } - Map table = new HashMap(); + Map table = new HashMap(); m_objectsInProgress.put( value, table ); // Convert all keys diff --git a/src/main/java/dan200/computercraft/core/terminal/Terminal.java b/src/main/java/dan200/computercraft/core/terminal/Terminal.java index 40d9ecf55..9a6643534 100644 --- a/src/main/java/dan200/computercraft/core/terminal/Terminal.java +++ b/src/main/java/dan200/computercraft/core/terminal/Terminal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/core/terminal/TextBuffer.java b/src/main/java/dan200/computercraft/core/terminal/TextBuffer.java index 9cc54e5b5..135bab194 100644 --- a/src/main/java/dan200/computercraft/core/terminal/TextBuffer.java +++ b/src/main/java/dan200/computercraft/core/terminal/TextBuffer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/server/proxy/CCTurtleProxyServer.java b/src/main/java/dan200/computercraft/server/proxy/CCTurtleProxyServer.java index a5fa5b905..caaf61400 100644 --- a/src/main/java/dan200/computercraft/server/proxy/CCTurtleProxyServer.java +++ b/src/main/java/dan200/computercraft/server/proxy/CCTurtleProxyServer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/server/proxy/ComputerCraftProxyServer.java b/src/main/java/dan200/computercraft/server/proxy/ComputerCraftProxyServer.java index b7cc31e53..d9b4c9f00 100644 --- a/src/main/java/dan200/computercraft/server/proxy/ComputerCraftProxyServer.java +++ b/src/main/java/dan200/computercraft/server/proxy/ComputerCraftProxyServer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -6,7 +6,6 @@ package dan200.computercraft.server.proxy; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; import dan200.computercraft.shared.peripheral.printer.TilePrinter; diff --git a/src/main/java/dan200/computercraft/shared/common/BlockDirectional.java b/src/main/java/dan200/computercraft/shared/common/BlockDirectional.java index 376a97aa0..025115f22 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockDirectional.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockDirectional.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java index 8c024785c..d9d379151 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,7 +10,6 @@ import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; -import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -25,8 +24,8 @@ import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; public abstract class BlockGeneric extends Block implements @@ -43,12 +42,13 @@ public abstract class BlockGeneric extends Block implements protected abstract TileGeneric createTile( int damage ); @Override - public final void dropBlockAsItemWithChance( World world, BlockPos pos, IBlockState state, float chance, int fortune ) + public final void dropBlockAsItemWithChance( World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, float chance, int fortune ) { } + @Nonnull @Override - public final List getDrops( IBlockAccess world, BlockPos pos, IBlockState state, int fortune ) + public final List getDrops( IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune ) { ArrayList drops = new ArrayList( 1 ); TileEntity tile = world.getTileEntity( pos ); @@ -60,6 +60,7 @@ public abstract class BlockGeneric extends Block implements return drops; } + @Nonnull @Override public final IBlockState onBlockPlaced( World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int damage, EntityLivingBase placer ) { @@ -67,7 +68,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public final boolean removedByPlayer( IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest ) + public final boolean removedByPlayer( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest ) { if( !world.isRemote ) { @@ -94,10 +95,8 @@ public abstract class BlockGeneric extends Block implements // Drop items if( drops.size() > 0 ) { - Iterator it = drops.iterator(); - while( it.hasNext() ) + for (ItemStack item : drops) { - ItemStack item = it.next(); dropItem( world, pos, item ); } } @@ -109,7 +108,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public final void breakBlock( World world, BlockPos pos, IBlockState newState ) + public final void breakBlock( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState newState ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) @@ -121,8 +120,9 @@ public abstract class BlockGeneric extends Block implements world.removeTileEntity( pos ); } + @Nonnull @Override - public final ItemStack getPickBlock( IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player ) + public final ItemStack getPickBlock( @Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) @@ -134,7 +134,7 @@ public abstract class BlockGeneric extends Block implements } @Override - protected final ItemStack createStackedBlock( IBlockState state ) + protected final ItemStack createStackedBlock( @Nonnull IBlockState state ) { return null; } @@ -152,6 +152,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block ) { TileEntity tile = world.getTileEntity( pos ); @@ -174,7 +175,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side ) + public final boolean isSideSolid( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) @@ -192,7 +193,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public float getExplosionResistance( World world, BlockPos pos, Entity exploder, Explosion explosion ) + public float getExplosionResistance( World world, BlockPos pos, @Nonnull Entity exploder, Explosion explosion ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() ) @@ -206,7 +207,9 @@ public abstract class BlockGeneric extends Block implements return super.getExplosionResistance( exploder ); } + @Nonnull @Override + @Deprecated public final AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess world, BlockPos pos ) { TileEntity tile = world.getTileEntity( pos ); @@ -218,14 +221,17 @@ public abstract class BlockGeneric extends Block implements return FULL_BLOCK_AABB; } + @Nonnull @Override - public AxisAlignedBB getSelectedBoundingBox( IBlockState state, World worldIn, BlockPos pos ) + @Deprecated + public final AxisAlignedBB getSelectedBoundingBox( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos ) { - return getBoundingBox( state, worldIn, pos ).offset( pos ); + return getBoundingBox( state, world, pos ).offset( pos ); } @Override - public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, World world, BlockPos pos ) + @Deprecated + public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() ) @@ -252,7 +258,8 @@ public abstract class BlockGeneric extends Block implements } @Override - public final void addCollisionBoxToList( IBlockState state, World world, BlockPos pos, AxisAlignedBB bigBox, List list, Entity entity ) + @Deprecated + public final void addCollisionBoxToList( IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB bigBox, @Nonnull List list, Entity entity ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric && tile.hasWorldObj() ) @@ -266,10 +273,8 @@ public abstract class BlockGeneric extends Block implements // Add collision bounds to list if( collision.size() > 0 ) { - Iterator it = collision.iterator(); - while( it.hasNext() ) + for (AxisAlignedBB localBounds : collision) { - AxisAlignedBB localBounds = it.next(); addCollisionBoxToList( pos, bigBox, list, localBounds ); } } @@ -277,6 +282,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public final boolean canProvidePower( IBlockState state ) { return true; @@ -295,6 +301,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public final int getStrongPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide ) { TileEntity tile = world.getTileEntity( pos ); @@ -307,6 +314,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public final int getWeakPower( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing oppositeSide ) { return getStrongPower( state, world, pos, oppositeSide ); @@ -335,6 +343,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public boolean eventReceived( IBlockState state, World world, BlockPos pos, int eventID, int eventParameter ) { if( world.isRemote ) @@ -349,14 +358,16 @@ public abstract class BlockGeneric extends Block implements return true; } + @Nonnull @Override - public final TileEntity createTileEntity( World world, IBlockState state ) + public final TileEntity createTileEntity( @Nonnull World world, @Nonnull IBlockState state ) { return createTile( state ); } + @Nonnull @Override - public final TileEntity createNewTileEntity( World world, int damage ) + public final TileEntity createNewTileEntity( @Nonnull World world, int damage ) { return createTile( damage ); } diff --git a/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java b/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java index 37177a019..b5c8a2a83 100644 --- a/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java +++ b/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java index dc4db1091..1b433c204 100644 --- a/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider { public DefaultBundledRedstoneProvider() @@ -19,7 +21,7 @@ public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider } @Override - public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) { return getDefaultBundledRedstoneOutput( world, pos, side ); } diff --git a/src/main/java/dan200/computercraft/shared/common/IDirectionalTile.java b/src/main/java/dan200/computercraft/shared/common/IDirectionalTile.java index 494486ba9..1f5c18f7b 100644 --- a/src/main/java/dan200/computercraft/shared/common/IDirectionalTile.java +++ b/src/main/java/dan200/computercraft/shared/common/IDirectionalTile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,6 @@ import net.minecraft.util.EnumFacing; public interface IDirectionalTile { - public EnumFacing getDirection(); - public void setDirection( EnumFacing dir ); + EnumFacing getDirection(); + void setDirection( EnumFacing dir ); } diff --git a/src/main/java/dan200/computercraft/shared/common/ITerminal.java b/src/main/java/dan200/computercraft/shared/common/ITerminal.java index 3b10da9a9..e3b295146 100644 --- a/src/main/java/dan200/computercraft/shared/common/ITerminal.java +++ b/src/main/java/dan200/computercraft/shared/common/ITerminal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,6 @@ import dan200.computercraft.core.terminal.Terminal; public interface ITerminal { - public Terminal getTerminal(); - public boolean isColour(); + Terminal getTerminal(); + boolean isColour(); } diff --git a/src/main/java/dan200/computercraft/shared/common/ITerminalTile.java b/src/main/java/dan200/computercraft/shared/common/ITerminalTile.java index f7bbc022a..47d3e16bb 100644 --- a/src/main/java/dan200/computercraft/shared/common/ITerminalTile.java +++ b/src/main/java/dan200/computercraft/shared/common/ITerminalTile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,5 +8,5 @@ package dan200.computercraft.shared.common; public interface ITerminalTile { - public ITerminal getTerminal(); + ITerminal getTerminal(); } diff --git a/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java b/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java index b8755a208..e4838bf3f 100644 --- a/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java +++ b/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index a8709b73a..09fcef63e 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,7 +15,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.AxisAlignedBB; @@ -23,6 +22,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; public abstract class TileGeneric extends TileEntity @@ -48,6 +49,7 @@ public abstract class TileGeneric extends TileEntity { } + @Nullable public BlockGeneric getBlock() { Block block = worldObj.getBlockState( getPos() ).getBlock(); @@ -77,7 +79,7 @@ public abstract class TileGeneric extends TileEntity worldObj.setBlockState( getPos(), newState, 3 ); } - public void getDroppedItems( List drops, boolean creative ) + public void getDroppedItems( @Nonnull List drops, boolean creative ) { } @@ -95,7 +97,7 @@ public abstract class TileGeneric extends TileEntity { } - public void onNeighbourTileEntityChange( BlockPos neighbour ) + public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) { } @@ -109,12 +111,13 @@ public abstract class TileGeneric extends TileEntity return false; } + @Nonnull public AxisAlignedBB getBounds() { return new AxisAlignedBB( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ); } - public void getCollisionBounds( List bounds ) + public void getCollisionBounds( @Nonnull List bounds ) { bounds.add( getBounds() ); } @@ -129,12 +132,12 @@ public abstract class TileGeneric extends TileEntity return 0; } - public boolean getBundledRedstoneConnectivity( EnumFacing side ) + public boolean getBundledRedstoneConnectivity( @Nonnull EnumFacing side ) { return false; } - public int getBundledRedstoneOutput( EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull EnumFacing side ) { return 0; } @@ -163,11 +166,11 @@ public abstract class TileGeneric extends TileEntity return false; } - protected void writeDescription( NBTTagCompound nbttagcompound ) + protected void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { } - protected void readDescription( NBTTagCompound nbttagcompound ) + protected void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { } @@ -186,7 +189,7 @@ public abstract class TileGeneric extends TileEntity } @Override - public boolean shouldRefresh( World world, BlockPos pos, IBlockState oldState, IBlockState newState ) + public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState ) { return newState.getBlock() != oldState.getBlock(); } @@ -215,6 +218,7 @@ public abstract class TileGeneric extends TileEntity } } + @Nonnull @Override public NBTTagCompound getUpdateTag () { @@ -224,7 +228,7 @@ public abstract class TileGeneric extends TileEntity } @Override - public void handleUpdateTag (NBTTagCompound tag) + public void handleUpdateTag ( @Nonnull NBTTagCompound tag) { super.handleUpdateTag(tag); readDescription( tag ); 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 189855231..692353b83 100644 --- a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,9 +21,9 @@ import net.minecraft.command.ICommandManager; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.HashMap; import java.util.Map; @@ -61,6 +61,7 @@ public class CommandAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -111,7 +112,7 @@ public class CommandAPI implements ILuaAPI // Get the details of the block IBlockState state = world.getBlockState( pos ); Block block = state.getBlock(); - String name = ((ResourceLocation)Block.REGISTRY.getNameForObject( block )).toString(); + String name = Block.REGISTRY.getNameForObject( block ).toString(); int metadata = block.getMetaFromState( state ); Map table = new HashMap(); @@ -119,9 +120,8 @@ public class CommandAPI implements ILuaAPI table.put( "metadata", metadata ); Map stateTable = new HashMap(); - for( Object o : state.getActualState( world, pos ).getProperties().entrySet() ) + for( ImmutableMap.Entry, Comparable> entry : state.getActualState( world, pos ).getProperties().entrySet() ) { - ImmutableMap.Entry entry = (ImmutableMap.Entry)o; String propertyName = entry.getKey().getName(); Object value = entry.getValue(); if( value instanceof String || value instanceof Number || value instanceof Boolean ) @@ -139,7 +139,7 @@ public class CommandAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { @@ -193,12 +193,11 @@ public class CommandAPI implements ILuaAPI { ICommandManager commandManager = server.getCommandManager(); ICommandSender commmandSender = m_computer.getCommandSender(); - Map commands = commandManager.getCommands(); - for( Object entryObject : commands.entrySet() ) + Map commands = commandManager.getCommands(); + for( Map.Entry entry : commands.entrySet() ) { - Map.Entry entry = (Map.Entry)entryObject; - String name = (String)entry.getKey(); - ICommand command = (ICommand)entry.getValue(); + String name = entry.getKey(); + ICommand command = entry.getValue(); try { if( command.checkPermission( server, commmandSender ) ) diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockCommandComputer.java index f5db1af1f..ab0aaf7ab 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockCommandComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,10 +9,8 @@ package dan200.computercraft.shared.computer.blocks; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.IComputer; -import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; @@ -25,6 +23,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class BlockCommandComputer extends BlockComputerBase { // Statics @@ -32,7 +32,7 @@ public class BlockCommandComputer extends BlockComputerBase public static class Properties { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); - public static final PropertyEnum STATE = PropertyEnum.create("state", ComputerState.class); + public static final PropertyEnum STATE = PropertyEnum.create("state", ComputerState.class); } // Members @@ -50,16 +50,16 @@ public class BlockCommandComputer extends BlockComputerBase ); } + @Nonnull @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] { - Properties.FACING, - Properties.STATE - }); + return new BlockStateContainer(this, Properties.FACING, Properties.STATE ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { EnumFacing dir = EnumFacing.getFront( meta & 0x7 ); @@ -73,11 +73,13 @@ public class BlockCommandComputer extends BlockComputerBase @Override public int getMetaFromState( IBlockState state ) { - return ((EnumFacing)state.getValue( Properties.FACING )).getIndex(); + return state.getValue( Properties.FACING ).getIndex(); } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof IComputerTile ) diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java index 6beb393ec..9db8a672c 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,7 +12,6 @@ import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.items.ItemComputer; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; @@ -22,11 +21,13 @@ import net.minecraft.entity.EntityLivingBase; 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.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class BlockComputer extends BlockComputerBase { // Statics @@ -34,7 +35,7 @@ public class BlockComputer extends BlockComputerBase { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final PropertyBool ADVANCED = PropertyBool.create("advanced"); - public static final PropertyEnum STATE = PropertyEnum.create("state", ComputerState.class); + public static final PropertyEnum STATE = PropertyEnum.create("state", ComputerState.class); } // Members @@ -52,17 +53,16 @@ public class BlockComputer extends BlockComputerBase ); } + @Nonnull @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] { - Properties.FACING, - Properties.ADVANCED, - Properties.STATE - }); + return new BlockStateContainer( this, Properties.FACING, Properties.ADVANCED, Properties.STATE ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { EnumFacing dir = EnumFacing.getFront( meta & 0x7 ); @@ -86,8 +86,8 @@ public class BlockComputer extends BlockComputerBase @Override public int getMetaFromState( IBlockState state ) { - int meta = ((EnumFacing)state.getValue( Properties.FACING )).getIndex(); - if( (Boolean)state.getValue( Properties.ADVANCED ) ) + int meta = state.getValue( Properties.FACING ).getIndex(); + if( state.getValue( Properties.ADVANCED ) ) { meta += 8; } @@ -117,8 +117,10 @@ public class BlockComputer extends BlockComputerBase } } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof IComputerTile ) @@ -148,7 +150,7 @@ public class BlockComputer extends BlockComputerBase @Override public ComputerFamily getFamily( IBlockState state ) { - if( (Boolean)state.getValue( Properties.ADVANCED ) ) { + if( state.getValue( Properties.ADVANCED ) ) { return ComputerFamily.Advanced; } else { return ComputerFamily.Normal; diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java index 4c4a099f9..93cd938c0 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerPeripheral.java b/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerPeripheral.java index d0bb9ffc4..d2ef39602 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.shared.computer.core.ServerComputer; +import javax.annotation.Nonnull; + public class ComputerPeripheral implements IPeripheral { @@ -26,12 +28,14 @@ public class ComputerPeripheral // IPeripheral implementation + @Nonnull @Override public String getType() { return m_type; } + @Nonnull @Override public String[] getMethodNames() { @@ -45,7 +49,7 @@ public class ComputerPeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException { switch( method ) { @@ -87,12 +91,12 @@ public class ComputerPeripheral } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { } @Override - public void detach( IComputerAccess computer ) + public void detach( @Nonnull IComputerAccess computer ) { } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerState.java b/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerState.java index bcebed315..6683053cf 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerState.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/ComputerState.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,8 @@ package dan200.computercraft.shared.computer.blocks; import net.minecraft.util.IStringSerializable; +import javax.annotation.Nonnull; + public enum ComputerState implements IStringSerializable { Off( "off" ), @@ -16,11 +18,12 @@ public enum ComputerState implements IStringSerializable private String m_name; - private ComputerState( String name ) + ComputerState( String name ) { m_name = name; } + @Nonnull @Override public String getName() { diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/IComputerTile.java b/src/main/java/dan200/computercraft/shared/computer/blocks/IComputerTile.java index c2d8173c9..dc0917c8e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/IComputerTile.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/IComputerTile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,9 +12,9 @@ import dan200.computercraft.shared.computer.core.IComputer; public interface IComputerTile extends ITerminalTile { - public void setComputerID( int id ); - public void setLabel( String label ); - public IComputer getComputer(); - public IComputer createComputer(); - public ComputerFamily getFamily(); + void setComputerID( int id ); + void setLabel( String label ); + IComputer getComputer(); + IComputer createComputer(); + ComputerFamily getFamily(); } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java index 045be5934..1c1e90fe0 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,7 +21,7 @@ import net.minecraft.util.text.*; import net.minecraft.util.*; import net.minecraft.world.World; -import javax.annotation.Nullable; +import javax.annotation.Nonnull; import java.util.HashMap; import java.util.Map; @@ -53,6 +53,7 @@ public class TileCommandComputer extends TileComputer // ICommandSender + @Nonnull @Override public ITextComponent getDisplayName() { @@ -69,7 +70,7 @@ public class TileCommandComputer extends TileComputer } @Override - public void addChatMessage( ITextComponent chatComponent ) + public void addChatMessage( @Nonnull ITextComponent chatComponent ) { m_outputTable.put( m_outputTable.size() + 1, chatComponent.getUnformattedText() ); } @@ -80,12 +81,14 @@ public class TileCommandComputer extends TileComputer return level <= 2; } + @Nonnull @Override public BlockPos getPosition() { return TileCommandComputer.this.getPos(); } + @Nonnull @Override public Vec3d getPositionVector() { @@ -93,6 +96,7 @@ public class TileCommandComputer extends TileComputer return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } + @Nonnull @Override public World getEntityWorld() { @@ -126,7 +130,7 @@ public class TileCommandComputer extends TileComputer } @Override - public void fillInInfo( ByteBuf buf ) + public void fillInInfo( @Nonnull ByteBuf buf ) { } } @@ -142,7 +146,7 @@ public class TileCommandComputer extends TileComputer public EnumFacing getDirection() { IBlockState state = getBlockState(); - return (EnumFacing)state.getValue( BlockCommandComputer.Properties.FACING ); + return state.getValue( BlockCommandComputer.Properties.FACING ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java index 476453203..acb1c7f0c 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import javax.annotation.Nonnull; import java.util.List; public class TileComputer extends TileComputerBase @@ -47,7 +48,7 @@ public class TileComputer extends TileComputerBase } @Override - public void getDroppedItems( List drops, boolean creative ) + public void getDroppedItems( @Nonnull List drops, boolean creative ) { IComputer computer = getComputer(); if( !creative || (computer != null && computer.getLabel() != null) ) @@ -69,7 +70,7 @@ public class TileComputer extends TileComputerBase } @Override - public final void readDescription( NBTTagCompound nbttagcompound ) + public final void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); updateBlock(); @@ -86,7 +87,7 @@ public class TileComputer extends TileComputerBase public EnumFacing getDirection() { IBlockState state = getBlockState(); - return (EnumFacing)state.getValue( BlockComputer.Properties.FACING ); + return state.getValue( BlockComputer.Properties.FACING ); } @Override 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 baeec3720..143d65df0 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -27,6 +27,8 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; +import javax.annotation.Nonnull; + public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable { @@ -167,14 +169,14 @@ public abstract class TileComputerBase extends TileGeneric } @Override - public boolean getBundledRedstoneConnectivity( EnumFacing side ) + public boolean getBundledRedstoneConnectivity( @Nonnull EnumFacing side ) { int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) ); return !isRedstoneBlockedOnSide( localDir ); } @Override - public int getBundledRedstoneOutput( EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull EnumFacing side ) { int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) ); if( !isRedstoneBlockedOnSide( localDir ) ) @@ -198,7 +200,7 @@ public abstract class TileComputerBase extends TileGeneric } @Override - public void onNeighbourTileEntityChange( BlockPos neighbour ) + public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) { updateInput( neighbour ); } @@ -239,6 +241,7 @@ public abstract class TileComputerBase extends TileGeneric } } + @Nonnull @Override public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound ) { @@ -517,14 +520,14 @@ public abstract class TileComputerBase extends TileGeneric // Networking stuff @Override - public void writeDescription( NBTTagCompound nbttagcompound ) + public void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.writeDescription( nbttagcompound ); nbttagcompound.setInteger( "instanceID", createServerComputer().getInstanceID() ); } @Override - public void readDescription( NBTTagCompound nbttagcompound ) + public void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); m_instanceID = nbttagcompound.getInteger( "instanceID" ); diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java index 812f0c204..eca8eadc9 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputerRegistry.java b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputerRegistry.java index 1b009eb4d..c5bfd4c3b 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputerRegistry.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputerRegistry.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java b/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java index c57b30689..7317ef02e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ComputerFamily.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ComputerRegistry.java b/src/main/java/dan200/computercraft/shared/computer/core/ComputerRegistry.java index d8e500805..164e150b4 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ComputerRegistry.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ComputerRegistry.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/core/IComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/IComputer.java index dfc5718c9..fdcb5548d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/IComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/IComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,16 +10,16 @@ import dan200.computercraft.shared.common.ITerminal; public interface IComputer extends ITerminal { - public int getInstanceID(); - public int getID(); - public String getLabel(); + int getInstanceID(); + int getID(); + String getLabel(); - public boolean isOn(); - public boolean isCursorDisplayed(); - public void turnOn(); - public void shutdown(); - public void reboot(); + boolean isOn(); + boolean isCursorDisplayed(); + void turnOn(); + void shutdown(); + void reboot(); - public void queueEvent( String event ); - public void queueEvent( String event, Object[] arguments ); + void queueEvent( String event ); + void queueEvent( String event, Object[] arguments ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/core/IComputerContainer.java b/src/main/java/dan200/computercraft/shared/computer/core/IComputerContainer.java index 28ed13e33..68c19bfbb 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/IComputerContainer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/IComputerContainer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,5 +8,5 @@ package dan200.computercraft.shared.computer.core; public interface IComputerContainer { - public IComputer getComputer(); + 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 4161afb7d..c1cf5312f 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputerRegistry.java b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputerRegistry.java index 131add5f4..932b63352 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputerRegistry.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputerRegistry.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com 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 d99c4ca8a..bf3952aac 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,7 @@ import dan200.computercraft.shared.computer.core.IContainerComputer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ContainerComputer extends Container @@ -25,7 +26,7 @@ public class ContainerComputer extends Container } @Override - public boolean canInteractWith( EntityPlayer player ) + public boolean canInteractWith( @Nonnull EntityPlayer player ) { return m_computer.isUseableByPlayer( player ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java b/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java index ea7b0d284..27b23c3ea 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ComputerItemFactory.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java b/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java index 4ca1bae03..c30e76012 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,7 +11,7 @@ import net.minecraft.item.ItemStack; public interface IComputerItem { - public int getComputerID( ItemStack stack ); - public String getLabel( ItemStack stack ); - public ComputerFamily getFamily( ItemStack stack ); + int getComputerID( ItemStack stack ); + String getLabel( ItemStack stack ); + ComputerFamily getFamily( ItemStack stack ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java index bfe63c328..1f6ec1000 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import javax.annotation.Nonnull; import java.util.List; public class ItemCommandComputer extends ItemComputer @@ -51,7 +52,7 @@ public class ItemCommandComputer extends ItemComputer } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, @Nonnull CreativeTabs tabs, @Nonnull List list ) { list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Command ) ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java index 463181623..2d9d290bd 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,6 +21,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class ItemComputer extends ItemComputerBase @@ -71,14 +72,14 @@ public class ItemComputer extends ItemComputerBase } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, @Nonnull CreativeTabs tabs, @Nonnull List list ) { list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Normal ) ); list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ) ); } @Override - public boolean placeBlockAt( ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState ) + public boolean placeBlockAt( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState ) { if( super.placeBlockAt( stack, player, world, pos, side, hitX, hitY, hitZ, newState ) ) { @@ -110,6 +111,7 @@ public class ItemComputer extends ItemComputerBase } } + @Nonnull @Override public String getUnlocalizedName( ItemStack stack ) { diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java index b3ce17fd5..4656a4a5d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.computer.core.ServerComputer; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; @@ -18,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.SoundEvent; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public abstract class ItemComputerBase extends ItemBlock implements IComputerItem, IMedia @@ -36,7 +36,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte } @Override - public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean debug ) + public void addInformation( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull List list, boolean debug ) { if( debug ) { @@ -54,7 +54,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte public abstract int getComputerID( ItemStack stack ); @Override - public String getLabel( ItemStack stack ) + public String getLabel( @Nonnull ItemStack stack ) { if( stack.hasDisplayName() ) { @@ -73,7 +73,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte // IMedia implementation @Override - public boolean setLabel( ItemStack stack, String label ) + public boolean setLabel( @Nonnull ItemStack stack, String label ) { if( label != null ) { @@ -87,19 +87,19 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte } @Override - public String getAudioTitle( ItemStack stack ) + public String getAudioTitle( @Nonnull ItemStack stack ) { return null; } @Override - public SoundEvent getAudio( ItemStack stack ) + public SoundEvent getAudio( @Nonnull ItemStack stack ) { return null; } @Override - public IMount createDataMount( ItemStack stack, World world ) + public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ) { ComputerFamily family = getFamily( stack ); if( family != ComputerFamily.Command ) diff --git a/src/main/java/dan200/computercraft/shared/media/common/DefaultMediaProvider.java b/src/main/java/dan200/computercraft/shared/media/common/DefaultMediaProvider.java index 50bbc57f2..d005a7758 100644 --- a/src/main/java/dan200/computercraft/shared/media/common/DefaultMediaProvider.java +++ b/src/main/java/dan200/computercraft/shared/media/common/DefaultMediaProvider.java @@ -7,6 +7,8 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class DefaultMediaProvider implements IMediaProvider { public DefaultMediaProvider() @@ -14,7 +16,7 @@ public class DefaultMediaProvider implements IMediaProvider } @Override - public IMedia getMedia( ItemStack stack ) + public IMedia getMedia( @Nonnull ItemStack stack ) { Item item = stack.getItem(); if( item instanceof IMedia ) diff --git a/src/main/java/dan200/computercraft/shared/media/inventory/ContainerHeldItem.java b/src/main/java/dan200/computercraft/shared/media/inventory/ContainerHeldItem.java index d19b9b7c5..a5d84b317 100644 --- a/src/main/java/dan200/computercraft/shared/media/inventory/ContainerHeldItem.java +++ b/src/main/java/dan200/computercraft/shared/media/inventory/ContainerHeldItem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; +import javax.annotation.Nonnull; + public class ContainerHeldItem extends Container { private final ItemStack m_stack; @@ -29,7 +31,7 @@ public class ContainerHeldItem extends Container } @Override - public boolean canInteractWith( EntityPlayer player ) + public boolean canInteractWith( @Nonnull EntityPlayer player ) { if( player != null && player.isEntityAlive() ) { diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java index a3643e5c2..c6624ad64 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskExpanded.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java index 348faa531..76d703f2f 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -20,6 +20,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class ItemDiskLegacy extends Item @@ -34,7 +35,7 @@ public class ItemDiskLegacy extends Item } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List list ) { for( int colour=0; colour<16; ++colour ) { @@ -79,7 +80,7 @@ public class ItemDiskLegacy extends Item } @Override - public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean debug ) + public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean debug ) { if( debug ) { @@ -94,7 +95,7 @@ public class ItemDiskLegacy extends Item // IMedia implementation @Override - public String getLabel( ItemStack stack ) + public String getLabel( @Nonnull ItemStack stack ) { if( stack.hasDisplayName() ) { @@ -104,7 +105,7 @@ public class ItemDiskLegacy extends Item } @Override - public boolean setLabel( ItemStack stack, String label ) + public boolean setLabel( @Nonnull ItemStack stack, String label ) { if( label != null ) { @@ -118,19 +119,19 @@ public class ItemDiskLegacy extends Item } @Override - public String getAudioTitle( ItemStack stack ) + public String getAudioTitle( @Nonnull ItemStack stack ) { return null; } @Override - public SoundEvent getAudio( ItemStack stack ) + public SoundEvent getAudio( @Nonnull ItemStack stack ) { return null; } @Override - public IMount createDataMount( ItemStack stack, World world ) + public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ) { int diskID = getDiskID( stack ); if( diskID < 0 ) diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java index 336a6edc0..0014dc2f1 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,6 +17,7 @@ import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class ItemPrintout extends Item @@ -41,7 +42,7 @@ public class ItemPrintout extends Item } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List list ) { list.add( createSingleFromTitleAndText( null, new String[ LINES_PER_PAGE ], new String[ LINES_PER_PAGE ] ) ); list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); @@ -49,7 +50,7 @@ public class ItemPrintout extends Item } @Override - public void addInformation( ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean flag ) + public void addInformation( ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean flag ) { String title = getTitle( itemstack ); if( title != null && title.length() > 0 ) @@ -58,6 +59,7 @@ public class ItemPrintout extends Item } } + @Nonnull @Override public String getUnlocalizedName( ItemStack stack ) { @@ -80,8 +82,9 @@ public class ItemPrintout extends Item } } + @Nonnull @Override - public ActionResult onItemRightClick( ItemStack stack, World world, EntityPlayer player, EnumHand hand ) + public ActionResult onItemRightClick( @Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand ) { if( !world.isRemote ) { diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java index 4e9953419..f7407f084 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,11 +21,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Random; public class ItemTreasureDisk extends Item implements IMedia @@ -38,12 +36,12 @@ public class ItemTreasureDisk extends Item } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List list ) { } @Override - public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean bool ) + public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean bool ) { String label = getTitle( stack ); if( label != null && label.length() > 0 ) @@ -61,31 +59,31 @@ public class ItemTreasureDisk extends Item // IMedia implementation @Override - public String getLabel( ItemStack stack ) + public String getLabel( @Nonnull ItemStack stack ) { return getTitle( stack ); } @Override - public boolean setLabel( ItemStack stack, String label ) + public boolean setLabel( @Nonnull ItemStack stack, String label ) { return false; } @Override - public String getAudioTitle( ItemStack stack ) + public String getAudioTitle( @Nonnull ItemStack stack ) { return null; } @Override - public SoundEvent getAudio( ItemStack stack ) + public SoundEvent getAudio( @Nonnull ItemStack stack ) { return null; } @Override - public IMount createDataMount( ItemStack stack, World world ) + public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ) { IMount rootTreasure = getTreasureMount(); String subPath = getSubPath( stack ); diff --git a/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java b/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java index ffaf433ed..b01c1c458 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java +++ b/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,6 +15,8 @@ import net.minecraft.util.SoundEvent; import net.minecraft.world.World; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import javax.annotation.Nonnull; + // An implementation of IMedia for ItemRecord's public class RecordMedia implements IMedia { @@ -23,32 +25,32 @@ public class RecordMedia implements IMedia } @Override - public String getLabel( ItemStack stack ) + public String getLabel( @Nonnull ItemStack stack ) { return getAudioTitle( stack ); } @Override - public boolean setLabel( ItemStack stack, String label ) + public boolean setLabel( @Nonnull ItemStack stack, String label ) { return false; } @Override - public String getAudioTitle( ItemStack stack ) + public String getAudioTitle( @Nonnull ItemStack stack ) { return ComputerCraft.getRecordInfo( stack ); } @Override - public SoundEvent getAudio( ItemStack stack ) + public SoundEvent getAudio( @Nonnull ItemStack stack ) { ItemRecord itemRecord = (ItemRecord)stack.getItem(); return ObfuscationReflectionHelper.getPrivateValue(ItemRecord.class, itemRecord, "field_185076_b"); } @Override - public IMount createDataMount( ItemStack stack, World world ) + public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ) { return null; } diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java index 5d0cad320..4c9a59468 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class DiskRecipe implements IRecipe { public DiskRecipe() @@ -21,7 +23,7 @@ public class DiskRecipe implements IRecipe } @Override - public boolean matches( InventoryCrafting inventory, World world ) + public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world ) { boolean diskFound = false; boolean paperFound = false; @@ -75,7 +77,7 @@ public class DiskRecipe implements IRecipe } @Override - public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) + public ItemStack getCraftingResult( @Nonnull InventoryCrafting par1InventoryCrafting) { int diskID = -1; String diskLabel = null; @@ -83,7 +85,7 @@ public class DiskRecipe implements IRecipe int[] var3 = new int[3]; int var4 = 0; int var5 = 0; - ItemDiskLegacy var6 = null; + ItemDiskLegacy var6; int var7; int var9; float var10; @@ -153,8 +155,9 @@ public class DiskRecipe implements IRecipe return ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); } + @Nonnull @Override - public ItemStack[] getRemainingItems( InventoryCrafting inventoryCrafting ) + public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) { ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ]; for (int i = 0; i < results.length; ++i) diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java index 36638e011..f3c703695 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class PrintoutRecipe implements IRecipe { public PrintoutRecipe( ) @@ -33,13 +35,13 @@ public class PrintoutRecipe implements IRecipe } @Override - public boolean matches( InventoryCrafting _inventory, World world ) + public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world ) { return (getCraftingResult( _inventory ) != null); } @Override - public ItemStack getCraftingResult( InventoryCrafting inventory ) + public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) { // See if we match the recipe, and extract the input disk ID and dye colour int numPages = 0; @@ -146,8 +148,9 @@ public class PrintoutRecipe implements IRecipe return null; } + @Nonnull @Override - public ItemStack[] getRemainingItems( InventoryCrafting inventoryCrafting ) + public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) { ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ]; for (int i = 0; i < results.length; ++i) diff --git a/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java b/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java index fdb16f8d9..f20368895 100644 --- a/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java +++ b/src/main/java/dan200/computercraft/shared/network/ComputerCraftPacket.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/network/INetworkedThing.java b/src/main/java/dan200/computercraft/shared/network/INetworkedThing.java index 7773e4a19..56e6f4f9f 100644 --- a/src/main/java/dan200/computercraft/shared/network/INetworkedThing.java +++ b/src/main/java/dan200/computercraft/shared/network/INetworkedThing.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,5 +9,5 @@ import net.minecraft.entity.player.EntityPlayer; public interface INetworkedThing { - public void handlePacket( ComputerCraftPacket packet, EntityPlayer sender ); + void handlePacket( ComputerCraftPacket packet, EntityPlayer sender ); } diff --git a/src/main/java/dan200/computercraft/shared/network/PacketHandler.java b/src/main/java/dan200/computercraft/shared/network/PacketHandler.java index 84fc18a0a..ad64d6757 100644 --- a/src/main/java/dan200/computercraft/shared/network/PacketHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/PacketHandler.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/peripheral/PeripheralType.java b/src/main/java/dan200/computercraft/shared/peripheral/PeripheralType.java index 6c7cb1455..455937f96 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/PeripheralType.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/PeripheralType.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,6 +8,8 @@ package dan200.computercraft.shared.peripheral; import net.minecraft.util.IStringSerializable; +import javax.annotation.Nonnull; + public enum PeripheralType implements IStringSerializable { DiskDrive( "disk_drive" ), @@ -22,11 +24,12 @@ public enum PeripheralType implements IStringSerializable private String m_name; - private PeripheralType( String name ) + PeripheralType( String name ) { m_name = name; } + @Nonnull @Override public String getName() { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java index f491b5f49..29b99708d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.tileentity.TileEntityCommandBlock; import net.minecraft.util.math.BlockPos; +import javax.annotation.Nonnull; + public class CommandBlockPeripheral implements IPeripheral { private final TileEntityCommandBlock m_commandBlock; @@ -25,12 +27,14 @@ public class CommandBlockPeripheral implements IPeripheral // IPeripheral methods + @Nonnull @Override public String getType() { return "command"; } + @Nonnull @Override public String[] getMethodNames() { @@ -42,7 +46,7 @@ public class CommandBlockPeripheral implements IPeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, final Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull final Object[] arguments ) throws LuaException, InterruptedException { switch (method) { @@ -108,12 +112,12 @@ public class CommandBlockPeripheral implements IPeripheral } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { } @Override - public void detach( IComputerAccess computer ) + public void detach( @Nonnull IComputerAccess computer ) { } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheralProvider.java b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheralProvider.java index 88f76cb1d..3800ceee1 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheralProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,10 +14,12 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class CommandBlockPeripheralProvider implements IPeripheralProvider { @Override - public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileEntityCommandBlock ) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java index 629c8ef19..bcedb4024 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,24 +10,25 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.modem.TileCable; import net.minecraft.block.Block; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; +import javax.annotation.Nonnull; + public class BlockCable extends BlockPeripheralBase { // Statics public static class Properties { - public static final PropertyEnum MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class ); + public static final PropertyEnum MODEM = PropertyEnum.create( "modem", BlockCableModemVariant.class ); public static final PropertyBool CABLE = PropertyBool.create( "cable" ); public static final PropertyBool NORTH = PropertyBool.create( "north" ); public static final PropertyBool SOUTH = PropertyBool.create( "south" ); @@ -73,10 +74,11 @@ public class BlockCable extends BlockPeripheralBase ); } + @Nonnull @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] { + return new BlockStateContainer( this, Properties.MODEM, Properties.CABLE, Properties.NORTH, @@ -84,11 +86,13 @@ public class BlockCable extends BlockPeripheralBase Properties.EAST, Properties.WEST, Properties.UP, - Properties.DOWN, - }); + Properties.DOWN + ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { IBlockState state = getDefaultState(); @@ -114,8 +118,8 @@ public class BlockCable extends BlockPeripheralBase public int getMetaFromState( IBlockState state ) { int meta = 0; - boolean cable = (Boolean)state.getValue( Properties.CABLE ); - BlockCableModemVariant modem = (BlockCableModemVariant)state.getValue( Properties.MODEM ); + boolean cable = state.getValue( Properties.CABLE ); + BlockCableModemVariant modem = state.getValue( Properties.MODEM ); if( cable && modem != BlockCableModemVariant.None ) { meta = 6 + modem.getFacing().getIndex(); @@ -160,11 +164,11 @@ public class BlockCable extends BlockPeripheralBase private boolean doesConnect( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing dir ) { - if( !((Boolean)state.getValue( Properties.CABLE )) ) + if( !state.getValue( Properties.CABLE ) ) { return false; } - else if( ((BlockCableModemVariant)state.getValue( Properties.MODEM )).getFacing() == dir ) + else if( state.getValue( Properties.MODEM ).getFacing() == dir ) { return true; } @@ -174,8 +178,10 @@ public class BlockCable extends BlockPeripheralBase } } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { state = state.withProperty( Properties.NORTH, doesConnect( state, world, pos, EnumFacing.NORTH ) ); state = state.withProperty( Properties.SOUTH, doesConnect( state, world, pos, EnumFacing.SOUTH ) ); @@ -196,7 +202,7 @@ public class BlockCable extends BlockPeripheralBase anim = 0; } - BlockCableModemVariant modem = ((BlockCableModemVariant)state.getValue( Properties.MODEM )); + BlockCableModemVariant modem = state.getValue( Properties.MODEM ); if( modem != BlockCableModemVariant.None ) { modem = BlockCableModemVariant.values()[ @@ -209,7 +215,8 @@ public class BlockCable extends BlockPeripheralBase } @Override - public boolean shouldSideBeRendered( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side ) + @Deprecated + public boolean shouldSideBeRendered( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side ) { return true; } @@ -223,8 +230,8 @@ public class BlockCable extends BlockPeripheralBase @Override public PeripheralType getPeripheralType( IBlockState state ) { - boolean cable = (Boolean)state.getValue( Properties.CABLE ); - BlockCableModemVariant modem = (BlockCableModemVariant)state.getValue( Properties.MODEM ); + boolean cable = state.getValue( Properties.CABLE ); + BlockCableModemVariant modem = state.getValue( Properties.MODEM ); if( cable && modem != BlockCableModemVariant.None ) { return PeripheralType.WiredModemWithCable; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableModemVariant.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableModemVariant.java index ffb572ac6..f76ad2002 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableModemVariant.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCableModemVariant.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,6 +9,8 @@ package dan200.computercraft.shared.peripheral.common; import net.minecraft.util.EnumFacing; import net.minecraft.util.IStringSerializable; +import javax.annotation.Nonnull; + public enum BlockCableModemVariant implements IStringSerializable { None( "none", null ), @@ -54,12 +56,13 @@ public enum BlockCableModemVariant implements IStringSerializable private String m_name; private EnumFacing m_facing; - private BlockCableModemVariant( String name, EnumFacing facing ) + BlockCableModemVariant( String name, EnumFacing facing ) { m_name = name; m_facing = facing; } + @Nonnull @Override public String getName() { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java index 2a0047881..9c31ab39f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,7 +13,6 @@ import dan200.computercraft.shared.peripheral.modem.TileWirelessModem; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.peripheral.printer.TilePrinter; import dan200.computercraft.shared.util.DirectionUtil; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; @@ -22,20 +21,22 @@ import net.minecraft.entity.EntityLivingBase; 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.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import javax.annotation.Nonnull; + public class BlockPeripheral extends BlockPeripheralBase { public static class Properties { public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL ); - public static final PropertyEnum VARIANT = PropertyEnum.create( "variant", BlockPeripheralVariant.class ); + public static final PropertyEnum VARIANT = PropertyEnum.create( "variant", BlockPeripheralVariant.class ); } public BlockPeripheral() @@ -49,22 +50,23 @@ public class BlockPeripheral extends BlockPeripheralBase ); } + @Nonnull @SideOnly( Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } + @Nonnull @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] { - Properties.FACING, - Properties.VARIANT - }); + return new BlockStateContainer( this, Properties.FACING, Properties.VARIANT ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { IBlockState state = getDefaultState(); @@ -110,12 +112,12 @@ public class BlockPeripheral extends BlockPeripheralBase public int getMetaFromState( IBlockState state ) { int meta = 0; - BlockPeripheralVariant variant = (BlockPeripheralVariant)state.getValue( Properties.VARIANT ); + BlockPeripheralVariant variant = state.getValue( Properties.VARIANT ); switch( variant.getPeripheralType() ) { case DiskDrive: { - EnumFacing dir = (EnumFacing)state.getValue( Properties.FACING ); + EnumFacing dir = state.getValue( Properties.FACING ); if( dir.getAxis() == EnumFacing.Axis.Y ) { dir = EnumFacing.NORTH; } @@ -140,7 +142,7 @@ public class BlockPeripheral extends BlockPeripheralBase } default: { - EnumFacing dir = (EnumFacing)state.getValue( Properties.FACING ); + EnumFacing dir = state.getValue( Properties.FACING ); meta = dir.getIndex() + 4; break; } @@ -166,8 +168,10 @@ public class BlockPeripheral extends BlockPeripheralBase return meta; } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { int anim; EnumFacing dir; @@ -181,8 +185,8 @@ public class BlockPeripheral extends BlockPeripheralBase else { anim = 0; - dir = (EnumFacing)state.getValue( Properties.FACING ); - switch( (BlockPeripheralVariant)state.getValue( BlockPeripheral.Properties.VARIANT ) ) + dir = state.getValue( Properties.FACING ); + switch( state.getValue( Properties.VARIANT ) ) { case WirelessModemDownOff: case WirelessModemDownOn: @@ -497,7 +501,7 @@ public class BlockPeripheral extends BlockPeripheralBase @Override public PeripheralType getPeripheralType( IBlockState state ) { - return ((BlockPeripheralVariant)state.getValue( Properties.VARIANT )).getPeripheralType(); + return state.getValue( Properties.VARIANT ).getPeripheralType(); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java index a96c3dc0a..2da659042 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,6 +17,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public abstract class BlockPeripheralBase extends BlockDirectional { public BlockPeripheralBase() @@ -30,19 +32,21 @@ public abstract class BlockPeripheralBase extends BlockDirectional protected abstract TilePeripheralBase createTile( PeripheralType type ); @Override + @Deprecated public final boolean isOpaqueCube( IBlockState state ) { return false; } @Override + @Deprecated public final boolean isFullCube( IBlockState state ) { return false; } @Override - public final boolean canPlaceBlockOnSide( World world, BlockPos pos, EnumFacing side ) + public final boolean canPlaceBlockOnSide( @Nonnull World world, @Nonnull BlockPos pos, EnumFacing side ) { return true; // ItemPeripheralBase handles this } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralVariant.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralVariant.java index 15e403c17..fc2b44efa 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralVariant.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockPeripheralVariant.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,6 +9,8 @@ package dan200.computercraft.shared.peripheral.common; import dan200.computercraft.shared.peripheral.PeripheralType; import net.minecraft.util.IStringSerializable; +import javax.annotation.Nonnull; + public enum BlockPeripheralVariant implements IStringSerializable { DiskDriveEmpty( "disk_drive_empty", PeripheralType.DiskDrive ), @@ -124,12 +126,13 @@ public enum BlockPeripheralVariant implements IStringSerializable private String m_name; private PeripheralType m_peripheralType; - private BlockPeripheralVariant( String name, PeripheralType peripheralType ) + BlockPeripheralVariant( String name, PeripheralType peripheralType ) { m_name = name; m_peripheralType = peripheralType; } + @Nonnull @Override public String getName() { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/DefaultPeripheralProvider.java b/src/main/java/dan200/computercraft/shared/peripheral/common/DefaultPeripheralProvider.java index 91f85a545..5564b1ecd 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/DefaultPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/DefaultPeripheralProvider.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -16,6 +16,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class DefaultPeripheralProvider implements IPeripheralProvider { public DefaultPeripheralProvider() @@ -23,7 +25,7 @@ public class DefaultPeripheralProvider implements IPeripheralProvider } @Override - public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null ) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralItem.java b/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralItem.java index ae5b199f7..cacbf304b 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralItem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralItem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,5 +11,5 @@ import net.minecraft.item.ItemStack; public interface IPeripheralItem { - public PeripheralType getPeripheralType( ItemStack stack ); + PeripheralType getPeripheralType( ItemStack stack ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralTile.java b/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralTile.java index d3052e995..5970845bf 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralTile.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/IPeripheralTile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,7 +13,7 @@ import net.minecraft.util.EnumFacing; public interface IPeripheralTile extends IDirectionalTile { - public PeripheralType getPeripheralType(); - public IPeripheral getPeripheral( EnumFacing side ); - public String getLabel(); + PeripheralType getPeripheralType(); + IPeripheral getPeripheral( EnumFacing side ); + String getLabel(); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java index dd40f9a6f..4ed99cc39 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,6 +13,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; import java.util.List; public class ItemAdvancedModem extends ItemPeripheralBase @@ -48,7 +49,7 @@ public class ItemAdvancedModem extends ItemPeripheralBase } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, @Nonnull CreativeTabs tabs, @Nonnull List list ) { list.add( PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 ) ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java index c98e0d41c..5228c8ec8 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,7 +13,6 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -24,6 +23,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class ItemCable extends ItemPeripheralBase @@ -63,14 +63,15 @@ public class ItemCable extends ItemPeripheralBase } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, @Nonnull CreativeTabs tabs, @Nonnull List list ) { list.add( PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Cable, null, 1 ) ); } + @Nonnull @Override - public EnumActionResult onItemUse( ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float fx, float fy, float fz ) + public EnumActionResult onItemUse( ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumHand hand, @Nonnull EnumFacing side, float fx, float fy, float fz ) { if( !canPlaceBlockOnSide( world, pos, side, player, stack ) ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java index 5e5660795..df3dbba5a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,6 +13,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; import java.util.List; public class ItemPeripheral extends ItemPeripheralBase @@ -68,7 +69,7 @@ public class ItemPeripheral extends ItemPeripheralBase } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, @Nonnull CreativeTabs tabs, @Nonnull List list ) { list.add( PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Printer, null, 1 ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheralBase.java index 640cebab3..d5841e62e 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheralBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,6 +15,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public abstract class ItemPeripheralBase extends ItemBlock implements IPeripheralItem { protected ItemPeripheralBase( Block block ) @@ -33,7 +35,7 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera } @Override - public boolean canPlaceBlockOnSide( World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack ) // canPlaceItemBlockOnSide + public boolean canPlaceBlockOnSide( World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, EntityPlayer player, @Nonnull ItemStack stack ) // canPlaceItemBlockOnSide { PeripheralType type = getPeripheralType( stack ); switch( type ) @@ -55,6 +57,7 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera } } + @Nonnull @Override public String getUnlocalizedName( ItemStack stack ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/PeripheralItemFactory.java b/src/main/java/dan200/computercraft/shared/peripheral/common/PeripheralItemFactory.java index 55768d3bf..d0fe8ffb3 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/PeripheralItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/PeripheralItemFactory.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java index 2544d0af6..1a33d54c0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,6 +15,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; import net.minecraft.util.EnumFacing; +import javax.annotation.Nonnull; import java.util.List; public abstract class TilePeripheralBase extends TileGeneric @@ -45,7 +46,7 @@ public abstract class TilePeripheralBase extends TileGeneric } @Override - public void getDroppedItems( List drops, boolean creative ) + public void getDroppedItems( @Nonnull List drops, boolean creative ) { if( !creative ) { @@ -149,7 +150,8 @@ public abstract class TilePeripheralBase extends TileGeneric } } - @Override + @Nonnull + @Override public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound ) { // Write properties @@ -164,7 +166,7 @@ public abstract class TilePeripheralBase extends TileGeneric } @Override - public void readDescription( NBTTagCompound nbttagcompound ) + public void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); m_dir = EnumFacing.getFront( nbttagcompound.getInteger( "dir" ) ); @@ -180,7 +182,7 @@ public abstract class TilePeripheralBase extends TileGeneric } @Override - public void writeDescription( NBTTagCompound nbttagcompound ) + public void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.writeDescription( nbttagcompound ); nbttagcompound.setInteger( "dir", m_dir.getIndex() ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java index 7c9139343..115325889 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class ContainerDiskDrive extends Container { private final TileDiskDrive m_diskDrive; @@ -36,7 +38,7 @@ public class ContainerDiskDrive extends Container } @Override - public boolean canInteractWith( EntityPlayer player ) + public boolean canInteractWith( @Nonnull EntityPlayer player ) { return m_diskDrive.isUseableByPlayer( player ); } @@ -45,7 +47,7 @@ public class ContainerDiskDrive extends Container public ItemStack transferStackInSlot( EntityPlayer player, int i ) { ItemStack itemstack = null; - Slot slot = (Slot)inventorySlots.get(i); + Slot slot = inventorySlots.get(i); if(slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java index 36a945456..92a813f3d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -16,6 +16,8 @@ import dan200.computercraft.shared.util.StringUtil; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class DiskDrivePeripheral implements IPeripheral { private final TileDiskDrive m_diskDrive; @@ -25,12 +27,14 @@ public class DiskDrivePeripheral implements IPeripheral m_diskDrive = diskDrive; } + @Nonnull @Override public String getType() { return "drive"; } + @Nonnull @Override public String[] getMethodNames() { @@ -50,7 +54,7 @@ public class DiskDrivePeripheral implements IPeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException { switch( method ) { @@ -174,13 +178,13 @@ public class DiskDrivePeripheral implements IPeripheral } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { m_diskDrive.mount( computer ); } @Override - public void detach( IComputerAccess computer ) + public void detach( @Nonnull IComputerAccess computer ) { m_diskDrive.unmount( computer ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java index 65f0be7da..7bad34116 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,20 +17,18 @@ import dan200.computercraft.shared.peripheral.common.BlockPeripheral; import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; import dan200.computercraft.shared.util.InventoryUtil; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.audio.Sound; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ITickable; import net.minecraft.util.*; import net.minecraft.util.math.*; import net.minecraft.util.text.*; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -120,7 +118,7 @@ public class TileDiskDrive extends TilePeripheralBase public EnumFacing getDirection() { IBlockState state = getBlockState(); - return (EnumFacing)state.getValue( BlockPeripheral.Properties.FACING ); + return state.getValue( BlockPeripheral.Properties.FACING ); } @Override @@ -145,6 +143,7 @@ public class TileDiskDrive extends TilePeripheralBase } } + @Nonnull @Override public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { @@ -276,10 +275,8 @@ public class TileDiskDrive extends TilePeripheralBase if( m_diskStack != null ) { Set computers = m_computers.keySet(); - Iterator it = computers.iterator(); - while( it.hasNext() ) + for( IComputerAccess computer : computers ) { - IComputerAccess computer = it.next(); unmountDisk( computer ); } } @@ -304,10 +301,8 @@ public class TileDiskDrive extends TilePeripheralBase if( m_diskStack != null ) { Set computers = m_computers.keySet(); - Iterator it = computers.iterator(); - while( it.hasNext() ) + for( IComputerAccess computer : computers ) { - IComputerAccess computer = it.next(); mountDisk( computer ); } } @@ -320,6 +315,7 @@ public class TileDiskDrive extends TilePeripheralBase return getLabel() != null; } + @Nonnull @Override public String getName() { @@ -334,6 +330,7 @@ public class TileDiskDrive extends TilePeripheralBase } } + @Nonnull @Override public ITextComponent getDisplayName() { @@ -354,23 +351,23 @@ public class TileDiskDrive extends TilePeripheralBase } @Override - public void openInventory( EntityPlayer player ) + public void openInventory( @Nonnull EntityPlayer player ) { } @Override - public void closeInventory( EntityPlayer player ) + public void closeInventory( @Nonnull EntityPlayer player ) { } @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) + public boolean isItemValidForSlot( int i, @Nonnull ItemStack itemstack) { return true; } @Override - public boolean isUseableByPlayer( EntityPlayer player ) + public boolean isUseableByPlayer( @Nonnull EntityPlayer player ) { return isUsable( player, false ); } @@ -613,7 +610,7 @@ public class TileDiskDrive extends TilePeripheralBase } @Override - public final void readDescription( NBTTagCompound nbttagcompound ) + public final void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); if( nbttagcompound.hasKey( "item" ) ) @@ -628,7 +625,7 @@ public class TileDiskDrive extends TilePeripheralBase } @Override - public void writeDescription( NBTTagCompound nbttagcompound ) + public void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.writeDescription( nbttagcompound ); if( m_diskStack != null ) @@ -659,7 +656,7 @@ public class TileDiskDrive extends TilePeripheralBase } @Override - public boolean shouldRefresh( World world, BlockPos pos, IBlockState oldState, IBlockState newState ) + public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState ) { return super.shouldRefresh( world, pos, oldState, newState ) || ComputerCraft.Blocks.peripheral.getPeripheralType( newState ) != PeripheralType.DiskDrive; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java index f5b4dcce9..4482e5ce2 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/BlockAdvancedModem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,18 +10,16 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.common.BlockPeripheralBase; import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; + +import javax.annotation.Nonnull; public class BlockAdvancedModem extends BlockPeripheralBase { @@ -42,16 +40,16 @@ public class BlockAdvancedModem extends BlockPeripheralBase ); } + @Nonnull @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] { - Properties.FACING, - Properties.ON - }); + return new BlockStateContainer(this, Properties.FACING, Properties.ON ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { IBlockState state = getDefaultState(); @@ -63,12 +61,14 @@ public class BlockAdvancedModem extends BlockPeripheralBase @Override public int getMetaFromState( IBlockState state ) { - EnumFacing dir = (EnumFacing) state.getValue( Properties.FACING ); + EnumFacing dir = state.getValue( Properties.FACING ); return dir.getIndex(); } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { int anim; EnumFacing dir; @@ -82,7 +82,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase else { anim = 0; - dir = (EnumFacing)state.getValue( Properties.FACING ); + dir = state.getValue( Properties.FACING ); } state = state.withProperty( Properties.FACING, dir ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/INetwork.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/INetwork.java index 91fbcb394..976037517 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/INetwork.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/INetwork.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,8 +11,8 @@ import net.minecraft.world.World; public interface INetwork { - public void addReceiver( IReceiver receiver ); - public void removeReceiver( IReceiver receiver ); - public void transmit( int channel, int replyChannel, Object payload, World world, Vec3d pos, double range, boolean interdimensional, Object senderObject ); - public boolean isWireless(); + void addReceiver( IReceiver receiver ); + void removeReceiver( IReceiver receiver ); + void transmit( int channel, int replyChannel, Object payload, World world, Vec3d pos, double range, boolean interdimensional, Object senderObject ); + boolean isWireless(); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/IReceiver.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/IReceiver.java index 869c1ea15..1de273ee0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/IReceiver.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/IReceiver.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,11 +10,11 @@ import net.minecraft.world.World; public interface IReceiver { - public int getChannel(); - public World getWorld(); - public Vec3d getWorldPosition(); - public boolean isInterdimensional(); - public double getReceiveRange(); - public void receiveSameDimension( int replyChannel, Object payload, double distance, Object senderObject ); - public void receiveDifferentDimension( int replyChannel, Object payload, Object senderObject ); + int getChannel(); + World getWorld(); + Vec3d getWorldPosition(); + boolean isInterdimensional(); + double getReceiveRange(); + void receiveSameDimension( int replyChannel, Object payload, double distance, Object senderObject ); + void receiveDifferentDimension( int replyChannel, Object payload, Object senderObject ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemPeripheral.java index c3c92781a..f3033e5f8 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,8 +13,8 @@ import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; public abstract class ModemPeripheral @@ -84,7 +84,7 @@ public abstract class ModemPeripheral private INetwork m_network; private IComputerAccess m_computer; - private Map m_channels; + private final Map m_channels; private boolean m_open; private boolean m_changed; @@ -106,10 +106,9 @@ public abstract class ModemPeripheral // Leave old network if( m_network != null ) { - Iterator it = m_channels.values().iterator(); - while( it.hasNext() ) + for( IReceiver iReceiver : m_channels.values() ) { - m_network.removeReceiver( it.next() ); + m_network.removeReceiver( iReceiver ); } } @@ -119,10 +118,9 @@ public abstract class ModemPeripheral // Join new network if( m_network != null ) { - Iterator it = m_channels.values().iterator(); - while( it.hasNext() ) + for( IReceiver iReceiver : m_channels.values() ) { - m_network.addReceiver( it.next() ); + m_network.addReceiver( iReceiver ); } } } @@ -203,12 +201,14 @@ public abstract class ModemPeripheral // IPeripheral implementation + @Nonnull @Override public String getType() { return "modem"; } + @Nonnull @Override public String[] getMethodNames() { @@ -237,7 +237,7 @@ public abstract class ModemPeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { @@ -312,10 +312,9 @@ public abstract class ModemPeripheral { if( m_network != null ) { - Iterator it = m_channels.values().iterator(); - while( it.hasNext() ) + for( IReceiver iReceiver : m_channels.values() ) { - m_network.removeReceiver( it.next() ); + m_network.removeReceiver( iReceiver ); } } m_channels.clear(); @@ -366,7 +365,7 @@ public abstract class ModemPeripheral } @Override - public synchronized void attach( IComputerAccess computer ) + public synchronized void attach( @Nonnull IComputerAccess computer ) { m_computer = computer; setNetwork( getNetwork() ); @@ -374,14 +373,13 @@ public abstract class ModemPeripheral } @Override - public synchronized void detach( IComputerAccess computer ) + public synchronized void detach( @Nonnull IComputerAccess computer ) { if( m_network != null ) { - Iterator it = m_channels.values().iterator(); - while( it.hasNext() ) + for( IReceiver iReceiver : m_channels.values() ) { - m_network.removeReceiver( it.next() ); + m_network.removeReceiver( iReceiver ); } m_channels.clear(); m_network = null; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java index c8c5dfb52..bf2eb5613 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -7,7 +7,6 @@ package dan200.computercraft.shared.peripheral.modem; import dan200.computercraft.api.peripheral.IPeripheral; -import dan200.computercraft.shared.peripheral.common.BlockPeripheral; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; @@ -64,7 +63,7 @@ public class TileAdvancedModem extends TileModemBase { // Wireless Modem IBlockState state = getBlockState(); - return (EnumFacing)state.getValue( BlockAdvancedModem.Properties.FACING ); + return state.getValue( BlockAdvancedModem.Properties.FACING ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java index fcfca3d17..19d3bba12 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -26,11 +26,14 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; -import net.minecraft.util.math.*; -import net.minecraft.util.text.*; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.io.File; import java.util.*; @@ -93,6 +96,7 @@ public class TileCable extends TileModemBase return new Vec3d( (double)pos.getX() + 0.5, (double)pos.getY() + 0.5, (double)pos.getZ() + 0.5 ); } + @Nonnull @Override public String[] getMethodNames() { @@ -117,7 +121,7 @@ public class TileCable extends TileModemBase } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { String[] methods = super.getMethodNames(); switch( method - methods.length ) @@ -129,10 +133,8 @@ public class TileCable extends TileModemBase { int idx = 1; Map table = new HashMap(); - Iterator it = m_entity.m_peripheralWrappersByName.keySet().iterator(); - while( it.hasNext() ) + for( String name : m_entity.m_peripheralWrappersByName.keySet() ) { - String name = it.next(); table.put( idx++, name ); } return new Object[] { table }; @@ -186,15 +188,13 @@ public class TileCable extends TileModemBase } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { super.attach( computer ); synchronized( m_entity.m_peripheralsByName ) { - Iterator it = m_entity.m_peripheralsByName.keySet().iterator(); - while( it.hasNext() ) + for (String periphName : m_entity.m_peripheralsByName.keySet()) { - String periphName = it.next(); IPeripheral peripheral = m_entity.m_peripheralsByName.get( periphName ); if( peripheral != null ) { @@ -205,14 +205,12 @@ public class TileCable extends TileModemBase } @Override - public synchronized void detach( IComputerAccess computer ) + public synchronized void detach( @Nonnull IComputerAccess computer ) { synchronized( m_entity.m_peripheralsByName ) { - Iterator it = m_entity.m_peripheralsByName.keySet().iterator(); - while( it.hasNext() ) + for (String periphName : m_entity.m_peripheralsByName.keySet()) { - String periphName = it.next(); m_entity.detachPeripheral( periphName ); } } @@ -235,13 +233,13 @@ public class TileCable extends TileModemBase // Members - private Map> m_receivers; - private Queue m_transmitQueue; + private final Map> m_receivers; + private final Queue m_transmitQueue; private boolean m_peripheralAccessAllowed; private int m_attachedPeripheralID; - private Map m_peripheralsByName; + private final Map m_peripheralsByName; private Map m_peripheralWrappersByName; private boolean m_peripheralsKnown; private boolean m_destroyed; @@ -279,7 +277,7 @@ public class TileCable extends TileModemBase public EnumFacing getDirection() { IBlockState state = getBlockState(); - BlockCableModemVariant modem = (BlockCableModemVariant)state.getValue( BlockCable.Properties.MODEM ); + BlockCableModemVariant modem = state.getValue( BlockCable.Properties.MODEM ); if( modem != BlockCableModemVariant.None ) { return modem.getFacing(); @@ -294,7 +292,7 @@ public class TileCable extends TileModemBase public void setDirection( EnumFacing dir ) { IBlockState state = getBlockState(); - BlockCableModemVariant modem = ( BlockCableModemVariant )state.getValue( BlockCable.Properties.MODEM ); + BlockCableModemVariant modem = state.getValue( BlockCable.Properties.MODEM ); if( modem != BlockCableModemVariant.None ) { setBlockState( state.withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.fromFacing( dir ) ) ); @@ -302,7 +300,7 @@ public class TileCable extends TileModemBase } @Override - public void getDroppedItems( List drops, boolean creative ) + public void getDroppedItems( @Nonnull List drops, boolean creative ) { if( !creative ) { @@ -409,6 +407,7 @@ public class TileCable extends TileModemBase return new AxisAlignedBB( xMin, yMin, zMin, xMax, yMax, zMax ); } + @Nonnull @Override public AxisAlignedBB getBounds() { @@ -434,7 +433,7 @@ public class TileCable extends TileModemBase } @Override - public void getCollisionBounds( List bounds ) + public void getCollisionBounds( @Nonnull List bounds ) { PeripheralType type = getPeripheralType(); if( type == PeripheralType.WiredModem || type == PeripheralType.WiredModemWithCable ) @@ -503,7 +502,8 @@ public class TileCable extends TileModemBase m_attachedPeripheralID = nbttagcompound.getInteger( "peripheralID" ); } - @Override + @Nonnull + @Override public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { // Write properties @@ -752,11 +752,9 @@ public class TileCable extends TileModemBase Set receivers = m_receivers.get( packet.channel ); if( receivers != null ) { - Iterator it = receivers.iterator(); - while( it.hasNext() ) + for( IReceiver receiver : receivers ) { - IReceiver receiver = it.next(); - receiver.receiveSameDimension( packet.replyChannel, packet.payload, (double)distanceTravelled, packet.senderObject ); + receiver.receiveSameDimension( packet.replyChannel, packet.payload, (double) distanceTravelled, packet.senderObject ); } } } @@ -828,25 +826,25 @@ public class TileCable extends TileModemBase // IComputerAccess implementation @Override - public String mount( String desiredLocation, IMount mount ) + public String mount( @Nonnull String desiredLocation, @Nonnull IMount mount ) { return m_computer.mount( desiredLocation, mount, m_name ); } @Override - public String mount( String desiredLocation, IMount mount, String driveName ) + public String mount( @Nonnull String desiredLocation, @Nonnull IMount mount, @Nonnull String driveName ) { return m_computer.mount( desiredLocation, mount, driveName ); } @Override - public String mountWritable( String desiredLocation, IWritableMount mount ) + public String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount ) { return m_computer.mountWritable( desiredLocation, mount, m_name ); } @Override - public String mountWritable( String desiredLocation, IWritableMount mount, String driveName ) + public String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount, @Nonnull String driveName ) { return m_computer.mountWritable( desiredLocation, mount, driveName ); } @@ -864,11 +862,12 @@ public class TileCable extends TileModemBase } @Override - public void queueEvent( String event, Object[] arguments ) + public void queueEvent( @Nonnull String event, Object[] arguments ) { m_computer.queueEvent( event, arguments ); } + @Nonnull @Override public String getAttachmentName() { @@ -915,10 +914,8 @@ public class TileCable extends TileModemBase } // Attach all the new peripherals - Iterator it2 = newPeripheralsByName.keySet().iterator(); - while( it2.hasNext() ) + for( String periphName : newPeripheralsByName.keySet() ) { - String periphName = it2.next(); if( !m_peripheralsByName.containsKey( periphName ) ) { IPeripheral peripheral = newPeripheralsByName.get( periphName ); @@ -989,9 +986,9 @@ public class TileCable extends TileModemBase // Generic network search stuff - private static interface ICableVisitor + private interface ICableVisitor { - public void visit( TileCable modem, int distance ); + void visit( TileCable modem, int distance ); } private static class SearchLoc diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileModemBase.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileModemBase.java index 0ac40d1e6..a865f383a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileModemBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileModemBase.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; +import javax.annotation.Nonnull; + public abstract class TileModemBase extends TilePeripheralBase { private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] { @@ -65,6 +67,7 @@ public abstract class TileModemBase extends TilePeripheralBase } } + @Nonnull @Override public AxisAlignedBB getBounds() { @@ -95,7 +98,7 @@ public abstract class TileModemBase extends TilePeripheralBase } @Override - public final void readDescription( NBTTagCompound nbttagcompound ) + public final void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); updateBlock(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java index e68788dd7..e20c0f228 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,6 +17,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class TileWirelessModem extends TileModemBase { // Statics @@ -67,7 +69,7 @@ public class TileWirelessModem extends TileModemBase { // Wireless Modem IBlockState state = getBlockState(); - switch( (BlockPeripheralVariant)state.getValue( BlockPeripheral.Properties.VARIANT ) ) + switch( state.getValue( BlockPeripheral.Properties.VARIANT ) ) { case WirelessModemDownOff: case WirelessModemDownOn: @@ -81,7 +83,7 @@ public class TileWirelessModem extends TileModemBase } default: { - return (EnumFacing)state.getValue( BlockPeripheral.Properties.FACING ); + return state.getValue( BlockPeripheral.Properties.FACING ); } } } @@ -120,7 +122,7 @@ public class TileWirelessModem extends TileModemBase } @Override - public boolean shouldRefresh( World world, BlockPos pos, IBlockState oldState, IBlockState newState ) + public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState ) { return super.shouldRefresh( world, pos, oldState, newState ) || ComputerCraft.Blocks.peripheral.getPeripheralType( newState ) != PeripheralType.WirelessModem; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java index ba1ed8e4a..ac61fa6d8 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessNetwork.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessNetwork.java index 24f462974..95417a8e0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessNetwork.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessNetwork.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -66,10 +66,8 @@ public class WirelessNetwork implements INetwork Set receivers = m_receivers.get( channel ); if( receivers != null ) { - Iterator it = receivers.iterator(); - while( it.hasNext() ) + for( IReceiver receiver : receivers ) { - IReceiver receiver = it.next(); tryTransmit( receiver, replyChannel, payload, world, pos, range, interdimensional, senderObject ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorPeripheral.java index 5eeec0de0..1fec5c424 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorPeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -16,6 +16,8 @@ import org.apache.commons.lang3.ArrayUtils; import java.util.HashMap; +import javax.annotation.Nonnull; + public class MonitorPeripheral implements IPeripheral { private final TileMonitor m_monitor; @@ -27,12 +29,14 @@ public class MonitorPeripheral implements IPeripheral // IPeripheral implementation + @Nonnull @Override public String getType() { return "monitor"; } + @Nonnull @Override public String[] getMethodNames() { @@ -65,7 +69,7 @@ public class MonitorPeripheral implements IPeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object args[] ) throws LuaException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object args[] ) throws LuaException { switch( method ) { @@ -115,7 +119,7 @@ public class MonitorPeripheral implements IPeripheral throw new LuaException( "Expected boolean" ); } Terminal terminal = m_monitor.getTerminal().getTerminal(); - terminal.setCursorBlink( ((Boolean)args[0]).booleanValue() ); + terminal.setCursorBlink( (Boolean) args[ 0 ] ); return null; } case 4: @@ -273,13 +277,13 @@ public class MonitorPeripheral implements IPeripheral } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { m_monitor.addComputer( computer ); } @Override - public void detach( IComputerAccess computer ) + public void detach( @Nonnull IComputerAccess computer ) { m_monitor.removeComputer( computer ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index 59c33035f..6f228da88 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -25,6 +25,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.HashSet; import java.util.Set; @@ -111,6 +112,7 @@ public class TileMonitor extends TilePeripheralBase return false; } + @Nonnull @Override public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound ) { @@ -206,7 +208,7 @@ public class TileMonitor extends TilePeripheralBase // Networking stuff @Override - public void writeDescription( NBTTagCompound nbttagcompound ) + public void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.writeDescription( nbttagcompound ); nbttagcompound.setInteger( "xIndex", m_xIndex ); @@ -219,7 +221,7 @@ public class TileMonitor extends TilePeripheralBase } @Override - public final void readDescription( NBTTagCompound nbttagcompound ) + public final void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); @@ -815,6 +817,7 @@ public class TileMonitor extends TilePeripheralBase } } + @Nonnull @Override public AxisAlignedBB getRenderBoundingBox() { @@ -840,7 +843,7 @@ public class TileMonitor extends TilePeripheralBase } @Override - public boolean shouldRefresh( World world, BlockPos pos, IBlockState oldState, IBlockState newState ) + public boolean shouldRefresh( World world, BlockPos pos, @Nonnull IBlockState oldState, @Nonnull IBlockState newState ) { if( super.shouldRefresh( world, pos, oldState, newState ) ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java index 52c6f2cc6..c64f5abdb 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class ContainerPrinter extends Container { private TilePrinter m_printer; @@ -75,12 +77,11 @@ public class ContainerPrinter extends Container if( !m_printer.getWorld().isRemote ) { boolean printing = m_printer.isPrinting(); - for (int i=0; i 0 ) - { - return true; - } - return false; + ItemStack inkStack = m_inventory[ 0 ]; + return inkStack != null && isInk( inkStack ) && getPaperLevel() > 0; } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java b/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java index 8ef404c0f..6b8576db0 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java +++ b/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -19,6 +19,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class PocketAPI implements ILuaAPI { private final PocketServerComputer m_computer; @@ -51,6 +53,7 @@ public class PocketAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -61,7 +64,7 @@ public class PocketAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { 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 0199f92b1..29afeebaf 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -35,6 +35,7 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import javax.annotation.Nonnull; import java.util.List; public class ItemPocketComputer extends Item implements IComputerItem, IMedia @@ -79,7 +80,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } @Override - public void getSubItems( Item itemID, CreativeTabs tabs, List list ) + public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, List list ) { getSubItems( list, ComputerFamily.Normal ); getSubItems( list, ComputerFamily.Advanced ); @@ -151,8 +152,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } } + @Nonnull @Override - public ActionResult onItemRightClick( ItemStack stack, World world, EntityPlayer player, EnumHand hand ) + public ActionResult onItemRightClick( @Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand ) { if( !world.isRemote ) { @@ -176,6 +178,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia return new ActionResult( EnumActionResult.SUCCESS, stack ); } + @Nonnull @Override public String getUnlocalizedName( ItemStack stack ) { @@ -193,8 +196,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } } + @Nonnull @Override - public String getItemStackDisplayName( ItemStack stack ) + public String getItemStackDisplayName( @Nonnull ItemStack stack ) { String baseString = getUnlocalizedName( stack ); IPocketUpgrade upgrade = getUpgrade( stack ); @@ -212,7 +216,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } @Override - public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean debug ) + public void addInformation( ItemStack stack, EntityPlayer player, List list, boolean debug ) { if( debug ) { @@ -331,7 +335,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } @Override - public String getLabel( ItemStack stack ) + public String getLabel( @Nonnull ItemStack stack ) { if( stack.hasDisplayName() ) { @@ -361,7 +365,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia // IMedia @Override - public boolean setLabel( ItemStack stack, String label ) + public boolean setLabel( @Nonnull ItemStack stack, String label ) { if( label != null ) { @@ -375,19 +379,19 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia } @Override - public String getAudioTitle( ItemStack stack ) + public String getAudioTitle( @Nonnull ItemStack stack ) { return null; } @Override - public SoundEvent getAudio( ItemStack stack ) + public SoundEvent getAudio( @Nonnull ItemStack stack ) { return null; } @Override - public IMount createDataMount( ItemStack stack, World world ) + public IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world ) { ServerComputer computer = createServerComputer( world, null, null, stack ); if( computer != null ) diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java b/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java index 2fa08d038..1f7424b14 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/PocketComputerItemFactory.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModemPeripheral.java b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModemPeripheral.java index 07371dc93..69f100edc 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModemPeripheral.java @@ -5,7 +5,7 @@ import dan200.computercraft.shared.peripheral.modem.WirelessModemPeripheral; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -52,10 +52,6 @@ public class PocketModemPeripheral extends WirelessModemPeripheral @Override public boolean equals( IPeripheral other ) { - if( other instanceof PocketModemPeripheral ) - { - return true; - } - return false; + return other instanceof PocketModemPeripheral; } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java index 7eeefef94..5f2faa764 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -16,6 +16,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class PocketComputerUpgradeRecipe implements IRecipe { public PocketComputerUpgradeRecipe() @@ -35,13 +37,13 @@ public class PocketComputerUpgradeRecipe implements IRecipe } @Override - public boolean matches( InventoryCrafting inventory, World world ) + public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world ) { return (getCraftingResult( inventory ) != null); } @Override - public ItemStack getCraftingResult( InventoryCrafting inventory ) + public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) { // Scan the grid for a pocket computer ItemStack computer = null; @@ -112,8 +114,9 @@ public class PocketComputerUpgradeRecipe implements IRecipe return PocketComputerItemFactory.create( computerID, label, family, upgrade ); } + @Nonnull @Override - public ItemStack[] getRemainingItems( InventoryCrafting inventoryCrafting ) + public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) { ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ]; for (int i = 0; i < results.length; ++i) diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index cdad31e62..1702855f9 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,7 +8,6 @@ package dan200.computercraft.shared.proxy; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleUpgrade; -import dan200.computercraft.api.turtle.TurtleUpgradeType; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.ComputerItemFactory; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; @@ -25,6 +24,7 @@ import dan200.computercraft.shared.turtle.upgrades.*; import dan200.computercraft.shared.util.IEntityDropConsumer; import dan200.computercraft.shared.util.ImpostorRecipe; import dan200.computercraft.shared.util.InventoryUtil; +import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; @@ -32,6 +32,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingDropsEvent; @@ -111,7 +112,6 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy } catch( Exception e ) { - continue; } } return null; @@ -177,23 +177,23 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy { boolean captured = ObfuscationReflectionHelper.getPrivateValue( Entity.class, - entity, + entity, "captureDrops" - ).booleanValue(); + ); if( !captured ) { ObfuscationReflectionHelper.setPrivateValue( - Entity.class, - entity, - new Boolean( true ), - "captureDrops" + Entity.class, + entity, + Boolean.TRUE, + "captureDrops" ); ArrayList items = ObfuscationReflectionHelper.getPrivateValue( - Entity.class, - entity, - "capturedDrops" + Entity.class, + entity, + "capturedDrops" ); if( items == null || items.size() == 0 ) @@ -219,15 +219,15 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy { ObfuscationReflectionHelper.setPrivateValue( Entity.class, - entity, - new Boolean( false ), + entity, + Boolean.FALSE, "captureDrops" ); ArrayList items = ObfuscationReflectionHelper.getPrivateValue( - Entity.class, - entity, - "capturedDrops" + Entity.class, + entity, + "capturedDrops" ); if( items != null ) @@ -276,7 +276,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy if( isUpgradeVanilla( upgrade ) ) { // Add fake recipes to fool NEI - List recipeList = CraftingManager.getInstance().getRecipeList(); + List recipeList = CraftingManager.getInstance().getRecipeList(); ItemStack craftingItem = upgrade.getCraftingItem(); // A turtle just containing this upgrade @@ -326,14 +326,14 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy // Blocks // Turtle ComputerCraft.Blocks.turtle = BlockTurtle.createTurtleBlock(); - GameRegistry.registerBlock( ComputerCraft.Blocks.turtle, ItemTurtleLegacy.class, "CC-Turtle" ); + registerBlock( ComputerCraft.Blocks.turtle, new ItemTurtleLegacy(ComputerCraft.Blocks.turtle), "CC-Turtle" ); ComputerCraft.Blocks.turtleExpanded = BlockTurtle.createTurtleBlock(); - GameRegistry.registerBlock( ComputerCraft.Blocks.turtleExpanded, ItemTurtleNormal.class, "CC-TurtleExpanded" ); + registerBlock( ComputerCraft.Blocks.turtleExpanded, new ItemTurtleNormal( ComputerCraft.Blocks.turtleExpanded ), "CC-TurtleExpanded" ); // Advanced Turtle ComputerCraft.Blocks.turtleAdvanced = BlockTurtle.createTurtleBlock(); - GameRegistry.registerBlock( ComputerCraft.Blocks.turtleAdvanced, ItemTurtleAdvanced.class, "CC-TurtleAdvanced" ); + registerBlock( ComputerCraft.Blocks.turtleAdvanced, new ItemTurtleAdvanced( ComputerCraft.Blocks.turtleAdvanced ), "CC-TurtleAdvanced" ); // Recipe types RecipeSorter.register( "computercraft:turtle", TurtleRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); @@ -403,6 +403,11 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy registerTurtleUpgradeInternal( ComputerCraft.Upgrades.advancedModem ); } + private void registerBlock( Block block, Item item, String name) { + GameRegistry.register( block.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); + GameRegistry.register( item.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); + } + private void registerTileEntities() { // TileEntities @@ -437,10 +442,8 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy if( consumer != null ) { // All checks have passed, lets dispatch the drops - Iterator it = drops.iterator(); - while( it.hasNext() ) + for(EntityItem entityItem : drops) { - EntityItem entityItem = (EntityItem)it.next(); consumer.consumeDrop( entity, entityItem.getEntityItem() ); } drops.clear(); diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 369d8f94e..b3a780c0e 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -9,6 +9,7 @@ package dan200.computercraft.shared.proxy; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.api.pocket.IPocketUpgrade; +import dan200.computercraft.core.computer.Computer; import dan200.computercraft.core.computer.MainThread; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; import dan200.computercraft.shared.common.TileGeneric; @@ -51,6 +52,7 @@ 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.*; +import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -61,10 +63,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumHand; import net.minecraft.util.IThreadListener; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -212,7 +215,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy if (tileEntity != null && tileEntity instanceof TileGeneric) { TileGeneric generic = (TileGeneric) tileEntity; - Packet description = generic.getUpdatePacket(); + SPacketUpdateTileEntity description = generic.getUpdatePacket(); if (description != null) { ((EntityPlayerMP) player).connection.sendPacket( description ); @@ -231,43 +234,43 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy // Blocks // Computer ComputerCraft.Blocks.computer = new BlockComputer(); - GameRegistry.registerBlock( ComputerCraft.Blocks.computer, ItemComputer.class, "CC-Computer" ); + registerBlock( ComputerCraft.Blocks.computer, new ItemComputer( ComputerCraft.Blocks.computer ), "CC-Computer" ); // Peripheral ComputerCraft.Blocks.peripheral = new BlockPeripheral(); - GameRegistry.registerBlock( ComputerCraft.Blocks.peripheral, ItemPeripheral.class, "CC-Peripheral" ); + registerBlock( ComputerCraft.Blocks.peripheral, new ItemPeripheral( ComputerCraft.Blocks.peripheral ), "CC-Peripheral" ); // Cable ComputerCraft.Blocks.cable = new BlockCable(); - GameRegistry.registerBlock( ComputerCraft.Blocks.cable, ItemCable.class, "CC-Cable" ); + registerBlock( ComputerCraft.Blocks.cable, new ItemCable( ComputerCraft.Blocks.cable ), "CC-Cable" ); // Command Computer ComputerCraft.Blocks.commandComputer = new BlockCommandComputer(); - GameRegistry.registerBlock( ComputerCraft.Blocks.commandComputer, ItemCommandComputer.class, "command_computer" ); + registerBlock( ComputerCraft.Blocks.commandComputer, new ItemCommandComputer( ComputerCraft.Blocks.commandComputer ), "command_computer" ); // Command Computer ComputerCraft.Blocks.advancedModem = new BlockAdvancedModem(); - GameRegistry.registerBlock( ComputerCraft.Blocks.advancedModem, ItemAdvancedModem.class, "advanced_modem" ); + registerBlock( ComputerCraft.Blocks.advancedModem, new ItemAdvancedModem( ComputerCraft.Blocks.advancedModem ), "advanced_modem" ); // Items // Floppy Disk ComputerCraft.Items.disk = new ItemDiskLegacy(); - GameRegistry.registerItem( ComputerCraft.Items.disk, "disk" ); + GameRegistry.register( ComputerCraft.Items.disk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "disk" ) ) ); ComputerCraft.Items.diskExpanded = new ItemDiskExpanded(); - GameRegistry.registerItem( ComputerCraft.Items.diskExpanded, "diskExpanded" ); + GameRegistry.register( ComputerCraft.Items.diskExpanded.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "diskExpanded" ) ) ); // Treasure Disk ComputerCraft.Items.treasureDisk = new ItemTreasureDisk(); - GameRegistry.registerItem( ComputerCraft.Items.treasureDisk, "treasureDisk" ); + GameRegistry.register( ComputerCraft.Items.treasureDisk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "treasureDisk" ) ) ); // Printout ComputerCraft.Items.printout = new ItemPrintout(); - GameRegistry.registerItem( ComputerCraft.Items.printout, "printout" ); + GameRegistry.register( ComputerCraft.Items.printout.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "printout" ) ) ); // Pocket computer ComputerCraft.Items.pocketComputer = new ItemPocketComputer(); - GameRegistry.registerItem( ComputerCraft.Items.pocketComputer, "pocketComputer" ); + GameRegistry.register( ComputerCraft.Items.pocketComputer.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "pocketComputer" ) ) ); // Recipe types RecipeSorter.register( "computercraft:impostor", ImpostorRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); @@ -376,7 +379,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy ItemStack paper = new ItemStack( Items.PAPER, 1 ); ItemStack redstone = new ItemStack( Items.REDSTONE, 1 ); ItemStack basicDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( basicDisk, new Object[]{redstone, paper} ) ); + GameRegistry.addRecipe( new ImpostorShapelessRecipe( basicDisk, new ItemStack[]{redstone, paper} ) ); for (int colour = 0; colour < 16; ++colour) { @@ -387,12 +390,12 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy if (colour != otherColour) { ItemStack otherDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[]{ + GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new ItemStack[]{ otherDisk, dye } ) ); } } - GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new Object[]{ + GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new ItemStack[]{ redstone, paper, dye } ) ); } @@ -406,10 +409,10 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy // Impostor Printout recipes (to fool NEI) ItemStack string = new ItemStack( Items.STRING, 1, 0 ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( multiplePrintout, new Object[]{singlePrintout, singlePrintout, string} ) ); + GameRegistry.addRecipe( new ImpostorShapelessRecipe( multiplePrintout, new ItemStack[]{singlePrintout, singlePrintout, string} ) ); ItemStack leather = new ItemStack( Items.LEATHER, 1, 0 ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new Object[]{leather, singlePrintout, string} ) ); + GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new ItemStack[]{leather, singlePrintout, string} ) ); // Pocket Computer ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, ComputerFamily.Normal, null ); @@ -470,6 +473,11 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy GameRegistry.addShapelessRecipe( cloudyHead, monitor, new ItemStack( Items.SKULL, 1, 1 ) ); } + private void registerBlock( Block block, Item item, String name) { + GameRegistry.register( block.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); + GameRegistry.register( item.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); + } + private void registerTileEntities() { // Tile Entities @@ -673,7 +681,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy @SubscribeEvent public void onConfigChanged( ConfigChangedEvent.OnConfigChangedEvent event) { - if( event.getModID().equals( "ComputerCraft" ) ) + if( event.getModID().equals( ComputerCraft.MOD_ID ) ) { ComputerCraft.syncConfig(); } diff --git a/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java b/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java index 6c6b3ca25..af0b1edf8 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,15 +15,15 @@ import java.util.List; public interface ICCTurtleProxy { - public void preInit(); - public void init(); + void preInit(); + void init(); - public void registerTurtleUpgrade( ITurtleUpgrade upgrade ); - public ITurtleUpgrade getTurtleUpgrade( String id ); - public ITurtleUpgrade getTurtleUpgrade( int legacyId ); - public ITurtleUpgrade getTurtleUpgrade( ItemStack item ); - public void addAllUpgradedTurtles( List list ); + void registerTurtleUpgrade( ITurtleUpgrade upgrade ); + ITurtleUpgrade getTurtleUpgrade( String id ); + ITurtleUpgrade getTurtleUpgrade( int legacyId ); + ITurtleUpgrade getTurtleUpgrade( ItemStack item ); + void addAllUpgradedTurtles( List list ); - public void setEntityDropConsumer( Entity entity, IEntityDropConsumer consumer ); - public void clearEntityDropConsumer( Entity entity ); + void setEntityDropConsumer( Entity entity, IEntityDropConsumer consumer ); + void clearEntityDropConsumer( Entity entity ); } diff --git a/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java b/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java index 31101b609..fc07c2e01 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java +++ b/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -23,25 +23,25 @@ import java.io.File; public interface IComputerCraftProxy { - public void preInit(); - public void init(); - public boolean isClient(); + void preInit(); + void init(); + boolean isClient(); - public boolean getGlobalCursorBlink(); - public long getRenderFrame(); - public void deleteDisplayLists( int list, int range ); - public Object getFixedWidthFontRenderer(); + boolean getGlobalCursorBlink(); + long getRenderFrame(); + void deleteDisplayLists( int list, int range ); + Object getFixedWidthFontRenderer(); - public String getRecordInfo( ItemStack item ); - public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos ); + String getRecordInfo( ItemStack item ); + void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos ); - public Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive ); - public Object getComputerGUI( TileComputer computer ); - public Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer ); - public Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle ); - public abstract Object getPrintoutGUI( EntityPlayer player, EnumHand hand ); - public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand ); + Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive ); + Object getComputerGUI( TileComputer computer ); + Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer ); + Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle ); + Object getPrintoutGUI( EntityPlayer player, EnumHand hand ); + Object getPocketComputerGUI( EntityPlayer player, EnumHand hand ); - public File getWorldDir( World world ); - public void handlePacket( ComputerCraftPacket packet, EntityPlayer player ); + File getWorldDir( World world ); + void handlePacket( ComputerCraftPacket packet, EntityPlayer player ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java index 0fd7f62a7..0af561f25 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java +++ b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,8 +17,8 @@ import dan200.computercraft.core.apis.ILuaAPI; import dan200.computercraft.shared.turtle.core.*; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; +import javax.annotation.Nonnull; import java.util.HashMap; import java.util.Map; @@ -58,6 +58,7 @@ public class TurtleAPI implements ILuaAPI { } + @Nonnull @Override public String[] getMethodNames() { @@ -181,7 +182,7 @@ public class TurtleAPI implements ILuaAPI } @Override - public Object[] callMethod( ILuaContext context, int method, Object[] args ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException, InterruptedException { switch( method ) { @@ -478,7 +479,7 @@ public class TurtleAPI implements ILuaAPI if( stack != null && stack.stackSize > 0 ) { Item item = stack.getItem(); - String name = ((ResourceLocation)Item.REGISTRY.getNameForObject( item )).toString(); + String name = Item.REGISTRY.getNameForObject( item ).toString(); int damage = stack.getItemDamage(); int count = stack.stackSize; diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java index 87dc2ba5e..ac1a68cb9 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -8,14 +8,11 @@ package dan200.computercraft.shared.turtle.blocks; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.blocks.BlockComputerBase; -import dan200.computercraft.shared.computer.blocks.TileCommandComputer; import dan200.computercraft.shared.computer.blocks.TileComputerBase; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.util.DirectionUtil; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; -import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -27,6 +24,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class BlockTurtle extends BlockComputerBase { // Statics @@ -54,31 +53,38 @@ public class BlockTurtle extends BlockComputerBase ); } + @Nonnull @Override + @Deprecated public EnumBlockRenderType getRenderType( IBlockState state ) { return EnumBlockRenderType.INVISIBLE; } @Override + @Deprecated public boolean isOpaqueCube( IBlockState state ) { return false; } @Override + @Deprecated public boolean isFullCube( IBlockState state ) { return false; } + @Nonnull @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, Properties.FACING ); } + @Nonnull @Override + @Deprecated public IBlockState getStateFromMeta( int meta ) { return getDefaultState(); @@ -90,8 +96,10 @@ public class BlockTurtle extends BlockComputerBase return 0; } + @Nonnull @Override - public IBlockState getActualState( IBlockState state, IBlockAccess world, BlockPos pos ) + @Deprecated + public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos ) { return state.withProperty( Properties.FACING, getDirection( world, pos ) ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java index 2f7907d48..e3add1579 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/ITurtleTile.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -17,12 +17,12 @@ import net.minecraft.util.math.Vec3d; public interface ITurtleTile extends IComputerTile, IDirectionalTile { - public Colour getColour(); - public ResourceLocation getOverlay(); - public ITurtleUpgrade getUpgrade( TurtleSide side ); - public ITurtleAccess getAccess(); + Colour getColour(); + ResourceLocation getOverlay(); + ITurtleUpgrade getUpgrade( TurtleSide side ); + ITurtleAccess getAccess(); - public Vec3d getRenderOffset( float f ); - public float getRenderYaw( float f ); - public float getToolRenderAngle( TurtleSide side, float f ); + Vec3d getRenderOffset( float f ); + float getRenderYaw( float f ); + float getToolRenderAngle( TurtleSide side, float f ); } 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 f37afecda..09c80c0b9 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; -import dan200.computercraft.api.turtle.TurtleUpgradeType; import dan200.computercraft.shared.computer.blocks.TileComputerBase; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.IComputer; @@ -18,7 +17,10 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.turtle.apis.TurtleAPI; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; -import dan200.computercraft.shared.util.*; +import dan200.computercraft.shared.util.Colour; +import dan200.computercraft.shared.util.InventoryUtil; +import dan200.computercraft.shared.util.RedstoneUtil; +import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -28,12 +30,19 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; import net.minecraft.util.ITickable; -import net.minecraft.util.*; -import net.minecraft.util.math.*; -import net.minecraft.util.text.*; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.common.util.Constants; +import javax.annotation.Nonnull; import java.util.List; public class TileTurtle extends TileComputerBase @@ -144,7 +153,7 @@ public class TileTurtle extends TileComputerBase } @Override - public void getDroppedItems( List drops, boolean creative ) + public void getDroppedItems( @Nonnull List drops, boolean creative ) { IComputer computer = getComputer(); if( !creative || (computer != null && computer.getLabel() != null) ) @@ -196,7 +205,8 @@ public class TileTurtle extends TileComputerBase m_brain.setDyeColour( -1 ); if( !player.capabilities.isCreativeMode ) { - currentItem.setItem( Items.BUCKET ); + player.setHeldItem( EnumHand.MAIN_HAND, new ItemStack( Items.BUCKET ) ); + player.inventory.markDirty(); } } } @@ -235,14 +245,11 @@ public class TileTurtle extends TileComputerBase } else { - if( exploder != null && ( exploder instanceof EntityLivingBase || exploder instanceof EntityFireball ) ) - { - return true; - } - return false; + return exploder != null && (exploder instanceof EntityLivingBase || exploder instanceof EntityFireball); } } + @Nonnull @Override public AxisAlignedBB getBounds() { @@ -293,7 +300,7 @@ public class TileTurtle extends TileComputerBase } @Override - public void onNeighbourTileEntityChange(BlockPos neighbour) + public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour) { if ( m_moveState == MoveState.NOT_MOVED ) { @@ -342,6 +349,7 @@ public class TileTurtle extends TileComputerBase m_brain.readFromNBT( nbttagcompound ); } + @Nonnull @Override public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound ) { @@ -539,6 +547,7 @@ public class TileTurtle extends TileComputerBase } } + @Nonnull @Override public String getName() { @@ -569,6 +578,7 @@ public class TileTurtle extends TileComputerBase return false; } + @Nonnull @Override public ITextComponent getDisplayName() { @@ -589,17 +599,17 @@ public class TileTurtle extends TileComputerBase } @Override - public void openInventory( EntityPlayer player ) + public void openInventory( @Nonnull EntityPlayer player ) { } @Override - public void closeInventory( EntityPlayer player ) + public void closeInventory( @Nonnull EntityPlayer player ) { } @Override - public boolean isItemValidForSlot( int slot, ItemStack stack ) + public boolean isItemValidForSlot( int slot, @Nonnull ItemStack stack ) { return true; } @@ -625,7 +635,7 @@ public class TileTurtle extends TileComputerBase } @Override - public boolean isUseableByPlayer( EntityPlayer player ) + public boolean isUseableByPlayer( @Nonnull EntityPlayer player ) { return isUsable( player, false ); } @@ -666,14 +676,14 @@ public class TileTurtle extends TileComputerBase // Networking stuff @Override - public void writeDescription( NBTTagCompound nbttagcompound ) + public void writeDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.writeDescription( nbttagcompound ); m_brain.writeDescription( nbttagcompound ); } @Override - public void readDescription( NBTTagCompound nbttagcompound ) + public void readDescription( @Nonnull NBTTagCompound nbttagcompound ) { super.readDescription( nbttagcompound ); m_brain.readDescription( nbttagcompound ); @@ -691,11 +701,7 @@ public class TileTurtle extends TileComputerBase case 5: upgrade = getUpgrade( TurtleSide.Left ); break; default: return false; } - if( upgrade != null && upgrade.getType().isPeripheral() ) - { - return true; - } - return false; + return upgrade != null && upgrade.getType().isPeripheral(); } public void transferStateFrom( TileTurtle copy ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleAdvanced.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleAdvanced.java index 9332a2521..9fba1cdbd 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleAdvanced.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleAdvanced.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleExpanded.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleExpanded.java index 8218bffe0..0a83052f4 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleExpanded.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtleExpanded.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java b/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java index e38de691a..da7b21363 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java b/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java index 3df018026..aaf6a1601 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurnDirection.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurnDirection.java index ef04e25b8..edf8e4b6b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurnDirection.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurnDirection.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleAttackCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleAttackCommand.java index 361dab384..94e0329eb 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleAttackCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleAttackCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com 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 6f9071cb7..594a51cc3 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -26,12 +26,16 @@ import net.minecraft.entity.Entity; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; -import net.minecraft.util.math.*; -import net.minecraft.util.text.*; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; +import javax.annotation.Nonnull; import java.lang.ref.WeakReference; import java.util.*; @@ -334,11 +338,11 @@ public class TurtleBrain implements ITurtleAccess // Write NBT if( m_upgradeNBTData.containsKey( TurtleSide.Left ) ) { - nbttagcompound.setTag( "leftUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Left ).copy() ); + nbttagcompound.setTag( "leftUpgradeNBT", getUpgradeNBTData( TurtleSide.Left ).copy() ); } if( m_upgradeNBTData.containsKey( TurtleSide.Right ) ) { - nbttagcompound.setTag( "rightUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Right ).copy() ); + nbttagcompound.setTag( "rightUpgradeNBT", getUpgradeNBTData( TurtleSide.Right ).copy() ); } return nbttagcompound; @@ -370,11 +374,11 @@ public class TurtleBrain implements ITurtleAccess // NBT if( m_upgradeNBTData.containsKey( TurtleSide.Left ) ) { - nbttagcompound.setTag( "leftUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Left ).copy() ); + nbttagcompound.setTag( "leftUpgradeNBT", getUpgradeNBTData( TurtleSide.Left ).copy() ); } if( m_upgradeNBTData.containsKey( TurtleSide.Right ) ) { - nbttagcompound.setTag( "rightUpgradeNBT", (NBTTagCompound) getUpgradeNBTData( TurtleSide.Right ).copy() ); + nbttagcompound.setTag( "rightUpgradeNBT", getUpgradeNBTData( TurtleSide.Right ).copy() ); } // Colour @@ -473,12 +477,14 @@ public class TurtleBrain implements ITurtleAccess m_fuelLevel = nbttagcompound.getInteger( "fuelLevel" ); } + @Nonnull @Override public World getWorld() { return m_owner.getWorld(); } + @Nonnull @Override public BlockPos getPosition() { @@ -486,7 +492,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public boolean teleportTo( World world, BlockPos pos ) + public boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos ) { if( world.isRemote || getWorld().isRemote ) { @@ -555,6 +561,7 @@ public class TurtleBrain implements ITurtleAccess return false; } + @Nonnull @Override public Vec3d getVisualPosition( float f ) { @@ -570,8 +577,7 @@ public class TurtleBrain implements ITurtleAccess @Override public float getVisualYaw( float f ) { - float forward = DirectionUtil.toYawAngle( getDirection() ); - float yaw = forward; + float yaw = DirectionUtil.toYawAngle( getDirection() ); switch( m_animation ) { case TurnLeft: @@ -596,6 +602,7 @@ public class TurtleBrain implements ITurtleAccess return yaw; } + @Nonnull @Override public EnumFacing getDirection() { @@ -603,7 +610,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public void setDirection( EnumFacing dir ) + public void setDirection( @Nonnull EnumFacing dir ) { if( dir.getAxis() == EnumFacing.Axis.Y ) { @@ -635,6 +642,7 @@ public class TurtleBrain implements ITurtleAccess } } + @Nonnull @Override public IInventory getInventory() { @@ -711,8 +719,9 @@ public class TurtleBrain implements ITurtleAccess return m_commandsIssued; } + @Nonnull @Override - public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException + public Object[] executeCommand( @Nonnull ILuaContext context, @Nonnull ITurtleCommand command ) throws LuaException, InterruptedException { if( getWorld().isRemote ) { @@ -731,10 +740,7 @@ public class TurtleBrain implements ITurtleAccess if( ( (Number) response[ 1 ] ).intValue() == commandID ) { Object[] returnValues = new Object[ response.length - 2 ]; - for( int i = 0; i < returnValues.length; ++i ) - { - returnValues[ i ] = response[ i + 2 ]; - } + System.arraycopy( response, 2, returnValues, 0, returnValues.length ); return returnValues; } } @@ -742,7 +748,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public void playAnimation( TurtleAnimation animation ) + public void playAnimation( @Nonnull TurtleAnimation animation ) { if( getWorld().isRemote ) { @@ -798,7 +804,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public ITurtleUpgrade getUpgrade( TurtleSide side ) + public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side ) { if( m_upgrades.containsKey( side ) ) { @@ -808,7 +814,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ) + public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade ) { // Remove old upgrade if( m_upgrades.containsKey( side ) ) @@ -846,7 +852,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public IPeripheral getPeripheral( TurtleSide side ) + public IPeripheral getPeripheral( @Nonnull TurtleSide side ) { if( m_peripherals.containsKey( side ) ) { @@ -855,6 +861,7 @@ public class TurtleBrain implements ITurtleAccess return null; } + @Nonnull @Override public NBTTagCompound getUpgradeNBTData( TurtleSide side ) { @@ -866,7 +873,7 @@ public class TurtleBrain implements ITurtleAccess } @Override - public void updateUpgradeNBTData( TurtleSide side ) + public void updateUpgradeNBTData( @Nonnull TurtleSide side ) { m_owner.updateBlock(); } @@ -1025,10 +1032,7 @@ public class TurtleBrain implements ITurtleAccess Object[] arguments = new Object[ results.length + 2 ]; arguments[0] = callbackID; arguments[1] = true; - for( int i=0; i list = world.getEntitiesWithinAABBExcludingEntity( null, aabb ); if( !list.isEmpty() ) { double pushStep = 1.0f / (float) ANIM_DURATION; double pushStepX = (double) moveDir.getFrontOffsetX() * pushStep; double pushStepY = (double) moveDir.getFrontOffsetY() * pushStep; double pushStepZ = (double) moveDir.getFrontOffsetZ() * pushStep; - for( int i = 0; i < list.size(); ++i ) + for (Entity entity : list) { - Entity entity = (Entity) list.get( i ); - entity.moveEntity( - pushStepX, pushStepY, pushStepZ - ); + entity.moveEntity( pushStepX, pushStepY, pushStepZ ); } } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCheckRedstoneCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCheckRedstoneCommand.java index 94e5f9e1b..c864f4307 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCheckRedstoneCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCheckRedstoneCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,6 +11,8 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.core.apis.IAPIEnvironment; +import javax.annotation.Nonnull; + public class TurtleCheckRedstoneCommand implements ITurtleCommand { private final IAPIEnvironment m_environment; @@ -22,8 +24,9 @@ public class TurtleCheckRedstoneCommand implements ITurtleCommand m_direction = direction; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Do the checking int redstoneSide; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCommandQueueEntry.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCommandQueueEntry.java index a25081308..35ece2f6b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCommandQueueEntry.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCommandQueueEntry.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java index a68b66600..ef7309697 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -19,8 +19,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.ReflectionHelper; +import javax.annotation.Nonnull; import java.lang.reflect.Method; -import java.util.Iterator; public class TurtleCompareCommand implements ITurtleCommand { @@ -31,8 +31,9 @@ public class TurtleCompareCommand implements ITurtleCommand m_direction = direction; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction EnumFacing direction = m_direction.toWorldDir( turtle ); @@ -82,10 +83,8 @@ public class TurtleCompareCommand implements ITurtleCommand java.util.List drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 ); if( drops != null && drops.size() > 0 ) { - Iterator it = drops.iterator(); - while( it.hasNext() ) + for( ItemStack drop : drops ) { - ItemStack drop = it.next(); if( drop.getItem() == Item.getItemFromBlock( lookAtBlock ) ) { lookAtStack = drop; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java index 3c85c3607..fe93a0db4 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.shared.util.InventoryUtil; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class TurtleCompareToCommand implements ITurtleCommand { private final int m_slot; @@ -21,8 +23,9 @@ public class TurtleCompareToCommand implements ITurtleCommand m_slot = slot; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); ItemStack stack = turtle.getInventory().getStackInSlot( m_slot ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCraftCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCraftCommand.java index 8c5928f24..d358db525 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCraftCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCraftCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -16,6 +16,7 @@ import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import javax.annotation.Nonnull; import java.util.ArrayList; public class TurtleCraftCommand implements ITurtleCommand @@ -27,8 +28,9 @@ public class TurtleCraftCommand implements ITurtleCommand m_limit = limit; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Craft the item TurtleInventoryCrafting crafting = new TurtleInventoryCrafting( turtle ); @@ -36,9 +38,8 @@ public class TurtleCraftCommand implements ITurtleCommand if( results != null ) { // Store the results - for( int i=0; i table = new HashMap(); @@ -57,9 +58,8 @@ public class TurtleInspectCommand implements ITurtleCommand table.put( "metadata", metadata ); Map stateTable = new HashMap(); - for( Object o : state.getActualState( world, newPosition ).getProperties().entrySet() ) + for( ImmutableMap.Entry, ?> entry : state.getActualState( world, newPosition ).getProperties().entrySet() ) { - ImmutableMap.Entry entry = (ImmutableMap.Entry)o; String propertyName = entry.getKey().getName(); Object value = entry.getValue(); if( value instanceof String || value instanceof Number || value instanceof Boolean ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java index 6d790fc49..fd68a8818 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -19,6 +19,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class TurtleMoveCommand implements ITurtleCommand @@ -30,8 +31,9 @@ public class TurtleMoveCommand implements ITurtleCommand m_direction = direction; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction EnumFacing direction = m_direction.toWorldDir( turtle ); @@ -70,10 +72,9 @@ public class TurtleMoveCommand implements ITurtleCommand if( ComputerCraft.turtlesCanPush && m_direction != MoveDirection.Up && m_direction != MoveDirection.Down ) { // Check there is space for all the pushable entities to be pushed - List list = oldWorld.getEntitiesWithinAABBExcludingEntity( (Entity)null, aabb ); - for( int i=0; i list = oldWorld.getEntitiesWithinAABBExcludingEntity( null, aabb ); + for( Entity entity : list ) { - Entity entity = (Entity)list.get( i ); if( !entity.isDead && entity.preventEntitySpawning ) { AxisAlignedBB entityBB = entity.getEntityBoundingBox(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index 522ecf52e..4d02774d1 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -33,6 +33,8 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nonnull; + public class TurtlePlaceCommand implements ITurtleCommand { private final InteractDirection m_direction; @@ -44,8 +46,9 @@ public class TurtlePlaceCommand implements ITurtleCommand m_extraArguments = arguments; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get thing to place ItemStack stack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); @@ -205,8 +208,7 @@ public class TurtlePlaceCommand implements ITurtleCommand final BlockPos position = turtle.getPosition(); Vec3d turtlePos = new Vec3d( turtlePlayer.posX, turtlePlayer.posY, turtlePlayer.posZ ); Vec3d rayDir = turtlePlayer.getLook( 1.0f ); - Vec3d rayStart = turtlePos; - Pair hit = WorldUtil.rayTraceEntities( world, rayStart, rayDir, 1.5 ); + Pair hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 ); if( hit == null ) { return stack; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java index 87e3b1b16..25fb5b7a1 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -18,6 +18,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.FakePlayer; +import javax.annotation.Nonnull; import java.util.UUID; public class TurtlePlayer extends FakePlayer @@ -83,7 +84,7 @@ public class TurtlePlayer extends FakePlayer } @Override - public void dismountEntity( Entity entity ) + public void dismountEntity( @Nonnull Entity entity ) { } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java index d521e4877..0ade611a2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -14,6 +14,8 @@ import dan200.computercraft.shared.util.InventoryUtil; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityFurnace; +import javax.annotation.Nonnull; + public class TurtleRefuelCommand implements ITurtleCommand { private final int m_limit; @@ -23,8 +25,9 @@ public class TurtleRefuelCommand implements ITurtleCommand m_limit = limit; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { if( m_limit == 0 ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSelectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSelectCommand.java index a34bd61e6..6fec07da7 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSelectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSelectCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,8 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; +import javax.annotation.Nonnull; + public class TurtleSelectCommand implements ITurtleCommand { private final int m_slot; @@ -19,8 +21,9 @@ public class TurtleSelectCommand implements ITurtleCommand m_slot = slot; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { turtle.setSelectedSlot( m_slot ); return TurtleCommandResult.success(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSetRedstoneCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSetRedstoneCommand.java index 90174f836..310ddef80 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSetRedstoneCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSetRedstoneCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -12,6 +12,8 @@ import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.core.apis.IAPIEnvironment; +import javax.annotation.Nonnull; + public class TurtleSetRedstoneCommand implements ITurtleCommand { private final IAPIEnvironment m_environment; @@ -25,8 +27,9 @@ public class TurtleSetRedstoneCommand implements ITurtleCommand m_value = value; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Do the setting int redstoneSide; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java index e2d14061f..2d5271647 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -21,6 +21,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; +import javax.annotation.Nonnull; import java.util.List; public class TurtleSuckCommand implements ITurtleCommand @@ -34,8 +35,9 @@ public class TurtleSuckCommand implements ITurtleCommand m_quantity = quantity; } + @Nonnull @Override - public TurtleCommandResult execute( ITurtleAccess turtle ) + public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Sucking nothing is easy if( m_quantity == 0 ) @@ -88,19 +90,18 @@ public class TurtleSuckCommand implements ITurtleCommand newPosition.getX(), newPosition.getY(), newPosition.getZ(), newPosition.getX() + 1.0, newPosition.getY() + 1.0, newPosition.getZ() + 1.0 ); - List list = world.getEntitiesWithinAABBExcludingEntity( null, aabb ); + List list = world.getEntitiesWithinAABBExcludingEntity( null, aabb ); if( list.size() > 0 ) { boolean foundItems = false; boolean storedItems = false; - for( int i=0; i getArmorInventoryList() { 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 780144989..99a20c0f1 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -18,6 +18,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ContainerTurtle extends Container @@ -107,12 +108,11 @@ public class ContainerTurtle extends Container super.detectAndSendChanges(); int selectedSlot = m_turtle.getSelectedSlot(); - for( int i=0; i list ) { List all = new ArrayList(); ComputerCraft.addAllUpgradedTurtles( all ); @@ -56,7 +57,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle } @Override - public boolean placeBlockAt( ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState ) + public boolean placeBlockAt( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState ) { if( super.placeBlockAt( stack, player, world, pos, side, hitX, hitY, hitZ, newState ) ) { @@ -112,6 +113,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle } } + @Nonnull @Override public String getUnlocalizedName( ItemStack stack ) { @@ -134,8 +136,9 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle } } + @Nonnull @Override - public String getItemStackDisplayName( ItemStack stack ) + public String getItemStackDisplayName( @Nonnull ItemStack stack ) { String baseString = getUnlocalizedName( stack ); ITurtleUpgrade left = getUpgrade( stack, TurtleSide.Left ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java index 595558af7..c514a9e24 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleLegacy.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java index 8ae57682f..4496b4046 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleNormal.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java b/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java index 56d195ced..2a72a1685 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/TurtleItemFactory.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java index dc306d14e..cba296587 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -15,6 +15,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class TurtleRecipe implements IRecipe { private final Item[] m_recipe; @@ -39,13 +41,13 @@ public class TurtleRecipe implements IRecipe } @Override - public boolean matches( InventoryCrafting _inventory, World world ) + public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world ) { return (getCraftingResult( _inventory ) != null); } @Override - public ItemStack getCraftingResult( InventoryCrafting inventory ) + public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) { // See if we match the recipe, and extract the input computercraft ID int computerID = -1; @@ -90,8 +92,9 @@ public class TurtleRecipe implements IRecipe } } + @Nonnull @Override - public ItemStack[] getRemainingItems( InventoryCrafting inventoryCrafting ) + public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) { ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ]; for (int i = 0; i < results.length; ++i) diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java index 13a9b758d..f49054585 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -20,6 +20,8 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class TurtleUpgradeRecipe implements IRecipe { public TurtleUpgradeRecipe() @@ -39,13 +41,13 @@ public class TurtleUpgradeRecipe implements IRecipe } @Override - public boolean matches( InventoryCrafting inventory, World world ) + public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world ) { return (getCraftingResult( inventory ) != null); } @Override - public ItemStack getCraftingResult( InventoryCrafting inventory ) + public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) { // Scan the grid for a row containing a turtle and 1 or 2 items ItemStack leftItem = null; @@ -157,8 +159,9 @@ public class TurtleUpgradeRecipe implements IRecipe return TurtleItemFactory.create( computerID, label, colour, family, upgrades[0], upgrades[1], fuelLevel, overlay ); } + @Nonnull @Override - public ItemStack[] getRemainingItems( InventoryCrafting inventoryCrafting ) + public ItemStack[] getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) { ItemStack[] results = new ItemStack[ inventoryCrafting.getSizeInventory() ]; for (int i = 0; i < results.length; ++i) diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/CraftingTablePeripheral.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/CraftingTablePeripheral.java index d4e9a45ab..69bf92302 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/CraftingTablePeripheral.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/CraftingTablePeripheral.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,6 +13,8 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.shared.turtle.core.TurtleCraftCommand; +import javax.annotation.Nonnull; + public class CraftingTablePeripheral implements IPeripheral { @@ -25,12 +27,14 @@ public class CraftingTablePeripheral // IPeripheral implementation + @Nonnull @Override public String getType() { return "workbench"; } + @Nonnull @Override public String[] getMethodNames() { @@ -59,7 +63,7 @@ public class CraftingTablePeripheral } @Override - public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException + public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException { switch( method ) { @@ -77,12 +81,12 @@ public class CraftingTablePeripheral } @Override - public void attach( IComputerAccess computer ) + public void attach( @Nonnull IComputerAccess computer ) { } @Override - public void detach( IComputerAccess computer ) + public void detach( @Nonnull IComputerAccess computer ) { } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java index e9be49357..e0abeb674 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleAxe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java index 5533a8356..25f08a10b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -20,6 +20,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nonnull; import javax.vecmath.Matrix4f; public class TurtleCraftingTable implements ITurtleUpgrade @@ -41,6 +42,7 @@ public class TurtleCraftingTable implements ITurtleUpgrade m_item = new ItemStack( Blocks.CRAFTING_TABLE, 1, 0 ); } + @Nonnull @Override public ResourceLocation getUpgradeID() { @@ -53,12 +55,14 @@ public class TurtleCraftingTable implements ITurtleUpgrade return m_legacyID; } + @Nonnull @Override public String getUnlocalisedAdjective() { return "upgrade.minecraft:crafting_table.adjective"; } + @Nonnull @Override public TurtleUpgradeType getType() { @@ -72,13 +76,14 @@ public class TurtleCraftingTable implements ITurtleUpgrade } @Override - public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ) + public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { return new CraftingTablePeripheral( turtle ); } + @Nonnull @Override - public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing dir ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir ) { return null; } @@ -93,9 +98,10 @@ public class TurtleCraftingTable implements ITurtleUpgrade } } + @Nonnull @Override @SideOnly( Side.CLIENT ) - public Pair getModel( ITurtleAccess turtle, TurtleSide side ) + public Pair getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { loadModelLocations(); @@ -113,7 +119,7 @@ public class TurtleCraftingTable implements ITurtleUpgrade } @Override - public void update( ITurtleAccess turtle, TurtleSide side ) + public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { } } 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 5fa690098..4bf30bb97 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -11,7 +11,6 @@ import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleVerb; import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand; -import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; @@ -21,6 +20,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import javax.annotation.Nonnull; + public class TurtleHoe extends TurtleTool { public TurtleHoe( ResourceLocation id, int legacyId, String adjective, Item item ) @@ -45,8 +46,9 @@ public class TurtleHoe extends TurtleTool return false; } + @Nonnull @Override - public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) { if( verb == TurtleVerb.Dig ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java index 3d1191a17..7d94267e2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -18,6 +18,7 @@ import net.minecraft.util.text.ITextComponent; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import javax.annotation.Nonnull; import java.util.ArrayList; public class TurtleInventoryCrafting extends InventoryCrafting @@ -201,6 +202,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting return m_turtle.getInventory().getStackInSlot( i ); } + @Nonnull @Override public String getName() { @@ -213,6 +215,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting return false; } + @Nonnull @Override public ITextComponent getDisplayName() { diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java index 776080031..ff0ad8251 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -26,6 +26,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nonnull; import javax.vecmath.Matrix4f; public class TurtleModem implements ITurtleUpgrade @@ -93,6 +94,7 @@ public class TurtleModem implements ITurtleUpgrade m_legacyID = legacyId; } + @Nonnull @Override public ResourceLocation getUpgradeID() { @@ -105,6 +107,7 @@ public class TurtleModem implements ITurtleUpgrade return m_legacyID; } + @Nonnull @Override public String getUnlocalisedAdjective() { @@ -118,6 +121,7 @@ public class TurtleModem implements ITurtleUpgrade } } + @Nonnull @Override public TurtleUpgradeType getType() { @@ -138,13 +142,14 @@ public class TurtleModem implements ITurtleUpgrade } @Override - public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ) + public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { return new Peripheral( turtle, m_advanced ); } + @Nonnull @Override - public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing dir ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir ) { return null; } @@ -171,9 +176,10 @@ public class TurtleModem implements ITurtleUpgrade } } + @Nonnull @Override @SideOnly( Side.CLIENT ) - public Pair getModel( ITurtleAccess turtle, TurtleSide side ) + public Pair getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { loadModelLocations(); @@ -207,7 +213,7 @@ public class TurtleModem implements ITurtleUpgrade } @Override - public void update( ITurtleAccess turtle, TurtleSide side ) + public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { // Advance the modem if( !turtle.getWorld().isRemote ) 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 9f9d65398..551420713 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java @@ -1,11 +1,10 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com */ package dan200.computercraft.shared.turtle.upgrades; -import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; 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 818766729..6eef57226 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java @@ -1,11 +1,10 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com */ package dan200.computercraft.shared.turtle.upgrades; -import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; 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 ec90134b6..787a8532a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -19,7 +19,6 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.item.EntityArmorStand; @@ -35,8 +34,8 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nonnull; import javax.vecmath.Matrix4f; -import java.util.Iterator; public class TurtleTool implements ITurtleUpgrade { @@ -53,6 +52,7 @@ public class TurtleTool implements ITurtleUpgrade m_item = new ItemStack( item, 1, 0 ); } + @Nonnull @Override public ResourceLocation getUpgradeID() { @@ -65,12 +65,14 @@ public class TurtleTool implements ITurtleUpgrade return m_legacyId; } + @Nonnull @Override public String getUnlocalisedAdjective() { return m_adjective; } + @Nonnull @Override public TurtleUpgradeType getType() { @@ -84,14 +86,15 @@ public class TurtleTool implements ITurtleUpgrade } @Override - public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ) + public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { return null; } + @Nonnull @Override @SideOnly( Side.CLIENT ) - public Pair getModel( ITurtleAccess turtle, TurtleSide side ) + public Pair getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) { float xOffset = (side == TurtleSide.Left) ? -0.40625f : 0.40625f; Matrix4f transform = new Matrix4f( @@ -108,12 +111,13 @@ public class TurtleTool implements ITurtleUpgrade } @Override - public void update( ITurtleAccess turtle, TurtleSide side ) + public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { } + @Nonnull @Override - public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) { switch( verb ) { @@ -136,11 +140,7 @@ public class TurtleTool implements ITurtleUpgrade { IBlockState state = world.getBlockState( pos ); Block block = state.getBlock(); - if( block.isAir( state, world, pos ) || block == Blocks.BEDROCK || state.getBlockHardness( world, pos ) <= -1.0F ) - { - return false; - } - return true; + return !block.isAir( state, world, pos ) && block != Blocks.BEDROCK && state.getBlockHardness( world, pos ) > -1.0F; } protected boolean canHarvestBlock( World world, BlockPos pos ) @@ -166,8 +166,7 @@ public class TurtleTool implements ITurtleUpgrade // See if there is an entity present Vec3d turtlePos = new Vec3d( turtlePlayer.posX, turtlePlayer.posY, turtlePlayer.posZ ); Vec3d rayDir = turtlePlayer.getLook( 1.0f ); - Vec3d rayStart = turtlePos; - Pair hit = WorldUtil.rayTraceEntities( world, rayStart, rayDir, 1.5 ); + Pair hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 ); if( hit != null ) { // Load up the turtle's inventory @@ -265,10 +264,8 @@ public class TurtleTool implements ITurtleUpgrade java.util.List items = getBlockDropped( world, newPosition ); if( items != null && items.size() > 0 ) { - Iterator it = items.iterator(); - while( it.hasNext() ) + for( ItemStack stack : items ) { - ItemStack stack = it.next(); ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getInventory(), 0, turtle.getInventory().getSizeInventory(), turtle.getSelectedSlot() ); if( remainder != null ) { diff --git a/src/main/java/dan200/computercraft/shared/util/Colour.java b/src/main/java/dan200/computercraft/shared/util/Colour.java index 957735324..fe43bc915 100644 --- a/src/main/java/dan200/computercraft/shared/util/Colour.java +++ b/src/main/java/dan200/computercraft/shared/util/Colour.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -37,7 +37,7 @@ public enum Colour private int m_hex; private float[] m_rgb; - private Colour( int hex ) + Colour( int hex ) { m_hex = hex; m_rgb = new float[] { diff --git a/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java b/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java index b9e7a914e..2ec9fcd7b 100644 --- a/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java +++ b/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,8 @@ import dan200.computercraft.ComputerCraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; +import javax.annotation.Nonnull; + public class CreativeTabMain extends CreativeTabs { public CreativeTabMain( int i ) @@ -17,12 +19,14 @@ public class CreativeTabMain extends CreativeTabs super( i, "ComputerCraft" ); } + @Nonnull @Override public Item getTabIconItem() { return Item.getItemFromBlock( ComputerCraft.Blocks.computer ); } + @Nonnull @Override public String getTranslatedTabLabel() { diff --git a/src/main/java/dan200/computercraft/shared/util/CreativeTabTreasure.java b/src/main/java/dan200/computercraft/shared/util/CreativeTabTreasure.java index 74a7ac770..f30197f6e 100644 --- a/src/main/java/dan200/computercraft/shared/util/CreativeTabTreasure.java +++ b/src/main/java/dan200/computercraft/shared/util/CreativeTabTreasure.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -10,6 +10,8 @@ import dan200.computercraft.ComputerCraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; +import javax.annotation.Nonnull; + public class CreativeTabTreasure extends CreativeTabs { public CreativeTabTreasure( int i ) @@ -17,12 +19,14 @@ public class CreativeTabTreasure extends CreativeTabs super( i, "Treasure Disks" ); } + @Nonnull @Override public Item getTabIconItem() { return ComputerCraft.Items.treasureDisk; } + @Nonnull @Override public String getTranslatedTabLabel() { diff --git a/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java b/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java index 318acba53..cf727a1ab 100644 --- a/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/util/Holiday.java b/src/main/java/dan200/computercraft/shared/util/Holiday.java index e77b365b9..83ee42566 100644 --- a/src/main/java/dan200/computercraft/shared/util/Holiday.java +++ b/src/main/java/dan200/computercraft/shared/util/Holiday.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java b/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java index a31652a53..376cf9e73 100644 --- a/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/HolidayUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java index 15d665bfe..b1eb6910e 100644 --- a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java +++ b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java @@ -21,7 +21,7 @@ public class IDAssigner private static int getNextID( File location, boolean directory ) { // Determine where to locate ID file - File lastidFile = null; + File lastidFile; if( directory ) { location.mkdirs(); @@ -41,13 +41,15 @@ public class IDAssigner if( directory && location.exists() && location.isDirectory() ) { String[] contents = location.list(); - for( int i=0; i(Arrays.asList( ingredients ))); } @Override diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java index edd9194ca..5e37ef95c 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -206,12 +206,11 @@ public class InventoryUtil // Inspect the slots in order and try to find empty or stackable slots ItemStack remainder = stack; - for( int n=0; n 0 ) { ItemStack stack = inventory.getStackInSlot( slot ); diff --git a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java index ea4a08884..9ef46a315 100644 --- a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -20,7 +20,7 @@ public class NBTUtil { if( object instanceof Boolean ) { - boolean b = ((Boolean)object).booleanValue(); + boolean b = (Boolean) object; return new NBTTagByte( b ? (byte)1 : (byte)0 ); } else if( object instanceof Number ) @@ -35,10 +35,10 @@ public class NBTUtil } else if( object instanceof Map ) { - Map m = (Map)object; + Map m = (Map)object; NBTTagCompound nbt = new NBTTagCompound(); int i=0; - for( Map.Entry entry : m.entrySet() ) + for( Map.Entry entry : m.entrySet() ) { NBTBase key = toNBTTag( entry.getKey() ); NBTBase value = toNBTTag( entry.getKey() ); @@ -85,18 +85,15 @@ public class NBTUtil { case Constants.NBT.TAG_BYTE: // byte { - boolean b = (((NBTTagByte)tag).getByte() > 0); - return b; + return (((NBTTagByte)tag).getByte() > 0); } case Constants.NBT.TAG_DOUBLE: // Double { - double d = ((NBTTagDouble)tag).getDouble(); - return d; + return ((NBTTagDouble)tag).getDouble(); } case Constants.NBT.TAG_STRING: // String { - String s = ((NBTTagString)tag).getString(); - return s; + return ((NBTTagString)tag).getString(); } case Constants.NBT.TAG_COMPOUND: // Compound { diff --git a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java index 1a99f300d..85129cc8d 100644 --- a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com diff --git a/src/main/java/dan200/computercraft/shared/util/ReflectionUtil.java b/src/main/java/dan200/computercraft/shared/util/ReflectionUtil.java index 758898d1b..ef7cd7071 100644 --- a/src/main/java/dan200/computercraft/shared/util/ReflectionUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/ReflectionUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -13,7 +13,7 @@ import java.lang.reflect.Modifier; public class ReflectionUtil { - public static Class getOptionalClass( String name ) + public static Class getOptionalClass( String name ) { try { @@ -26,20 +26,20 @@ public class ReflectionUtil return null; } - public static Class getOptionalInnerClass( Class enclosingClass, String name ) + public static Class getOptionalInnerClass( Class enclosingClass, String name ) { if( enclosingClass != null ) { try { - Class[] declaredClasses = enclosingClass.getDeclaredClasses(); + Class[] declaredClasses = enclosingClass.getDeclaredClasses(); if( declaredClasses != null ) { - for( int i=0; i declaredClass : declaredClasses ) { - if( declaredClasses[i].getSimpleName().equals( name ) ) + if( declaredClass.getSimpleName().equals( name ) ) { - return declaredClasses[i]; + return declaredClass; } } } @@ -52,7 +52,7 @@ public class ReflectionUtil return null; } - public static Method getOptionalMethod( Class clazz, String name, Class[] arguments ) + public static Method getOptionalMethod( Class clazz, String name, Class[] arguments ) { if( clazz != null ) { @@ -68,7 +68,7 @@ public class ReflectionUtil return null; } - public static Constructor getOptionalConstructor( Class clazz, Class[] arguments ) + public static Constructor getOptionalConstructor( Class clazz, Class[] arguments ) { if( clazz != null ) { @@ -84,7 +84,7 @@ public class ReflectionUtil return null; } - public static Field getOptionalField( Class clazz, String name ) + public static Field getOptionalField( Class clazz, String name ) { if( clazz != null ) { @@ -97,7 +97,7 @@ public class ReflectionUtil { field.setAccessible( true ); } - catch( Exception e ) + catch( Exception ignored ) { } } @@ -111,16 +111,16 @@ public class ReflectionUtil return null; } - public static T safeNew( Constructor constructor, Object[] arguments, Class resultClass ) + public static T safeNew( Constructor constructor, Object[] arguments, Class resultClass ) { if( constructor != null ) { try { - Object result = constructor.newInstance( arguments ); + T result = constructor.newInstance( arguments ); if( result != null && resultClass.isInstance( result ) ) { - return (T)result; + return result; } } catch( Exception e ) @@ -131,7 +131,7 @@ public class ReflectionUtil return null; } - public static boolean safeInstanceOf( Object object, Class clazz ) + public static boolean safeInstanceOf( Object object, Class clazz ) { if( clazz != null ) { @@ -158,6 +158,7 @@ public class ReflectionUtil } } + @SuppressWarnings("unchecked") public static T safeInvoke( Method method, Object object, Object[] arguments, Class resultClass ) { if( method != null ) @@ -182,6 +183,7 @@ public class ReflectionUtil return null; } + @SuppressWarnings("unchecked") public static T safeGet( Field field, Object object, Class resultClass ) { if( field != null ) diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index dccde1b57..096f8f32a 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -1,4 +1,4 @@ -/** +/* * This file is part of ComputerCraft - http://www.computercraft.info * Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. * Send enquiries to dratcliffe@gmail.com @@ -6,8 +6,6 @@ package dan200.computercraft.shared.util; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; @@ -62,10 +60,9 @@ public class WorldUtil Entity closest = null; double closestDist = 99.0; - List list = world.getEntitiesWithinAABBExcludingEntity( null, bigBox ); - for( int i=0; i list = world.getEntitiesWithinAABBExcludingEntity( null, bigBox ); + for( Entity entity : list ) { - Entity entity = (net.minecraft.entity.Entity)list.get(i); if( entity.isDead || !entity.canBeCollidedWith() ) { continue;