Search in sources :

Example 11 with Configuration

use of net.minecraftforge.common.config.Configuration in project RecurrentComplex by Ivorforce.

the class RCConfig method loadConfig.

public static void loadConfig(String configID) {
    Configuration config = RecurrentComplex.config;
    if (configID == null || configID.equals(CATEGORY_GENERAL)) {
        lightweightMode = config.getBoolean("lightweightMode", CATEGORY_GENERAL, false, "Enabling this will make the mod register as little as possible, which enables it to be used server-side only. Note that this prevents you from editing or importing structures.");
        commandPrefix = config.getString("commandPrefix", CATEGORY_GENERAL, "#", "The String that will be prefixed to every command, e.g. '#' -> '/#gen', '#paste' etc.");
        commandMatchers.clear();
        parseMap(config.getStringList("commandMatchers", CATEGORY_GENERAL, new String[0], "List of Command Expressions determining if a command can be executed. Example: #export:#3 | $Ivorforce"), null, Function.identity(), "command matcher", (expression) -> ExpressionCache.of(new CommandExpression(), expression), commandMatchers::put);
        asCommandPermissionLevel = config.getInt("asCommandPermissionLevel", CATEGORY_DECORATION, 4, -1, 10, "The required permission level for /#as to function. Set to 2 for command blocks and OPs, 4 for only server, or -1 to disable. Note that this could be a security problem on low levels.");
        savePlayerCache = config.getBoolean("savePlayerCache", CATEGORY_GENERAL, true, "Whether player caches like the clipboard and previewed operations will be saved and loaded.");
        notifyAdminOnBlockCommands = config.getBoolean("notifyAdminOnBlockCommands", CATEGORY_GENERAL, false, "Disabling this will prevent spawn command blocks from notifying the server admins, as normal commands would.");
        postWorldStatus = config.getBoolean("postWorldStatus", CATEGORY_GENERAL, true, "Once per world, post the status of ReC to the admins.");
        memorizeDecoration = config.getBoolean("memorizeDecoration", CATEGORY_GENERAL, false, "Memorize decoration spawns like trees or mushrooms (for /#whatisthis). Since decoration is so common, it is recommended to use this only for debugging / balancing purposes.");
        memorizeSaplings = config.getBoolean("memorizeSaplings", CATEGORY_GENERAL, false, "Memorize sapling spawns (for /#whatisthis). Since saplings are so common, it is recommended to use this only for debugging / balancing purposes.");
    }
    if (configID == null || configID.equals(CATEGORY_BALANCING)) {
        avoidOverlappingGeneration = config.getBoolean("avoidOverlappingGeneration", CATEGORY_BALANCING, true, "Enabling this will cancel any structure generation if another structure is present at the cooridnate already.");
        honorStructureGenerationOption = config.getBoolean("honorStructureGenerationOption", CATEGORY_BALANCING, true, "If disabled, Recurrent Complex will generate structures in worlds without the structure generation option.");
        generateNature = config.getBoolean("generateNature", CATEGORY_BALANCING, true, "Whether the nature (e.g. trees, mushrooms) added by the mod should be actively generating.");
        minDistToSpawnForGeneration = config.getFloat("minDistToSpawnForGeneration", CATEGORY_BALANCING, 30.0f, 0.0f, 500.0f, "Within this block radius, default structures won't spawn (in the main dimension).");
        structureSpawnChanceModifier = config.getFloat("structureSpawnChance", CATEGORY_BALANCING, 1.0f, 0.0f, 10.0f, "How often do structures spawn?");
        spawnTweaks.clear();
        parseMap(config.getStringList("spawnTweaks", CATEGORY_GENERAL, new String[0], "List of spawn chance tweaks to structures: IceThorn:0.5"), null, Function.identity(), "spawn tweak float", Floats::tryParse, spawnTweaks::put);
        structureLoadMatcher.setExpression(config.getString("structureLoadMatcher", CATEGORY_BALANCING, "", "Resource Expression that will be applied to each loading structure, determining if it should be loaded."));
        logExpressionException(structureLoadMatcher, "structureLoadMatcher", RecurrentComplex.logger);
        structureGenerationMatcher.setExpression(config.getString("structureGenerationMatcher", CATEGORY_BALANCING, "", "Resource Expression that will be applied to each loading structure, determining if it should be set to 'active'."));
        logExpressionException(structureGenerationMatcher, "structureGenerationMatcher", RecurrentComplex.logger);
        inventoryGeneratorLoadMatcher.setExpression(config.getString("inventoryGeneratorLoadMatcher", CATEGORY_BALANCING, "", "Resource Expression that will be applied to each loading inventory generator, determining if it should be loaded."));
        logExpressionException(inventoryGeneratorLoadMatcher, "inventoryGeneratorLoadMatcher", RecurrentComplex.logger);
        inventoryGeneratorGenerationMatcher.setExpression(config.getString("inventoryGeneratorGenerationMatcher", CATEGORY_BALANCING, "", "Resource Expression that will be applied to each loading inventory generator, determining if it should be set to 'active'."));
        logExpressionException(inventoryGeneratorGenerationMatcher, "inventoryGeneratorGenerationMatcher", RecurrentComplex.logger);
        universalBiomeExpression.setExpression(config.getString("universalBiomeMatcher", CATEGORY_BALANCING, "", "Biome Expression that will be checked for every single structure. Use this if you want to blacklist / whitelist specific biomes that shouldn't have structures."));
        logExpressionException(universalBiomeExpression, "universalBiomeMatcher", RecurrentComplex.logger);
        universalDimensionExpression.setExpression(config.getString("universalDimensionMatcher", CATEGORY_BALANCING, "", "Dimension Expression that will be checked for every single structure. Use this if you want to blacklist / whitelist specific dimensions that shouldn't have structures."));
        logExpressionException(universalDimensionExpression, "universalDimensionMatcher", RecurrentComplex.logger);
        customArtifactTag = Pair.of(config.getString("customArtifactTag", CATEGORY_BALANCING, "", "Custom Inventory Generator to override when an artifact generation tag fires."), config.getFloat("customArtifactChance", CATEGORY_BALANCING, 0.0f, 0, 1, "Chance to use the customArtifactTag when an artifact generation tag fires."));
        customBookTag = Pair.of(config.getString("customBookTag", CATEGORY_BALANCING, "", "Custom Inventory Generator to override when a book generation tag fires."), config.getFloat("customBookChance", CATEGORY_BALANCING, 0.0f, 0, 1, "Chance to use the customArtifactTag when a book generation tag fires."));
        mazePlacementReversesPerRoom = config.getFloat("mazePlacementReversesPerRoom", CATEGORY_BALANCING, 3, -1, 100, "Maximum number of reverses per room the maze generator can do. A higher number results in a better generation success rate, but may freeze the server temporarily.");
        universalTransformer = null;
        Collections.addAll(universalTransformerPresets, config.getStringList("universalTransformerPresets", CATEGORY_BALANCING, new String[0], "Transformer preset names that are gonna be applied to every single generating structure. Use this if you need to enforce specific rules (e.g. \"don't ever spawn wood blocks\" (with a replace transformer)."));
        globalToggles.clear();
        parseMap(config.getStringList("globalToggles", CATEGORY_BALANCING, new String[] { "treeLeavesDecay: true" }, "Global toggles that can be used in expressions. You can also add your own. Ex: 'treeLeavesDecay: true'."), null, Function.identity(), "global toggle boolean", Boolean::valueOf, globalToggles::put);
    }
    if (configID == null || configID.equals(CATEGORY_DECORATION)) {
        baseVillageSpawnWeight = config.getInt("baseVillageSpawnWeight", CATEGORY_DECORATION, 10, 0, 100000, "The base weight of RC village generation types. Vanilla average is about 10 - if you want to fully replace vanilla structures in villages, crank this up to something big.");
        saplingTriggerChance = config.getFloat("saplingTriggerChance", CATEGORY_DECORATION, 1f, 0, 1, "The chance to trigger any special sapling spawns at all. If you want to disable the big trees, set this to 0.");
        baseSaplingSpawnWeight = config.getFloat("baseSaplingSpawnWeight", CATEGORY_DECORATION, 0.2f, 0, 100000, "The base weight of RC sapling generation types. The vanilla tree weight is 1 - if you want to fully replace vanilla trees, crank this up to something big.");
        baseDecorationWeights.clear();
        for (RCBiomeDecorator.DecorationType decorationType : RCBiomeDecorator.DecorationType.values()) baseDecorationWeights.put(decorationType, config.getFloat("baseWeight_" + decorationType.id(), CATEGORY_DECORATION, 0.2f, 0, 1000, "The base weight of this decoration type. The vanilla decorator has a weight of 1 - if you want to fully replace vanilla decoration, crank this up to something big."));
    }
    RecurrentComplex.proxy.loadConfig(configID);
}
Also used : RCBiomeDecorator(ivorius.reccomplex.world.gen.feature.decoration.RCBiomeDecorator) Configuration(net.minecraftforge.common.config.Configuration) CommandExpression(ivorius.reccomplex.utils.expression.CommandExpression) Floats(com.google.common.primitives.Floats)

Example 12 with Configuration

use of net.minecraftforge.common.config.Configuration in project SecurityCraft by Geforce132.

the class mod_SecurityCraft method preInit.

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
    log("Starting to load....");
    log("Loading config file....");
    log(mod_SecurityCraft.VERSION + " of SecurityCraft is for a post MC-1.6.4 version! Configuration files are useless for setting anything besides options.");
    mod_SecurityCraft.configFile = new Configuration(event.getSuggestedConfigurationFile());
    mod_SecurityCraft.configHandler.setupConfiguration();
    log("Config file loaded.");
    log("Setting up handlers!");
    mod_SecurityCraft.configHandler.setupHandlers(event);
    log("Handlers registered.");
    log("Setting up network....");
    mod_SecurityCraft.network = NetworkRegistry.INSTANCE.newSimpleChannel(mod_SecurityCraft.MODID);
    mod_SecurityCraft.configHandler.setupPackets(mod_SecurityCraft.network);
    log("Network setup.");
    log("Loading mod additions....");
    mod_SecurityCraft.configHandler.setupAdditions();
    if (mod_SecurityCraft.debuggingMode) {
        mod_SecurityCraft.configHandler.setupDebugAdditions();
    }
    log("Finished loading mod additions.");
    log("Doing registering stuff... (PT 1/2)");
    mod_SecurityCraft.configHandler.setupGameRegistry();
    mod_SecurityCraft.serverProxy.setupTextureRegistry();
    serverProxy.registerTextureFiles();
    ModMetadata modMeta = event.getModMetadata();
    modMeta.authorList = Arrays.asList(new String[] { "Geforce, bl4ckscor3" });
    modMeta.autogenerated = false;
    modMeta.credits = "Thanks to all of you guys for your support!";
    modMeta.description = "Adds a load of things to keep your house safe with.\nIf you like this mod, hit the green arrow\nin the corner of the forum thread!\nPlease visit the URL above for help. \n \nMessage of the update: \n" + MOTU;
    modMeta.url = "http://geforcemods.net";
    modMeta.logoFile = "/scLogo.png";
}
Also used : Configuration(net.minecraftforge.common.config.Configuration) ModMetadata(net.minecraftforge.fml.common.ModMetadata) EventHandler(net.minecraftforge.fml.common.Mod.EventHandler) ForgeEventHandler(net.geforcemods.securitycraft.handlers.ForgeEventHandler)

Example 13 with Configuration

use of net.minecraftforge.common.config.Configuration in project AgriCraft by AgriCraft.

the class CoreHandler method preInit.

public static void preInit(FMLPreInitializationEvent event) {
    // Setup Config.
    configDir = event.getSuggestedConfigurationFile().getParentFile().toPath().resolve(Reference.MOD_ID);
    config = new Configuration(configDir.resolve("config.cfg").toFile());
    // Setup Plant Dir.
    jsonDir = configDir.resolve("json");
    defaultDir = jsonDir.resolve("defaults");
    // Setup Provider
    AgriConfigAdapter provider = new ModProvider(config);
    MinecraftForge.EVENT_BUS.register(provider);
    // Initialize AgriCore
    AgriCore.init(new ModLogger(), new ModTranslator(), new ModValidator(), new ModConverter(), provider);
    // Transfer Defaults
    ResourceHelper.findResources(JSON_FILE_PATTERN.asPredicate()).stream().filter(AGRI_FOLDER_PATTERN.asPredicate()).forEach(r -> ResourceHelper.copyResource(r, configDir.resolve(r), false));
    // Load the JSON files.
    loadJsons();
}
Also used : Configuration(net.minecraftforge.common.config.Configuration) AgriConfigAdapter(com.agricraft.agricore.config.AgriConfigAdapter)

Example 14 with Configuration

use of net.minecraftforge.common.config.Configuration in project malmo by Microsoft.

the class ClientStateMachine method initialiseComms.

/**
 * Set up the mission poller.<br>
 * This is called during the initialisation episode, but also needs to be
 * available for other episodes in case the configuration changes, resulting
 * in changes to the ports.
 *
 * @throws UnknownHostException
 */
protected void initialiseComms() throws UnknownHostException {
    // Start polling for missions:
    if (this.missionPoller != null) {
        this.missionPoller.stopServer();
    }
    this.missionPoller = new TCPInputPoller(AddressHelper.getMissionControlPortOverride(), AddressHelper.MIN_MISSION_CONTROL_PORT, AddressHelper.MAX_FREE_PORT, "mcp") {

        @Override
        public void onError(String error, DataOutputStream dos) {
            System.out.println("SENDING ERROR: " + error);
            try {
                dos.writeInt(error.length());
                dos.writeBytes(error);
            } catch (IOException e) {
            }
        }

        private void reply(String reply, DataOutputStream dos) {
            System.out.println("REPLYING WITH: " + reply);
            try {
                dos.writeInt(reply.length());
                dos.writeBytes(reply);
            } catch (IOException e) {
                System.out.println("Failed to reply to message!");
            }
        }

        @Override
        public boolean onCommand(String command, String ipFrom, DataOutputStream dos) {
            System.out.println("Received from " + ipFrom + ":");
            System.out.println(command.substring(0, Math.min(command.length(), 1024)));
            boolean keepProcessing = false;
            // Possible commands:
            // 1: MALMO_REQUEST_CLIENT:<malmo version>:<reservation_length(ms)><experiment_id>
            // 2: MALMO_CANCEL_REQUEST
            // 3: MALMO_FIND_SERVER<experiment_id>
            // 4: MALMO_KILL_CLIENT
            // 5: MissionInit
            String reservePrefixGeneral = "MALMO_REQUEST_CLIENT:";
            String reservePrefix = reservePrefixGeneral + Loader.instance().activeModContainer().getVersion() + ":";
            String findServerPrefix = "MALMO_FIND_SERVER";
            String cancelRequestCommand = "MALMO_CANCEL_REQUEST";
            String killClientCommand = "MALMO_KILL_CLIENT";
            if (command.startsWith(reservePrefix)) {
                // Reservation request.
                // We either reply with MALMOOK, if we are free, or MALMOBUSY if not.
                IState currentState = getStableState();
                if (currentState != null && currentState.equals(ClientState.DORMANT) && !isReserved()) {
                    reserveClient(command.substring(reservePrefix.length()));
                    reply("MALMOOK", dos);
                } else {
                    // We're busy - we can't be reserved.
                    reply("MALMOBUSY", dos);
                }
            } else if (command.startsWith(reservePrefixGeneral)) {
                // Reservation request, but it didn't match the request we expect, above.
                // This happens if the agent sending the request is running a different version of Malmo -
                // a version mismatch error.
                reply("MALMOERRORVERSIONMISMATCH in reservation string (Got " + command + ", expected " + reservePrefix + " - check your path for old versions of MalmoPython/MalmoJava/Malmo.lib etc)", dos);
            } else if (command.equals(cancelRequestCommand)) {
                // If we've been reserved, cancel the reservation.
                if (isReserved()) {
                    cancelReservation();
                    reply("MALMOOK", dos);
                } else {
                    // We weren't reserved in the first place - something is odd.
                    reply("MALMOERRORAttempt to cancel a reservation that was never made.", dos);
                }
            } else if (command.startsWith(findServerPrefix)) {
                // Request to find the server for the given experiment ID.
                String expID = command.substring(findServerPrefix.length());
                if (currentMissionInit() != null && currentMissionInit().getExperimentUID().equals(expID)) {
                    // Our Experiment IDs match, so we are running the same experiment.
                    // Return the port and server IP address to the caller:
                    MinecraftServerConnection msc = currentMissionInit().getMinecraftServerConnection();
                    if (msc == null)
                        // Mission might be starting up.
                        reply("MALMONOSERVERYET", dos);
                    else
                        reply("MALMOS" + msc.getAddress() + ":" + msc.getPort(), dos);
                } else {
                    // We don't have a MissionInit ourselves, or we're running a different experiment,
                    // so we can't help.
                    reply("MALMONOSERVER", dos);
                }
            } else if (command.equals(killClientCommand)) {
                // Kill switch provided in case AI takes over the world...
                // Or, more likely, in case this Minecraft instance has become unreliable (eg if it's been running for several days)
                // and needs to be replaced with a fresh instance.
                // If we are currently running a mission, we gracefully decline, to prevent users from wiping out
                // other users' experiments.
                // We also decline unless we were launched in "replaceable" mode - a command-line switch that indicates we were
                // launched by a script which is still running, and can therefore replace us when we terminate.
                IState currentState = getStableState();
                if (currentState != null && currentState.equals(ClientState.DORMANT) && !isReserved()) {
                    Configuration config = MalmoMod.instance.getModSessionConfigFile();
                    if (config.getBoolean("replaceable", "runtype", false, "Will be replaced if killed")) {
                        reply("MALMOOK", dos);
                        // Have to use FMLCommonHandler; direct calls to System.exit() are trapped and denied by the FML code.
                        FMLCommonHandler.instance().exitJava(0, false);
                    } else {
                        reply("MALMOERRORNOTKILLABLE", dos);
                    }
                } else {
                    // We're too busy and important to be killed.
                    reply("MALMOBUSY", dos);
                }
            } else {
                // See if we've been sent a MissionInit message:
                MissionInitResult missionInitResult = decodeMissionInit(command);
                if (missionInitResult.wasMissionInit && missionInitResult.missionInit == null) {
                    // Got sent a duff MissionInit xml - pass back the JAXB/SAXB errors.
                    reply("MALMOERROR" + missionInitResult.error, dos);
                } else if (missionInitResult.wasMissionInit && missionInitResult.missionInit != null) {
                    MissionInit missionInit = missionInitResult.missionInit;
                    // We've been sent a MissionInit message.
                    // First, check the version number:
                    String platformVersion = missionInit.getPlatformVersion();
                    String ourVersion = Loader.instance().activeModContainer().getVersion();
                    if (platformVersion == null || !platformVersion.equals(ourVersion)) {
                        reply("MALMOERRORVERSIONMISMATCH (Got " + platformVersion + ", expected " + ourVersion + " - check your path for old versions of MalmoPython/MalmoJava/Malmo.lib etc)", dos);
                    } else {
                        // MissionInit passed to us - this is a request to launch this mission. Can we?
                        IState currentState = getStableState();
                        if (currentState != null && currentState.equals(ClientState.DORMANT) && isAvailable(missionInit.getExperimentUID())) {
                            reply("MALMOOK", dos);
                            // State machine will now process this MissionInit and start the mission.
                            keepProcessing = true;
                        } else {
                            // We're busy - we can't run this mission.
                            reply("MALMOBUSY", dos);
                        }
                    }
                }
            }
            return keepProcessing;
        }
    };
    this.missionPoller.start();
    // Tell the address helper what the actual port is:
    AddressHelper.setMissionControlPort(ClientStateMachine.this.missionPoller.getPortBlocking());
    if (AddressHelper.getMissionControlPort() == -1) {
        // Failed to create a mission control port - nothing will work!
        System.out.println("**** NO MISSION CONTROL SOCKET CREATED - WAS THE PORT IN USE? (Check Mod GUI options) ****");
        ClientStateMachine.this.getScreenHelper().addFragment("ERROR: Could not open a Mission Control Port - check the Mod GUI options.", TextCategory.TXT_CLIENT_WARNING, MISSING_MCP_PORT_ERROR);
    } else {
        // Clear the error string, if there was one:
        ClientStateMachine.this.getScreenHelper().clearFragment(MISSING_MCP_PORT_ERROR);
    }
    // Display the port number:
    ClientStateMachine.this.getScreenHelper().clearFragment(INFO_MCP_PORT);
    if (AddressHelper.getMissionControlPort() != -1)
        ClientStateMachine.this.getScreenHelper().addFragment("MCP: " + AddressHelper.getMissionControlPort(), TextCategory.TXT_INFO, INFO_MCP_PORT);
}
Also used : IState(com.microsoft.Malmo.IState) Configuration(net.minecraftforge.common.config.Configuration) DataOutputStream(java.io.DataOutputStream) MinecraftServerConnection(com.microsoft.Malmo.Schemas.MinecraftServerConnection) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) MissionInit(com.microsoft.Malmo.Schemas.MissionInit) TCPInputPoller(com.microsoft.Malmo.Utils.TCPInputPoller)

Example 15 with Configuration

use of net.minecraftforge.common.config.Configuration in project RFToolsDimensions by McJty.

the class CommonProxy method readMainConfig.

private void readMainConfig() {
    Configuration cfg = mainConfig;
    try {
        cfg.load();
        cfg.addCustomCategoryComment(GeneralConfiguration.CATEGORY_GENERAL, "Dimension related settings");
        cfg.addCustomCategoryComment(MachineConfiguration.CATEGORY_MACHINES, "Machine related settings");
        cfg.addCustomCategoryComment(WorldgenConfiguration.CATEGORY_WORLDGEN, "Worldgen related settings");
        cfg.addCustomCategoryComment(PowerConfiguration.CATEGORY_POWER, "Power related settings");
        cfg.addCustomCategoryComment(DimletConfiguration.CATEGORY_DIMLETS, "Dimlet related settings");
        cfg.addCustomCategoryComment(MobConfiguration.CATEGORY_MOBS, "Mob related settings");
        cfg.addCustomCategoryComment(OresAPlentyConfiguration.CATEGORY_ORESAPLENTY, "Settings for the OresAPlenty dimlet");
        cfg.addCustomCategoryComment(DimletConstructionConfiguration.CATEGORY_DIMLET_CONSTRUCTION, "Dimlet construction related settings");
        cfg.addCustomCategoryComment(LostCityConfiguration.CATEGORY_LOSTCITY, "Settings related to the Lost City dimlet");
        GeneralConfiguration.init(cfg);
        MachineConfiguration.init(cfg);
        WorldgenConfiguration.init(cfg);
        PowerConfiguration.init(cfg);
        DimletConfiguration.init(cfg);
        MobConfiguration.init(cfg);
        OresAPlentyConfiguration.init(cfg);
        LostCityConfiguration.init(cfg);
        DimletConstructionConfiguration.init(cfg);
    } catch (Exception e1) {
        Logging.logError("Problem loading config file!", e1);
    } finally {
        if (mainConfig.hasChanged()) {
            mainConfig.save();
        }
    }
}
Also used : Configuration(net.minecraftforge.common.config.Configuration)

Aggregations

Configuration (net.minecraftforge.common.config.Configuration)39 File (java.io.File)14 EventHandler (net.minecraftforge.fml.common.Mod.EventHandler)5 EventHandler (cpw.mods.fml.common.Mod.EventHandler)4 IOException (java.io.IOException)2 Property (net.minecraftforge.common.config.Property)2 ModMetadata (net.minecraftforge.fml.common.ModMetadata)2 AgriConfigAdapter (com.agricraft.agricore.config.AgriConfigAdapter)1 WorldConversionEventHandler (com.bluepowermod.convert.WorldConversionEventHandler)1 BPEventHandler (com.bluepowermod.event.BPEventHandler)1 Config (com.bluepowermod.init.Config)1 RedstoneProviderQmunityLib (com.bluepowermod.redstone.RedstoneProviderQmunityLib)1 ProxyASMTest (com.builtbroken.mc.core.asm.ProxyASMTest)1 ItemDevData (com.builtbroken.mc.core.content.debug.ItemDevData)1 ItemInstaHole (com.builtbroken.mc.core.content.debug.ItemInstaHole)1 TileInfInv (com.builtbroken.mc.core.content.debug.TileInfInv)1 ItemScrewdriver (com.builtbroken.mc.core.content.tool.ItemScrewdriver)1 ItemSelectionWand (com.builtbroken.mc.core.content.tool.ItemSelectionWand)1 ToolModeGeneral (com.builtbroken.mc.core.content.tool.screwdriver.ToolModeGeneral)1 ToolModeRotation (com.builtbroken.mc.core.content.tool.screwdriver.ToolModeRotation)1