use of net.minecraftforge.common.ForgeConfigSpec in project Shrines by Silverminer007.
the class GeneralSettingsScreen method init.
@Override
public void init(Minecraft mc, int width, int height) {
super.init(mc, width, height);
int titleHeight = mc.font.wordWrapHeight(title.getString(), width - 2 * PADDING);
int paddedTitleHeight = titleHeight + PADDING * 2;
addButton(width - 120 - 2 * PADDING, 0, 60, paddedTitleHeight, new StringTextComponent("Back"), button -> mc.setScreen(parent));
addButton(width - 60 - PADDING, 0, 60, paddedTitleHeight, new StringTextComponent("Save"), button -> {
this.optionList.commitChanges();
for (ForgeConfigSpec spec : configSpecs) spec.save();
mc.setScreen(parent);
});
int optionListHeaderHeight = titleHeight + 2 * PADDING;
this.optionList = new ModOptionList(configSpecs, minecraft, width, height, optionListHeaderHeight, height - optionListHeaderHeight, 26);
this.children.add(optionList);
}
use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.
the class CConfigureConfigPacket method handle.
@Override
public void handle(Supplier<NetworkEvent.Context> context) {
context.get().enqueueWork(() -> {
try {
ServerPlayer sender = context.get().getSender();
if (sender == null || !sender.hasPermissions(2))
return;
ForgeConfigSpec spec = ConfigHelper.findForgeConfigSpecFor(ModConfig.Type.SERVER, modID);
if (spec == null)
return;
ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(path);
ForgeConfigSpec.ConfigValue<T> configValue = spec.getValues().get(path);
T v = (T) deserialize(configValue.get(), value);
if (!valueSpec.test(v))
return;
configValue.set(v);
} catch (Exception e) {
Create.LOGGER.warn("Unable to handle ConfigureConfig Packet. ", e);
}
});
context.get().setPacketHandled(true);
}
use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.
the class ConfigHelper method setConfigValue.
// Directly set a value
public static <T> void setConfigValue(ConfigPath path, String value) throws InvalidValueException {
ForgeConfigSpec spec = findForgeConfigSpecFor(path.getType(), path.getModID());
if (spec == null)
return;
List<String> pathList = Arrays.asList(path.getPath());
ForgeConfigSpec.ValueSpec valueSpec = spec.getRaw(pathList);
ForgeConfigSpec.ConfigValue<T> configValue = spec.getValues().get(pathList);
T v = (T) CConfigureConfigPacket.deserialize(configValue.get(), value);
if (!valueSpec.test(v))
throw new InvalidValueException();
configValue.set(v);
}
use of net.minecraftforge.common.ForgeConfigSpec in project Create by Creators-of-Create.
the class SubMenuConfigScreen method find.
public static SubMenuConfigScreen find(ConfigHelper.ConfigPath path) {
// TODO 1.17: can be null
ForgeConfigSpec spec = ConfigHelper.findForgeConfigSpecFor(path.getType(), path.getModID());
UnmodifiableConfig values = spec.getValues();
BaseConfigScreen base = new BaseConfigScreen(null, path.getModID());
SubMenuConfigScreen screen = new SubMenuConfigScreen(base, "root", path.getType(), spec, values);
List<String> remainingPath = Lists.newArrayList(path.getPath());
path: while (!remainingPath.isEmpty()) {
String next = remainingPath.remove(0);
for (Map.Entry<String, Object> entry : values.valueMap().entrySet()) {
String key = entry.getKey();
Object obj = entry.getValue();
if (!key.equalsIgnoreCase(next))
continue;
if (!(obj instanceof AbstractConfig)) {
// highlight entry
screen.highlights.add(path.getPath()[path.getPath().length - 1]);
continue;
}
values = (UnmodifiableConfig) obj;
screen = new SubMenuConfigScreen(screen, toHumanReadable(key), path.getType(), spec, values);
continue path;
}
break;
}
ConfigScreen.modID = path.getModID();
return screen;
}
use of net.minecraftforge.common.ForgeConfigSpec in project artifacts by ochotonida.
the class ModConfig method registerClient.
public static void registerClient() {
Pair<ClientConfig, ForgeConfigSpec> clientSpecPair = new ForgeConfigSpec.Builder().configure(ClientConfig::new);
ForgeConfigSpec clientSpec = clientSpecPair.getRight();
client = clientSpecPair.getLeft();
ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.CLIENT, clientSpec);
}
Aggregations