Merge master into fd-limit

This commit is contained in:
Lignum 2017-05-02 18:26:45 +02:00
commit 2bfb53227a
No known key found for this signature in database
GPG Key ID: 0889206F5A8A700D
12 changed files with 224 additions and 65 deletions

View File

@ -15,7 +15,7 @@
Contributing
============
While ComputerCraft will no longer be actively developed by Daniel Ratcliffe, you may still contribute pull requests which will be reviewed and incorporated into releases periodically. A pull requests is more likely to be accepted if it meets the following criteria:
While ComputerCraft will no longer be actively developed by Daniel Ratcliffe, you may still contribute pull requests which will be reviewed and incorporated into releases periodically. A pull request is more likely to be accepted if it meets the following criteria:
* It does not add any new dependencies for compiling, running or using the mod.
* It does not break compatibility with world saves or programs created with previous versions of the mod.

View File

@ -3,9 +3,10 @@
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft;
import com.google.common.base.CaseFormat;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.filesystem.IWritableMount;
import dan200.computercraft.api.media.IMedia;
@ -82,7 +83,10 @@
// UNIVERSAL //
///////////////
@Mod( modid = "ComputerCraft", name = "ComputerCraft", version = "${version}" )
@Mod(
modid = "ComputerCraft", name = "ComputerCraft", version = "${version}",
guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory"
)
public class ComputerCraft
{
// GUI IDs
@ -159,6 +163,32 @@ public static class Upgrades
public static TurtleModem advancedModem;
}
public static class Config {
public static Configuration config;
public static Property http_enable;
public static Property http_whitelist;
public static Property disable_lua51_features;
public static Property default_computer_settings;
public static Property enableCommandBlock;
public static Property turtlesNeedFuel;
public static Property turtleFuelLimit;
public static Property advancedTurtleFuelLimit;
public static Property turtlesObeyBlockProtection;
public static Property turtlesCanPush;
public static Property modem_range;
public static Property modem_highAltitudeRange;
public static Property modem_rangeDuringStorm;
public static Property modem_highAltitudeRangeDuringStorm;
public static Property computerSpaceLimit;
public static Property floppySpaceLimit;
public static Property maximumFilesOpen;
}
// Registries
public static ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
public static ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
@ -193,80 +223,66 @@ public ComputerCraft()
public void preInit( FMLPreInitializationEvent event )
{
// Load config
Configuration config = new Configuration( event.getSuggestedConfigurationFile() );
config.load();
Config.config = new Configuration( event.getSuggestedConfigurationFile() );
Config.config.load();
// Setup general
Config.http_enable = Config.config.get( Configuration.CATEGORY_GENERAL, "http_enable", http_enable );
Config.http_enable.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" for more fine grained control than this)" );
Property prop = config.get(Configuration.CATEGORY_GENERAL, "http_enable", http_enable);
prop.setComment( "Enable the \"http\" API on Computers (see \"http_whitelist\" for more fine grained control than this)" );
http_enable = prop.getBoolean(http_enable);
Config.http_whitelist = Config.config.get( Configuration.CATEGORY_GENERAL, "http_whitelist", http_whitelist );
Config.http_whitelist.setComment( "A semicolon limited list of wildcards for domains that can be accessed through the \"http\" API on Computers. Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com;*.github.com;*.computercraft.info\" will restrict access to just those 3 domains." );
prop = config.get(Configuration.CATEGORY_GENERAL, "http_whitelist", http_whitelist );
prop.setComment( "A semicolon limited list of wildcards for domains that can be accessed through the \"http\" API on Computers. Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com;*.github.com;*.computercraft.info\" will restrict access to just those 3 domains." );
http_whitelist = prop.getString();
Config.disable_lua51_features = Config.config.get( Configuration.CATEGORY_GENERAL, "disable_lua51_features", disable_lua51_features );
Config.disable_lua51_features.setComment( "Set this to true to disable Lua 5.1 functions that will be removed in a future update. Useful for ensuring forward compatibility of your programs now." );
prop = config.get(Configuration.CATEGORY_GENERAL, "disable_lua51_features", disable_lua51_features );
prop.setComment( "Set this to true to disable Lua 5.1 functions that will be removed in a future update. Useful for ensuring forward compatibility of your programs now." );
disable_lua51_features = prop.getBoolean( disable_lua51_features );
Config.default_computer_settings = Config.config.get( Configuration.CATEGORY_GENERAL, "default_computer_settings", default_computer_settings );
Config.default_computer_settings.setComment( "A comma seperated list of default system settings to set on new computers. Example: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all autocompletion" );
prop = config.get( Configuration.CATEGORY_GENERAL, "default_computer_settings", default_computer_settings );
prop.setComment( "A comma seperated list of default system settings to set on new computers. Example: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all autocompletion" );
default_computer_settings = prop.getString();
Config.enableCommandBlock = Config.config.get( Configuration.CATEGORY_GENERAL, "enableCommandBlock", enableCommandBlock );
Config.enableCommandBlock.setComment( "Enable Command Block peripheral support" );
prop = config.get(Configuration.CATEGORY_GENERAL, "enableCommandBlock", enableCommandBlock);
prop.setComment( "Enable Command Block peripheral support" );
enableCommandBlock = prop.getBoolean(enableCommandBlock);
Config.modem_range = Config.config.get( Configuration.CATEGORY_GENERAL, "modem_range", modem_range );
Config.modem_range.setComment( "The range of Wireless Modems at low altitude in clear weather, in meters" );
prop = config.get(Configuration.CATEGORY_GENERAL, "modem_range", modem_range);
prop.setComment( "The range of Wireless Modems at low altitude in clear weather, in meters" );
modem_range = Math.min( prop.getInt(), 100000 );
Config.modem_highAltitudeRange = Config.config.get( Configuration.CATEGORY_GENERAL, "modem_highAltitudeRange", modem_highAltitudeRange );
Config.modem_highAltitudeRange.setComment( "The range of Wireless Modems at maximum altitude in clear weather, in meters" );
prop = config.get(Configuration.CATEGORY_GENERAL, "modem_highAltitudeRange", modem_highAltitudeRange);
prop.setComment( "The range of Wireless Modems at maximum altitude in clear weather, in meters" );
modem_highAltitudeRange = Math.min( prop.getInt(), 100000 );
Config.modem_rangeDuringStorm = Config.config.get( Configuration.CATEGORY_GENERAL, "modem_rangeDuringStorm", modem_rangeDuringStorm );
Config.modem_rangeDuringStorm.setComment( "The range of Wireless Modems at low altitude in stormy weather, in meters" );
prop = config.get(Configuration.CATEGORY_GENERAL, "modem_rangeDuringStorm", modem_rangeDuringStorm);
prop.setComment( "The range of Wireless Modems at low altitude in stormy weather, in meters" );
modem_rangeDuringStorm = Math.min( prop.getInt(), 100000 );
Config.modem_highAltitudeRangeDuringStorm = Config.config.get( Configuration.CATEGORY_GENERAL, "modem_highAltitudeRangeDuringStorm", modem_highAltitudeRangeDuringStorm );
Config.modem_highAltitudeRangeDuringStorm.setComment( "The range of Wireless Modems at maximum altitude in stormy weather, in meters" );
prop = config.get(Configuration.CATEGORY_GENERAL, "modem_highAltitudeRangeDuringStorm", modem_highAltitudeRangeDuringStorm);
prop.setComment( "The range of Wireless Modems at maximum altitude in stormy weather, in meters" );
modem_highAltitudeRangeDuringStorm = Math.min( prop.getInt(), 100000 );
Config.computerSpaceLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "computerSpaceLimit", computerSpaceLimit );
Config.computerSpaceLimit.setComment( "The disk space limit for computers and turtles, in bytes" );
prop = config.get(Configuration.CATEGORY_GENERAL, "computerSpaceLimit", computerSpaceLimit);
prop.setComment( "The disk space limit for computers and turtles, in bytes" );
computerSpaceLimit = prop.getInt();
Config.floppySpaceLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "floppySpaceLimit", floppySpaceLimit );
Config.floppySpaceLimit.setComment( "The disk space limit for floppy disks, in bytes" );
prop = config.get(Configuration.CATEGORY_GENERAL, "floppySpaceLimit", floppySpaceLimit);
prop.setComment( "The disk space limit for floppy disks, in bytes" );
floppySpaceLimit = prop.getInt();
Config.turtlesNeedFuel = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel );
Config.turtlesNeedFuel.setComment( "Set whether Turtles require fuel to move" );
prop = config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen);
prop.setComment( "How many files a computer can have open at the same time" );
maximumFilesOpen = prop.getInt();
Config.maximumFilesOpen = Config.config.get(Configuration.CATEGORY_GENERAL, "maximumFilesOpen", maximumFilesOpen);
Config.maximumFilesOpen.setComment( "How many files a computer can have open at the same time" );
prop = config.get(Configuration.CATEGORY_GENERAL, "turtlesNeedFuel", turtlesNeedFuel);
prop.setComment( "Set whether Turtles require fuel to move" );
turtlesNeedFuel = prop.getBoolean( turtlesNeedFuel );
Config.turtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit );
Config.turtleFuelLimit.setComment( "The fuel limit for Turtles" );
prop = config.get(Configuration.CATEGORY_GENERAL, "turtleFuelLimit", turtleFuelLimit);
prop.setComment( "The fuel limit for Turtles" );
turtleFuelLimit = prop.getInt( turtleFuelLimit );
Config.advancedTurtleFuelLimit = Config.config.get( Configuration.CATEGORY_GENERAL, "advancedTurtleFuelLimit", advancedTurtleFuelLimit );
Config.advancedTurtleFuelLimit.setComment( "The fuel limit for Advanced Turtles" );
prop = config.get(Configuration.CATEGORY_GENERAL, "advancedTurtleFuelLimit", advancedTurtleFuelLimit);
prop.setComment( "The fuel limit for Advanced Turtles" );
advancedTurtleFuelLimit = prop.getInt(advancedTurtleFuelLimit);
Config.turtlesObeyBlockProtection = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesObeyBlockProtection", turtlesObeyBlockProtection );
Config.turtlesObeyBlockProtection.setComment( "If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)" );
prop = config.get(Configuration.CATEGORY_GENERAL, "turtlesObeyBlockProtection", turtlesObeyBlockProtection);
prop.setComment( "If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)" );
turtlesObeyBlockProtection = prop.getBoolean( turtlesObeyBlockProtection );
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" );
prop = config.get(Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush);
prop.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
turtlesCanPush = prop.getBoolean(turtlesCanPush);
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
{
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
}
config.save();
syncConfig();
// Setup network
networkEventChannel = NetworkRegistry.INSTANCE.newEventDrivenChannel( "CC" );
@ -276,6 +292,33 @@ public void preInit( FMLPreInitializationEvent event )
turtleProxy.preInit();
}
public static void syncConfig() {
http_enable = Config.http_enable.getBoolean();
http_whitelist = Config.http_whitelist.getString();
disable_lua51_features = Config.disable_lua51_features.getBoolean();
default_computer_settings = Config.default_computer_settings.getString();
enableCommandBlock = Config.enableCommandBlock.getBoolean();
modem_range = Math.min( Config.modem_range.getInt(), 100000 );
modem_highAltitudeRange = Math.min( Config.modem_highAltitudeRange.getInt(), 100000 );
modem_rangeDuringStorm = Math.min( Config.modem_rangeDuringStorm.getInt(), 100000 );
modem_highAltitudeRangeDuringStorm = Math.min( Config.modem_highAltitudeRangeDuringStorm.getInt(), 100000 );
computerSpaceLimit = Config.computerSpaceLimit.getInt();
floppySpaceLimit = Config.floppySpaceLimit.getInt();
maximumFilesOpen = Math.max( 0, Config.maximumFilesOpen.getInt() );
turtlesNeedFuel = Config.turtlesNeedFuel.getBoolean();
turtleFuelLimit = Config.turtleFuelLimit.getInt();
advancedTurtleFuelLimit = Config.advancedTurtleFuelLimit.getInt();
turtlesObeyBlockProtection = Config.turtlesObeyBlockProtection.getBoolean();
turtlesCanPush = Config.turtlesCanPush.getBoolean();
Config.config.save();
}
@Mod.EventHandler
public void init( FMLInitializationEvent event )
{

View File

@ -0,0 +1,61 @@
package dan200.computercraft.client.gui;
import dan200.computercraft.ComputerCraft;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.IModGuiFactory;
import net.minecraftforge.fml.client.config.GuiConfig;
import net.minecraftforge.fml.client.config.IConfigElement;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class GuiConfigCC extends GuiConfig
{
public GuiConfigCC( GuiScreen parentScreen )
{
super( parentScreen, getConfigElements(), "ComputerCraft", false, false, "ComputerCraft" );
}
private static List<IConfigElement> getConfigElements()
{
ArrayList<IConfigElement> elements = new ArrayList<IConfigElement>();
for (Property property : ComputerCraft.Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
{
elements.add( new ConfigElement( property ) );
}
return elements;
}
public static class Factory
implements IModGuiFactory
{
@Override
public void initialize( Minecraft minecraft )
{
}
@Override
public Class<? extends GuiScreen> mainConfigGuiClass()
{
return GuiConfigCC.class;
}
@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
{
return null;
}
@Override
public RuntimeOptionGuiHandler getHandlerFor( RuntimeOptionCategoryElement runtimeOptionCategoryElement )
{
return null;
}
}
}

View File

@ -231,7 +231,7 @@ public void run()
}
}
} );
thread.setDaemon(true);
thread.start();
}

View File

@ -8,6 +8,7 @@
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.shared.util.StringUtil;
import java.util.Arrays;
import java.util.HashMap;
@ -266,11 +267,7 @@ public Object[] callMethod( ILuaContext context, int method, Object[] args ) thr
{
throw new LuaException( "Expected string or nil" );
}
label = (String)args[0];
if( label.length() > 32 )
{
label = label.substring( 0, 32 );
}
label = StringUtil.normaliseLabel( (String) args[0] );
}
m_apiEnvironment.setLabel( label );
return null;

View File

@ -113,6 +113,7 @@ public void run() {
} );
// Run the task
worker.setDaemon(true);
worker.start();
worker.join( 7000 );
@ -173,7 +174,8 @@ public void run() {
}
}
}, "Computer Dispatch Thread" );
m_thread.setDaemon(true);
m_thread.start();
m_running = true;
}

View File

@ -12,6 +12,7 @@
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -87,6 +88,7 @@ public Object[] callMethod( IComputerAccess computer, ILuaContext context, int m
if( media != null )
{
ItemStack disk = m_diskDrive.getDiskStack();
label = StringUtil.normaliseLabel( label );
if( media.setLabel( disk, label ) )
{
m_diskDrive.setDiskStack( disk );

View File

@ -71,6 +71,7 @@
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
@ -656,5 +657,13 @@ public void onWorldLoad( WorldEvent.Load event )
public void onWorldUnload( WorldEvent.Unload event )
{
}
@SubscribeEvent
public void onConfigChanged( ConfigChangedEvent.OnConfigChangedEvent event) {
if( event.getModID().equals( "ComputerCraft" ) )
{
ComputerCraft.syncConfig();
}
}
}
}

View File

@ -0,0 +1,26 @@
package dan200.computercraft.shared.util;
public class StringUtil
{
public static String normaliseLabel( String label )
{
if( label == null ) return null;
int length = Math.min( 32, label.length() );
StringBuilder builder = new StringBuilder( length );
for (int i = 0; i < length; i++)
{
char c = label.charAt( i );
if( (c >= ' ' && c <= '~') || (c >= 161 && c <= 172) || (c >= 174 && c <= 255) )
{
builder.append( c );
}
else
{
builder.append( '?' );
}
}
return builder.toString();
}
}

View File

@ -39,3 +39,20 @@ upgrade.computercraft:advanced_modem.adjective=Ender
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
gui.computercraft:config.http_enable=Enable HTTP API
gui.computercraft:config.http_whitelist=HTTP whitelist
gui.computercraft:config.disable_lua51_features=Disable Lua 5.1 features
gui.computercraft:config.default_computer_settings=Default Computer settings
gui.computercraft:config.enable_command_block=Enable command block peripheral
gui.computercraft:config.modem_range=Modem range (default)
gui.computercraft:config.modem_high_altitude_range=Modem range (high-altitude)
gui.computercraft:config.modem_range_during_storm=Modem range (bad weather)
gui.computercraft:config.modem_high_altitude_range_during_storm=Modem range (high-altitude, bad weather)
gui.computercraft:config.computer_space_limit=Computer space limit (bytes)
gui.computercraft:config.floppy_space_limit=Floppy Disk space limit (bytes)
gui.computercraft:config.turtles_need_fuel=Enable fuel
gui.computercraft:config.turtle_fuel_limit=Turtle fuel limit
gui.computercraft:config.advanced_turtle_fuel_limit=Advanced Turtle fuel limit
gui.computercraft:config.turtles_obey_block_protection=Turtles obey block protection
gui.computercraft:config.turtles_can_push=Turtles can push entities

View File

@ -2,6 +2,7 @@ New Features in ComputerCraft 1.80:
* Added .getResponseHeaders() to HTTP responses.
* Return a HTTP response when a HTTP error occurs.
* Added a GUI to change ComputerCraft config options
New Features in ComputerCraft 1.79:

View File

@ -2,5 +2,6 @@ New Features in ComputerCraft 1.80:
* Added .getResponseHeaders() to HTTP responses.
* Return a HTTP response when a HTTP error occurs.
* Added a GUI to change ComputerCraft config options
Type "help changelog" to see the full version history.