Advertisement
Guest User

ShapedArmourUpgradeRecipe

a guest
Aug 30th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package com.cookiehook.liquidenchanting;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.inventory.InventoryCrafting;
  5. import net.minecraft.item.Item;
  6. import net.minecraft.item.ItemArmor;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.item.ItemSword;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.util.MathHelper;
  11. import net.minecraftforge.oredict.ShapedOreRecipe;
  12.  
  13. /**
  14. * 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.
  15. * <p>
  16. * Test for this thread:
  17. * http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2513998-help-needed-creating-crafting-recipe-with-damaged
  18. */
  19. public class ShapedArmorUpgradeRecipe extends ShapedOreRecipe {
  20. public ShapedArmorUpgradeRecipe(Block result, Object... recipe) {
  21. super(result, recipe);
  22. }
  23.  
  24. public ShapedArmorUpgradeRecipe(Item result, Object... recipe) {
  25. super(result, recipe);
  26. }
  27.  
  28. public ShapedArmorUpgradeRecipe(ItemStack result, Object... recipe) {
  29. super(result, recipe);
  30. }
  31.  
  32. @Override
  33. public ItemStack getCraftingResult(InventoryCrafting inv) {
  34. ItemStack output = super.getCraftingResult(inv); // Get the default output
  35.  
  36. for (int i = 0; i < inv.getSizeInventory(); i++) { // For each slot in the crafting inventory,
  37. ItemStack ingredient = inv.getStackInSlot(i); // Get the ingredient in the slot
  38.  
  39.  
  40. if (ingredient != null && ingredient.getItem() instanceof ItemArmor || ingredient.getItem() instanceof ItemSword)
  41. { // If it's an armour/sword item,
  42. // Clone its item damage, clamping it to the output's damage range
  43. int newDamage = MathHelper.clamp_int(ingredient.getItemDamage(), 0, output.getMaxDamage());
  44. output.setItemDamage(newDamage);
  45. NBTTagCompound enchant = ingredient.getTagCompound();
  46. output.setTagCompound(enchant);
  47. break; // Break now
  48. }
  49.  
  50. }
  51.  
  52. return output; // Return the modified output
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement