Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Add the ability to define harvestlevel names depending on tinker mate…
Browse files Browse the repository at this point in the history
…rials. woo!
  • Loading branch information
bonii-xx committed Aug 30, 2014
1 parent f59866c commit b055f88
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
@@ -0,0 +1,71 @@
package iguanaman.iguanatweakstconstruct.override;

import iguanaman.iguanatweakstconstruct.reference.Config;
import iguanaman.iguanatweakstconstruct.util.HarvestLevels;
import iguanaman.iguanatweakstconstruct.util.Log;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolMaterial;

import java.util.HashMap;
import java.util.Map;

public class HarvestLevelNameOverride implements IOverride {
@Override
public void createDefault(Configuration config) {
Log.info("Creating Harvest Level Name Default File");

config.get("HarvestLevelNames", "Level0", "Stone");
config.get("HarvestLevelNames", "Level1", "Copper");
config.get("HarvestLevelNames", "Level2", "Iron");
config.get("HarvestLevelNames", "Level3", "Bronze");
config.get("HarvestLevelNames", "Level4", "Steel");
config.get("HarvestLevelNames", "Level5", "Obsidian");
config.get("HarvestLevelNames", "Level6", "Ardite");
config.get("HarvestLevelNames", "Level7", "Cobalt");
config.get("HarvestLevelNames", "Level8", "Manyullyn");
}

@Override
public void processConfig(Configuration config) {
Log.info("Loading Harvest Level Name Overrides");

ConfigCategory cat = config.getCategory("HarvestLevelNames");
cat.setComment("Use materialnames to set the name of a harvest level. Check the MaterialDefaults file for the material names.\nFor Example: 'Level0=wood' would change the first harvest level to wood from stone.");

Map<Integer, ToolMaterial> mats = new HashMap<Integer, ToolMaterial>();

for(Property prop : cat.values())
{
if(!prop.getName().startsWith("Level"))
{
Log.error("Invalid entry: " + prop.getName());
continue;
}
Integer lvl;
try {
lvl = Integer.valueOf(prop.getName().substring(5));
}
catch(NumberFormatException e)
{
Log.error("Invalid entry: " + prop.getName());
continue;
}

// find material. we have to loop through all materials, because configs don't like case sensitivity.
String matName = prop.getString().toLowerCase();
for(ToolMaterial mat : TConstructRegistry.toolMaterials.values())
if(matName.equals(mat.name().toLowerCase()))
{
mats.put(lvl, mat);
if(Config.logOverrideChanges)
Log.info(String.format("Harvest Level Name Override: Changed Level %s to %s", lvl, mat.materialName));
break;
}
}

HarvestLevels.setCustomHarvestLevelNames(mats);
}
}
Expand Up @@ -26,6 +26,7 @@ public void postInit(FMLPostInitializationEvent event)
doOverride("Tool", new ToolOverride());
doOverride("Block", new BlockOverride());
doOverride("BonusModifier", new ModifierOverride());
doOverride("HarvestLevelNames", new HarvestLevelNameOverride());
}

public static void doOverride(String type, IOverride overrider)
Expand Down
Expand Up @@ -2,7 +2,10 @@

import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import tconstruct.TConstruct;
import tconstruct.library.tools.ToolMaterial;

import java.util.List;
import java.util.Map;

import static net.minecraft.util.EnumChatFormatting.*;
Expand Down Expand Up @@ -75,4 +78,10 @@ public static String getHarvestLevelName(int num)
{
return tconstruct.library.util.HarvestLevels.getHarvestLevelName(num);
}

public static void setCustomHarvestLevelNames(Map<Integer, ToolMaterial> mats)
{
for(Map.Entry<Integer, ToolMaterial> mat : mats.entrySet())
tconstruct.library.util.HarvestLevels.harvestLevelNames.put(mat.getKey(), mat.getValue().style() + mat.getValue().name());
}
}

0 comments on commit b055f88

Please sign in to comment.