1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-04 02:52:56 +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;
@ -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();
@ -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 );
} }
@ -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 );
} }
} }
@ -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;

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 ); return (String) computerCraft_getVersion.invoke( null );
} catch (Exception e) { }
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 ); return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
} catch (Exception e) { }
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 ); return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
} catch (Exception e){ }
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 ); return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
} catch (Exception e){ }
catch( Exception e )
{
// It failed // It failed
} }
} }
@ -169,9 +181,12 @@ public final class ComputerCraftAPI
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 ); return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
} catch (Exception e){ }
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,8 +430,10 @@ 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<?>[] {
} ); } );
@ -440,9 +478,13 @@ public final class ComputerCraftAPI
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

@ -31,11 +31,11 @@ public class GuiPrintout extends GuiContainer
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

@ -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] );
} }

View File

@ -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] );
} }
@ -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 );
} }
} }

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

@ -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

@ -94,10 +94,12 @@ 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 };
@ -137,9 +139,12 @@ 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 ) }; return new Object[] { m_fileSystem.exists( path ) };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
return new Object[] { false }; return new Object[] { false };
} }
} }
@ -147,9 +152,12 @@ public class FSAPI implements ILuaAPI
{ {
// isDir // isDir
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
return new Object[] { m_fileSystem.isDir( path ) }; return new Object[] { m_fileSystem.isDir( path ) };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
return new Object[] { false }; return new Object[] { false };
} }
} }
@ -157,9 +165,12 @@ public class FSAPI implements ILuaAPI
{ {
// isReadOnly // isReadOnly
String path = getString( args, 0 ); String path = getString( args, 0 );
try { try
{
return new Object[] { m_fileSystem.isReadOnly( path ) }; return new Object[] { m_fileSystem.isReadOnly( path ) };
} catch( FileSystemException e ) { }
catch( FileSystemException e )
{
return new Object[] { false }; return new Object[] { false };
} }
} }
@ -167,11 +178,14 @@ public class FSAPI implements ILuaAPI
{ {
// 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() );
} }
} }

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;
} }
} }
@ -207,7 +212,7 @@ public class OSAPI implements ILuaAPI
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;
} }

View File

@ -51,8 +51,10 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
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,16 +256,21 @@ 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();
} }
} }
@ -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() )
@ -328,7 +338,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
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() )
@ -345,7 +355,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
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() )
@ -432,7 +442,8 @@ 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 };
@ -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

@ -65,7 +65,7 @@ public class RedstoneAPI implements ILuaAPI
{ {
// 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] );
} }
@ -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 = "";
} }

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;
@ -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;
} }
@ -480,7 +480,7 @@ 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] )
{ {
@ -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;
@ -756,9 +757,12 @@ 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
} }
@ -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

@ -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;
} }
} }
@ -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,7 +769,8 @@ 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 != '*') )
{ {
@ -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( '/' );
} }
} }
@ -844,9 +872,12 @@ public class FileSystem
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

@ -296,7 +296,7 @@ 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 )
{ {
@ -546,7 +546,7 @@ public class CobaltLuaMachine implements ILuaMachine
} }
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 );
@ -633,7 +633,7 @@ public class CobaltLuaMachine implements ILuaMachine
{ {
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 );
@ -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;
@ -40,7 +41,7 @@ public class Terminal
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;
} }
@ -95,7 +98,7 @@ public class Terminal
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 )
{ {
@ -222,7 +225,7 @@ public class Terminal
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 )
@ -247,7 +250,7 @@ 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 ) );
@ -325,7 +328,7 @@ 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() );
@ -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 ) )

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;
} }
@ -28,9 +28,9 @@ public class TextBuffer
{ {
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 );
} }
@ -46,9 +46,9 @@ public class TextBuffer
{ {
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 );
} }

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

@ -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;

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

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 );
@ -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;

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;

View File

@ -225,11 +225,11 @@ public class CommandAPI implements ILuaAPI
} }
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 ) );

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;

View File

@ -150,9 +150,12 @@ public class BlockComputer extends BlockComputerBase
@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,8 +40,11 @@ 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

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

@ -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() };

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

@ -133,7 +133,7 @@ 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 )
{ {
@ -143,7 +143,7 @@ public class ItemPrintout extends Item
} }
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 )
{ {
@ -221,7 +221,7 @@ 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 )
{ {
@ -240,7 +240,7 @@ 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 )
{ {

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 );
@ -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,9 +61,9 @@ 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() )
@ -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

@ -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

@ -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;

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

@ -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();

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

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;

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

@ -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

View File

@ -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 );
} }
} }

View File

@ -122,7 +122,7 @@ 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] );
} }
@ -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 )
{ {

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 );

View File

@ -322,11 +322,16 @@ public class TileMonitor extends TilePeripheralBase
public EnumFacing getDirection() public EnumFacing getDirection()
{ {
int dir = getDir() % 6; int dir = getDir() % 6;
switch( dir ) { switch( dir )
case 2: return EnumFacing.NORTH; {
case 3: return EnumFacing.SOUTH; case 2:
case 4: return EnumFacing.WEST; return EnumFacing.NORTH;
case 5: return EnumFacing.EAST; case 3:
return EnumFacing.SOUTH;
case 4:
return EnumFacing.WEST;
case 5:
return EnumFacing.EAST;
} }
return EnumFacing.NORTH; return EnumFacing.NORTH;
} }
@ -350,11 +355,16 @@ public class TileMonitor extends TilePeripheralBase
public EnumFacing getRight() public EnumFacing getRight()
{ {
int dir = getDir() % 6; int dir = getDir() % 6;
switch( dir ) { switch( dir )
case 2: return EnumFacing.WEST; {
case 3: return EnumFacing.EAST; case 2:
case 4: return EnumFacing.SOUTH; return EnumFacing.WEST;
case 5: return EnumFacing.NORTH; case 3:
return EnumFacing.EAST;
case 4:
return EnumFacing.SOUTH;
case 5:
return EnumFacing.NORTH;
} }
return EnumFacing.WEST; return EnumFacing.WEST;
} }
@ -364,17 +374,26 @@ public class TileMonitor extends TilePeripheralBase
int dir = getDir(); int dir = getDir();
if( dir <= 5 ) return EnumFacing.UP; if( dir <= 5 ) return EnumFacing.UP;
switch( dir ) { switch( dir )
{
// up facing // up facing
case 8: return EnumFacing.NORTH; case 8:
case 9: return EnumFacing.SOUTH; return EnumFacing.NORTH;
case 10: return EnumFacing.WEST; case 9:
case 11: return EnumFacing.EAST; return EnumFacing.SOUTH;
case 10:
return EnumFacing.WEST;
case 11:
return EnumFacing.EAST;
// down facing // down facing
case 14: return EnumFacing.SOUTH; case 14:
case 15: return EnumFacing.NORTH; return EnumFacing.SOUTH;
case 16: return EnumFacing.EAST; case 15:
case 17: return EnumFacing.WEST; return EnumFacing.NORTH;
case 16:
return EnumFacing.EAST;
case 17:
return EnumFacing.WEST;
} }
return EnumFacing.NORTH; return EnumFacing.NORTH;
} }
@ -587,33 +606,43 @@ public class TileMonitor extends TilePeripheralBase
public void expand() public void expand()
{ {
while( mergeLeft() || mergeRight() || mergeUp() || mergeDown() ) {} while( mergeLeft() || mergeRight() || mergeUp() || mergeDown() )
{
}
} }
public void contractNeighbours() public void contractNeighbours()
{ {
m_ignoreMe = true; m_ignoreMe = true;
if( m_xIndex > 0 ) { if( m_xIndex > 0 )
{
TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex ); TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex );
if( left != null ) { if( left != null )
{
left.contract(); left.contract();
} }
} }
if( m_xIndex + 1 < m_width ) { if( m_xIndex + 1 < m_width )
{
TileMonitor right = getNeighbour( m_xIndex + 1, m_yIndex ); TileMonitor right = getNeighbour( m_xIndex + 1, m_yIndex );
if( right != null ) { if( right != null )
{
right.contract(); right.contract();
} }
} }
if( m_yIndex > 0 ) { if( m_yIndex > 0 )
{
TileMonitor below = getNeighbour( m_xIndex, m_yIndex - 1 ); TileMonitor below = getNeighbour( m_xIndex, m_yIndex - 1 );
if( below != null ) { if( below != null )
{
below.contract(); below.contract();
} }
} }
if( m_yIndex + 1 < m_height ) { if( m_yIndex + 1 < m_height )
{
TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 ); TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 );
if( above != null ) { if( above != null )
{
above.contract(); above.contract();
} }
} }
@ -630,30 +659,36 @@ public class TileMonitor extends TilePeripheralBase
{ {
TileMonitor right = null; TileMonitor right = null;
TileMonitor below = null; TileMonitor below = null;
if( width > 1 ) { if( width > 1 )
{
right = getNeighbour( 1, 0 ); right = getNeighbour( 1, 0 );
} }
if( height > 1 ) { if( height > 1 )
{
below = getNeighbour( 0, 1 ); below = getNeighbour( 0, 1 );
} }
if( right != null ) { if( right != null )
{
right.resize( width - 1, 1 ); right.resize( width - 1, 1 );
} }
if( below != null ) { if( below != null )
{
below.resize( width, height - 1 ); below.resize( width, height - 1 );
} }
if( right != null ) { if( right != null )
{
right.expand(); right.expand();
} }
if( below != null ) { if( below != null )
{
below.expand(); below.expand();
} }
return; return;
} }
for( int y=0; y<height; ++y ) for( int y = 0; y < height; y++ )
{ {
for( int x=0; x<width; ++x ) for( int x = 0; x < width; x++ )
{ {
TileMonitor monitor = origin.getNeighbour( x, y ); TileMonitor monitor = origin.getNeighbour( x, y );
if( monitor == null ) if( monitor == null )
@ -664,34 +699,42 @@ public class TileMonitor extends TilePeripheralBase
TileMonitor right = null; TileMonitor right = null;
TileMonitor below = null; TileMonitor below = null;
if( y > 0 ) { if( y > 0 )
{
above = origin; above = origin;
above.resize( width, y ); above.resize( width, y );
} }
if( x > 0 ) { if( x > 0 )
{
left = origin.getNeighbour( 0, y ); left = origin.getNeighbour( 0, y );
left.resize( x, 1 ); left.resize( x, 1 );
} }
if( x + 1 < width ) { if( x + 1 < width )
{
right = origin.getNeighbour( x + 1, y ); right = origin.getNeighbour( x + 1, y );
right.resize( width - (x + 1), 1 ); right.resize( width - (x + 1), 1 );
} }
if( y + 1 < height ) { if( y + 1 < height )
{
below = origin.getNeighbour( 0, y + 1 ); below = origin.getNeighbour( 0, y + 1 );
below.resize( width, height - (y + 1) ); below.resize( width, height - (y + 1) );
} }
// Re-expand // Re-expand
if( above != null ) { if( above != null )
{
above.expand(); above.expand();
} }
if( left != null ) { if( left != null )
{
left.expand(); left.expand();
} }
if( right != null ) { if( right != null )
{
right.expand(); right.expand();
} }
if( below != null ) { if( below != null )
{
below.expand(); below.expand();
} }
return; return;
@ -723,9 +766,9 @@ public class TileMonitor extends TilePeripheralBase
int xCharPos = (int) Math.min( originTerminal.getWidth(), Math.max( ((pair.x - RENDER_BORDER - RENDER_MARGIN) / xCharWidth) + 1.0, 1.0 ) ); int xCharPos = (int) Math.min( originTerminal.getWidth(), Math.max( ((pair.x - RENDER_BORDER - RENDER_MARGIN) / xCharWidth) + 1.0, 1.0 ) );
int yCharPos = (int) Math.min( originTerminal.getHeight(), Math.max( ((pair.y - RENDER_BORDER - RENDER_MARGIN) / yCharHeight) + 1.0, 1.0 ) ); int yCharPos = (int) Math.min( originTerminal.getHeight(), Math.max( ((pair.y - RENDER_BORDER - RENDER_MARGIN) / yCharHeight) + 1.0, 1.0 ) );
for( int y = 0; y < m_height; ++y ) for( int y = 0; y < m_height; y++ )
{ {
for( int x = 0; x < m_width; ++x ) for( int x = 0; x < m_width; x++ )
{ {
TileMonitor monitor = getNeighbour( x, y ); TileMonitor monitor = getNeighbour( x, y );
if( monitor == null ) continue; if( monitor == null ) continue;

View File

@ -30,13 +30,13 @@ public class ContainerPrinter extends Container
addSlotToContainer( new Slot( m_printer, 0, 13, 35 ) ); addSlotToContainer( new Slot( m_printer, 0, 13, 35 ) );
// In-tray // In-tray
for( int i = 0; i < 6; ++i ) for( int i = 0; i < 6; i++ )
{ {
addSlotToContainer( new Slot( m_printer, i + 1, 61 + i * 18, 22 ) ); addSlotToContainer( new Slot( m_printer, i + 1, 61 + i * 18, 22 ) );
} }
// Out-tray // Out-tray
for( int i = 0; i < 6; ++i ) for( int i = 0; i < 6; i++ )
{ {
addSlotToContainer( new Slot( m_printer, i + 7, 61 + i * 18, 49 ) ); addSlotToContainer( new Slot( m_printer, i + 7, 61 + i * 18, 49 ) );
} }

View File

@ -59,9 +59,12 @@ public class PrinterPeripheral 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 = "";
} }

View File

@ -104,7 +104,7 @@ public class TilePrinter extends TilePeripheralBase
synchronized( m_inventory ) synchronized( m_inventory )
{ {
NBTTagList nbttaglist = nbttagcompound.getTagList( "Items", Constants.NBT.TAG_COMPOUND ); NBTTagList nbttaglist = nbttagcompound.getTagList( "Items", Constants.NBT.TAG_COMPOUND );
for( int i=0; i<nbttaglist.tagCount(); ++i ) for( int i = 0; i < nbttaglist.tagCount(); i++ )
{ {
NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i ); NBTTagCompound itemTag = nbttaglist.getCompoundTagAt( i );
int j = itemTag.getByte( "Slot" ) & 0xff; int j = itemTag.getByte( "Slot" ) & 0xff;
@ -134,7 +134,7 @@ public class TilePrinter extends TilePeripheralBase
synchronized( m_inventory ) synchronized( m_inventory )
{ {
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for(int i=0; i<m_inventory.size(); ++i) for( int i = 0; i < m_inventory.size(); i++ )
{ {
if( !m_inventory.get( i ).isEmpty() ) if( !m_inventory.get( i ).isEmpty() )
{ {
@ -253,7 +253,7 @@ public class TilePrinter extends TilePeripheralBase
{ {
synchronized( m_inventory ) synchronized( m_inventory )
{ {
for( int i=0; i<m_inventory.size(); ++i ) for( int i = 0; i < m_inventory.size(); i++ )
{ {
m_inventory.set( i, ItemStack.EMPTY ); m_inventory.set( i, ItemStack.EMPTY );
} }
@ -350,9 +350,12 @@ public class TilePrinter extends TilePeripheralBase
{ {
switch( side ) switch( side )
{ {
case DOWN: return bottomSlots; // Bottom (Out tray) case DOWN:
case UP: return topSlots; // Top (In tray) return bottomSlots; // Bottom (Out tray)
default: return sideSlots; // Sides (Ink) case UP:
return topSlots; // Top (In tray)
default:
return sideSlots; // Sides (Ink)
} }
} }
@ -434,7 +437,7 @@ public class TilePrinter extends TilePeripheralBase
int count = 0; int count = 0;
synchronized( m_inventory ) synchronized( m_inventory )
{ {
for( int i=1; i<7; ++i ) for( int i = 1; i < 7; i++ )
{ {
ItemStack paperStack = m_inventory.get( i ); ItemStack paperStack = m_inventory.get( i );
if( !paperStack.isEmpty() && isPaper( paperStack ) ) if( !paperStack.isEmpty() && isPaper( paperStack ) )
@ -484,16 +487,19 @@ public class TilePrinter extends TilePeripheralBase
return false; return false;
} }
for( int i=1; i<7; ++i ) for( int i = 1; i < 7; i++ )
{ {
ItemStack paperStack = m_inventory.get( i ); ItemStack paperStack = m_inventory.get( i );
if( !paperStack.isEmpty() && isPaper( paperStack ) ) if( !paperStack.isEmpty() && isPaper( paperStack ) )
{ {
// Setup the new page // Setup the new page
int colour = inkStack.getItemDamage(); int colour = inkStack.getItemDamage();
if( colour >= 0 && colour < 16 ) { if( colour >= 0 && colour < 16 )
{
m_page.setTextColour( 15 - colour ); m_page.setTextColour( 15 - colour );
} else { }
else
{
m_page.setTextColour( 15 ); m_page.setTextColour( 15 );
} }
@ -503,7 +509,7 @@ public class TilePrinter extends TilePeripheralBase
m_pageTitle = ItemPrintout.getTitle( paperStack ); m_pageTitle = ItemPrintout.getTitle( paperStack );
String[] text = ItemPrintout.getText( paperStack ); String[] text = ItemPrintout.getText( paperStack );
String[] textColour = ItemPrintout.getColours( paperStack ); String[] textColour = ItemPrintout.getColours( paperStack );
for( int y=0; y<m_page.getHeight(); ++y ) for( int y = 0; y < m_page.getHeight(); y++ )
{ {
m_page.setLine( y, text[y], textColour[y], "" ); m_page.setLine( y, text[y], textColour[y], "" );
} }
@ -545,7 +551,7 @@ public class TilePrinter extends TilePeripheralBase
int height = m_page.getHeight(); int height = m_page.getHeight();
String[] lines = new String[height]; String[] lines = new String[height];
String[] colours = new String[height]; String[] colours = new String[height];
for( int i=0; i<height; ++i ) for( int i = 0; i < height; i++ )
{ {
lines[i] = m_page.getLine( i ).toString(); lines[i] = m_page.getLine( i ).toString();
colours[i] = m_page.getTextColourLine( i ).toString(); colours[i] = m_page.getTextColourLine( i ).toString();
@ -569,7 +575,7 @@ public class TilePrinter extends TilePeripheralBase
{ {
synchronized( m_inventory ) synchronized( m_inventory )
{ {
for( int i=0; i<13; ++i ) for( int i = 0; i < 13; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
@ -597,7 +603,7 @@ public class TilePrinter extends TilePeripheralBase
synchronized( m_inventory ) synchronized( m_inventory )
{ {
int anim = 0; int anim = 0;
for( int i=1;i<7;++i ) for( int i = 1; i < 7; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )
@ -606,7 +612,7 @@ public class TilePrinter extends TilePeripheralBase
break; break;
} }
} }
for( int i=7;i<13;++i ) for( int i = 7; i < 13; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = m_inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )

View File

@ -20,7 +20,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static dan200.computercraft.core.apis.ArgumentHelper.getString; import static dan200.computercraft.core.apis.ArgumentHelper.getString;

View File

@ -11,7 +11,6 @@ import dan200.computercraft.api.pocket.IPocketAccess;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory; import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;

View File

@ -60,9 +60,9 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
ItemStack computer = ItemStack.EMPTY; ItemStack computer = ItemStack.EMPTY;
int computerX = -1; int computerX = -1;
int computerY = -1; int computerY = -1;
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 item = inventory.getStackInRowAndColumn( x, y ); ItemStack item = inventory.getStackInRowAndColumn( x, y );
if( !item.isEmpty() && item.getItem() instanceof ItemPocketComputer ) if( !item.isEmpty() && item.getItem() instanceof ItemPocketComputer )
@ -92,9 +92,9 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
// Check for upgrades around the item // Check for upgrades around the item
IPocketUpgrade upgrade = null; IPocketUpgrade upgrade = null;
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 item = inventory.getStackInRowAndColumn( x, y ); ItemStack item = inventory.getStackInRowAndColumn( x, y );
if( x == computerX && y == computerY ) if( x == computerX && y == computerY )
@ -131,7 +131,7 @@ public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecip
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

@ -528,7 +528,8 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
} }
@SubscribeEvent @SubscribeEvent
public void onTurtleAction( TurtleActionEvent event) { public void onTurtleAction( TurtleActionEvent event )
{
if( ComputerCraft.turtleDisabledActions.contains( event.getAction() ) ) if( ComputerCraft.turtleDisabledActions.contains( event.getAction() ) )
{ {
event.setCanceled( true, "Action has been disabled" ); event.setCanceled( true, "Action has been disabled" );

View File

@ -209,7 +209,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
if( listener.isCallingFromMinecraftThread() ) if( listener.isCallingFromMinecraftThread() )
{ {
processPacket( packet, player ); processPacket( packet, player );
} else }
else
{ {
listener.addScheduledTask( () -> processPacket( packet, player ) ); listener.addScheduledTask( () -> processPacket( packet, player ) );
} }
@ -709,7 +710,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
} }
@SubscribeEvent @SubscribeEvent
public void onConfigChanged( ConfigChangedEvent.OnConfigChangedEvent event) { public void onConfigChanged( ConfigChangedEvent.OnConfigChangedEvent event )
{
if( event.getModID().equals( ComputerCraft.MOD_ID ) ) if( event.getModID().equals( ComputerCraft.MOD_ID ) )
{ {
ComputerCraft.syncConfig(); ComputerCraft.syncConfig();

View File

@ -15,21 +15,27 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
public interface ICCTurtleProxy public interface ICCTurtleProxy
{ {
void preInit(); void preInit();
void init(); void init();
void registerTurtleUpgrade( ITurtleUpgrade upgrade ); void registerTurtleUpgrade( ITurtleUpgrade upgrade );
ITurtleUpgrade getTurtleUpgrade( String id ); ITurtleUpgrade getTurtleUpgrade( String id );
ITurtleUpgrade getTurtleUpgrade( int legacyId ); ITurtleUpgrade getTurtleUpgrade( int legacyId );
ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack item ); ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack item );
void addAllUpgradedTurtles( NonNullList<ItemStack> list ); void addAllUpgradedTurtles( NonNullList<ItemStack> list );
void setDropConsumer( Entity entity, Function<ItemStack, ItemStack> consumer ); void setDropConsumer( Entity entity, Function<ItemStack, ItemStack> consumer );
void setDropConsumer( World world, BlockPos pos, Function<ItemStack, ItemStack> consumer ); void setDropConsumer( World world, BlockPos pos, Function<ItemStack, ItemStack> consumer );
List<ItemStack> clearDropConsumer(); List<ItemStack> clearDropConsumer();
} }

View File

@ -28,25 +28,38 @@ import java.io.File;
public interface IComputerCraftProxy public interface IComputerCraftProxy
{ {
void preInit(); void preInit();
void init(); void init();
void initServer( MinecraftServer server ); void initServer( MinecraftServer server );
boolean isClient(); boolean isClient();
boolean getGlobalCursorBlink(); boolean getGlobalCursorBlink();
long getRenderFrame(); long getRenderFrame();
Object getFixedWidthFontRenderer(); Object getFixedWidthFontRenderer();
String getRecordInfo( @Nonnull ItemStack item ); String getRecordInfo( @Nonnull ItemStack item );
void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos ); void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos );
Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive ); Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );
Object getComputerGUI( TileComputer computer ); Object getComputerGUI( TileComputer computer );
Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer ); Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer );
Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle ); Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
Object getPrintoutGUI( EntityPlayer player, EnumHand hand ); Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
Object getPocketComputerGUI( EntityPlayer player, EnumHand hand ); Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family ); Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family );
File getWorldDir( World world ); File getWorldDir( World world );
void handlePacket( ComputerCraftPacket packet, EntityPlayer player ); void handlePacket( ComputerCraftPacket packet, EntityPlayer player );
} }

View File

@ -17,11 +17,16 @@ import net.minecraft.util.math.Vec3d;
public interface ITurtleTile extends IComputerTile, IDirectionalTile public interface ITurtleTile extends IComputerTile, IDirectionalTile
{ {
int getColour(); int getColour();
ResourceLocation getOverlay(); ResourceLocation getOverlay();
ITurtleUpgrade getUpgrade( TurtleSide side ); ITurtleUpgrade getUpgrade( TurtleSide side );
ITurtleAccess getAccess(); ITurtleAccess getAccess();
Vec3d getRenderOffset( float f ); Vec3d getRenderOffset( float f );
float getRenderYaw( float f ); float getRenderYaw( float f );
float getToolRenderAngle( TurtleSide side, float f ); float getToolRenderAngle( TurtleSide side, float f );
} }

View File

@ -31,7 +31,10 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.*; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
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.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -140,7 +143,7 @@ public class TileTurtle extends TileComputerBase
if( !getWorld().isRemote ) if( !getWorld().isRemote )
{ {
int size = getSizeInventory(); int size = getSizeInventory();
for( int i=0; i<size; ++i ) for( int i = 0; i < size; i++ )
{ {
ItemStack stack = getStackInSlot( i ); ItemStack stack = getStackInSlot( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
@ -299,7 +302,7 @@ public class TileTurtle extends TileComputerBase
} }
m_inventoryChanged = false; m_inventoryChanged = false;
for( int n=0; n<getSizeInventory(); ++n ) for( int n = 0; n < getSizeInventory(); n++ )
{ {
m_previousInventory.set( n, InventoryUtil.copyItem( getStackInSlot( n ) ) ); m_previousInventory.set( n, InventoryUtil.copyItem( getStackInSlot( n ) ) );
} }
@ -351,7 +354,7 @@ public class TileTurtle extends TileComputerBase
NBTTagList nbttaglist = nbttagcompound.getTagList( "Items", Constants.NBT.TAG_COMPOUND ); NBTTagList nbttaglist = nbttagcompound.getTagList( "Items", Constants.NBT.TAG_COMPOUND );
m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
for( int i=0; i<nbttaglist.tagCount(); ++i ) for( int i = 0; i < nbttaglist.tagCount(); i++ )
{ {
NBTTagCompound itemtag = nbttaglist.getCompoundTagAt( i ); NBTTagCompound itemtag = nbttaglist.getCompoundTagAt( i );
int slot = itemtag.getByte( "Slot" ) & 0xff; int slot = itemtag.getByte( "Slot" ) & 0xff;
@ -374,7 +377,7 @@ public class TileTurtle extends TileComputerBase
// Write inventory // Write inventory
NBTTagList nbttaglist = new NBTTagList(); NBTTagList nbttaglist = new NBTTagList();
for( int i=0; i<INVENTORY_SIZE; ++i ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !m_inventory.get( i ).isEmpty() ) if( !m_inventory.get( i ).isEmpty() )
{ {
@ -570,7 +573,7 @@ public class TileTurtle extends TileComputerBase
synchronized( m_inventory ) synchronized( m_inventory )
{ {
boolean changed = false; boolean changed = false;
for( int i = 0; i < INVENTORY_SIZE; ++i ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !m_inventory.get( i ).isEmpty() ) if( !m_inventory.get( i ).isEmpty() )
{ {
@ -660,7 +663,7 @@ public class TileTurtle extends TileComputerBase
{ {
if( !m_inventoryChanged ) if( !m_inventoryChanged )
{ {
for( int n=0; n<getSizeInventory(); ++n ) for( int n = 0; n < getSizeInventory(); n++ )
{ {
if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) ) if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) )
{ {
@ -735,9 +738,14 @@ public class TileTurtle extends TileComputerBase
ITurtleUpgrade upgrade; ITurtleUpgrade upgrade;
switch( side ) switch( side )
{ {
case 4: upgrade = getUpgrade( TurtleSide.Right ); break; case 4:
case 5: upgrade = getUpgrade( TurtleSide.Left ); break; upgrade = getUpgrade( TurtleSide.Right );
default: return false; break;
case 5:
upgrade = getUpgrade( TurtleSide.Left );
break;
default:
return false;
} }
return upgrade != null && upgrade.getType().isPeripheral(); return upgrade != null && upgrade.getType().isPeripheral();
} }

View File

@ -178,7 +178,8 @@ public class TurtleBrain implements ITurtleAccess
public ComputerProxy getProxy() public ComputerProxy getProxy()
{ {
if(m_proxy == null) { if( m_proxy == null )
{
m_proxy = new ComputerProxy() m_proxy = new ComputerProxy()
{ {
@Override @Override

View File

@ -75,7 +75,7 @@ public class TurtleCompareCommand implements ITurtleCommand
// See if the block drops anything with the same ID as itself // See if the block drops anything with the same ID as itself
// (try 5 times to try and beat random number generators) // (try 5 times to try and beat random number generators)
for( int i=0; (i<5) && lookAtStack.isEmpty(); ++i ) for( int i = 0; (i < 5) && lookAtStack.isEmpty(); i++ )
{ {
NonNullList<ItemStack> drops = NonNullList.create(); NonNullList<ItemStack> drops = NonNullList.create();
lookAtBlock.getDrops( drops, world, newPosition, lookAtState, 0 ); lookAtBlock.getDrops( drops, world, newPosition, lookAtState, 0 );

View File

@ -10,8 +10,8 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.ITurtleCommand;
import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.TurtleCommandResult;
import dan200.computercraft.shared.util.WorldUtil; import dan200.computercraft.shared.util.WorldUtil;
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;

View File

@ -107,7 +107,7 @@ public class TurtlePlayer extends FakePlayer
// Store (or drop) anything else we found // Store (or drop) anything else we found
BlockPos dropPosition = turtle.getPosition(); BlockPos dropPosition = turtle.getPosition();
EnumFacing dropDirection = turtle.getDirection().getOpposite(); EnumFacing dropDirection = turtle.getDirection().getOpposite();
for( int i = 0; i < inventory.getSizeInventory(); ++i ) for( int i = 0; i < inventory.getSizeInventory(); i++ )
{ {
ItemStack stack = inventory.getStackInSlot( i ); ItemStack stack = inventory.getStackInSlot( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )

View File

@ -18,8 +18,11 @@ import javax.annotation.Nonnull;
public interface ITurtleItem extends IComputerItem, IColouredItem public interface ITurtleItem extends IComputerItem, IColouredItem
{ {
ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side ); ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
int getFuelLevel( ItemStack stack ); int getFuelLevel( ItemStack stack );
ResourceLocation getOverlay( ItemStack stack ); ResourceLocation getOverlay( ItemStack stack );
@Override @Override
int getColour( @Nonnull ItemStack stack ); int getColour( @Nonnull ItemStack stack );
} }

View File

@ -64,40 +64,56 @@ public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> imple
ItemStack turtle = ItemStack.EMPTY; ItemStack turtle = ItemStack.EMPTY;
ItemStack rightItem = ItemStack.EMPTY; ItemStack rightItem = ItemStack.EMPTY;
for( int y=0; y<inventory.getHeight(); ++y ) for( int y = 0; y < inventory.getHeight(); y++ )
{ {
if( turtle.isEmpty() ) if( turtle.isEmpty() )
{ {
// Search this row for potential turtles // Search this row for potential turtles
boolean finishedRow = false; boolean finishedRow = false;
for( int x=0; x<inventory.getWidth(); ++x ) for( int x = 0; x < inventory.getWidth(); x++ )
{ {
ItemStack item = inventory.getStackInRowAndColumn( x, y ); ItemStack item = inventory.getStackInRowAndColumn( x, y );
if( !item.isEmpty() ) { if( !item.isEmpty() )
if( finishedRow ) { {
if( finishedRow )
{
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if( item.getItem() instanceof ITurtleItem ) { if( item.getItem() instanceof ITurtleItem )
{
// Item is a turtle // Item is a turtle
if( turtle.isEmpty() ) { if( turtle.isEmpty() )
{
turtle = item; turtle = item;
} else { }
else
{
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
} else { }
else
{
// Item is not a turtle // Item is not a turtle
if( turtle.isEmpty() && leftItem.isEmpty() ) { if( turtle.isEmpty() && leftItem.isEmpty() )
{
leftItem = item; leftItem = item;
} else if( !turtle.isEmpty() && rightItem.isEmpty() ) { }
else if( !turtle.isEmpty() && rightItem.isEmpty() )
{
rightItem = item; rightItem = item;
} else { }
else
{
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
} }
} else { }
else
{
// Item is empty // Item is empty
if( !leftItem.isEmpty() || !turtle.isEmpty() ) { if( !leftItem.isEmpty() || !turtle.isEmpty() )
{
finishedRow = true; finishedRow = true;
} }
} }
@ -112,10 +128,11 @@ public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> imple
else else
{ {
// Turtle is already found, just check this row is empty // Turtle is already found, just check this row is empty
for( int x=0; x<inventory.getWidth(); ++x ) for( int x = 0; x < inventory.getWidth(); x++ )
{ {
ItemStack item = inventory.getStackInRowAndColumn( x, y ); ItemStack item = inventory.getStackInRowAndColumn( x, y );
if( !item.isEmpty() ) { if( !item.isEmpty() )
{
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
} }
@ -139,7 +156,7 @@ public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> imple
// Get the upgrades for the new items // Get the upgrades for the new items
ItemStack[] items = new ItemStack[] { rightItem, leftItem }; ItemStack[] items = new ItemStack[] { rightItem, leftItem };
for( int i=0; i<2; ++i ) for( int i = 0; i < 2; i++ )
{ {
if( !items[i].isEmpty() ) if( !items[i].isEmpty() )
{ {
@ -174,7 +191,7 @@ public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> imple
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

@ -43,9 +43,9 @@ public class TurtleInventoryCrafting extends InventoryCrafting
m_yStart = yStart; m_yStart = yStart;
// Check the non-relevant parts of the inventory are empty // Check the non-relevant parts of the inventory are empty
for( int x=0; x<TileTurtle.INVENTORY_WIDTH; ++x ) for( int x = 0; x < TileTurtle.INVENTORY_WIDTH; x++ )
{ {
for( int y=0; y<TileTurtle.INVENTORY_HEIGHT; ++y ) for( int y = 0; y < TileTurtle.INVENTORY_HEIGHT; y++ )
{ {
if( x < m_xStart || x >= m_xStart + 3 || if( x < m_xStart || x >= m_xStart + 3 ||
y < m_yStart || y >= m_yStart + 3 ) y < m_yStart || y >= m_yStart + 3 )
@ -100,7 +100,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
if( maxCount > 1 ) if( maxCount > 1 )
{ {
int minStackSize = 0; int minStackSize = 0;
for( int n=0; n<size; ++n ) for( int n = 0; n < size; n++ )
{ {
ItemStack stack = getStackInSlot( n ); ItemStack stack = getStackInSlot( n );
if( !stack.isEmpty() && (minStackSize == 0 || minStackSize > stack.getCount()) ) if( !stack.isEmpty() && (minStackSize == 0 || minStackSize > stack.getCount()) )
@ -124,7 +124,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
// Consume resources from the inventory // Consume resources from the inventory
NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems( this, world ); NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems( this, world );
for( int n=0; n<size; ++n ) for( int n = 0; n < size; n++ )
{ {
ItemStack stack = getStackInSlot( n ); ItemStack stack = getStackInSlot( n );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
@ -304,7 +304,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
@Override @Override
public void clear() public void clear()
{ {
for( int i=0; i<getSizeInventory(); ++i ) for( int i = 0; i < getSizeInventory(); i++ )
{ {
int j = modifyIndex( i ); int j = modifyIndex( i );
m_turtle.getInventory().setInventorySlotContents( j, ItemStack.EMPTY ); m_turtle.getInventory().setInventorySlotContents( j, ItemStack.EMPTY );

View File

@ -36,7 +36,8 @@ public enum Colour
return null; return null;
} }
public static Colour fromHex(int colour) { public static Colour fromHex( int colour )
{
for( Colour entry : VALUES ) for( Colour entry : VALUES )
{ {
if( entry.getHex() == colour ) return entry; if( entry.getHex() == colour ) return entry;

View File

@ -89,11 +89,16 @@ public class DirectionUtil
public static EnumFacing fromEntityRot( EntityLivingBase player ) public static EnumFacing fromEntityRot( EntityLivingBase player )
{ {
int rot = MathHelper.floor( (player.rotationYaw / 90.0f) + 0.5f ) & 0x3; int rot = MathHelper.floor( (player.rotationYaw / 90.0f) + 0.5f ) & 0x3;
switch( rot ) { switch( rot )
case 0: return EnumFacing.NORTH; {
case 1: return EnumFacing.EAST; case 0:
case 2: return EnumFacing.SOUTH; return EnumFacing.NORTH;
case 3: return EnumFacing.WEST; case 1:
return EnumFacing.EAST;
case 2:
return EnumFacing.SOUTH;
case 3:
return EnumFacing.WEST;
} }
return EnumFacing.NORTH; return EnumFacing.NORTH;
} }
@ -102,11 +107,16 @@ public class DirectionUtil
{ {
switch( dir ) switch( dir )
{ {
case NORTH: return 180.0f; case NORTH:
case SOUTH: return 0.0f; return 180.0f;
case WEST: return 90.0f; case SOUTH:
case EAST: return 270.0f; return 0.0f;
default: return 0.0f; case WEST:
return 90.0f;
case EAST:
return 270.0f;
default:
return 0.0f;
} }
} }
@ -114,9 +124,12 @@ public class DirectionUtil
{ {
switch( dir ) switch( dir )
{ {
case DOWN: return 90.0f; case DOWN:
case UP: return 270.0f; return 90.0f;
default: return 0.0f; case UP:
return 270.0f;
default:
return 0.0f;
} }
} }
} }

View File

@ -46,7 +46,7 @@ public class NBTUtil
{ {
nbt.setTag( "k" + Integer.toString( i ), key ); nbt.setTag( "k" + Integer.toString( i ), key );
nbt.setTag( "v" + Integer.toString( i ), value ); nbt.setTag( "v" + Integer.toString( i ), value );
++i; i++;
} }
} }
nbt.setInteger( "len", m.size() ); nbt.setInteger( "len", m.size() );
@ -62,7 +62,7 @@ public class NBTUtil
{ {
NBTTagCompound nbt = new NBTTagCompound(); NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger( "len", objects.length ); nbt.setInteger( "len", objects.length );
for( int i=0; i<objects.length; ++i ) for( int i = 0; i < objects.length; i++ )
{ {
Object object = objects[i]; Object object = objects[i];
NBTBase tag = toNBTTag( object ); NBTBase tag = toNBTTag( object );
@ -100,7 +100,7 @@ public class NBTUtil
NBTTagCompound c = (NBTTagCompound) tag; NBTTagCompound c = (NBTTagCompound) tag;
int len = c.getInteger( "len" ); int len = c.getInteger( "len" );
Map<Object, Object> map = new HashMap<>( len ); Map<Object, Object> map = new HashMap<>( len );
for( int i=0; i<len; ++i ) for( int i = 0; i < len; i++ )
{ {
Object key = fromNBTTag( c.getTag( "k" + Integer.toString( i ) ) ); Object key = fromNBTTag( c.getTag( "k" + Integer.toString( i ) ) );
Object value = fromNBTTag( c.getTag( "v" + Integer.toString( i ) ) ); Object value = fromNBTTag( c.getTag( "v" + Integer.toString( i ) ) );
@ -122,7 +122,7 @@ public class NBTUtil
if( len > 0 ) if( len > 0 )
{ {
Object[] objects = new Object[len]; Object[] objects = new Object[len];
for( int i=0; i<len; ++i ) for( int i = 0; i < len; i++ )
{ {
String key = Integer.toString( i ); String key = Integer.toString( i );
if( tagCompound.hasKey( key ) ) if( tagCompound.hasKey( key ) )

View File

@ -49,7 +49,7 @@ public class Palette
public void resetColours() public void resetColours()
{ {
for(int i = 0; i < Colour.values().length; ++i) for( int i = 0; i < Colour.values().length; i++ )
{ {
resetColour( i ); resetColour( i );
} }
@ -78,7 +78,7 @@ public class Palette
{ {
int[] rgb8 = new int[colours.length]; int[] rgb8 = new int[colours.length];
for(int i = 0; i < colours.length; ++i) for( int i = 0; i < colours.length; i++ )
{ {
rgb8[i] = encodeRGB8( colours[i] ); rgb8[i] = encodeRGB8( colours[i] );
} }
@ -94,7 +94,7 @@ public class Palette
if( rgb8.length != colours.length ) return; if( rgb8.length != colours.length ) return;
for(int i = 0; i < colours.length; ++i) for( int i = 0; i < colours.length; i++ )
{ {
colours[i] = decodeRGB8( rgb8[i] ); colours[i] = decodeRGB8( rgb8[i] );
} }

View File

@ -2,8 +2,8 @@ package dan200.computercraft.shared.util;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
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;
public class PeripheralUtil public class PeripheralUtil

View File

@ -43,10 +43,12 @@ public class RecipeUtil
JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" ); JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" );
if( patternJ.size() == 0 ) if( patternJ.size() == 0 )
{
throw new JsonSyntaxException( "Invalid pattern: empty pattern not allowed" ); throw new JsonSyntaxException( "Invalid pattern: empty pattern not allowed" );
}
String[] pattern = new String[patternJ.size()]; String[] pattern = new String[patternJ.size()];
for( int x = 0; x < pattern.length; ++x ) for( int x = 0; x < pattern.length; x++ )
{ {
String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" ); String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" );
if( x > 0 && pattern[0].length() != line.length() ) if( x > 0 && pattern[0].length() != line.length() )

View File

@ -46,7 +46,7 @@ public class StringUtil
{ {
byte[] chars = new byte[string.length()]; byte[] chars = new byte[string.length()];
for( int i = 0; i < chars.length; ++i ) for( int i = 0; i < chars.length; i++ )
{ {
char c = string.charAt( i ); char c = string.charAt( i );
chars[i] = c < 256 ? (byte) c : 63; chars[i] = c < 256 ? (byte) c : 63;

View File

@ -6,12 +6,10 @@
package dan200.computercraft.shared.util; package dan200.computercraft.shared.util;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
@ -125,13 +123,15 @@ public class WorldUtil
return new Vec3d( entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ ); return new Vec3d( entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ );
} }
public static Vec3d getRayEnd( EntityPlayer player) { public static Vec3d getRayEnd( EntityPlayer player )
{
double reach = player.getEntityAttribute( EntityPlayer.REACH_DISTANCE ).getAttributeValue(); double reach = player.getEntityAttribute( EntityPlayer.REACH_DISTANCE ).getAttributeValue();
Vec3d look = player.getLookVec(); Vec3d look = player.getLookVec();
return getRayStart( player ).add( look.x * reach, look.y * reach, look.z * reach ); return getRayStart( player ).add( look.x * reach, look.y * reach, look.z * reach );
} }
public static boolean isVecInsideInclusive(AxisAlignedBB bb , Vec3d vec) { public static boolean isVecInsideInclusive( AxisAlignedBB bb, Vec3d vec )
{
return vec.x >= bb.minX && vec.x <= bb.maxX && vec.y >= bb.minY && vec.y <= bb.maxY && vec.z >= bb.minZ && vec.z <= bb.maxZ; return vec.x >= bb.minX && vec.x <= bb.maxX && vec.y >= bb.minY && vec.y <= bb.maxY && vec.z >= bb.minZ && vec.z <= bb.maxZ;
} }