Merge pull request 'bug/17-config_list_definitions' (#18) from bug/17-config_list_definitions into 1.20.1

Reviewed-on: #18
This commit is contained in:
2025-06-09 18:43:21 +00:00
2 changed files with 24 additions and 5 deletions

View File

@ -4,7 +4,7 @@ org.gradle.daemon=false
mod_id=xp_tools
mod_name=XP Tools
mod_license=All Rights Reserved
mod_version=1.0.1
mod_version=1.0.2
mod_group_id=dev.micle
mod_authors=Micle
mod_description=Minecraft Forge mod for tweaking various things about XP in Minecraft. Primarily targeted at modpack developers.

View File

@ -13,6 +13,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent;
import org.apache.commons.lang3.tuple.Pair;
import java.util.*;
import java.util.stream.Collectors;
@Mod.EventBusSubscriber(modid = XpTools.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public final class Config {
@ -104,13 +105,13 @@ public final class Config {
.comment("Global operations are run before any unique operations.")
.comment("Examples:")
.comment("'set,0,0,0' - Sets the xp of all blocks to 0.")
.define("blockBreakGlobalOperations", new ArrayList<>());
.defineList("blockBreakGlobalOperations", List.of(), Server::isValidGlobalOperationEntry);
blockBreakOperationsRaw = builder
.comment("List of unique operations. Format: '[block_id/tag_id],[operation],[min],[max],[priority],[is_last]'")
.comment("Examples:")
.comment("'minecraft:dirt,set,2,2,0,true' - Sets the xp drop of the dirt block to 2, takes highest priority and stops any additional operations.")
.comment("'#forge:ores,multiply,1,2,1,false' - Multiplies xp drop of all blocks tagged forge:ores by 1-2, allows additional operations.")
.define("blockBreakOperations", new ArrayList<>());
.defineList("blockBreakOperations", List.of(), Server::isValidOperationEntry);
builder.pop();
builder.comment("Settings for entity killing").push("entity_killing");
@ -120,13 +121,13 @@ public final class Config {
.comment("Global operations are run before any unique operations.")
.comment("Examples:")
.comment("'set,0,0,0' - Sets the xp of all entities to 0.")
.define("entityKillGlobalOperations", new ArrayList<>());
.defineList("entityKillGlobalOperations", List.of(), Server::isValidGlobalOperationEntry);
entityKillOperationsRaw = builder
.comment("List of unique operations. Format: '[entity_id/tag_id],[operation],[min],[max],[priority],[is_last]'")
.comment("Examples:")
.comment("'minecraft:creeper,set,2,2,0,true' - Sets the xp drop for killing creepers to 2, takes highest priority and stops any additional operations.")
.comment("'#some_mod:some_tag,multiply,1,2,1,false' - Multiplies the xp drop for killing all entities tagged some_mod:some_tag by 1-2, allows additional operations.")
.define("entityKillOperations", new ArrayList<>());
.defineList("entityKillOperations", List.of(), Server::isValidOperationEntry);
builder.pop();
}
@ -161,5 +162,23 @@ public final class Config {
entityKillOperationItems.add(OperationItem.fromConfig(s));
}
}
private static boolean isValidGlobalOperationEntry(Object entry) {
return entry instanceof String && ((String) entry).matches(
String.format(
"(?i)^(%s),(\\d*\\.?\\d+),(\\d*\\.?\\d+),(\\d+)$",
Arrays.stream(OperationType.values()).map(OperationType::toString).collect(Collectors.joining("|"))
)
);
}
private static boolean isValidOperationEntry(Object entry) {
return entry instanceof String && ((String) entry).matches(
String.format(
"(?i)^(\\#?\\w+:[\\w\\/]+),(%s),(\\d*\\.?\\d+),(\\d*\\.?\\d+),(\\d+),(TRUE|FALSE)$",
Arrays.stream(OperationType.values()).map(OperationType::toString).collect(Collectors.joining("|"))
)
);
}
}
}