Camellias_

Untitled

Jun 2nd, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package com.camellias.voidaicarcania.items.baubles.amulets;
  2.  
  3. import com.camellias.voidaicarcania.Main;
  4. import com.camellias.voidaicarcania.init.ModItems;
  5. import com.camellias.voidaicarcania.util.IHasModel;
  6.  
  7. import baubles.api.BaubleType;
  8. import baubles.api.BaublesApi;
  9. import baubles.api.IBauble;
  10. import baubles.api.cap.IBaublesItemHandler;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.SharedMonsterAttributes;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.init.Items;
  16. import net.minecraft.item.Item;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.util.ActionResult;
  19. import net.minecraft.util.DamageSource;
  20. import net.minecraft.util.EnumActionResult;
  21. import net.minecraft.util.EnumHand;
  22. import net.minecraft.world.World;
  23. import net.minecraftforge.event.entity.living.LivingHurtEvent;
  24. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  25.  
  26. public class ItemShieldAmulet extends Item implements IHasModel, IBauble
  27. {
  28.     public ItemShieldAmulet(String name)
  29.     {
  30.         this.setUnlocalizedName(name);
  31.         this.setRegistryName(name);
  32.         this.setCreativeTab(Main.voidictab);
  33.         this.maxStackSize = 1;
  34.         this.setMaxDamage(5);
  35.        
  36.         ModItems.ITEMS.add(this);
  37.     }
  38.  
  39.     @Override
  40.     public BaubleType getBaubleType(ItemStack itemstack)
  41.     {
  42.         return BaubleType.AMULET;
  43.     }
  44.    
  45.     @Override
  46.     public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
  47.     {
  48.         if(stack.getItemDamage() <= 4 && entity.ticksExisted % 100 == 0)
  49.         {
  50.             stack.setItemDamage(stack.getItemDamage() - 1);
  51.         }
  52.     }
  53.    
  54.     @Override
  55.     public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
  56.     {
  57.         if(!world.isRemote)
  58.         {
  59.             IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
  60.            
  61.             for(int i = 0; i < baubles.getSlots(); i++)
  62.             {
  63.                 if((baubles.getStackInSlot(i) == null || baubles.getStackInSlot(i).isEmpty()) &&
  64.                         baubles.isItemValidForSlot(i, player.getHeldItem(hand), player))
  65.                 {
  66.                     baubles.setStackInSlot(i, player.getHeldItem(hand).copy());
  67.                    
  68.                     if(!player.capabilities.isCreativeMode)
  69.                     {
  70.                         player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
  71.                     }
  72.                     onEquipped(player.getHeldItem(hand), player);
  73.                     break;
  74.                 }
  75.             }
  76.         }
  77.         return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  78.     }
  79.    
  80.     @Override
  81.     public void onWornTick(ItemStack stack, EntityLivingBase player)
  82.     {
  83.         if(this.getDamage(new ItemStack(this)) > 0)
  84.         {
  85.             this.setDamage(new ItemStack(this), this.getMaxDamage() - 1);
  86.         }
  87.        
  88.         if(this.getDamage(new ItemStack(this)) == 0)
  89.         {
  90.            
  91.         }
  92.     }
  93.    
  94.     @SubscribeEvent
  95.     public void onPlayerHurt(LivingHurtEvent event)
  96.     {
  97.         if(event.getEntityLiving() instanceof EntityPlayer)
  98.         {
  99.             EntityPlayer player = (EntityPlayer) event.getEntityLiving();
  100.            
  101.             if(BaublesApi.isBaubleEquipped(player, this))
  102.             {
  103.                
  104.             }
  105.         }
  106.     }
  107.    
  108.     @Override
  109.     public void onEquipped(ItemStack itemstack, EntityLivingBase player)
  110.     {
  111.         player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(player.getMaxHealth() - 2);
  112.     }
  113.    
  114.     @Override
  115.     public void onUnequipped(ItemStack itemstack, EntityLivingBase player)
  116.     {
  117.         player.setEntityInvulnerable(false);
  118.         player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(player.getMaxHealth() + 2);
  119.     }
  120.    
  121.     @Override
  122.     public void registerModels()
  123.     {
  124.         Main.proxy.registerItemRenderer(this, 0, "inventory");
  125.     }
  126.    
  127.     public static boolean isUsable(ItemStack stack)
  128.     {
  129.         return stack.getItemDamage() < stack.getMaxDamage() - 1;
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment