1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-29 15:30:48 +00:00

Reformat everything

It's been a long time comin'
But tonight is the end of the war, my friend
Tomorrow only one style will remain.
This commit is contained in:
SquidDev 2018-12-23 17:46:58 +00:00
parent 72b9d3d802
commit 2032e7a83a
173 changed files with 2028 additions and 1672 deletions

View File

@ -219,7 +219,8 @@ public class ComputerCraft
public static PocketSpeaker pocketSpeaker; public static PocketSpeaker pocketSpeaker;
} }
public static class Config { public static class Config
{
public static Configuration config; public static Configuration config;
public static Property http_enable; public static Property http_enable;
@ -379,7 +380,7 @@ public class ComputerCraft
Config.turtlesNeedFuel = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel ); Config.turtlesNeedFuel = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel );
Config.turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" ); Config.turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" );
Config.maximumFilesOpen = Config.config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen); Config.maximumFilesOpen = Config.config.get( Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen );
Config.maximumFilesOpen.setComment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." ); Config.maximumFilesOpen.setComment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." );
Config.turtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit ); Config.turtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit );
@ -394,13 +395,13 @@ public class ComputerCraft
Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush ); Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush );
Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" ); Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
Config.turtleDisabledActions = Config.config.get( Configuration.CATEGORY_GENERAL, "turtle_disabled_actions", new String[ 0 ] ); Config.turtleDisabledActions = Config.config.get( Configuration.CATEGORY_GENERAL, "turtle_disabled_actions", new String[0] );
Config.turtleDisabledActions.setComment( "A list of turtle actions which are disabled." ); Config.turtleDisabledActions.setComment( "A list of turtle actions which are disabled." );
Config.maxNotesPerTick = Config.config.get( Configuration.CATEGORY_GENERAL, "maxNotesPerTick", maxNotesPerTick ); Config.maxNotesPerTick = Config.config.get( Configuration.CATEGORY_GENERAL, "maxNotesPerTick", maxNotesPerTick );
Config.maxNotesPerTick.setComment( "Maximum amount of notes a speaker can play at once" ); Config.maxNotesPerTick.setComment( "Maximum amount of notes a speaker can play at once" );
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues()) for( Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues() )
{ {
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) ); property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
} }
@ -408,7 +409,8 @@ public class ComputerCraft
syncConfig(); syncConfig();
} }
public static void syncConfig() { public static void syncConfig()
{
http_enable = Config.http_enable.getBoolean(); http_enable = Config.http_enable.getBoolean();
http_websocket_enable = Config.http_websocket_enable.getBoolean(); http_websocket_enable = Config.http_websocket_enable.getBoolean();
@ -451,7 +453,7 @@ public class ComputerCraft
} }
} }
maxNotesPerTick = Math.max(1, Config.maxNotesPerTick.getInt()); maxNotesPerTick = Math.max( 1, Config.maxNotesPerTick.getInt() );
Config.config.save(); Config.config.save();
} }
@ -580,7 +582,7 @@ public class ComputerCraft
public static File getBaseDir() public static File getBaseDir()
{ {
return FMLCommonHandler.instance().getMinecraftServerInstance().getFile("."); return FMLCommonHandler.instance().getMinecraftServerInstance().getFile( "." );
} }
public static File getResourcePackDir() public static File getResourcePackDir()
@ -602,7 +604,7 @@ public class ComputerCraft
public static void sendToPlayer( EntityPlayer player, ComputerCraftPacket packet ) public static void sendToPlayer( EntityPlayer player, ComputerCraftPacket packet )
{ {
networkEventChannel.sendTo( encode( packet ), (EntityPlayerMP)player ); networkEventChannel.sendTo( encode( packet ), (EntityPlayerMP) player );
} }
public static void sendToAllPlayers( ComputerCraftPacket packet ) public static void sendToAllPlayers( ComputerCraftPacket packet )
@ -843,7 +845,8 @@ public class ComputerCraft
return null; return null;
} }
public static IPocketUpgrade getPocketUpgrade(String id) { public static IPocketUpgrade getPocketUpgrade( String id )
{
return pocketUpgrades.get( id ); return pocketUpgrades.get( id );
} }
@ -851,7 +854,7 @@ public class ComputerCraft
{ {
if( stack.isEmpty() ) return null; if( stack.isEmpty() ) return null;
for (IPocketUpgrade upgrade : pocketUpgrades.values()) for( IPocketUpgrade upgrade : pocketUpgrades.values() )
{ {
ItemStack craftingStack = upgrade.getCraftingItem(); ItemStack craftingStack = upgrade.getCraftingItem();
if( !craftingStack.isEmpty() && InventoryUtil.areItemsStackable( stack, craftingStack ) ) if( !craftingStack.isEmpty() && InventoryUtil.areItemsStackable( stack, craftingStack ) )
@ -863,10 +866,13 @@ public class ComputerCraft
return null; return null;
} }
public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades() { public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades()
{
List<IPocketUpgrade> upgrades = new ArrayList<>(); List<IPocketUpgrade> upgrades = new ArrayList<>();
for(IPocketUpgrade upgrade : pocketUpgrades.values()) { for( IPocketUpgrade upgrade : pocketUpgrades.values() )
if(upgrade instanceof PocketModem || upgrade instanceof PocketSpeaker) { {
if( upgrade instanceof PocketModem || upgrade instanceof PocketSpeaker )
{
upgrades.add( upgrade ); upgrades.add( upgrade );
} }
} }
@ -886,7 +892,7 @@ public class ComputerCraft
public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
{ {
return IDAssigner.getNextIDFromDirectory(new File(getWorldDir(world), parentSubPath)); return IDAssigner.getNextIDFromDirectory( new File( getWorldDir( world ), parentSubPath ) );
} }
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
@ -972,7 +978,7 @@ public class ComputerCraft
// Return the combination of all the mounts found // Return the combination of all the mounts found
if( mounts.size() >= 2 ) if( mounts.size() >= 2 )
{ {
IMount[] mountArray = new IMount[ mounts.size() ]; IMount[] mountArray = new IMount[mounts.size()];
mounts.toArray( mountArray ); mounts.toArray( mountArray );
return new ComboMount( mountArray ); return new ComboMount( mountArray );
} }
@ -1078,16 +1084,22 @@ public class ComputerCraft
} }
URL url; URL url;
try { try
{
url = new URL( path ); url = new URL( path );
} catch (MalformedURLException e1) { }
catch( MalformedURLException e1 )
{
return null; return null;
} }
File file; File file;
try { try
{
file = new File( url.toURI() ); file = new File( url.toURI() );
} catch(URISyntaxException e) { }
catch( URISyntaxException e )
{
file = new File( url.getPath() ); file = new File( url.getPath() );
} }
return file; return file;
@ -1096,7 +1108,7 @@ public class ComputerCraft
private static File getDebugCodeDir( Class<?> modClass ) private static File getDebugCodeDir( Class<?> modClass )
{ {
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath(); String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
int bangIndex = path.indexOf("!"); int bangIndex = path.indexOf( "!" );
if( bangIndex >= 0 ) if( bangIndex >= 0 )
{ {
return null; return null;
@ -1139,7 +1151,7 @@ public class ComputerCraft
turtleProxy.setDropConsumer( world, pos, consumer ); turtleProxy.setDropConsumer( world, pos, consumer );
} }
public static List<ItemStack> clearDropConsumer( ) public static List<ItemStack> clearDropConsumer()
{ {
return turtleProxy.clearDropConsumer(); return turtleProxy.clearDropConsumer();
} }

View File

@ -49,9 +49,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_getVersion != null ) if( computerCraft_getVersion != null )
{ {
try { try
return (String)computerCraft_getVersion.invoke( null ); {
} catch (Exception e) { return (String) computerCraft_getVersion.invoke( null );
}
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -82,9 +85,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_createUniqueNumberedSaveDir != null ) if( computerCraft_createUniqueNumberedSaveDir != null )
{ {
try { try
return (Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath ); {
} catch (Exception e) { return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
}
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -115,9 +121,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_createSaveDirMount != null ) if( computerCraft_createSaveDirMount != null )
{ {
try { try
return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity ); {
} catch (Exception e){ return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
}
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -148,9 +157,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_createResourceMount != null ) if( computerCraft_createResourceMount != null )
{ {
try { try
return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath ); {
} catch (Exception e){ return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
}
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -167,11 +179,14 @@ public final class ComputerCraftAPI
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider handler ) public static void registerPeripheralProvider( @Nonnull IPeripheralProvider handler )
{ {
findCC(); findCC();
if ( computerCraft_registerPeripheralProvider != null) if( computerCraft_registerPeripheralProvider != null )
{
try
{ {
try {
computerCraft_registerPeripheralProvider.invoke( null, handler ); computerCraft_registerPeripheralProvider.invoke( null, handler );
} catch (Exception e){ }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -192,9 +207,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_registerTurtleUpgrade != null ) if( computerCraft_registerTurtleUpgrade != null )
{ {
try { try
{
computerCraft_registerTurtleUpgrade.invoke( null, upgrade ); computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
} catch( Exception e ) { }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -212,9 +230,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_registerBundledRedstoneProvider != null ) if( computerCraft_registerBundledRedstoneProvider != null )
{ {
try { try
{
computerCraft_registerBundledRedstoneProvider.invoke( null, handler ); computerCraft_registerBundledRedstoneProvider.invoke( null, handler );
} catch (Exception e) { }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -235,9 +256,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_getDefaultBundledRedstoneOutput != null ) if( computerCraft_getDefaultBundledRedstoneOutput != null )
{ {
try { try
return (Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side ); {
} catch (Exception e){ return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
}
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -255,9 +279,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_registerMediaProvider != null ) if( computerCraft_registerMediaProvider != null )
{ {
try { try
{
computerCraft_registerMediaProvider.invoke( null, handler ); computerCraft_registerMediaProvider.invoke( null, handler );
} catch (Exception e){ }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -276,9 +303,12 @@ public final class ComputerCraftAPI
findCC(); findCC();
if( computerCraft_registerPermissionProvider != null ) if( computerCraft_registerPermissionProvider != null )
{ {
try { try
{
computerCraft_registerPermissionProvider.invoke( null, handler ); computerCraft_registerPermissionProvider.invoke( null, handler );
} catch (Exception e) { }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -287,10 +317,14 @@ public final class ComputerCraftAPI
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade ) public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
{ {
findCC(); findCC();
if(computerCraft_registerPocketUpgrade != null) { if( computerCraft_registerPocketUpgrade != null )
try { {
try
{
computerCraft_registerPocketUpgrade.invoke( null, upgrade ); computerCraft_registerPocketUpgrade.invoke( null, upgrade );
} catch (Exception e) { }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -309,7 +343,9 @@ public final class ComputerCraftAPI
try try
{ {
return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null ); return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null );
} catch (Exception e) { }
catch( Exception e )
{
// It failed; // It failed;
} }
} }
@ -394,12 +430,14 @@ public final class ComputerCraftAPI
private static void findCC() private static void findCC()
{ {
if( !ccSearched ) { if( !ccSearched )
try { {
try
{
computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" ); 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 World.class, String.class
} ); } );
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] { computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] {
@ -437,12 +475,16 @@ public final class ComputerCraftAPI
computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] { computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] {
IWiredElement.class IWiredElement.class
} ); } );
computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[]{ computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[] {
IBlockAccess.class, BlockPos.class, EnumFacing.class IBlockAccess.class, BlockPos.class, EnumFacing.class
} ); } );
} catch( Exception e ) { }
catch( Exception e )
{
System.out.println( "ComputerCraftAPI: ComputerCraft not found." ); System.out.println( "ComputerCraftAPI: ComputerCraft not found." );
} finally { }
finally
{
ccSearched = true; ccSearched = true;
} }
} }
@ -450,13 +492,16 @@ public final class ComputerCraftAPI
private static Method findCCMethod( String name, Class<?>[] args ) private static Method findCCMethod( String name, Class<?>[] args )
{ {
try { try
{
if( computerCraft != null ) if( computerCraft != null )
{ {
return computerCraft.getMethod( name, args ); return computerCraft.getMethod( name, args );
} }
return null; return null;
} catch( NoSuchMethodException e ) { }
catch( NoSuchMethodException e )
{
System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." ); System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
return null; return null;
} }

View File

@ -35,7 +35,7 @@ public class FixedWidthFontRenderer
private static void greyscaleify( double[] rgb ) private static void greyscaleify( double[] rgb )
{ {
Arrays.fill( rgb, ( rgb[0] + rgb[1] + rgb[2] ) / 3.0f ); Arrays.fill( rgb, (rgb[0] + rgb[1] + rgb[2]) / 3.0f );
} }
private void drawChar( BufferBuilder renderer, double x, double y, int index, int color, Palette p, boolean greyscale ) private void drawChar( BufferBuilder renderer, double x, double y, int index, int color, Palette p, boolean greyscale )
@ -44,13 +44,13 @@ public class FixedWidthFontRenderer
int row = index / 16; int row = index / 16;
double[] colour = p.getColour( 15 - color ); double[] colour = p.getColour( 15 - color );
if(greyscale) if( greyscale )
{ {
greyscaleify( colour ); greyscaleify( colour );
} }
float r = (float)colour[0]; float r = (float) colour[0];
float g = (float)colour[1]; float g = (float) colour[1];
float b = (float)colour[2]; float b = (float) colour[2];
int xStart = 1 + column * (FONT_WIDTH + 2); int xStart = 1 + column * (FONT_WIDTH + 2);
int yStart = 1 + row * (FONT_HEIGHT + 2); int yStart = 1 + row * (FONT_HEIGHT + 2);
@ -66,13 +66,13 @@ public class FixedWidthFontRenderer
private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale ) private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
{ {
double[] colour = p.getColour( 15 - color ); double[] colour = p.getColour( 15 - color );
if(greyscale) if( greyscale )
{ {
greyscaleify( colour ); greyscaleify( colour );
} }
float r = (float)colour[0]; float r = (float) colour[0];
float g = (float)colour[1]; float g = (float) colour[1];
float b = (float)colour[2]; float b = (float) colour[2];
renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex(); renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex(); renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
@ -96,7 +96,7 @@ public class FixedWidthFontRenderer
if( leftMarginSize > 0.0 ) if( leftMarginSize > 0.0 )
{ {
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) ); int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
if( colour1 < 0 || (greyScale && !isGreyScale(colour1)) ) if( colour1 < 0 || (greyScale && !isGreyScale( colour1 )) )
{ {
colour1 = 15; colour1 = 15;
} }
@ -105,7 +105,7 @@ public class FixedWidthFontRenderer
if( rightMarginSize > 0.0 ) if( rightMarginSize > 0.0 )
{ {
int colour2 = "0123456789abcdef".indexOf( backgroundColour.charAt( backgroundColour.length() - 1 ) ); int colour2 = "0123456789abcdef".indexOf( backgroundColour.charAt( backgroundColour.length() - 1 ) );
if( colour2 < 0 || (greyScale && !isGreyScale(colour2)) ) if( colour2 < 0 || (greyScale && !isGreyScale( colour2 )) )
{ {
colour2 = 15; colour2 = 15;
} }
@ -114,7 +114,7 @@ public class FixedWidthFontRenderer
for( int i = 0; i < backgroundColour.length(); i++ ) for( int i = 0; i < backgroundColour.length(); i++ )
{ {
int colour = "0123456789abcdef".indexOf( backgroundColour.charAt( i ) ); int colour = "0123456789abcdef".indexOf( backgroundColour.charAt( i ) );
if( colour < 0 || ( greyScale && !isGreyScale( colour ) ) ) if( colour < 0 || (greyScale && !isGreyScale( colour )) )
{ {
colour = 15; colour = 15;
} }
@ -135,7 +135,7 @@ public class FixedWidthFontRenderer
{ {
// Switch colour // Switch colour
int colour = "0123456789abcdef".indexOf( textColour.charAt( i ) ); int colour = "0123456789abcdef".indexOf( textColour.charAt( i ) );
if( colour < 0 || ( greyScale && !isGreyScale( colour ) ) ) if( colour < 0 || (greyScale && !isGreyScale( colour )) )
{ {
colour = 0; colour = 0;
} }
@ -174,9 +174,9 @@ public class FixedWidthFontRenderer
} }
} }
public int getStringWidth(String s) public int getStringWidth( String s )
{ {
if(s == null) if( s == null )
{ {
return 0; return 0;
} }

View File

@ -87,7 +87,7 @@ public class GuiComputer extends GuiContainer
} }
@Override @Override
protected void keyTyped(char c, int k) throws IOException protected void keyTyped( char c, int k ) throws IOException
{ {
if( k == 1 ) if( k == 1 )
{ {
@ -127,7 +127,7 @@ public class GuiComputer extends GuiContainer
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) protected void drawGuiContainerForegroundLayer( int par1, int par2 )
{ {
} }
@ -173,15 +173,15 @@ public class GuiComputer extends GuiContainer
} }
} }
drawTexturedModalRect(startX - 12, startY - 12, 12, 28, 12, 12); drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
drawTexturedModalRect(startX - 12, endY, 12, 40, 12, 16); drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 16 );
drawTexturedModalRect(endX, startY - 12, 24, 28, 12, 12); drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
drawTexturedModalRect(endX, endY, 24, 40, 12, 16); drawTexturedModalRect( endX, endY, 24, 40, 12, 16 );
drawTexturedModalRect(startX, startY-12, 0, 0, endX - startX, 12); drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
drawTexturedModalRect(startX, endY, 0, 12, endX - startX, 16); drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 16 );
drawTexturedModalRect(startX-12, startY, 0, 28, 12, endY - startY); drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
drawTexturedModalRect(endX, startY, 36, 28, 12, endY - startY); drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
} }
} }

View File

@ -24,7 +24,7 @@ public class GuiConfigCC extends GuiConfig
private static List<IConfigElement> getConfigElements() private static List<IConfigElement> getConfigElements()
{ {
ArrayList<IConfigElement> elements = new ArrayList<>(); ArrayList<IConfigElement> elements = new ArrayList<>();
for (Property property : ComputerCraft.Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues()) for( Property property : ComputerCraft.Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues() )
{ {
elements.add( new ConfigElement( property ) ); elements.add( new ConfigElement( property ) );
} }

View File

@ -22,33 +22,33 @@ public class GuiDiskDrive extends GuiContainer
public GuiDiskDrive( InventoryPlayer inventoryplayer, TileDiskDrive diskDrive ) public GuiDiskDrive( InventoryPlayer inventoryplayer, TileDiskDrive diskDrive )
{ {
super( new ContainerDiskDrive(inventoryplayer, diskDrive) ); super( new ContainerDiskDrive( inventoryplayer, diskDrive ) );
m_diskDrive = diskDrive; m_diskDrive = diskDrive;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) protected void drawGuiContainerForegroundLayer( int par1, int par2 )
{ {
String title = m_diskDrive.getDisplayName().getUnformattedText(); String title = m_diskDrive.getDisplayName().getUnformattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 ); fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
{ {
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
this.mc.getTextureManager().bindTexture( background ); this.mc.getTextureManager().bindTexture( background );
int l = (width - xSize) / 2; int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2; int i1 = (height - ySize) / 2;
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize); drawTexturedModalRect( l, i1, 0, 0, xSize, ySize );
} }
@Override @Override
public void drawScreen( int mouseX, int mouseY, float partialTicks) public void drawScreen( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks); super.drawScreen( mouseX, mouseY, partialTicks );
renderHoveredToolTip(mouseX, mouseY); renderHoveredToolTip( mouseX, mouseY );
} }
} }

View File

@ -21,42 +21,42 @@ public class GuiPrinter extends GuiContainer
private TilePrinter m_printer; private TilePrinter m_printer;
private ContainerPrinter m_container; private ContainerPrinter m_container;
public GuiPrinter(InventoryPlayer inventoryplayer, TilePrinter printer) public GuiPrinter( InventoryPlayer inventoryplayer, TilePrinter printer )
{ {
super(new ContainerPrinter(inventoryplayer, printer)); super( new ContainerPrinter( inventoryplayer, printer ) );
m_printer = printer; m_printer = printer;
m_container = (ContainerPrinter)inventorySlots; m_container = (ContainerPrinter) inventorySlots;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) protected void drawGuiContainerForegroundLayer( int par1, int par2 )
{ {
String title = m_printer.getDisplayName().getUnformattedText(); String title = m_printer.getDisplayName().getUnformattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 ); fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
{ {
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
this.mc.getTextureManager().bindTexture( background ); this.mc.getTextureManager().bindTexture( background );
int startX = (width - xSize) / 2; int startX = (width - xSize) / 2;
int startY = (height - ySize) / 2; int startY = (height - ySize) / 2;
drawTexturedModalRect(startX, startY, 0, 0, xSize, ySize); drawTexturedModalRect( startX, startY, 0, 0, xSize, ySize );
boolean printing = m_container.isPrinting(); boolean printing = m_container.isPrinting();
if( printing ) if( printing )
{ {
drawTexturedModalRect(startX + 34, startY + 21, 176, 0, 25, 45); drawTexturedModalRect( startX + 34, startY + 21, 176, 0, 25, 45 );
} }
} }
@Override @Override
public void drawScreen( int mouseX, int mouseY, float partialTicks) public void drawScreen( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks); super.drawScreen( mouseX, mouseY, partialTicks );
renderHoveredToolTip(mouseX, mouseY); renderHoveredToolTip( mouseX, mouseY );
} }
} }

View File

@ -30,12 +30,12 @@ public class GuiPrintout extends GuiContainer
super( container ); super( container );
String[] text = ItemPrintout.getText( container.getStack() ); String[] text = ItemPrintout.getText( container.getStack() );
m_text = new TextBuffer[ text.length ]; m_text = new TextBuffer[text.length];
for( int i = 0; i < m_text.length; ++i ) m_text[ i ] = new TextBuffer( text[ i ] ); for( int i = 0; i < m_text.length; i++ ) m_text[i] = new TextBuffer( text[i] );
String[] colours = ItemPrintout.getColours( container.getStack() ); String[] colours = ItemPrintout.getColours( container.getStack() );
m_colours = new TextBuffer[ colours.length ]; m_colours = new TextBuffer[colours.length];
for( int i = 0; i < m_colours.length; ++i ) m_colours[ i ] = new TextBuffer( colours[ i ] ); for( int i = 0; i < m_colours.length; i++ ) m_colours[i] = new TextBuffer( colours[i] );
m_page = 0; m_page = 0;
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 ); m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );

View File

@ -60,10 +60,10 @@ public class GuiTurtle extends GuiContainer
public void initGui() public void initGui()
{ {
super.initGui(); super.initGui();
Keyboard.enableRepeatEvents(true); Keyboard.enableRepeatEvents( true );
m_terminalGui = new WidgetTerminal( m_terminalGui = new WidgetTerminal(
( width - xSize ) / 2 + 8, (width - xSize) / 2 + 8,
( height - ySize ) / 2 + 8, (height - ySize) / 2 + 8,
ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalWidth_turtle,
ComputerCraft.terminalHeight_turtle, ComputerCraft.terminalHeight_turtle,
() -> m_computer, () -> m_computer,
@ -76,7 +76,7 @@ public class GuiTurtle extends GuiContainer
public void onGuiClosed() public void onGuiClosed()
{ {
super.onGuiClosed(); super.onGuiClosed();
Keyboard.enableRepeatEvents(false); Keyboard.enableRepeatEvents( false );
} }
@Override @Override
@ -87,7 +87,7 @@ public class GuiTurtle extends GuiContainer
} }
@Override @Override
protected void keyTyped(char c, int k) throws IOException protected void keyTyped( char c, int k ) throws IOException
{ {
if( k == 1 ) if( k == 1 )
{ {
@ -100,7 +100,7 @@ public class GuiTurtle extends GuiContainer
} }
@Override @Override
protected void mouseClicked(int x, int y, int button) throws IOException protected void mouseClicked( int x, int y, int button ) throws IOException
{ {
super.mouseClicked( x, y, button ); super.mouseClicked( x, y, button );
m_terminalGui.mouseClicked( x, y, button ); m_terminalGui.mouseClicked( x, y, button );
@ -132,10 +132,10 @@ public class GuiTurtle extends GuiContainer
if( slot >= 0 ) if( slot >= 0 )
{ {
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
int slotX = (slot%4); int slotX = (slot % 4);
int slotY = (slot/4); int slotY = (slot / 4);
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background ); this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
drawTexturedModalRect(x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24); drawTexturedModalRect( x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
} }
} }
@ -151,16 +151,16 @@ public class GuiTurtle extends GuiContainer
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background ); this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
int x = (width - xSize) / 2; int x = (width - xSize) / 2;
int y = (height - ySize) / 2; int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize); drawTexturedModalRect( x, y, 0, 0, xSize, ySize );
drawSelectionSlot( advanced ); drawSelectionSlot( advanced );
} }
@Override @Override
public void drawScreen( int mouseX, int mouseY, float partialTicks) public void drawScreen( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks); super.drawScreen( mouseX, mouseY, partialTicks );
renderHoveredToolTip(mouseX, mouseY); renderHoveredToolTip( mouseX, mouseY );
} }
} }

View File

@ -122,7 +122,7 @@ public class WidgetTerminal extends Widget
} }
// Queue the "paste" event // Queue the "paste" event
queueEvent( "paste", new Object[]{ queueEvent( "paste", new Object[] {
clipboard clipboard
} ); } );
} }
@ -143,7 +143,7 @@ public class WidgetTerminal extends Widget
} }
// Queue the "key" event // Queue the "key" event
queueEvent( "key", new Object[]{ queueEvent( "key", new Object[] {
key, repeat key, repeat
} ); } );
handled = true; handled = true;
@ -152,7 +152,7 @@ public class WidgetTerminal extends Widget
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
{ {
// Queue the "char" event // Queue the "char" event
queueEvent( "char", new Object[]{ queueEvent( "char", new Object[] {
Character.toString( ch ) Character.toString( ch )
} ); } );
handled = true; handled = true;
@ -171,7 +171,7 @@ public class WidgetTerminal extends Widget
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() && if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() ) mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
{ {
if( !m_focus && button == 0) if( !m_focus && button == 0 )
{ {
m_focus = true; m_focus = true;
} }
@ -184,12 +184,12 @@ public class WidgetTerminal extends Widget
Terminal term = computer.getTerminal(); Terminal term = computer.getTerminal();
if( term != null ) if( term != null )
{ {
int charX = ( mouseX - ( getXPosition() + m_leftMargin ) ) / FixedWidthFontRenderer.FONT_WIDTH; int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
int charY = ( mouseY - ( getYPosition() + m_topMargin ) ) / FixedWidthFontRenderer.FONT_HEIGHT; int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 ); charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 ); charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
computer.queueEvent( "mouse_click", new Object[]{ computer.queueEvent( "mouse_click", new Object[] {
button + 1, charX + 1, charY + 1 button + 1, charX + 1, charY + 1
} ); } );
@ -222,7 +222,7 @@ public class WidgetTerminal extends Widget
if( m_focus ) if( m_focus )
{ {
// Queue the "key_up" event // Queue the "key_up" event
queueEvent( "key_up", new Object[]{ queueEvent( "key_up", new Object[] {
key key
} ); } );
handled = true; handled = true;
@ -244,8 +244,8 @@ public class WidgetTerminal extends Widget
Terminal term = computer.getTerminal(); Terminal term = computer.getTerminal();
if( term != null ) if( term != null )
{ {
int charX = ( mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH; int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
int charY = ( mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT; int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 ); charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 ); charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
@ -253,7 +253,7 @@ public class WidgetTerminal extends Widget
{ {
if( m_focus ) if( m_focus )
{ {
computer.queueEvent( "mouse_up", new Object[]{ computer.queueEvent( "mouse_up", new Object[] {
m_lastClickButton + 1, charX + 1, charY + 1 m_lastClickButton + 1, charX + 1, charY + 1
} ); } );
} }
@ -270,20 +270,20 @@ public class WidgetTerminal extends Widget
{ {
if( wheelChange < 0 ) if( wheelChange < 0 )
{ {
computer.queueEvent( "mouse_scroll", new Object[]{ computer.queueEvent( "mouse_scroll", new Object[] {
1, charX + 1, charY + 1 1, charX + 1, charY + 1
} ); } );
} }
else if( wheelChange > 0 ) else if( wheelChange > 0 )
{ {
computer.queueEvent( "mouse_scroll", new Object[]{ computer.queueEvent( "mouse_scroll", new Object[] {
-1, charX + 1, charY + 1 -1, charX + 1, charY + 1
} ); } );
} }
if( m_lastClickButton >= 0 && ( charX != m_lastClickX || charY != m_lastClickY ) ) if( m_lastClickButton >= 0 && (charX != m_lastClickX || charY != m_lastClickY) )
{ {
computer.queueEvent( "mouse_drag", new Object[]{ computer.queueEvent( "mouse_drag", new Object[] {
m_lastClickButton + 1, charX + 1, charY + 1 m_lastClickButton + 1, charX + 1, charY + 1
} ); } );
m_lastClickX = charX; m_lastClickX = charX;
@ -318,7 +318,7 @@ public class WidgetTerminal extends Widget
} }
// Ctrl+R for reboot // Ctrl+R for reboot
if( Keyboard.isKeyDown(19) ) if( Keyboard.isKeyDown( 19 ) )
{ {
if( m_rebootTimer < TERMINATE_TIME ) if( m_rebootTimer < TERMINATE_TIME )
{ {
@ -339,7 +339,7 @@ public class WidgetTerminal extends Widget
} }
// Ctrl+S for shutdown // Ctrl+S for shutdown
if( Keyboard.isKeyDown(31) ) if( Keyboard.isKeyDown( 31 ) )
{ {
if( m_shutdownTimer < TERMINATE_TIME ) if( m_shutdownTimer < TERMINATE_TIME )
{ {
@ -377,7 +377,7 @@ public class WidgetTerminal extends Widget
{ {
// Draw the screen contents // Draw the screen contents
IComputer computer = m_computer.getComputer(); IComputer computer = m_computer.getComputer();
Terminal terminal = ( computer != null ) ? computer.getTerminal() : null; Terminal terminal = (computer != null) ? computer.getTerminal() : null;
if( terminal != null ) if( terminal != null )
{ {
// Draw the terminal // Draw the terminal
@ -405,7 +405,7 @@ public class WidgetTerminal extends Widget
} }
if( m_bottomMargin > 0 ) if( m_bottomMargin > 0 )
{ {
fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + ( th - 1 ) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette ); fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
} }
// Draw lines // Draw lines
@ -433,7 +433,8 @@ public class WidgetTerminal extends Widget
palette palette
); );
} }
} else }
else
{ {
// Draw a black background // Draw a black background
mc.getTextureManager().bindTexture( background ); mc.getTextureManager().bindTexture( background );
@ -442,7 +443,8 @@ public class WidgetTerminal extends Widget
try try
{ {
drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() ); drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
} finally }
finally
{ {
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
} }

View File

@ -102,7 +102,7 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names ) private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names )
{ {
ResourceLocation[] resources = new ResourceLocation[names.length]; ResourceLocation[] resources = new ResourceLocation[names.length];
for( int i=0; i<names.length; ++i ) for( int i = 0; i < names.length; i++ )
{ {
resources[i] = new ResourceLocation( "computercraft:" + names[i] ); resources[i] = new ResourceLocation( "computercraft:" + names[i] );
} }
@ -141,7 +141,7 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager(); IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
if( resourceManager instanceof SimpleReloadableResourceManager ) if( resourceManager instanceof SimpleReloadableResourceManager )
{ {
SimpleReloadableResourceManager reloadableResourceManager = (SimpleReloadableResourceManager)resourceManager; SimpleReloadableResourceManager reloadableResourceManager = (SimpleReloadableResourceManager) resourceManager;
reloadableResourceManager.registerReloadListener( m_turtleSmartItemModel ); reloadableResourceManager.registerReloadListener( m_turtleSmartItemModel );
} }
} }

View File

@ -110,9 +110,9 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
{ {
ItemComputer itemComputer = (ItemComputer) stack.getItem(); ItemComputer itemComputer = (ItemComputer) stack.getItem();
ComputerFamily family = itemComputer.getFamily( stack.getItemDamage() ); ComputerFamily family = itemComputer.getFamily( stack.getItemDamage() );
return ( family == ComputerFamily.Advanced ) ? advanced_computer : computer; return (family == ComputerFamily.Advanced) ? advanced_computer : computer;
} }
}, new String[]{ "computer", "advanced_computer" } ); }, new String[] { "computer", "advanced_computer" } );
registerItemModel( ComputerCraft.Blocks.peripheral, 0, "peripheral" ); registerItemModel( ComputerCraft.Blocks.peripheral, 0, "peripheral" );
registerItemModel( ComputerCraft.Blocks.peripheral, 1, "wireless_modem" ); registerItemModel( ComputerCraft.Blocks.peripheral, 1, "wireless_modem" );
registerItemModel( ComputerCraft.Blocks.peripheral, 2, "monitor" ); registerItemModel( ComputerCraft.Blocks.peripheral, 2, "monitor" );
@ -279,7 +279,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names ) private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names )
{ {
ResourceLocation[] resources = new ResourceLocation[names.length]; ResourceLocation[] resources = new ResourceLocation[names.length];
for( int i=0; i<resources.length; ++i ) for( int i = 0; i < resources.length; i++ )
{ {
resources[i] = new ResourceLocation( "computercraft", names[i] ); resources[i] = new ResourceLocation( "computercraft", names[i] );
} }
@ -296,7 +296,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
@Override @Override
public boolean getGlobalCursorBlink() public boolean getGlobalCursorBlink()
{ {
return ( m_tick / 8) % 2 == 0; return (m_tick / 8) % 2 == 0;
} }
@Override @Override
@ -316,9 +316,12 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
{ {
List<String> info = new ArrayList<>( 1 ); List<String> info = new ArrayList<>( 1 );
recordStack.getItem().addInformation( recordStack, null, info, ITooltipFlag.TooltipFlags.NORMAL ); recordStack.getItem().addInformation( recordStack, null, info, ITooltipFlag.TooltipFlags.NORMAL );
if( info.size() > 0 ) { if( info.size() > 0 )
{
return info.get( 0 ); return info.get( 0 );
} else { }
else
{
return super.getRecordInfo( recordStack ); return super.getRecordInfo( recordStack );
} }
} }
@ -427,7 +430,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
case ComputerCraftPacket.ComputerChanged: case ComputerCraftPacket.ComputerChanged:
case ComputerCraftPacket.ComputerTerminalChanged: case ComputerCraftPacket.ComputerTerminalChanged:
{ {
int instanceID = packet.m_dataInt[ 0 ]; int instanceID = packet.m_dataInt[0];
if( !ComputerCraft.clientComputerRegistry.contains( instanceID ) ) if( !ComputerCraft.clientComputerRegistry.contains( instanceID ) )
{ {
ComputerCraft.clientComputerRegistry.add( instanceID, new ClientComputer( instanceID ) ); ComputerCraft.clientComputerRegistry.add( instanceID, new ClientComputer( instanceID ) );
@ -437,7 +440,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} }
case ComputerCraftPacket.ComputerDeleted: case ComputerCraftPacket.ComputerDeleted:
{ {
int instanceID = packet.m_dataInt[ 0 ]; int instanceID = packet.m_dataInt[0];
if( ComputerCraft.clientComputerRegistry.contains( instanceID ) ) if( ComputerCraft.clientComputerRegistry.contains( instanceID ) )
{ {
ComputerCraft.clientComputerRegistry.remove( instanceID ); ComputerCraft.clientComputerRegistry.remove( instanceID );
@ -446,13 +449,13 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} }
case ComputerCraftPacket.PlayRecord: case ComputerCraftPacket.PlayRecord:
{ {
BlockPos pos = new BlockPos( packet.m_dataInt[ 0 ], packet.m_dataInt[ 1 ], packet.m_dataInt[ 2 ] ); BlockPos pos = new BlockPos( packet.m_dataInt[0], packet.m_dataInt[1], packet.m_dataInt[2] );
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
if( packet.m_dataInt.length > 3 ) if( packet.m_dataInt.length > 3 )
{ {
SoundEvent sound = SoundEvent.REGISTRY.getObjectById( packet.m_dataInt[ 3 ] ); SoundEvent sound = SoundEvent.REGISTRY.getObjectById( packet.m_dataInt[3] );
mc.world.playRecord( pos, sound ); mc.world.playRecord( pos, sound );
mc.ingameGUI.setRecordPlayingMessage( packet.m_dataString[ 0 ] ); mc.ingameGUI.setRecordPlayingMessage( packet.m_dataString[0] );
} }
else else
{ {
@ -597,7 +600,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
} }
} }
@SideOnly(Side.CLIENT) @SideOnly( Side.CLIENT )
private static class DiskColorHandler implements IItemColor private static class DiskColorHandler implements IItemColor
{ {
private final ItemDiskLegacy disk; private final ItemDiskLegacy disk;

View File

@ -34,7 +34,7 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
/** /**
* Emulates map rendering for pocket computers * Emulates map rendering for pocket computers
*/ */
@SideOnly(Side.CLIENT) @SideOnly( Side.CLIENT )
public class ItemPocketRenderer public class ItemPocketRenderer
{ {
@SubscribeEvent @SubscribeEvent

View File

@ -85,8 +85,8 @@ public final class ModelTransformer
private final Matrix4f normalMatrix; private final Matrix4f normalMatrix;
private int vertexIndex = 0, elementIndex = 0; private int vertexIndex = 0, elementIndex = 0;
private final Point3f[] before = new Point3f[ 4 ]; private final Point3f[] before = new Point3f[4];
private final Point3f[] after = new Point3f[ 4 ]; private final Point3f[] after = new Point3f[4];
public NormalAwareTransformer( IVertexConsumer parent, Matrix4f positionMatrix, Matrix4f normalMatrix ) public NormalAwareTransformer( IVertexConsumer parent, Matrix4f positionMatrix, Matrix4f normalMatrix )
{ {
@ -112,13 +112,13 @@ public final class ModelTransformer
Point3f newVec = new Point3f(); Point3f newVec = new Point3f();
positionMatrix.transform( vec, newVec ); positionMatrix.transform( vec, newVec );
float[] newData = new float[ 4 ]; float[] newData = new float[4];
newVec.get( newData ); newVec.get( newData );
super.put( element, newData ); super.put( element, newData );
before[ vertexIndex ] = vec; before[vertexIndex] = vec;
after[ vertexIndex ] = newVec; after[vertexIndex] = newVec;
break; break;
} }
case NORMAL: case NORMAL:
@ -126,7 +126,7 @@ public final class ModelTransformer
Vector3f vec = new Vector3f( data ); Vector3f vec = new Vector3f( data );
normalMatrix.transform( vec ); normalMatrix.transform( vec );
float[] newData = new float[ 4 ]; float[] newData = new float[4];
vec.get( newData ); vec.get( newData );
super.put( element, newData ); super.put( element, newData );
break; break;
@ -150,14 +150,14 @@ public final class ModelTransformer
Vector3f crossBefore = new Vector3f(), crossAfter = new Vector3f(); Vector3f crossBefore = new Vector3f(), crossAfter = new Vector3f();
// Determine what cross product we expect to have // Determine what cross product we expect to have
temp1.sub( before[ 1 ], before[ 0 ] ); temp1.sub( before[1], before[0] );
temp2.sub( before[ 1 ], before[ 2 ] ); temp2.sub( before[1], before[2] );
crossBefore.cross( temp1, temp2 ); crossBefore.cross( temp1, temp2 );
normalMatrix.transform( crossBefore ); normalMatrix.transform( crossBefore );
// And determine what cross product we actually have // And determine what cross product we actually have
temp1.sub( after[ 1 ], after[ 0 ] ); temp1.sub( after[1], after[0] );
temp2.sub( after[ 1 ], after[ 2 ] ); temp2.sub( after[1], after[2] );
crossAfter.cross( temp1, temp2 ); crossAfter.cross( temp1, temp2 );
// If the angle between expected and actual cross product is greater than // If the angle between expected and actual cross product is greater than
@ -189,7 +189,7 @@ public final class ModelTransformer
private BakedQuadBuilder( VertexFormat format ) private BakedQuadBuilder( VertexFormat format )
{ {
this.format = format; this.format = format;
this.vertexData = new int[ format.getSize() ]; this.vertexData = new int[format.getSize()];
} }
@Nonnull @Nonnull
@ -241,9 +241,9 @@ public final class ModelTransformer
int length = vertexData.length / 4; int length = vertexData.length / 4;
for( int i = 0; i < length; i++ ) for( int i = 0; i < length; i++ )
{ {
int temp = vertexData[ a * length + i ]; int temp = vertexData[a * length + i];
vertexData[ a * length + i ] = vertexData[ b * length + i ]; vertexData[a * length + i] = vertexData[b * length + i];
vertexData[ b * length + i ] = temp; vertexData[b * length + i] = temp;
} }
} }

View File

@ -59,7 +59,7 @@ public class PrintoutRenderer
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
{ {
fontRenderer.drawString( text[ start + line ], x, y + line * FONT_HEIGHT, colours[ start + line ], null, 0, 0, false, Palette.DEFAULT ); fontRenderer.drawString( text[start + line], x, y + line * FONT_HEIGHT, colours[start + line], null, 0, 0, false, Palette.DEFAULT );
} }
} }
@ -73,7 +73,7 @@ public class PrintoutRenderer
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line ) for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
{ {
fontRenderer.drawString( new TextBuffer( text[ start + line ] ), x, y + line * FONT_HEIGHT, new TextBuffer( colours[ start + line ] ), null, 0, 0, false, Palette.DEFAULT ); fontRenderer.drawString( new TextBuffer( text[start + line] ), x, y + line * FONT_HEIGHT, new TextBuffer( colours[start + line] ), null, 0, 0, false, Palette.DEFAULT );
} }
} }

View File

@ -9,10 +9,10 @@ import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;

View File

@ -85,8 +85,8 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
(origin.getHeight() - 0.5) - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN), (origin.getHeight() - 0.5) - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
0.5 0.5
); );
double xSize = origin.getWidth() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER ); double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
double ySize = origin.getHeight() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER ); double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
// Get renderers // Get renderers
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
@ -126,8 +126,8 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
try try
{ {
double xScale = xSize / ( width * FixedWidthFontRenderer.FONT_WIDTH ); double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
double yScale = ySize / ( height * FixedWidthFontRenderer.FONT_HEIGHT ); double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
GlStateManager.scale( xScale, -yScale, 1.0 ); GlStateManager.scale( xScale, -yScale, 1.0 );
// Draw background // Draw background
@ -158,7 +158,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
} }
// Backgrounds // Backgrounds
for( int y = 0; y < height; ++y ) for( int y = 0; y < height; y++ )
{ {
fontRenderer.drawStringBackgroundPart( fontRenderer.drawStringBackgroundPart(
0, FixedWidthFontRenderer.FONT_HEIGHT * y, 0, FixedWidthFontRenderer.FONT_HEIGHT * y,
@ -186,7 +186,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
try try
{ {
// Lines // Lines
for( int y = 0; y < height; ++y ) for( int y = 0; y < height; y++ )
{ {
fontRenderer.drawStringTextPart( fontRenderer.drawStringTextPart(
0, FixedWidthFontRenderer.FONT_HEIGHT * y, 0, FixedWidthFontRenderer.FONT_HEIGHT * y,

View File

@ -236,7 +236,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
BufferBuilder buffer = tessellator.getBuffer(); BufferBuilder buffer = tessellator.getBuffer();
VertexFormat format = DefaultVertexFormats.ITEM; VertexFormat format = DefaultVertexFormats.ITEM;
buffer.begin( GL11.GL_QUADS, format ); buffer.begin( GL11.GL_QUADS, format );
for (BakedQuad quad : quads) for( BakedQuad quad : quads )
{ {
VertexFormat quadFormat = quad.getFormat(); VertexFormat quadFormat = quad.getFormat();
if( quadFormat != format ) if( quadFormat != format )
@ -250,7 +250,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
if( quad.hasTintIndex() && tints != null ) if( quad.hasTintIndex() && tints != null )
{ {
int index = quad.getTintIndex(); int index = quad.getTintIndex();
if( index >= 0 && index < tints.length ) colour = tints[ index ] | 0xFF000000; if( index >= 0 && index < tints.length ) colour = tints[index] | 0xFF000000;
} }
LightUtil.renderQuadColor( buffer, quad, colour ); LightUtil.renderQuadColor( buffer, quad, colour );

View File

@ -32,8 +32,8 @@ public class AddressPredicate
for( int i = 0; i < entry.length; i++ ) for( int i = 0; i < entry.length; i++ )
{ {
int value = 0xFF & entry[ i ]; int value = 0xFF & entry[i];
if( value < (0xFF & min[ i ]) || value > (0xFF & max[ i ]) ) return false; if( value < (0xFF & min[i]) || value > (0xFF & max[i]) ) return false;
} }
return true; return true;
@ -85,13 +85,13 @@ public class AddressPredicate
{ {
if( size <= 0 ) if( size <= 0 )
{ {
minBytes[ i ] &= 0; minBytes[i] &= 0;
maxBytes[ i ] |= 0xFF; maxBytes[i] |= 0xFF;
} }
else if( size < 8 ) else if( size < 8 )
{ {
minBytes[ i ] &= 0xFF << (8 - size); minBytes[i] &= 0xFF << (8 - size);
maxBytes[ i ] |= ~(0xFF << (8 - size)); maxBytes[i] |= ~(0xFF << (8 - size));
} }
size -= 8; size -= 8;

View File

@ -58,7 +58,7 @@ public final class ArgumentHelper
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "number", "nil" ); if( index >= args.length ) throw badArgument( index, "number", "nil" );
Object value = args[ index ]; Object value = args[index];
if( value instanceof Number ) if( value instanceof Number )
{ {
return ((Number) value).doubleValue(); return ((Number) value).doubleValue();
@ -77,7 +77,7 @@ public final class ArgumentHelper
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "number", "nil" ); if( index >= args.length ) throw badArgument( index, "number", "nil" );
Object value = args[ index ]; Object value = args[index];
if( value instanceof Number ) if( value instanceof Number )
{ {
return checkReal( index, (Number) value ).longValue(); return checkReal( index, (Number) value ).longValue();
@ -96,7 +96,7 @@ public final class ArgumentHelper
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "boolean", "nil" ); if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
Object value = args[ index ]; Object value = args[index];
if( value instanceof Boolean ) if( value instanceof Boolean )
{ {
return (Boolean) value; return (Boolean) value;
@ -111,7 +111,7 @@ public final class ArgumentHelper
public static String getString( @Nonnull Object[] args, int index ) throws LuaException public static String getString( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "string", "nil" ); if( index >= args.length ) throw badArgument( index, "string", "nil" );
Object value = args[ index ]; Object value = args[index];
if( value instanceof String ) if( value instanceof String )
{ {
return (String) value; return (String) value;
@ -122,12 +122,12 @@ public final class ArgumentHelper
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings( "unchecked" )
@Nonnull @Nonnull
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
{ {
if( index >= args.length ) throw badArgument( index, "table", "nil" ); if( index >= args.length ) throw badArgument( index, "table", "nil" );
Object value = args[ index ]; Object value = args[index];
if( value instanceof Map ) if( value instanceof Map )
{ {
return (Map<Object, Object>) value; return (Map<Object, Object>) value;
@ -140,7 +140,7 @@ public final class ArgumentHelper
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[index] : null;
if( value == null ) if( value == null )
{ {
return def; return def;
@ -162,7 +162,7 @@ public final class ArgumentHelper
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[index] : null;
if( value == null ) if( value == null )
{ {
return def; return def;
@ -184,7 +184,7 @@ public final class ArgumentHelper
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[index] : null;
if( value == null ) if( value == null )
{ {
return def; return def;
@ -201,7 +201,7 @@ public final class ArgumentHelper
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[index] : null;
if( value == null ) if( value == null )
{ {
return def; return def;
@ -216,10 +216,10 @@ public final class ArgumentHelper
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings( "unchecked" )
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
{ {
Object value = index < args.length ? args[ index ] : null; Object value = index < args.length ? args[index] : null;
if( value == null ) if( value == null )
{ {
return def; return def;

View File

@ -49,13 +49,13 @@ public class FSAPI implements ILuaAPI
} }
@Override @Override
public void startup( ) public void startup()
{ {
m_fileSystem = m_env.getFileSystem(); m_fileSystem = m_env.getFileSystem();
} }
@Override @Override
public void shutdown( ) public void shutdown()
{ {
m_fileSystem = null; m_fileSystem = null;
} }
@ -94,11 +94,13 @@ public class FSAPI implements ILuaAPI
// list // list
String path = getString( args, 0 ); String path = getString( args, 0 );
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
try { try
{
String[] results = m_fileSystem.list( path ); String[] results = m_fileSystem.list( path );
Map<Object,Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
for(int i=0; i<results.length; ++i ) { for( int i = 0; i < results.length; i++ )
table.put( i+1, results[i] ); {
table.put( i + 1, results[i] );
} }
return new Object[] { table }; return new Object[] { table };
} }
@ -118,7 +120,7 @@ public class FSAPI implements ILuaAPI
{ {
// getName // getName
String path = getString( args, 0 ); String path = getString( args, 0 );
return new Object[]{ FileSystem.getName( path ) }; return new Object[] { FileSystem.getName( path ) };
} }
case 3: case 3:
{ {
@ -126,7 +128,7 @@ public class FSAPI implements ILuaAPI
String path = getString( args, 0 ); String path = getString( args, 0 );
try try
{ {
return new Object[]{ m_fileSystem.getSize( path ) }; return new Object[] { m_fileSystem.getSize( path ) };
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -137,41 +139,53 @@ public class FSAPI implements ILuaAPI
{ {
// exists // exists
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
return new Object[]{ m_fileSystem.exists( path ) }; {
} catch( FileSystemException e ) { return new Object[] { m_fileSystem.exists( path ) };
return new Object[]{ false }; }
catch( FileSystemException e )
{
return new Object[] { false };
} }
} }
case 5: case 5:
{ {
// isDir // isDir
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
return new Object[]{ m_fileSystem.isDir( path ) }; {
} catch( FileSystemException e ) { return new Object[] { m_fileSystem.isDir( path ) };
return new Object[]{ false }; }
catch( FileSystemException e )
{
return new Object[] { false };
} }
} }
case 6: case 6:
{ {
// isReadOnly // isReadOnly
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
return new Object[]{ m_fileSystem.isReadOnly( path ) }; {
} catch( FileSystemException e ) { return new Object[] { m_fileSystem.isReadOnly( path ) };
return new Object[]{ false }; }
catch( FileSystemException e )
{
return new Object[] { false };
} }
} }
case 7: case 7:
{ {
// makeDir // makeDir
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
m_fileSystem.makeDir( path ); m_fileSystem.makeDir( path );
return null; return null;
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -180,11 +194,14 @@ public class FSAPI implements ILuaAPI
// move // move
String path = getString( args, 0 ); String path = getString( args, 0 );
String dest = getString( args, 1 ); String dest = getString( args, 1 );
try { try
{
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
m_fileSystem.move( path, dest ); m_fileSystem.move( path, dest );
return null; return null;
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -193,11 +210,14 @@ public class FSAPI implements ILuaAPI
// copy // copy
String path = getString( args, 0 ); String path = getString( args, 0 );
String dest = getString( args, 1 ); String dest = getString( args, 1 );
try { try
{
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
m_fileSystem.copy( path, dest ); m_fileSystem.copy( path, dest );
return null; return null;
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -205,11 +225,14 @@ public class FSAPI implements ILuaAPI
{ {
// delete // delete
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
m_fileSystem.delete( path ); m_fileSystem.delete( path );
return null; return null;
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -219,7 +242,8 @@ public class FSAPI implements ILuaAPI
String path = getString( args, 0 ); String path = getString( args, 0 );
String mode = getString( args, 1 ); String mode = getString( args, 1 );
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
try { try
{
switch( mode ) switch( mode )
{ {
case "r": case "r":
@ -261,7 +285,9 @@ public class FSAPI implements ILuaAPI
default: default:
throw new LuaException( "Unsupported mode" ); throw new LuaException( "Unsupported mode" );
} }
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
return new Object[] { null, e.getMessage() }; return new Object[] { null, e.getMessage() };
} }
} }
@ -269,13 +295,16 @@ public class FSAPI implements ILuaAPI
{ {
// getDrive // getDrive
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
if( !m_fileSystem.exists( path ) ) if( !m_fileSystem.exists( path ) )
{ {
return null; return null;
} }
return new Object[]{ m_fileSystem.getMountLabel( path ) }; return new Object[] { m_fileSystem.getMountLabel( path ) };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -283,14 +312,17 @@ public class FSAPI implements ILuaAPI
{ {
// getFreeSpace // getFreeSpace
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
long freeSpace = m_fileSystem.getFreeSpace( path ); long freeSpace = m_fileSystem.getFreeSpace( path );
if( freeSpace >= 0 ) if( freeSpace >= 0 )
{ {
return new Object[]{ freeSpace }; return new Object[] { freeSpace };
} }
return new Object[]{ "unlimited" }; return new Object[] { "unlimited" };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -298,15 +330,19 @@ public class FSAPI implements ILuaAPI
{ {
// find // find
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
m_env.addTrackingChange( TrackingField.FS_OPS ); m_env.addTrackingChange( TrackingField.FS_OPS );
String[] results = m_fileSystem.find( path ); String[] results = m_fileSystem.find( path );
Map<Object,Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
for(int i=0; i<results.length; ++i ) { for( int i = 0; i < results.length; i++ )
table.put( i+1, results[i] ); {
table.put( i + 1, results[i] );
} }
return new Object[] { table }; return new Object[] { table };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
throw new LuaException( e.getMessage() ); throw new LuaException( e.getMessage() );
} }
} }
@ -314,11 +350,11 @@ public class FSAPI implements ILuaAPI
{ {
// getDir // getDir
String path = getString( args, 0 ); String path = getString( args, 0 );
return new Object[]{ FileSystem.getDirectory( path ) }; return new Object[] { FileSystem.getDirectory( path ) };
} }
default: default:
{ {
assert( false ); assert (false);
return null; return null;
} }
} }

View File

@ -44,7 +44,7 @@ public class HTTPAPI implements ILuaAPI
@Override @Override
public String[] getNames() public String[] getNames()
{ {
return new String[]{ return new String[] {
"http" "http"
}; };
} }
@ -95,7 +95,7 @@ public class HTTPAPI implements ILuaAPI
@Override @Override
public String[] getMethodNames() public String[] getMethodNames()
{ {
return new String[]{ return new String[] {
"request", "request",
"checkURL", "checkURL",
"websocket", "websocket",
@ -164,11 +164,11 @@ public class HTTPAPI implements ILuaAPI
{ {
m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( request ) ); m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( request ) );
} }
return new Object[]{ true }; return new Object[] { true };
} }
catch( HTTPRequestException e ) catch( HTTPRequestException e )
{ {
return new Object[]{ false, e.getMessage() }; return new Object[] { false, e.getMessage() };
} }
} }
case 1: case 1:
@ -186,11 +186,11 @@ public class HTTPAPI implements ILuaAPI
{ {
m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( check ) ); m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( check ) );
} }
return new Object[]{ true }; return new Object[] { true };
} }
catch( HTTPRequestException e ) catch( HTTPRequestException e )
{ {
return new Object[]{ false, e.getMessage() }; return new Object[] { false, e.getMessage() };
} }
} }
case 2: // websocket case 2: // websocket
@ -223,11 +223,11 @@ public class HTTPAPI implements ILuaAPI
{ {
m_httpTasks.add( connector ); m_httpTasks.add( connector );
} }
return new Object[]{ true }; return new Object[] { true };
} }
catch( HTTPRequestException e ) catch( HTTPRequestException e )
{ {
return new Object[]{ false, e.getMessage() }; return new Object[] { false, e.getMessage() };
} }
} }
default: default:

View File

@ -23,27 +23,39 @@ public interface IAPIEnvironment extends IComputerOwned
@Override @Override
Computer getComputer(); Computer getComputer();
int getComputerID(); int getComputerID();
IComputerEnvironment getComputerEnvironment(); IComputerEnvironment getComputerEnvironment();
Terminal getTerminal(); Terminal getTerminal();
FileSystem getFileSystem(); FileSystem getFileSystem();
void shutdown(); void shutdown();
void reboot(); void reboot();
void queueEvent( String event, Object[] args ); void queueEvent( String event, Object[] args );
void setOutput( int side, int output ); void setOutput( int side, int output );
int getOutput( int side ); int getOutput( int side );
int getInput( int side ); int getInput( int side );
void setBundledOutput( int side, int output ); void setBundledOutput( int side, int output );
int getBundledOutput( int side ); int getBundledOutput( int side );
int getBundledInput( int side ); int getBundledInput( int side );
void setPeripheralChangeListener( IPeripheralChangeListener listener ); void setPeripheralChangeListener( IPeripheralChangeListener listener );
IPeripheral getPeripheral( int side ); IPeripheral getPeripheral( int side );
String getLabel(); String getLabel();
void setLabel( String label ); void setLabel( String label );
void addTrackingChange( TrackingField field, long change ); void addTrackingChange( TrackingField field, long change );

View File

@ -55,11 +55,16 @@ public class OSAPI implements ILuaAPI
{ {
double t = m_day * 24.0 + m_time; double t = m_day * 24.0 + m_time;
double ot = m_day * 24.0 + m_time; double ot = m_day * 24.0 + m_time;
if( t < ot ) { if( t < ot )
{
return -1; return -1;
} else if( t > ot ) { }
else if( t > ot )
{
return 1; return 1;
} else { }
else
{
return 0; return 0;
} }
} }
@ -145,7 +150,7 @@ public class OSAPI implements ILuaAPI
double t = alarm.m_day * 24.0 + alarm.m_time; double t = alarm.m_day * 24.0 + alarm.m_time;
if( now >= t ) if( now >= t )
{ {
queueLuaEvent( "alarm", new Object[]{ entry.getKey() } ); queueLuaEvent( "alarm", new Object[] { entry.getKey() } );
it.remove(); it.remove();
} }
} }
@ -157,7 +162,7 @@ public class OSAPI implements ILuaAPI
} }
@Override @Override
public void shutdown( ) public void shutdown()
{ {
synchronized( m_timers ) synchronized( m_timers )
{ {
@ -194,28 +199,28 @@ public class OSAPI implements ILuaAPI
}; };
} }
private float getTimeForCalendar(Calendar c) private float getTimeForCalendar( Calendar c )
{ {
float time = c.get(Calendar.HOUR_OF_DAY); float time = c.get( Calendar.HOUR_OF_DAY );
time += c.get(Calendar.MINUTE) / 60.0f; time += c.get( Calendar.MINUTE ) / 60.0f;
time += c.get(Calendar.SECOND) / (60.0f * 60.0f); time += c.get( Calendar.SECOND ) / (60.0f * 60.0f);
return time; return time;
} }
private int getDayForCalendar(Calendar c) private int getDayForCalendar( Calendar c )
{ {
GregorianCalendar g = (c instanceof GregorianCalendar) ? (GregorianCalendar)c : new GregorianCalendar(); GregorianCalendar g = (c instanceof GregorianCalendar) ? (GregorianCalendar) c : new GregorianCalendar();
int year = c.get(Calendar.YEAR); int year = c.get( Calendar.YEAR );
int day = 0; int day = 0;
for( int y=1970; y<year; ++y ) for( int y = 1970; y < year; y++ )
{ {
day += g.isLeapYear(y) ? 366 : 365; day += g.isLeapYear( y ) ? 366 : 365;
} }
day += c.get(Calendar.DAY_OF_YEAR); day += c.get( Calendar.DAY_OF_YEAR );
return day; return day;
} }
private long getEpochForCalendar(Calendar c) private long getEpochForCalendar( Calendar c )
{ {
return c.getTime().getTime(); return c.getTime().getTime();
} }
@ -237,7 +242,7 @@ public class OSAPI implements ILuaAPI
double timer = getReal( args, 0 ); double timer = getReal( args, 0 );
synchronized( m_timers ) synchronized( m_timers )
{ {
m_timers.put( m_nextTimerToken, new Timer( (int)Math.round( timer / 0.05 ) ) ); m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
return new Object[] { m_nextTimerToken++ }; return new Object[] { m_nextTimerToken++ };
} }
} }

View File

@ -40,19 +40,21 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
public PeripheralWrapper( IPeripheral peripheral, String side ) public PeripheralWrapper( IPeripheral peripheral, String side )
{ {
super(m_environment); super( m_environment );
m_side = side; m_side = side;
m_peripheral = peripheral; m_peripheral = peripheral;
m_attached = false; m_attached = false;
m_type = peripheral.getType(); m_type = peripheral.getType();
m_methods = peripheral.getMethodNames(); m_methods = peripheral.getMethodNames();
assert( m_type != null ); assert (m_type != null);
assert( m_methods != null ); assert (m_methods != null);
m_methodMap = new HashMap<>(); m_methodMap = new HashMap<>();
for(int i=0; i<m_methods.length; ++i ) { for( int i = 0; i < m_methods.length; i++ )
if( m_methods[i] != null ) { {
if( m_methods[i] != null )
{
m_methodMap.put( m_methods[i], i ); m_methodMap.put( m_methods[i], i );
} }
} }
@ -235,7 +237,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
m_environment.setPeripheralChangeListener( this ); m_environment.setPeripheralChangeListener( this );
m_peripherals = new PeripheralWrapper[6]; m_peripherals = new PeripheralWrapper[6];
for(int i=0; i<6; ++i) for( int i = 0; i < 6; i++ )
{ {
m_peripherals[i] = null; m_peripherals[i] = null;
} }
@ -254,21 +256,26 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
{ {
// Queue a detachment // Queue a detachment
final PeripheralWrapper wrapper = m_peripherals[side]; final PeripheralWrapper wrapper = m_peripherals[side];
ComputerThread.queueTask(new ITask() { ComputerThread.queueTask( new ITask()
{
@Override @Override
public Computer getOwner() { public Computer getOwner()
{
return m_environment.getComputer(); return m_environment.getComputer();
} }
@Override @Override
public void execute() { public void execute()
synchronized (m_peripherals) { {
if (wrapper.isAttached()) { synchronized( m_peripherals )
{
if( wrapper.isAttached() )
{
wrapper.detach(); wrapper.detach();
} }
} }
} }
}, null); }, null );
// Queue a detachment event // Queue a detachment event
m_environment.queueEvent( "peripheral_detach", new Object[] { Computer.s_sideNames[side] } ); m_environment.queueEvent( "peripheral_detach", new Object[] { Computer.s_sideNames[side] } );
@ -288,14 +295,17 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
{ {
// Queue an attachment // Queue an attachment
final PeripheralWrapper wrapper = m_peripherals[side]; final PeripheralWrapper wrapper = m_peripherals[side];
ComputerThread.queueTask( new ITask() { ComputerThread.queueTask( new ITask()
{
@Override @Override
public Computer getOwner() { public Computer getOwner()
{
return m_environment.getComputer(); return m_environment.getComputer();
} }
@Override @Override
public void execute() { public void execute()
{
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
if( m_running && !wrapper.isAttached() ) if( m_running && !wrapper.isAttached() )
@ -323,12 +333,12 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
} }
@Override @Override
public void startup( ) public void startup()
{ {
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
m_running = true; m_running = true;
for( int i=0; i<6; ++i ) for( int i = 0; i < 6; i++ )
{ {
PeripheralWrapper wrapper = m_peripherals[i]; PeripheralWrapper wrapper = m_peripherals[i];
if( wrapper != null && !wrapper.isAttached() ) if( wrapper != null && !wrapper.isAttached() )
@ -340,12 +350,12 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
} }
@Override @Override
public void shutdown( ) public void shutdown()
{ {
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
m_running = false; m_running = false;
for( int i=0; i<6; ++i ) for( int i = 0; i < 6; i++ )
{ {
PeripheralWrapper wrapper = m_peripherals[i]; PeripheralWrapper wrapper = m_peripherals[i];
if( wrapper != null && wrapper.isAttached() ) if( wrapper != null && wrapper.isAttached() )
@ -382,7 +392,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
{ {
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
PeripheralWrapper p = m_peripherals[ side ]; PeripheralWrapper p = m_peripherals[side];
if( p != null ) if( p != null )
{ {
present = true; present = true;
@ -400,7 +410,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
{ {
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
PeripheralWrapper p = m_peripherals[ side ]; PeripheralWrapper p = m_peripherals[side];
if( p != null ) if( p != null )
{ {
type = p.getType(); type = p.getType();
@ -422,7 +432,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
{ {
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
PeripheralWrapper p = m_peripherals[ side ]; PeripheralWrapper p = m_peripherals[side];
if( p != null ) if( p != null )
{ {
methods = p.getMethods(); methods = p.getMethods();
@ -431,9 +441,10 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
} }
if( methods != null ) if( methods != null )
{ {
Map<Object,Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
for(int i=0; i<methods.length; ++i ) { for( int i = 0; i < methods.length; i++ )
table.put( i+1, methods[i] ); {
table.put( i + 1, methods[i] );
} }
return new Object[] { table }; return new Object[] { table };
} }
@ -451,7 +462,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
PeripheralWrapper p; PeripheralWrapper p;
synchronized( m_peripherals ) synchronized( m_peripherals )
{ {
p = m_peripherals[ side ]; p = m_peripherals[side];
} }
if( p != null ) if( p != null )
{ {
@ -472,7 +483,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
private int parseSide( Object[] args ) throws LuaException private int parseSide( Object[] args ) throws LuaException
{ {
String side = getString( args, 0 ); String side = getString( args, 0 );
for( int n=0; n<Computer.s_sideNames.length; ++n ) for( int n = 0; n < Computer.s_sideNames.length; n++ )
{ {
if( side.equals( Computer.s_sideNames[n] ) ) if( side.equals( Computer.s_sideNames[n] ) )
{ {

View File

@ -64,10 +64,10 @@ public class RedstoneAPI implements ILuaAPI
case 0: case 0:
{ {
// getSides // getSides
Map<Object,Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
for(int i=0; i< Computer.s_sideNames.length; ++i ) for( int i = 0; i < Computer.s_sideNames.length; i++ )
{ {
table.put( i+1, Computer.s_sideNames[i] ); table.put( i + 1, Computer.s_sideNames[i] );
} }
return new Object[] { table }; return new Object[] { table };
} }
@ -156,7 +156,7 @@ public class RedstoneAPI implements ILuaAPI
private int parseSide( Object[] args ) throws LuaException private int parseSide( Object[] args ) throws LuaException
{ {
String side = getString( args, 0 ); String side = getString( args, 0 );
for( int n=0; n<Computer.s_sideNames.length; ++n ) for( int n = 0; n < Computer.s_sideNames.length; n++ )
{ {
if( side.equals( Computer.s_sideNames[n] ) ) if( side.equals( Computer.s_sideNames[n] ) )
{ {

View File

@ -109,9 +109,12 @@ public class TermAPI implements ILuaAPI
{ {
// write // write
String text; String text;
if( args.length > 0 && args[0] != null ) { if( args.length > 0 && args[0] != null )
{
text = args[0].toString(); text = args[0].toString();
} else { }
else
{
text = ""; text = "";
} }
@ -128,7 +131,7 @@ public class TermAPI implements ILuaAPI
int y = getInt( args, 0 ); int y = getInt( args, 0 );
synchronized( m_terminal ) synchronized( m_terminal )
{ {
m_terminal.scroll(y); m_terminal.scroll( y );
} }
return null; return null;
} }
@ -260,7 +263,7 @@ public class TermAPI implements ILuaAPI
{ {
int hex = getInt( args, 1 ); int hex = getInt( args, 1 );
double[] rgb = Palette.decodeRGB8( hex ); double[] rgb = Palette.decodeRGB8( hex );
setColour( m_terminal, colour, rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] ); setColour( m_terminal, colour, rgb[0], rgb[1], rgb[2] );
} }
else else
{ {
@ -278,7 +281,7 @@ public class TermAPI implements ILuaAPI
int colour = 15 - parseColour( args ); int colour = 15 - parseColour( args );
synchronized( m_terminal ) synchronized( m_terminal )
{ {
if ( m_terminal.getPalette() != null ) if( m_terminal.getPalette() != null )
{ {
return ArrayUtils.toObject( m_terminal.getPalette().getColour( colour ) ); return ArrayUtils.toObject( m_terminal.getPalette().getColour( colour ) );
} }

View File

@ -58,7 +58,7 @@ public class BinaryReadableHandle extends HandleGeneric
checkOpen(); checkOpen();
try try
{ {
if( args.length > 0 && args[ 0 ] != null ) if( args.length > 0 && args[0] != null )
{ {
int count = getInt( args, 0 ); int count = getInt( args, 0 );
if( count < 0 ) if( count < 0 )
@ -104,7 +104,7 @@ public class BinaryReadableHandle extends HandleGeneric
} }
// Now just copy all the bytes across! // Now just copy all the bytes across!
byte[] bytes = new byte[ totalRead ]; byte[] bytes = new byte[totalRead];
int pos = 0; int pos = 0;
for( ByteBuffer part : parts ) for( ByteBuffer part : parts )
{ {

View File

@ -52,23 +52,23 @@ public class BinaryWritableHandle extends HandleGeneric
checkOpen(); checkOpen();
try try
{ {
if( args.length > 0 && args[ 0 ] instanceof Number ) if( args.length > 0 && args[0] instanceof Number )
{ {
int number = ((Number) args[ 0 ]).intValue(); int number = ((Number) args[0]).intValue();
single.clear(); single.clear();
single.put( (byte) number ); single.put( (byte) number );
single.flip(); single.flip();
m_writer.write( single ); m_writer.write( single );
} }
else if( args.length > 0 && args[ 0 ] instanceof String ) else if( args.length > 0 && args[0] instanceof String )
{ {
String value = (String) args[ 0 ]; String value = (String) args[0];
m_writer.write( ByteBuffer.wrap( StringUtil.encodeString( value ) ) ); m_writer.write( ByteBuffer.wrap( StringUtil.encodeString( value ) ) );
} }
else else
{ {
throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[ 0 ] : null ); throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[0] : null );
} }
return null; return null;
} }

View File

@ -115,7 +115,7 @@ public class EncodedReadableHandle extends HandleGeneric
else if( count <= BUFFER_SIZE ) else if( count <= BUFFER_SIZE )
{ {
// If we've got a small count, then allocate that and read it. // If we've got a small count, then allocate that and read it.
char[] chars = new char[ count ]; char[] chars = new char[count];
int read = m_reader.read( chars ); int read = m_reader.read( chars );
return read < 0 ? null : new Object[] { new String( chars, 0, read ) }; return read < 0 ? null : new Object[] { new String( chars, 0, read ) };
@ -123,7 +123,7 @@ public class EncodedReadableHandle extends HandleGeneric
else else
{ {
// If we've got a large count, read in bunches of 8192. // If we've got a large count, read in bunches of 8192.
char[] buffer = new char[ BUFFER_SIZE ]; char[] buffer = new char[BUFFER_SIZE];
// Read the initial set of characters, failing if none are read. // Read the initial set of characters, failing if none are read.
int read = m_reader.read( buffer, 0, Math.min( buffer.length, count ) ); int read = m_reader.read( buffer, 0, Math.min( buffer.length, count ) );

View File

@ -51,9 +51,9 @@ public class EncodedWritableHandle extends HandleGeneric
// write // write
checkOpen(); checkOpen();
String text; String text;
if( args.length > 0 && args[ 0 ] != null ) if( args.length > 0 && args[0] != null )
{ {
text = args[ 0 ].toString(); text = args[0].toString();
} }
else else
{ {
@ -74,9 +74,9 @@ public class EncodedWritableHandle extends HandleGeneric
// writeLine // writeLine
checkOpen(); checkOpen();
String text; String text;
if( args.length > 0 && args[ 0 ] != null ) if( args.length > 0 && args[0] != null )
{ {
text = args[ 0 ].toString(); text = args[0].toString();
} }
else else
{ {
@ -125,8 +125,8 @@ public class EncodedWritableHandle extends HandleGeneric
// Create a charset encoder with the same properties as StreamEncoder does for // Create a charset encoder with the same properties as StreamEncoder does for
// OutputStreams: namely, replace everything instead of erroring. // OutputStreams: namely, replace everything instead of erroring.
CharsetEncoder encoder = charset.newEncoder() CharsetEncoder encoder = charset.newEncoder()
.onMalformedInput( CodingErrorAction.REPLACE) .onMalformedInput( CodingErrorAction.REPLACE )
.onUnmappableCharacter(CodingErrorAction.REPLACE); .onUnmappableCharacter( CodingErrorAction.REPLACE );
return new BufferedWriter( Channels.newWriter( channel, encoder, -1 ) ); return new BufferedWriter( Channels.newWriter( channel, encoder, -1 ) );
} }
} }

View File

@ -70,11 +70,11 @@ public abstract class HandleGeneric implements ILuaObject
throw new LuaException( "bad argument #1 to 'seek' (invalid option '" + whence + "'" ); throw new LuaException( "bad argument #1 to 'seek' (invalid option '" + whence + "'" );
} }
return new Object[]{ channel.position() }; return new Object[] { channel.position() };
} }
catch( IllegalArgumentException e ) catch( IllegalArgumentException e )
{ {
return new Object[]{ false, "Position is negative" }; return new Object[] { false, "Position is negative" };
} }
catch( IOException e ) catch( IOException e )
{ {

View File

@ -110,7 +110,7 @@ public class HTTPRequest implements Runnable
{ {
// Queue the failure event if not. // Queue the failure event if not.
String error = e.getMessage(); String error = e.getMessage();
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, error == null ? "Could not connect" : error, null } ); m_environment.queueEvent( "http_failure", new Object[] { m_urlString, error == null ? "Could not connect" : error, null } );
return; return;
} }
@ -214,17 +214,17 @@ public class HTTPRequest implements Runnable
// Queue the appropriate event. // Queue the appropriate event.
if( responseSuccess ) if( responseSuccess )
{ {
m_environment.queueEvent( "http_success", new Object[]{ m_urlString, stream } ); m_environment.queueEvent( "http_success", new Object[] { m_urlString, stream } );
} }
else else
{ {
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, "Could not connect", stream } ); m_environment.queueEvent( "http_failure", new Object[] { m_urlString, "Could not connect", stream } );
} }
} }
catch( IOException e ) catch( IOException e )
{ {
// There was an error // There was an error
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, "Could not connect", null } ); m_environment.queueEvent( "http_failure", new Object[] { m_urlString, "Could not connect", null } );
} }
} }
@ -258,12 +258,12 @@ public class HTTPRequest implements Runnable
case 0: case 0:
{ {
// getResponseCode // getResponseCode
return new Object[]{ responseCode }; return new Object[] { responseCode };
} }
case 1: case 1:
{ {
// getResponseHeaders // getResponseHeaders
return new Object[]{ responseHeaders }; return new Object[] { responseHeaders };
} }
default: default:
{ {

View File

@ -76,7 +76,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
private void onClosed() private void onClosed()
{ {
close( true ); close( true );
computer.queueEvent( CLOSE_EVENT, new Object[]{ url } ); computer.queueEvent( CLOSE_EVENT, new Object[] { url } );
} }
@Override @Override
@ -107,7 +107,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
if( !handshaker.isHandshakeComplete() ) if( !handshaker.isHandshakeComplete() )
{ {
handshaker.finishHandshake( ch, (FullHttpResponse) msg ); handshaker.finishHandshake( ch, (FullHttpResponse) msg );
computer.queueEvent( SUCCESS_EVENT, new Object[]{ url, this } ); computer.queueEvent( SUCCESS_EVENT, new Object[] { url, this } );
return; return;
} }
@ -123,7 +123,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
String data = ((TextWebSocketFrame) frame).text(); String data = ((TextWebSocketFrame) frame).text();
computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, data.length() ); computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, data.length() );
computer.queueEvent( MESSAGE_EVENT, new Object[]{ url, data } ); computer.queueEvent( MESSAGE_EVENT, new Object[] { url, data } );
} }
else if( frame instanceof BinaryWebSocketFrame ) else if( frame instanceof BinaryWebSocketFrame )
{ {
@ -132,7 +132,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
data.readBytes( converted ); data.readBytes( converted );
computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, converted.length ); computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, converted.length );
computer.queueEvent( MESSAGE_EVENT, new Object[]{ url, converted } ); computer.queueEvent( MESSAGE_EVENT, new Object[] { url, converted } );
} }
else if( frame instanceof CloseWebSocketFrame ) else if( frame instanceof CloseWebSocketFrame )
{ {
@ -145,7 +145,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause ) public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause )
{ {
ctx.close(); ctx.close();
computer.queueEvent( FAILURE_EVENT, new Object[]{ computer.queueEvent( FAILURE_EVENT, new Object[] {
url, url,
cause instanceof WebSocketHandshakeException ? cause.getMessage() : "Could not connect" cause instanceof WebSocketHandshakeException ? cause.getMessage() : "Could not connect"
} ); } );
@ -155,7 +155,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
@Override @Override
public String[] getMethodNames() public String[] getMethodNames()
{ {
return new String[]{ "receive", "send", "close" }; return new String[] { "receive", "send", "close" };
} }
@Nullable @Nullable
@ -171,14 +171,14 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
Object[] event = context.pullEvent( MESSAGE_EVENT ); Object[] event = context.pullEvent( MESSAGE_EVENT );
if( event.length >= 3 && Objects.equal( event[1], url ) ) if( event.length >= 3 && Objects.equal( event[1], url ) )
{ {
return new Object[]{ event[2] }; return new Object[] { event[2] };
} }
} }
case 1: case 1:
{ {
checkOpen(); checkOpen();
String text = arguments.length > 0 && arguments[0] != null ? arguments[0].toString() : ""; String text = arguments.length > 0 && arguments[0] != null ? arguments[0].toString() : "";
boolean binary = optBoolean(arguments, 1, false); boolean binary = optBoolean( arguments, 1, false );
computer.addTrackingChange( TrackingField.WEBSOCKET_OUTGOING, text.length() ); computer.addTrackingChange( TrackingField.WEBSOCKET_OUTGOING, text.length() );
channel.writeAndFlush( binary channel.writeAndFlush( binary
? new BinaryWebSocketFrame( Unpooled.wrappedBuffer( StringUtil.encodeString( text ) ) ) ? new BinaryWebSocketFrame( Unpooled.wrappedBuffer( StringUtil.encodeString( text ) ) )

View File

@ -11,8 +11,8 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.filesystem.IFileSystem; import dan200.computercraft.api.filesystem.IFileSystem;
import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.ILuaAPI;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.core.apis.*; import dan200.computercraft.core.apis.*;
import dan200.computercraft.core.filesystem.FileSystem; import dan200.computercraft.core.filesystem.FileSystem;
@ -144,7 +144,7 @@ public class Computer
{ {
synchronized( m_computer.m_peripherals ) synchronized( m_computer.m_peripherals )
{ {
return m_computer.m_peripherals[ side ]; return m_computer.m_peripherals[side];
} }
} }
@ -337,7 +337,7 @@ public class Computer
m_inputChanged = false; m_inputChanged = false;
m_peripherals = new IPeripheral[6]; m_peripherals = new IPeripheral[6];
for( int i=0; i<6; ++i ) for( int i = 0; i < 6; i++ )
{ {
m_peripherals[i] = null; m_peripherals[i] = null;
} }
@ -466,7 +466,7 @@ public class Computer
// Advance our APIs // Advance our APIs
synchronized( m_apis ) synchronized( m_apis )
{ {
for(ILuaAPI api : m_apis) for( ILuaAPI api : m_apis )
{ {
api.update(); api.update();
} }
@ -480,16 +480,16 @@ public class Computer
if( m_internalOutputChanged ) if( m_internalOutputChanged )
{ {
boolean changed = false; boolean changed = false;
for( int i=0; i<6; ++i ) for( int i = 0; i < 6; i++ )
{ {
if( m_externalOutput[i] != m_internalOutput[i] ) if( m_externalOutput[i] != m_internalOutput[i] )
{ {
m_externalOutput[ i ] = m_internalOutput[ i ]; m_externalOutput[i] = m_internalOutput[i];
changed = true; changed = true;
} }
if( m_externalBundledOutput[i] != m_internalBundledOutput[i] ) if( m_externalBundledOutput[i] != m_internalBundledOutput[i] )
{ {
m_externalBundledOutput[ i ] = m_internalBundledOutput[ i ]; m_externalBundledOutput[i] = m_internalBundledOutput[i];
changed = true; changed = true;
} }
} }
@ -519,7 +519,8 @@ public class Computer
public boolean pollAndResetChanged() public boolean pollAndResetChanged()
{ {
synchronized(this) { synchronized( this )
{
boolean changed = m_externalOutputChanged; boolean changed = m_externalOutputChanged;
m_externalOutputChanged = false; m_externalOutputChanged = false;
return changed; return changed;
@ -735,7 +736,7 @@ public class Computer
ILuaMachine machine = new CobaltLuaMachine( this ); ILuaMachine machine = new CobaltLuaMachine( this );
// Add the APIs // Add the APIs
for(ILuaAPI api : m_apis) for( ILuaAPI api : m_apis )
{ {
machine.addAPI( api ); machine.addAPI( api );
api.startup(); api.startup();
@ -756,16 +757,19 @@ public class Computer
if( biosStream != null ) if( biosStream != null )
{ {
machine.loadBios( biosStream ); machine.loadBios( biosStream );
try { try
{
biosStream.close(); biosStream.close();
} catch( IOException e ) { }
catch( IOException e )
{
// meh // meh
} }
if( machine.isFinished() ) if( machine.isFinished() )
{ {
m_terminal.reset(); m_terminal.reset();
m_terminal.write("Error starting bios.lua" ); m_terminal.write( "Error starting bios.lua" );
m_terminal.setCursorPos( 0, 1 ); m_terminal.setCursorPos( 0, 1 );
m_terminal.write( "ComputerCraft may be installed incorrectly" ); m_terminal.write( "ComputerCraft may be installed incorrectly" );
@ -780,7 +784,7 @@ public class Computer
else else
{ {
m_terminal.reset(); m_terminal.reset();
m_terminal.write("Error loading bios.lua" ); m_terminal.write( "Error loading bios.lua" );
m_terminal.setCursorPos( 0, 1 ); m_terminal.setCursorPos( 0, 1 );
m_terminal.write( "ComputerCraft may be installed incorrectly" ); m_terminal.write( "ComputerCraft may be installed incorrectly" );
@ -804,7 +808,8 @@ public class Computer
// Turn the computercraft on // Turn the computercraft on
final Computer computer = this; final Computer computer = this;
ComputerThread.queueTask( new ITask() { ComputerThread.queueTask( new ITask()
{
@Override @Override
public Computer getOwner() public Computer getOwner()
{ {
@ -882,7 +887,8 @@ public class Computer
// Turn the computercraft off // Turn the computercraft off
final Computer computer = this; final Computer computer = this;
ComputerThread.queueTask( new ITask() { ComputerThread.queueTask( new ITask()
{
@Override @Override
public Computer getOwner() public Computer getOwner()
{ {
@ -932,7 +938,7 @@ public class Computer
// Reset redstone output // Reset redstone output
synchronized( m_internalOutput ) synchronized( m_internalOutput )
{ {
for( int i=0; i<6; ++i ) for( int i = 0; i < 6; i++ )
{ {
m_internalOutput[i] = 0; m_internalOutput[i] = 0;
m_internalBundledOutput[i] = 0; m_internalBundledOutput[i] = 0;
@ -962,7 +968,8 @@ public class Computer
} }
final Computer computer = this; final Computer computer = this;
ITask task = new ITask() { ITask task = new ITask()
{
@Override @Override
public Computer getOwner() public Computer getOwner()
{ {

View File

@ -5,6 +5,7 @@
*/ */
package dan200.computercraft.core.computer; package dan200.computercraft.core.computer;
import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.filesystem.IWritableMount;
@ -13,13 +14,20 @@ import java.io.InputStream;
public interface IComputerEnvironment public interface IComputerEnvironment
{ {
int getDay(); int getDay();
double getTimeOfDay(); double getTimeOfDay();
boolean isColour(); boolean isColour();
long getComputerSpaceLimit(); long getComputerSpaceLimit();
String getHostString(); String getHostString();
int assignNewID(); int assignNewID();
IWritableMount createSaveDirMount( String subPath, long capacity ); IWritableMount createSaveDirMount( String subPath, long capacity );
IMount createResourceMount( String domain, String subPath ); IMount createResourceMount( String domain, String subPath );
InputStream createResourceFile( String domain, String subPath ); InputStream createResourceFile( String domain, String subPath );
} }

View File

@ -9,5 +9,6 @@ package dan200.computercraft.core.computer;
public interface ITask public interface ITask
{ {
Computer getOwner(); Computer getOwner();
void execute(); void execute();
} }

View File

@ -31,7 +31,7 @@ public class ComboMount implements IMount
@Override @Override
public boolean exists( @Nonnull String path ) throws IOException public boolean exists( @Nonnull String path ) throws IOException
{ {
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.exists( path ) ) if( part.exists( path ) )
@ -45,7 +45,7 @@ public class ComboMount implements IMount
@Override @Override
public boolean isDirectory( @Nonnull String path ) throws IOException public boolean isDirectory( @Nonnull String path ) throws IOException
{ {
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.isDirectory( path ) ) if( part.isDirectory( path ) )
@ -62,7 +62,7 @@ public class ComboMount implements IMount
// Combine the lists from all the mounts // Combine the lists from all the mounts
List<String> foundFiles = null; List<String> foundFiles = null;
int foundDirs = 0; int foundDirs = 0;
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.exists( path ) && part.isDirectory( path ) ) if( part.exists( path ) && part.isDirectory( path ) )
@ -85,7 +85,7 @@ public class ComboMount implements IMount
{ {
// We found multiple directories, so filter for duplicates // We found multiple directories, so filter for duplicates
Set<String> seen = new HashSet<>(); Set<String> seen = new HashSet<>();
for(String file : foundFiles) for( String file : foundFiles )
{ {
if( seen.add( file ) ) if( seen.add( file ) )
{ {
@ -102,7 +102,7 @@ public class ComboMount implements IMount
@Override @Override
public long getSize( @Nonnull String path ) throws IOException public long getSize( @Nonnull String path ) throws IOException
{ {
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.exists( path ) ) if( part.exists( path ) )
@ -118,7 +118,7 @@ public class ComboMount implements IMount
@Deprecated @Deprecated
public InputStream openForRead( @Nonnull String path ) throws IOException public InputStream openForRead( @Nonnull String path ) throws IOException
{ {
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.exists( path ) && !part.isDirectory( path ) ) if( part.exists( path ) && !part.isDirectory( path ) )
@ -133,7 +133,7 @@ public class ComboMount implements IMount
@Override @Override
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
{ {
for( int i=m_parts.length-1; i>=0; --i ) for( int i = m_parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = m_parts[i];
if( part.exists( path ) && !part.isDirectory( path ) ) if( part.exists( path ) && !part.isDirectory( path ) )

View File

@ -45,7 +45,7 @@ public class FileSystem
public MountWrapper( String label, String location, IWritableMount mount ) public MountWrapper( String label, String location, IWritableMount mount )
{ {
this( label, location, (IMount)mount ); this( label, location, (IMount) mount );
m_writableMount = mount; m_writableMount = mount;
} }
@ -344,7 +344,8 @@ public class FileSystem
{ {
if( mount == null ) throw new NullPointerException(); if( mount == null ) throw new NullPointerException();
location = sanitizePath( location ); location = sanitizePath( location );
if( location.contains( ".." ) ) { if( location.contains( ".." ) )
{
throw new FileSystemException( "Cannot mount below the root" ); throw new FileSystemException( "Cannot mount below the root" );
} }
mount( new MountWrapper( label, location, mount ) ); mount( new MountWrapper( label, location, mount ) );
@ -382,11 +383,16 @@ public class FileSystem
path = sanitizePath( path, true ); path = sanitizePath( path, true );
childPath = sanitizePath( childPath, true ); childPath = sanitizePath( childPath, true );
if( path.isEmpty() ) { if( path.isEmpty() )
{
return childPath; return childPath;
} else if( childPath.isEmpty() ) { }
else if( childPath.isEmpty() )
{
return path; return path;
} else { }
else
{
return sanitizePath( path + '/' + childPath, true ); return sanitizePath( path + '/' + childPath, true );
} }
} }
@ -394,14 +400,18 @@ public class FileSystem
public static String getDirectory( String path ) public static String getDirectory( String path )
{ {
path = sanitizePath( path, true ); path = sanitizePath( path, true );
if( path.isEmpty() ) { if( path.isEmpty() )
{
return ".."; return "..";
} }
int lastSlash = path.lastIndexOf('/'); int lastSlash = path.lastIndexOf( '/' );
if( lastSlash >= 0 ) { if( lastSlash >= 0 )
{
return path.substring( 0, lastSlash ); return path.substring( 0, lastSlash );
} else { }
else
{
return ""; return "";
} }
} }
@ -409,14 +419,18 @@ public class FileSystem
public static String getName( String path ) public static String getName( String path )
{ {
path = sanitizePath( path, true ); path = sanitizePath( path, true );
if( path.isEmpty() ) { if( path.isEmpty() )
{
return "root"; return "root";
} }
int lastSlash = path.lastIndexOf('/'); int lastSlash = path.lastIndexOf( '/' );
if( lastSlash >= 0 ) { if( lastSlash >= 0 )
{
return path.substring( lastSlash + 1 ); return path.substring( lastSlash + 1 );
} else { }
else
{
return path; return path;
} }
} }
@ -447,8 +461,8 @@ public class FileSystem
} }
// Return list // Return list
String[] array = new String[ list.size() ]; String[] array = new String[list.size()];
list.toArray(array); list.toArray( array );
Arrays.sort( array ); Arrays.sort( array );
return array; return array;
} }
@ -479,7 +493,7 @@ public class FileSystem
int starIndex = wildPath.indexOf( '*' ); int starIndex = wildPath.indexOf( '*' );
if( starIndex == -1 ) if( starIndex == -1 )
{ {
return exists( wildPath ) ? new String[]{wildPath} : new String[0]; return exists( wildPath ) ? new String[] { wildPath } : new String[0];
} }
// Find the all non-wildcarded directories. For instance foo/bar/baz* -> foo/bar // Find the all non-wildcarded directories. For instance foo/bar/baz* -> foo/bar
@ -495,8 +509,8 @@ public class FileSystem
findIn( startDir, matches, wildPattern ); findIn( startDir, matches, wildPattern );
// Return matches // Return matches
String[] array = new String[ matches.size() ]; String[] array = new String[matches.size()];
matches.toArray(array); matches.toArray( array );
return array; return array;
} }
@ -546,16 +560,20 @@ public class FileSystem
{ {
sourcePath = sanitizePath( sourcePath ); sourcePath = sanitizePath( sourcePath );
destPath = sanitizePath( destPath ); destPath = sanitizePath( destPath );
if( isReadOnly( sourcePath ) || isReadOnly( destPath ) ) { if( isReadOnly( sourcePath ) || isReadOnly( destPath ) )
{
throw new FileSystemException( "Access denied" ); throw new FileSystemException( "Access denied" );
} }
if( !exists( sourcePath ) ) { if( !exists( sourcePath ) )
{
throw new FileSystemException( "No such file" ); throw new FileSystemException( "No such file" );
} }
if( exists( destPath ) ) { if( exists( destPath ) )
{
throw new FileSystemException( "File exists" ); throw new FileSystemException( "File exists" );
} }
if( contains( sourcePath, destPath ) ) { if( contains( sourcePath, destPath ) )
{
throw new FileSystemException( "Can't move a directory inside itself" ); throw new FileSystemException( "Can't move a directory inside itself" );
} }
copy( sourcePath, destPath ); copy( sourcePath, destPath );
@ -566,16 +584,20 @@ public class FileSystem
{ {
sourcePath = sanitizePath( sourcePath ); sourcePath = sanitizePath( sourcePath );
destPath = sanitizePath( destPath ); destPath = sanitizePath( destPath );
if( isReadOnly( destPath ) ) { if( isReadOnly( destPath ) )
{
throw new FileSystemException( "/" + destPath + ": Access denied" ); throw new FileSystemException( "/" + destPath + ": Access denied" );
} }
if( !exists( sourcePath ) ) { if( !exists( sourcePath ) )
{
throw new FileSystemException( "/" + sourcePath + ": No such file" ); throw new FileSystemException( "/" + sourcePath + ": No such file" );
} }
if( exists( destPath ) ) { if( exists( destPath ) )
{
throw new FileSystemException( "/" + destPath + ": File exists" ); throw new FileSystemException( "/" + destPath + ": File exists" );
} }
if( contains( sourcePath, destPath ) ) { if( contains( sourcePath, destPath ) )
{
throw new FileSystemException( "/" + sourcePath + ": Can't copy a directory inside itself" ); throw new FileSystemException( "/" + sourcePath + ": Can't copy a directory inside itself" );
} }
copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) ); copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) );
@ -707,9 +729,11 @@ public class FileSystem
while( it.hasNext() ) while( it.hasNext() )
{ {
MountWrapper mount = it.next(); MountWrapper mount = it.next();
if( contains( mount.getLocation(), path ) ) { if( contains( mount.getLocation(), path ) )
{
int len = toLocal( path, mount.getLocation() ).length(); int len = toLocal( path, mount.getLocation() ).length();
if( match == null || len < matchLength ) { if( match == null || len < matchLength )
{
match = mount; match = mount;
matchLength = len; matchLength = len;
} }
@ -733,6 +757,7 @@ public class FileSystem
} }
private static final Pattern threeDotsPattern = Pattern.compile( "^\\.{3,}$" ); private static final Pattern threeDotsPattern = Pattern.compile( "^\\.{3,}$" );
private static String sanitizePath( String path, boolean allowWildcards ) private static String sanitizePath( String path, boolean allowWildcards )
{ {
// Allow windowsy slashes // Allow windowsy slashes
@ -744,8 +769,9 @@ public class FileSystem
}; };
StringBuilder cleanName = new StringBuilder(); StringBuilder cleanName = new StringBuilder();
for( int i = 0; i < path.length(); i++ ) { for( int i = 0; i < path.length(); i++ )
char c = path.charAt(i); {
char c = path.charAt( i );
if( c >= 32 && Arrays.binarySearch( specialChars, c ) < 0 && (allowWildcards || c != '*') ) if( c >= 32 && Arrays.binarySearch( specialChars, c ) < 0 && (allowWildcards || c != '*') )
{ {
cleanName.append( c ); cleanName.append( c );
@ -754,7 +780,7 @@ public class FileSystem
path = cleanName.toString(); path = cleanName.toString();
// Collapse the string into its component parts, removing ..'s // Collapse the string into its component parts, removing ..'s
String[] parts = path.split("/"); String[] parts = path.split( "/" );
Stack<String> outputParts = new Stack<>(); Stack<String> outputParts = new Stack<>();
for( String part : parts ) for( String part : parts )
{ {
@ -799,10 +825,12 @@ public class FileSystem
// Recombine the output parts into a new string // Recombine the output parts into a new string
StringBuilder result = new StringBuilder( "" ); StringBuilder result = new StringBuilder( "" );
Iterator<String> it = outputParts.iterator(); Iterator<String> it = outputParts.iterator();
while( it.hasNext() ) { while( it.hasNext() )
{
String part = it.next(); String part = it.next();
result.append( part ); result.append( part );
if( it.hasNext() ) { if( it.hasNext() )
{
result.append( '/' ); result.append( '/' );
} }
} }
@ -815,11 +843,11 @@ public class FileSystem
pathA = sanitizePath( pathA ); pathA = sanitizePath( pathA );
pathB = sanitizePath( pathB ); pathB = sanitizePath( pathB );
if( pathB.equals("..") ) if( pathB.equals( ".." ) )
{ {
return false; return false;
} }
else if ( pathB.startsWith("../") ) else if( pathB.startsWith( "../" ) )
{ {
return false; return false;
} }
@ -842,11 +870,14 @@ public class FileSystem
path = sanitizePath( path ); path = sanitizePath( path );
location = sanitizePath( location ); location = sanitizePath( location );
assert( contains( location, path ) ); assert (contains( location, path ));
String local = path.substring( location.length() ); String local = path.substring( location.length() );
if( local.startsWith("/") ) { if( local.startsWith( "/" ) )
{
return local.substring( 1 ); return local.substring( 1 );
} else { }
else
{
return local; return local;
} }
} }

View File

@ -6,10 +6,12 @@
package dan200.computercraft.core.filesystem; package dan200.computercraft.core.filesystem;
public class FileSystemException extends Exception { public class FileSystemException extends Exception
{
private static final long serialVersionUID = -2500631644868104029L; private static final long serialVersionUID = -2500631644868104029L;
FileSystemException( String s ) { FileSystemException( String s )
{
super( s ); super( s );
} }
} }

View File

@ -145,7 +145,7 @@ public class CobaltLuaMachine implements ILuaMachine
if( ComputerCraft.debug_enable ) m_globals.load( state, new DebugLib() ); if( ComputerCraft.debug_enable ) m_globals.load( state, new DebugLib() );
// Register custom load/loadstring provider which automatically adds prefixes. // Register custom load/loadstring provider which automatically adds prefixes.
LibFunction.bind( state, m_globals, PrefixLoader.class, new String[]{ "load", "loadstring" } ); LibFunction.bind( state, m_globals, PrefixLoader.class, new String[] { "load", "loadstring" } );
// Remove globals we don't want to expose // Remove globals we don't want to expose
// m_globals.rawset( "collectgarbage", Constants.NIL ); // m_globals.rawset( "collectgarbage", Constants.NIL );
@ -296,13 +296,13 @@ public class CobaltLuaMachine implements ILuaMachine
{ {
LuaTable table = new LuaTable(); LuaTable table = new LuaTable();
String[] methods = object.getMethodNames(); String[] methods = object.getMethodNames();
for( int i = 0; i < methods.length; ++i ) for( int i = 0; i < methods.length; i++ )
{ {
if( methods[ i ] != null ) if( methods[i] != null )
{ {
final int method = i; final int method = i;
final ILuaObject apiObject = object; final ILuaObject apiObject = object;
final String methodName = methods[ i ]; final String methodName = methods[i];
table.rawset( methodName, new VarArgFunction() table.rawset( methodName, new VarArgFunction()
{ {
@Override @Override
@ -319,7 +319,7 @@ public class CobaltLuaMachine implements ILuaMachine
public Object[] pullEvent( String filter ) throws LuaException, InterruptedException public Object[] pullEvent( String filter ) throws LuaException, InterruptedException
{ {
Object[] results = pullEventRaw( filter ); Object[] results = pullEventRaw( filter );
if( results.length >= 1 && results[ 0 ].equals( "terminate" ) ) if( results.length >= 1 && results[0].equals( "terminate" ) )
{ {
throw new LuaException( "Terminated", 0 ); throw new LuaException( "Terminated", 0 );
} }
@ -373,9 +373,9 @@ public class CobaltLuaMachine implements ILuaMachine
Object[] results = task.execute(); Object[] results = task.execute();
if( results != null ) if( results != null )
{ {
Object[] eventArguments = new Object[ results.length + 2 ]; Object[] eventArguments = new Object[results.length + 2];
eventArguments[ 0 ] = taskID; eventArguments[0] = taskID;
eventArguments[ 1 ] = true; eventArguments[1] = true;
System.arraycopy( results, 0, eventArguments, 2, results.length ); System.arraycopy( results, 0, eventArguments, 2, results.length );
m_computer.queueEvent( "task_complete", eventArguments ); m_computer.queueEvent( "task_complete", eventArguments );
} }
@ -422,12 +422,12 @@ public class CobaltLuaMachine implements ILuaMachine
while( true ) while( true )
{ {
Object[] response = pullEvent( "task_complete" ); Object[] response = pullEvent( "task_complete" );
if( response.length >= 3 && response[ 1 ] instanceof Number && response[ 2 ] instanceof Boolean ) if( response.length >= 3 && response[1] instanceof Number && response[2] instanceof Boolean )
{ {
if( ((Number) response[ 1 ]).intValue() == taskID ) if( ((Number) response[1]).intValue() == taskID )
{ {
Object[] returnValues = new Object[ response.length - 3 ]; Object[] returnValues = new Object[response.length - 3];
if( (Boolean) response[ 2 ] ) if( (Boolean) response[2] )
{ {
// Extract the return values from the event and return them // Extract the return values from the event and return them
System.arraycopy( response, 3, returnValues, 0, returnValues.length ); System.arraycopy( response, 3, returnValues, 0, returnValues.length );
@ -436,9 +436,9 @@ public class CobaltLuaMachine implements ILuaMachine
else else
{ {
// Extract the error message from the event and raise it // Extract the error message from the event and raise it
if( response.length >= 4 && response[ 3 ] instanceof String ) if( response.length >= 4 && response[3] instanceof String )
{ {
throw new LuaException( (String) response[ 3 ] ); throw new LuaException( (String) response[3] );
} }
else else
{ {
@ -545,11 +545,11 @@ public class CobaltLuaMachine implements ILuaMachine
return Constants.NONE; return Constants.NONE;
} }
LuaValue[] values = new LuaValue[ objects.length ]; LuaValue[] values = new LuaValue[objects.length];
for( int i = 0; i < values.length; ++i ) for( int i = 0; i < values.length; i++ )
{ {
Object object = objects[ i ]; Object object = objects[i];
values[ i ] = toValue( object, null ); values[i] = toValue( object, null );
} }
return varargsOf( values ); return varargsOf( values );
} }
@ -632,12 +632,12 @@ public class CobaltLuaMachine implements ILuaMachine
private static Object[] toObjects( Varargs values, int startIdx ) private static Object[] toObjects( Varargs values, int startIdx )
{ {
int count = values.count(); int count = values.count();
Object[] objects = new Object[ count - startIdx + 1 ]; Object[] objects = new Object[count - startIdx + 1];
for( int n = startIdx; n <= count; ++n ) for( int n = startIdx; n <= count; n++ )
{ {
int i = n - startIdx; int i = n - startIdx;
LuaValue value = values.arg( n ); LuaValue value = values.arg( n );
objects[ i ] = toObject( value, null ); objects[i] = toObject( value, null );
} }
return objects; return objects;
} }
@ -650,7 +650,7 @@ public class CobaltLuaMachine implements ILuaMachine
@Override @Override
public Varargs invoke( LuaState state, Varargs args ) throws LuaError public Varargs invoke( LuaState state, Varargs args ) throws LuaError
{ {
switch (opcode) switch( opcode )
{ {
case 0: // "load", // ( func [,chunkname] ) -> chunk | nil, msg case 0: // "load", // ( func [,chunkname] ) -> chunk | nil, msg
{ {
@ -700,7 +700,8 @@ public class CobaltLuaMachine implements ILuaMachine
try try
{ {
s = OperationHelper.call( state, func ); s = OperationHelper.call( state, func );
} catch (LuaError e) }
catch( LuaError e )
{ {
throw new IOException( e ); throw new IOException( e );
} }
@ -713,7 +714,8 @@ public class CobaltLuaMachine implements ILuaMachine
try try
{ {
ls = s.strvalue(); ls = s.strvalue();
} catch (LuaError e) }
catch( LuaError e )
{ {
throw new IOException( e ); throw new IOException( e );
} }

View File

@ -5,6 +5,7 @@
*/ */
package dan200.computercraft.core.lua; package dan200.computercraft.core.lua;
import dan200.computercraft.api.lua.ILuaAPI; import dan200.computercraft.api.lua.ILuaAPI;
import java.io.InputStream; import java.io.InputStream;
@ -15,11 +16,15 @@ public interface ILuaMachine
void addAPI( ILuaAPI api ); void addAPI( ILuaAPI api );
void loadBios( InputStream bios ); void loadBios( InputStream bios );
void handleEvent( String eventName, Object[] arguments ); void handleEvent( String eventName, Object[] arguments );
void softAbort( String abortMessage ); void softAbort( String abortMessage );
void hardAbort( String abortMessage ); void hardAbort( String abortMessage );
boolean saveState( OutputStream output ); boolean saveState( OutputStream output );
boolean restoreState( InputStream input ); boolean restoreState( InputStream input );
boolean isFinished(); boolean isFinished();

View File

@ -5,6 +5,7 @@
*/ */
package dan200.computercraft.core.terminal; package dan200.computercraft.core.terminal;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -37,10 +38,10 @@ public class Terminal
m_cursorColour = 0; m_cursorColour = 0;
m_cursorBackgroundColour = 15; m_cursorBackgroundColour = 15;
m_text = new TextBuffer[ m_height ]; m_text = new TextBuffer[m_height];
m_textColour = new TextBuffer[ m_height ]; m_textColour = new TextBuffer[m_height];
m_backgroundColour = new TextBuffer[ m_height ]; m_backgroundColour = new TextBuffer[m_height];
for( int i=0; i<m_height; ++i ) for( int i = 0; i < m_height; i++ )
{ {
m_text[i] = new TextBuffer( ' ', m_width ); m_text[i] = new TextBuffer( ' ', m_width );
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
@ -68,11 +69,13 @@ public class Terminal
m_palette.resetColours(); m_palette.resetColours();
} }
public int getWidth() { public int getWidth()
{
return m_width; return m_width;
} }
public int getHeight() { public int getHeight()
{
return m_height; return m_height;
} }
@ -92,31 +95,31 @@ public class Terminal
m_width = width; m_width = width;
m_height = height; m_height = height;
m_text = new TextBuffer[ m_height ]; m_text = new TextBuffer[m_height];
m_textColour = new TextBuffer[ m_height ]; m_textColour = new TextBuffer[m_height];
m_backgroundColour = new TextBuffer[ m_height ]; m_backgroundColour = new TextBuffer[m_height];
for( int i=0; i<m_height; ++i ) for( int i = 0; i < m_height; i++ )
{ {
if( i >= oldHeight ) if( i >= oldHeight )
{ {
m_text[ i ] = new TextBuffer( ' ', m_width ); m_text[i] = new TextBuffer( ' ', m_width );
m_textColour[ i ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
m_backgroundColour[ i ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
} }
else if( m_width == oldWidth ) else if( m_width == oldWidth )
{ {
m_text[ i ] = oldText[ i ]; m_text[i] = oldText[i];
m_textColour[ i ] = oldTextColour[ i ]; m_textColour[i] = oldTextColour[i];
m_backgroundColour[ i ] = oldBackgroundColour[ i ]; m_backgroundColour[i] = oldBackgroundColour[i];
} }
else else
{ {
m_text[ i ] = new TextBuffer( ' ', m_width ); m_text[i] = new TextBuffer( ' ', m_width );
m_textColour[ i ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
m_backgroundColour[ i ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
m_text[ i ].write( oldText[ i ] ); m_text[i].write( oldText[i] );
m_textColour[ i ].write( oldTextColour[ i ] ); m_textColour[i].write( oldTextColour[i] );
m_backgroundColour[ i ].write( oldBackgroundColour[ i ] ); m_backgroundColour[i].write( oldBackgroundColour[i] );
} }
} }
m_changed = true; m_changed = true;
@ -195,9 +198,9 @@ public class Terminal
int y = m_cursorY; int y = m_cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < m_height )
{ {
m_text[ y ].write( text, x ); m_text[y].write( text, x );
m_textColour[ y ].write( textColour, x ); m_textColour[y].write( textColour, x );
m_backgroundColour[ y ].write( backgroundColour, x ); m_backgroundColour[y].write( backgroundColour, x );
m_changed = true; m_changed = true;
} }
} }
@ -208,9 +211,9 @@ public class Terminal
int y = m_cursorY; int y = m_cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < m_height )
{ {
m_text[ y ].write( text, x ); m_text[y].write( text, x );
m_textColour[ y ].fill( base16.charAt( m_cursorColour ), x, x + text.length() ); m_textColour[y].fill( base16.charAt( m_cursorColour ), x, x + text.length() );
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() ); m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() );
m_changed = true; m_changed = true;
} }
} }
@ -219,23 +222,23 @@ public class Terminal
{ {
if( yDiff != 0 ) if( yDiff != 0 )
{ {
TextBuffer[] newText = new TextBuffer[ m_height ]; TextBuffer[] newText = new TextBuffer[m_height];
TextBuffer[] newTextColour = new TextBuffer[ m_height ]; TextBuffer[] newTextColour = new TextBuffer[m_height];
TextBuffer[] newBackgroundColour = new TextBuffer[ m_height ]; TextBuffer[] newBackgroundColour = new TextBuffer[m_height];
for( int y = 0; y < m_height; ++y ) for( int y = 0; y < m_height; y++ )
{ {
int oldY = y + yDiff; int oldY = y + yDiff;
if( oldY >= 0 && oldY < m_height ) if( oldY >= 0 && oldY < m_height )
{ {
newText[ y ] = m_text[ oldY ]; newText[y] = m_text[oldY];
newTextColour[ y ] = m_textColour[ oldY ]; newTextColour[y] = m_textColour[oldY];
newBackgroundColour[ y ] = m_backgroundColour[ oldY ]; newBackgroundColour[y] = m_backgroundColour[oldY];
} }
else else
{ {
newText[ y ] = new TextBuffer( ' ', m_width ); newText[y] = new TextBuffer( ' ', m_width );
newTextColour[ y ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); newTextColour[y] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
newBackgroundColour[ y ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); newBackgroundColour[y] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
} }
} }
m_text = newText; m_text = newText;
@ -247,11 +250,11 @@ public class Terminal
public synchronized void clear() public synchronized void clear()
{ {
for( int y = 0; y < m_height; ++y ) for( int y = 0; y < m_height; y++ )
{ {
m_text[ y ].fill( ' ' ); m_text[y].fill( ' ' );
m_textColour[ y ].fill( base16.charAt( m_cursorColour ) ); m_textColour[y].fill( base16.charAt( m_cursorColour ) );
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ) ); m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
} }
m_changed = true; m_changed = true;
} }
@ -261,9 +264,9 @@ public class Terminal
int y = m_cursorY; int y = m_cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < m_height )
{ {
m_text[ y ].fill( ' ' ); m_text[y].fill( ' ' );
m_textColour[ y ].fill( base16.charAt( m_cursorColour ) ); m_textColour[y].fill( base16.charAt( m_cursorColour ) );
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ) ); m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
m_changed = true; m_changed = true;
} }
} }
@ -272,7 +275,7 @@ public class Terminal
{ {
if( y >= 0 && y < m_height ) if( y >= 0 && y < m_height )
{ {
return m_text[ y ]; return m_text[y];
} }
return null; return null;
} }
@ -287,18 +290,18 @@ public class Terminal
public synchronized TextBuffer getTextColourLine( int y ) public synchronized TextBuffer getTextColourLine( int y )
{ {
if( y>=0 && y<m_height ) if( y >= 0 && y < m_height )
{ {
return m_textColour[ y ]; return m_textColour[y];
} }
return null; return null;
} }
public synchronized TextBuffer getBackgroundColourLine( int y ) public synchronized TextBuffer getBackgroundColourLine( int y )
{ {
if( y>=0 && y<m_height ) if( y >= 0 && y < m_height )
{ {
return m_backgroundColour[ y ]; return m_backgroundColour[y];
} }
return null; return null;
} }
@ -325,13 +328,13 @@ public class Terminal
nbttagcompound.setBoolean( "term_cursorBlink", m_cursorBlink ); nbttagcompound.setBoolean( "term_cursorBlink", m_cursorBlink );
nbttagcompound.setInteger( "term_textColour", m_cursorColour ); nbttagcompound.setInteger( "term_textColour", m_cursorColour );
nbttagcompound.setInteger( "term_bgColour", m_cursorBackgroundColour ); nbttagcompound.setInteger( "term_bgColour", m_cursorBackgroundColour );
for( int n=0; n<m_height; ++n ) for( int n = 0; n < m_height; n++ )
{ {
nbttagcompound.setString( "term_text_" + n, m_text[n].toString() ); nbttagcompound.setString( "term_text_" + n, m_text[n].toString() );
nbttagcompound.setString( "term_textColour_" + n, m_textColour[n].toString() ); nbttagcompound.setString( "term_textColour_" + n, m_textColour[n].toString() );
nbttagcompound.setString( "term_textBgColour_" + n, m_backgroundColour[ n ].toString() ); nbttagcompound.setString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
} }
if(m_palette != null) if( m_palette != null )
{ {
m_palette.writeToNBT( nbttagcompound ); m_palette.writeToNBT( nbttagcompound );
} }
@ -346,7 +349,7 @@ public class Terminal
m_cursorColour = nbttagcompound.getInteger( "term_textColour" ); m_cursorColour = nbttagcompound.getInteger( "term_textColour" );
m_cursorBackgroundColour = nbttagcompound.getInteger( "term_bgColour" ); m_cursorBackgroundColour = nbttagcompound.getInteger( "term_bgColour" );
for( int n=0; n<m_height; ++n ) for( int n = 0; n < m_height; n++ )
{ {
m_text[n].fill( ' ' ); m_text[n].fill( ' ' );
if( nbttagcompound.hasKey( "term_text_" + n ) ) if( nbttagcompound.hasKey( "term_text_" + n ) )
@ -364,7 +367,7 @@ public class Terminal
m_backgroundColour[n].write( nbttagcompound.getString( "term_textBgColour_" + n ) ); m_backgroundColour[n].write( nbttagcompound.getString( "term_textBgColour_" + n ) );
} }
} }
if (m_palette != null) if( m_palette != null )
{ {
m_palette.readFromNBT( nbttagcompound ); m_palette.readFromNBT( nbttagcompound );
} }

View File

@ -13,7 +13,7 @@ public class TextBuffer
public TextBuffer( char c, int length ) public TextBuffer( char c, int length )
{ {
m_text = new char[length]; m_text = new char[length];
for( int i = 0; i < length; ++i ) for( int i = 0; i < length; i++ )
{ {
m_text[i] = c; m_text[i] = c;
} }
@ -27,12 +27,12 @@ public class TextBuffer
public TextBuffer( String text, int repetitions ) public TextBuffer( String text, int repetitions )
{ {
int textLength = text.length(); int textLength = text.length();
m_text = new char[ textLength * repetitions ]; m_text = new char[textLength * repetitions];
for( int i = 0; i < repetitions; ++i ) for( int i = 0; i < repetitions; i++ )
{ {
for( int j = 0; j < textLength; ++j ) for( int j = 0; j < textLength; j++ )
{ {
m_text[ j + i * textLength ] = text.charAt(j ); m_text[j + i * textLength] = text.charAt( j );
} }
} }
} }
@ -45,12 +45,12 @@ public class TextBuffer
public TextBuffer( TextBuffer text, int repetitions ) public TextBuffer( TextBuffer text, int repetitions )
{ {
int textLength = text.length(); int textLength = text.length();
m_text = new char[ textLength * repetitions ]; m_text = new char[textLength * repetitions];
for( int i = 0; i < repetitions; ++i ) for( int i = 0; i < repetitions; i++ )
{ {
for( int j = 0; j < textLength; ++j ) for( int j = 0; j < textLength; j++ )
{ {
m_text[ j + i * textLength ] = text.charAt(j ); m_text[j + i * textLength] = text.charAt( j );
} }
} }
} }
@ -94,7 +94,7 @@ public class TextBuffer
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, pos + text.length() ); end = Math.min( end, pos + text.length() );
end = Math.min( end, m_text.length ); end = Math.min( end, m_text.length );
for( int i=start; i<end; ++i ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( i - pos ); m_text[i] = text.charAt( i - pos );
} }
@ -116,7 +116,7 @@ public class TextBuffer
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, pos + text.length() ); end = Math.min( end, pos + text.length() );
end = Math.min( end, m_text.length ); end = Math.min( end, m_text.length );
for( int i=start; i<end; ++i ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( i - pos ); m_text[i] = text.charAt( i - pos );
} }
@ -136,7 +136,7 @@ public class TextBuffer
{ {
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, m_text.length ); end = Math.min( end, m_text.length );
for( int i=start; i<end; ++i ) for( int i = start; i < end; i++ )
{ {
m_text[i] = c; m_text[i] = c;
} }
@ -159,7 +159,7 @@ public class TextBuffer
end = Math.min( end, m_text.length ); end = Math.min( end, m_text.length );
int textLength = text.length(); int textLength = text.length();
for( int i=start; i<end; ++i ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( (i - pos) % textLength ); m_text[i] = text.charAt( (i - pos) % textLength );
} }
@ -182,7 +182,7 @@ public class TextBuffer
end = Math.min( end, m_text.length ); end = Math.min( end, m_text.length );
int textLength = text.length(); int textLength = text.length();
for( int i=start; i<end; ++i ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( (i - pos) % textLength ); m_text[i] = text.charAt( (i - pos) % textLength );
} }
@ -190,14 +190,14 @@ public class TextBuffer
public char charAt( int i ) public char charAt( int i )
{ {
return m_text[ i ]; return m_text[i];
} }
public void setChar( int i, char c ) public void setChar( int i, char c )
{ {
if( i >= 0 && i <m_text.length ) if( i >= 0 && i < m_text.length )
{ {
m_text[ i ] = c; m_text[i] = c;
} }
} }

View File

@ -6,11 +6,9 @@
package dan200.computercraft.server.proxy; package dan200.computercraft.server.proxy;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.network.ComputerCraftPacket;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.printer.TilePrinter; import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon; import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
@ -18,8 +16,6 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;

View File

@ -26,7 +26,7 @@ public class TextFormatter
* @see net.minecraft.client.gui.FontRenderer#getCharWidth(char) * @see net.minecraft.client.gui.FontRenderer#getCharWidth(char)
*/ */
private static final String CHARACTERS = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000"; private static final String CHARACTERS = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000";
private static final int[] CHAR_WIDTHS = new int[]{ private static final int[] CHAR_WIDTHS = new int[] {
6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 4,
4, 6, 7, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1, 4, 6, 7, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1,
1, 2, 5, 6, 6, 6, 6, 3, 5, 5, 5, 6, 2, 6, 2, 6, 1, 2, 5, 6, 6, 6, 6, 3, 5, 5, 5, 6, 2, 6, 2, 6,
@ -45,11 +45,11 @@ public class TextFormatter
7, 7, 7, 7, 9, 6, 7, 8, 7, 6, 6, 9, 7, 6, 7, 1 7, 7, 7, 7, 9, 6, 7, 8, 7, 6, 6, 9, 7, 6, 7, 1
}; };
private static final int[] EXTRA_CHARS = new int[]{ private static final int[] EXTRA_CHARS = new int[] {
'\u20e2', '\u261b', '\u20e2', '\u261b',
}; };
private static final byte[] EXTRA_WIDTHS = new byte[]{ private static final byte[] EXTRA_WIDTHS = new byte[] {
8, 4, 8, 4,
}; };

View File

@ -146,7 +146,7 @@ public class TextTable
{ {
ComputerCraftPacket packet = new ComputerCraftPacket(); ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.PostChat; packet.m_packetType = ComputerCraftPacket.PostChat;
packet.m_dataInt = new int[]{ id }; packet.m_dataInt = new int[] { id };
String[] lines = packet.m_dataString = new String[out.size()]; String[] lines = packet.m_dataString = new String[out.size()];
for( int i = 0; i < out.size(); i++ ) for( int i = 0; i < out.size(); i++ )

View File

@ -8,8 +8,8 @@ package dan200.computercraft.shared.common;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -25,7 +25,7 @@ public abstract class BlockDirectional extends BlockGeneric
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof IDirectionalTile ) if( tile != null && tile instanceof IDirectionalTile )
{ {
IDirectionalTile directional = (IDirectionalTile)tile; IDirectionalTile directional = (IDirectionalTile) tile;
return directional.getDirection(); return directional.getDirection();
} }
return EnumFacing.NORTH; return EnumFacing.NORTH;
@ -36,7 +36,7 @@ public abstract class BlockDirectional extends BlockGeneric
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof IDirectionalTile ) if( tile != null && tile instanceof IDirectionalTile )
{ {
IDirectionalTile directional = (IDirectionalTile)tile; IDirectionalTile directional = (IDirectionalTile) tile;
directional.setDirection( dir ); directional.setDirection( dir );
} }
} }

View File

@ -40,7 +40,9 @@ public abstract class BlockGeneric extends Block implements
} }
protected abstract IBlockState getDefaultBlockState( int damage, EnumFacing placedSide ); protected abstract IBlockState getDefaultBlockState( int damage, EnumFacing placedSide );
protected abstract TileGeneric createTile( IBlockState state ); protected abstract TileGeneric createTile( IBlockState state );
protected abstract TileGeneric createTile( int damage ); protected abstract TileGeneric createTile( int damage );
@Override @Override
@ -95,7 +97,7 @@ public abstract class BlockGeneric extends Block implements
// Drop items // Drop items
if( drops.size() > 0 ) if( drops.size() > 0 )
{ {
for (ItemStack item : drops) for( ItemStack item : drops )
{ {
dropItem( world, pos, item ); dropItem( world, pos, item );
} }
@ -115,7 +117,7 @@ public abstract class BlockGeneric extends Block implements
world.removeTileEntity( pos ); world.removeTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
generic.destroy(); generic.destroy();
} }
} }
@ -127,7 +129,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getPickedItem(); return generic.getPickedItem();
} }
return ItemStack.EMPTY; return ItemStack.EMPTY;
@ -139,7 +141,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.onActivate( player, side, hitX, hitY, hitZ ); return generic.onActivate( player, side, hitX, hitY, hitZ );
} }
return false; return false;
@ -152,7 +154,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
generic.onNeighbourChange(); generic.onNeighbourChange();
} }
} }
@ -163,7 +165,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric ) if( tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
generic.onNeighbourTileEntityChange( neighbour ); generic.onNeighbourTileEntityChange( neighbour );
} }
} }
@ -175,7 +177,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.isSolidOnSide( side.ordinal() ); return generic.isSolidOnSide( side.ordinal() );
} }
return false; return false;
@ -193,7 +195,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
if( generic.isImmuneToExplosion( exploder ) ) if( generic.isImmuneToExplosion( exploder ) )
{ {
return 2000.0f; return 2000.0f;
@ -210,7 +212,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getBounds(); return generic.getBounds();
} }
return FULL_BLOCK_AABB; return FULL_BLOCK_AABB;
@ -231,7 +233,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
// Get collision bounds // Get collision bounds
List<AxisAlignedBB> collision = new ArrayList<>( 1 ); List<AxisAlignedBB> collision = new ArrayList<>( 1 );
@ -258,7 +260,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
// Get collision bounds // Get collision bounds
List<AxisAlignedBB> collision = new ArrayList<>( 1 ); List<AxisAlignedBB> collision = new ArrayList<>( 1 );
@ -267,7 +269,7 @@ public abstract class BlockGeneric extends Block implements
// Add collision bounds to list // Add collision bounds to list
if( collision.size() > 0 ) if( collision.size() > 0 )
{ {
for (AxisAlignedBB localBounds : collision) for( AxisAlignedBB localBounds : collision )
{ {
addCollisionBoxToList( pos, bigBox, list, localBounds ); addCollisionBoxToList( pos, bigBox, list, localBounds );
} }
@ -288,7 +290,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getRedstoneConnectivity( side ); return generic.getRedstoneConnectivity( side );
} }
return false; return false;
@ -301,7 +303,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getRedstoneOutput( oppositeSide.getOpposite() ); return generic.getRedstoneOutput( oppositeSide.getOpposite() );
} }
return 0; return 0;
@ -319,7 +321,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric ) if( tile != null && tile instanceof TileGeneric )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getBundledRedstoneConnectivity( side ); return generic.getBundledRedstoneConnectivity( side );
} }
return false; return false;
@ -330,7 +332,7 @@ public abstract class BlockGeneric extends Block implements
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
{ {
TileGeneric generic = (TileGeneric)tile; TileGeneric generic = (TileGeneric) tile;
return generic.getBundledRedstoneOutput( side ); return generic.getBundledRedstoneOutput( side );
} }
return 0; return 0;

View File

@ -51,7 +51,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
ColourTracker tracker = new ColourTracker(); ColourTracker tracker = new ColourTracker();
for( int i = 0; i < inv.getSizeInventory(); ++i ) for( int i = 0; i < inv.getSizeInventory(); i++ )
{ {
ItemStack stack = inv.getStackInSlot( i ); ItemStack stack = inv.getStackInSlot( i );
@ -66,7 +66,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
int index = ColourUtils.getStackColour( stack ); int index = ColourUtils.getStackColour( stack );
if( index < 0 ) continue; if( index < 0 ) continue;
Colour colour = Colour.values()[ index ]; Colour colour = Colour.values()[index];
tracker.addColour( colour.getR(), colour.getG(), colour.getB() ); tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
} }
} }
@ -103,7 +103,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i ) for( int i = 0; i < results.size(); i++ )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) ); results.set( i, ForgeHooks.getContainerItem( stack ) );

View File

@ -8,8 +8,8 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -31,7 +31,7 @@ public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
Block block = world.getBlockState( pos ).getBlock(); Block block = world.getBlockState( pos ).getBlock();
if( block != null && block instanceof BlockGeneric ) if( block != null && block instanceof BlockGeneric )
{ {
BlockGeneric generic = (BlockGeneric)block; BlockGeneric generic = (BlockGeneric) block;
if( generic.getBundledRedstoneConnectivity( world, pos, side ) ) if( generic.getBundledRedstoneConnectivity( world, pos, side ) )
{ {
return generic.getBundledRedstoneOutput( world, pos, side ); return generic.getBundledRedstoneOutput( world, pos, side );

View File

@ -11,5 +11,6 @@ import net.minecraft.util.EnumFacing;
public interface IDirectionalTile public interface IDirectionalTile
{ {
EnumFacing getDirection(); EnumFacing getDirection();
void setDirection( EnumFacing dir ); void setDirection( EnumFacing dir );
} }

View File

@ -11,5 +11,6 @@ import dan200.computercraft.core.terminal.Terminal;
public interface ITerminal public interface ITerminal
{ {
Terminal getTerminal(); Terminal getTerminal();
boolean isColour(); boolean isColour();
} }

View File

@ -17,10 +17,10 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -41,7 +41,7 @@ public abstract class TileGeneric extends TileEntity
packet.m_packetType = ComputerCraftPacket.RequestTileEntityUpdate; packet.m_packetType = ComputerCraftPacket.RequestTileEntityUpdate;
BlockPos pos = getPos(); BlockPos pos = getPos();
packet.m_dataInt = new int[]{ pos.getX(), pos.getY(), pos.getZ() }; packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ() };
ComputerCraft.sendToServer( packet ); ComputerCraft.sendToServer( packet );
} }
} }
@ -56,7 +56,7 @@ public abstract class TileGeneric extends TileEntity
Block block = getWorld().getBlockState( getPos() ).getBlock(); Block block = getWorld().getBlockState( getPos() ).getBlock();
if( block != null && block instanceof BlockGeneric ) if( block != null && block instanceof BlockGeneric )
{ {
return (BlockGeneric)block; return (BlockGeneric) block;
} }
return null; return null;
} }
@ -159,7 +159,7 @@ public abstract class TileGeneric extends TileEntity
double range = getInteractRange( player ); double range = getInteractRange( player );
BlockPos pos = getPos(); BlockPos pos = getPos();
return player.getEntityWorld() == getWorld() && return player.getEntityWorld() == getWorld() &&
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= ( range * range ); player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= (range * range);
} }
return true; return true;
} }
@ -207,7 +207,7 @@ public abstract class TileGeneric extends TileEntity
@Nonnull @Nonnull
@Override @Override
public NBTTagCompound getUpdateTag () public NBTTagCompound getUpdateTag()
{ {
NBTTagCompound tag = super.getUpdateTag(); NBTTagCompound tag = super.getUpdateTag();
writeDescription( tag ); writeDescription( tag );
@ -215,9 +215,9 @@ public abstract class TileGeneric extends TileEntity
} }
@Override @Override
public void handleUpdateTag ( @Nonnull NBTTagCompound tag) public void handleUpdateTag( @Nonnull NBTTagCompound tag )
{ {
super.handleUpdateTag(tag); super.handleUpdateTag( tag );
readDescription( tag ); readDescription( tag );
} }
} }

View File

@ -82,7 +82,7 @@ public class CommandAPI implements ILuaAPI
sender.clearOutput(); sender.clearOutput();
int result = commandManager.executeCommand( sender, command ); int result = commandManager.executeCommand( sender, command );
return new Object[]{ (result > 0), sender.copyOutput() }; return new Object[] { (result > 0), sender.copyOutput() };
} }
catch( Throwable t ) catch( Throwable t )
{ {
@ -90,7 +90,7 @@ public class CommandAPI implements ILuaAPI
{ {
ComputerCraft.log.error( "Error running command.", t ); ComputerCraft.log.error( "Error running command.", t );
} }
return new Object[]{ false, createOutput( "Java Exception Thrown: " + t.toString() ) }; return new Object[] { false, createOutput( "Java Exception Thrown: " + t.toString() ) };
} }
} }
else else
@ -182,7 +182,7 @@ public class CommandAPI implements ILuaAPI
} }
} }
} }
return new Object[]{ result }; return new Object[] { result };
} ); } );
} }
case 3: case 3:
@ -219,24 +219,24 @@ public class CommandAPI implements ILuaAPI
{ {
throw new LuaException( "Co-ordinates out or range" ); throw new LuaException( "Co-ordinates out or range" );
} }
if( ( max.getX() - min.getX() + 1 ) * ( max.getY() - min.getY() + 1 ) * ( max.getZ() - min.getZ() + 1 ) > 4096 ) if( (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1) * (max.getZ() - min.getZ() + 1) > 4096 )
{ {
throw new LuaException( "Too many blocks" ); throw new LuaException( "Too many blocks" );
} }
int i=1; int i = 1;
Map<Object, Object> results = new HashMap<>(); Map<Object, Object> results = new HashMap<>();
for( int y=min.getY(); y<= max.getY(); ++y ) for( int y = min.getY(); y <= max.getY(); y++ )
{ {
for( int z = min.getZ(); z <= max.getZ(); ++z ) for( int z = min.getZ(); z <= max.getZ(); z++ )
{ {
for( int x = min.getX(); x <= max.getX(); ++x ) for( int x = min.getX(); x <= max.getX(); x++ )
{ {
BlockPos pos = new BlockPos( x, y, z ); BlockPos pos = new BlockPos( x, y, z );
results.put( i++, getBlockInfo( world, pos ) ); results.put( i++, getBlockInfo( world, pos ) );
} }
} }
} }
return new Object[]{ results }; return new Object[] { results };
} ); } );
} }
case 5: case 5:
@ -252,7 +252,7 @@ public class CommandAPI implements ILuaAPI
BlockPos position = new BlockPos( x, y, z ); BlockPos position = new BlockPos( x, y, z );
if( WorldUtil.isBlockInWorld( world, position ) ) if( WorldUtil.isBlockInWorld( world, position ) )
{ {
return new Object[]{ getBlockInfo( world, position ) }; return new Object[] { getBlockInfo( world, position ) };
} }
else else
{ {

View File

@ -18,8 +18,8 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -31,8 +31,8 @@ public class BlockCommandComputer extends BlockComputerBase
public static class Properties public static class Properties
{ {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create("state", ComputerState.class); public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
} }
// Members // Members
@ -54,7 +54,7 @@ public class BlockCommandComputer extends BlockComputerBase
@Override @Override
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockStateContainer(this, Properties.FACING, Properties.STATE ); return new BlockStateContainer( this, Properties.FACING, Properties.STATE );
} }
@Nonnull @Nonnull
@ -84,7 +84,7 @@ public class BlockCommandComputer extends BlockComputerBase
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof IComputerTile ) if( tile != null && tile instanceof IComputerTile )
{ {
IComputer computer = ((IComputerTile)tile).getComputer(); IComputer computer = ((IComputerTile) tile).getComputer();
if( computer != null && computer.isOn() ) if( computer != null && computer.isOn() )
{ {
if( computer.isCursorDisplayed() ) if( computer.isCursorDisplayed() )

View File

@ -33,9 +33,9 @@ public class BlockComputer extends BlockComputerBase
// Statics // Statics
public static class Properties public static class Properties
{ {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
public static final PropertyBool ADVANCED = PropertyBool.create("advanced"); public static final PropertyBool ADVANCED = PropertyBool.create( "advanced" );
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create("state", ComputerState.class); public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
} }
// Members // Members
@ -125,7 +125,7 @@ public class BlockComputer extends BlockComputerBase
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof IComputerTile ) if( tile != null && tile instanceof IComputerTile )
{ {
IComputer computer = ((IComputerTile)tile).getComputer(); IComputer computer = ((IComputerTile) tile).getComputer();
if( computer != null && computer.isOn() ) if( computer != null && computer.isOn() )
{ {
if( computer.isCursorDisplayed() ) if( computer.isCursorDisplayed() )
@ -144,15 +144,18 @@ public class BlockComputer extends BlockComputerBase
@Override @Override
public ComputerFamily getFamily( int damage ) public ComputerFamily getFamily( int damage )
{ {
return ((ItemComputer) Item.getItemFromBlock(this)).getFamily( damage ); return ((ItemComputer) Item.getItemFromBlock( this )).getFamily( damage );
} }
@Override @Override
public ComputerFamily getFamily( IBlockState state ) public ComputerFamily getFamily( IBlockState state )
{ {
if( state.getValue( Properties.ADVANCED ) ) { if( state.getValue( Properties.ADVANCED ) )
{
return ComputerFamily.Advanced; return ComputerFamily.Advanced;
} else { }
else
{
return ComputerFamily.Normal; return ComputerFamily.Normal;
} }
} }

View File

@ -13,8 +13,8 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -40,14 +40,17 @@ public abstract class BlockComputerBase extends BlockDirectional
} }
protected abstract IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide ); protected abstract IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide );
protected abstract ComputerFamily getFamily( int damage ); protected abstract ComputerFamily getFamily( int damage );
protected abstract ComputerFamily getFamily( IBlockState state ); protected abstract ComputerFamily getFamily( IBlockState state );
protected abstract TileComputerBase createTile( ComputerFamily family ); protected abstract TileComputerBase createTile( ComputerFamily family );
@Override @Override
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide ) protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
{ {
ItemComputerBase item = (ItemComputerBase)Item.getItemFromBlock( this ); ItemComputerBase item = (ItemComputerBase) Item.getItemFromBlock( this );
return getDefaultBlockState( item.getFamily( damage ), placedSide ); return getDefaultBlockState( item.getFamily( damage ), placedSide );
} }
@ -73,7 +76,7 @@ public abstract class BlockComputerBase extends BlockDirectional
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileComputerBase ) if( tile != null && tile instanceof TileComputerBase )
{ {
TileComputerBase computer = (TileComputerBase)tile; TileComputerBase computer = (TileComputerBase) tile;
computer.updateInput(); computer.updateInput();
} }
} }

View File

@ -13,8 +13,12 @@ import dan200.computercraft.shared.computer.core.IComputer;
public interface IComputerTile extends ITerminalTile public interface IComputerTile extends ITerminalTile
{ {
void setComputerID( int id ); void setComputerID( int id );
void setLabel( String label ); void setLabel( String label );
IComputer getComputer(); IComputer getComputer();
IComputer createComputer(); IComputer createComputer();
ComputerFamily getFamily(); ComputerFamily getFamily();
} }

View File

@ -16,9 +16,12 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.CommandBlockBaseLogic; import net.minecraft.tileentity.CommandBlockBaseLogic;
import net.minecraft.util.math.*; import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.*; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.*; 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.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -125,6 +125,6 @@ public class TileComputer extends TileComputerBase
@Override @Override
protected int remapLocalSide( int localSide ) protected int remapLocalSide( int localSide )
{ {
return s_remapSide[ localSide ]; return s_remapSide[localSide];
} }
} }

View File

@ -55,7 +55,7 @@ public abstract class TileComputerBase extends TileGeneric
Block block = super.getBlock(); Block block = super.getBlock();
if( block != null && block instanceof BlockComputerBase ) if( block != null && block instanceof BlockComputerBase )
{ {
return (BlockComputerBase)block; return (BlockComputerBase) block;
} }
return null; return null;
} }
@ -368,7 +368,7 @@ public abstract class TileComputerBase extends TileGeneric
for( EnumFacing dir : EnumFacing.VALUES ) for( EnumFacing dir : EnumFacing.VALUES )
{ {
BlockPos offset = pos.offset( dir ); BlockPos offset = pos.offset( dir );
if ( offset.equals( neighbour ) ) if( offset.equals( neighbour ) )
{ {
updateSideInput( computer, dir, offset ); updateSideInput( computer, dir, offset );
break; break;

View File

@ -11,15 +11,22 @@ import dan200.computercraft.shared.common.ITerminal;
public interface IComputer extends ITerminal public interface IComputer extends ITerminal
{ {
int getInstanceID(); int getInstanceID();
int getID(); int getID();
String getLabel(); String getLabel();
boolean isOn(); boolean isOn();
boolean isCursorDisplayed(); boolean isCursorDisplayed();
void turnOn(); void turnOn();
void shutdown(); void shutdown();
void reboot(); void reboot();
void queueEvent( String event ); void queueEvent( String event );
void queueEvent( String event, Object[] arguments ); void queueEvent( String event, Object[] arguments );
} }

View File

@ -65,7 +65,8 @@ public class ServerComputer extends ServerTerminal
m_ticksSincePing = 0; m_ticksSincePing = 0;
} }
public ComputerFamily getFamily(){ public ComputerFamily getFamily()
{
return m_family; return m_family;
} }
@ -145,7 +146,8 @@ public class ServerComputer extends ServerTerminal
m_changed = true; m_changed = true;
} }
private ComputerCraftPacket createComputerPacket() { private ComputerCraftPacket createComputerPacket()
{
ComputerCraftPacket packet = new ComputerCraftPacket(); ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.ComputerChanged; packet.m_packetType = ComputerCraftPacket.ComputerChanged;
packet.m_dataInt = new int[] { getInstanceID() }; packet.m_dataInt = new int[] { getInstanceID() };
@ -154,7 +156,8 @@ public class ServerComputer extends ServerTerminal
return packet; return packet;
} }
protected ComputerCraftPacket createTerminalPacket() { protected ComputerCraftPacket createTerminalPacket()
{
ComputerCraftPacket packet = new ComputerCraftPacket(); ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.ComputerTerminalChanged; packet.m_packetType = ComputerCraftPacket.ComputerTerminalChanged;
packet.m_dataInt = new int[] { getInstanceID() }; packet.m_dataInt = new int[] { getInstanceID() };
@ -163,9 +166,9 @@ public class ServerComputer extends ServerTerminal
return packet; return packet;
} }
public void broadcastState(boolean force) public void broadcastState( boolean force )
{ {
if(hasOutputChanged() || force) if( hasOutputChanged() || force )
{ {
// Send computer state to all clients // Send computer state to all clients
ComputerCraft.sendToAllPlayers( createComputerPacket() ); ComputerCraft.sendToAllPlayers( createComputerPacket() );
@ -349,7 +352,7 @@ public class ServerComputer extends ServerTerminal
@Override @Override
public int getDay() public int getDay()
{ {
return (int)((m_world.getWorldTime() + 6000) / 24000) + 1; return (int) ((m_world.getWorldTime() + 6000) / 24000) + 1;
} }
@Override @Override

View File

@ -33,7 +33,7 @@ public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
computer.update(); computer.update();
if( computer.hasTerminalChanged() || computer.hasOutputChanged() ) if( computer.hasTerminalChanged() || computer.hasOutputChanged() )
{ {
computer.broadcastState(false); computer.broadcastState( false );
} }
} }
} }
@ -44,7 +44,7 @@ public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
{ {
//System.out.println( "ADD SERVER COMPUTER " + instanceID ); //System.out.println( "ADD SERVER COMPUTER " + instanceID );
super.add( instanceID, computer ); super.add( instanceID, computer );
computer.broadcastState(true); computer.broadcastState( true );
//System.out.println( getComputers().size() + " SERVER COMPUTERS" ); //System.out.println( getComputers().size() + " SERVER COMPUTERS" );
} }

View File

@ -36,8 +36,8 @@ public class ComputerItemFactory
@Nonnull @Nonnull
public static ItemStack create( int id, String label, ComputerFamily family ) public static ItemStack create( int id, String label, ComputerFamily family )
{ {
ItemComputer computer = ((ItemComputer)Item.getItemFromBlock( ComputerCraft.Blocks.computer )); ItemComputer computer = ((ItemComputer) Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
ItemCommandComputer commandComputer = ((ItemCommandComputer)Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer )); ItemCommandComputer commandComputer = ((ItemCommandComputer) Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer ));
switch( family ) switch( family )
{ {
case Normal: case Normal:

View File

@ -14,7 +14,10 @@ import javax.annotation.Nonnull;
public interface IComputerItem public interface IComputerItem
{ {
int getComputerID( @Nonnull ItemStack stack ); int getComputerID( @Nonnull ItemStack stack );
String getLabel( @Nonnull ItemStack stack ); String getLabel( @Nonnull ItemStack stack );
ComputerFamily getFamily( @Nonnull ItemStack stack ); ComputerFamily getFamily( @Nonnull ItemStack stack );
ItemStack withFamily(@Nonnull ItemStack stack, @Nonnull ComputerFamily family);
ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family );
} }

View File

@ -14,7 +14,6 @@ import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -28,9 +28,9 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
{ {
// See if we match the recipe, and extract the input computercraft ID // See if we match the recipe, and extract the input computercraft ID
ItemStack computerStack = null; ItemStack computerStack = null;
for( int y = 0; y < 3; ++y ) for( int y = 0; y < 3; y++ )
{ {
for( int x = 0; x < 3; ++x ) for( int x = 0; x < 3; x++ )
{ {
ItemStack stack = inventory.getStackInRowAndColumn( x, y ); ItemStack stack = inventory.getStackInRowAndColumn( x, y );
Ingredient target = getIngredients().get( x + y * 3 ); Ingredient target = getIngredients().get( x + y * 3 );
@ -50,9 +50,9 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
@Override @Override
public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory ) public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{ {
for( int y = 0; y < 3; ++y ) for( int y = 0; y < 3; y++ )
{ {
for( int x = 0; x < 3; ++x ) for( int x = 0; x < 3; x++ )
{ {
ItemStack item = inventory.getStackInRowAndColumn( x, y ); ItemStack item = inventory.getStackInRowAndColumn( x, y );

View File

@ -42,10 +42,10 @@ public final class IntegrationCharset
} }
@SubscribeEvent @SubscribeEvent
public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event) public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event )
{ {
TileEntity tile = event.getObject(); TileEntity tile = event.getObject();
if(tile instanceof TileGeneric) if( tile instanceof TileGeneric )
{ {
event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) ); event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) );
} }

View File

@ -28,7 +28,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
if( nbt == null ) if( nbt == null )
{ {
nbt = new NBTTagCompound(); nbt = new NBTTagCompound();
stack.setTagCompound(nbt); stack.setTagCompound( nbt );
} }
nbt.setInteger( "color", colour ); nbt.setInteger( "color", colour );
ComputerCraft.Items.diskExpanded.setDiskID( stack, id ); ComputerCraft.Items.diskExpanded.setDiskID( stack, id );
@ -72,7 +72,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
} }
else else
{ {
return Colour.values()[ Math.min( 15, stack.getItemDamage() ) ].getHex(); return Colour.values()[Math.min( 15, stack.getItemDamage() )].getHex();
} }
} }
} }

View File

@ -47,9 +47,9 @@ public class ItemPrintout extends Item
public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list ) public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{ {
if( !isInCreativeTab( tabs ) ) return; if( !isInCreativeTab( tabs ) ) return;
list.add( createSingleFromTitleAndText( null, new String[ LINES_PER_PAGE ], new String[ LINES_PER_PAGE ] ) ); 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 ] ) ); list.add( createMultipleFromTitleAndText( null, new String[2 * LINES_PER_PAGE], new String[2 * LINES_PER_PAGE] ) );
list.add( createBookFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); list.add( createBookFromTitleAndText( null, new String[2 * LINES_PER_PAGE], new String[2 * LINES_PER_PAGE] ) );
} }
@Override @Override
@ -133,21 +133,21 @@ public class ItemPrintout extends Item
if( text != null ) if( text != null )
{ {
nbt.setInteger( "pages", text.length / LINES_PER_PAGE ); nbt.setInteger( "pages", text.length / LINES_PER_PAGE );
for(int i=0; i<text.length; ++i) for( int i = 0; i < text.length; i++ )
{ {
if( text[i] != null ) if( text[i] != null )
{ {
nbt.setString( "line"+i, text[i] ); nbt.setString( "line" + i, text[i] );
} }
} }
} }
if( colours != null ) if( colours != null )
{ {
for(int i=0; i<colours.length; ++i) for( int i = 0; i < colours.length; i++ )
{ {
if( colours[i] != null ) if( colours[i] != null )
{ {
nbt.setString( "colour"+i, colours[i] ); nbt.setString( "colour" + i, colours[i] );
} }
} }
} }
@ -221,11 +221,11 @@ public class ItemPrintout extends Item
NBTTagCompound nbt = stack.getTagCompound(); NBTTagCompound nbt = stack.getTagCompound();
int numLines = getPageCount( stack ) * LINES_PER_PAGE; int numLines = getPageCount( stack ) * LINES_PER_PAGE;
String[] lines = new String[numLines]; String[] lines = new String[numLines];
for( int i=0; i<lines.length; ++i ) for( int i = 0; i < lines.length; i++ )
{ {
if( nbt != null ) if( nbt != null )
{ {
lines[i] = nbt.getString( "line"+i ); lines[i] = nbt.getString( "line" + i );
} }
else else
{ {
@ -240,11 +240,11 @@ public class ItemPrintout extends Item
NBTTagCompound nbt = stack.getTagCompound(); NBTTagCompound nbt = stack.getTagCompound();
int numLines = getPageCount( stack ) * LINES_PER_PAGE; int numLines = getPageCount( stack ) * LINES_PER_PAGE;
String[] lines = new String[numLines]; String[] lines = new String[numLines];
for( int i=0; i<lines.length; ++i ) for( int i = 0; i < lines.length; i++ )
{ {
if( nbt != null ) if( nbt != null )
{ {
lines[i] = nbt.getString( "colour"+i ); lines[i] = nbt.getString( "colour" + i );
} }
else else
{ {

View File

@ -33,7 +33,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
boolean paperFound = false; boolean paperFound = false;
boolean redstoneFound = false; boolean redstoneFound = false;
for( int i = 0; i < inv.getSizeInventory(); ++i ) for( int i = 0; i < inv.getSizeInventory(); i++ )
{ {
ItemStack stack = inv.getStackInSlot( i ); ItemStack stack = inv.getStackInSlot( i );
@ -65,7 +65,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
{ {
ColourTracker tracker = new ColourTracker(); ColourTracker tracker = new ColourTracker();
for( int i = 0; i < inv.getSizeInventory(); ++i ) for( int i = 0; i < inv.getSizeInventory(); i++ )
{ {
ItemStack stack = inv.getStackInSlot( i ); ItemStack stack = inv.getStackInSlot( i );
@ -76,7 +76,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
int index = ColourUtils.getStackColour( stack ); int index = ColourUtils.getStackColour( stack );
if( index < 0 ) continue; if( index < 0 ) continue;
Colour colour = Colour.values()[ index ]; Colour colour = Colour.values()[index];
tracker.addColour( colour.getR(), colour.getG(), colour.getB() ); tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
} }
} }
@ -108,7 +108,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i ) for( int i = 0; i < results.size(); i++ )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) ); results.set( i, ForgeHooks.getContainerItem( stack ) );

View File

@ -8,7 +8,6 @@ package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
@ -62,11 +61,11 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
boolean stringFound = false; boolean stringFound = false;
boolean leatherFound = false; boolean leatherFound = false;
boolean printoutFound = false; boolean printoutFound = false;
for( int y=0; y<inventory.getHeight(); ++y ) for( int y = 0; y < inventory.getHeight(); y++ )
{ {
for( int x=0; x<inventory.getWidth(); ++x ) for( int x = 0; x < inventory.getWidth(); x++ )
{ {
ItemStack stack = inventory.getStackInRowAndColumn(x, y); ItemStack stack = inventory.getStackInRowAndColumn( x, y );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
if( stack.getItem() instanceof ItemPrintout && ItemPrintout.getType( stack ) != ItemPrintout.Type.Book ) if( stack.getItem() instanceof ItemPrintout && ItemPrintout.getType( stack ) != ItemPrintout.Type.Book )
@ -75,7 +74,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
{ {
printouts = new ItemStack[9]; printouts = new ItemStack[9];
} }
printouts[ numPrintouts ] = stack; printouts[numPrintouts] = stack;
numPages = numPages + ItemPrintout.getPageCount( stack ); numPages = numPages + ItemPrintout.getPageCount( stack );
numPrintouts++; numPrintouts++;
printoutFound = true; printoutFound = true;
@ -86,7 +85,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
{ {
printouts = new ItemStack[9]; printouts = new ItemStack[9];
} }
printouts[ numPrintouts ] = stack; printouts[numPrintouts] = stack;
numPages++; numPages++;
numPrintouts++; numPrintouts++;
} }
@ -109,11 +108,11 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
// Build some pages with what was passed in // Build some pages with what was passed in
if( numPages <= ItemPrintout.MAX_PAGES && stringFound && printoutFound && numPrintouts >= (leatherFound ? 1 : 2) ) if( numPages <= ItemPrintout.MAX_PAGES && stringFound && printoutFound && numPrintouts >= (leatherFound ? 1 : 2) )
{ {
String[] text = new String[ numPages * ItemPrintout.LINES_PER_PAGE ]; String[] text = new String[numPages * ItemPrintout.LINES_PER_PAGE];
String[] colours = new String[ numPages * ItemPrintout.LINES_PER_PAGE ]; String[] colours = new String[numPages * ItemPrintout.LINES_PER_PAGE];
int line = 0; int line = 0;
for( int printout=0; printout<numPrintouts; ++printout ) for( int printout = 0; printout < numPrintouts; ++printout )
{ {
ItemStack stack = printouts[printout]; ItemStack stack = printouts[printout];
if( stack.getItem() instanceof ItemPrintout ) if( stack.getItem() instanceof ItemPrintout )
@ -121,20 +120,20 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
// Add a printout // Add a printout
String[] pageText = ItemPrintout.getText( printouts[printout] ); String[] pageText = ItemPrintout.getText( printouts[printout] );
String[] pageColours = ItemPrintout.getColours( printouts[printout] ); String[] pageColours = ItemPrintout.getColours( printouts[printout] );
for( int pageLine=0; pageLine<pageText.length; ++pageLine ) for( int pageLine = 0; pageLine < pageText.length; ++pageLine )
{ {
text[ line ] = pageText[ pageLine ]; text[line] = pageText[pageLine];
colours[ line ] = pageColours[ pageLine ]; colours[line] = pageColours[pageLine];
line++; line++;
} }
} }
else else
{ {
// Add a blank page // Add a blank page
for( int pageLine=0; pageLine<ItemPrintout.LINES_PER_PAGE; ++pageLine ) for( int pageLine = 0; pageLine < ItemPrintout.LINES_PER_PAGE; ++pageLine )
{ {
text[ line ] = ""; text[line] = "";
colours[ line ] = ""; colours[line] = "";
line++; line++;
} }
} }
@ -164,7 +163,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
{ {
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
for( int i = 0; i < results.size(); ++i ) for( int i = 0; i < results.size(); i++ )
{ {
ItemStack stack = inventoryCrafting.getStackInSlot( i ); ItemStack stack = inventoryCrafting.getStackInSlot( i );
results.set( i, ForgeHooks.getContainerItem( stack ) ); results.set( i, ForgeHooks.getContainerItem( stack ) );

View File

@ -158,7 +158,7 @@ public class ComputerCraftPacket
} }
else else
{ {
m_dataString = new String[ nString ]; m_dataString = new String[nString];
for( int k = 0; k < nString; k++ ) for( int k = 0; k < nString; k++ )
{ {
if( buffer.readBoolean() ) if( buffer.readBoolean() )
@ -168,11 +168,11 @@ public class ComputerCraftPacket
buffer.readBytes( b ); buffer.readBytes( b );
try try
{ {
m_dataString[ k ] = new String( b, "UTF-8" ); m_dataString[k] = new String( b, "UTF-8" );
} }
catch( UnsupportedEncodingException e ) catch( UnsupportedEncodingException e )
{ {
m_dataString[ k ] = null; m_dataString[k] = null;
} }
} }
} }
@ -183,10 +183,10 @@ public class ComputerCraftPacket
} }
else else
{ {
m_dataInt = new int[ nInt ]; m_dataInt = new int[nInt];
for( int k = 0; k < nInt; k++ ) for( int k = 0; k < nInt; k++ )
{ {
m_dataInt[ k ] = buffer.readInt(); m_dataInt[k] = buffer.readInt();
} }
} }
if( nByte == 0 ) if( nByte == 0 )
@ -195,14 +195,14 @@ public class ComputerCraftPacket
} }
else else
{ {
m_dataByte = new byte[ nByte ][]; m_dataByte = new byte[nByte][];
for( int k = 0; k < nByte; k++ ) for( int k = 0; k < nByte; k++ )
{ {
int length = buffer.readInt(); int length = buffer.readInt();
if( length > 0 ) if( length > 0 )
{ {
m_dataByte[ k ] = new byte[ length ]; m_dataByte[k] = new byte[length];
buffer.getBytes( buffer.readerIndex(), m_dataByte[ k ] ); buffer.getBytes( buffer.readerIndex(), m_dataByte[k] );
} }
} }
} }
@ -214,7 +214,7 @@ public class ComputerCraftPacket
else else
{ {
int byteLength = buffer.readInt(); int byteLength = buffer.readInt();
byte[] bytes = new byte[ byteLength ]; byte[] bytes = new byte[byteLength];
buffer.getBytes( buffer.readerIndex(), bytes ); buffer.getBytes( buffer.readerIndex(), bytes );
try try
{ {
@ -232,7 +232,8 @@ public class ComputerCraftPacket
* Determine whether this packet requires the player to be interacting with the * Determine whether this packet requires the player to be interacting with the
* target. * target.
*/ */
public boolean requiresContainer() { public boolean requiresContainer()
{
return m_packetType != RequestComputerUpdate && m_packetType != RequestTileEntityUpdate; return m_packetType != RequestComputerUpdate && m_packetType != RequestTileEntityUpdate;
} }
} }

View File

@ -5,6 +5,7 @@
*/ */
package dan200.computercraft.shared.network; package dan200.computercraft.shared.network;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
public interface INetworkedThing public interface INetworkedThing

View File

@ -35,7 +35,7 @@ public class PacketHandler
{ {
ComputerCraftPacket packet = new ComputerCraftPacket(); ComputerCraftPacket packet = new ComputerCraftPacket();
packet.fromBytes( event.getPacket().payload() ); packet.fromBytes( event.getPacket().payload() );
ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer)event.getHandler()).player ); ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer) event.getHandler()).player );
} }
catch( Exception e ) catch( Exception e )
{ {

View File

@ -49,7 +49,7 @@ public class CommandBlockPeripheral implements IPeripheral
@Override @Override
public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull 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) switch( method )
{ {
case 0: case 0:
{ {

View File

@ -10,8 +10,8 @@ import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider; import dan200.computercraft.api.peripheral.IPeripheralProvider;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityCommandBlock; import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -24,7 +24,7 @@ public class CommandBlockPeripheralProvider implements IPeripheralProvider
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TileEntityCommandBlock ) if( tile != null && tile instanceof TileEntityCommandBlock )
{ {
TileEntityCommandBlock commandBlock = (TileEntityCommandBlock)tile; TileEntityCommandBlock commandBlock = (TileEntityCommandBlock) tile;
return new CommandBlockPeripheral( commandBlock ); return new CommandBlockPeripheral( commandBlock );
} }
return null; return null;

View File

@ -10,7 +10,8 @@ public enum BlockCableCableVariant implements IStringSerializable
ANY( "any" ), ANY( "any" ),
X_AXIS( "x" ), X_AXIS( "x" ),
Y_AXIS( "y" ), Y_AXIS( "y" ),
Z_AXIS( "z" ),; Z_AXIS( "z" ),
;
private final String m_name; private final String m_name;

View File

@ -43,12 +43,18 @@ public enum BlockCableModemVariant implements IStringSerializable
{ {
switch( facing ) switch( facing )
{ {
case DOWN: return DownOff; case DOWN:
case UP: return UpOff; return DownOff;
case NORTH: return NorthOff; case UP:
case SOUTH: return SouthOff; return UpOff;
case WEST: return WestOff; case NORTH:
case EAST: return EastOff; return NorthOff;
case SOUTH:
return SouthOff;
case WEST:
return WestOff;
case EAST:
return EastOff;
} }
return NorthOff; return NorthOff;
} }

View File

@ -54,7 +54,7 @@ public class BlockPeripheral extends BlockPeripheralBase
@Override @Override
@Nonnull @Nonnull
@SideOnly( Side.CLIENT) @SideOnly( Side.CLIENT )
public BlockRenderLayer getRenderLayer() public BlockRenderLayer getRenderLayer()
{ {
return BlockRenderLayer.CUTOUT; return BlockRenderLayer.CUTOUT;
@ -108,9 +108,9 @@ public class BlockPeripheral extends BlockPeripheralBase
{ {
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor ); state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
} }
else if (meta == 13) else if( meta == 13 )
{ {
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker); state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker );
} }
return state; return state;
} }
@ -125,7 +125,8 @@ public class BlockPeripheral extends BlockPeripheralBase
case DiskDrive: case DiskDrive:
{ {
EnumFacing dir = state.getValue( Properties.FACING ); EnumFacing dir = state.getValue( Properties.FACING );
if( dir.getAxis() == EnumFacing.Axis.Y ) { if( dir.getAxis() == EnumFacing.Axis.Y )
{
dir = EnumFacing.NORTH; dir = EnumFacing.NORTH;
} }
meta = dir.getIndex(); meta = dir.getIndex();
@ -190,7 +191,7 @@ public class BlockPeripheral extends BlockPeripheralBase
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile != null && tile instanceof TilePeripheralBase ) if( tile != null && tile instanceof TilePeripheralBase )
{ {
TilePeripheralBase peripheral = (TilePeripheralBase)tile; TilePeripheralBase peripheral = (TilePeripheralBase) tile;
anim = peripheral.getAnim(); anim = peripheral.getAnim();
dir = peripheral.getDirection(); dir = peripheral.getDirection();
} }
@ -347,7 +348,7 @@ public class BlockPeripheral extends BlockPeripheralBase
int xIndex, yIndex, width, height; int xIndex, yIndex, width, height;
if( tile != null && tile instanceof TileMonitor ) if( tile != null && tile instanceof TileMonitor )
{ {
TileMonitor monitor = (TileMonitor)tile; TileMonitor monitor = (TileMonitor) tile;
dir = monitor.getDirection(); dir = monitor.getDirection();
front = monitor.getFront(); front = monitor.getFront();
xIndex = monitor.getXIndex(); xIndex = monitor.getXIndex();
@ -446,7 +447,7 @@ public class BlockPeripheral extends BlockPeripheralBase
state = state.withProperty( Properties.FACING, dir ); state = state.withProperty( Properties.FACING, dir );
state = state.withProperty( Properties.VARIANT, state = state.withProperty( Properties.VARIANT,
BlockPeripheralVariant.values()[ baseVariant.ordinal() + subType ] BlockPeripheralVariant.values()[baseVariant.ordinal() + subType]
); );
break; break;
} }
@ -516,7 +517,7 @@ public class BlockPeripheral extends BlockPeripheralBase
@Override @Override
public PeripheralType getPeripheralType( int damage ) public PeripheralType getPeripheralType( int damage )
{ {
return ((ItemPeripheral)Item.getItemFromBlock(this)).getPeripheralType( damage ); return ((ItemPeripheral) Item.getItemFromBlock( this )).getPeripheralType( damage );
} }
@Override @Override
@ -576,7 +577,7 @@ public class BlockPeripheral extends BlockPeripheralBase
setDirection( world, pos, dir ); setDirection( world, pos, dir );
if( stack.hasDisplayName() && tile != null && tile instanceof TilePeripheralBase ) if( stack.hasDisplayName() && tile != null && tile instanceof TilePeripheralBase )
{ {
TilePeripheralBase peripheral = (TilePeripheralBase)tile; TilePeripheralBase peripheral = (TilePeripheralBase) tile;
peripheral.setLabel( stack.getDisplayName() ); peripheral.setLabel( stack.getDisplayName() );
} }
break; break;
@ -596,7 +597,7 @@ public class BlockPeripheral extends BlockPeripheralBase
direction += 6; direction += 6;
} }
TileMonitor monitor = (TileMonitor)tile; TileMonitor monitor = (TileMonitor) tile;
if( world.isRemote ) if( world.isRemote )
{ {
monitor.setDir( direction ); monitor.setDir( direction );
@ -648,7 +649,7 @@ public class BlockPeripheral extends BlockPeripheralBase
@Override @Override
@Deprecated @Deprecated
public boolean causesSuffocation(IBlockState state) public boolean causesSuffocation( IBlockState state )
{ {
// This normally uses the default state // This normally uses the default state
return material.blocksMovement() && state.isOpaqueCube(); return material.blocksMovement() && state.isOpaqueCube();

View File

@ -12,8 +12,8 @@ import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -27,8 +27,11 @@ public abstract class BlockPeripheralBase extends BlockDirectional
} }
protected abstract IBlockState getDefaultBlockState( PeripheralType type, EnumFacing placedSide ); protected abstract IBlockState getDefaultBlockState( PeripheralType type, EnumFacing placedSide );
protected abstract PeripheralType getPeripheralType( int damage ); protected abstract PeripheralType getPeripheralType( int damage );
protected abstract PeripheralType getPeripheralType( IBlockState state ); protected abstract PeripheralType getPeripheralType( IBlockState state );
protected abstract TilePeripheralBase createTile( PeripheralType type ); protected abstract TilePeripheralBase createTile( PeripheralType type );
@Override @Override
@ -40,7 +43,7 @@ public abstract class BlockPeripheralBase extends BlockDirectional
@Override @Override
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide ) protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
{ {
ItemPeripheralBase item = (ItemPeripheralBase)Item.getItemFromBlock( this ); ItemPeripheralBase item = (ItemPeripheralBase) Item.getItemFromBlock( this );
return getDefaultBlockState( item.getPeripheralType( damage ), placedSide ); return getDefaultBlockState( item.getPeripheralType( damage ), placedSide );
} }

View File

@ -12,8 +12,8 @@ import dan200.computercraft.shared.computer.blocks.ComputerPeripheral;
import dan200.computercraft.shared.computer.blocks.TileComputerBase; import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -33,17 +33,17 @@ public class DefaultPeripheralProvider implements IPeripheralProvider
// Handle our peripherals // Handle our peripherals
if( tile instanceof IPeripheralTile ) if( tile instanceof IPeripheralTile )
{ {
IPeripheralTile peripheralTile = (IPeripheralTile)tile; IPeripheralTile peripheralTile = (IPeripheralTile) tile;
return peripheralTile.getPeripheral( side ); return peripheralTile.getPeripheral( side );
} }
// Handle our computers // Handle our computers
if( tile instanceof TileComputerBase ) if( tile instanceof TileComputerBase )
{ {
TileComputerBase computerTile = (TileComputerBase)tile; TileComputerBase computerTile = (TileComputerBase) tile;
if( tile instanceof TileTurtle ) if( tile instanceof TileTurtle )
{ {
if( !((TileTurtle)tile).hasMoved() ) if( !((TileTurtle) tile).hasMoved() )
{ {
return new ComputerPeripheral( "turtle", computerTile.createProxy() ); return new ComputerPeripheral( "turtle", computerTile.createProxy() );
} }

View File

@ -14,6 +14,8 @@ import net.minecraft.util.EnumFacing;
public interface IPeripheralTile extends IDirectionalTile public interface IPeripheralTile extends IDirectionalTile
{ {
PeripheralType getPeripheralType(); PeripheralType getPeripheralType();
IPeripheral getPeripheral( EnumFacing side ); IPeripheral getPeripheral( EnumFacing side );
String getLabel(); String getLabel();
} }

View File

@ -130,7 +130,7 @@ public class ItemCable extends ItemPeripheralBase
TileEntity tile = world.getTileEntity( offset ); TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable ) if( tile != null && tile instanceof TileCable )
{ {
TileCable cable = (TileCable)tile; TileCable cable = (TileCable) tile;
cable.modemChanged(); cable.modemChanged();
cable.connectionsChanged(); cable.connectionsChanged();
} }
@ -153,7 +153,7 @@ public class ItemCable extends ItemPeripheralBase
TileEntity tile = world.getTileEntity( offset ); TileEntity tile = world.getTileEntity( offset );
if( tile != null && tile instanceof TileCable ) if( tile != null && tile instanceof TileCable )
{ {
TileCable cable = (TileCable)tile; TileCable cable = (TileCable) tile;
cable.modemChanged(); cable.modemChanged();
cable.connectionsChanged(); cable.connectionsChanged();
} }

View File

@ -57,7 +57,7 @@ public class ItemPeripheral extends ItemPeripheralBase
} }
case Speaker: case Speaker:
{ {
stack = new ItemStack(this, quantity, 5); stack = new ItemStack( this, quantity, 5 );
break; break;
} }
@ -83,7 +83,7 @@ public class ItemPeripheral extends ItemPeripheralBase
list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) );
list.add( PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 1 ) );
list.add( PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ) );
list.add( PeripheralItemFactory.create( PeripheralType.Speaker, null, 1) ); list.add( PeripheralItemFactory.create( PeripheralType.Speaker, null, 1 ) );
} }
@Override @Override

View File

@ -24,9 +24,9 @@ public class PeripheralItemFactory
@Nonnull @Nonnull
public static ItemStack create( PeripheralType type, String label, int quantity ) public static ItemStack create( PeripheralType type, String label, int quantity )
{ {
ItemPeripheral peripheral = ((ItemPeripheral)Item.getItemFromBlock( ComputerCraft.Blocks.peripheral )); ItemPeripheral peripheral = ((ItemPeripheral) Item.getItemFromBlock( ComputerCraft.Blocks.peripheral ));
ItemCable cable = ((ItemCable)Item.getItemFromBlock( ComputerCraft.Blocks.cable )); ItemCable cable = ((ItemCable) Item.getItemFromBlock( ComputerCraft.Blocks.cable ));
ItemAdvancedModem advancedModem = ((ItemAdvancedModem)Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem )); ItemAdvancedModem advancedModem = ((ItemAdvancedModem) Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem ));
switch( type ) switch( type )
{ {
case Speaker: case Speaker:

View File

@ -11,12 +11,11 @@ import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.PeripheralType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ITickable;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List;
public abstract class TilePeripheralBase extends TileGeneric public abstract class TilePeripheralBase extends TileGeneric
implements IPeripheralTile, ITickable implements IPeripheralTile, ITickable
@ -42,7 +41,7 @@ public abstract class TilePeripheralBase extends TileGeneric
@Override @Override
public BlockPeripheralBase getBlock() public BlockPeripheralBase getBlock()
{ {
return (BlockPeripheralBase)super.getBlock(); return (BlockPeripheralBase) super.getBlock();
} }
@Override @Override
@ -140,7 +139,7 @@ public abstract class TilePeripheralBase extends TileGeneric
public void readFromNBT( NBTTagCompound nbttagcompound ) public void readFromNBT( NBTTagCompound nbttagcompound )
{ {
// Read properties // Read properties
super.readFromNBT(nbttagcompound); super.readFromNBT( nbttagcompound );
if( nbttagcompound.hasKey( "dir" ) ) if( nbttagcompound.hasKey( "dir" ) )
{ {
m_dir = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) ); m_dir = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) );

View File

@ -21,19 +21,19 @@ public class ContainerDiskDrive extends Container
public ContainerDiskDrive( IInventory playerInventory, TileDiskDrive diskDrive ) public ContainerDiskDrive( IInventory playerInventory, TileDiskDrive diskDrive )
{ {
m_diskDrive = diskDrive; m_diskDrive = diskDrive;
addSlotToContainer(new Slot( m_diskDrive, 0, 8 + 4 * 18, 35)); addSlotToContainer( new Slot( m_diskDrive, 0, 8 + 4 * 18, 35 ) );
for(int j = 0; j < 3; j++) for( int j = 0; j < 3; j++ )
{ {
for(int i1 = 0; i1 < 9; i1++) for( int i1 = 0; i1 < 9; i1++ )
{ {
addSlotToContainer(new Slot(playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18)); addSlotToContainer( new Slot( playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18 ) );
} }
} }
for(int k = 0; k < 9; k++) for( int k = 0; k < 9; k++ )
{ {
addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142)); addSlotToContainer( new Slot( playerInventory, k, 8 + k * 18, 142 ) );
} }
} }
@ -48,35 +48,35 @@ public class ContainerDiskDrive extends Container
public ItemStack transferStackInSlot( EntityPlayer player, int i ) public ItemStack transferStackInSlot( EntityPlayer player, int i )
{ {
ItemStack itemstack = ItemStack.EMPTY; ItemStack itemstack = ItemStack.EMPTY;
Slot slot = inventorySlots.get(i); Slot slot = inventorySlots.get( i );
if(slot != null && slot.getHasStack()) if( slot != null && slot.getHasStack() )
{ {
ItemStack itemstack1 = slot.getStack().copy(); ItemStack itemstack1 = slot.getStack().copy();
itemstack = itemstack1.copy(); itemstack = itemstack1.copy();
if(i == 0 ) if( i == 0 )
{ {
if(!mergeItemStack(itemstack1, 1, 37, true)) if( !mergeItemStack( itemstack1, 1, 37, true ) )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
} }
else if( !mergeItemStack(itemstack1, 0, 1, false) ) else if( !mergeItemStack( itemstack1, 0, 1, false ) )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if(itemstack1.isEmpty()) if( itemstack1.isEmpty() )
{ {
slot.putStack(ItemStack.EMPTY); slot.putStack( ItemStack.EMPTY );
} }
else else
{ {
slot.onSlotChanged(); slot.onSlotChanged();
} }
if(itemstack1.getCount() != itemstack.getCount()) if( itemstack1.getCount() != itemstack.getCount() )
{ {
slot.onTake(player, itemstack1); slot.onTake( player, itemstack1 );
} }
else else
{ {

View File

@ -159,7 +159,7 @@ public class DiskDrivePeripheral implements IPeripheral
Item item = disk.getItem(); Item item = disk.getItem();
if( item instanceof ItemDiskLegacy ) if( item instanceof ItemDiskLegacy )
{ {
return new Object[] { ((ItemDiskLegacy)item).getDiskID( disk ) }; return new Object[] { ((ItemDiskLegacy) item).getDiskID( disk ) };
} }
} }
return null; return null;
@ -188,7 +188,7 @@ public class DiskDrivePeripheral implements IPeripheral
{ {
if( other instanceof DiskDrivePeripheral ) if( other instanceof DiskDrivePeripheral )
{ {
DiskDrivePeripheral otherDiskDrive = (DiskDrivePeripheral)other; DiskDrivePeripheral otherDiskDrive = (DiskDrivePeripheral) other;
if( otherDiskDrive.m_diskDrive == this.m_diskDrive ) if( otherDiskDrive.m_diskDrive == this.m_diskDrive )
{ {
return true; return true;

View File

@ -95,7 +95,7 @@ public class TileDiskDrive extends TilePeripheralBase
if( !getWorld().isRemote ) if( !getWorld().isRemote )
{ {
ItemStack disk = player.getHeldItem( EnumHand.MAIN_HAND ); ItemStack disk = player.getHeldItem( EnumHand.MAIN_HAND );
if( !disk.isEmpty() && getStackInSlot(0).isEmpty() ) if( !disk.isEmpty() && getStackInSlot( 0 ).isEmpty() )
{ {
if( ComputerCraft.getMedia( disk ) != null ) if( ComputerCraft.getMedia( disk ) != null )
{ {
@ -136,9 +136,9 @@ public class TileDiskDrive extends TilePeripheralBase
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbttagcompound) public void readFromNBT( NBTTagCompound nbttagcompound )
{ {
super.readFromNBT(nbttagcompound); super.readFromNBT( nbttagcompound );
if( nbttagcompound.hasKey( "item" ) ) if( nbttagcompound.hasKey( "item" ) )
{ {
NBTTagCompound item = nbttagcompound.getCompoundTag( "item" ); NBTTagCompound item = nbttagcompound.getCompoundTag( "item" );
@ -149,9 +149,9 @@ public class TileDiskDrive extends TilePeripheralBase
@Nonnull @Nonnull
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
{ {
nbttagcompound = super.writeToNBT(nbttagcompound); nbttagcompound = super.writeToNBT( nbttagcompound );
if( !m_diskStack.isEmpty() ) if( !m_diskStack.isEmpty() )
{ {
NBTTagCompound item = new NBTTagCompound(); NBTTagCompound item = new NBTTagCompound();
@ -218,14 +218,14 @@ public class TileDiskDrive extends TilePeripheralBase
@Nonnull @Nonnull
@Override @Override
public ItemStack getStackInSlot(int i) public ItemStack getStackInSlot( int i )
{ {
return m_diskStack; return m_diskStack;
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack removeStackFromSlot(int i) public ItemStack removeStackFromSlot( int i )
{ {
ItemStack result = m_diskStack; ItemStack result = m_diskStack;
m_diskStack = ItemStack.EMPTY; m_diskStack = ItemStack.EMPTY;
@ -236,22 +236,22 @@ public class TileDiskDrive extends TilePeripheralBase
@Nonnull @Nonnull
@Override @Override
public ItemStack decrStackSize(int i, int j) public ItemStack decrStackSize( int i, int j )
{ {
if (m_diskStack.isEmpty()) if( m_diskStack.isEmpty() )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if (m_diskStack.getCount() <= j) if( m_diskStack.getCount() <= j )
{ {
ItemStack disk = m_diskStack; ItemStack disk = m_diskStack;
setInventorySlotContents( 0, ItemStack.EMPTY ); setInventorySlotContents( 0, ItemStack.EMPTY );
return disk; return disk;
} }
ItemStack part = m_diskStack.splitStack(j); ItemStack part = m_diskStack.splitStack( j );
if (m_diskStack.isEmpty()) if( m_diskStack.isEmpty() )
{ {
setInventorySlotContents( 0, ItemStack.EMPTY ); setInventorySlotContents( 0, ItemStack.EMPTY );
} }
@ -371,7 +371,7 @@ public class TileDiskDrive extends TilePeripheralBase
} }
@Override @Override
public boolean isItemValidForSlot( int i, @Nonnull ItemStack itemstack) public boolean isItemValidForSlot( int i, @Nonnull ItemStack itemstack )
{ {
return true; return true;
} }
@ -395,13 +395,13 @@ public class TileDiskDrive extends TilePeripheralBase
} }
@Override @Override
public int getField(int id) public int getField( int id )
{ {
return 0; return 0;
} }
@Override @Override
public void setField(int id, int value) public void setField( int id, int value )
{ {
} }
@ -509,13 +509,13 @@ public class TileDiskDrive extends TilePeripheralBase
} }
if( m_diskMount != null ) if( m_diskMount != null )
{ {
if( m_diskMount instanceof IWritableMount) if( m_diskMount instanceof IWritableMount )
{ {
// Try mounting at the lowest numbered "disk" name we can // Try mounting at the lowest numbered "disk" name we can
int n = 1; int n = 1;
while( info.mountPath == null ) while( info.mountPath == null )
{ {
info.mountPath = computer.mountWritable( (n==1) ? "disk" : ("disk" + n), (IWritableMount)m_diskMount ); info.mountPath = computer.mountWritable( (n == 1) ? "disk" : ("disk" + n), (IWritableMount) m_diskMount );
n++; n++;
} }
} }
@ -525,7 +525,7 @@ public class TileDiskDrive extends TilePeripheralBase
int n = 1; int n = 1;
while( info.mountPath == null ) while( info.mountPath == null )
{ {
info.mountPath = computer.mount( (n==1) ? "disk" : ("disk" + n), m_diskMount ); info.mountPath = computer.mount( (n == 1) ? "disk" : ("disk" + n), m_diskMount );
n++; n++;
} }
} }
@ -544,7 +544,7 @@ public class TileDiskDrive extends TilePeripheralBase
if( !m_diskStack.isEmpty() ) if( !m_diskStack.isEmpty() )
{ {
MountInfo info = m_computers.get( computer ); MountInfo info = m_computers.get( computer );
assert( info != null ); assert (info != null);
if( info.mountPath != null ) if( info.mountPath != null )
{ {
computer.unmount( info.mountPath ); computer.unmount( info.mountPath );
@ -559,9 +559,12 @@ public class TileDiskDrive extends TilePeripheralBase
if( !m_diskStack.isEmpty() ) if( !m_diskStack.isEmpty() )
{ {
IMedia contents = getDiskMedia(); IMedia contents = getDiskMedia();
if( contents != null ) { if( contents != null )
{
setAnim( 2 ); setAnim( 2 );
} else { }
else
{
setAnim( 1 ); setAnim( 1 );
} }
} }
@ -603,10 +606,10 @@ public class TileDiskDrive extends TilePeripheralBase
entityitem.motionY = 0.0; entityitem.motionY = 0.0;
entityitem.motionZ = zOff * 0.15; entityitem.motionZ = zOff * 0.15;
getWorld().spawnEntity(entityitem); getWorld().spawnEntity( entityitem );
if( !destroyed ) if( !destroyed )
{ {
getWorld().playBroadcastSound(1000, getPos(), 0); getWorld().playBroadcastSound( 1000, getPos(), 0 );
} }
} }
} }

View File

@ -45,7 +45,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase
@Override @Override
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
return new BlockStateContainer(this, Properties.FACING, Properties.ON ); return new BlockStateContainer( this, Properties.FACING, Properties.ON );
} }
@Nonnull @Nonnull

View File

@ -86,7 +86,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
{ {
for( IComputerAccess computer : m_computers ) for( IComputerAccess computer : m_computers )
{ {
computer.queueEvent( "modem_message", new Object[]{ computer.queueEvent( "modem_message", new Object[] {
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload(), distance computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload(), distance
} ); } );
} }
@ -102,7 +102,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
{ {
for( IComputerAccess computer : m_computers ) for( IComputerAccess computer : m_computers )
{ {
computer.queueEvent( "modem_message", new Object[]{ computer.queueEvent( "modem_message", new Object[] {
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload() computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload()
} ); } );
} }
@ -124,7 +124,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public String[] getMethodNames() public String[] getMethodNames()
{ {
return new String[]{ return new String[] {
"open", "open",
"isOpen", "isOpen",
"close", "close",
@ -160,7 +160,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
{ {
// isOpen // isOpen
int channel = parseChannel( arguments, 0 ); int channel = parseChannel( arguments, 0 );
return new Object[]{ m_state.isOpen( channel ) }; return new Object[] { m_state.isOpen( channel ) };
} }
case 2: case 2:
{ {
@ -204,7 +204,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
{ {
// isWireless // isWireless
IPacketNetwork network = m_network; IPacketNetwork network = m_network;
return new Object[]{ network != null && network.isWireless() }; return new Object[] { network != null && network.isWireless() };
} }
default: default:
{ {

View File

@ -49,7 +49,7 @@ public class TileAdvancedModem extends TileModemBase
{ {
if( other instanceof Peripheral ) if( other instanceof Peripheral )
{ {
Peripheral otherModem = (Peripheral)other; Peripheral otherModem = (Peripheral) other;
return otherModem.m_entity == m_entity; return otherModem.m_entity == m_entity;
} }
return false; return false;

View File

@ -43,7 +43,7 @@ public class TileCable extends TileModemBase
public static final double MAX = 1 - MIN; public static final double MAX = 1 - MIN;
private static final AxisAlignedBB BOX_CENTRE = new AxisAlignedBB( MIN, MIN, MIN, MAX, MAX, MAX ); private static final AxisAlignedBB BOX_CENTRE = new AxisAlignedBB( MIN, MIN, MIN, MAX, MAX, MAX );
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[]{ private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] {
new AxisAlignedBB( MIN, 0, MIN, MAX, MIN, MAX ), // Down new AxisAlignedBB( MIN, 0, MIN, MAX, MIN, MAX ), // Down
new AxisAlignedBB( MIN, MAX, MIN, MAX, 1, MAX ), // Up new AxisAlignedBB( MIN, MAX, MIN, MAX, 1, MAX ), // Up
new AxisAlignedBB( MIN, MIN, 0, MAX, MAX, MIN ), // North new AxisAlignedBB( MIN, MIN, 0, MAX, MAX, MIN ), // North

View File

@ -59,7 +59,7 @@ public abstract class TileModemBase extends TilePeripheralBase
if( !getWorld().isSideSolid( getPos().offset( dir ), dir.getOpposite() ) ) if( !getWorld().isSideSolid( getPos().offset( dir ), dir.getOpposite() ) )
{ {
// Drop everything and remove block // Drop everything and remove block
((BlockGeneric)getBlockType()).dropAllItems( getWorld(), getPos(), false ); ((BlockGeneric) getBlockType()).dropAllItems( getWorld(), getPos(), false );
getWorld().setBlockToAir( getPos() ); getWorld().setBlockToAir( getPos() );
} }
} }
@ -69,7 +69,7 @@ public abstract class TileModemBase extends TilePeripheralBase
public AxisAlignedBB getBounds() public AxisAlignedBB getBounds()
{ {
int direction = getDirection().ordinal(); int direction = getDirection().ordinal();
return direction >= 0 && direction < BOXES.length ? BOXES[ direction ] : Block.FULL_BLOCK_AABB; return direction >= 0 && direction < BOXES.length ? BOXES[direction] : Block.FULL_BLOCK_AABB;
} }
@Override @Override

View File

@ -98,20 +98,20 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
int idx = 1; int idx = 1;
for( String name : wrappers.keySet() ) table.put( idx++, name ); for( String name : wrappers.keySet() ) table.put( idx++, name );
} }
return new Object[]{ table }; return new Object[] { table };
} }
case 1: case 1:
{ {
// isPresentRemote // isPresentRemote
String name = getString( arguments, 0 ); String name = getString( arguments, 0 );
return new Object[]{ getWrapper( computer, name ) != null }; return new Object[] { getWrapper( computer, name ) != null };
} }
case 2: case 2:
{ {
// getTypeRemote // getTypeRemote
String name = getString( arguments, 0 ); String name = getString( arguments, 0 );
RemotePeripheralWrapper wrapper = getWrapper( computer, name ); RemotePeripheralWrapper wrapper = getWrapper( computer, name );
return wrapper != null ? new Object[]{ wrapper.getType() } : null; return wrapper != null ? new Object[] { wrapper.getType() } : null;
} }
case 3: case 3:
{ {
@ -122,11 +122,11 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
String[] methodNames = wrapper.getMethodNames(); String[] methodNames = wrapper.getMethodNames();
Map<Object, Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
for( int i = 0; i < methodNames.length; ++i ) for( int i = 0; i < methodNames.length; i++ )
{ {
table.put( i + 1, methodNames[i] ); table.put( i + 1, methodNames[i] );
} }
return new Object[]{ table }; return new Object[] { table };
} }
case 4: case 4:
{ {
@ -144,7 +144,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
{ {
// getNameLocal // getNameLocal
String local = getLocalPeripheral().getConnectedName(); String local = getLocalPeripheral().getConnectedName();
return local == null ? null : new Object[]{ local }; return local == null ? null : new Object[] { local };
} }
default: default:
{ {
@ -226,7 +226,8 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
{ {
synchronized( peripheralWrappers ) synchronized( peripheralWrappers )
{ {
for(ConcurrentMap<String, RemotePeripheralWrapper> wrappers : peripheralWrappers.values()) { for( ConcurrentMap<String, RemotePeripheralWrapper> wrappers : peripheralWrappers.values() )
{
RemotePeripheralWrapper wrapper = wrappers.remove( name ); RemotePeripheralWrapper wrapper = wrappers.remove( name );
if( wrapper != null ) wrapper.detach(); if( wrapper != null ) wrapper.detach();
} }
@ -244,7 +245,8 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
} }
} }
private ConcurrentMap<String, RemotePeripheralWrapper> getWrappers( IComputerAccess computer ) { private ConcurrentMap<String, RemotePeripheralWrapper> getWrappers( IComputerAccess computer )
{
synchronized( peripheralWrappers ) synchronized( peripheralWrappers )
{ {
return peripheralWrappers.get( computer ); return peripheralWrappers.get( computer );
@ -281,7 +283,7 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
assert (m_methods != null); assert (m_methods != null);
m_methodMap = new HashMap<>(); m_methodMap = new HashMap<>();
for( int i = 0; i < m_methods.length; ++i ) for( int i = 0; i < m_methods.length; i++ )
{ {
if( m_methods[i] != null ) if( m_methods[i] != null )
{ {
@ -293,13 +295,13 @@ public abstract class WiredModemPeripheral extends ModemPeripheral implements IW
public void attach() public void attach()
{ {
m_peripheral.attach( this ); m_peripheral.attach( this );
m_computer.queueEvent( "peripheral", new Object[]{ getAttachmentName() } ); m_computer.queueEvent( "peripheral", new Object[] { getAttachmentName() } );
} }
public void detach() public void detach()
{ {
m_peripheral.detach( this ); m_peripheral.detach( this );
m_computer.queueEvent( "peripheral_detach", new Object[]{ getAttachmentName() } ); m_computer.queueEvent( "peripheral_detach", new Object[] { getAttachmentName() } );
} }
public String getType() public String getType()

View File

@ -56,7 +56,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral
} }
if( position.y > 96.0 && maxRange > minRange ) if( position.y > 96.0 && maxRange > minRange )
{ {
return minRange + ( position.y - 96.0 ) * ( ( maxRange - minRange ) / ( ( world.getHeight() - 1 ) - 96.0 ) ); return minRange + (position.y - 96.0) * ((maxRange - minRange) / ((world.getHeight() - 1) - 96.0));
} }
return minRange; return minRange;
} }

View File

@ -86,9 +86,12 @@ public class MonitorPeripheral implements IPeripheral
{ {
// write // write
String text; String text;
if( args.length > 0 && args[0] != null ) { if( args.length > 0 && args[0] != null )
{
text = args[0].toString(); text = args[0].toString();
} else { }
else
{
text = ""; text = "";
} }
terminal.write( text ); terminal.write( text );
@ -216,7 +219,7 @@ public class MonitorPeripheral implements IPeripheral
{ {
int hex = getInt( args, 1 ); int hex = getInt( args, 1 );
double[] rgb = Palette.decodeRGB8( hex ); double[] rgb = Palette.decodeRGB8( hex );
TermAPI.setColour( terminal, colour, rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] ); TermAPI.setColour( terminal, colour, rgb[0], rgb[1], rgb[2] );
} }
else else
{ {
@ -271,7 +274,7 @@ public class MonitorPeripheral implements IPeripheral
{ {
if( other != null && other instanceof MonitorPeripheral ) if( other != null && other instanceof MonitorPeripheral )
{ {
MonitorPeripheral otherMonitor = (MonitorPeripheral)other; MonitorPeripheral otherMonitor = (MonitorPeripheral) other;
if( otherMonitor.m_monitor == this.m_monitor ) if( otherMonitor.m_monitor == this.m_monitor )
{ {
return true; return true;

Some files were not shown because too many files have changed in this diff Show More