mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-03-24 04:16:58 +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:
parent
72b9d3d802
commit
2032e7a83a
@ -219,7 +219,8 @@ public class ComputerCraft
|
||||
public static PocketSpeaker pocketSpeaker;
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
public static class Config
|
||||
{
|
||||
public static Configuration config;
|
||||
|
||||
public static Property http_enable;
|
||||
@ -379,7 +380,7 @@ public class ComputerCraft
|
||||
Config.turtlesNeedFuel = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel );
|
||||
Config.turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" );
|
||||
|
||||
Config.maximumFilesOpen = Config.config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen);
|
||||
Config.maximumFilesOpen = Config.config.get( Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen );
|
||||
Config.maximumFilesOpen.setComment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." );
|
||||
|
||||
Config.turtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit );
|
||||
@ -394,13 +395,13 @@ public class ComputerCraft
|
||||
Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush );
|
||||
Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
|
||||
|
||||
Config.turtleDisabledActions = Config.config.get( Configuration.CATEGORY_GENERAL, "turtle_disabled_actions", new String[ 0 ] );
|
||||
Config.turtleDisabledActions = Config.config.get( Configuration.CATEGORY_GENERAL, "turtle_disabled_actions", new String[0] );
|
||||
Config.turtleDisabledActions.setComment( "A list of turtle actions which are disabled." );
|
||||
|
||||
Config.maxNotesPerTick = Config.config.get( Configuration.CATEGORY_GENERAL, "maxNotesPerTick", maxNotesPerTick );
|
||||
Config.maxNotesPerTick.setComment( "Maximum amount of notes a speaker can play at once" );
|
||||
|
||||
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
||||
for( Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues() )
|
||||
{
|
||||
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
|
||||
}
|
||||
@ -408,7 +409,8 @@ public class ComputerCraft
|
||||
syncConfig();
|
||||
}
|
||||
|
||||
public static void syncConfig() {
|
||||
public static void syncConfig()
|
||||
{
|
||||
|
||||
http_enable = Config.http_enable.getBoolean();
|
||||
http_websocket_enable = Config.http_websocket_enable.getBoolean();
|
||||
@ -451,7 +453,7 @@ public class ComputerCraft
|
||||
}
|
||||
}
|
||||
|
||||
maxNotesPerTick = Math.max(1, Config.maxNotesPerTick.getInt());
|
||||
maxNotesPerTick = Math.max( 1, Config.maxNotesPerTick.getInt() );
|
||||
|
||||
Config.config.save();
|
||||
}
|
||||
@ -580,7 +582,7 @@ public class ComputerCraft
|
||||
|
||||
public static File getBaseDir()
|
||||
{
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getFile(".");
|
||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getFile( "." );
|
||||
}
|
||||
|
||||
public static File getResourcePackDir()
|
||||
@ -602,7 +604,7 @@ public class ComputerCraft
|
||||
|
||||
public static void sendToPlayer( EntityPlayer player, ComputerCraftPacket packet )
|
||||
{
|
||||
networkEventChannel.sendTo( encode( packet ), (EntityPlayerMP)player );
|
||||
networkEventChannel.sendTo( encode( packet ), (EntityPlayerMP) player );
|
||||
}
|
||||
|
||||
public static void sendToAllPlayers( ComputerCraftPacket packet )
|
||||
@ -843,7 +845,8 @@ public class ComputerCraft
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IPocketUpgrade getPocketUpgrade(String id) {
|
||||
public static IPocketUpgrade getPocketUpgrade( String id )
|
||||
{
|
||||
return pocketUpgrades.get( id );
|
||||
}
|
||||
|
||||
@ -851,7 +854,7 @@ public class ComputerCraft
|
||||
{
|
||||
if( stack.isEmpty() ) return null;
|
||||
|
||||
for (IPocketUpgrade upgrade : pocketUpgrades.values())
|
||||
for( IPocketUpgrade upgrade : pocketUpgrades.values() )
|
||||
{
|
||||
ItemStack craftingStack = upgrade.getCraftingItem();
|
||||
if( !craftingStack.isEmpty() && InventoryUtil.areItemsStackable( stack, craftingStack ) )
|
||||
@ -863,10 +866,13 @@ public class ComputerCraft
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades() {
|
||||
public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades()
|
||||
{
|
||||
List<IPocketUpgrade> upgrades = new ArrayList<>();
|
||||
for(IPocketUpgrade upgrade : pocketUpgrades.values()) {
|
||||
if(upgrade instanceof PocketModem || upgrade instanceof PocketSpeaker) {
|
||||
for( IPocketUpgrade upgrade : pocketUpgrades.values() )
|
||||
{
|
||||
if( upgrade instanceof PocketModem || upgrade instanceof PocketSpeaker )
|
||||
{
|
||||
upgrades.add( upgrade );
|
||||
}
|
||||
}
|
||||
@ -886,7 +892,7 @@ public class ComputerCraft
|
||||
|
||||
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
|
||||
{
|
||||
return IDAssigner.getNextIDFromDirectory(new File(getWorldDir(world), parentSubPath));
|
||||
return IDAssigner.getNextIDFromDirectory( new File( getWorldDir( world ), parentSubPath ) );
|
||||
}
|
||||
|
||||
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
|
||||
@ -972,7 +978,7 @@ public class ComputerCraft
|
||||
// Return the combination of all the mounts found
|
||||
if( mounts.size() >= 2 )
|
||||
{
|
||||
IMount[] mountArray = new IMount[ mounts.size() ];
|
||||
IMount[] mountArray = new IMount[mounts.size()];
|
||||
mounts.toArray( mountArray );
|
||||
return new ComboMount( mountArray );
|
||||
}
|
||||
@ -1078,16 +1084,22 @@ public class ComputerCraft
|
||||
}
|
||||
|
||||
URL url;
|
||||
try {
|
||||
try
|
||||
{
|
||||
url = new URL( path );
|
||||
} catch (MalformedURLException e1) {
|
||||
}
|
||||
catch( MalformedURLException e1 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
File file;
|
||||
try {
|
||||
try
|
||||
{
|
||||
file = new File( url.toURI() );
|
||||
} catch(URISyntaxException e) {
|
||||
}
|
||||
catch( URISyntaxException e )
|
||||
{
|
||||
file = new File( url.getPath() );
|
||||
}
|
||||
return file;
|
||||
@ -1096,7 +1108,7 @@ public class ComputerCraft
|
||||
private static File getDebugCodeDir( Class<?> modClass )
|
||||
{
|
||||
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
int bangIndex = path.indexOf("!");
|
||||
int bangIndex = path.indexOf( "!" );
|
||||
if( bangIndex >= 0 )
|
||||
{
|
||||
return null;
|
||||
@ -1139,7 +1151,7 @@ public class ComputerCraft
|
||||
turtleProxy.setDropConsumer( world, pos, consumer );
|
||||
}
|
||||
|
||||
public static List<ItemStack> clearDropConsumer( )
|
||||
public static List<ItemStack> clearDropConsumer()
|
||||
{
|
||||
return turtleProxy.clearDropConsumer();
|
||||
}
|
||||
|
@ -49,9 +49,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_getVersion != null )
|
||||
{
|
||||
try {
|
||||
return (String)computerCraft_getVersion.invoke( null );
|
||||
} catch (Exception e) {
|
||||
try
|
||||
{
|
||||
return (String) computerCraft_getVersion.invoke( null );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -82,9 +85,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_createUniqueNumberedSaveDir != null )
|
||||
{
|
||||
try {
|
||||
return (Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
|
||||
} catch (Exception e) {
|
||||
try
|
||||
{
|
||||
return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -115,9 +121,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_createSaveDirMount != null )
|
||||
{
|
||||
try {
|
||||
return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
|
||||
} catch (Exception e){
|
||||
try
|
||||
{
|
||||
return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -148,9 +157,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_createResourceMount != null )
|
||||
{
|
||||
try {
|
||||
return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
|
||||
} catch (Exception e){
|
||||
try
|
||||
{
|
||||
return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -167,11 +179,14 @@ public final class ComputerCraftAPI
|
||||
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider handler )
|
||||
{
|
||||
findCC();
|
||||
if ( computerCraft_registerPeripheralProvider != null)
|
||||
if( computerCraft_registerPeripheralProvider != null )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
computerCraft_registerPeripheralProvider.invoke( null, handler );
|
||||
} catch (Exception e){
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -192,9 +207,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_registerTurtleUpgrade != null )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
|
||||
} catch( Exception e ) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -212,9 +230,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_registerBundledRedstoneProvider != null )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
computerCraft_registerBundledRedstoneProvider.invoke( null, handler );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -235,9 +256,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_getDefaultBundledRedstoneOutput != null )
|
||||
{
|
||||
try {
|
||||
return (Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
|
||||
} catch (Exception e){
|
||||
try
|
||||
{
|
||||
return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -255,9 +279,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_registerMediaProvider != null )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
computerCraft_registerMediaProvider.invoke( null, handler );
|
||||
} catch (Exception e){
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -276,9 +303,12 @@ public final class ComputerCraftAPI
|
||||
findCC();
|
||||
if( computerCraft_registerPermissionProvider != null )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
computerCraft_registerPermissionProvider.invoke( null, handler );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -287,10 +317,14 @@ public final class ComputerCraftAPI
|
||||
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
||||
{
|
||||
findCC();
|
||||
if(computerCraft_registerPocketUpgrade != null) {
|
||||
try {
|
||||
if( computerCraft_registerPocketUpgrade != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
computerCraft_registerPocketUpgrade.invoke( null, upgrade );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
@ -309,7 +343,9 @@ public final class ComputerCraftAPI
|
||||
try
|
||||
{
|
||||
return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
// It failed;
|
||||
}
|
||||
}
|
||||
@ -394,12 +430,14 @@ public final class ComputerCraftAPI
|
||||
|
||||
private static void findCC()
|
||||
{
|
||||
if( !ccSearched ) {
|
||||
try {
|
||||
if( !ccSearched )
|
||||
{
|
||||
try
|
||||
{
|
||||
computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" );
|
||||
computerCraft_getVersion = findCCMethod( "getVersion", new Class<?>[]{
|
||||
computerCraft_getVersion = findCCMethod( "getVersion", new Class<?>[] {
|
||||
} );
|
||||
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class<?>[]{
|
||||
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class<?>[] {
|
||||
World.class, String.class
|
||||
} );
|
||||
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] {
|
||||
@ -437,12 +475,16 @@ public final class ComputerCraftAPI
|
||||
computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] {
|
||||
IWiredElement.class
|
||||
} );
|
||||
computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[]{
|
||||
computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[] {
|
||||
IBlockAccess.class, BlockPos.class, EnumFacing.class
|
||||
} );
|
||||
} catch( Exception e ) {
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
System.out.println( "ComputerCraftAPI: ComputerCraft not found." );
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
ccSearched = true;
|
||||
}
|
||||
}
|
||||
@ -450,13 +492,16 @@ public final class ComputerCraftAPI
|
||||
|
||||
private static Method findCCMethod( String name, Class<?>[] args )
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
if( computerCraft != null )
|
||||
{
|
||||
return computerCraft.getMethod( name, args );
|
||||
}
|
||||
return null;
|
||||
} catch( NoSuchMethodException e ) {
|
||||
}
|
||||
catch( NoSuchMethodException e )
|
||||
{
|
||||
System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
|
||||
return null;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class FixedWidthFontRenderer
|
||||
|
||||
private static void greyscaleify( double[] rgb )
|
||||
{
|
||||
Arrays.fill( rgb, ( rgb[0] + rgb[1] + rgb[2] ) / 3.0f );
|
||||
Arrays.fill( rgb, (rgb[0] + rgb[1] + rgb[2]) / 3.0f );
|
||||
}
|
||||
|
||||
private void drawChar( BufferBuilder renderer, double x, double y, int index, int color, Palette p, boolean greyscale )
|
||||
@ -44,13 +44,13 @@ public class FixedWidthFontRenderer
|
||||
int row = index / 16;
|
||||
|
||||
double[] colour = p.getColour( 15 - color );
|
||||
if(greyscale)
|
||||
if( greyscale )
|
||||
{
|
||||
greyscaleify( colour );
|
||||
}
|
||||
float r = (float)colour[0];
|
||||
float g = (float)colour[1];
|
||||
float b = (float)colour[2];
|
||||
float r = (float) colour[0];
|
||||
float g = (float) colour[1];
|
||||
float b = (float) colour[2];
|
||||
|
||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||
@ -66,13 +66,13 @@ public class FixedWidthFontRenderer
|
||||
private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
|
||||
{
|
||||
double[] colour = p.getColour( 15 - color );
|
||||
if(greyscale)
|
||||
if( greyscale )
|
||||
{
|
||||
greyscaleify( colour );
|
||||
}
|
||||
float r = (float)colour[0];
|
||||
float g = (float)colour[1];
|
||||
float b = (float)colour[2];
|
||||
float r = (float) colour[0];
|
||||
float g = (float) colour[1];
|
||||
float b = (float) colour[2];
|
||||
|
||||
renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
@ -96,7 +96,7 @@ public class FixedWidthFontRenderer
|
||||
if( leftMarginSize > 0.0 )
|
||||
{
|
||||
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
|
||||
if( colour1 < 0 || (greyScale && !isGreyScale(colour1)) )
|
||||
if( colour1 < 0 || (greyScale && !isGreyScale( colour1 )) )
|
||||
{
|
||||
colour1 = 15;
|
||||
}
|
||||
@ -105,7 +105,7 @@ public class FixedWidthFontRenderer
|
||||
if( rightMarginSize > 0.0 )
|
||||
{
|
||||
int colour2 = "0123456789abcdef".indexOf( backgroundColour.charAt( backgroundColour.length() - 1 ) );
|
||||
if( colour2 < 0 || (greyScale && !isGreyScale(colour2)) )
|
||||
if( colour2 < 0 || (greyScale && !isGreyScale( colour2 )) )
|
||||
{
|
||||
colour2 = 15;
|
||||
}
|
||||
@ -114,7 +114,7 @@ public class FixedWidthFontRenderer
|
||||
for( int i = 0; i < backgroundColour.length(); i++ )
|
||||
{
|
||||
int colour = "0123456789abcdef".indexOf( backgroundColour.charAt( i ) );
|
||||
if( colour < 0 || ( greyScale && !isGreyScale( colour ) ) )
|
||||
if( colour < 0 || (greyScale && !isGreyScale( colour )) )
|
||||
{
|
||||
colour = 15;
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class FixedWidthFontRenderer
|
||||
{
|
||||
// Switch colour
|
||||
int colour = "0123456789abcdef".indexOf( textColour.charAt( i ) );
|
||||
if( colour < 0 || ( greyScale && !isGreyScale( colour ) ) )
|
||||
if( colour < 0 || (greyScale && !isGreyScale( colour )) )
|
||||
{
|
||||
colour = 0;
|
||||
}
|
||||
@ -162,21 +162,21 @@ public class FixedWidthFontRenderer
|
||||
// Draw the quads
|
||||
drawStringBackgroundPart( x, y, backgroundColour, leftMarginSize, rightMarginSize, greyScale, p );
|
||||
}
|
||||
|
||||
|
||||
// Draw text
|
||||
if( s != null && textColour != null )
|
||||
{
|
||||
// Bind the font texture
|
||||
bindFont();
|
||||
|
||||
|
||||
// Draw the quads
|
||||
drawStringTextPart( x, y, s, textColour, greyScale, p );
|
||||
}
|
||||
}
|
||||
|
||||
public int getStringWidth(String s)
|
||||
public int getStringWidth( String s )
|
||||
{
|
||||
if(s == null)
|
||||
if( s == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class GuiComputer extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int k) throws IOException
|
||||
protected void keyTyped( char c, int k ) throws IOException
|
||||
{
|
||||
if( k == 1 )
|
||||
{
|
||||
@ -127,7 +127,7 @@ public class GuiComputer extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
|
||||
{
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ public class GuiComputer extends GuiContainer
|
||||
// Draw background
|
||||
drawDefaultBackground();
|
||||
|
||||
// Draw terminal
|
||||
// Draw terminal
|
||||
m_terminal.draw( this.mc, startX, startY, mouseX, mouseY );
|
||||
|
||||
// Draw a border around the terminal
|
||||
@ -173,15 +173,15 @@ public class GuiComputer extends GuiContainer
|
||||
}
|
||||
}
|
||||
|
||||
drawTexturedModalRect(startX - 12, startY - 12, 12, 28, 12, 12);
|
||||
drawTexturedModalRect(startX - 12, endY, 12, 40, 12, 16);
|
||||
drawTexturedModalRect(endX, startY - 12, 24, 28, 12, 12);
|
||||
drawTexturedModalRect(endX, endY, 24, 40, 12, 16);
|
||||
drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
|
||||
drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 16 );
|
||||
drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
|
||||
drawTexturedModalRect( endX, endY, 24, 40, 12, 16 );
|
||||
|
||||
drawTexturedModalRect(startX, startY-12, 0, 0, endX - startX, 12);
|
||||
drawTexturedModalRect(startX, endY, 0, 12, endX - startX, 16);
|
||||
drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
|
||||
drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 16 );
|
||||
|
||||
drawTexturedModalRect(startX-12, startY, 0, 28, 12, endY - startY);
|
||||
drawTexturedModalRect(endX, startY, 36, 28, 12, endY - startY);
|
||||
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||
drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class GuiConfigCC extends GuiConfig
|
||||
private static List<IConfigElement> getConfigElements()
|
||||
{
|
||||
ArrayList<IConfigElement> elements = new ArrayList<>();
|
||||
for (Property property : ComputerCraft.Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
||||
for( Property property : ComputerCraft.Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues() )
|
||||
{
|
||||
elements.add( new ConfigElement( property ) );
|
||||
}
|
||||
|
@ -22,33 +22,33 @@ public class GuiDiskDrive extends GuiContainer
|
||||
|
||||
public GuiDiskDrive( InventoryPlayer inventoryplayer, TileDiskDrive diskDrive )
|
||||
{
|
||||
super( new ContainerDiskDrive(inventoryplayer, diskDrive) );
|
||||
super( new ContainerDiskDrive( inventoryplayer, diskDrive ) );
|
||||
m_diskDrive = diskDrive;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
|
||||
{
|
||||
String title = m_diskDrive.getDisplayName().getUnformattedText();
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 );
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
|
||||
protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
|
||||
{
|
||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
this.mc.getTextureManager().bindTexture( background );
|
||||
int l = (width - xSize) / 2;
|
||||
int i1 = (height - ySize) / 2;
|
||||
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
|
||||
drawTexturedModalRect( l, i1, 0, 0, xSize, ySize );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks)
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
renderHoveredToolTip(mouseX, mouseY);
|
||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
@ -17,46 +17,46 @@ import net.minecraft.util.ResourceLocation;
|
||||
public class GuiPrinter extends GuiContainer
|
||||
{
|
||||
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||
|
||||
|
||||
private TilePrinter m_printer;
|
||||
private ContainerPrinter m_container;
|
||||
|
||||
public GuiPrinter(InventoryPlayer inventoryplayer, TilePrinter printer)
|
||||
public GuiPrinter( InventoryPlayer inventoryplayer, TilePrinter printer )
|
||||
{
|
||||
super(new ContainerPrinter(inventoryplayer, printer));
|
||||
super( new ContainerPrinter( inventoryplayer, printer ) );
|
||||
m_printer = printer;
|
||||
m_container = (ContainerPrinter)inventorySlots;
|
||||
m_container = (ContainerPrinter) inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
|
||||
{
|
||||
String title = m_printer.getDisplayName().getUnformattedText();
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 );
|
||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
|
||||
protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
|
||||
{
|
||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
this.mc.getTextureManager().bindTexture( background );
|
||||
int startX = (width - xSize) / 2;
|
||||
int startY = (height - ySize) / 2;
|
||||
drawTexturedModalRect(startX, startY, 0, 0, xSize, ySize);
|
||||
|
||||
drawTexturedModalRect( startX, startY, 0, 0, xSize, ySize );
|
||||
|
||||
boolean printing = m_container.isPrinting();
|
||||
if( printing )
|
||||
{
|
||||
drawTexturedModalRect(startX + 34, startY + 21, 176, 0, 25, 45);
|
||||
drawTexturedModalRect( startX + 34, startY + 21, 176, 0, 25, 45 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks)
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
renderHoveredToolTip(mouseX, mouseY);
|
||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ public class GuiPrintout extends GuiContainer
|
||||
super( container );
|
||||
|
||||
String[] text = ItemPrintout.getText( container.getStack() );
|
||||
m_text = new TextBuffer[ text.length ];
|
||||
for( int i = 0; i < m_text.length; ++i ) m_text[ i ] = new TextBuffer( text[ i ] );
|
||||
m_text = new TextBuffer[text.length];
|
||||
for( int i = 0; i < m_text.length; i++ ) m_text[i] = new TextBuffer( text[i] );
|
||||
|
||||
String[] colours = ItemPrintout.getColours( container.getStack() );
|
||||
m_colours = new TextBuffer[ colours.length ];
|
||||
for( int i = 0; i < m_colours.length; ++i ) m_colours[ i ] = new TextBuffer( colours[ i ] );
|
||||
m_colours = new TextBuffer[colours.length];
|
||||
for( int i = 0; i < m_colours.length; i++ ) m_colours[i] = new TextBuffer( colours[i] );
|
||||
|
||||
m_page = 0;
|
||||
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||
|
@ -60,10 +60,10 @@ public class GuiTurtle extends GuiContainer
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
Keyboard.enableRepeatEvents( true );
|
||||
m_terminalGui = new WidgetTerminal(
|
||||
( width - xSize ) / 2 + 8,
|
||||
( height - ySize ) / 2 + 8,
|
||||
(width - xSize) / 2 + 8,
|
||||
(height - ySize) / 2 + 8,
|
||||
ComputerCraft.terminalWidth_turtle,
|
||||
ComputerCraft.terminalHeight_turtle,
|
||||
() -> m_computer,
|
||||
@ -76,7 +76,7 @@ public class GuiTurtle extends GuiContainer
|
||||
public void onGuiClosed()
|
||||
{
|
||||
super.onGuiClosed();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
Keyboard.enableRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -87,7 +87,7 @@ public class GuiTurtle extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int k) throws IOException
|
||||
protected void keyTyped( char c, int k ) throws IOException
|
||||
{
|
||||
if( k == 1 )
|
||||
{
|
||||
@ -100,7 +100,7 @@ public class GuiTurtle extends GuiContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) throws IOException
|
||||
protected void mouseClicked( int x, int y, int button ) throws IOException
|
||||
{
|
||||
super.mouseClicked( x, y, button );
|
||||
m_terminalGui.mouseClicked( x, y, button );
|
||||
@ -132,10 +132,10 @@ public class GuiTurtle extends GuiContainer
|
||||
if( slot >= 0 )
|
||||
{
|
||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
int slotX = (slot%4);
|
||||
int slotY = (slot/4);
|
||||
int slotX = (slot % 4);
|
||||
int slotY = (slot / 4);
|
||||
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
|
||||
drawTexturedModalRect(x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24);
|
||||
drawTexturedModalRect( x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,16 +151,16 @@ public class GuiTurtle extends GuiContainer
|
||||
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
|
||||
int x = (width - xSize) / 2;
|
||||
int y = (height - ySize) / 2;
|
||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||
drawTexturedModalRect( x, y, 0, 0, xSize, ySize );
|
||||
|
||||
drawSelectionSlot( advanced );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks)
|
||||
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
drawDefaultBackground();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
renderHoveredToolTip(mouseX, mouseY);
|
||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||
renderHoveredToolTip( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
@ -122,8 +122,8 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
|
||||
// Queue the "paste" event
|
||||
queueEvent( "paste", new Object[]{
|
||||
clipboard
|
||||
queueEvent( "paste", new Object[] {
|
||||
clipboard
|
||||
} );
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
|
||||
// Queue the "key" event
|
||||
queueEvent( "key", new Object[]{
|
||||
queueEvent( "key", new Object[] {
|
||||
key, repeat
|
||||
} );
|
||||
handled = true;
|
||||
@ -152,7 +152,7 @@ public class WidgetTerminal extends Widget
|
||||
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
|
||||
{
|
||||
// Queue the "char" event
|
||||
queueEvent( "char", new Object[]{
|
||||
queueEvent( "char", new Object[] {
|
||||
Character.toString( ch )
|
||||
} );
|
||||
handled = true;
|
||||
@ -171,7 +171,7 @@ public class WidgetTerminal extends Widget
|
||||
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
||||
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
|
||||
{
|
||||
if( !m_focus && button == 0)
|
||||
if( !m_focus && button == 0 )
|
||||
{
|
||||
m_focus = true;
|
||||
}
|
||||
@ -184,12 +184,12 @@ public class WidgetTerminal extends Widget
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
{
|
||||
int charX = ( mouseX - ( getXPosition() + m_leftMargin ) ) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int charY = ( mouseY - ( getYPosition() + m_topMargin ) ) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||
|
||||
computer.queueEvent( "mouse_click", new Object[]{
|
||||
computer.queueEvent( "mouse_click", new Object[] {
|
||||
button + 1, charX + 1, charY + 1
|
||||
} );
|
||||
|
||||
@ -222,7 +222,7 @@ public class WidgetTerminal extends Widget
|
||||
if( m_focus )
|
||||
{
|
||||
// Queue the "key_up" event
|
||||
queueEvent( "key_up", new Object[]{
|
||||
queueEvent( "key_up", new Object[] {
|
||||
key
|
||||
} );
|
||||
handled = true;
|
||||
@ -244,8 +244,8 @@ public class WidgetTerminal extends Widget
|
||||
Terminal term = computer.getTerminal();
|
||||
if( term != null )
|
||||
{
|
||||
int charX = ( mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int charY = ( mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||
|
||||
@ -253,7 +253,7 @@ public class WidgetTerminal extends Widget
|
||||
{
|
||||
if( m_focus )
|
||||
{
|
||||
computer.queueEvent( "mouse_up", new Object[]{
|
||||
computer.queueEvent( "mouse_up", new Object[] {
|
||||
m_lastClickButton + 1, charX + 1, charY + 1
|
||||
} );
|
||||
}
|
||||
@ -270,20 +270,20 @@ public class WidgetTerminal extends Widget
|
||||
{
|
||||
if( wheelChange < 0 )
|
||||
{
|
||||
computer.queueEvent( "mouse_scroll", new Object[]{
|
||||
1, charX + 1, charY + 1
|
||||
computer.queueEvent( "mouse_scroll", new Object[] {
|
||||
1, charX + 1, charY + 1
|
||||
} );
|
||||
}
|
||||
else if( wheelChange > 0 )
|
||||
{
|
||||
computer.queueEvent( "mouse_scroll", new Object[]{
|
||||
-1, charX + 1, charY + 1
|
||||
computer.queueEvent( "mouse_scroll", new Object[] {
|
||||
-1, charX + 1, charY + 1
|
||||
} );
|
||||
}
|
||||
|
||||
if( m_lastClickButton >= 0 && ( charX != m_lastClickX || charY != m_lastClickY ) )
|
||||
if( m_lastClickButton >= 0 && (charX != m_lastClickX || charY != m_lastClickY) )
|
||||
{
|
||||
computer.queueEvent( "mouse_drag", new Object[]{
|
||||
computer.queueEvent( "mouse_drag", new Object[] {
|
||||
m_lastClickButton + 1, charX + 1, charY + 1
|
||||
} );
|
||||
m_lastClickX = charX;
|
||||
@ -318,7 +318,7 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
|
||||
// Ctrl+R for reboot
|
||||
if( Keyboard.isKeyDown(19) )
|
||||
if( Keyboard.isKeyDown( 19 ) )
|
||||
{
|
||||
if( m_rebootTimer < TERMINATE_TIME )
|
||||
{
|
||||
@ -339,7 +339,7 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
|
||||
// Ctrl+S for shutdown
|
||||
if( Keyboard.isKeyDown(31) )
|
||||
if( Keyboard.isKeyDown( 31 ) )
|
||||
{
|
||||
if( m_shutdownTimer < TERMINATE_TIME )
|
||||
{
|
||||
@ -377,7 +377,7 @@ public class WidgetTerminal extends Widget
|
||||
{
|
||||
// Draw the screen contents
|
||||
IComputer computer = m_computer.getComputer();
|
||||
Terminal terminal = ( computer != null ) ? computer.getTerminal() : null;
|
||||
Terminal terminal = (computer != null) ? computer.getTerminal() : null;
|
||||
if( terminal != null )
|
||||
{
|
||||
// Draw the terminal
|
||||
@ -405,7 +405,7 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
if( m_bottomMargin > 0 )
|
||||
{
|
||||
fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + ( th - 1 ) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
||||
fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
||||
}
|
||||
|
||||
// Draw lines
|
||||
@ -424,16 +424,17 @@ public class WidgetTerminal extends Widget
|
||||
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
||||
|
||||
fontRenderer.drawString(
|
||||
cursor,
|
||||
x + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
||||
startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
||||
cursorColour, null,
|
||||
0, 0,
|
||||
greyscale,
|
||||
palette
|
||||
cursor,
|
||||
x + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
||||
startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
||||
cursorColour, null,
|
||||
0, 0,
|
||||
greyscale,
|
||||
palette
|
||||
);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw a black background
|
||||
mc.getTextureManager().bindTexture( background );
|
||||
@ -442,7 +443,8 @@ public class WidgetTerminal extends Widget
|
||||
try
|
||||
{
|
||||
drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
|
||||
} finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ import javax.annotation.Nonnull;
|
||||
public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
||||
{
|
||||
// IComputerCraftProxy implementation
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void preInit()
|
||||
{
|
||||
{
|
||||
super.preInit();
|
||||
|
||||
// Setup client forge handlers
|
||||
@ -102,7 +102,7 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
||||
private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names )
|
||||
{
|
||||
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] );
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||
if( resourceManager instanceof SimpleReloadableResourceManager )
|
||||
{
|
||||
SimpleReloadableResourceManager reloadableResourceManager = (SimpleReloadableResourceManager)resourceManager;
|
||||
SimpleReloadableResourceManager reloadableResourceManager = (SimpleReloadableResourceManager) resourceManager;
|
||||
reloadableResourceManager.registerReloadListener( m_turtleSmartItemModel );
|
||||
}
|
||||
}
|
||||
|
@ -110,9 +110,9 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
{
|
||||
ItemComputer itemComputer = (ItemComputer) stack.getItem();
|
||||
ComputerFamily family = itemComputer.getFamily( stack.getItemDamage() );
|
||||
return ( family == ComputerFamily.Advanced ) ? advanced_computer : computer;
|
||||
return (family == ComputerFamily.Advanced) ? advanced_computer : computer;
|
||||
}
|
||||
}, new String[]{ "computer", "advanced_computer" } );
|
||||
}, new String[] { "computer", "advanced_computer" } );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 0, "peripheral" );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 1, "wireless_modem" );
|
||||
registerItemModel( ComputerCraft.Blocks.peripheral, 2, "monitor" );
|
||||
@ -279,7 +279,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
private void registerItemModel( Item item, ItemMeshDefinition definition, String[] names )
|
||||
{
|
||||
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] );
|
||||
}
|
||||
@ -296,7 +296,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
@Override
|
||||
public boolean getGlobalCursorBlink()
|
||||
{
|
||||
return ( m_tick / 8) % 2 == 0;
|
||||
return (m_tick / 8) % 2 == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -316,9 +316,12 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
{
|
||||
List<String> info = new ArrayList<>( 1 );
|
||||
recordStack.getItem().addInformation( recordStack, null, info, ITooltipFlag.TooltipFlags.NORMAL );
|
||||
if( info.size() > 0 ) {
|
||||
if( info.size() > 0 )
|
||||
{
|
||||
return info.get( 0 );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.getRecordInfo( recordStack );
|
||||
}
|
||||
}
|
||||
@ -427,7 +430,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
case ComputerCraftPacket.ComputerChanged:
|
||||
case ComputerCraftPacket.ComputerTerminalChanged:
|
||||
{
|
||||
int instanceID = packet.m_dataInt[ 0 ];
|
||||
int instanceID = packet.m_dataInt[0];
|
||||
if( !ComputerCraft.clientComputerRegistry.contains( instanceID ) )
|
||||
{
|
||||
ComputerCraft.clientComputerRegistry.add( instanceID, new ClientComputer( instanceID ) );
|
||||
@ -437,7 +440,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
}
|
||||
case ComputerCraftPacket.ComputerDeleted:
|
||||
{
|
||||
int instanceID = packet.m_dataInt[ 0 ];
|
||||
int instanceID = packet.m_dataInt[0];
|
||||
if( ComputerCraft.clientComputerRegistry.contains( instanceID ) )
|
||||
{
|
||||
ComputerCraft.clientComputerRegistry.remove( instanceID );
|
||||
@ -446,13 +449,13 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
}
|
||||
case ComputerCraftPacket.PlayRecord:
|
||||
{
|
||||
BlockPos pos = new BlockPos( packet.m_dataInt[ 0 ], packet.m_dataInt[ 1 ], packet.m_dataInt[ 2 ] );
|
||||
BlockPos pos = new BlockPos( packet.m_dataInt[0], packet.m_dataInt[1], packet.m_dataInt[2] );
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if( packet.m_dataInt.length > 3 )
|
||||
{
|
||||
SoundEvent sound = SoundEvent.REGISTRY.getObjectById( packet.m_dataInt[ 3 ] );
|
||||
SoundEvent sound = SoundEvent.REGISTRY.getObjectById( packet.m_dataInt[3] );
|
||||
mc.world.playRecord( pos, sound );
|
||||
mc.ingameGUI.setRecordPlayingMessage( packet.m_dataString[ 0 ] );
|
||||
mc.ingameGUI.setRecordPlayingMessage( packet.m_dataString[0] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -551,7 +554,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
{
|
||||
case HELMET:
|
||||
case PORTAL:
|
||||
//case CROSSHAIRS:
|
||||
//case CROSSHAIRS:
|
||||
case BOSSHEALTH:
|
||||
case ARMOR:
|
||||
case HEALTH:
|
||||
@ -597,7 +600,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
private static class DiskColorHandler implements IItemColor
|
||||
{
|
||||
private final ItemDiskLegacy disk;
|
||||
|
@ -34,7 +34,7 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||
/**
|
||||
* Emulates map rendering for pocket computers
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
public class ItemPocketRenderer
|
||||
{
|
||||
@SubscribeEvent
|
||||
@ -89,8 +89,8 @@ public class ItemPocketRenderer
|
||||
ClientComputer computer = pocketComputer.createClientComputer( stack );
|
||||
|
||||
{
|
||||
// First render the background item. We use the item's model rather than a direct texture as this ensures
|
||||
// we display the pocket light and other such decorations.
|
||||
// First render the background item. We use the item's model rather than a direct texture as this ensures
|
||||
// we display the pocket light and other such decorations.
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
GlStateManager.scale( 1.0f, -1.0f, 1.0f );
|
||||
@ -215,7 +215,7 @@ public class ItemPocketRenderer
|
||||
}
|
||||
|
||||
// Setup the appropriate transformations. This is just copied from the
|
||||
// corresponding method in ItemRenderer.
|
||||
// corresponding method in ItemRenderer.
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||
float f1 = MathHelper.sqrt( swingProgress );
|
||||
|
@ -85,8 +85,8 @@ public final class ModelTransformer
|
||||
private final Matrix4f normalMatrix;
|
||||
|
||||
private int vertexIndex = 0, elementIndex = 0;
|
||||
private final Point3f[] before = new Point3f[ 4 ];
|
||||
private final Point3f[] after = new Point3f[ 4 ];
|
||||
private final Point3f[] before = new Point3f[4];
|
||||
private final Point3f[] after = new Point3f[4];
|
||||
|
||||
public NormalAwareTransformer( IVertexConsumer parent, Matrix4f positionMatrix, Matrix4f normalMatrix )
|
||||
{
|
||||
@ -112,13 +112,13 @@ public final class ModelTransformer
|
||||
Point3f newVec = new Point3f();
|
||||
positionMatrix.transform( vec, newVec );
|
||||
|
||||
float[] newData = new float[ 4 ];
|
||||
float[] newData = new float[4];
|
||||
newVec.get( newData );
|
||||
super.put( element, newData );
|
||||
|
||||
|
||||
before[ vertexIndex ] = vec;
|
||||
after[ vertexIndex ] = newVec;
|
||||
before[vertexIndex] = vec;
|
||||
after[vertexIndex] = newVec;
|
||||
break;
|
||||
}
|
||||
case NORMAL:
|
||||
@ -126,7 +126,7 @@ public final class ModelTransformer
|
||||
Vector3f vec = new Vector3f( data );
|
||||
normalMatrix.transform( vec );
|
||||
|
||||
float[] newData = new float[ 4 ];
|
||||
float[] newData = new float[4];
|
||||
vec.get( newData );
|
||||
super.put( element, newData );
|
||||
break;
|
||||
@ -150,17 +150,17 @@ public final class ModelTransformer
|
||||
Vector3f crossBefore = new Vector3f(), crossAfter = new Vector3f();
|
||||
|
||||
// Determine what cross product we expect to have
|
||||
temp1.sub( before[ 1 ], before[ 0 ] );
|
||||
temp2.sub( before[ 1 ], before[ 2 ] );
|
||||
temp1.sub( before[1], before[0] );
|
||||
temp2.sub( before[1], before[2] );
|
||||
crossBefore.cross( temp1, temp2 );
|
||||
normalMatrix.transform( crossBefore );
|
||||
|
||||
// And determine what cross product we actually have
|
||||
temp1.sub( after[ 1 ], after[ 0 ] );
|
||||
temp2.sub( after[ 1 ], after[ 2 ] );
|
||||
temp1.sub( after[1], after[0] );
|
||||
temp2.sub( after[1], after[2] );
|
||||
crossAfter.cross( temp1, temp2 );
|
||||
|
||||
// If the angle between expected and actual cross product is greater than
|
||||
// If the angle between expected and actual cross product is greater than
|
||||
// pi/2 radians then we will need to reorder our quads.
|
||||
return Math.abs( crossBefore.angle( crossAfter ) ) >= Math.PI / 2;
|
||||
}
|
||||
@ -189,7 +189,7 @@ public final class ModelTransformer
|
||||
private BakedQuadBuilder( VertexFormat format )
|
||||
{
|
||||
this.format = format;
|
||||
this.vertexData = new int[ format.getSize() ];
|
||||
this.vertexData = new int[format.getSize()];
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -241,9 +241,9 @@ public final class ModelTransformer
|
||||
int length = vertexData.length / 4;
|
||||
for( int i = 0; i < length; i++ )
|
||||
{
|
||||
int temp = vertexData[ a * length + i ];
|
||||
vertexData[ a * length + i ] = vertexData[ b * length + i ];
|
||||
vertexData[ b * length + i ] = temp;
|
||||
int temp = vertexData[a * length + i];
|
||||
vertexData[a * length + i] = vertexData[b * length + i];
|
||||
vertexData[b * length + i] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class PrintoutRenderer
|
||||
|
||||
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
|
||||
{
|
||||
fontRenderer.drawString( text[ start + line ], x, y + line * FONT_HEIGHT, colours[ start + line ], null, 0, 0, false, Palette.DEFAULT );
|
||||
fontRenderer.drawString( text[start + line], x, y + line * FONT_HEIGHT, colours[start + line], null, 0, 0, false, Palette.DEFAULT );
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class PrintoutRenderer
|
||||
|
||||
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
|
||||
{
|
||||
fontRenderer.drawString( new TextBuffer( text[ start + line ] ), x, y + line * FONT_HEIGHT, new TextBuffer( colours[ start + line ] ), null, 0, 0, false, Palette.DEFAULT );
|
||||
fontRenderer.drawString( new TextBuffer( text[start + line] ), x, y + line * FONT_HEIGHT, new TextBuffer( colours[start + line] ), null, 0, 0, false, Palette.DEFAULT );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,10 @@ import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
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.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
|
@ -51,7 +51,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
BlockPos monitorPos = monitor.getPos();
|
||||
|
||||
// Ensure each monitor terminal is rendered only once. We allow rendering a specific tile
|
||||
// multiple times in a single frame to ensure compatibility with shaders which may run a
|
||||
// multiple times in a single frame to ensure compatibility with shaders which may run a
|
||||
// pass multiple times.
|
||||
long renderFrame = ComputerCraft.getRenderFrame();
|
||||
if( originTerminal.lastRenderFrame == renderFrame && !monitorPos.equals( originTerminal.lastRenderPos ) )
|
||||
@ -85,8 +85,8 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
(origin.getHeight() - 0.5) - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
|
||||
0.5
|
||||
);
|
||||
double xSize = origin.getWidth() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );
|
||||
double ySize = origin.getHeight() - 2.0 * ( TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER );
|
||||
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||
|
||||
// Get renderers
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
@ -126,8 +126,8 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
GlStateManager.pushMatrix();
|
||||
try
|
||||
{
|
||||
double xScale = xSize / ( width * FixedWidthFontRenderer.FONT_WIDTH );
|
||||
double yScale = ySize / ( height * FixedWidthFontRenderer.FONT_HEIGHT );
|
||||
double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
|
||||
double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
|
||||
GlStateManager.scale( xScale, -yScale, 1.0 );
|
||||
|
||||
// Draw background
|
||||
@ -158,14 +158,14 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
}
|
||||
|
||||
// Backgrounds
|
||||
for( int y = 0; y < height; ++y )
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
fontRenderer.drawStringBackgroundPart(
|
||||
0, FixedWidthFontRenderer.FONT_HEIGHT * y,
|
||||
terminal.getBackgroundColourLine( y ),
|
||||
marginXSize, marginXSize,
|
||||
greyscale,
|
||||
palette
|
||||
0, FixedWidthFontRenderer.FONT_HEIGHT * y,
|
||||
terminal.getBackgroundColourLine( y ),
|
||||
marginXSize, marginXSize,
|
||||
greyscale,
|
||||
palette
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -186,14 +186,14 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
try
|
||||
{
|
||||
// Lines
|
||||
for( int y = 0; y < height; ++y )
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
fontRenderer.drawStringTextPart(
|
||||
0, FixedWidthFontRenderer.FONT_HEIGHT * y,
|
||||
terminal.getLine( y ),
|
||||
terminal.getTextColourLine( y ),
|
||||
greyscale,
|
||||
palette
|
||||
0, FixedWidthFontRenderer.FONT_HEIGHT * y,
|
||||
terminal.getLine( y ),
|
||||
terminal.getTextColourLine( y ),
|
||||
greyscale,
|
||||
palette
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -219,13 +219,13 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
||||
TextBuffer cursor = new TextBuffer( "_" );
|
||||
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
||||
fontRenderer.drawString(
|
||||
cursor,
|
||||
FixedWidthFontRenderer.FONT_WIDTH * cursorX,
|
||||
FixedWidthFontRenderer.FONT_HEIGHT * cursorY,
|
||||
cursorColour, null,
|
||||
0, 0,
|
||||
greyscale,
|
||||
palette
|
||||
cursor,
|
||||
FixedWidthFontRenderer.FONT_WIDTH * cursorX,
|
||||
FixedWidthFontRenderer.FONT_HEIGHT * cursorY,
|
||||
cursorColour, null,
|
||||
0, 0,
|
||||
greyscale,
|
||||
palette
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
||||
GlStateManager.rotate( -toolAngle, 1.0f, 0.0f, 0.0f );
|
||||
GlStateManager.translate( 0.0f, -0.5f, -0.5f );
|
||||
|
||||
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
||||
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
||||
if( pair != null )
|
||||
{
|
||||
if( pair.getRight() != null )
|
||||
@ -236,7 +236,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
VertexFormat format = DefaultVertexFormats.ITEM;
|
||||
buffer.begin( GL11.GL_QUADS, format );
|
||||
for (BakedQuad quad : quads)
|
||||
for( BakedQuad quad : quads )
|
||||
{
|
||||
VertexFormat quadFormat = quad.getFormat();
|
||||
if( quadFormat != format )
|
||||
@ -250,7 +250,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
||||
if( quad.hasTintIndex() && tints != null )
|
||||
{
|
||||
int index = quad.getTintIndex();
|
||||
if( index >= 0 && index < tints.length ) colour = tints[ index ] | 0xFF000000;
|
||||
if( index >= 0 && index < tints.length ) colour = tints[index] | 0xFF000000;
|
||||
}
|
||||
|
||||
LightUtil.renderQuadColor( buffer, quad, colour );
|
||||
|
@ -32,8 +32,8 @@ public class AddressPredicate
|
||||
|
||||
for( int i = 0; i < entry.length; i++ )
|
||||
{
|
||||
int value = 0xFF & entry[ i ];
|
||||
if( value < (0xFF & min[ i ]) || value > (0xFF & max[ i ]) ) return false;
|
||||
int value = 0xFF & entry[i];
|
||||
if( value < (0xFF & min[i]) || value > (0xFF & max[i]) ) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -85,13 +85,13 @@ public class AddressPredicate
|
||||
{
|
||||
if( size <= 0 )
|
||||
{
|
||||
minBytes[ i ] &= 0;
|
||||
maxBytes[ i ] |= 0xFF;
|
||||
minBytes[i] &= 0;
|
||||
maxBytes[i] |= 0xFF;
|
||||
}
|
||||
else if( size < 8 )
|
||||
{
|
||||
minBytes[ i ] &= 0xFF << (8 - size);
|
||||
maxBytes[ i ] |= ~(0xFF << (8 - size));
|
||||
minBytes[i] &= 0xFF << (8 - size);
|
||||
maxBytes[i] |= ~(0xFF << (8 - size));
|
||||
}
|
||||
|
||||
size -= 8;
|
||||
|
@ -58,7 +58,7 @@ public final class ArgumentHelper
|
||||
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
|
||||
{
|
||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||
Object value = args[ index ];
|
||||
Object value = args[index];
|
||||
if( value instanceof Number )
|
||||
{
|
||||
return ((Number) value).doubleValue();
|
||||
@ -77,7 +77,7 @@ public final class ArgumentHelper
|
||||
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
||||
{
|
||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||
Object value = args[ index ];
|
||||
Object value = args[index];
|
||||
if( value instanceof Number )
|
||||
{
|
||||
return checkReal( index, (Number) value ).longValue();
|
||||
@ -96,7 +96,7 @@ public final class ArgumentHelper
|
||||
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
||||
{
|
||||
if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
|
||||
Object value = args[ index ];
|
||||
Object value = args[index];
|
||||
if( value instanceof Boolean )
|
||||
{
|
||||
return (Boolean) value;
|
||||
@ -111,7 +111,7 @@ public final class ArgumentHelper
|
||||
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
||||
{
|
||||
if( index >= args.length ) throw badArgument( index, "string", "nil" );
|
||||
Object value = args[ index ];
|
||||
Object value = args[index];
|
||||
if( value instanceof String )
|
||||
{
|
||||
return (String) value;
|
||||
@ -122,12 +122,12 @@ public final class ArgumentHelper
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Nonnull
|
||||
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
||||
{
|
||||
if( index >= args.length ) throw badArgument( index, "table", "nil" );
|
||||
Object value = args[ index ];
|
||||
Object value = args[index];
|
||||
if( value instanceof Map )
|
||||
{
|
||||
return (Map<Object, Object>) value;
|
||||
@ -140,7 +140,7 @@ public final class ArgumentHelper
|
||||
|
||||
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||
{
|
||||
Object value = index < args.length ? args[ index ] : null;
|
||||
Object value = index < args.length ? args[index] : null;
|
||||
if( value == null )
|
||||
{
|
||||
return def;
|
||||
@ -162,7 +162,7 @@ public final class ArgumentHelper
|
||||
|
||||
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
||||
{
|
||||
Object value = index < args.length ? args[ index ] : null;
|
||||
Object value = index < args.length ? args[index] : null;
|
||||
if( value == null )
|
||||
{
|
||||
return def;
|
||||
@ -184,7 +184,7 @@ public final class ArgumentHelper
|
||||
|
||||
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
||||
{
|
||||
Object value = index < args.length ? args[ index ] : null;
|
||||
Object value = index < args.length ? args[index] : null;
|
||||
if( value == null )
|
||||
{
|
||||
return def;
|
||||
@ -201,7 +201,7 @@ public final class ArgumentHelper
|
||||
|
||||
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
||||
{
|
||||
Object value = index < args.length ? args[ index ] : null;
|
||||
Object value = index < args.length ? args[index] : null;
|
||||
if( value == null )
|
||||
{
|
||||
return def;
|
||||
@ -216,10 +216,10 @@ public final class ArgumentHelper
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
||||
{
|
||||
Object value = index < args.length ? args[ index ] : null;
|
||||
Object value = index < args.length ? args[index] : null;
|
||||
if( value == null )
|
||||
{
|
||||
return def;
|
||||
|
@ -33,13 +33,13 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
private IAPIEnvironment m_env;
|
||||
private FileSystem m_fileSystem;
|
||||
|
||||
|
||||
public FSAPI( IAPIEnvironment _env )
|
||||
{
|
||||
m_env = _env;
|
||||
m_fileSystem = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNames()
|
||||
{
|
||||
@ -49,13 +49,13 @@ public class FSAPI implements ILuaAPI
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startup( )
|
||||
public void startup()
|
||||
{
|
||||
m_fileSystem = m_env.getFileSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown( )
|
||||
public void shutdown()
|
||||
{
|
||||
m_fileSystem = null;
|
||||
}
|
||||
@ -94,11 +94,13 @@ public class FSAPI implements ILuaAPI
|
||||
// list
|
||||
String path = getString( args, 0 );
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
try {
|
||||
try
|
||||
{
|
||||
String[] results = m_fileSystem.list( path );
|
||||
Map<Object,Object> table = new HashMap<>();
|
||||
for(int i=0; i<results.length; ++i ) {
|
||||
table.put( i+1, results[i] );
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
for( int i = 0; i < results.length; i++ )
|
||||
{
|
||||
table.put( i + 1, results[i] );
|
||||
}
|
||||
return new Object[] { table };
|
||||
}
|
||||
@ -118,7 +120,7 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// getName
|
||||
String path = getString( args, 0 );
|
||||
return new Object[]{ FileSystem.getName( path ) };
|
||||
return new Object[] { FileSystem.getName( path ) };
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
@ -126,7 +128,7 @@ public class FSAPI implements ILuaAPI
|
||||
String path = getString( args, 0 );
|
||||
try
|
||||
{
|
||||
return new Object[]{ m_fileSystem.getSize( path ) };
|
||||
return new Object[] { m_fileSystem.getSize( path ) };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@ -137,41 +139,53 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// exists
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
return new Object[]{ m_fileSystem.exists( path ) };
|
||||
} catch( FileSystemException e ) {
|
||||
return new Object[]{ false };
|
||||
try
|
||||
{
|
||||
return new Object[] { m_fileSystem.exists( path ) };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
return new Object[] { false };
|
||||
}
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
// isDir
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
return new Object[]{ m_fileSystem.isDir( path ) };
|
||||
} catch( FileSystemException e ) {
|
||||
return new Object[]{ false };
|
||||
try
|
||||
{
|
||||
return new Object[] { m_fileSystem.isDir( path ) };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
return new Object[] { false };
|
||||
}
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
// isReadOnly
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
return new Object[]{ m_fileSystem.isReadOnly( path ) };
|
||||
} catch( FileSystemException e ) {
|
||||
return new Object[]{ false };
|
||||
try
|
||||
{
|
||||
return new Object[] { m_fileSystem.isReadOnly( path ) };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
return new Object[] { false };
|
||||
}
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
// makeDir
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
m_fileSystem.makeDir( path );
|
||||
return null;
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -180,11 +194,14 @@ public class FSAPI implements ILuaAPI
|
||||
// move
|
||||
String path = getString( args, 0 );
|
||||
String dest = getString( args, 1 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
m_fileSystem.move( path, dest );
|
||||
return null;
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -193,11 +210,14 @@ public class FSAPI implements ILuaAPI
|
||||
// copy
|
||||
String path = getString( args, 0 );
|
||||
String dest = getString( args, 1 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
m_fileSystem.copy( path, dest );
|
||||
return null;
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -205,11 +225,14 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// delete
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
m_fileSystem.delete( path );
|
||||
return null;
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -219,7 +242,8 @@ public class FSAPI implements ILuaAPI
|
||||
String path = getString( args, 0 );
|
||||
String mode = getString( args, 1 );
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
try {
|
||||
try
|
||||
{
|
||||
switch( mode )
|
||||
{
|
||||
case "r":
|
||||
@ -261,7 +285,9 @@ public class FSAPI implements ILuaAPI
|
||||
default:
|
||||
throw new LuaException( "Unsupported mode" );
|
||||
}
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
return new Object[] { null, e.getMessage() };
|
||||
}
|
||||
}
|
||||
@ -269,13 +295,16 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// getDrive
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
if( !m_fileSystem.exists( path ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Object[]{ m_fileSystem.getMountLabel( path ) };
|
||||
} catch( FileSystemException e ) {
|
||||
return new Object[] { m_fileSystem.getMountLabel( path ) };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -283,14 +312,17 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// getFreeSpace
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
long freeSpace = m_fileSystem.getFreeSpace( path );
|
||||
if( freeSpace >= 0 )
|
||||
{
|
||||
return new Object[]{ freeSpace };
|
||||
return new Object[] { freeSpace };
|
||||
}
|
||||
return new Object[]{ "unlimited" };
|
||||
} catch( FileSystemException e ) {
|
||||
return new Object[] { "unlimited" };
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -298,15 +330,19 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// find
|
||||
String path = getString( args, 0 );
|
||||
try {
|
||||
try
|
||||
{
|
||||
m_env.addTrackingChange( TrackingField.FS_OPS );
|
||||
String[] results = m_fileSystem.find( path );
|
||||
Map<Object,Object> table = new HashMap<>();
|
||||
for(int i=0; i<results.length; ++i ) {
|
||||
table.put( i+1, results[i] );
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
for( int i = 0; i < results.length; i++ )
|
||||
{
|
||||
table.put( i + 1, results[i] );
|
||||
}
|
||||
return new Object[] { table };
|
||||
} catch( FileSystemException e ) {
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
throw new LuaException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
@ -314,11 +350,11 @@ public class FSAPI implements ILuaAPI
|
||||
{
|
||||
// getDir
|
||||
String path = getString( args, 0 );
|
||||
return new Object[]{ FileSystem.getDirectory( path ) };
|
||||
return new Object[] { FileSystem.getDirectory( path ) };
|
||||
}
|
||||
default:
|
||||
{
|
||||
assert( false );
|
||||
assert (false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
@Override
|
||||
public String[] getNames()
|
||||
{
|
||||
return new String[]{
|
||||
return new String[] {
|
||||
"http"
|
||||
};
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
@Override
|
||||
public String[] getMethodNames()
|
||||
{
|
||||
return new String[]{
|
||||
return new String[] {
|
||||
"request",
|
||||
"checkURL",
|
||||
"websocket",
|
||||
@ -164,11 +164,11 @@ public class HTTPAPI implements ILuaAPI
|
||||
{
|
||||
m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( request ) );
|
||||
}
|
||||
return new Object[]{ true };
|
||||
return new Object[] { true };
|
||||
}
|
||||
catch( HTTPRequestException e )
|
||||
{
|
||||
return new Object[]{ false, e.getMessage() };
|
||||
return new Object[] { false, e.getMessage() };
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
@ -186,11 +186,11 @@ public class HTTPAPI implements ILuaAPI
|
||||
{
|
||||
m_httpTasks.add( HTTPExecutor.EXECUTOR.submit( check ) );
|
||||
}
|
||||
return new Object[]{ true };
|
||||
return new Object[] { true };
|
||||
}
|
||||
catch( HTTPRequestException e )
|
||||
{
|
||||
return new Object[]{ false, e.getMessage() };
|
||||
return new Object[] { false, e.getMessage() };
|
||||
}
|
||||
}
|
||||
case 2: // websocket
|
||||
@ -223,11 +223,11 @@ public class HTTPAPI implements ILuaAPI
|
||||
{
|
||||
m_httpTasks.add( connector );
|
||||
}
|
||||
return new Object[]{ true };
|
||||
return new Object[] { true };
|
||||
}
|
||||
catch( HTTPRequestException e )
|
||||
{
|
||||
return new Object[]{ false, e.getMessage() };
|
||||
return new Object[] { false, e.getMessage() };
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -23,27 +23,39 @@ public interface IAPIEnvironment extends IComputerOwned
|
||||
|
||||
@Override
|
||||
Computer getComputer();
|
||||
|
||||
int getComputerID();
|
||||
|
||||
IComputerEnvironment getComputerEnvironment();
|
||||
|
||||
Terminal getTerminal();
|
||||
|
||||
FileSystem getFileSystem();
|
||||
|
||||
|
||||
void shutdown();
|
||||
|
||||
void reboot();
|
||||
|
||||
void queueEvent( String event, Object[] args );
|
||||
|
||||
void setOutput( int side, int output );
|
||||
|
||||
int getOutput( int side );
|
||||
|
||||
int getInput( int side );
|
||||
|
||||
void setBundledOutput( int side, int output );
|
||||
|
||||
int getBundledOutput( int side );
|
||||
|
||||
int getBundledInput( int side );
|
||||
|
||||
|
||||
void setPeripheralChangeListener( IPeripheralChangeListener listener );
|
||||
|
||||
IPeripheral getPeripheral( int side );
|
||||
|
||||
String getLabel();
|
||||
|
||||
void setLabel( String label );
|
||||
|
||||
void addTrackingChange( TrackingField field, long change );
|
||||
|
@ -28,7 +28,7 @@ public class OSAPI implements ILuaAPI
|
||||
|
||||
private int m_nextTimerToken;
|
||||
private int m_nextAlarmToken;
|
||||
|
||||
|
||||
private static class Timer
|
||||
{
|
||||
public int m_ticksLeft;
|
||||
@ -38,7 +38,7 @@ public class OSAPI implements ILuaAPI
|
||||
m_ticksLeft = ticksLeft;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class Alarm implements Comparable<Alarm>
|
||||
{
|
||||
public final double m_time;
|
||||
@ -55,16 +55,21 @@ public class OSAPI implements ILuaAPI
|
||||
{
|
||||
double t = m_day * 24.0 + m_time;
|
||||
double ot = m_day * 24.0 + m_time;
|
||||
if( t < ot ) {
|
||||
if( t < ot )
|
||||
{
|
||||
return -1;
|
||||
} else if( t > ot ) {
|
||||
}
|
||||
else if( t > ot )
|
||||
{
|
||||
return 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public OSAPI( IAPIEnvironment environment )
|
||||
{
|
||||
m_apiEnvironment = environment;
|
||||
@ -73,9 +78,9 @@ public class OSAPI implements ILuaAPI
|
||||
m_timers = new HashMap<>();
|
||||
m_alarms = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
// ILuaAPI implementation
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNames()
|
||||
{
|
||||
@ -83,7 +88,7 @@ public class OSAPI implements ILuaAPI
|
||||
"os"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void startup()
|
||||
{
|
||||
@ -101,7 +106,7 @@ public class OSAPI implements ILuaAPI
|
||||
m_alarms.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
@ -109,7 +114,7 @@ public class OSAPI implements ILuaAPI
|
||||
{
|
||||
// Update the clock
|
||||
m_clock++;
|
||||
|
||||
|
||||
// Countdown all of our active timers
|
||||
Iterator<Map.Entry<Integer, Timer>> it = m_timers.entrySet().iterator();
|
||||
while( it.hasNext() )
|
||||
@ -125,15 +130,15 @@ public class OSAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Wait for all of our alarms
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
double previousTime = m_time;
|
||||
int previousDay = m_day;
|
||||
double time = m_apiEnvironment.getComputerEnvironment().getTimeOfDay();
|
||||
int day = m_apiEnvironment.getComputerEnvironment().getDay();
|
||||
|
||||
int day = m_apiEnvironment.getComputerEnvironment().getDay();
|
||||
|
||||
if( time > previousTime || day > previousDay )
|
||||
{
|
||||
double now = m_day * 24.0 + m_time;
|
||||
@ -145,7 +150,7 @@ public class OSAPI implements ILuaAPI
|
||||
double t = alarm.m_day * 24.0 + alarm.m_time;
|
||||
if( now >= t )
|
||||
{
|
||||
queueLuaEvent( "alarm", new Object[]{ entry.getKey() } );
|
||||
queueLuaEvent( "alarm", new Object[] { entry.getKey() } );
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
@ -155,15 +160,15 @@ public class OSAPI implements ILuaAPI
|
||||
m_day = day;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void shutdown( )
|
||||
public void shutdown()
|
||||
{
|
||||
synchronized( m_timers )
|
||||
{
|
||||
m_timers.clear();
|
||||
}
|
||||
|
||||
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
m_alarms.clear();
|
||||
@ -194,28 +199,28 @@ public class OSAPI implements ILuaAPI
|
||||
};
|
||||
}
|
||||
|
||||
private float getTimeForCalendar(Calendar c)
|
||||
private float getTimeForCalendar( Calendar c )
|
||||
{
|
||||
float time = c.get(Calendar.HOUR_OF_DAY);
|
||||
time += c.get(Calendar.MINUTE) / 60.0f;
|
||||
time += c.get(Calendar.SECOND) / (60.0f * 60.0f);
|
||||
float time = c.get( Calendar.HOUR_OF_DAY );
|
||||
time += c.get( Calendar.MINUTE ) / 60.0f;
|
||||
time += c.get( Calendar.SECOND ) / (60.0f * 60.0f);
|
||||
return time;
|
||||
}
|
||||
|
||||
private int getDayForCalendar(Calendar c)
|
||||
private int getDayForCalendar( Calendar c )
|
||||
{
|
||||
GregorianCalendar g = (c instanceof GregorianCalendar) ? (GregorianCalendar)c : new GregorianCalendar();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
GregorianCalendar g = (c instanceof GregorianCalendar) ? (GregorianCalendar) c : new GregorianCalendar();
|
||||
int year = c.get( Calendar.YEAR );
|
||||
int day = 0;
|
||||
for( int y=1970; y<year; ++y )
|
||||
for( int y = 1970; y < year; y++ )
|
||||
{
|
||||
day += g.isLeapYear(y) ? 366 : 365;
|
||||
day += g.isLeapYear( y ) ? 366 : 365;
|
||||
}
|
||||
day += c.get(Calendar.DAY_OF_YEAR);
|
||||
day += c.get( Calendar.DAY_OF_YEAR );
|
||||
return day;
|
||||
}
|
||||
|
||||
private long getEpochForCalendar(Calendar c)
|
||||
private long getEpochForCalendar( Calendar c )
|
||||
{
|
||||
return c.getTime().getTime();
|
||||
}
|
||||
@ -237,7 +242,7 @@ public class OSAPI implements ILuaAPI
|
||||
double timer = getReal( args, 0 );
|
||||
synchronized( m_timers )
|
||||
{
|
||||
m_timers.put( m_nextTimerToken, new Timer( (int)Math.round( timer / 0.05 ) ) );
|
||||
m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
|
||||
return new Object[] { m_nextTimerToken++ };
|
||||
}
|
||||
}
|
||||
@ -248,7 +253,7 @@ public class OSAPI implements ILuaAPI
|
||||
if( time < 0.0 || time >= 24.0 )
|
||||
{
|
||||
throw new LuaException( "Number out of range" );
|
||||
}
|
||||
}
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
int day = (time > m_time) ? m_day : (m_day + 1);
|
||||
@ -425,12 +430,12 @@ public class OSAPI implements ILuaAPI
|
||||
{
|
||||
m_apiEnvironment.queueEvent( event, args );
|
||||
}
|
||||
|
||||
|
||||
private Object[] trimArray( Object[] array, int skip )
|
||||
{
|
||||
return Arrays.copyOfRange( array, skip, array.length );
|
||||
}
|
||||
|
||||
|
||||
private int getComputerID()
|
||||
{
|
||||
return m_apiEnvironment.getComputerID();
|
||||
|
@ -40,19 +40,21 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
|
||||
public PeripheralWrapper( IPeripheral peripheral, String side )
|
||||
{
|
||||
super(m_environment);
|
||||
super( m_environment );
|
||||
m_side = side;
|
||||
m_peripheral = peripheral;
|
||||
m_attached = false;
|
||||
|
||||
m_type = peripheral.getType();
|
||||
m_methods = peripheral.getMethodNames();
|
||||
assert( m_type != null );
|
||||
assert( m_methods != null );
|
||||
assert (m_type != null);
|
||||
assert (m_methods != null);
|
||||
|
||||
m_methodMap = new HashMap<>();
|
||||
for(int i=0; i<m_methods.length; ++i ) {
|
||||
if( m_methods[i] != null ) {
|
||||
for( int i = 0; i < m_methods.length; i++ )
|
||||
{
|
||||
if( m_methods[i] != null )
|
||||
{
|
||||
m_methodMap.put( m_methods[i], i );
|
||||
}
|
||||
}
|
||||
@ -235,7 +237,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
m_environment.setPeripheralChangeListener( this );
|
||||
|
||||
m_peripherals = new PeripheralWrapper[6];
|
||||
for(int i=0; i<6; ++i)
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
m_peripherals[i] = null;
|
||||
}
|
||||
@ -254,21 +256,26 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
{
|
||||
// Queue a detachment
|
||||
final PeripheralWrapper wrapper = m_peripherals[side];
|
||||
ComputerThread.queueTask(new ITask() {
|
||||
ComputerThread.queueTask( new ITask()
|
||||
{
|
||||
@Override
|
||||
public Computer getOwner() {
|
||||
public Computer getOwner()
|
||||
{
|
||||
return m_environment.getComputer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
synchronized (m_peripherals) {
|
||||
if (wrapper.isAttached()) {
|
||||
public void execute()
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
if( wrapper.isAttached() )
|
||||
{
|
||||
wrapper.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
}, null );
|
||||
|
||||
// Queue a detachment event
|
||||
m_environment.queueEvent( "peripheral_detach", new Object[] { Computer.s_sideNames[side] } );
|
||||
@ -288,14 +295,17 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
{
|
||||
// Queue an attachment
|
||||
final PeripheralWrapper wrapper = m_peripherals[side];
|
||||
ComputerThread.queueTask( new ITask() {
|
||||
ComputerThread.queueTask( new ITask()
|
||||
{
|
||||
@Override
|
||||
public Computer getOwner() {
|
||||
public Computer getOwner()
|
||||
{
|
||||
return m_environment.getComputer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public void execute()
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
if( m_running && !wrapper.isAttached() )
|
||||
@ -323,12 +333,12 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startup( )
|
||||
public void startup()
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
m_running = true;
|
||||
for( int i=0; i<6; ++i )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
PeripheralWrapper wrapper = m_peripherals[i];
|
||||
if( wrapper != null && !wrapper.isAttached() )
|
||||
@ -340,12 +350,12 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown( )
|
||||
public void shutdown()
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
m_running = false;
|
||||
for( int i=0; i<6; ++i )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
PeripheralWrapper wrapper = m_peripherals[i];
|
||||
if( wrapper != null && wrapper.isAttached() )
|
||||
@ -382,7 +392,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
PeripheralWrapper p = m_peripherals[ side ];
|
||||
PeripheralWrapper p = m_peripherals[side];
|
||||
if( p != null )
|
||||
{
|
||||
present = true;
|
||||
@ -400,7 +410,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
PeripheralWrapper p = m_peripherals[ side ];
|
||||
PeripheralWrapper p = m_peripherals[side];
|
||||
if( p != null )
|
||||
{
|
||||
type = p.getType();
|
||||
@ -422,7 +432,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
PeripheralWrapper p = m_peripherals[ side ];
|
||||
PeripheralWrapper p = m_peripherals[side];
|
||||
if( p != null )
|
||||
{
|
||||
methods = p.getMethods();
|
||||
@ -431,9 +441,10 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
}
|
||||
if( methods != null )
|
||||
{
|
||||
Map<Object,Object> table = new HashMap<>();
|
||||
for(int i=0; i<methods.length; ++i ) {
|
||||
table.put( i+1, methods[i] );
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
for( int i = 0; i < methods.length; i++ )
|
||||
{
|
||||
table.put( i + 1, methods[i] );
|
||||
}
|
||||
return new Object[] { table };
|
||||
}
|
||||
@ -451,7 +462,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
PeripheralWrapper p;
|
||||
synchronized( m_peripherals )
|
||||
{
|
||||
p = m_peripherals[ side ];
|
||||
p = m_peripherals[side];
|
||||
}
|
||||
if( p != null )
|
||||
{
|
||||
@ -472,7 +483,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
||||
private int parseSide( Object[] args ) throws LuaException
|
||||
{
|
||||
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] ) )
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ public class RedstoneAPI implements ILuaAPI
|
||||
{
|
||||
m_environment = environment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNames()
|
||||
{
|
||||
@ -64,10 +64,10 @@ public class RedstoneAPI implements ILuaAPI
|
||||
case 0:
|
||||
{
|
||||
// getSides
|
||||
Map<Object,Object> table = new HashMap<>();
|
||||
for(int i=0; i< Computer.s_sideNames.length; ++i )
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
for( int i = 0; i < Computer.s_sideNames.length; i++ )
|
||||
{
|
||||
table.put( i+1, Computer.s_sideNames[i] );
|
||||
table.put( i + 1, Computer.s_sideNames[i] );
|
||||
}
|
||||
return new Object[] { table };
|
||||
}
|
||||
@ -152,11 +152,11 @@ public class RedstoneAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int parseSide( Object[] args ) throws LuaException
|
||||
{
|
||||
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] ) )
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ public class TermAPI implements ILuaAPI
|
||||
m_terminal = _environment.getTerminal();
|
||||
m_environment = _environment.getComputerEnvironment();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNames()
|
||||
{
|
||||
@ -68,7 +68,7 @@ public class TermAPI implements ILuaAPI
|
||||
"getCursorBlink",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static int parseColour( Object[] args ) throws LuaException
|
||||
{
|
||||
int colour = getInt( args, 0 );
|
||||
@ -109,12 +109,15 @@ public class TermAPI implements ILuaAPI
|
||||
{
|
||||
// write
|
||||
String text;
|
||||
if( args.length > 0 && args[0] != null ) {
|
||||
if( args.length > 0 && args[0] != null )
|
||||
{
|
||||
text = args[0].toString();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "";
|
||||
}
|
||||
|
||||
|
||||
synchronized( m_terminal )
|
||||
{
|
||||
m_terminal.write( text );
|
||||
@ -128,7 +131,7 @@ public class TermAPI implements ILuaAPI
|
||||
int y = getInt( args, 0 );
|
||||
synchronized( m_terminal )
|
||||
{
|
||||
m_terminal.scroll(y);
|
||||
m_terminal.scroll( y );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -172,7 +175,7 @@ public class TermAPI implements ILuaAPI
|
||||
{
|
||||
width = m_terminal.getWidth();
|
||||
height = m_terminal.getHeight();
|
||||
}
|
||||
}
|
||||
return new Object[] { width, height };
|
||||
}
|
||||
case 6:
|
||||
@ -260,7 +263,7 @@ public class TermAPI implements ILuaAPI
|
||||
{
|
||||
int hex = getInt( args, 1 );
|
||||
double[] rgb = Palette.decodeRGB8( hex );
|
||||
setColour( m_terminal, colour, rgb[ 0 ], rgb[ 1 ], rgb[ 2 ] );
|
||||
setColour( m_terminal, colour, rgb[0], rgb[1], rgb[2] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -278,7 +281,7 @@ public class TermAPI implements ILuaAPI
|
||||
int colour = 15 - parseColour( args );
|
||||
synchronized( m_terminal )
|
||||
{
|
||||
if ( m_terminal.getPalette() != null )
|
||||
if( m_terminal.getPalette() != null )
|
||||
{
|
||||
return ArrayUtils.toObject( m_terminal.getPalette().getColour( colour ) );
|
||||
}
|
||||
@ -294,7 +297,7 @@ public class TermAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int getHighestBit( int group )
|
||||
{
|
||||
int bit = 0;
|
||||
|
@ -58,7 +58,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
checkOpen();
|
||||
try
|
||||
{
|
||||
if( args.length > 0 && args[ 0 ] != null )
|
||||
if( args.length > 0 && args[0] != null )
|
||||
{
|
||||
int count = getInt( args, 0 );
|
||||
if( count < 0 )
|
||||
@ -73,7 +73,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
if( count <= BUFFER_SIZE )
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer.allocate( count );
|
||||
|
||||
|
||||
int read = m_reader.read( buffer );
|
||||
if( read < 0 ) return null;
|
||||
return new Object[] { read < count ? Arrays.copyOf( buffer.array(), read ) : buffer.array() };
|
||||
@ -92,7 +92,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
return new Object[] { Arrays.copyOf( buffer.array(), read ) };
|
||||
}
|
||||
|
||||
// Build up an array of ByteBuffers. Hopefully this means we can perform less allocation
|
||||
// Build up an array of ByteBuffers. Hopefully this means we can perform less allocation
|
||||
// than doubling up the buffer each time.
|
||||
List<ByteBuffer> parts = new ArrayList<>( 4 );
|
||||
parts.add( buffer );
|
||||
@ -104,7 +104,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
}
|
||||
|
||||
// Now just copy all the bytes across!
|
||||
byte[] bytes = new byte[ totalRead ];
|
||||
byte[] bytes = new byte[totalRead];
|
||||
int pos = 0;
|
||||
for( ByteBuffer part : parts )
|
||||
{
|
||||
|
@ -52,23 +52,23 @@ public class BinaryWritableHandle extends HandleGeneric
|
||||
checkOpen();
|
||||
try
|
||||
{
|
||||
if( args.length > 0 && args[ 0 ] instanceof Number )
|
||||
if( args.length > 0 && args[0] instanceof Number )
|
||||
{
|
||||
int number = ((Number) args[ 0 ]).intValue();
|
||||
int number = ((Number) args[0]).intValue();
|
||||
single.clear();
|
||||
single.put( (byte) number );
|
||||
single.flip();
|
||||
|
||||
m_writer.write( single );
|
||||
}
|
||||
else if( args.length > 0 && args[ 0 ] instanceof String )
|
||||
else if( args.length > 0 && args[0] instanceof String )
|
||||
{
|
||||
String value = (String) args[ 0 ];
|
||||
String value = (String) args[0];
|
||||
m_writer.write( ByteBuffer.wrap( StringUtil.encodeString( value ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[ 0 ] : null );
|
||||
throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[0] : null );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
@Nonnull
|
||||
@Override
|
||||
public String[] getMethodNames()
|
||||
{
|
||||
{
|
||||
return new String[] {
|
||||
"readLine",
|
||||
"readAll",
|
||||
@ -108,14 +108,14 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
int count = optInt( args, 0, 1 );
|
||||
if( count < 0 )
|
||||
{
|
||||
// Whilst this may seem absurd to allow reading 0 characters, PUC Lua it so
|
||||
// Whilst this may seem absurd to allow reading 0 characters, PUC Lua it so
|
||||
// it seems best to remain somewhat consistent.
|
||||
throw new LuaException( "Cannot read a negative number of characters" );
|
||||
}
|
||||
else if( count <= BUFFER_SIZE )
|
||||
{
|
||||
// If we've got a small count, then allocate that and read it.
|
||||
char[] chars = new char[ count ];
|
||||
char[] chars = new char[count];
|
||||
int read = m_reader.read( chars );
|
||||
|
||||
return read < 0 ? null : new Object[] { new String( chars, 0, read ) };
|
||||
@ -123,7 +123,7 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
else
|
||||
{
|
||||
// If we've got a large count, read in bunches of 8192.
|
||||
char[] buffer = new char[ BUFFER_SIZE ];
|
||||
char[] buffer = new char[BUFFER_SIZE];
|
||||
|
||||
// Read the initial set of characters, failing if none are read.
|
||||
int read = m_reader.read( buffer, 0, Math.min( buffer.length, count ) );
|
||||
@ -162,7 +162,7 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
|
||||
public static BufferedReader open( ReadableByteChannel channel, Charset charset )
|
||||
{
|
||||
// Create a charset decoder with the same properties as StreamDecoder does for
|
||||
// Create a charset decoder with the same properties as StreamDecoder does for
|
||||
// InputStreams: namely, replace everything instead of erroring.
|
||||
CharsetDecoder decoder = charset.newDecoder()
|
||||
.onMalformedInput( CodingErrorAction.REPLACE )
|
||||
|
@ -51,9 +51,9 @@ public class EncodedWritableHandle extends HandleGeneric
|
||||
// write
|
||||
checkOpen();
|
||||
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
|
||||
{
|
||||
@ -74,9 +74,9 @@ public class EncodedWritableHandle extends HandleGeneric
|
||||
// writeLine
|
||||
checkOpen();
|
||||
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
|
||||
{
|
||||
@ -122,11 +122,11 @@ public class EncodedWritableHandle extends HandleGeneric
|
||||
|
||||
public static BufferedWriter open( WritableByteChannel channel, Charset charset )
|
||||
{
|
||||
// Create a charset encoder with the same properties as StreamEncoder does for
|
||||
// Create a charset encoder with the same properties as StreamEncoder does for
|
||||
// OutputStreams: namely, replace everything instead of erroring.
|
||||
CharsetEncoder encoder = charset.newEncoder()
|
||||
.onMalformedInput( CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||
.onMalformedInput( CodingErrorAction.REPLACE )
|
||||
.onUnmappableCharacter( CodingErrorAction.REPLACE );
|
||||
return new BufferedWriter( Channels.newWriter( channel, encoder, -1 ) );
|
||||
}
|
||||
}
|
||||
|
@ -70,11 +70,11 @@ public abstract class HandleGeneric implements ILuaObject
|
||||
throw new LuaException( "bad argument #1 to 'seek' (invalid option '" + whence + "'" );
|
||||
}
|
||||
|
||||
return new Object[]{ channel.position() };
|
||||
return new Object[] { channel.position() };
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
return new Object[]{ false, "Position is negative" };
|
||||
return new Object[] { false, "Position is negative" };
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ public class HTTPRequest implements Runnable
|
||||
{
|
||||
// Queue the failure event if not.
|
||||
String error = e.getMessage();
|
||||
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, error == null ? "Could not connect" : error, null } );
|
||||
m_environment.queueEvent( "http_failure", new Object[] { m_urlString, error == null ? "Could not connect" : error, null } );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -214,17 +214,17 @@ public class HTTPRequest implements Runnable
|
||||
// Queue the appropriate event.
|
||||
if( responseSuccess )
|
||||
{
|
||||
m_environment.queueEvent( "http_success", new Object[]{ m_urlString, stream } );
|
||||
m_environment.queueEvent( "http_success", new Object[] { m_urlString, stream } );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, "Could not connect", stream } );
|
||||
m_environment.queueEvent( "http_failure", new Object[] { m_urlString, "Could not connect", stream } );
|
||||
}
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
// There was an error
|
||||
m_environment.queueEvent( "http_failure", new Object[]{ m_urlString, "Could not connect", null } );
|
||||
m_environment.queueEvent( "http_failure", new Object[] { m_urlString, "Could not connect", null } );
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,12 +258,12 @@ public class HTTPRequest implements Runnable
|
||||
case 0:
|
||||
{
|
||||
// getResponseCode
|
||||
return new Object[]{ responseCode };
|
||||
return new Object[] { responseCode };
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
// getResponseHeaders
|
||||
return new Object[]{ responseHeaders };
|
||||
return new Object[] { responseHeaders };
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
private void onClosed()
|
||||
{
|
||||
close( true );
|
||||
computer.queueEvent( CLOSE_EVENT, new Object[]{ url } );
|
||||
computer.queueEvent( CLOSE_EVENT, new Object[] { url } );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,7 +107,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
if( !handshaker.isHandshakeComplete() )
|
||||
{
|
||||
handshaker.finishHandshake( ch, (FullHttpResponse) msg );
|
||||
computer.queueEvent( SUCCESS_EVENT, new Object[]{ url, this } );
|
||||
computer.queueEvent( SUCCESS_EVENT, new Object[] { url, this } );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
String data = ((TextWebSocketFrame) frame).text();
|
||||
|
||||
computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, data.length() );
|
||||
computer.queueEvent( MESSAGE_EVENT, new Object[]{ url, data } );
|
||||
computer.queueEvent( MESSAGE_EVENT, new Object[] { url, data } );
|
||||
}
|
||||
else if( frame instanceof BinaryWebSocketFrame )
|
||||
{
|
||||
@ -132,7 +132,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
data.readBytes( converted );
|
||||
|
||||
computer.addTrackingChange( TrackingField.WEBSOCKET_INCOMING, converted.length );
|
||||
computer.queueEvent( MESSAGE_EVENT, new Object[]{ url, converted } );
|
||||
computer.queueEvent( MESSAGE_EVENT, new Object[] { url, converted } );
|
||||
}
|
||||
else if( frame instanceof CloseWebSocketFrame )
|
||||
{
|
||||
@ -145,7 +145,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause )
|
||||
{
|
||||
ctx.close();
|
||||
computer.queueEvent( FAILURE_EVENT, new Object[]{
|
||||
computer.queueEvent( FAILURE_EVENT, new Object[] {
|
||||
url,
|
||||
cause instanceof WebSocketHandshakeException ? cause.getMessage() : "Could not connect"
|
||||
} );
|
||||
@ -155,7 +155,7 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
@Override
|
||||
public String[] getMethodNames()
|
||||
{
|
||||
return new String[]{ "receive", "send", "close" };
|
||||
return new String[] { "receive", "send", "close" };
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -171,14 +171,14 @@ public class WebsocketConnection extends SimpleChannelInboundHandler<Object> imp
|
||||
Object[] event = context.pullEvent( MESSAGE_EVENT );
|
||||
if( event.length >= 3 && Objects.equal( event[1], url ) )
|
||||
{
|
||||
return new Object[]{ event[2] };
|
||||
return new Object[] { event[2] };
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
checkOpen();
|
||||
String text = arguments.length > 0 && arguments[0] != null ? arguments[0].toString() : "";
|
||||
boolean binary = optBoolean(arguments, 1, false);
|
||||
boolean binary = optBoolean( arguments, 1, false );
|
||||
computer.addTrackingChange( TrackingField.WEBSOCKET_OUTGOING, text.length() );
|
||||
channel.writeAndFlush( binary
|
||||
? new BinaryWebSocketFrame( Unpooled.wrappedBuffer( StringUtil.encodeString( text ) ) )
|
||||
|
@ -11,8 +11,8 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.filesystem.IFileSystem;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
import dan200.computercraft.api.lua.*;
|
||||
import dan200.computercraft.api.lua.ILuaAPI;
|
||||
import dan200.computercraft.api.lua.*;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.core.apis.*;
|
||||
import dan200.computercraft.core.filesystem.FileSystem;
|
||||
@ -31,11 +31,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Computer
|
||||
{
|
||||
{
|
||||
public static final String[] s_sideNames = new String[] {
|
||||
"bottom", "top", "back", "front", "right", "left",
|
||||
};
|
||||
|
||||
|
||||
private enum State
|
||||
{
|
||||
Off,
|
||||
@ -43,18 +43,18 @@ public class Computer
|
||||
Running,
|
||||
Stopping,
|
||||
}
|
||||
|
||||
|
||||
private static class APIEnvironment implements IAPIEnvironment
|
||||
{
|
||||
private Computer m_computer;
|
||||
private IAPIEnvironment.IPeripheralChangeListener m_peripheralListener;
|
||||
|
||||
|
||||
public APIEnvironment( Computer computer )
|
||||
{
|
||||
m_computer = computer;
|
||||
m_peripheralListener = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Computer getComputer()
|
||||
{
|
||||
@ -66,19 +66,19 @@ public class Computer
|
||||
{
|
||||
return m_computer.assignID();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IComputerEnvironment getComputerEnvironment()
|
||||
{
|
||||
return m_computer.m_environment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal()
|
||||
{
|
||||
return m_computer.m_terminal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FileSystem getFileSystem()
|
||||
{
|
||||
@ -108,19 +108,19 @@ public class Computer
|
||||
{
|
||||
m_computer.setRedstoneOutput( side, output );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOutput( int side )
|
||||
{
|
||||
return m_computer.getInternalRedstoneOutput( side );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getInput( int side )
|
||||
{
|
||||
return m_computer.getRedstoneInput( side );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBundledOutput( int side, int output )
|
||||
{
|
||||
@ -132,22 +132,22 @@ public class Computer
|
||||
{
|
||||
return m_computer.getInternalBundledRedstoneOutput( side );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getBundledInput( int side )
|
||||
{
|
||||
return m_computer.getBundledRedstoneInput( side );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IPeripheral getPeripheral( int side )
|
||||
{
|
||||
synchronized( m_computer.m_peripherals )
|
||||
{
|
||||
return m_computer.m_peripherals[ side ];
|
||||
return m_computer.m_peripherals[side];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setPeripheralChangeListener( IPeripheralChangeListener listener )
|
||||
{
|
||||
@ -285,7 +285,7 @@ public class Computer
|
||||
private ILuaMachine m_machine;
|
||||
private final List<ILuaAPI> m_apis;
|
||||
private final APIEnvironment m_apiEnvironment;
|
||||
|
||||
|
||||
private final Terminal m_terminal;
|
||||
private FileSystem m_fileSystem;
|
||||
private IWritableMount m_rootMount;
|
||||
@ -301,7 +301,7 @@ public class Computer
|
||||
private final int[] m_input;
|
||||
private final int[] m_bundledInput;
|
||||
private boolean m_inputChanged;
|
||||
|
||||
|
||||
private final IPeripheral[] m_peripherals;
|
||||
|
||||
public Computer( IComputerEnvironment environment, Terminal terminal, int id )
|
||||
@ -335,9 +335,9 @@ public class Computer
|
||||
m_input = new int[6];
|
||||
m_bundledInput = new int[6];
|
||||
m_inputChanged = false;
|
||||
|
||||
|
||||
m_peripherals = new IPeripheral[6];
|
||||
for( int i=0; i<6; ++i )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
m_peripherals[i] = null;
|
||||
}
|
||||
@ -345,12 +345,12 @@ public class Computer
|
||||
m_rootMount = null;
|
||||
createAPIs();
|
||||
}
|
||||
|
||||
|
||||
public IAPIEnvironment getAPIEnvironment()
|
||||
{
|
||||
return m_apiEnvironment;
|
||||
}
|
||||
|
||||
|
||||
public void turnOn()
|
||||
{
|
||||
if( m_state == State.Off )
|
||||
@ -358,17 +358,17 @@ public class Computer
|
||||
m_startRequested = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
stopComputer( false );
|
||||
}
|
||||
|
||||
|
||||
public void reboot()
|
||||
{
|
||||
stopComputer( true );
|
||||
}
|
||||
|
||||
|
||||
public boolean isOn()
|
||||
{
|
||||
synchronized( this )
|
||||
@ -376,14 +376,14 @@ public class Computer
|
||||
return m_state == State.Running;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void abort( boolean hard )
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
if( m_state != State.Off && m_machine != null )
|
||||
{
|
||||
if( hard )
|
||||
if( hard )
|
||||
{
|
||||
m_machine.hardAbort( "Too long without yielding" );
|
||||
}
|
||||
@ -394,7 +394,7 @@ public class Computer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void unload()
|
||||
{
|
||||
synchronized( this )
|
||||
@ -437,9 +437,9 @@ public class Computer
|
||||
}
|
||||
|
||||
public void advance( double _dt )
|
||||
{
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
{
|
||||
// Start after a number of ticks
|
||||
if( m_ticksSinceStart >= 0 )
|
||||
{
|
||||
@ -450,11 +450,11 @@ public class Computer
|
||||
startComputer();
|
||||
m_startRequested = false;
|
||||
}
|
||||
|
||||
|
||||
if( m_state == State.Running )
|
||||
{
|
||||
{
|
||||
// Fire the redstone event if our redstone input has changed
|
||||
synchronized( m_input )
|
||||
synchronized( m_input )
|
||||
{
|
||||
if( m_inputChanged )
|
||||
{
|
||||
@ -466,7 +466,7 @@ public class Computer
|
||||
// Advance our APIs
|
||||
synchronized( m_apis )
|
||||
{
|
||||
for(ILuaAPI api : m_apis)
|
||||
for( ILuaAPI api : m_apis )
|
||||
{
|
||||
api.update();
|
||||
}
|
||||
@ -480,16 +480,16 @@ public class Computer
|
||||
if( m_internalOutputChanged )
|
||||
{
|
||||
boolean changed = false;
|
||||
for( int i=0; i<6; ++i )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
if( m_externalOutput[i] != m_internalOutput[i] )
|
||||
{
|
||||
m_externalOutput[ i ] = m_internalOutput[ i ];
|
||||
m_externalOutput[i] = m_internalOutput[i];
|
||||
changed = true;
|
||||
}
|
||||
if( m_externalBundledOutput[i] != m_internalBundledOutput[i] )
|
||||
{
|
||||
m_externalBundledOutput[ i ] = m_internalBundledOutput[ i ];
|
||||
m_externalBundledOutput[i] = m_internalBundledOutput[i];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@ -500,14 +500,14 @@ public class Computer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set outputchanged if the terminal has changed from blinking to not
|
||||
synchronized( m_terminal )
|
||||
{
|
||||
boolean blinking =
|
||||
m_terminal.getCursorBlink() &&
|
||||
m_terminal.getCursorX() >= 0 && m_terminal.getCursorX() < m_terminal.getWidth() &&
|
||||
m_terminal.getCursorY() >= 0 && m_terminal.getCursorY() < m_terminal.getHeight();
|
||||
m_terminal.getCursorX() >= 0 && m_terminal.getCursorX() < m_terminal.getWidth() &&
|
||||
m_terminal.getCursorY() >= 0 && m_terminal.getCursorY() < m_terminal.getHeight();
|
||||
|
||||
if( blinking != m_blinking )
|
||||
{
|
||||
@ -516,10 +516,11 @@ public class Computer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean pollAndResetChanged()
|
||||
{
|
||||
synchronized(this) {
|
||||
synchronized( this )
|
||||
{
|
||||
boolean changed = m_externalOutputChanged;
|
||||
m_externalOutputChanged = false;
|
||||
return changed;
|
||||
@ -542,9 +543,9 @@ public class Computer
|
||||
}
|
||||
return m_rootMount;
|
||||
}
|
||||
|
||||
|
||||
// FileSystem
|
||||
|
||||
|
||||
private boolean initFileSystem()
|
||||
{
|
||||
// Create the file system
|
||||
@ -569,7 +570,7 @@ public class Computer
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Redstone
|
||||
|
||||
public int getRedstoneOutput( int side )
|
||||
@ -648,7 +649,7 @@ public class Computer
|
||||
}
|
||||
}
|
||||
|
||||
public void setBundledRedstoneInput( int side, int combination )
|
||||
public void setBundledRedstoneInput( int side, int combination )
|
||||
{
|
||||
synchronized( m_input )
|
||||
{
|
||||
@ -659,7 +660,7 @@ public class Computer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getBundledRedstoneInput( int side )
|
||||
{
|
||||
synchronized( m_input )
|
||||
@ -669,7 +670,7 @@ public class Computer
|
||||
}
|
||||
|
||||
// Peripherals
|
||||
|
||||
|
||||
public void addAPI( ILuaAPI api )
|
||||
{
|
||||
m_apis.add( api );
|
||||
@ -679,7 +680,7 @@ public class Computer
|
||||
{
|
||||
addAPI( (ILuaAPI) api );
|
||||
}
|
||||
|
||||
|
||||
public void setPeripheral( int side, IPeripheral peripheral )
|
||||
{
|
||||
synchronized( m_peripherals )
|
||||
@ -702,9 +703,9 @@ public class Computer
|
||||
return m_peripherals[side];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Lua
|
||||
|
||||
|
||||
private void createAPIs()
|
||||
{
|
||||
m_apis.add( new TermAPI( m_apiEnvironment ) );
|
||||
@ -728,19 +729,19 @@ public class Computer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void initLua()
|
||||
{
|
||||
// Create the lua machine
|
||||
ILuaMachine machine = new CobaltLuaMachine( this );
|
||||
|
||||
|
||||
// Add the APIs
|
||||
for(ILuaAPI api : m_apis)
|
||||
for( ILuaAPI api : m_apis )
|
||||
{
|
||||
machine.addAPI( api );
|
||||
api.startup();
|
||||
}
|
||||
|
||||
|
||||
// Load the bios resource
|
||||
InputStream biosStream;
|
||||
try
|
||||
@ -751,21 +752,24 @@ public class Computer
|
||||
{
|
||||
biosStream = null;
|
||||
}
|
||||
|
||||
|
||||
// Start the machine running the bios resource
|
||||
if( biosStream != null )
|
||||
{
|
||||
machine.loadBios( biosStream );
|
||||
try {
|
||||
try
|
||||
{
|
||||
biosStream.close();
|
||||
} catch( IOException e ) {
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
|
||||
|
||||
if( machine.isFinished() )
|
||||
{
|
||||
m_terminal.reset();
|
||||
m_terminal.write("Error starting bios.lua" );
|
||||
m_terminal.write( "Error starting bios.lua" );
|
||||
m_terminal.setCursorPos( 0, 1 );
|
||||
m_terminal.write( "ComputerCraft may be installed incorrectly" );
|
||||
|
||||
@ -780,7 +784,7 @@ public class Computer
|
||||
else
|
||||
{
|
||||
m_terminal.reset();
|
||||
m_terminal.write("Error loading bios.lua" );
|
||||
m_terminal.write( "Error loading bios.lua" );
|
||||
m_terminal.setCursorPos( 0, 1 );
|
||||
m_terminal.write( "ComputerCraft may be installed incorrectly" );
|
||||
|
||||
@ -788,7 +792,7 @@ public class Computer
|
||||
m_machine = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void startComputer()
|
||||
{
|
||||
synchronized( this )
|
||||
@ -801,10 +805,11 @@ public class Computer
|
||||
m_externalOutputChanged = true;
|
||||
m_ticksSinceStart = 0;
|
||||
}
|
||||
|
||||
|
||||
// Turn the computercraft on
|
||||
final Computer computer = this;
|
||||
ComputerThread.queueTask( new ITask() {
|
||||
ComputerThread.queueTask( new ITask()
|
||||
{
|
||||
@Override
|
||||
public Computer getOwner()
|
||||
{
|
||||
@ -820,14 +825,14 @@ public class Computer
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Init terminal
|
||||
|
||||
// Init terminal
|
||||
synchronized( m_terminal )
|
||||
{
|
||||
m_terminal.reset();
|
||||
}
|
||||
|
||||
// Init filesystem
|
||||
|
||||
// Init filesystem
|
||||
if( !initFileSystem() )
|
||||
{
|
||||
// Init failed, so shutdown
|
||||
@ -840,7 +845,7 @@ public class Computer
|
||||
stopComputer( false );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Init lua
|
||||
initLua();
|
||||
if( m_machine == null )
|
||||
@ -855,7 +860,7 @@ public class Computer
|
||||
stopComputer( false );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Start a new state
|
||||
m_state = State.Running;
|
||||
m_externalOutputChanged = true;
|
||||
@ -867,7 +872,7 @@ public class Computer
|
||||
}
|
||||
}, computer );
|
||||
}
|
||||
|
||||
|
||||
private void stopComputer( final boolean reboot )
|
||||
{
|
||||
synchronized( this )
|
||||
@ -879,10 +884,11 @@ public class Computer
|
||||
m_state = State.Stopping;
|
||||
m_externalOutputChanged = true;
|
||||
}
|
||||
|
||||
|
||||
// Turn the computercraft off
|
||||
final Computer computer = this;
|
||||
ComputerThread.queueTask( new ITask() {
|
||||
ComputerThread.queueTask( new ITask()
|
||||
{
|
||||
@Override
|
||||
public Computer getOwner()
|
||||
{
|
||||
@ -893,12 +899,12 @@ public class Computer
|
||||
public void execute()
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
{
|
||||
if( m_state != State.Stopping )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Shutdown our APIs
|
||||
synchronized( m_apis )
|
||||
{
|
||||
@ -907,14 +913,14 @@ public class Computer
|
||||
api.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Shutdown terminal and filesystem
|
||||
if( m_fileSystem != null )
|
||||
{
|
||||
m_fileSystem.unload();
|
||||
m_fileSystem = null;
|
||||
}
|
||||
|
||||
|
||||
if( m_machine != null )
|
||||
{
|
||||
synchronized( m_terminal )
|
||||
@ -928,11 +934,11 @@ public class Computer
|
||||
m_machine = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reset redstone output
|
||||
synchronized( m_internalOutput )
|
||||
{
|
||||
for( int i=0; i<6; ++i )
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
m_internalOutput[i] = 0;
|
||||
m_internalBundledOutput[i] = 0;
|
||||
@ -950,7 +956,7 @@ public class Computer
|
||||
}
|
||||
}, computer );
|
||||
}
|
||||
|
||||
|
||||
public void queueEvent( final String event, final Object[] arguments )
|
||||
{
|
||||
synchronized( this )
|
||||
@ -960,9 +966,10 @@ public class Computer
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final Computer computer = this;
|
||||
ITask task = new ITask() {
|
||||
ITask task = new ITask()
|
||||
{
|
||||
@Override
|
||||
public Computer getOwner()
|
||||
{
|
||||
@ -979,7 +986,7 @@ public class Computer
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
synchronized( m_machine )
|
||||
{
|
||||
m_machine.handleEvent( event, arguments );
|
||||
@ -995,7 +1002,7 @@ public class Computer
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ComputerThread.queueTask( task, computer );
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
package dan200.computercraft.core.computer;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||
|
||||
@ -13,13 +14,20 @@ import java.io.InputStream;
|
||||
public interface IComputerEnvironment
|
||||
{
|
||||
int getDay();
|
||||
|
||||
double getTimeOfDay();
|
||||
|
||||
boolean isColour();
|
||||
|
||||
long getComputerSpaceLimit();
|
||||
|
||||
String getHostString();
|
||||
|
||||
int assignNewID();
|
||||
|
||||
IWritableMount createSaveDirMount( String subPath, long capacity );
|
||||
|
||||
IMount createResourceMount( String domain, String subPath );
|
||||
|
||||
InputStream createResourceFile( String domain, String subPath );
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ package dan200.computercraft.core.computer;
|
||||
public interface ITask
|
||||
{
|
||||
Computer getOwner();
|
||||
|
||||
void execute();
|
||||
}
|
||||
|
@ -18,20 +18,20 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ComboMount implements IMount
|
||||
{
|
||||
{
|
||||
private IMount[] m_parts;
|
||||
|
||||
|
||||
public ComboMount( IMount[] parts )
|
||||
{
|
||||
m_parts = parts;
|
||||
}
|
||||
|
||||
|
||||
// IMount implementation
|
||||
|
||||
|
||||
@Override
|
||||
public boolean exists( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) )
|
||||
@ -41,11 +41,11 @@ public class ComboMount implements IMount
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDirectory( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.isDirectory( path ) )
|
||||
@ -55,14 +55,14 @@ public class ComboMount implements IMount
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException
|
||||
{
|
||||
// Combine the lists from all the mounts
|
||||
List<String> foundFiles = null;
|
||||
int foundDirs = 0;
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && part.isDirectory( path ) )
|
||||
@ -71,11 +71,11 @@ public class ComboMount implements IMount
|
||||
{
|
||||
foundFiles = new ArrayList<>();
|
||||
}
|
||||
part.list( path, foundFiles );
|
||||
part.list( path, foundFiles );
|
||||
foundDirs++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( foundDirs == 1 )
|
||||
{
|
||||
// We found one directory, so we know it already doesn't contain duplicates
|
||||
@ -85,7 +85,7 @@ public class ComboMount implements IMount
|
||||
{
|
||||
// We found multiple directories, so filter for duplicates
|
||||
Set<String> seen = new HashSet<>();
|
||||
for(String file : foundFiles)
|
||||
for( String file : foundFiles )
|
||||
{
|
||||
if( seen.add( file ) )
|
||||
{
|
||||
@ -98,11 +98,11 @@ public class ComboMount implements IMount
|
||||
throw new IOException( "/" + path + ": Not a directory" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getSize( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) )
|
||||
@ -110,7 +110,7 @@ public class ComboMount implements IMount
|
||||
return part.getSize( path );
|
||||
}
|
||||
}
|
||||
throw new IOException( "/" + path + ": No such file" );
|
||||
throw new IOException( "/" + path + ": No such file" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -118,7 +118,7 @@ public class ComboMount implements IMount
|
||||
@Deprecated
|
||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
||||
@ -133,7 +133,7 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i=m_parts.length-1; i>=0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
||||
|
@ -26,15 +26,15 @@ import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FileSystem
|
||||
{
|
||||
{
|
||||
private class MountWrapper
|
||||
{
|
||||
private String m_label;
|
||||
private String m_location;
|
||||
|
||||
|
||||
private IMount m_mount;
|
||||
private IWritableMount m_writableMount;
|
||||
|
||||
|
||||
public MountWrapper( String label, String location, IMount mount )
|
||||
{
|
||||
m_label = label;
|
||||
@ -45,10 +45,10 @@ public class FileSystem
|
||||
|
||||
public MountWrapper( String label, String location, IWritableMount mount )
|
||||
{
|
||||
this( label, location, (IMount)mount );
|
||||
this( label, location, (IMount) mount );
|
||||
m_writableMount = mount;
|
||||
}
|
||||
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return m_label;
|
||||
@ -58,14 +58,14 @@ public class FileSystem
|
||||
{
|
||||
return m_location;
|
||||
}
|
||||
|
||||
|
||||
public long getFreeSpace()
|
||||
{
|
||||
if( m_writableMount == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return m_writableMount.getRemainingSpace();
|
||||
@ -75,14 +75,14 @@ public class FileSystem
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isReadOnly( String path )
|
||||
{
|
||||
return (m_writableMount == null);
|
||||
}
|
||||
|
||||
|
||||
// IMount forwarders:
|
||||
|
||||
|
||||
public boolean exists( String path ) throws FileSystemException
|
||||
{
|
||||
path = toLocal( path );
|
||||
@ -95,7 +95,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isDirectory( String path ) throws FileSystemException
|
||||
{
|
||||
path = toLocal( path );
|
||||
@ -108,7 +108,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void list( String path, List<String> contents ) throws FileSystemException
|
||||
{
|
||||
path = toLocal( path );
|
||||
@ -128,7 +128,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long getSize( String path ) throws FileSystemException
|
||||
{
|
||||
path = toLocal( path );
|
||||
@ -155,7 +155,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ReadableByteChannel openForRead( String path ) throws FileSystemException
|
||||
{
|
||||
path = toLocal( path );
|
||||
@ -175,9 +175,9 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IWritableMount forwarders:
|
||||
|
||||
|
||||
public void makeDirectory( String path ) throws FileSystemException
|
||||
{
|
||||
if( m_writableMount == null )
|
||||
@ -204,7 +204,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void delete( String path ) throws FileSystemException
|
||||
{
|
||||
if( m_writableMount == null )
|
||||
@ -228,7 +228,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WritableByteChannel openForWrite( String path ) throws FileSystemException
|
||||
{
|
||||
if( m_writableMount == null )
|
||||
@ -264,7 +264,7 @@ public class FileSystem
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WritableByteChannel openForAppend( String path ) throws FileSystemException
|
||||
{
|
||||
if( m_writableMount == null )
|
||||
@ -302,11 +302,11 @@ public class FileSystem
|
||||
catch( IOException e )
|
||||
{
|
||||
throw new FileSystemException( e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private members
|
||||
|
||||
|
||||
private String toLocal( String path )
|
||||
{
|
||||
return FileSystem.toLocal( path, m_location );
|
||||
@ -323,12 +323,12 @@ public class FileSystem
|
||||
{
|
||||
mount( rootLabel, "", rootMount );
|
||||
}
|
||||
|
||||
|
||||
public FileSystem( String rootLabel, IWritableMount rootMount ) throws FileSystemException
|
||||
{
|
||||
mountWritable( rootLabel, "", rootMount );
|
||||
}
|
||||
|
||||
|
||||
public void unload()
|
||||
{
|
||||
// Close all dangling open files
|
||||
@ -339,17 +339,18 @@ public class FileSystem
|
||||
while( m_openFileQueue.poll() != null ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void mount( String label, String location, IMount mount ) throws FileSystemException
|
||||
{
|
||||
if( mount == null ) throw new NullPointerException();
|
||||
location = sanitizePath( location );
|
||||
if( location.contains( ".." ) ) {
|
||||
if( location.contains( ".." ) )
|
||||
{
|
||||
throw new FileSystemException( "Cannot mount below the root" );
|
||||
}
|
||||
}
|
||||
mount( new MountWrapper( label, location, mount ) );
|
||||
}
|
||||
|
||||
|
||||
public synchronized void mountWritable( String label, String location, IWritableMount mount ) throws FileSystemException
|
||||
{
|
||||
if( mount == null )
|
||||
@ -360,7 +361,7 @@ public class FileSystem
|
||||
if( location.contains( ".." ) )
|
||||
{
|
||||
throw new FileSystemException( "Cannot mount below the root" );
|
||||
}
|
||||
}
|
||||
mount( new MountWrapper( label, location, mount ) );
|
||||
}
|
||||
|
||||
@ -370,38 +371,47 @@ public class FileSystem
|
||||
m_mounts.remove( location );
|
||||
m_mounts.put( location, wrapper );
|
||||
}
|
||||
|
||||
|
||||
public synchronized void unmount( String path )
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
m_mounts.remove( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized String combine( String path, String childPath )
|
||||
{
|
||||
path = sanitizePath( path, true );
|
||||
childPath = sanitizePath( childPath, true );
|
||||
|
||||
if( path.isEmpty() ) {
|
||||
|
||||
if( path.isEmpty() )
|
||||
{
|
||||
return childPath;
|
||||
} else if( childPath.isEmpty() ) {
|
||||
}
|
||||
else if( childPath.isEmpty() )
|
||||
{
|
||||
return path;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return sanitizePath( path + '/' + childPath, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getDirectory( String path )
|
||||
{
|
||||
path = sanitizePath( path, true );
|
||||
if( path.isEmpty() ) {
|
||||
if( path.isEmpty() )
|
||||
{
|
||||
return "..";
|
||||
}
|
||||
|
||||
int lastSlash = path.lastIndexOf('/');
|
||||
if( lastSlash >= 0 ) {
|
||||
|
||||
int lastSlash = path.lastIndexOf( '/' );
|
||||
if( lastSlash >= 0 )
|
||||
{
|
||||
return path.substring( 0, lastSlash );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -409,34 +419,38 @@ public class FileSystem
|
||||
public static String getName( String path )
|
||||
{
|
||||
path = sanitizePath( path, true );
|
||||
if( path.isEmpty() ) {
|
||||
if( path.isEmpty() )
|
||||
{
|
||||
return "root";
|
||||
}
|
||||
|
||||
int lastSlash = path.lastIndexOf('/');
|
||||
if( lastSlash >= 0 ) {
|
||||
|
||||
int lastSlash = path.lastIndexOf( '/' );
|
||||
if( lastSlash >= 0 )
|
||||
{
|
||||
return path.substring( lastSlash + 1 );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized long getSize( String path ) throws FileSystemException
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.getSize( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized String[] list( String path ) throws FileSystemException
|
||||
{
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
|
||||
|
||||
// Gets a list of the files in the mount
|
||||
List<String> list = new ArrayList<>();
|
||||
mount.list( path, list );
|
||||
|
||||
|
||||
// Add any mounts that are mounted at this location
|
||||
for( MountWrapper otherMount : m_mounts.values() )
|
||||
{
|
||||
@ -445,10 +459,10 @@ public class FileSystem
|
||||
list.add( getName( otherMount.getLocation() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return list
|
||||
String[] array = new String[ list.size() ];
|
||||
list.toArray(array);
|
||||
String[] array = new String[list.size()];
|
||||
list.toArray( array );
|
||||
Arrays.sort( array );
|
||||
return array;
|
||||
}
|
||||
@ -479,7 +493,7 @@ public class FileSystem
|
||||
int starIndex = wildPath.indexOf( '*' );
|
||||
if( starIndex == -1 )
|
||||
{
|
||||
return exists( wildPath ) ? new String[]{wildPath} : new String[0];
|
||||
return exists( wildPath ) ? new String[] { wildPath } : new String[0];
|
||||
}
|
||||
|
||||
// Find the all non-wildcarded directories. For instance foo/bar/baz* -> foo/bar
|
||||
@ -495,8 +509,8 @@ public class FileSystem
|
||||
findIn( startDir, matches, wildPattern );
|
||||
|
||||
// Return matches
|
||||
String[] array = new String[ matches.size() ];
|
||||
matches.toArray(array);
|
||||
String[] array = new String[matches.size()];
|
||||
matches.toArray( array );
|
||||
return array;
|
||||
}
|
||||
|
||||
@ -506,76 +520,84 @@ public class FileSystem
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.exists( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean isDir( String path ) throws FileSystemException
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.isDirectory( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean isReadOnly( String path ) throws FileSystemException
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.isReadOnly( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized String getMountLabel( String path ) throws FileSystemException
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.getLabel();
|
||||
}
|
||||
|
||||
|
||||
public synchronized void makeDir( String path ) throws FileSystemException
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
mount.makeDirectory( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized void delete( String path ) throws FileSystemException
|
||||
{
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
mount.delete( path );
|
||||
}
|
||||
|
||||
|
||||
public synchronized void move( String sourcePath, String destPath ) throws FileSystemException
|
||||
{
|
||||
sourcePath = sanitizePath( sourcePath );
|
||||
destPath = sanitizePath( destPath );
|
||||
if( isReadOnly( sourcePath ) || isReadOnly( destPath ) ) {
|
||||
if( isReadOnly( sourcePath ) || isReadOnly( destPath ) )
|
||||
{
|
||||
throw new FileSystemException( "Access denied" );
|
||||
}
|
||||
if( !exists( sourcePath ) ) {
|
||||
if( !exists( sourcePath ) )
|
||||
{
|
||||
throw new FileSystemException( "No such file" );
|
||||
}
|
||||
if( exists( destPath ) ) {
|
||||
if( exists( destPath ) )
|
||||
{
|
||||
throw new FileSystemException( "File exists" );
|
||||
}
|
||||
if( contains( sourcePath, destPath ) ) {
|
||||
if( contains( sourcePath, destPath ) )
|
||||
{
|
||||
throw new FileSystemException( "Can't move a directory inside itself" );
|
||||
}
|
||||
copy( sourcePath, destPath );
|
||||
delete( sourcePath );
|
||||
}
|
||||
|
||||
|
||||
public synchronized void copy( String sourcePath, String destPath ) throws FileSystemException
|
||||
{
|
||||
sourcePath = sanitizePath( sourcePath );
|
||||
destPath = sanitizePath( destPath );
|
||||
if( isReadOnly( destPath ) ) {
|
||||
if( isReadOnly( destPath ) )
|
||||
{
|
||||
throw new FileSystemException( "/" + destPath + ": Access denied" );
|
||||
}
|
||||
if( !exists( sourcePath ) ) {
|
||||
if( !exists( sourcePath ) )
|
||||
{
|
||||
throw new FileSystemException( "/" + sourcePath + ": No such file" );
|
||||
}
|
||||
if( exists( destPath ) ) {
|
||||
if( exists( destPath ) )
|
||||
{
|
||||
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" );
|
||||
}
|
||||
copyRecursive( sourcePath, getMount( sourcePath ), destPath, getMount( destPath ) );
|
||||
@ -587,13 +609,13 @@ public class FileSystem
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( sourceMount.isDirectory( sourcePath ) )
|
||||
{
|
||||
// Copy a directory:
|
||||
// Make the new directory
|
||||
destinationMount.makeDirectory( destinationPath );
|
||||
|
||||
|
||||
// Copy the source contents into it
|
||||
List<String> sourceChildren = new ArrayList<>();
|
||||
sourceMount.list( sourcePath, sourceChildren );
|
||||
@ -655,7 +677,7 @@ public class FileSystem
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void removeFile( FileSystemWrapper<?> handle )
|
||||
synchronized void removeFile( FileSystemWrapper<?> handle )
|
||||
{
|
||||
synchronized( m_openFiles )
|
||||
{
|
||||
@ -697,7 +719,7 @@ public class FileSystem
|
||||
MountWrapper mount = getMount( path );
|
||||
return mount.getFreeSpace();
|
||||
}
|
||||
|
||||
|
||||
private MountWrapper getMount( String path ) throws FileSystemException
|
||||
{
|
||||
// Return the deepest mount that contains a given path
|
||||
@ -707,9 +729,11 @@ public class FileSystem
|
||||
while( it.hasNext() )
|
||||
{
|
||||
MountWrapper mount = it.next();
|
||||
if( contains( mount.getLocation(), path ) ) {
|
||||
if( contains( mount.getLocation(), path ) )
|
||||
{
|
||||
int len = toLocal( path, mount.getLocation() ).length();
|
||||
if( match == null || len < matchLength ) {
|
||||
if( match == null || len < matchLength )
|
||||
{
|
||||
match = mount;
|
||||
matchLength = len;
|
||||
}
|
||||
@ -733,32 +757,34 @@ public class FileSystem
|
||||
}
|
||||
|
||||
private static final Pattern threeDotsPattern = Pattern.compile( "^\\.{3,}$" );
|
||||
|
||||
private static String sanitizePath( String path, boolean allowWildcards )
|
||||
{
|
||||
// Allow windowsy slashes
|
||||
path = path.replace( '\\', '/' );
|
||||
|
||||
|
||||
// Clean the path or illegal characters.
|
||||
final char[] specialChars = {
|
||||
'"', ':', '<', '>', '?', '|' // Sorted by ascii value (important)
|
||||
};
|
||||
|
||||
StringBuilder cleanName = new StringBuilder();
|
||||
for( int i = 0; i < path.length(); i++ ) {
|
||||
char c = path.charAt(i);
|
||||
for( int i = 0; i < path.length(); i++ )
|
||||
{
|
||||
char c = path.charAt( i );
|
||||
if( c >= 32 && Arrays.binarySearch( specialChars, c ) < 0 && (allowWildcards || c != '*') )
|
||||
{
|
||||
cleanName.append( c );
|
||||
}
|
||||
}
|
||||
path = cleanName.toString();
|
||||
|
||||
|
||||
// Collapse the string into its component parts, removing ..'s
|
||||
String[] parts = path.split("/");
|
||||
String[] parts = path.split( "/" );
|
||||
Stack<String> outputParts = new Stack<>();
|
||||
for( String part : parts )
|
||||
{
|
||||
if( part.length() == 0 || part.equals( "." ) || threeDotsPattern.matcher( part ).matches() )
|
||||
if( part.length() == 0 || part.equals( "." ) || threeDotsPattern.matcher( part ).matches() )
|
||||
{
|
||||
// . is redundant
|
||||
// ... and more are treated as .
|
||||
@ -795,31 +821,33 @@ public class FileSystem
|
||||
outputParts.push( part );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Recombine the output parts into a new string
|
||||
StringBuilder result = new StringBuilder( "" );
|
||||
Iterator<String> it = outputParts.iterator();
|
||||
while( it.hasNext() ) {
|
||||
while( it.hasNext() )
|
||||
{
|
||||
String part = it.next();
|
||||
result.append( part );
|
||||
if( it.hasNext() ) {
|
||||
if( it.hasNext() )
|
||||
{
|
||||
result.append( '/' );
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public static boolean contains( String pathA, String pathB )
|
||||
{
|
||||
pathA = sanitizePath( pathA );
|
||||
pathB = sanitizePath( pathB );
|
||||
|
||||
if( pathB.equals("..") )
|
||||
if( pathB.equals( ".." ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ( pathB.startsWith("../") )
|
||||
else if( pathB.startsWith( "../" ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -836,17 +864,20 @@ public class FileSystem
|
||||
return pathB.startsWith( pathA + "/" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String toLocal( String path, String location )
|
||||
{
|
||||
path = sanitizePath( path );
|
||||
location = sanitizePath( location );
|
||||
|
||||
assert( contains( location, path ) );
|
||||
|
||||
assert (contains( location, path ));
|
||||
String local = path.substring( location.length() );
|
||||
if( local.startsWith("/") ) {
|
||||
if( local.startsWith( "/" ) )
|
||||
{
|
||||
return local.substring( 1 );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return local;
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,12 @@
|
||||
|
||||
package dan200.computercraft.core.filesystem;
|
||||
|
||||
public class FileSystemException extends Exception {
|
||||
public class FileSystemException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = -2500631644868104029L;
|
||||
|
||||
FileSystemException( String s ) {
|
||||
FileSystemException( String s )
|
||||
{
|
||||
super( s );
|
||||
}
|
||||
}
|
||||
|
@ -15,36 +15,36 @@ import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.List;
|
||||
|
||||
public class SubMount implements IMount
|
||||
{
|
||||
{
|
||||
private IMount m_parent;
|
||||
private String m_subPath;
|
||||
|
||||
|
||||
public SubMount( IMount parent, String subPath )
|
||||
{
|
||||
m_parent = parent;
|
||||
m_subPath = subPath;
|
||||
}
|
||||
|
||||
|
||||
// IMount implementation
|
||||
|
||||
|
||||
@Override
|
||||
public boolean exists( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return m_parent.exists( getFullPath( path ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDirectory( @Nonnull String path ) throws IOException
|
||||
{
|
||||
return m_parent.isDirectory( getFullPath( path ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException
|
||||
{
|
||||
m_parent.list( getFullPath( path ), contents );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getSize( @Nonnull String path ) throws IOException
|
||||
{
|
||||
|
@ -145,7 +145,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
if( ComputerCraft.debug_enable ) m_globals.load( state, new DebugLib() );
|
||||
|
||||
// Register custom load/loadstring provider which automatically adds prefixes.
|
||||
LibFunction.bind( state, m_globals, PrefixLoader.class, new String[]{ "load", "loadstring" } );
|
||||
LibFunction.bind( state, m_globals, PrefixLoader.class, new String[] { "load", "loadstring" } );
|
||||
|
||||
// Remove globals we don't want to expose
|
||||
// m_globals.rawset( "collectgarbage", Constants.NIL );
|
||||
@ -296,13 +296,13 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
{
|
||||
LuaTable table = new LuaTable();
|
||||
String[] methods = object.getMethodNames();
|
||||
for( int i = 0; i < methods.length; ++i )
|
||||
for( int i = 0; i < methods.length; i++ )
|
||||
{
|
||||
if( methods[ i ] != null )
|
||||
if( methods[i] != null )
|
||||
{
|
||||
final int method = i;
|
||||
final ILuaObject apiObject = object;
|
||||
final String methodName = methods[ i ];
|
||||
final String methodName = methods[i];
|
||||
table.rawset( methodName, new VarArgFunction()
|
||||
{
|
||||
@Override
|
||||
@ -319,7 +319,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
public Object[] pullEvent( String filter ) throws LuaException, InterruptedException
|
||||
{
|
||||
Object[] results = pullEventRaw( filter );
|
||||
if( results.length >= 1 && results[ 0 ].equals( "terminate" ) )
|
||||
if( results.length >= 1 && results[0].equals( "terminate" ) )
|
||||
{
|
||||
throw new LuaException( "Terminated", 0 );
|
||||
}
|
||||
@ -373,9 +373,9 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
Object[] results = task.execute();
|
||||
if( results != null )
|
||||
{
|
||||
Object[] eventArguments = new Object[ results.length + 2 ];
|
||||
eventArguments[ 0 ] = taskID;
|
||||
eventArguments[ 1 ] = true;
|
||||
Object[] eventArguments = new Object[results.length + 2];
|
||||
eventArguments[0] = taskID;
|
||||
eventArguments[1] = true;
|
||||
System.arraycopy( results, 0, eventArguments, 2, results.length );
|
||||
m_computer.queueEvent( "task_complete", eventArguments );
|
||||
}
|
||||
@ -422,12 +422,12 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
while( true )
|
||||
{
|
||||
Object[] response = pullEvent( "task_complete" );
|
||||
if( response.length >= 3 && response[ 1 ] instanceof Number && response[ 2 ] instanceof Boolean )
|
||||
if( response.length >= 3 && response[1] instanceof Number && response[2] instanceof Boolean )
|
||||
{
|
||||
if( ((Number) response[ 1 ]).intValue() == taskID )
|
||||
if( ((Number) response[1]).intValue() == taskID )
|
||||
{
|
||||
Object[] returnValues = new Object[ response.length - 3 ];
|
||||
if( (Boolean) response[ 2 ] )
|
||||
Object[] returnValues = new Object[response.length - 3];
|
||||
if( (Boolean) response[2] )
|
||||
{
|
||||
// Extract the return values from the event and return them
|
||||
System.arraycopy( response, 3, returnValues, 0, returnValues.length );
|
||||
@ -436,9 +436,9 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
else
|
||||
{
|
||||
// Extract the error message from the event and raise it
|
||||
if( response.length >= 4 && response[ 3 ] instanceof String )
|
||||
if( response.length >= 4 && response[3] instanceof String )
|
||||
{
|
||||
throw new LuaException( (String) response[ 3 ] );
|
||||
throw new LuaException( (String) response[3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -545,11 +545,11 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
return Constants.NONE;
|
||||
}
|
||||
|
||||
LuaValue[] values = new LuaValue[ objects.length ];
|
||||
for( int i = 0; i < values.length; ++i )
|
||||
LuaValue[] values = new LuaValue[objects.length];
|
||||
for( int i = 0; i < values.length; i++ )
|
||||
{
|
||||
Object object = objects[ i ];
|
||||
values[ i ] = toValue( object, null );
|
||||
Object object = objects[i];
|
||||
values[i] = toValue( object, null );
|
||||
}
|
||||
return varargsOf( values );
|
||||
}
|
||||
@ -632,12 +632,12 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
private static Object[] toObjects( Varargs values, int startIdx )
|
||||
{
|
||||
int count = values.count();
|
||||
Object[] objects = new Object[ count - startIdx + 1 ];
|
||||
for( int n = startIdx; n <= count; ++n )
|
||||
Object[] objects = new Object[count - startIdx + 1];
|
||||
for( int n = startIdx; n <= count; n++ )
|
||||
{
|
||||
int i = n - startIdx;
|
||||
LuaValue value = values.arg( n );
|
||||
objects[ i ] = toObject( value, null );
|
||||
objects[i] = toObject( value, null );
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
@ -650,7 +650,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
@Override
|
||||
public Varargs invoke( LuaState state, Varargs args ) throws LuaError
|
||||
{
|
||||
switch (opcode)
|
||||
switch( opcode )
|
||||
{
|
||||
case 0: // "load", // ( func [,chunkname] ) -> chunk | nil, msg
|
||||
{
|
||||
@ -700,7 +700,8 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
try
|
||||
{
|
||||
s = OperationHelper.call( state, func );
|
||||
} catch (LuaError e)
|
||||
}
|
||||
catch( LuaError e )
|
||||
{
|
||||
throw new IOException( e );
|
||||
}
|
||||
@ -713,7 +714,8 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
try
|
||||
{
|
||||
ls = s.strvalue();
|
||||
} catch (LuaError e)
|
||||
}
|
||||
catch( LuaError e )
|
||||
{
|
||||
throw new IOException( e );
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
package dan200.computercraft.core.lua;
|
||||
|
||||
import dan200.computercraft.api.lua.ILuaAPI;
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -13,16 +14,20 @@ import java.io.OutputStream;
|
||||
public interface ILuaMachine
|
||||
{
|
||||
void addAPI( ILuaAPI api );
|
||||
|
||||
|
||||
void loadBios( InputStream bios );
|
||||
|
||||
void handleEvent( String eventName, Object[] arguments );
|
||||
|
||||
void softAbort( String abortMessage );
|
||||
|
||||
void hardAbort( String abortMessage );
|
||||
|
||||
|
||||
boolean saveState( OutputStream output );
|
||||
|
||||
boolean restoreState( InputStream input );
|
||||
|
||||
|
||||
boolean isFinished();
|
||||
|
||||
|
||||
void unload();
|
||||
}
|
||||
|
@ -5,11 +5,12 @@
|
||||
*/
|
||||
|
||||
package dan200.computercraft.core.terminal;
|
||||
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class Terminal
|
||||
{
|
||||
{
|
||||
private static final String base16 = "0123456789abcdef";
|
||||
|
||||
private int m_cursorX;
|
||||
@ -33,24 +34,24 @@ public class Terminal
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
|
||||
m_cursorColour = 0;
|
||||
m_cursorBackgroundColour = 15;
|
||||
|
||||
m_text = new TextBuffer[ m_height ];
|
||||
m_textColour = new TextBuffer[ m_height ];
|
||||
m_backgroundColour = new TextBuffer[ m_height ];
|
||||
for( int i=0; i<m_height; ++i )
|
||||
m_text = new TextBuffer[m_height];
|
||||
m_textColour = new TextBuffer[m_height];
|
||||
m_backgroundColour = new TextBuffer[m_height];
|
||||
for( int i = 0; i < m_height; i++ )
|
||||
{
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
|
||||
|
||||
m_cursorX = 0;
|
||||
m_cursorY = 0;
|
||||
m_cursorBlink = false;
|
||||
|
||||
|
||||
m_changed = false;
|
||||
|
||||
m_palette = new Palette();
|
||||
@ -67,22 +68,24 @@ public class Terminal
|
||||
m_changed = true;
|
||||
m_palette.resetColours();
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void resize( int width, int height )
|
||||
{
|
||||
if( width == m_width && height == m_height )
|
||||
if( width == m_width && height == m_height )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int oldHeight = m_height;
|
||||
int oldWidth = m_width;
|
||||
TextBuffer[] oldText = m_text;
|
||||
@ -92,36 +95,36 @@ public class Terminal
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
m_text = new TextBuffer[ m_height ];
|
||||
m_textColour = new TextBuffer[ m_height ];
|
||||
m_backgroundColour = new TextBuffer[ m_height ];
|
||||
for( int i=0; i<m_height; ++i )
|
||||
m_text = new TextBuffer[m_height];
|
||||
m_textColour = new TextBuffer[m_height];
|
||||
m_backgroundColour = new TextBuffer[m_height];
|
||||
for( int i = 0; i < m_height; i++ )
|
||||
{
|
||||
if( i >= oldHeight )
|
||||
{
|
||||
m_text[ i ] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[ i ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[ i ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
else if( m_width == oldWidth )
|
||||
{
|
||||
m_text[ i ] = oldText[ i ];
|
||||
m_textColour[ i ] = oldTextColour[ i ];
|
||||
m_backgroundColour[ i ] = oldBackgroundColour[ i ];
|
||||
m_text[i] = oldText[i];
|
||||
m_textColour[i] = oldTextColour[i];
|
||||
m_backgroundColour[i] = oldBackgroundColour[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_text[ i ] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[ i ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[ i ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
m_text[ i ].write( oldText[ i ] );
|
||||
m_textColour[ i ].write( oldTextColour[ i ] );
|
||||
m_backgroundColour[ i ].write( oldBackgroundColour[ i ] );
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
m_text[i].write( oldText[i] );
|
||||
m_textColour[i].write( oldTextColour[i] );
|
||||
m_backgroundColour[i].write( oldBackgroundColour[i] );
|
||||
}
|
||||
}
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
|
||||
public void setCursorPos( int x, int y )
|
||||
{
|
||||
if( m_cursorX != x || m_cursorY != y )
|
||||
@ -131,7 +134,7 @@ public class Terminal
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setCursorBlink( boolean blink )
|
||||
{
|
||||
if( m_cursorBlink != blink )
|
||||
@ -140,7 +143,7 @@ public class Terminal
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setTextColour( int colour )
|
||||
{
|
||||
if( m_cursorColour != colour )
|
||||
@ -149,7 +152,7 @@ public class Terminal
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setBackgroundColour( int colour )
|
||||
{
|
||||
if( m_cursorBackgroundColour != colour )
|
||||
@ -158,27 +161,27 @@ public class Terminal
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getCursorX()
|
||||
{
|
||||
return m_cursorX;
|
||||
}
|
||||
|
||||
|
||||
public int getCursorY()
|
||||
{
|
||||
return m_cursorY;
|
||||
}
|
||||
|
||||
|
||||
public boolean getCursorBlink()
|
||||
{
|
||||
return m_cursorBlink;
|
||||
}
|
||||
|
||||
|
||||
public int getTextColour()
|
||||
{
|
||||
return m_cursorColour;
|
||||
}
|
||||
|
||||
|
||||
public int getBackgroundColour()
|
||||
{
|
||||
return m_cursorBackgroundColour;
|
||||
@ -195,9 +198,9 @@ public class Terminal
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
m_text[ y ].write( text, x );
|
||||
m_textColour[ y ].write( textColour, x );
|
||||
m_backgroundColour[ y ].write( backgroundColour, x );
|
||||
m_text[y].write( text, x );
|
||||
m_textColour[y].write( textColour, x );
|
||||
m_backgroundColour[y].write( backgroundColour, x );
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
@ -208,34 +211,34 @@ public class Terminal
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
m_text[ y ].write( text, x );
|
||||
m_textColour[ y ].fill( base16.charAt( m_cursorColour ), x, x + text.length() );
|
||||
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() );
|
||||
m_text[y].write( text, x );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ), x, x + text.length() );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() );
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void scroll( int yDiff )
|
||||
{
|
||||
if( yDiff != 0 )
|
||||
{
|
||||
TextBuffer[] newText = new TextBuffer[ m_height ];
|
||||
TextBuffer[] newTextColour = new TextBuffer[ m_height ];
|
||||
TextBuffer[] newBackgroundColour = new TextBuffer[ m_height ];
|
||||
for( int y = 0; y < m_height; ++y )
|
||||
TextBuffer[] newText = new TextBuffer[m_height];
|
||||
TextBuffer[] newTextColour = new TextBuffer[m_height];
|
||||
TextBuffer[] newBackgroundColour = new TextBuffer[m_height];
|
||||
for( int y = 0; y < m_height; y++ )
|
||||
{
|
||||
int oldY = y + yDiff;
|
||||
if( oldY >= 0 && oldY < m_height )
|
||||
{
|
||||
newText[ y ] = m_text[ oldY ];
|
||||
newTextColour[ y ] = m_textColour[ oldY ];
|
||||
newBackgroundColour[ y ] = m_backgroundColour[ oldY ];
|
||||
newText[y] = m_text[oldY];
|
||||
newTextColour[y] = m_textColour[oldY];
|
||||
newBackgroundColour[y] = m_backgroundColour[oldY];
|
||||
}
|
||||
else
|
||||
{
|
||||
newText[ y ] = new TextBuffer( ' ', m_width );
|
||||
newTextColour[ y ] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
newBackgroundColour[ y ] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
newText[y] = new TextBuffer( ' ', m_width );
|
||||
newTextColour[y] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
newBackgroundColour[y] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
}
|
||||
m_text = newText;
|
||||
@ -244,14 +247,14 @@ public class Terminal
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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_textColour[ y ].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
m_text[y].fill( ' ' );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
}
|
||||
m_changed = true;
|
||||
}
|
||||
@ -261,18 +264,18 @@ public class Terminal
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
m_text[ y ].fill( ' ' );
|
||||
m_textColour[ y ].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[ y ].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
m_text[y].fill( ' ' );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
m_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized TextBuffer getLine( int y )
|
||||
{
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return m_text[ y ];
|
||||
return m_text[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -284,21 +287,21 @@ public class Terminal
|
||||
m_backgroundColour[y].write( backgroundColour );
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
|
||||
public synchronized TextBuffer getTextColourLine( int y )
|
||||
{
|
||||
if( y>=0 && y<m_height )
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return m_textColour[ y ];
|
||||
return m_textColour[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized TextBuffer getBackgroundColourLine( int y )
|
||||
{
|
||||
if( y>=0 && y<m_height )
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return m_backgroundColour[ y ];
|
||||
return m_backgroundColour[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -325,13 +328,13 @@ public class Terminal
|
||||
nbttagcompound.setBoolean( "term_cursorBlink", m_cursorBlink );
|
||||
nbttagcompound.setInteger( "term_textColour", m_cursorColour );
|
||||
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_textColour_" + n, m_textColour[n].toString() );
|
||||
nbttagcompound.setString( "term_textBgColour_" + n, m_backgroundColour[ n ].toString() );
|
||||
nbttagcompound.setString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
|
||||
}
|
||||
if(m_palette != null)
|
||||
if( m_palette != null )
|
||||
{
|
||||
m_palette.writeToNBT( nbttagcompound );
|
||||
}
|
||||
@ -346,7 +349,7 @@ public class Terminal
|
||||
m_cursorColour = nbttagcompound.getInteger( "term_textColour" );
|
||||
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( ' ' );
|
||||
if( nbttagcompound.hasKey( "term_text_" + n ) )
|
||||
@ -364,7 +367,7 @@ public class Terminal
|
||||
m_backgroundColour[n].write( nbttagcompound.getString( "term_textBgColour_" + n ) );
|
||||
}
|
||||
}
|
||||
if (m_palette != null)
|
||||
if( m_palette != null )
|
||||
{
|
||||
m_palette.readFromNBT( nbttagcompound );
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class TextBuffer
|
||||
public TextBuffer( char c, int length )
|
||||
{
|
||||
m_text = new char[length];
|
||||
for( int i = 0; i < length; ++i )
|
||||
for( int i = 0; i < length; i++ )
|
||||
{
|
||||
m_text[i] = c;
|
||||
}
|
||||
@ -27,12 +27,12 @@ public class TextBuffer
|
||||
public TextBuffer( String text, int repetitions )
|
||||
{
|
||||
int textLength = text.length();
|
||||
m_text = new char[ textLength * repetitions ];
|
||||
for( int i = 0; i < repetitions; ++i )
|
||||
m_text = new char[textLength * repetitions];
|
||||
for( int i = 0; i < repetitions; i++ )
|
||||
{
|
||||
for( int j = 0; j < textLength; ++j )
|
||||
for( int j = 0; j < textLength; j++ )
|
||||
{
|
||||
m_text[ j + i * textLength ] = text.charAt(j );
|
||||
m_text[j + i * textLength] = text.charAt( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,12 +45,12 @@ public class TextBuffer
|
||||
public TextBuffer( TextBuffer text, int repetitions )
|
||||
{
|
||||
int textLength = text.length();
|
||||
m_text = new char[ textLength * repetitions ];
|
||||
for( int i = 0; i < repetitions; ++i )
|
||||
m_text = new char[textLength * repetitions];
|
||||
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 );
|
||||
end = Math.min( end, pos + 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 );
|
||||
}
|
||||
@ -116,7 +116,7 @@ public class TextBuffer
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, pos + 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 );
|
||||
}
|
||||
@ -136,7 +136,7 @@ public class TextBuffer
|
||||
{
|
||||
start = Math.max( start, 0 );
|
||||
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;
|
||||
}
|
||||
@ -159,7 +159,7 @@ public class TextBuffer
|
||||
end = Math.min( end, m_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 );
|
||||
}
|
||||
@ -182,7 +182,7 @@ public class TextBuffer
|
||||
end = Math.min( end, m_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 );
|
||||
}
|
||||
@ -190,14 +190,14 @@ public class TextBuffer
|
||||
|
||||
public char charAt( int i )
|
||||
{
|
||||
return m_text[ i ];
|
||||
return m_text[i];
|
||||
}
|
||||
|
||||
public void setChar( int i, char c )
|
||||
{
|
||||
if( i >= 0 && i <m_text.length )
|
||||
if( i >= 0 && i < m_text.length )
|
||||
{
|
||||
m_text[ i ] = c;
|
||||
m_text[i] = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@ public class CCTurtleProxyServer extends CCTurtleProxyCommon
|
||||
public CCTurtleProxyServer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ICCTurtleProxy implementation
|
||||
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
|
@ -6,11 +6,9 @@
|
||||
|
||||
package dan200.computercraft.server.proxy;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
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.printer.TilePrinter;
|
||||
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.InventoryPlayer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
@ -30,9 +26,9 @@ public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
|
||||
public ComputerCraftProxyServer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// IComputerCraftProxy implementation
|
||||
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
@ -74,7 +70,7 @@ public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getComputerGUI( TileComputer computer )
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ public class TextFormatter
|
||||
* @see net.minecraft.client.gui.FontRenderer#getCharWidth(char)
|
||||
*/
|
||||
private static final String CHARACTERS = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000";
|
||||
private static final int[] CHAR_WIDTHS = new int[]{
|
||||
private static final int[] CHAR_WIDTHS = new int[] {
|
||||
6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 4,
|
||||
4, 6, 7, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 2, 5, 6, 6, 6, 6, 3, 5, 5, 5, 6, 2, 6, 2, 6,
|
||||
@ -45,11 +45,11 @@ public class TextFormatter
|
||||
7, 7, 7, 7, 9, 6, 7, 8, 7, 6, 6, 9, 7, 6, 7, 1
|
||||
};
|
||||
|
||||
private static final int[] EXTRA_CHARS = new int[]{
|
||||
private static final int[] EXTRA_CHARS = new int[] {
|
||||
'\u20e2', '\u261b',
|
||||
};
|
||||
|
||||
private static final byte[] EXTRA_WIDTHS = new byte[]{
|
||||
private static final byte[] EXTRA_WIDTHS = new byte[] {
|
||||
8, 4,
|
||||
};
|
||||
|
||||
@ -138,7 +138,7 @@ public class TextFormatter
|
||||
// Append a fixed number of spaces
|
||||
if( spaces > 0 ) out.appendSibling( new TextComponentString( StringUtils.repeat( ' ', spaces ) ) );
|
||||
|
||||
// Append several minor characters to pad to a full string
|
||||
// Append several minor characters to pad to a full string
|
||||
if( extra > 0 )
|
||||
{
|
||||
out.appendSibling( coloured( StringUtils.repeat( PADDING_CHAR, extra ), TextFormatting.GRAY ) );
|
||||
|
@ -146,7 +146,7 @@ public class TextTable
|
||||
{
|
||||
ComputerCraftPacket packet = new ComputerCraftPacket();
|
||||
packet.m_packetType = ComputerCraftPacket.PostChat;
|
||||
packet.m_dataInt = new int[]{ id };
|
||||
packet.m_dataInt = new int[] { id };
|
||||
|
||||
String[] lines = packet.m_dataString = new String[out.size()];
|
||||
for( int i = 0; i < out.size(); i++ )
|
||||
|
@ -8,8 +8,8 @@ package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -25,7 +25,7 @@ public abstract class BlockDirectional extends BlockGeneric
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IDirectionalTile )
|
||||
{
|
||||
IDirectionalTile directional = (IDirectionalTile)tile;
|
||||
IDirectionalTile directional = (IDirectionalTile) tile;
|
||||
return directional.getDirection();
|
||||
}
|
||||
return EnumFacing.NORTH;
|
||||
@ -36,7 +36,7 @@ public abstract class BlockDirectional extends BlockGeneric
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IDirectionalTile )
|
||||
{
|
||||
IDirectionalTile directional = (IDirectionalTile)tile;
|
||||
IDirectionalTile directional = (IDirectionalTile) tile;
|
||||
directional.setDirection( dir );
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,9 @@ public abstract class BlockGeneric extends Block implements
|
||||
}
|
||||
|
||||
protected abstract IBlockState getDefaultBlockState( int damage, EnumFacing placedSide );
|
||||
|
||||
protected abstract TileGeneric createTile( IBlockState state );
|
||||
|
||||
protected abstract TileGeneric createTile( int damage );
|
||||
|
||||
@Override
|
||||
@ -95,7 +97,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
// Drop items
|
||||
if( drops.size() > 0 )
|
||||
{
|
||||
for (ItemStack item : drops)
|
||||
for( ItemStack item : drops )
|
||||
{
|
||||
dropItem( world, pos, item );
|
||||
}
|
||||
@ -115,7 +117,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
world.removeTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.destroy();
|
||||
}
|
||||
}
|
||||
@ -127,7 +129,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getPickedItem();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
@ -139,7 +141,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.onActivate( player, side, hitX, hitY, hitZ );
|
||||
}
|
||||
return false;
|
||||
@ -152,7 +154,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.onNeighbourChange();
|
||||
}
|
||||
}
|
||||
@ -163,7 +165,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
generic.onNeighbourTileEntityChange( neighbour );
|
||||
}
|
||||
}
|
||||
@ -175,7 +177,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.isSolidOnSide( side.ordinal() );
|
||||
}
|
||||
return false;
|
||||
@ -193,7 +195,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
if( generic.isImmuneToExplosion( exploder ) )
|
||||
{
|
||||
return 2000.0f;
|
||||
@ -210,7 +212,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBounds();
|
||||
}
|
||||
return FULL_BLOCK_AABB;
|
||||
@ -231,7 +233,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
|
||||
// Get collision bounds
|
||||
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
|
||||
@ -258,7 +260,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
|
||||
// Get collision bounds
|
||||
List<AxisAlignedBB> collision = new ArrayList<>( 1 );
|
||||
@ -267,7 +269,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
// Add collision bounds to list
|
||||
if( collision.size() > 0 )
|
||||
{
|
||||
for (AxisAlignedBB localBounds : collision)
|
||||
for( AxisAlignedBB localBounds : collision )
|
||||
{
|
||||
addCollisionBoxToList( pos, bigBox, list, localBounds );
|
||||
}
|
||||
@ -288,7 +290,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getRedstoneConnectivity( side );
|
||||
}
|
||||
return false;
|
||||
@ -301,7 +303,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getRedstoneOutput( oppositeSide.getOpposite() );
|
||||
}
|
||||
return 0;
|
||||
@ -319,7 +321,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBundledRedstoneConnectivity( side );
|
||||
}
|
||||
return false;
|
||||
@ -330,7 +332,7 @@ public abstract class BlockGeneric extends Block implements
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileGeneric && tile.hasWorld() )
|
||||
{
|
||||
TileGeneric generic = (TileGeneric)tile;
|
||||
TileGeneric generic = (TileGeneric) tile;
|
||||
return generic.getBundledRedstoneOutput( side );
|
||||
}
|
||||
return 0;
|
||||
|
@ -51,7 +51,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||
|
||||
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 );
|
||||
|
||||
@ -66,7 +66,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||
int index = ColourUtils.getStackColour( stack );
|
||||
if( index < 0 ) continue;
|
||||
|
||||
Colour colour = Colour.values()[ index ];
|
||||
Colour colour = Colour.values()[index];
|
||||
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class ColourableRecipe extends IForgeRegistryEntry.Impl<IRecipe> implemen
|
||||
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
|
||||
{
|
||||
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 );
|
||||
results.set( i, ForgeHooks.getContainerItem( stack ) );
|
||||
|
@ -8,8 +8,8 @@ package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -31,7 +31,7 @@ public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
|
||||
Block block = world.getBlockState( pos ).getBlock();
|
||||
if( block != null && block instanceof BlockGeneric )
|
||||
{
|
||||
BlockGeneric generic = (BlockGeneric)block;
|
||||
BlockGeneric generic = (BlockGeneric) block;
|
||||
if( generic.getBundledRedstoneConnectivity( world, pos, side ) )
|
||||
{
|
||||
return generic.getBundledRedstoneOutput( world, pos, side );
|
||||
|
@ -11,5 +11,6 @@ import net.minecraft.util.EnumFacing;
|
||||
public interface IDirectionalTile
|
||||
{
|
||||
EnumFacing getDirection();
|
||||
|
||||
void setDirection( EnumFacing dir );
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ import dan200.computercraft.core.terminal.Terminal;
|
||||
public interface ITerminal
|
||||
{
|
||||
Terminal getTerminal();
|
||||
|
||||
boolean isColour();
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -41,7 +41,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
packet.m_packetType = ComputerCraftPacket.RequestTileEntityUpdate;
|
||||
|
||||
BlockPos pos = getPos();
|
||||
packet.m_dataInt = new int[]{ pos.getX(), pos.getY(), pos.getZ() };
|
||||
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ() };
|
||||
ComputerCraft.sendToServer( packet );
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
Block block = getWorld().getBlockState( getPos() ).getBlock();
|
||||
if( block != null && block instanceof BlockGeneric )
|
||||
{
|
||||
return (BlockGeneric)block;
|
||||
return (BlockGeneric) block;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -159,7 +159,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
double range = getInteractRange( player );
|
||||
BlockPos pos = getPos();
|
||||
return player.getEntityWorld() == getWorld() &&
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= ( range * range );
|
||||
player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= (range * range);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -207,7 +207,7 @@ public abstract class TileGeneric extends TileEntity
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag ()
|
||||
public NBTTagCompound getUpdateTag()
|
||||
{
|
||||
NBTTagCompound tag = super.getUpdateTag();
|
||||
writeDescription( tag );
|
||||
@ -215,9 +215,9 @@ public abstract class TileGeneric extends TileEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag ( @Nonnull NBTTagCompound tag)
|
||||
public void handleUpdateTag( @Nonnull NBTTagCompound tag )
|
||||
{
|
||||
super.handleUpdateTag(tag);
|
||||
super.handleUpdateTag( tag );
|
||||
readDescription( tag );
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class CommandAPI implements ILuaAPI
|
||||
sender.clearOutput();
|
||||
|
||||
int result = commandManager.executeCommand( sender, command );
|
||||
return new Object[]{ (result > 0), sender.copyOutput() };
|
||||
return new Object[] { (result > 0), sender.copyOutput() };
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
@ -90,7 +90,7 @@ public class CommandAPI implements ILuaAPI
|
||||
{
|
||||
ComputerCraft.log.error( "Error running command.", t );
|
||||
}
|
||||
return new Object[]{ false, createOutput( "Java Exception Thrown: " + t.toString() ) };
|
||||
return new Object[] { false, createOutput( "Java Exception Thrown: " + t.toString() ) };
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -182,7 +182,7 @@ public class CommandAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Object[]{ result };
|
||||
return new Object[] { result };
|
||||
} );
|
||||
}
|
||||
case 3:
|
||||
@ -206,37 +206,37 @@ public class CommandAPI implements ILuaAPI
|
||||
// Get the details of the block
|
||||
World world = m_computer.getWorld();
|
||||
BlockPos min = new BlockPos(
|
||||
Math.min( minx, maxx ),
|
||||
Math.min( miny, maxy ),
|
||||
Math.min( minz, maxz )
|
||||
Math.min( minx, maxx ),
|
||||
Math.min( miny, maxy ),
|
||||
Math.min( minz, maxz )
|
||||
);
|
||||
BlockPos max = new BlockPos(
|
||||
Math.max( minx, maxx ),
|
||||
Math.max( miny, maxy ),
|
||||
Math.max( minz, maxz )
|
||||
Math.max( minx, maxx ),
|
||||
Math.max( miny, maxy ),
|
||||
Math.max( minz, maxz )
|
||||
);
|
||||
if( !WorldUtil.isBlockInWorld( world, min ) || !WorldUtil.isBlockInWorld( world, max ) )
|
||||
{
|
||||
throw new LuaException( "Co-ordinates out or range" );
|
||||
}
|
||||
if( ( max.getX() - min.getX() + 1 ) * ( max.getY() - min.getY() + 1 ) * ( max.getZ() - min.getZ() + 1 ) > 4096 )
|
||||
if( (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1) * (max.getZ() - min.getZ() + 1) > 4096 )
|
||||
{
|
||||
throw new LuaException( "Too many blocks" );
|
||||
}
|
||||
int i=1;
|
||||
int i = 1;
|
||||
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 );
|
||||
results.put( i++, getBlockInfo( world, pos ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Object[]{ results };
|
||||
return new Object[] { results };
|
||||
} );
|
||||
}
|
||||
case 5:
|
||||
@ -252,7 +252,7 @@ public class CommandAPI implements ILuaAPI
|
||||
BlockPos position = new BlockPos( x, y, z );
|
||||
if( WorldUtil.isBlockInWorld( world, position ) )
|
||||
{
|
||||
return new Object[]{ getBlockInfo( world, position ) };
|
||||
return new Object[] { getBlockInfo( world, position ) };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -31,8 +31,8 @@ public class BlockCommandComputer extends BlockComputerBase
|
||||
|
||||
public static class Properties
|
||||
{
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
|
||||
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create("state", ComputerState.class);
|
||||
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
|
||||
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
|
||||
}
|
||||
|
||||
// Members
|
||||
@ -54,7 +54,7 @@ public class BlockCommandComputer extends BlockComputerBase
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, Properties.FACING, Properties.STATE );
|
||||
return new BlockStateContainer( this, Properties.FACING, Properties.STATE );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@ -84,7 +84,7 @@ public class BlockCommandComputer extends BlockComputerBase
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IComputerTile )
|
||||
{
|
||||
IComputer computer = ((IComputerTile)tile).getComputer();
|
||||
IComputer computer = ((IComputerTile) tile).getComputer();
|
||||
if( computer != null && computer.isOn() )
|
||||
{
|
||||
if( computer.isCursorDisplayed() )
|
||||
|
@ -33,13 +33,13 @@ public class BlockComputer extends BlockComputerBase
|
||||
// Statics
|
||||
public static class Properties
|
||||
{
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
|
||||
public static final PropertyBool ADVANCED = PropertyBool.create("advanced");
|
||||
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create("state", ComputerState.class);
|
||||
public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );
|
||||
public static final PropertyBool ADVANCED = PropertyBool.create( "advanced" );
|
||||
public static final PropertyEnum<ComputerState> STATE = PropertyEnum.create( "state", ComputerState.class );
|
||||
}
|
||||
|
||||
// Members
|
||||
|
||||
|
||||
public BlockComputer()
|
||||
{
|
||||
super( Material.ROCK );
|
||||
@ -125,7 +125,7 @@ public class BlockComputer extends BlockComputerBase
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof IComputerTile )
|
||||
{
|
||||
IComputer computer = ((IComputerTile)tile).getComputer();
|
||||
IComputer computer = ((IComputerTile) tile).getComputer();
|
||||
if( computer != null && computer.isOn() )
|
||||
{
|
||||
if( computer.isCursorDisplayed() )
|
||||
@ -144,15 +144,18 @@ public class BlockComputer extends BlockComputerBase
|
||||
@Override
|
||||
public ComputerFamily getFamily( int damage )
|
||||
{
|
||||
return ((ItemComputer) Item.getItemFromBlock(this)).getFamily( damage );
|
||||
return ((ItemComputer) Item.getItemFromBlock( this )).getFamily( damage );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputerFamily getFamily( IBlockState state )
|
||||
{
|
||||
if( state.getValue( Properties.ADVANCED ) ) {
|
||||
if( state.getValue( Properties.ADVANCED ) )
|
||||
{
|
||||
return ComputerFamily.Advanced;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return ComputerFamily.Normal;
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -40,14 +40,17 @@ public abstract class BlockComputerBase extends BlockDirectional
|
||||
}
|
||||
|
||||
protected abstract IBlockState getDefaultBlockState( ComputerFamily family, EnumFacing placedSide );
|
||||
|
||||
protected abstract ComputerFamily getFamily( int damage );
|
||||
|
||||
protected abstract ComputerFamily getFamily( IBlockState state );
|
||||
|
||||
protected abstract TileComputerBase createTile( ComputerFamily family );
|
||||
|
||||
@Override
|
||||
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
|
||||
{
|
||||
ItemComputerBase item = (ItemComputerBase)Item.getItemFromBlock( this );
|
||||
ItemComputerBase item = (ItemComputerBase) Item.getItemFromBlock( this );
|
||||
return getDefaultBlockState( item.getFamily( damage ), placedSide );
|
||||
}
|
||||
|
||||
@ -73,7 +76,7 @@ public abstract class BlockComputerBase extends BlockDirectional
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileComputerBase )
|
||||
{
|
||||
TileComputerBase computer = (TileComputerBase)tile;
|
||||
TileComputerBase computer = (TileComputerBase) tile;
|
||||
computer.updateInput();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class ComputerPeripheral
|
||||
m_type = type;
|
||||
m_computer = computer;
|
||||
}
|
||||
|
||||
|
||||
// IPeripheral implementation
|
||||
|
||||
@Nonnull
|
||||
|
@ -13,8 +13,12 @@ import dan200.computercraft.shared.computer.core.IComputer;
|
||||
public interface IComputerTile extends ITerminalTile
|
||||
{
|
||||
void setComputerID( int id );
|
||||
|
||||
void setLabel( String label );
|
||||
|
||||
IComputer getComputer();
|
||||
|
||||
IComputer createComputer();
|
||||
|
||||
ComputerFamily getFamily();
|
||||
}
|
||||
|
@ -16,9 +16,12 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.CommandBlockBaseLogic;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.text.*;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -26,7 +26,7 @@ public class TileComputer extends TileComputerBase
|
||||
|
||||
// Members
|
||||
private ComputerProxy m_proxy;
|
||||
|
||||
|
||||
public TileComputer()
|
||||
{
|
||||
}
|
||||
@ -125,6 +125,6 @@ public class TileComputer extends TileComputerBase
|
||||
@Override
|
||||
protected int remapLocalSide( int localSide )
|
||||
{
|
||||
return s_remapSide[ localSide ];
|
||||
return s_remapSide[localSide];
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public abstract class TileComputerBase extends TileGeneric
|
||||
Block block = super.getBlock();
|
||||
if( block != null && block instanceof BlockComputerBase )
|
||||
{
|
||||
return (BlockComputerBase)block;
|
||||
return (BlockComputerBase) block;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -368,7 +368,7 @@ public abstract class TileComputerBase extends TileGeneric
|
||||
for( EnumFacing dir : EnumFacing.VALUES )
|
||||
{
|
||||
BlockPos offset = pos.offset( dir );
|
||||
if ( offset.equals( neighbour ) )
|
||||
if( offset.equals( neighbour ) )
|
||||
{
|
||||
updateSideInput( computer, dir, offset );
|
||||
break;
|
||||
|
@ -11,15 +11,22 @@ import dan200.computercraft.shared.common.ITerminal;
|
||||
public interface IComputer extends ITerminal
|
||||
{
|
||||
int getInstanceID();
|
||||
|
||||
int getID();
|
||||
|
||||
String getLabel();
|
||||
|
||||
boolean isOn();
|
||||
|
||||
boolean isCursorDisplayed();
|
||||
|
||||
void turnOn();
|
||||
|
||||
void shutdown();
|
||||
|
||||
void reboot();
|
||||
|
||||
void queueEvent( String event );
|
||||
|
||||
void queueEvent( String event, Object[] arguments );
|
||||
}
|
||||
|
@ -65,7 +65,8 @@ public class ServerComputer extends ServerTerminal
|
||||
m_ticksSincePing = 0;
|
||||
}
|
||||
|
||||
public ComputerFamily getFamily(){
|
||||
public ComputerFamily getFamily()
|
||||
{
|
||||
return m_family;
|
||||
}
|
||||
|
||||
@ -144,8 +145,9 @@ public class ServerComputer extends ServerTerminal
|
||||
{
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
private ComputerCraftPacket createComputerPacket() {
|
||||
|
||||
private ComputerCraftPacket createComputerPacket()
|
||||
{
|
||||
ComputerCraftPacket packet = new ComputerCraftPacket();
|
||||
packet.m_packetType = ComputerCraftPacket.ComputerChanged;
|
||||
packet.m_dataInt = new int[] { getInstanceID() };
|
||||
@ -154,7 +156,8 @@ public class ServerComputer extends ServerTerminal
|
||||
return packet;
|
||||
}
|
||||
|
||||
protected ComputerCraftPacket createTerminalPacket() {
|
||||
protected ComputerCraftPacket createTerminalPacket()
|
||||
{
|
||||
ComputerCraftPacket packet = new ComputerCraftPacket();
|
||||
packet.m_packetType = ComputerCraftPacket.ComputerTerminalChanged;
|
||||
packet.m_dataInt = new int[] { getInstanceID() };
|
||||
@ -163,9 +166,9 @@ public class ServerComputer extends ServerTerminal
|
||||
return packet;
|
||||
}
|
||||
|
||||
public void broadcastState(boolean force)
|
||||
public void broadcastState( boolean force )
|
||||
{
|
||||
if(hasOutputChanged() || force)
|
||||
if( hasOutputChanged() || force )
|
||||
{
|
||||
// Send computer state to all clients
|
||||
ComputerCraft.sendToAllPlayers( createComputerPacket() );
|
||||
@ -349,7 +352,7 @@ public class ServerComputer extends ServerTerminal
|
||||
@Override
|
||||
public int getDay()
|
||||
{
|
||||
return (int)((m_world.getWorldTime() + 6000) / 24000) + 1;
|
||||
return (int) ((m_world.getWorldTime() + 6000) / 24000) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
|
||||
computer.update();
|
||||
if( computer.hasTerminalChanged() || computer.hasOutputChanged() )
|
||||
{
|
||||
computer.broadcastState(false);
|
||||
computer.broadcastState( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
|
||||
{
|
||||
//System.out.println( "ADD SERVER COMPUTER " + instanceID );
|
||||
super.add( instanceID, computer );
|
||||
computer.broadcastState(true);
|
||||
computer.broadcastState( true );
|
||||
//System.out.println( getComputers().size() + " SERVER COMPUTERS" );
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,12 @@ public class ContainerComputer extends Container
|
||||
implements IContainerComputer
|
||||
{
|
||||
private TileComputer m_computer;
|
||||
|
||||
|
||||
public ContainerComputer( TileComputer computer )
|
||||
{
|
||||
m_computer = computer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith( @Nonnull EntityPlayer player )
|
||||
{
|
||||
|
@ -36,8 +36,8 @@ public class ComputerItemFactory
|
||||
@Nonnull
|
||||
public static ItemStack create( int id, String label, ComputerFamily family )
|
||||
{
|
||||
ItemComputer computer = ((ItemComputer)Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
|
||||
ItemCommandComputer commandComputer = ((ItemCommandComputer)Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer ));
|
||||
ItemComputer computer = ((ItemComputer) Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
|
||||
ItemCommandComputer commandComputer = ((ItemCommandComputer) Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer ));
|
||||
switch( family )
|
||||
{
|
||||
case Normal:
|
||||
|
@ -14,7 +14,10 @@ import javax.annotation.Nonnull;
|
||||
public interface IComputerItem
|
||||
{
|
||||
int getComputerID( @Nonnull ItemStack stack );
|
||||
|
||||
String getLabel( @Nonnull ItemStack stack );
|
||||
|
||||
ComputerFamily getFamily( @Nonnull ItemStack stack );
|
||||
ItemStack withFamily(@Nonnull ItemStack stack, @Nonnull ComputerFamily family);
|
||||
|
||||
ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family );
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -28,9 +28,9 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
|
||||
{
|
||||
// See if we match the recipe, and extract the input computercraft ID
|
||||
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 );
|
||||
Ingredient target = getIngredients().get( x + y * 3 );
|
||||
@ -50,9 +50,9 @@ public abstract class ComputerConvertRecipe extends ShapedRecipes
|
||||
@Override
|
||||
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 );
|
||||
|
||||
|
@ -19,8 +19,8 @@ import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents an ingredient which requires an item to have a specific
|
||||
* computer family. This allows us to have operations which only work
|
||||
* on normal or
|
||||
* computer family. This allows us to have operations which only work
|
||||
* on normal or
|
||||
*/
|
||||
public class ComputerIngredient extends Ingredient
|
||||
{
|
||||
|
@ -42,10 +42,10 @@ public final class IntegrationCharset
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event)
|
||||
public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event )
|
||||
{
|
||||
TileEntity tile = event.getObject();
|
||||
if(tile instanceof TileGeneric)
|
||||
if( tile instanceof TileGeneric )
|
||||
{
|
||||
event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) );
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemDiskExpanded extends ItemDiskLegacy
|
||||
{
|
||||
{
|
||||
public ItemDiskExpanded()
|
||||
{
|
||||
}
|
||||
@ -23,20 +23,20 @@ public class ItemDiskExpanded extends ItemDiskLegacy
|
||||
public static ItemStack createFromIDAndColour( int id, String label, int colour )
|
||||
{
|
||||
ItemStack stack = new ItemStack( ComputerCraft.Items.diskExpanded, 1, 0 );
|
||||
|
||||
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
if( nbt == null )
|
||||
{
|
||||
nbt = new NBTTagCompound();
|
||||
stack.setTagCompound(nbt);
|
||||
stack.setTagCompound( nbt );
|
||||
}
|
||||
nbt.setInteger( "color", colour );
|
||||
ComputerCraft.Items.diskExpanded.setDiskID( stack, id );
|
||||
ComputerCraft.Items.diskExpanded.setLabel( stack, label );
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public int getDiskID( @Nonnull ItemStack stack )
|
||||
{
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
@ -72,7 +72,7 @@ public class ItemDiskExpanded extends ItemDiskLegacy
|
||||
}
|
||||
else
|
||||
{
|
||||
return Colour.values()[ Math.min( 15, stack.getItemDamage() ) ].getHex();
|
||||
return Colour.values()[Math.min( 15, stack.getItemDamage() )].getHex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ public class ItemPrintout extends Item
|
||||
public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
|
||||
{
|
||||
if( !isInCreativeTab( tabs ) ) return;
|
||||
list.add( createSingleFromTitleAndText( null, new String[ LINES_PER_PAGE ], new String[ LINES_PER_PAGE ] ) );
|
||||
list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) );
|
||||
list.add( createBookFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) );
|
||||
list.add( createSingleFromTitleAndText( null, new String[LINES_PER_PAGE], new String[LINES_PER_PAGE] ) );
|
||||
list.add( createMultipleFromTitleAndText( null, new String[2 * LINES_PER_PAGE], new String[2 * LINES_PER_PAGE] ) );
|
||||
list.add( createBookFromTitleAndText( null, new String[2 * LINES_PER_PAGE], new String[2 * LINES_PER_PAGE] ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -133,21 +133,21 @@ public class ItemPrintout extends Item
|
||||
if( text != null )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
nbt.setString( "line"+i, text[i] );
|
||||
nbt.setString( "line" + i, text[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( colours != null )
|
||||
{
|
||||
for(int i=0; i<colours.length; ++i)
|
||||
for( int i = 0; i < colours.length; i++ )
|
||||
{
|
||||
if( colours[i] != null )
|
||||
{
|
||||
nbt.setString( "colour"+i, colours[i] );
|
||||
nbt.setString( "colour" + i, colours[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -221,11 +221,11 @@ public class ItemPrintout extends Item
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
int numLines = getPageCount( stack ) * LINES_PER_PAGE;
|
||||
String[] lines = new String[numLines];
|
||||
for( int i=0; i<lines.length; ++i )
|
||||
for( int i = 0; i < lines.length; i++ )
|
||||
{
|
||||
if( nbt != null )
|
||||
{
|
||||
lines[i] = nbt.getString( "line"+i );
|
||||
lines[i] = nbt.getString( "line" + i );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -240,11 +240,11 @@ public class ItemPrintout extends Item
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
int numLines = getPageCount( stack ) * LINES_PER_PAGE;
|
||||
String[] lines = new String[numLines];
|
||||
for( int i=0; i<lines.length; ++i )
|
||||
for( int i = 0; i < lines.length; i++ )
|
||||
{
|
||||
if( nbt != null )
|
||||
{
|
||||
lines[i] = nbt.getString( "colour"+i );
|
||||
lines[i] = nbt.getString( "colour" + i );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -26,14 +26,14 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
|
||||
{
|
||||
private final Ingredient paper = new OreIngredient( "paper" );
|
||||
private final Ingredient redstone = new OreIngredient( "dustRedstone" );
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World world )
|
||||
{
|
||||
boolean paperFound = 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 );
|
||||
|
||||
@ -65,7 +65,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
|
||||
{
|
||||
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 );
|
||||
|
||||
@ -76,7 +76,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
|
||||
int index = ColourUtils.getStackColour( stack );
|
||||
if( index < 0 ) continue;
|
||||
|
||||
Colour colour = Colour.values()[ index ];
|
||||
Colour colour = Colour.values()[index];
|
||||
tracker.addColour( colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
}
|
||||
@ -108,7 +108,7 @@ public class DiskRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRe
|
||||
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
|
||||
{
|
||||
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 );
|
||||
results.set( i, ForgeHooks.getContainerItem( stack ) );
|
||||
|
@ -8,7 +8,6 @@ package dan200.computercraft.shared.media.recipes;
|
||||
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
@ -37,7 +36,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput()
|
||||
@ -62,11 +61,11 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
boolean stringFound = false;
|
||||
boolean leatherFound = 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.getItem() instanceof ItemPrintout && ItemPrintout.getType( stack ) != ItemPrintout.Type.Book )
|
||||
@ -75,7 +74,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
{
|
||||
printouts = new ItemStack[9];
|
||||
}
|
||||
printouts[ numPrintouts ] = stack;
|
||||
printouts[numPrintouts] = stack;
|
||||
numPages = numPages + ItemPrintout.getPageCount( stack );
|
||||
numPrintouts++;
|
||||
printoutFound = true;
|
||||
@ -86,7 +85,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
{
|
||||
printouts = new ItemStack[9];
|
||||
}
|
||||
printouts[ numPrintouts ] = stack;
|
||||
printouts[numPrintouts] = stack;
|
||||
numPages++;
|
||||
numPrintouts++;
|
||||
}
|
||||
@ -105,15 +104,15 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Build some pages with what was passed in
|
||||
if( numPages <= ItemPrintout.MAX_PAGES && stringFound && printoutFound && numPrintouts >= (leatherFound ? 1 : 2) )
|
||||
{
|
||||
String[] text = new String[ numPages * ItemPrintout.LINES_PER_PAGE ];
|
||||
String[] colours = new String[ numPages * ItemPrintout.LINES_PER_PAGE ];
|
||||
String[] text = new String[numPages * ItemPrintout.LINES_PER_PAGE];
|
||||
String[] colours = new String[numPages * ItemPrintout.LINES_PER_PAGE];
|
||||
int line = 0;
|
||||
|
||||
for( int printout=0; printout<numPrintouts; ++printout )
|
||||
|
||||
for( int printout = 0; printout < numPrintouts; ++printout )
|
||||
{
|
||||
ItemStack stack = printouts[printout];
|
||||
if( stack.getItem() instanceof ItemPrintout )
|
||||
@ -121,31 +120,31 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
// Add a printout
|
||||
String[] pageText = ItemPrintout.getText( printouts[printout] );
|
||||
String[] pageColours = ItemPrintout.getColours( printouts[printout] );
|
||||
for( int pageLine=0; pageLine<pageText.length; ++pageLine )
|
||||
for( int pageLine = 0; pageLine < pageText.length; ++pageLine )
|
||||
{
|
||||
text[ line ] = pageText[ pageLine ];
|
||||
colours[ line ] = pageColours[ pageLine ];
|
||||
text[line] = pageText[pageLine];
|
||||
colours[line] = pageColours[pageLine];
|
||||
line++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add a blank page
|
||||
for( int pageLine=0; pageLine<ItemPrintout.LINES_PER_PAGE; ++pageLine )
|
||||
for( int pageLine = 0; pageLine < ItemPrintout.LINES_PER_PAGE; ++pageLine )
|
||||
{
|
||||
text[ line ] = "";
|
||||
colours[ line ] = "";
|
||||
text[line] = "";
|
||||
colours[line] = "";
|
||||
line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String title = null;
|
||||
if( printouts[0].getItem() instanceof ItemPrintout )
|
||||
{
|
||||
title = ItemPrintout.getTitle( printouts[0] );
|
||||
}
|
||||
|
||||
|
||||
if( leatherFound )
|
||||
{
|
||||
return ItemPrintout.createBookFromTitleAndText( title, text, colours );
|
||||
@ -164,7 +163,7 @@ public class PrintoutRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements
|
||||
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
|
||||
{
|
||||
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 );
|
||||
results.set( i, ForgeHooks.getContainerItem( stack ) );
|
||||
|
@ -15,7 +15,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
|
||||
public class ComputerCraftPacket
|
||||
{
|
||||
// Packet types
|
||||
@ -158,7 +158,7 @@ public class ComputerCraftPacket
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dataString = new String[ nString ];
|
||||
m_dataString = new String[nString];
|
||||
for( int k = 0; k < nString; k++ )
|
||||
{
|
||||
if( buffer.readBoolean() )
|
||||
@ -168,11 +168,11 @@ public class ComputerCraftPacket
|
||||
buffer.readBytes( b );
|
||||
try
|
||||
{
|
||||
m_dataString[ k ] = new String( b, "UTF-8" );
|
||||
m_dataString[k] = new String( b, "UTF-8" );
|
||||
}
|
||||
catch( UnsupportedEncodingException e )
|
||||
{
|
||||
m_dataString[ k ] = null;
|
||||
m_dataString[k] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,10 +183,10 @@ public class ComputerCraftPacket
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dataInt = new int[ nInt ];
|
||||
m_dataInt = new int[nInt];
|
||||
for( int k = 0; k < nInt; k++ )
|
||||
{
|
||||
m_dataInt[ k ] = buffer.readInt();
|
||||
m_dataInt[k] = buffer.readInt();
|
||||
}
|
||||
}
|
||||
if( nByte == 0 )
|
||||
@ -195,14 +195,14 @@ public class ComputerCraftPacket
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dataByte = new byte[ nByte ][];
|
||||
m_dataByte = new byte[nByte][];
|
||||
for( int k = 0; k < nByte; k++ )
|
||||
{
|
||||
int length = buffer.readInt();
|
||||
if( length > 0 )
|
||||
{
|
||||
m_dataByte[ k ] = new byte[ length ];
|
||||
buffer.getBytes( buffer.readerIndex(), m_dataByte[ k ] );
|
||||
m_dataByte[k] = new byte[length];
|
||||
buffer.getBytes( buffer.readerIndex(), m_dataByte[k] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -214,7 +214,7 @@ public class ComputerCraftPacket
|
||||
else
|
||||
{
|
||||
int byteLength = buffer.readInt();
|
||||
byte[] bytes = new byte[ byteLength ];
|
||||
byte[] bytes = new byte[byteLength];
|
||||
buffer.getBytes( buffer.readerIndex(), bytes );
|
||||
try
|
||||
{
|
||||
@ -232,7 +232,8 @@ public class ComputerCraftPacket
|
||||
* Determine whether this packet requires the player to be interacting with the
|
||||
* target.
|
||||
*/
|
||||
public boolean requiresContainer() {
|
||||
public boolean requiresContainer()
|
||||
{
|
||||
return m_packetType != RequestComputerUpdate && m_packetType != RequestTileEntityUpdate;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public interface INetworkedThing
|
||||
|
@ -35,7 +35,7 @@ public class PacketHandler
|
||||
{
|
||||
ComputerCraftPacket packet = new ComputerCraftPacket();
|
||||
packet.fromBytes( event.getPacket().payload() );
|
||||
ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer)event.getHandler()).player );
|
||||
ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer) event.getHandler()).player );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ public class CommandBlockPeripheral implements IPeripheral
|
||||
@Override
|
||||
public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull final Object[] arguments ) throws LuaException, InterruptedException
|
||||
{
|
||||
switch (method)
|
||||
switch( method )
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
|
@ -10,8 +10,8 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityCommandBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -24,7 +24,7 @@ public class CommandBlockPeripheralProvider implements IPeripheralProvider
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TileEntityCommandBlock )
|
||||
{
|
||||
TileEntityCommandBlock commandBlock = (TileEntityCommandBlock)tile;
|
||||
TileEntityCommandBlock commandBlock = (TileEntityCommandBlock) tile;
|
||||
return new CommandBlockPeripheral( commandBlock );
|
||||
}
|
||||
return null;
|
||||
|
@ -10,7 +10,8 @@ public enum BlockCableCableVariant implements IStringSerializable
|
||||
ANY( "any" ),
|
||||
X_AXIS( "x" ),
|
||||
Y_AXIS( "y" ),
|
||||
Z_AXIS( "z" ),;
|
||||
Z_AXIS( "z" ),
|
||||
;
|
||||
|
||||
private final String m_name;
|
||||
|
||||
|
@ -43,12 +43,18 @@ public enum BlockCableModemVariant implements IStringSerializable
|
||||
{
|
||||
switch( facing )
|
||||
{
|
||||
case DOWN: return DownOff;
|
||||
case UP: return UpOff;
|
||||
case NORTH: return NorthOff;
|
||||
case SOUTH: return SouthOff;
|
||||
case WEST: return WestOff;
|
||||
case EAST: return EastOff;
|
||||
case DOWN:
|
||||
return DownOff;
|
||||
case UP:
|
||||
return UpOff;
|
||||
case NORTH:
|
||||
return NorthOff;
|
||||
case SOUTH:
|
||||
return SouthOff;
|
||||
case WEST:
|
||||
return WestOff;
|
||||
case EAST:
|
||||
return EastOff;
|
||||
}
|
||||
return NorthOff;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
@SideOnly( Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
public BlockRenderLayer getRenderLayer()
|
||||
{
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
@ -108,9 +108,9 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
{
|
||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
|
||||
}
|
||||
else if (meta == 13)
|
||||
else if( meta == 13 )
|
||||
{
|
||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker);
|
||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker );
|
||||
}
|
||||
return state;
|
||||
}
|
||||
@ -125,7 +125,8 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
case DiskDrive:
|
||||
{
|
||||
EnumFacing dir = state.getValue( Properties.FACING );
|
||||
if( dir.getAxis() == EnumFacing.Axis.Y ) {
|
||||
if( dir.getAxis() == EnumFacing.Axis.Y )
|
||||
{
|
||||
dir = EnumFacing.NORTH;
|
||||
}
|
||||
meta = dir.getIndex();
|
||||
@ -190,7 +191,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile != null && tile instanceof TilePeripheralBase )
|
||||
{
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase)tile;
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase) tile;
|
||||
anim = peripheral.getAnim();
|
||||
dir = peripheral.getDirection();
|
||||
}
|
||||
@ -347,7 +348,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
int xIndex, yIndex, width, height;
|
||||
if( tile != null && tile instanceof TileMonitor )
|
||||
{
|
||||
TileMonitor monitor = (TileMonitor)tile;
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
dir = monitor.getDirection();
|
||||
front = monitor.getFront();
|
||||
xIndex = monitor.getXIndex();
|
||||
@ -446,7 +447,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
|
||||
state = state.withProperty( Properties.FACING, dir );
|
||||
state = state.withProperty( Properties.VARIANT,
|
||||
BlockPeripheralVariant.values()[ baseVariant.ordinal() + subType ]
|
||||
BlockPeripheralVariant.values()[baseVariant.ordinal() + subType]
|
||||
);
|
||||
break;
|
||||
}
|
||||
@ -516,7 +517,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
@Override
|
||||
public PeripheralType getPeripheralType( int damage )
|
||||
{
|
||||
return ((ItemPeripheral)Item.getItemFromBlock(this)).getPeripheralType( damage );
|
||||
return ((ItemPeripheral) Item.getItemFromBlock( this )).getPeripheralType( damage );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -576,7 +577,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
setDirection( world, pos, dir );
|
||||
if( stack.hasDisplayName() && tile != null && tile instanceof TilePeripheralBase )
|
||||
{
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase)tile;
|
||||
TilePeripheralBase peripheral = (TilePeripheralBase) tile;
|
||||
peripheral.setLabel( stack.getDisplayName() );
|
||||
}
|
||||
break;
|
||||
@ -596,7 +597,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
direction += 6;
|
||||
}
|
||||
|
||||
TileMonitor monitor = (TileMonitor)tile;
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
if( world.isRemote )
|
||||
{
|
||||
monitor.setDir( direction );
|
||||
@ -648,9 +649,9 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
public boolean causesSuffocation( IBlockState state )
|
||||
{
|
||||
// This normally uses the default state
|
||||
// This normally uses the default state
|
||||
return material.blocksMovement() && state.isOpaqueCube();
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,8 @@ import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -27,8 +27,11 @@ public abstract class BlockPeripheralBase extends BlockDirectional
|
||||
}
|
||||
|
||||
protected abstract IBlockState getDefaultBlockState( PeripheralType type, EnumFacing placedSide );
|
||||
|
||||
protected abstract PeripheralType getPeripheralType( int damage );
|
||||
|
||||
protected abstract PeripheralType getPeripheralType( IBlockState state );
|
||||
|
||||
protected abstract TilePeripheralBase createTile( PeripheralType type );
|
||||
|
||||
@Override
|
||||
@ -40,7 +43,7 @@ public abstract class BlockPeripheralBase extends BlockDirectional
|
||||
@Override
|
||||
protected final IBlockState getDefaultBlockState( int damage, EnumFacing placedSide )
|
||||
{
|
||||
ItemPeripheralBase item = (ItemPeripheralBase)Item.getItemFromBlock( this );
|
||||
ItemPeripheralBase item = (ItemPeripheralBase) Item.getItemFromBlock( this );
|
||||
return getDefaultBlockState( item.getPeripheralType( damage ), placedSide );
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ public enum BlockPeripheralVariant implements IStringSerializable
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
public PeripheralType getPeripheralType()
|
||||
{
|
||||
return m_peripheralType;
|
||||
|
@ -12,8 +12,8 @@ import dan200.computercraft.shared.computer.blocks.ComputerPeripheral;
|
||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -33,17 +33,17 @@ public class DefaultPeripheralProvider implements IPeripheralProvider
|
||||
// Handle our peripherals
|
||||
if( tile instanceof IPeripheralTile )
|
||||
{
|
||||
IPeripheralTile peripheralTile = (IPeripheralTile)tile;
|
||||
IPeripheralTile peripheralTile = (IPeripheralTile) tile;
|
||||
return peripheralTile.getPeripheral( side );
|
||||
}
|
||||
|
||||
// Handle our computers
|
||||
if( tile instanceof TileComputerBase )
|
||||
{
|
||||
TileComputerBase computerTile = (TileComputerBase)tile;
|
||||
TileComputerBase computerTile = (TileComputerBase) tile;
|
||||
if( tile instanceof TileTurtle )
|
||||
{
|
||||
if( !((TileTurtle)tile).hasMoved() )
|
||||
if( !((TileTurtle) tile).hasMoved() )
|
||||
{
|
||||
return new ComputerPeripheral( "turtle", computerTile.createProxy() );
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import net.minecraft.util.EnumFacing;
|
||||
public interface IPeripheralTile extends IDirectionalTile
|
||||
{
|
||||
PeripheralType getPeripheralType();
|
||||
|
||||
IPeripheral getPeripheral( EnumFacing side );
|
||||
|
||||
String getLabel();
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class ItemCable extends ItemPeripheralBase
|
||||
TileEntity tile = world.getTileEntity( offset );
|
||||
if( tile != null && tile instanceof TileCable )
|
||||
{
|
||||
TileCable cable = (TileCable)tile;
|
||||
TileCable cable = (TileCable) tile;
|
||||
cable.modemChanged();
|
||||
cable.connectionsChanged();
|
||||
}
|
||||
@ -153,7 +153,7 @@ public class ItemCable extends ItemPeripheralBase
|
||||
TileEntity tile = world.getTileEntity( offset );
|
||||
if( tile != null && tile instanceof TileCable )
|
||||
{
|
||||
TileCable cable = (TileCable)tile;
|
||||
TileCable cable = (TileCable) tile;
|
||||
cable.modemChanged();
|
||||
cable.connectionsChanged();
|
||||
}
|
||||
@ -163,7 +163,7 @@ public class ItemCable extends ItemPeripheralBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return super.onItemUse( player, world, pos, hand, side, fx, fy, fz );
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ItemPeripheral extends ItemPeripheralBase
|
||||
}
|
||||
case Speaker:
|
||||
{
|
||||
stack = new ItemStack(this, quantity, 5);
|
||||
stack = new ItemStack( this, quantity, 5 );
|
||||
break;
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public class ItemPeripheral extends ItemPeripheralBase
|
||||
list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) );
|
||||
list.add( PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 1 ) );
|
||||
list.add( PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ) );
|
||||
list.add( PeripheralItemFactory.create( PeripheralType.Speaker, null, 1) );
|
||||
list.add( PeripheralItemFactory.create( PeripheralType.Speaker, null, 1 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,9 +24,9 @@ public class PeripheralItemFactory
|
||||
@Nonnull
|
||||
public static ItemStack create( PeripheralType type, String label, int quantity )
|
||||
{
|
||||
ItemPeripheral peripheral = ((ItemPeripheral)Item.getItemFromBlock( ComputerCraft.Blocks.peripheral ));
|
||||
ItemCable cable = ((ItemCable)Item.getItemFromBlock( ComputerCraft.Blocks.cable ));
|
||||
ItemAdvancedModem advancedModem = ((ItemAdvancedModem)Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem ));
|
||||
ItemPeripheral peripheral = ((ItemPeripheral) Item.getItemFromBlock( ComputerCraft.Blocks.peripheral ));
|
||||
ItemCable cable = ((ItemCable) Item.getItemFromBlock( ComputerCraft.Blocks.cable ));
|
||||
ItemAdvancedModem advancedModem = ((ItemAdvancedModem) Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem ));
|
||||
switch( type )
|
||||
{
|
||||
case Speaker:
|
||||
|
@ -11,12 +11,11 @@ import dan200.computercraft.shared.common.TileGeneric;
|
||||
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TilePeripheralBase extends TileGeneric
|
||||
implements IPeripheralTile, ITickable
|
||||
@ -42,7 +41,7 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
@Override
|
||||
public BlockPeripheralBase getBlock()
|
||||
{
|
||||
return (BlockPeripheralBase)super.getBlock();
|
||||
return (BlockPeripheralBase) super.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,7 +115,7 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
{
|
||||
return m_anim;
|
||||
}
|
||||
|
||||
|
||||
public void setAnim( int anim )
|
||||
{
|
||||
if( anim != m_anim )
|
||||
@ -126,7 +125,7 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if( m_changed )
|
||||
@ -135,12 +134,12 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public void readFromNBT( NBTTagCompound nbttagcompound )
|
||||
{
|
||||
// Read properties
|
||||
super.readFromNBT(nbttagcompound);
|
||||
super.readFromNBT( nbttagcompound );
|
||||
if( nbttagcompound.hasKey( "dir" ) )
|
||||
{
|
||||
m_dir = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) );
|
||||
|
@ -21,19 +21,19 @@ public class ContainerDiskDrive extends Container
|
||||
public ContainerDiskDrive( IInventory playerInventory, TileDiskDrive diskDrive )
|
||||
{
|
||||
m_diskDrive = diskDrive;
|
||||
addSlotToContainer(new Slot( m_diskDrive, 0, 8 + 4 * 18, 35));
|
||||
|
||||
for(int j = 0; j < 3; j++)
|
||||
addSlotToContainer( new Slot( m_diskDrive, 0, 8 + 4 * 18, 35 ) );
|
||||
|
||||
for( int j = 0; j < 3; j++ )
|
||||
{
|
||||
for(int i1 = 0; i1 < 9; i1++)
|
||||
for( int i1 = 0; i1 < 9; i1++ )
|
||||
{
|
||||
addSlotToContainer(new Slot(playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18));
|
||||
addSlotToContainer( new Slot( playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18 ) );
|
||||
}
|
||||
}
|
||||
|
||||
for(int k = 0; k < 9; k++)
|
||||
for( int k = 0; k < 9; k++ )
|
||||
{
|
||||
addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
|
||||
addSlotToContainer( new Slot( playerInventory, k, 8 + k * 18, 142 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,35 +48,35 @@ public class ContainerDiskDrive extends Container
|
||||
public ItemStack transferStackInSlot( EntityPlayer player, int i )
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot = inventorySlots.get(i);
|
||||
if(slot != null && slot.getHasStack())
|
||||
Slot slot = inventorySlots.get( i );
|
||||
if( slot != null && slot.getHasStack() )
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack().copy();
|
||||
itemstack = itemstack1.copy();
|
||||
if(i == 0 )
|
||||
if( i == 0 )
|
||||
{
|
||||
if(!mergeItemStack(itemstack1, 1, 37, true))
|
||||
if( !mergeItemStack( itemstack1, 1, 37, true ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else if( !mergeItemStack(itemstack1, 0, 1, false) )
|
||||
else if( !mergeItemStack( itemstack1, 0, 1, false ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if(itemstack1.isEmpty())
|
||||
|
||||
if( itemstack1.isEmpty() )
|
||||
{
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
slot.putStack( ItemStack.EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if(itemstack1.getCount() != itemstack.getCount())
|
||||
|
||||
if( itemstack1.getCount() != itemstack.getCount() )
|
||||
{
|
||||
slot.onTake(player, itemstack1);
|
||||
slot.onTake( player, itemstack1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ public class DiskDrivePeripheral implements IPeripheral
|
||||
Item item = disk.getItem();
|
||||
if( item instanceof ItemDiskLegacy )
|
||||
{
|
||||
return new Object[] { ((ItemDiskLegacy)item).getDiskID( disk ) };
|
||||
return new Object[] { ((ItemDiskLegacy) item).getDiskID( disk ) };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -188,7 +188,7 @@ public class DiskDrivePeripheral implements IPeripheral
|
||||
{
|
||||
if( other instanceof DiskDrivePeripheral )
|
||||
{
|
||||
DiskDrivePeripheral otherDiskDrive = (DiskDrivePeripheral)other;
|
||||
DiskDrivePeripheral otherDiskDrive = (DiskDrivePeripheral) other;
|
||||
if( otherDiskDrive.m_diskDrive == this.m_diskDrive )
|
||||
{
|
||||
return true;
|
||||
|
@ -58,7 +58,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
private ItemStack m_diskStack;
|
||||
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this );
|
||||
private IMount m_diskMount;
|
||||
|
||||
|
||||
private boolean m_recordQueued;
|
||||
private boolean m_recordPlaying;
|
||||
private boolean m_restartRecord;
|
||||
@ -70,7 +70,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
|
||||
m_diskStack = ItemStack.EMPTY;
|
||||
m_diskMount = null;
|
||||
|
||||
|
||||
m_recordQueued = false;
|
||||
m_recordPlaying = false;
|
||||
m_restartRecord = false;
|
||||
@ -95,7 +95,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
if( !getWorld().isRemote )
|
||||
{
|
||||
ItemStack disk = player.getHeldItem( EnumHand.MAIN_HAND );
|
||||
if( !disk.isEmpty() && getStackInSlot(0).isEmpty() )
|
||||
if( !disk.isEmpty() && getStackInSlot( 0 ).isEmpty() )
|
||||
{
|
||||
if( ComputerCraft.getMedia( disk ) != null )
|
||||
{
|
||||
@ -136,9 +136,9 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound)
|
||||
public void readFromNBT( NBTTagCompound nbttagcompound )
|
||||
{
|
||||
super.readFromNBT(nbttagcompound);
|
||||
super.readFromNBT( nbttagcompound );
|
||||
if( nbttagcompound.hasKey( "item" ) )
|
||||
{
|
||||
NBTTagCompound item = nbttagcompound.getCompoundTag( "item" );
|
||||
@ -149,9 +149,9 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound)
|
||||
public NBTTagCompound writeToNBT( NBTTagCompound nbttagcompound )
|
||||
{
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
nbttagcompound = super.writeToNBT( nbttagcompound );
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
@ -160,7 +160,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
@ -172,7 +172,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
ejectContents( false );
|
||||
m_ejectQueued = false;
|
||||
}
|
||||
|
||||
|
||||
// Music
|
||||
synchronized( this )
|
||||
{
|
||||
@ -203,7 +203,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
// IInventory implementation
|
||||
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
@ -218,40 +218,40 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
public ItemStack getStackInSlot( int i )
|
||||
{
|
||||
return m_diskStack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int i)
|
||||
public ItemStack removeStackFromSlot( int i )
|
||||
{
|
||||
ItemStack result = m_diskStack;
|
||||
m_diskStack = ItemStack.EMPTY;
|
||||
m_diskMount = null;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
public ItemStack decrStackSize( int i, int j )
|
||||
{
|
||||
if (m_diskStack.isEmpty())
|
||||
if( m_diskStack.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (m_diskStack.getCount() <= j)
|
||||
|
||||
if( m_diskStack.getCount() <= j )
|
||||
{
|
||||
ItemStack disk = m_diskStack;
|
||||
setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
return disk;
|
||||
}
|
||||
|
||||
ItemStack part = m_diskStack.splitStack(j);
|
||||
if (m_diskStack.isEmpty())
|
||||
|
||||
ItemStack part = m_diskStack.splitStack( j );
|
||||
if( m_diskStack.isEmpty() )
|
||||
{
|
||||
setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
}
|
||||
@ -264,7 +264,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( int i, @Nonnull ItemStack itemStack )
|
||||
{
|
||||
{
|
||||
if( getWorld().isRemote )
|
||||
{
|
||||
m_diskStack = itemStack;
|
||||
@ -280,7 +280,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
m_diskStack = itemStack;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Unmount old disk
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
@ -290,7 +290,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
unmountDisk( computer );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Stop music
|
||||
if( m_recordPlaying )
|
||||
{
|
||||
@ -298,7 +298,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
m_recordPlaying = false;
|
||||
m_recordQueued = false;
|
||||
}
|
||||
|
||||
|
||||
// Swap disk over
|
||||
m_diskStack = itemStack;
|
||||
m_diskMount = null;
|
||||
@ -364,14 +364,14 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
public void openInventory( @Nonnull EntityPlayer player )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void closeInventory( @Nonnull EntityPlayer player )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, @Nonnull ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int i, @Nonnull ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -395,13 +395,13 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id)
|
||||
public int getField( int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value)
|
||||
public void setField( int id, int value )
|
||||
{
|
||||
}
|
||||
|
||||
@ -494,7 +494,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
// private methods
|
||||
|
||||
|
||||
private synchronized void mountDisk( IComputerAccess computer )
|
||||
{
|
||||
if( !m_diskStack.isEmpty() )
|
||||
@ -509,14 +509,14 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
if( m_diskMount != null )
|
||||
{
|
||||
if( m_diskMount instanceof IWritableMount)
|
||||
if( m_diskMount instanceof IWritableMount )
|
||||
{
|
||||
// Try mounting at the lowest numbered "disk" name we can
|
||||
int n = 1;
|
||||
while( info.mountPath == null )
|
||||
{
|
||||
info.mountPath = computer.mountWritable( (n==1) ? "disk" : ("disk" + n), (IWritableMount)m_diskMount );
|
||||
n++;
|
||||
info.mountPath = computer.mountWritable( (n == 1) ? "disk" : ("disk" + n), (IWritableMount) m_diskMount );
|
||||
n++;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -525,8 +525,8 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
int n = 1;
|
||||
while( info.mountPath == null )
|
||||
{
|
||||
info.mountPath = computer.mount( (n==1) ? "disk" : ("disk" + n), m_diskMount );
|
||||
n++;
|
||||
info.mountPath = computer.mount( (n == 1) ? "disk" : ("disk" + n), m_diskMount );
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -544,7 +544,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
MountInfo info = m_computers.get( computer );
|
||||
assert( info != null );
|
||||
assert (info != null);
|
||||
if( info.mountPath != null )
|
||||
{
|
||||
computer.unmount( info.mountPath );
|
||||
@ -555,13 +555,16 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
}
|
||||
|
||||
private void updateAnim()
|
||||
{
|
||||
{
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
IMedia contents = getDiskMedia();
|
||||
if( contents != null ) {
|
||||
if( contents != null )
|
||||
{
|
||||
setAnim( 2 );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
setAnim( 1 );
|
||||
}
|
||||
}
|
||||
@ -570,14 +573,14 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
setAnim( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized void ejectContents( boolean destroyed )
|
||||
{
|
||||
if( getWorld().isRemote )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
// Remove the disks from the inventory
|
||||
@ -602,11 +605,11 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
entityitem.motionX = xOff * 0.15;
|
||||
entityitem.motionY = 0.0;
|
||||
entityitem.motionZ = zOff * 0.15;
|
||||
|
||||
getWorld().spawnEntity(entityitem);
|
||||
|
||||
getWorld().spawnEntity( entityitem );
|
||||
if( !destroyed )
|
||||
{
|
||||
getWorld().playBroadcastSound(1000, getPos(), 0);
|
||||
getWorld().playBroadcastSound( 1000, getPos(), 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -668,7 +671,7 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
@Override
|
||||
public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable EnumFacing facing )
|
||||
{
|
||||
return capability == ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
|
||||
return capability == ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -45,7 +45,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState()
|
||||
{
|
||||
return new BlockStateContainer(this, Properties.FACING, Properties.ON );
|
||||
return new BlockStateContainer( this, Properties.FACING, Properties.ON );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -86,7 +86,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
{
|
||||
for( IComputerAccess computer : m_computers )
|
||||
{
|
||||
computer.queueEvent( "modem_message", new Object[]{
|
||||
computer.queueEvent( "modem_message", new Object[] {
|
||||
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload(), distance
|
||||
} );
|
||||
}
|
||||
@ -102,7 +102,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
{
|
||||
for( IComputerAccess computer : m_computers )
|
||||
{
|
||||
computer.queueEvent( "modem_message", new Object[]{
|
||||
computer.queueEvent( "modem_message", new Object[] {
|
||||
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload()
|
||||
} );
|
||||
}
|
||||
@ -124,7 +124,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@Override
|
||||
public String[] getMethodNames()
|
||||
{
|
||||
return new String[]{
|
||||
return new String[] {
|
||||
"open",
|
||||
"isOpen",
|
||||
"close",
|
||||
@ -160,7 +160,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
{
|
||||
// isOpen
|
||||
int channel = parseChannel( arguments, 0 );
|
||||
return new Object[]{ m_state.isOpen( channel ) };
|
||||
return new Object[] { m_state.isOpen( channel ) };
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
@ -204,7 +204,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
{
|
||||
// isWireless
|
||||
IPacketNetwork network = m_network;
|
||||
return new Object[]{ network != null && network.isWireless() };
|
||||
return new Object[] { network != null && network.isWireless() };
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user