diff --git a/src/main/java/tconstruct/library/crafting/ToolBuilder.java b/src/main/java/tconstruct/library/crafting/ToolBuilder.java index a8e1343e..23632233 100644 --- a/src/main/java/tconstruct/library/crafting/ToolBuilder.java +++ b/src/main/java/tconstruct/library/crafting/ToolBuilder.java @@ -11,6 +11,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; import tconstruct.library.TConstructRegistry; +import tconstruct.library.event.ToolBuildEvent; import tconstruct.library.event.ToolCraftEvent; import tconstruct.library.modifier.ItemModifier; import tconstruct.library.tools.ToolCore; @@ -115,11 +116,8 @@ public class ToolBuilder if (stack == null) return -1; Item item = stack.getItem(); - if (item == Items.stick) - return 0; - else if (item == Items.bone) - return 5; - else if (item instanceof IToolPart) + + if (item instanceof IToolPart) return ((IToolPart) item).getMaterialID(stack); return -1; @@ -132,6 +130,19 @@ public class ToolBuilder if (headStack == null || handleStack == null) //Nothing to build without these. All tools need at least two parts! return null; + if(name == null) + name = ""; + + // fire the ToolBuild event to get the correct items + ToolBuildEvent buildEvent = new ToolBuildEvent(headStack, handleStack, accessoryStack, extraStack, name); + MinecraftForge.EVENT_BUS.post(buildEvent); + + // copy back the items + headStack = buildEvent.headStack; + handleStack = buildEvent.handleStack; + accessoryStack = buildEvent.accessoryStack; + extraStack = buildEvent.extraStack; + name = buildEvent.name; ToolCore item; boolean validMaterials = true; diff --git a/src/main/java/tconstruct/library/event/ToolBuildEvent.java b/src/main/java/tconstruct/library/event/ToolBuildEvent.java new file mode 100644 index 00000000..7afb70b5 --- /dev/null +++ b/src/main/java/tconstruct/library/event/ToolBuildEvent.java @@ -0,0 +1,24 @@ +package tconstruct.library.event; + +import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.item.ItemStack; + +/** + * Called when the ToolBuilder tries to piece together the Parts of a tool. + * + */ +public class ToolBuildEvent extends Event { + public ItemStack headStack; + public ItemStack handleStack; + public ItemStack accessoryStack; + public ItemStack extraStack; + public String name; // to allow shenanigans + + public ToolBuildEvent(ItemStack headStack, ItemStack handleStack, ItemStack accessoryStack, ItemStack extraStack, String name) { + this.headStack = headStack; + this.handleStack = handleStack; + this.accessoryStack = accessoryStack; + this.extraStack = extraStack; + this.name = name; + } +} diff --git a/src/main/java/tconstruct/tools/TinkerToolEvents.java b/src/main/java/tconstruct/tools/TinkerToolEvents.java index 31b12ae4..48673a8d 100644 --- a/src/main/java/tconstruct/tools/TinkerToolEvents.java +++ b/src/main/java/tconstruct/tools/TinkerToolEvents.java @@ -19,14 +19,12 @@ import net.minecraft.util.EntityDamageSourceIndirect; import net.minecraft.util.Vec3; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; import tconstruct.TConstruct; import tconstruct.armor.player.TPlayerStats; import tconstruct.library.TConstructRegistry; -import tconstruct.library.event.PartBuilderEvent; -import tconstruct.library.event.SmelteryCastEvent; -import tconstruct.library.event.SmelteryCastedEvent; -import tconstruct.library.event.ToolCraftEvent; +import tconstruct.library.event.*; import tconstruct.library.tools.AbilityHelper; import tconstruct.library.tools.ArrowMaterial; import tconstruct.library.tools.BowMaterial; @@ -39,6 +37,8 @@ import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent; +import java.util.List; + public class TinkerToolEvents { @SubscribeEvent @@ -58,7 +58,25 @@ public class TinkerToolEvents } } } - + + @SubscribeEvent + public void buildTool(ToolBuildEvent event) + { + // check if the handle is a bone + if(event.handleStack.getItem() == Items.bone) { + event.handleStack = new ItemStack(TinkerTools.toolRod, 1, 5); // bone tool rod + return; + } + + // check if the handle is a stick + List sticks = OreDictionary.getOres("stickWood"); + for(ItemStack stick : sticks) + if (OreDictionary.itemMatches(stick, event.handleStack, false)) { + event.handleStack = new ItemStack(TinkerTools.toolRod, 1, 0); // wooden tool rod + return; + } + } + @SubscribeEvent public void craftTool (ToolCraftEvent.NormalTool event) {