/**
* This is an example code to fully customize a recipe for the fusion furnace. @author zot
*/
/**
* Assign experience to every possible results.
*/
float exp = FurnaceRecipes.smelting().getExperience(new ItemStack(Item.ingotGold));
FusionRecipes.setExperience(new ItemStack(Item.goldNugget), exp / 9);
FusionRecipes.setExperience(new ItemStack(Item.ingotGold), exp);
/**
* Register the coal as ore, in case other mods added variations of coal.
*/
final String coal = "coal";
FusionRecipes.registerOre(coal, new ItemStack(Item.coal, 1, 0));
FusionRecipes.registerOre(coal, new ItemStack(Item.coal, 1, 1));
/**
* Use a chunk of coal as the catalyst and two gold instruments as the inputs.
* Smelt them into nuggets or ingots.
*/
FusionRecipes.getRecipeList().add(new Entry() {
/**
* Check if this recipe is applicable for the current combination.
*/
@Override public boolean matches(ItemStack input1, ItemStack input2, ItemStack catalyst) {
if (isItemCatalyst(catalyst) && isItemIput(input1) && isItemIput(input2))
return true;
return false;
}
/**
* A utility method used only here to tell the amount of ingots used in crafting the instruments.
*/
public int getNumberOfIngot(ItemStack input) {
if (input == null)
return 0;
int id = input.itemID;
if (id == Item.shovelGold.itemID)
return 1;
if (id == Item.swordGold.itemID || id == Item.hoeGold.itemID)
return 2;
if (id == Item.axeGold.itemID || id == Item.pickaxeGold.itemID)
return 3;
if (id == Item.bootsGold.itemID)
return 4;
if (id == Item.helmetGold.itemID)
return 5;
if (id == Item.legsGold.itemID)
return 7;
if (id == Item.plateGold.itemID)
return 8;
return 0;
}
/**
* A utility method used only here to tell the remaining portion of the durability of the instruments.
*/
public float getDurabilityPortion(ItemStack input) {
if (input == null)
return 1;
return 1 - input.getItemDamage() / (float) input.getMaxDamage();
}
/**
* Calculate the amount of output to be provided with the current combination. Null handled.
* The result can be nuggets or ingots, depending on the amount.
* Note that the stack size should not be zero here. Return null instead.
* Returning null would simply prevent the current fusion to process.
* No need to do matches here.
*/
@Override public ItemStack getOutput(ItemStack input1, ItemStack input2, ItemStack catalyst) {
int amount = (int) (6 *
(getNumberOfIngot(input1) * getDurabilityPortion(input1)
+ getNumberOfIngot(input2) * getDurabilityPortion(input2)));
if (amount <= 0)
return null;
if (amount <= 64)
return new ItemStack(Item.goldNugget, amount);
amount /= 9;
return new ItemStack(Item.ingotGold, amount);
}
/**
* Consume the item stacks passed in and return the according result.
* Though it is not the case here, it is suggested to call 'getOutput' at first,
* in case the stack sizes would affect the output.
* Since null is allowed in the inputs, null was handled here.
* No need to do matches here.
*/
@Override public ItemStack applyFusion(ItemStack input1, ItemStack input2, ItemStack catalyst) {
ItemStack ret = getOutput(input1, input2, catalyst);
catalyst.stackSize--;
if (input1 != null)
input1.stackSize--;
if (input2 != null)
input2.stackSize--;
return ret;
}
/**
* Tell if the item can be an input of this recipe or not.
* Null should be handled here, and has been already handled by the gold material.
*/
@Override public boolean isItemIput(ItemStack item) {
return goldMaterial.matches(item);
}
/**
* Tell if the item can be a catalyst of this recipe or not.
* Null should be handled here, and has been already handled by the coal material.
*/
@Override public boolean isItemCatalyst(ItemStack item) {
return coalMaterial.matches(item);
}
/**
* A list of the gold instruments.
* Wildcard value is applied to accept damaged instruments as well.
*/
private final List<ItemStack> items = ImmutableList.of(
new ItemStack(Item.shovelGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.swordGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.hoeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.axeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.pickaxeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.bootsGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.helmetGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.legsGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.plateGold, 1, FusionRecipes.WILDCARD_VALUE));
/**
* A custom material to represent gold instruments.
*/
public final Material goldMaterial = new Material() {
/**
* Loop through the items and matches them to the argument, allowing null in this case.
*/
@Override public boolean matches(ItemStack item) {
if (item == null)
return true;
for (ItemStack i : items)
if (FusionRecipes.matches(i, item))
return true;
return false;
}
/**
* Decrease the stack size for any items that matches at the method above. Null handled.
*/
@Override public void decrStackSize(ItemStack item) {
if (item == null)
return;
item.stackSize--;
}
/**
* Giving copies of the items, for display purpose.
* Null is included in this case as well.
*/
@Override public List<ItemStack> items() {
ArrayList<ItemStack> ret = Lists.newArrayList((ItemStack) null);
for (ItemStack i : items)
ret.add(i.copy());
return ret;
}
};
/**
* A material to represent coal.
*/
public final Material coalMaterial = Material.of(coal);
/**
* A simplified form of this customized recipe. Used below.
*/
public final BasicEntry basicEntry =
new BasicEntry(goldMaterial, goldMaterial, coalMaterial, new ItemStack(Item.goldNugget));
/**
* Return a simplified form of this customized recipe for display.
* If null is returned, this recipe will be prevented from displaying.
*/
@Override public BasicEntry basicEntry() {
return basicEntry;
}
});
* This is an example code to fully customize a recipe for the fusion furnace. @author zot
*/
/**
* Assign experience to every possible results.
*/
float exp = FurnaceRecipes.smelting().getExperience(new ItemStack(Item.ingotGold));
FusionRecipes.setExperience(new ItemStack(Item.goldNugget), exp / 9);
FusionRecipes.setExperience(new ItemStack(Item.ingotGold), exp);
/**
* Register the coal as ore, in case other mods added variations of coal.
*/
final String coal = "coal";
FusionRecipes.registerOre(coal, new ItemStack(Item.coal, 1, 0));
FusionRecipes.registerOre(coal, new ItemStack(Item.coal, 1, 1));
/**
* Use a chunk of coal as the catalyst and two gold instruments as the inputs.
* Smelt them into nuggets or ingots.
*/
FusionRecipes.getRecipeList().add(new Entry() {
/**
* Check if this recipe is applicable for the current combination.
*/
@Override public boolean matches(ItemStack input1, ItemStack input2, ItemStack catalyst) {
if (isItemCatalyst(catalyst) && isItemIput(input1) && isItemIput(input2))
return true;
return false;
}
/**
* A utility method used only here to tell the amount of ingots used in crafting the instruments.
*/
public int getNumberOfIngot(ItemStack input) {
if (input == null)
return 0;
int id = input.itemID;
if (id == Item.shovelGold.itemID)
return 1;
if (id == Item.swordGold.itemID || id == Item.hoeGold.itemID)
return 2;
if (id == Item.axeGold.itemID || id == Item.pickaxeGold.itemID)
return 3;
if (id == Item.bootsGold.itemID)
return 4;
if (id == Item.helmetGold.itemID)
return 5;
if (id == Item.legsGold.itemID)
return 7;
if (id == Item.plateGold.itemID)
return 8;
return 0;
}
/**
* A utility method used only here to tell the remaining portion of the durability of the instruments.
*/
public float getDurabilityPortion(ItemStack input) {
if (input == null)
return 1;
return 1 - input.getItemDamage() / (float) input.getMaxDamage();
}
/**
* Calculate the amount of output to be provided with the current combination. Null handled.
* The result can be nuggets or ingots, depending on the amount.
* Note that the stack size should not be zero here. Return null instead.
* Returning null would simply prevent the current fusion to process.
* No need to do matches here.
*/
@Override public ItemStack getOutput(ItemStack input1, ItemStack input2, ItemStack catalyst) {
int amount = (int) (6 *
(getNumberOfIngot(input1) * getDurabilityPortion(input1)
+ getNumberOfIngot(input2) * getDurabilityPortion(input2)));
if (amount <= 0)
return null;
if (amount <= 64)
return new ItemStack(Item.goldNugget, amount);
amount /= 9;
return new ItemStack(Item.ingotGold, amount);
}
/**
* Consume the item stacks passed in and return the according result.
* Though it is not the case here, it is suggested to call 'getOutput' at first,
* in case the stack sizes would affect the output.
* Since null is allowed in the inputs, null was handled here.
* No need to do matches here.
*/
@Override public ItemStack applyFusion(ItemStack input1, ItemStack input2, ItemStack catalyst) {
ItemStack ret = getOutput(input1, input2, catalyst);
catalyst.stackSize--;
if (input1 != null)
input1.stackSize--;
if (input2 != null)
input2.stackSize--;
return ret;
}
/**
* Tell if the item can be an input of this recipe or not.
* Null should be handled here, and has been already handled by the gold material.
*/
@Override public boolean isItemIput(ItemStack item) {
return goldMaterial.matches(item);
}
/**
* Tell if the item can be a catalyst of this recipe or not.
* Null should be handled here, and has been already handled by the coal material.
*/
@Override public boolean isItemCatalyst(ItemStack item) {
return coalMaterial.matches(item);
}
/**
* A list of the gold instruments.
* Wildcard value is applied to accept damaged instruments as well.
*/
private final List<ItemStack> items = ImmutableList.of(
new ItemStack(Item.shovelGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.swordGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.hoeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.axeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.pickaxeGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.bootsGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.helmetGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.legsGold, 1, FusionRecipes.WILDCARD_VALUE),
new ItemStack(Item.plateGold, 1, FusionRecipes.WILDCARD_VALUE));
/**
* A custom material to represent gold instruments.
*/
public final Material goldMaterial = new Material() {
/**
* Loop through the items and matches them to the argument, allowing null in this case.
*/
@Override public boolean matches(ItemStack item) {
if (item == null)
return true;
for (ItemStack i : items)
if (FusionRecipes.matches(i, item))
return true;
return false;
}
/**
* Decrease the stack size for any items that matches at the method above. Null handled.
*/
@Override public void decrStackSize(ItemStack item) {
if (item == null)
return;
item.stackSize--;
}
/**
* Giving copies of the items, for display purpose.
* Null is included in this case as well.
*/
@Override public List<ItemStack> items() {
ArrayList<ItemStack> ret = Lists.newArrayList((ItemStack) null);
for (ItemStack i : items)
ret.add(i.copy());
return ret;
}
};
/**
* A material to represent coal.
*/
public final Material coalMaterial = Material.of(coal);
/**
* A simplified form of this customized recipe. Used below.
*/
public final BasicEntry basicEntry =
new BasicEntry(goldMaterial, goldMaterial, coalMaterial, new ItemStack(Item.goldNugget));
/**
* Return a simplified form of this customized recipe for display.
* If null is returned, this recipe will be prevented from displaying.
*/
@Override public BasicEntry basicEntry() {
return basicEntry;
}
});