Skip to content

Commit

Permalink
Add a ToolBuildEvent that is called at the start of the tool building…
Browse files Browse the repository at this point in the history
… process. Allows to replace parts used for building with other parts.
  • Loading branch information
bonii-xx committed Aug 15, 2014
1 parent f9a4fd2 commit e786518
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/tconstruct/library/crafting/ToolBuilder.java
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -132,6 +133,19 @@ public ItemStack buildTool (ItemStack headStack, ItemStack handleStack, ItemStac

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;
Expand Down
24 changes: 24 additions & 0 deletions 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;
}
}

0 comments on commit e786518

Please sign in to comment.