mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 19:20: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:
parent
05d7be0362
commit
ac075d9f53
@ -112,7 +112,8 @@ public class ComputerCraft
|
|||||||
public static boolean disable_lua51_features = false;
|
public static boolean disable_lua51_features = false;
|
||||||
public static String default_computer_settings = "";
|
public static String default_computer_settings = "";
|
||||||
public static boolean debug_enable = true;
|
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 int computer_threads = 1;
|
||||||
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
|
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
|
||||||
|
@ -47,6 +47,7 @@ public final class Config
|
|||||||
private static Property defaultComputerSettings;
|
private static Property defaultComputerSettings;
|
||||||
private static Property debugEnabled;
|
private static Property debugEnabled;
|
||||||
private static Property logComputerErrors;
|
private static Property logComputerErrors;
|
||||||
|
private static Property commandRequireCreative;
|
||||||
|
|
||||||
private static Property computerThreads;
|
private static Property computerThreads;
|
||||||
private static Property maxMainGlobalTime;
|
private static Property maxMainGlobalTime;
|
||||||
@ -119,10 +120,14 @@ public final class Config
|
|||||||
logComputerErrors.setComment( "Log exceptions thrown by peripherals and other Lua objects.\n" +
|
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." );
|
"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(
|
setOrder(
|
||||||
CATEGORY_GENERAL,
|
CATEGORY_GENERAL,
|
||||||
computerSpaceLimit, floppySpaceLimit, maximumFilesOpen,
|
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.default_computer_settings = defaultComputerSettings.getString();
|
||||||
ComputerCraft.debug_enable = debugEnabled.getBoolean();
|
ComputerCraft.debug_enable = debugEnabled.getBoolean();
|
||||||
ComputerCraft.logPeripheralErrors = logComputerErrors.getBoolean();
|
ComputerCraft.logPeripheralErrors = logComputerErrors.getBoolean();
|
||||||
|
ComputerCraft.commandRequireCreative = commandRequireCreative.getBoolean();
|
||||||
|
|
||||||
// Execution
|
// Execution
|
||||||
ComputerCraft.computer_threads = computerThreads.getInt();
|
ComputerCraft.computer_threads = computerThreads.getInt();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.shared.computer.blocks;
|
package dan200.computercraft.shared.computer.blocks;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.computer.apis.CommandAPI;
|
import dan200.computercraft.shared.computer.apis.CommandAPI;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@ -167,6 +168,11 @@ public class TileCommandComputer extends TileComputer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUsable( EntityPlayer player, boolean ignoreRange )
|
public boolean isUsable( EntityPlayer player, boolean ignoreRange )
|
||||||
|
{
|
||||||
|
return isUsable( player ) && super.isUsable( player, ignoreRange );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUsable( EntityPlayer player )
|
||||||
{
|
{
|
||||||
MinecraftServer server = player.getServer();
|
MinecraftServer server = player.getServer();
|
||||||
if( server == null || !server.isCommandBlockEnabled() )
|
if( server == null || !server.isCommandBlockEnabled() )
|
||||||
@ -174,14 +180,12 @@ public class TileCommandComputer extends TileComputer
|
|||||||
player.sendMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
|
player.sendMessage( new TextComponentTranslation( "advMode.notEnabled" ) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if( !player.canUseCommandBlock() )
|
else if( ComputerCraft.commandRequireCreative ? !player.canUseCommandBlock() : !server.getPlayerList().canSendCommands( player.getGameProfile() ) )
|
||||||
{
|
{
|
||||||
player.sendMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
|
player.sendMessage( new TextComponentTranslation( "advMode.notAllowed" ) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return true;
|
||||||
return super.isUsable( player, ignoreRange );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,10 @@
|
|||||||
package dan200.computercraft.shared.computer.inventory;
|
package dan200.computercraft.shared.computer.inventory;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
|
||||||
import dan200.computercraft.shared.computer.core.*;
|
import dan200.computercraft.shared.computer.core.*;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
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 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();
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.default_computer_settings=Default Computer settings
|
||||||
gui.computercraft:config.debug_enabled=Enable debug library
|
gui.computercraft:config.debug_enabled=Enable debug library
|
||||||
gui.computercraft:config.log_computer_errors=Log computer errors
|
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=Execution
|
||||||
gui.computercraft:config.execution.computer_threads=Computer threads
|
gui.computercraft:config.execution.computer_threads=Computer threads
|
||||||
|
Loading…
Reference in New Issue
Block a user