-
Notifications
You must be signed in to change notification settings - Fork 1
ConfigObject
kr1viah_ edited this page Feb 18, 2026
·
5 revisions
ConfigObject is a class that makes adding simple new config types easier.
Note: @PopupConfig does not work. Use a nested ConfigObject instead.
How to use:
// define a class to use as the object
static class BlockPosConfig {
// define some config options (note: *not* static)
public final ConfigIntegerPlus x = new ConfigIntegerPlus("x");
public final ConfigIntegerPlus y = new ConfigIntegerPlus("y");
public final ConfigIntegerPlus z = new ConfigIntegerPlus("z");
// only types that extend IConfigBase and IConfigResettable (aka most normal configs) will get picked up
public final String thing = "Block: ";
// can just define normal methods and such here
public BlockPos get() {
return new BlockPos(x.getIntegerValue(), y.getIntegerValue(), z.getIntegerValue());
}
// ConfigObject#toString points to this toString, so define a toString here so it isn't garbage
// not necessary if you use a configDisplayName
@Override
public String toString() {
return thing + get().toString();
}
}
// define the actual config. here a list is used, because otherwise this would've been easier with @PopupConfig
static final ConfigList<ConfigObject<BlockPosConfig>> BLOCKS = new ConfigList<>("Block positions", () -> new ConfigObject<>("", /*the instance to use for configs: */new BlockPosConfig(), ""));
// basic usage
static final ConfigHotkeyPlus PRINT_KEY = new ConfigHotkeyPlus("Print blocks", (action, key) -> {
for (ConfigObject<BlockPosConfig> config : BLOCKS.getList()) {
BlockPosConfig blockConfig = config.get();
BlockPos pos = blockConfig.get();
System.out.println(pos);
}
return true;
});In game: