Skip to content

Commit

Permalink
Add always off option
Browse files Browse the repository at this point in the history
  • Loading branch information
Kotori316 committed Aug 29, 2024
1 parent bd8960c commit 32a56ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 13 additions & 4 deletions common/src/main/java/com/yogpc/qp/config/EnableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public EnableMap() {
}

public boolean enabled(String name) {
if (PlatformAccess.getAccess().registerObjects() != null &&
PlatformAccess.getAccess().registerObjects().defaultEnableSetting().get(name) == EnableOrNot.ALWAYS_ON) {
var defaultSetting = getDefaultValue(name);
if (defaultSetting == EnableOrNot.ALWAYS_ON) {
return true;
}
if (defaultSetting == EnableOrNot.ALWAYS_OFF) {
return false;
}
var value = machinesMap.get(name);
if (value == null) {
return false;
Expand Down Expand Up @@ -55,11 +58,17 @@ static EnableMap from(Map<String, Object> config) {
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}

static EnableOrNot getDefaultValue(String name) {
if (PlatformAccess.getAccess().registerObjects() != null) return null;

return PlatformAccess.getAccess().registerObjects().defaultEnableSetting().get(name);
}

public enum EnableOrNot {
CONFIG_ON, CONFIG_OFF, ALWAYS_ON;
CONFIG_ON, CONFIG_OFF, ALWAYS_ON, ALWAYS_OFF;

public boolean configurable() {
return this == CONFIG_ON || this == CONFIG_OFF;
return this == CONFIG_ON || this == CONFIG_OFF || this == ALWAYS_OFF;
}

public boolean on() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ static void registerAll() {
registerEntityBlock(FLEXIBLE_MARKER_BLOCK, FLEXIBLE_MARKER_ENTITY_TYPE, EnableMap.EnableOrNot.CONFIG_ON);
registerEntityBlock(CHUNK_MARKER_BLOCK, CHUNK_MARKER_ENTITY_TYPE, EnableMap.EnableOrNot.CONFIG_ON);
// Module
registerItem(PUMP_MODULE_ITEM, EnableMap.EnableOrNot.CONFIG_OFF);
registerItem(PUMP_MODULE_ITEM, EnableMap.EnableOrNot.ALWAYS_OFF);
registerItem(BEDROCK_MODULE_ITEM, EnableMap.EnableOrNot.CONFIG_OFF);
registerItem(EXP_MODULE_ITEM, EnableMap.EnableOrNot.CONFIG_OFF);
registerItem(REPEAT_TICK_MODULE_ITEM, EnableMap.EnableOrNot.CONFIG_OFF);
registerItem(EXP_MODULE_ITEM, EnableMap.EnableOrNot.ALWAYS_OFF);
registerItem(REPEAT_TICK_MODULE_ITEM, EnableMap.EnableOrNot.ALWAYS_OFF);
// Misc
registerItem(CHECKER_ITEM, EnableMap.EnableOrNot.ALWAYS_ON);
registerItem(Y_SET_ITEM, EnableMap.EnableOrNot.ALWAYS_ON);
Expand Down Expand Up @@ -306,11 +306,6 @@ public void onServerStopped(MinecraftServer server) {
}

private QuarryConfig modified() {
var config = QuarryConfig.load(configPath(), this::isInDevelopmentEnvironment);
var enableMap = config.enableMap();
enableMap.set(PumpModuleItem.NAME, false);
enableMap.set(ExpModuleItem.NAME, false);
enableMap.set(RepeatTickModuleItem.NAME, false);
return config;
return QuarryConfig.load(configPath(), this::isInDevelopmentEnvironment);
}
}

0 comments on commit 32a56ca

Please sign in to comment.