diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 3b1ce7495..f11c8adf4 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -7,6 +7,7 @@ package dan200.computercraft; import com.google.common.base.CaseFormat; +import com.google.common.base.Converter; import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.media.IMedia; @@ -18,6 +19,7 @@ import dan200.computercraft.api.permissions.ITurtlePermissionProvider; import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.turtle.ITurtleUpgrade; +import dan200.computercraft.api.turtle.event.TurtleAction; import dan200.computercraft.core.apis.AddressPredicate; import dan200.computercraft.core.filesystem.ComboMount; import dan200.computercraft.core.filesystem.FileMount; @@ -81,10 +83,7 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -133,6 +132,7 @@ public class ComputerCraft public static int advancedTurtleFuelLimit = 100000; public static boolean turtlesObeyBlockProtection = true; public static boolean turtlesCanPush = true; + public static EnumSet turtleDisabledActions = EnumSet.noneOf( TurtleAction.class ); public static final int terminalWidth_computer = 51; public static final int terminalHeight_computer = 19; @@ -212,6 +212,7 @@ public class ComputerCraft public static Property advancedTurtleFuelLimit; public static Property turtlesObeyBlockProtection; public static Property turtlesCanPush; + public static Property turtleDisabledActions; public static Property modem_range; public static Property modem_highAltitudeRange; @@ -341,6 +342,9 @@ 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.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" ); @@ -385,6 +389,20 @@ public class ComputerCraft turtlesObeyBlockProtection = Config.turtlesObeyBlockProtection.getBoolean(); turtlesCanPush = Config.turtlesCanPush.getBoolean(); + turtleDisabledActions.clear(); + Converter converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE ); + for( String value : Config.turtleDisabledActions.getStringList() ) + { + try + { + turtleDisabledActions.add( TurtleAction.valueOf( converter.convert( value ) ) ); + } + catch( IllegalArgumentException e ) + { + ComputerCraft.log.error( "Unknown turtle action " + value ); + } + } + maxNotesPerTick = Math.max(1, Config.maxNotesPerTick.getInt()); Config.config.save(); diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index 53e80563a..a5e20eab0 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -8,6 +8,7 @@ package dan200.computercraft.shared.proxy; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleUpgrade; +import dan200.computercraft.api.turtle.event.TurtleActionEvent; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle; @@ -465,6 +466,14 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy { dispatchEntityDrops( event.getEntity(), event.getDrops() ); } + + @SubscribeEvent + public void onTurtleAction( TurtleActionEvent event) { + if( ComputerCraft.turtleDisabledActions.contains( event.getAction() ) ) + { + event.setCanceled( true, "Action has been disabled" ); + } + } } private void dispatchEntityDrops( Entity entity, java.util.List drops ) diff --git a/src/main/resources/assets/computercraft/lang/en_us.lang b/src/main/resources/assets/computercraft/lang/en_us.lang index edc0b8a0d..cbc347bea 100644 --- a/src/main/resources/assets/computercraft/lang/en_us.lang +++ b/src/main/resources/assets/computercraft/lang/en_us.lang @@ -60,5 +60,6 @@ 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 +gui.computercraft:config.turtle_disabled_actions=Disabled turtle actions gui.computercraft:config.maximum_files_open=Maximum files open per computer gui.computercraft:config.max_notes_per_tick=Maximum notes that a computer can play at once