OnItemCraft
OxideCarbonItemCalled when an item is crafted.
object OnItemCraft(ItemCraftTask local0, BasePlayer owner, Item fromTempBlueprint)
object OnItemCraft(IndustrialCrafter industrialCrafter, ItemBlueprint itemBlueprint)Works — the game method in this build is the one the hook was written for.
Parameters
- local0
- ItemCraftTask
- owner
- BasePlayer
- fromTempBlueprint
- Item
Return value
objectThe returned value replaces the game result; null lets the game decide.
Example
object — you can affect the game: return a value to change or cancel the action.
private object OnItemCraft(ItemCraftTask local0, BasePlayer owner, Item fromTempBlueprint)
{
Puts("OnItemCraft");
// change nothing — the game continues as usual
return null;
// to affect the game:
// return false; // your value instead of the game result
}Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.
Injection point 1
Rust.opj (Oxide)
bool ItemCrafter.CraftItem(ItemBlueprint, BasePlayer, ProtoBuf.Item.InstanceData, int, int, Item, bool, int)
Passes: ItemCraftTask local0, BasePlayer owner, Item fromTempBlueprint
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (l0, a1, a5)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
itemCraftTask.skinID = skinID;
itemCraftTask.attachmentID = attachmentID;
if (fromTempBlueprint != null && itemCraftTask.takenItems != null)
{
fromTempBlueprint.RemoveFromContainer();
itemCraftTask.takenItems.Add(fromTempBlueprint);
itemCraftTask.conditionScale = 0.5f;
}
object returnvar = Interface.CallHook("OnItemCraft", itemCraftTask, owner, fromTempBlueprint);
if (returnvar is bool)
{
return (bool)returnvar;
}
queue.AddLast(itemCraftTask);
if (owner != null)
{
owner.Command("note.craft_add", itemCraftTask.taskUID, itemCraftTask.blueprint.targetItem.itemid, amount, itemCraftTask.skinID);
// …Injection point 2
Rust.opj (Oxide)
void IndustrialCrafter.RunJob()
Passes: IndustrialCrafter industrialCrafter, ItemBlueprint itemBlueprint
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, l2)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
for (int i = 0; i <= 3; i++)
{
Item targetBlueprint = GetTargetBlueprint(i);
if (targetBlueprint == null || GetWorkbench() == null || GetWorkbench().Workbenchlevel < targetBlueprint.blueprintTargetDef.Blueprint.GetWorkbenchLevel())
{
continue;
}
ItemBlueprint blueprint = targetBlueprint.blueprintTargetDef.Blueprint;
if (Interface.CallHook("OnItemCraft", this, blueprint) != null)
{
return;
}
bool flag = true;
foreach (ItemAmount ingredient in blueprint.GetIngredients())
{
if ((float)GetInputAmount(ingredient.itemDef) < ingredient.amount)
{
// …Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.