mirror of
https://github.com/GTNewHorizons/BetterBuildersWands.git
synced 2026-11-27 23:45:36 +00:00
Add overrides to config file.
This commit is contained in:
1 parent
b835826b14
commit
b599ecd702
3 files changed
+61
-4
No files matched your search
@@ -80,8 +80,10 @@ public class BetterBuildersWandsMod {
|
||||
blockCache = new StackedBlockManager();
|
||||
mappingManager = new CustomMappingManager();
|
||||
|
||||
mappingManager.setMapping(new CustomMapping(Blocks.lapis_ore, 0, new ItemStack(Blocks.lapis_ore, 1, 4), Blocks.lapis_ore, 0));
|
||||
mappingManager.setMapping(new CustomMapping(Blocks.lit_redstone_ore, 0, new ItemStack(Blocks.redstone_ore, 1, 0), Blocks.lit_redstone_ore, 0));
|
||||
mappingManager.loadConfig(configValues.OVERRIDES_RECIPES);
|
||||
|
||||
/*mappingManager.setMapping(new CustomMapping(Blocks.lapis_ore, 0, new ItemStack(Blocks.lapis_ore, 1, 4), Blocks.lapis_ore, 0));
|
||||
mappingManager.setMapping(new CustomMapping(Blocks.lit_redstone_ore, 0, new ItemStack(Blocks.redstone_ore, 1, 0), Blocks.lit_redstone_ore, 0));*/
|
||||
}
|
||||
|
||||
private ItemStack newWand(int damage) {
|
||||
|
||||
@@ -5,24 +5,31 @@ import net.minecraftforge.common.config.Configuration;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by james on 16/12/15.
|
||||
* Config file
|
||||
*/
|
||||
public class ConfigValues {
|
||||
private Configuration configFile;
|
||||
|
||||
public static final String CONFIG_WHYNOT = "why_not";
|
||||
public static final String CONFIG_GENERAL = "general";
|
||||
|
||||
public boolean NO_EXTRA_UTILS_RECIPES;
|
||||
public static final boolean NO_EXTRA_UTILS_RECIPES_DEFAULT = false;
|
||||
public static final String NO_EXTRA_UTILS_RECIPES_NAME = "straymav_ultimate_wand";
|
||||
public static final String NO_EXTRA_UTILS_RECIPES_DESCRIPTION = "For those that don't like Extra Utils progression.";
|
||||
|
||||
public String OVERRIDES_RECIPES;
|
||||
public static final String OVERRIDES_RECIPES_DEFAULT = "minecraft:lapis_ore/0=>1*minecraft:lapis_ore/4=>minecraft:lapis_ore/0,minecraft:lit_redstone_ore/0=>1*minecraft:redstone_ore/0=>minecraft:lit_redstone_ore/0";
|
||||
public static final String OVERRIDES_RECIPES_NAME = "forced_blocks";
|
||||
public static final String OVERRIDES_RECIPES_DESCRIPTION = "Specify forced mappings for what to build from certain blocks.\n(what you are looking at)=>(number required)*(item required)=>(block to build)";
|
||||
|
||||
public ConfigValues(File file) {
|
||||
configFile = new Configuration(file);
|
||||
}
|
||||
|
||||
public void loadConfigFile() {
|
||||
NO_EXTRA_UTILS_RECIPES = configFile.getBoolean(NO_EXTRA_UTILS_RECIPES_NAME, CONFIG_WHYNOT, NO_EXTRA_UTILS_RECIPES_DEFAULT, NO_EXTRA_UTILS_RECIPES_DESCRIPTION);
|
||||
OVERRIDES_RECIPES = configFile.get(CONFIG_GENERAL, OVERRIDES_RECIPES_NAME, OVERRIDES_RECIPES_DEFAULT, OVERRIDES_RECIPES_DESCRIPTION).getString();
|
||||
|
||||
configFile.save();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package portablejim.bbw.core.conversion;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import portablejim.bbw.BetterBuildersWandsMod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by james on 18/12/15.
|
||||
* Handle the mappings to force blocks to build with certain materials.
|
||||
*/
|
||||
public class CustomMappingManager {
|
||||
ArrayList<CustomMapping> mappings;
|
||||
@@ -14,6 +21,47 @@ public class CustomMappingManager {
|
||||
mappings = new ArrayList<CustomMapping>();
|
||||
}
|
||||
|
||||
public void loadConfig(String configString) {
|
||||
if(configString.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] split = configString.trim().split(",");
|
||||
for (String part : split) {
|
||||
CustomMapping customMapping = parseMappingString(part);
|
||||
if(customMapping != null) {
|
||||
mappings.add(customMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CustomMapping parseMappingString(String mappingString) {
|
||||
final String REGEX = "^(\\w[^:]+:[^/]+)/(\\d+)=>(\\d)+\\*(\\w[^:]+:[^/]+)/(\\d+)=>(\\w[^:]+:[^/]+)/(\\d+)$";
|
||||
Pattern p = Pattern.compile(REGEX);
|
||||
Matcher m = p.matcher(mappingString);
|
||||
if(!mappingString.isEmpty() && m.matches()) {
|
||||
Block sourceBlock = Block.getBlockFromName(m.group(1));
|
||||
int sourceMeta = Integer.parseInt(m.group(2));
|
||||
int itemCount = Integer.parseInt(m.group(3));
|
||||
|
||||
String itemString = m.group(4);
|
||||
Item itemItem = GameRegistry.findItem(itemString.split(":", 2)[0], itemString.split(":", 2)[1]);
|
||||
|
||||
int itemMeta = Integer.parseInt(m.group(5));
|
||||
Block targetBlock = Block.getBlockFromName(m.group(6));
|
||||
int targetMeta = Integer.parseInt(m.group(7));
|
||||
|
||||
if(sourceBlock != null && itemItem != null && targetBlock != null) {
|
||||
ItemStack itemItemstack = new ItemStack(itemItem, itemCount, itemMeta);
|
||||
CustomMapping newMapping = new CustomMapping(sourceBlock, sourceMeta, itemItemstack, targetBlock, targetMeta);
|
||||
BetterBuildersWandsMod.logger.info("Added '%s' to mapping", mappingString);
|
||||
return newMapping;
|
||||
}
|
||||
}
|
||||
BetterBuildersWandsMod.logger.error("Error adding '%s' to mapping", mappingString);
|
||||
return null;
|
||||
}
|
||||
|
||||
public CustomMapping getMapping(Block block, int meta) {
|
||||
for(CustomMapping mapping : mappings) {
|
||||
if(mapping.getLookBlock() == block && mapping.getMeta() == meta) {
|
||||
|
||||
Reference in new issue
Block a user