1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-22 01:17:38 +00:00

Allow disabling generic methods

Suddenly so easy as of the refactoring in 910a63214e395ecae6993d8e0487384c725b3dd3!

Closes #1382
This commit is contained in:
Jonathan Coates
2023-07-09 19:58:34 +01:00
parent 7f25c9a66b
commit af3263dec2
6 changed files with 35 additions and 3 deletions

View File

@@ -214,6 +214,7 @@ public final class LanguageProvider implements DataProvider {
addConfigEntry(ConfigSpec.defaultComputerSettings, "Default Computer settings");
addConfigEntry(ConfigSpec.logComputerErrors, "Log computer errors");
addConfigEntry(ConfigSpec.commandRequireCreative, "Command computers require creative");
addConfigEntry(ConfigSpec.disabledGenericMethods, "Disabled generic methods");
addConfigGroup(ConfigSpec.serverSpec, "execution", "Execution");
addConfigEntry(ConfigSpec.computerThreads, "Computer threads");

View File

@@ -6,10 +6,12 @@ package dan200.computercraft.impl;
import dan200.computercraft.api.lua.GenericSource;
import dan200.computercraft.core.asm.GenericMethod;
import dan200.computercraft.shared.config.ConfigSpec;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
/**
* The global registry for {@link GenericSource}s.
@@ -29,6 +31,11 @@ public final class GenericSources {
}
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();
}
}

View File

@@ -35,6 +35,7 @@ public final class ConfigSpec {
public static final ConfigFile.Value<Boolean> logComputerErrors;
public static final ConfigFile.Value<Boolean> commandRequireCreative;
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> maxMainGlobalTime;
@@ -139,6 +140,19 @@ public final class ConfigSpec {
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.""")
.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);
}
{