Skip to content

Commit

Permalink
Added config for required blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Mar 28, 2016
1 parent 5bf01e6 commit eebb639
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/info/loenwind/enderioaddons/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public enum Config {
+ "EnderIO:itemBasicCapacitor@0=10, EnderIO:itemBasicCapacitor@1=5, EnderIO:itemBasicCapacitor@2=1",
"A list of items with weights that will be dropped by the capacitor plant when harvested. Plants with a gain of 6-9 will drop "
+ "one item from this list, plants with a gain of 10 will drop 2."), //
plantRequiredBlocks(Section.FARM, "EnderIO:blockCapBank@1, minecraft:bedrock@-1, EnderIO:blockDarkIronBars@-1",
"Three items that define the soil, block under soil and block around for the capacitor plant. Please note that this are item IDs, not block IDs, but block"
+ " meta values. The blocks for these item will be looked up as ususal.", true, true), //
seedsAutomaticHarvestingEnabled(Section.FARM, false, "If enabled Capacitor Plants can be harvested with machines. I call it couch potato mode"), //
seedsBonemealEnabled(Section.FARM, false, "If enabled Capacitor Plants can be fertilized with bonemeal."), //
farmAggressiveTillingDefault(Section.FARM, true, "The initial value of 'till agressively' for newly placed farms"), //
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/info/loenwind/enderioaddons/config/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import java.util.regex.Pattern;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import org.apache.commons.lang3.tuple.Pair;

public class ItemHelper {

private static final Pattern p = Pattern.compile("^\\s*([^:\\s]+):([^@\\s]+)(?:@(\\d+))?\\s*=\\s*(\\d+)\\s*$");
private static final Pattern p = Pattern.compile("^\\s*([^:\\s]+):([^@\\s]+)(?:@(-?\\d+))?\\s*(?:=\\s*(\\d+)\\s*)?$");

public static List<WeightedItemStack> readWeightedList(String input) {
if (input == null || input.trim().isEmpty()) {
Expand All @@ -38,14 +39,16 @@ public static List<WeightedItemStack> readWeightedList(String input) {
String weightS = matcher.group(4);

try {
if (modid == null || itemid == null || weightS == null) {
if (modid == null || itemid == null) {
throw new NumberFormatException();
}
int meta = metaS == null ? 0 : Integer.valueOf(metaS);
if (meta < 0 || meta >= 4096) {
if (meta == -1) {
meta = OreDictionary.WILDCARD_VALUE;
} else if (meta < 0 || meta >= 4096) {
throw new NumberFormatException();
}
int weight = Integer.valueOf(weightS);
int weight = weightS == null ? 1 : Integer.valueOf(weightS);

MinecraftItem mci = new MinecraftItem(modid, itemid, meta);
ItemStack stack = mci.getItemStack();
Expand Down Expand Up @@ -85,6 +88,18 @@ public static List<WeightedItemStack> readWeightedList(Config config) {
return result;
}

public static List<ItemStack> readList(Config config) {
List<WeightedItemStack> weightedList = readWeightedList(config);
if (weightedList == null) {
return null;
}
List<ItemStack> result = new ArrayList<>();
for (WeightedItemStack weightedItemStack : weightedList) {
result.add(weightedItemStack.getStack());
}
return result;
}

public static void main(String[] args) {
readWeightedList(",minecraft:dirt@1=99,;, enderio:whatever@0 = 47 ,other:what=13,");
String a = "enderioaddons:itemMachineParts@23=13500, EnderIO:itemBasicCapacitor@0=10, EnderIO:itemBasicCapacitor@1=5, EnderIO:itemBasicCapacitor@2=1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
Expand All @@ -29,9 +30,56 @@ public class EioaGrowthRequirement implements IGrowthRequirement {
private final int[] brightness = { 13, 15, 0, 0 };

public EioaGrowthRequirement() {
// fall back values
capBank = new BlockWithMeta(Block.getBlockFromItem(Recipes.capBankCreative.getItem()), 1, true);
bedrock = new BlockWithMeta(Blocks.bedrock, OreDictionary.WILDCARD_VALUE, true);
darkBar = new BlockWithMeta(Block.getBlockFromItem(Recipes.darkSteelBars.getItem()), OreDictionary.WILDCARD_VALUE, true);

List<ItemStack> list = info.loenwind.enderioaddons.config.ItemHelper.readList(Config.plantRequiredBlocks);
if (list != null) {
if (list.size() == 3) {

ItemStack itemStackCapBank = list.get(0);
Block blockCapBank = Block.getBlockFromItem(itemStackCapBank.getItem());
if (blockCapBank != null) {
if (itemStackCapBank.getItemDamage() <= 15 || itemStackCapBank.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
capBank = new BlockWithMeta(blockCapBank, itemStackCapBank.getItemDamage(), true);
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (first element has invalid meta) and will be (partially) ignored.");
}
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (first element has no block) and will be (partially) ignored.");
}

ItemStack itemStackBedrock = list.get(1);
Block blockBedrock = Block.getBlockFromItem(itemStackBedrock.getItem());
if (blockBedrock != null) {
if (itemStackBedrock.getItemDamage() <= 15 || itemStackBedrock.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
bedrock = new BlockWithMeta(blockBedrock, itemStackBedrock.getItemDamage(), true);
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (second element has invalid meta) and will be (partially) ignored.");
}
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (second element has no block) and will be (partially) ignored.");
}

ItemStack itemStackDarkBar = list.get(1);
Block blockDarkBar = Block.getBlockFromItem(itemStackDarkBar.getItem());
if (blockDarkBar != null) {
if (itemStackDarkBar.getItemDamage() <= 15 || itemStackDarkBar.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
darkBar = new BlockWithMeta(blockDarkBar, itemStackDarkBar.getItemDamage(), true);
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (third element has invalid meta) and will be (partially) ignored.");
}
} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (third element has no block) and will be (partially) ignored.");
}

} else {
Log.warn("Config value 'plantRequiredBlocks' is invalid (wrong number of items) and will be ignored.");
}
}

try {
Class<?> newGrowthRequirementHandler = Class.forName("com.InfinityRaider.AgriCraft.farming.growthrequirement.GrowthRequirementHandler");
if (newGrowthRequirementHandler != null) {
Expand Down

0 comments on commit eebb639

Please sign in to comment.