Advertisement
MightyDanp

SlotArmor

Jul 7th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. package com.mightydanp.eot.core.client.gui.inventory;
  2.  
  3. import javax.swing.Icon;
  4.  
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7. import net.minecraft.inventory.Container;
  8. import net.minecraft.inventory.IInventory;
  9. import net.minecraft.inventory.Slot;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemArmor;
  12. import net.minecraft.item.ItemBlock;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.IIcon;
  15.  
  16. public class SlotArmor extends Slot
  17. {
  18. /**
  19. * The armor type that can be placed on that slot, it uses the same values
  20. * of armorType field on ItemArmor.
  21. */
  22. final int armorType;
  23.  
  24. /**
  25. * The parent class of this clot, ContainerPlayer, SlotArmor is a Anon inner
  26. * class.
  27. */
  28. final Container parent;
  29.  
  30. public SlotArmor(Container container, IInventory par2IInventory, int par3, int par4, int par5, int par6)
  31. {
  32. super(par2IInventory, par3, par4, par5);
  33. this.parent = container;
  34. this.armorType = par6;
  35. }
  36.  
  37. /**
  38. * Returns the maximum stack size for a given slot (usually the same as
  39. * getInventoryStackLimit(), but 1 in the case of armor slots)
  40. */
  41. @Override
  42. public int getSlotStackLimit ()
  43. {
  44. return 1;
  45. }
  46.  
  47. /**
  48. * Check if the stack is a valid item for this slot. Always true beside for
  49. * the armor slots.
  50. */
  51. @Override
  52. public boolean isItemValid (ItemStack par1ItemStack)
  53. {
  54. Item item = (par1ItemStack == null ? null : par1ItemStack.getItem());
  55. boolean isValidArmor = false;
  56. if (item instanceof ItemArmor)
  57. {
  58. isValidArmor = (((ItemArmor) item).armorType == armorType);
  59. }
  60. return item != null && (isValidArmor || (item instanceof ItemBlock && armorType == 0));
  61. }
  62.  
  63. @Override
  64. @SideOnly(Side.CLIENT)
  65. /**
  66. * Returns the icon index on items.png that is used as background image of the slot.
  67. */
  68. public IIcon getBackgroundIconIndex ()
  69. {
  70. return ItemArmor.func_94602_b(this.armorType);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement