1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Allow using command computers in survival mode

I'm really not a fan of this change, but it's gated behind a config
option and there's apparently sufficient demand that it's worthwhile.
Closes #442.
This commit is contained in:
SquidDev 2020-05-13 10:26:59 +01:00
parent 05d7be0362
commit ac075d9f53
5 changed files with 22 additions and 21 deletions

View File

@ -112,7 +112,8 @@ public class ComputerCraft
public static boolean disable_lua51_features = false;
public static String default_computer_settings = "";
public static boolean debug_enable = true;
public static boolean logPeripheralErrors = false;
public static boolean logPeripheralErrors = true;
public static boolean commandRequireCreative = true;
public static int computer_threads = 1;
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );

View File

@ -47,6 +47,7 @@ public final class Config
private static Property defaultComputerSettings;
private static Property debugEnabled;
private static Property logComputerErrors;
private static Property commandRequireCreative;
private static Property computerThreads;
private static Property maxMainGlobalTime;
@ -119,10 +120,14 @@ public final class Config
logComputerErrors.setComment( "Log exceptions thrown by peripherals and other Lua objects.\n" +
"This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods." );
commandRequireCreative = config.get( CATEGORY_GENERAL, "command_require_creative", ComputerCraft.commandRequireCreative );
commandRequireCreative.setComment( "Require players to be in creative mode and be opped in order to interact with command computers." +
"This is the default behaviour for vanilla's Command blocks." );
setOrder(
CATEGORY_GENERAL,
computerSpaceLimit, floppySpaceLimit, maximumFilesOpen,
disableLua51Features, defaultComputerSettings, debugEnabled, logComputerErrors
disableLua51Features, defaultComputerSettings, debugEnabled, logComputerErrors, commandRequireCreative
);
}
@ -441,6 +446,7 @@ public final class Config
ComputerCraft.default_computer_settings = defaultComputerSettings.getString();
ComputerCraft.debug_enable = debugEnabled.getBoolean();
ComputerCraft.logPeripheralErrors = logComputerErrors.getBoolean();
ComputerCraft.commandRequireCreative = commandRequireCreative.getBoolean();
// Execution
ComputerCraft.computer_threads = computerThreads.getInt();

View File

@ -5,6 +5,7 @@
*/
package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.apis.CommandAPI;
import dan200.computercraft.shared.computer.core.ServerComputer;
import io.netty.buffer.ByteBuf;
@ -167,6 +168,11 @@ public class TileCommandComputer extends TileComputer
@Override
public boolean isUsable( EntityPlayer player, boolean ignoreRange )
{
return isUsable( player ) && super.isUsable( player, ignoreRange );
}
public static boolean isUsable( EntityPlayer player )
{
MinecraftServer server = player.getServer();
if( server == null || !server.isCommandBlockEnabled() )
@ -174,14 +180,12 @@ public class TileCommandComputer extends TileComputer
player.sendMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
return false;
}
else if( !player.canUseCommandBlock() )
else if( ComputerCraft.commandRequireCreative ? !player.canUseCommandBlock() : !server.getPlayerList().canSendCommands( player.getGameProfile() ) )
{
player.sendMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
return false;
}
else
{
return super.isUsable( player, ignoreRange );
}
return true;
}
}

View File

@ -6,11 +6,10 @@
package dan200.computercraft.shared.computer.inventory;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
import dan200.computercraft.shared.computer.core.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentTranslation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -46,19 +45,9 @@ public class ContainerViewComputer extends Container implements IContainerComput
}
// If we're a command computer then ensure we're in creative
if( serverComputer.getFamily() == ComputerFamily.Command )
if( serverComputer.getFamily() == ComputerFamily.Command && !TileCommandComputer.isUsable( player ) )
{
MinecraftServer server = player.getServer();
if( server == null || !server.isCommandBlockEnabled() )
{
player.sendMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
return false;
}
else if( !player.canUseCommandBlock() )
{
player.sendMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
return false;
}
return false;
}
}

View File

@ -159,6 +159,7 @@ gui.computercraft:config.disable_lua51_features=Disable Lua 5.1 features
gui.computercraft:config.default_computer_settings=Default Computer settings
gui.computercraft:config.debug_enabled=Enable debug library
gui.computercraft:config.log_computer_errors=Log computer errors
gui.computercraft:config.command_require_creative=Command computers require creative
gui.computercraft:config.execution=Execution
gui.computercraft:config.execution.computer_threads=Computer threads