Skip to content

Commit

Permalink
add configurations
Browse files Browse the repository at this point in the history
Signed-off-by: Savage <[email protected]>
  • Loading branch information
devsavage committed May 2, 2020
1 parent 7419c91 commit a23e8e2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/main/java/io/savagedev/soulmatter/SoulMatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
* THE SOFTWARE.
*/

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.io.WritingMode;
import com.mojang.authlib.GameProfile;
import io.savagedev.soulmatter.handlers.MobDeathEvent;
import io.savagedev.soulmatter.handlers.MobDropsHandler;
import io.savagedev.soulmatter.init.ModBlocks;
import io.savagedev.soulmatter.init.ModContainers;
import io.savagedev.soulmatter.init.ModItems;
import io.savagedev.soulmatter.init.ModTileEntities;
import io.savagedev.soulmatter.init.*;
import io.savagedev.soulmatter.proxy.CommonProxy;
import io.savagedev.soulmatter.util.LogHelper;
import io.savagedev.soulmatter.util.ModReference;
Expand All @@ -38,11 +37,15 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;

import java.nio.file.Path;
import java.util.UUID;

@Mod(ModReference.MOD_ID)
Expand All @@ -67,6 +70,16 @@ public SoulMatter() {
modEventBus.register(new ModItems());
modEventBus.register(new ModTileEntities());
modEventBus.register(new ModContainers());

ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ModConfiguration.CLIENT);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModConfiguration.COMMON);
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ModConfiguration.SERVER);

Path configPath = FMLPaths.CONFIGDIR.get().resolve("soulmatter-common.toml");
CommentedFileConfig configData = CommentedFileConfig.builder(configPath).sync().autosave().writingMode(WritingMode.REPLACE).build();

configData.load();
ModConfiguration.COMMON.setConfig(configData);
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* THE SOFTWARE.
*/

import io.savagedev.soulmatter.init.ModConfiguration;
import io.savagedev.soulmatter.util.NBTHelper;
import net.minecraft.item.ItemStack;

Expand All @@ -31,7 +32,7 @@ public class SoulToolLevelHandler
public static final String SOUL_TOOL_TAG = "SoulTool";
public static final String SOUL_TOOL_TAG_XP = "SoulToolXP";
public static final String SOUL_TOOL_TAG_LEVEL = "SoulToolLevel";
public static final int SOUL_TOOL_MAX_LEVEL = 4; //TODO: Make this value configurable
public static final int SOUL_TOOL_MAX_LEVEL = ModConfiguration.MAX_SOUL_TOOL_LEVEL.get();

public static int getToolLevel(ItemStack soulTool) {
return NBTHelper.getInt(soulTool, SOUL_TOOL_TAG_LEVEL);
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/io/savagedev/soulmatter/init/ModConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.savagedev.soulmatter.init;

/*
* ModConfiguration.java
* Copyright (C) 2020 Savage - github.com/devsavage
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

import net.minecraftforge.common.ForgeConfigSpec;

public class ModConfiguration
{
public static final ForgeConfigSpec CLIENT;
public static final ForgeConfigSpec COMMON;
public static final ForgeConfigSpec SERVER;

static {
final ForgeConfigSpec.Builder client = new ForgeConfigSpec.Builder();

CLIENT = client.build();
}

public static final ForgeConfigSpec.IntValue MAX_SOUL_TOOL_LEVEL;

static {
final ForgeConfigSpec.Builder common = new ForgeConfigSpec.Builder();

common.comment("General configuration options.").push("General");

MAX_SOUL_TOOL_LEVEL = common
.comment("This number handles the Soul Matter Tool max tool level. When the tool reaches this number, it will have max abilities.")
.translation("configGui.soulmatter.max_soul_tool_level")
.defineInRange("maxSoulToolLevel", 2, 2, 8);

common.pop();

COMMON = common.build();
}

static {
final ForgeConfigSpec.Builder server = new ForgeConfigSpec.Builder();

SERVER = server.build();
}
}

0 comments on commit a23e8e2

Please sign in to comment.