Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cookiehook.liquidenchanting;
- import net.minecraft.block.Block;
- import net.minecraft.inventory.InventoryCrafting;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemArmor;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.MathHelper;
- import net.minecraftforge.oredict.ShapedOreRecipe;
- /**
- * A shaped recipe class that copies the item damage of the first armour ingredient to the output. The damage is clamped to the output item's damage range.
- * <p>
- * Test for this thread:
- * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2513998-help-needed-creating-crafting-recipe-with-damaged
- */
- public class ShapedArmorUpgradeRecipe extends ShapedOreRecipe {
- public ShapedArmorUpgradeRecipe(Block result, Object... recipe) {
- super(result, recipe);
- }
- public ShapedArmorUpgradeRecipe(Item result, Object... recipe) {
- super(result, recipe);
- }
- public ShapedArmorUpgradeRecipe(ItemStack result, Object... recipe) {
- super(result, recipe);
- }
- @Override
- public ItemStack getCraftingResult(InventoryCrafting inv) {
- ItemStack output = super.getCraftingResult(inv); // Get the default output
- for (int i = 0; i < inv.getSizeInventory(); i++) { // For each slot in the crafting inventory,
- ItemStack ingredient = inv.getStackInSlot(i); // Get the ingredient in the slot
- if (ingredient != null && ingredient.getItem() instanceof ItemArmor || ingredient.getItem() instanceof ItemSword)
- { // If it's an armour/sword item,
- // Clone its item damage, clamping it to the output's damage range
- int newDamage = MathHelper.clamp_int(ingredient.getItemDamage(), 0, output.getMaxDamage());
- output.setItemDamage(newDamage);
- NBTTagCompound enchant = ingredient.getTagCompound();
- output.setTagCompound(enchant);
- break; // Break now
- }
- }
- return output; // Return the modified output
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement