mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-03 04:39:12 +00:00
Allow disabling generic methods
Suddenly so easy as of the refactoring in 910a63214e395ecae6993d8e0487384c725b3dd3! Closes #1382
This commit is contained in:
parent
7f25c9a66b
commit
af3263dec2
@ -214,6 +214,7 @@ public final class LanguageProvider implements DataProvider {
|
|||||||
addConfigEntry(ConfigSpec.defaultComputerSettings, "Default Computer settings");
|
addConfigEntry(ConfigSpec.defaultComputerSettings, "Default Computer settings");
|
||||||
addConfigEntry(ConfigSpec.logComputerErrors, "Log computer errors");
|
addConfigEntry(ConfigSpec.logComputerErrors, "Log computer errors");
|
||||||
addConfigEntry(ConfigSpec.commandRequireCreative, "Command computers require creative");
|
addConfigEntry(ConfigSpec.commandRequireCreative, "Command computers require creative");
|
||||||
|
addConfigEntry(ConfigSpec.disabledGenericMethods, "Disabled generic methods");
|
||||||
|
|
||||||
addConfigGroup(ConfigSpec.serverSpec, "execution", "Execution");
|
addConfigGroup(ConfigSpec.serverSpec, "execution", "Execution");
|
||||||
addConfigEntry(ConfigSpec.computerThreads, "Computer threads");
|
addConfigEntry(ConfigSpec.computerThreads, "Computer threads");
|
||||||
|
@ -6,10 +6,12 @@ package dan200.computercraft.impl;
|
|||||||
|
|
||||||
import dan200.computercraft.api.lua.GenericSource;
|
import dan200.computercraft.api.lua.GenericSource;
|
||||||
import dan200.computercraft.core.asm.GenericMethod;
|
import dan200.computercraft.core.asm.GenericMethod;
|
||||||
|
import dan200.computercraft.shared.config.ConfigSpec;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global registry for {@link GenericSource}s.
|
* The global registry for {@link GenericSource}s.
|
||||||
@ -29,6 +31,11 @@ public final class GenericSources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<GenericMethod> getAllMethods() {
|
public static Collection<GenericMethod> getAllMethods() {
|
||||||
return sources.stream().flatMap(GenericMethod::getMethods).toList();
|
var disabledMethods = Set.copyOf(ConfigSpec.disabledGenericMethods.get());
|
||||||
|
return sources.stream()
|
||||||
|
.filter(x -> !disabledMethods.contains(x.id()))
|
||||||
|
.flatMap(GenericMethod::getMethods)
|
||||||
|
.filter(x -> !disabledMethods.contains(x.id()))
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ public final class ConfigSpec {
|
|||||||
public static final ConfigFile.Value<Boolean> logComputerErrors;
|
public static final ConfigFile.Value<Boolean> logComputerErrors;
|
||||||
public static final ConfigFile.Value<Boolean> commandRequireCreative;
|
public static final ConfigFile.Value<Boolean> commandRequireCreative;
|
||||||
public static final ConfigFile.Value<Integer> uploadMaxSize;
|
public static final ConfigFile.Value<Integer> uploadMaxSize;
|
||||||
|
public static final ConfigFile.Value<List<? extends String>> disabledGenericMethods;
|
||||||
|
|
||||||
public static final ConfigFile.Value<Integer> computerThreads;
|
public static final ConfigFile.Value<Integer> computerThreads;
|
||||||
public static final ConfigFile.Value<Integer> maxMainGlobalTime;
|
public static final ConfigFile.Value<Integer> maxMainGlobalTime;
|
||||||
@ -139,6 +140,19 @@ public final class ConfigSpec {
|
|||||||
Require players to be in creative mode and be opped in order to interact with
|
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.""")
|
command computers. This is the default behaviour for vanilla's Command blocks.""")
|
||||||
.define("command_require_creative", Config.commandRequireCreative);
|
.define("command_require_creative", Config.commandRequireCreative);
|
||||||
|
|
||||||
|
disabledGenericMethods = builder
|
||||||
|
.comment("""
|
||||||
|
A list of generic methods or method sources to disable. Generic methods are
|
||||||
|
methods added to a block/block entity when there is no explicit peripheral
|
||||||
|
provider. This includes inventory methods (i.e. inventory.getItemDetail,
|
||||||
|
inventory.pushItems), and (if on Forge), the fluid_storage and energy_storage
|
||||||
|
methods.
|
||||||
|
Methods in this list can either be a whole group of methods (computercraft:inventory)
|
||||||
|
or a single method (computercraft:inventory#pushItems).
|
||||||
|
""")
|
||||||
|
.worldRestart()
|
||||||
|
.defineList("disabled_generic_methods", List.of(), x -> x instanceof String);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -24,18 +24,24 @@ import java.util.stream.Stream;
|
|||||||
public final class GenericMethod {
|
public final class GenericMethod {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GenericMethod.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GenericMethod.class);
|
||||||
|
|
||||||
|
final GenericSource source;
|
||||||
final Method method;
|
final Method method;
|
||||||
final LuaFunction annotation;
|
final LuaFunction annotation;
|
||||||
final Class<?> target;
|
final Class<?> target;
|
||||||
final @Nullable PeripheralType peripheralType;
|
final @Nullable PeripheralType peripheralType;
|
||||||
|
|
||||||
private GenericMethod(Method method, LuaFunction annotation, Class<?> target, @Nullable PeripheralType peripheralType) {
|
private GenericMethod(GenericSource source, Method method, LuaFunction annotation, Class<?> target, @Nullable PeripheralType peripheralType) {
|
||||||
|
this.source = source;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.annotation = annotation;
|
this.annotation = annotation;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.peripheralType = peripheralType;
|
this.peripheralType = peripheralType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
return source.id() + "#" + name();
|
||||||
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
return method.getName();
|
return method.getName();
|
||||||
}
|
}
|
||||||
@ -69,7 +75,7 @@ public final class GenericMethod {
|
|||||||
var target = Reflect.getRawType(method, types[0], false);
|
var target = Reflect.getRawType(method, types[0], false);
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|
||||||
return new GenericMethod(method, annotation, target, type);
|
return new GenericMethod(source, method, annotation, target, type);
|
||||||
})
|
})
|
||||||
.filter(Objects::nonNull);
|
.filter(Objects::nonNull);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,8 @@
|
|||||||
"gui.computercraft.config.default_computer_settings.tooltip": "A comma separated list of default system settings to set on new computers.\nExample: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\"\nwill disable all autocompletion.",
|
"gui.computercraft.config.default_computer_settings.tooltip": "A comma separated list of default system settings to set on new computers.\nExample: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\"\nwill disable all autocompletion.",
|
||||||
"gui.computercraft.config.disable_lua51_features": "Disable Lua 5.1 features",
|
"gui.computercraft.config.disable_lua51_features": "Disable Lua 5.1 features",
|
||||||
"gui.computercraft.config.disable_lua51_features.tooltip": "Set this to true to disable Lua 5.1 functions that will be removed in a future\nupdate. Useful for ensuring forward compatibility of your programs now.",
|
"gui.computercraft.config.disable_lua51_features.tooltip": "Set this to true to disable Lua 5.1 functions that will be removed in a future\nupdate. Useful for ensuring forward compatibility of your programs now.",
|
||||||
|
"gui.computercraft.config.disabled_generic_methods": "Disabled generic methods",
|
||||||
|
"gui.computercraft.config.disabled_generic_methods.tooltip": "A list of generic methods or method sources to disable. Generic methods are\nmethods added to a block/block entity when there is no explicit peripheral\nprovider. This includes inventory methods (i.e. inventory.getItemDetail,\ninventory.pushItems), and (if on Forge), the fluid_storage and energy_storage\nmethods.\nMethods in this list can either be a whole group of methods (computercraft:inventory)\nor a single method (computercraft:inventory#pushItems).\n",
|
||||||
"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",
|
||||||
"gui.computercraft.config.execution.computer_threads.tooltip": "Set the number of threads computers can run on. A higher number means more\ncomputers can run at once, but may induce lag. Please note that some mods may\nnot work with a thread count higher than 1. Use with caution.\nRange: > 1",
|
"gui.computercraft.config.execution.computer_threads.tooltip": "Set the number of threads computers can run on. A higher number means more\ncomputers can run at once, but may induce lag. Please note that some mods may\nnot work with a thread count higher than 1. Use with caution.\nRange: > 1",
|
||||||
|
@ -81,6 +81,8 @@
|
|||||||
"gui.computercraft.config.default_computer_settings.tooltip": "A comma separated list of default system settings to set on new computers.\nExample: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\"\nwill disable all autocompletion.",
|
"gui.computercraft.config.default_computer_settings.tooltip": "A comma separated list of default system settings to set on new computers.\nExample: \"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\"\nwill disable all autocompletion.",
|
||||||
"gui.computercraft.config.disable_lua51_features": "Disable Lua 5.1 features",
|
"gui.computercraft.config.disable_lua51_features": "Disable Lua 5.1 features",
|
||||||
"gui.computercraft.config.disable_lua51_features.tooltip": "Set this to true to disable Lua 5.1 functions that will be removed in a future\nupdate. Useful for ensuring forward compatibility of your programs now.",
|
"gui.computercraft.config.disable_lua51_features.tooltip": "Set this to true to disable Lua 5.1 functions that will be removed in a future\nupdate. Useful for ensuring forward compatibility of your programs now.",
|
||||||
|
"gui.computercraft.config.disabled_generic_methods": "Disabled generic methods",
|
||||||
|
"gui.computercraft.config.disabled_generic_methods.tooltip": "A list of generic methods or method sources to disable. Generic methods are\nmethods added to a block/block entity when there is no explicit peripheral\nprovider. This includes inventory methods (i.e. inventory.getItemDetail,\ninventory.pushItems), and (if on Forge), the fluid_storage and energy_storage\nmethods.\nMethods in this list can either be a whole group of methods (computercraft:inventory)\nor a single method (computercraft:inventory#pushItems).\n",
|
||||||
"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",
|
||||||
"gui.computercraft.config.execution.computer_threads.tooltip": "Set the number of threads computers can run on. A higher number means more\ncomputers can run at once, but may induce lag. Please note that some mods may\nnot work with a thread count higher than 1. Use with caution.\nRange: > 1",
|
"gui.computercraft.config.execution.computer_threads.tooltip": "Set the number of threads computers can run on. A higher number means more\ncomputers can run at once, but may induce lag. Please note that some mods may\nnot work with a thread count higher than 1. Use with caution.\nRange: > 1",
|
||||||
|
Loading…
Reference in New Issue
Block a user