package bellcraft.core;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.common.config.Configuration;
public class Config
{
  	public static Configuration bcConfig;
  	public static boolean enableBellCraft;
  	public static boolean enableRandomBox;
	public static boolean enableRandomIngot;
	public static boolean enableRandomOreGen;
	public static boolean enableRandomOre;
	public static void Initialize(FMLPreInitializationEvent event)
  	{
		bcConfig = new Configuration(event.getSuggestedConfigurationFile());
		bcConfig.load();
		
		bcConfig.addCustomCategoryComment("General", "Here you can disable or re-enable any general options you choose.");
		enableBellCraft = bcConfig.get("General", "EnableBellCraft", true).getBoolean(true);
		
		bcConfig.addCustomCategoryComment("Ore Gen Enabled", "Here you can disable or re-enable any ore gen you choose. Change value to false to disable selected ore gen.");
		enableRandomOreGen = bcConfig.get("Ore Gen Enabled", "RandomOreGen", true).getBoolean(true);
		
		bcConfig.addCustomCategoryComment("Blocks Enabled", "Here you can disable or re-enable any blocks you choose. Change value to false to disable selected block.");
		enableRandomOre = bcConfig.get("Blocks Enabled", "RandomOre", true).getBoolean(true);
		
		bcConfig.addCustomCategoryComment("Items Enabled", "Here you can disable or re-enable any items you choose. Change value to false to disable selected item.");
		enableRandomIngot = bcConfig.get("Items Enabled", "RandomIngot", true).getBoolean(true);
		enableRandomBox = bcConfig.get("Items Enabled", "RandomBox", true).getBoolean(true);
			
		bcConfig.save();
		BellCraft.AddLog("Configuration load complete.");
	}
}
위는 현재 제 Config 클래스 예시입니다.
bcConfig 라는 설정 인스턴스를 생성하고, 로드시켜줍니다.
bcConfig.addCustomCategoryComment(String category, String comment);
문으로 카테고리 주석을 달아줍니다.
bcConfig.get(String category, String key, boolean defaultValue);
문으로 값을 받아옵니다. 지정된 값이 없거나 값에 문제가 있을경우 기본값으로 설정합니다.
bcConfig.save(); 설정값을 저장시켜줍니다.
+ 잘 응용하시면 받아오는값에 정수값을 받아올수도 있고, 문자값도 받아올 수 있습니다.
문자값을 split 하여 배열에 올릴수도 있구요.
위와같이 코딩하신 다음, bellcraft.core.Registry 클래스의 register(FMLPreInitializationEvent event) 메서드에 다음을 추가합니다.
	public static void register(FMLPreInitializationEvent event)
	{
		Config.Initialize(event); // 설정값 로드
	}
위 예시대로 코딩한 후 마인크래프트를 실행해주시면 다음과같은 설정파일이 생성됩니다.
파일 위치는 \Config\BellCraft.cfg 입니다.
# Configuration file
##########################################################################################################
# blocks enabled
#--------------------------------------------------------------------------------------------------------#
# Here you can disable or re-enable any blocks you choose. Change value to false to disable selected block.
##########################################################################################################
"blocks enabled" {
    B:RandomOre=true
}
##########################################################################################################
# general
#--------------------------------------------------------------------------------------------------------#
# Here you can disable or re-enable any general options you choose.
##########################################################################################################
general {
    B:EnableBellCraft=true
}
##########################################################################################################
# items enabled
#--------------------------------------------------------------------------------------------------------#
# Here you can disable or re-enable any items you choose. Change value to false to disable selected item.
##########################################################################################################
"items enabled" {
    B:RandomBox=true
    B:RandomIngot=true
}
##########################################################################################################
# ore gen enabled
#--------------------------------------------------------------------------------------------------------#
# Here you can disable or re-enable any ore gen you choose. Change value to false to disable selected ore gen.
##########################################################################################################
"ore gen enabled" {
    B:RandomOreGen=true
}
이제 저 값들을 이용하여 모드내의 일부 아이템을 생성하지 않거나, 조합법을 바꾸거나, 블럭이 월드에서 젠되지 않는 등 여러 설정을 하실 수 있습니다.
설정을 하는건 여러분의 몫입니다.
이제 저 값을 이용하여 주요부분에 저 값으로 기능을 ON/OFF 하게 만드실 수 있습니다.
ps. 게임레지스트리관련 명령줄을 모두 bellcraft.core.Registry 클래스에 옮겼습니다.
아래는 bellcraft.core.Registry 클래스의 예시입니다.
public class Registry {
	
	public static void register(FMLPreInitializationEvent event)
	{
		Config.Initialize(event); // 설정값 로드
	}
	
	public static void register(FMLInitializationEvent event)
	{
		Events.registerEvents(); // 이벤트 등록
		Items.registerItems(); // 아이템 등록
		Blocks.registerBlocks(); // 블럭 등록
		OreGeneration.registerOre(); // 광물 등록
		ItemRecipe.registerRecipe(); // 아이템 조합법 등록
		FurnaceRecipe.registerRecipe(); // 화로 조합법 등록
	}
}
위와같이 메서드 오버로딩을 하신 후, bellcraft.core.BellCraft 클래스에 각각 Initialize 메서드와 PreInitialize 메서드에 Registry.register(event); 문을 추가하시면 상황에 맞게 Registry 클래스에 해당 메서드가 실행됩니다.
'Game Dev > MineCraft - Mod' 카테고리의 다른 글
| 종합 아이템 생성 클래스 생성하기 (15) | 2014.12.14 | 
|---|---|
| 블럭 하베스트레벨, 부술시 나오는 아이템 지정하기 (0) | 2014.12.06 | 
| Bell Craft 모드 Github 오픈소스 (0) | 2014.12.02 | 
| 화로 조합법 등록하기 (0) | 2014.12.02 | 
| 블럭 밝기설정, 불투명도 설정, 강도설정, 소리설정 등 블럭설정과 조합법 추가하기 (0) | 2014.12.02 | 
댓글