diff --git a/tconstruct/common/TContent.java b/tconstruct/common/TContent.java index 618762e9..dee5ac3e 100644 --- a/tconstruct/common/TContent.java +++ b/tconstruct/common/TContent.java @@ -2107,6 +2107,7 @@ public class TContent implements IFuelHandler } } + public static Object getStaticItem (String name, String classPackage) { try diff --git a/tconstruct/library/crafting/ToolBuilder.java b/tconstruct/library/crafting/ToolBuilder.java index f10c7c33..1d103767 100644 --- a/tconstruct/library/crafting/ToolBuilder.java +++ b/tconstruct/library/crafting/ToolBuilder.java @@ -111,6 +111,21 @@ public class ToolBuilder { return buildTool(headStack, handleStack, accessoryStack, null, name); } + + public int getMaterialID(ItemStack stack) + { + if (stack == null) + return -1; + Item item = stack.getItem(); + if (item == Item.stick) + return 0; + else if (item == Item.bone) + return 5; + else if (item instanceof IToolPart) + return ((IToolPart) item).getMaterialID(stack); + + return -1; + } public ItemStack buildTool (ItemStack headStack, ItemStack handleStack, ItemStack accessoryStack, ItemStack extraStack, String name) { @@ -123,23 +138,27 @@ public class ToolBuilder ToolCore item; boolean validMaterials = true; int head = -1, handle = -1, accessory = -1, extra = -1; - if (headStack.getItem() instanceof IToolPart) + /*if (headStack.getItem() instanceof IToolPart) { head = ((IToolPart) headStack.getItem()).getMaterialID(headStack); } else + validMaterials = false;*/ + head = getMaterialID(headStack); + if (head == -1) validMaterials = false; - Item handleItem = handleStack.getItem(); - - if (handleItem == Item.stick) + handle = getMaterialID(handleStack); + if (handle == -1) + validMaterials = false; + /*if (handleItem == Item.stick) handle = 0; else if (handleItem == Item.bone) handle = 5; else if (handleItem instanceof IToolPart) handle = ((IToolPart) handleItem).getMaterialID(handleStack); else - validMaterials = false; + validMaterials = false;*/ if (!validMaterials) return null; @@ -150,16 +169,24 @@ public class ToolBuilder } else { - if (accessoryStack.getItem() instanceof IToolPart) + /*if (accessoryStack.getItem() instanceof IToolPart) accessory = ((IToolPart) accessoryStack.getItem()).getMaterialID(accessoryStack); else + return null;*/ + + accessory = getMaterialID(accessoryStack); + if (accessory == -1) return null; if (extraStack != null) { - if (extraStack.getItem() instanceof IToolPart) + /*if (extraStack.getItem() instanceof IToolPart) extra = ((IToolPart) extraStack.getItem()).getMaterialID(extraStack); else + return null;*/ + + extra = getMaterialID(extraStack); + if (extra == -1) return null; item = getMatchingRecipe(headStack.getItem(), handleStack.getItem(), accessoryStack.getItem(), extraStack.getItem()); diff --git a/tconstruct/library/tools/FletchingMaterial.java b/tconstruct/library/tools/FletchingMaterial.java index 5383b39b..a40dcc69 100644 --- a/tconstruct/library/tools/FletchingMaterial.java +++ b/tconstruct/library/tools/FletchingMaterial.java @@ -1,5 +1,6 @@ package tconstruct.library.tools; +import net.minecraft.block.Block; import net.minecraft.item.ItemStack; public class FletchingMaterial extends CustomMaterial diff --git a/tconstruct/util/TEventHandler.java b/tconstruct/util/TEventHandler.java index aee37087..7ffcf896 100644 --- a/tconstruct/util/TEventHandler.java +++ b/tconstruct/util/TEventHandler.java @@ -223,7 +223,7 @@ public class TEventHandler } return false; } - + /* Damage */ @ForgeSubscribe public void onHurt (LivingHurtEvent event) @@ -869,7 +869,13 @@ public class TEventHandler public void unfuxOreDictionary () { - ArrayList ores = OreDictionary.getOres("ingotCopper"); + ArrayList ores = OreDictionary.getOres("plankWood"); + for (ItemStack ore : ores) + { + PatternBuilder.instance.registerMaterial(ore, 2, "Wood"); + } + + ores = OreDictionary.getOres("ingotCopper"); for (ItemStack ore : ores) { PatternBuilder.instance.registerMaterial(ore, 2, "Copper"); diff --git a/test/EncodingSequence.java b/test/EncodingSequence.java new file mode 100644 index 00000000..ca6c7544 --- /dev/null +++ b/test/EncodingSequence.java @@ -0,0 +1,6 @@ +package test; + +public class EncodingSequence +{ + +} diff --git a/test/Trait.java b/test/Trait.java new file mode 100644 index 00000000..23342145 --- /dev/null +++ b/test/Trait.java @@ -0,0 +1,64 @@ +package test; + +import java.util.Random; + +//Quantitive Trait Locus +public class Trait +{ + protected int[] alleles; + static Random rand = new Random(); + + public int getAverage () + { + int average = 0; + + if (alleles.length > 0) + { + for (byte i = 0; i < alleles.length; i++) + average += alleles[i]; + + average /= alleles.length; + } + + return average; + } + + public int[] breed (byte[] other, float[] mutation) + { + assert alleles.length == other.length : "Complete trait arrays need to have identical length"; + + int[] result = new int[alleles.length > other.length ? alleles.length : other.length]; + + for (int i = 0; i < result.length; i++) + { + if (rand.nextFloat() < mutation[0]) + { + result[i] = mutate(alleles[i], other[i], mutation[1]); + } + else + { + result[i] = rand.nextBoolean() ? alleles[i] : other[i]; + } + } + + return result; + } + + //Assumes linear progression from worst to best. Use other methods for other types + protected int mutate (int allele, int other, float variance) + { + int mutator = rand.nextBoolean() ? allele : other; + double bellcurve = rand.nextGaussian(); + double offset = variance * bellcurve; + offset -= offset / 2; + + if (mutator + offset < 0) + mutator = 0; + else if (mutator + offset > Integer.MAX_VALUE) + mutator = Integer.MAX_VALUE; + else + mutator = (int) (mutator + offset); + + return mutator; + } +}