Advertisement
Guest User

Muramasa

a guest
Dec 20th, 2018
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.29 KB | None | 0 0
  1. package com.github.elrol.SwordsOfLegend.items;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.annotation.Nullable;
  6.  
  7. import com.github.elrol.SwordsOfLegend.SwordsOfLegend;
  8. import com.github.elrol.SwordsOfLegend.config.ConfigManager;
  9. import com.github.elrol.SwordsOfLegend.materials.ToolMaterials;
  10. import com.google.common.collect.HashMultimap;
  11. import com.google.common.collect.Multimap;
  12.  
  13. import net.minecraft.client.util.ITooltipFlag;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.entity.Entity;
  16. import net.minecraft.entity.SharedMonsterAttributes;
  17. import net.minecraft.entity.ai.attributes.AttributeModifier;
  18. import net.minecraft.inventory.EntityEquipmentSlot;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.item.ItemSword;
  21. import net.minecraft.nbt.NBTTagCompound;
  22. import net.minecraft.world.World;
  23.  
  24. public class Muramasa extends ItemSword{
  25.  
  26.     protected String name = "muramasa";
  27.     protected double souls;
  28.    
  29.     public Muramasa() {
  30.         super(ToolMaterials.muramasa);
  31.         setUnlocalizedName(name);
  32.         setRegistryName(name);
  33.     }
  34.  
  35.     public void registerItemModel() {
  36.         SwordsOfLegend.proxy.registerItemRenderer(this, 0, name);
  37.     }
  38.  
  39.     @Override
  40.     public Muramasa setCreativeTab(CreativeTabs tab) {
  41.         super.setCreativeTab(tab);
  42.         return this;
  43.     }
  44.    
  45.     @Override
  46.     public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot){
  47.         Multimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
  48.         if (equipmentSlot == EntityEquipmentSlot.MAINHAND){
  49.             multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)ToolMaterials.muramasa.getAttackDamage() + getAttackMod(), 0));
  50.             multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -3.5D + getSpeedMod(), 0));
  51.         }
  52.  
  53.         return multimap;
  54.     }
  55.    
  56.     @Override
  57.     public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) {
  58.         //Update nbt data
  59.         if(itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("souls")) {
  60.             this.souls = itemStack.getTagCompound().getInteger("souls");
  61.         } else {
  62.             itemStack.setTagCompound(new NBTTagCompound());
  63.             itemStack.getTagCompound().setInteger("souls", 0);
  64.         }
  65.        
  66.     }
  67.    
  68.     @Override
  69.     public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn){
  70.         if(stack.hasTagCompound() && stack.getTagCompound().hasKey("souls")) {
  71.             tooltip.add("Souls: " + stack.getTagCompound().getInteger("souls"));
  72.         }
  73.     }
  74.    
  75.     private double getAttackMod() {
  76.         if(souls > 0) {
  77.             if((double)(souls / ConfigManager.soulsPerDamage + super.getAttackDamage()) >= ConfigManager.maxSoulDamage) {
  78.                 return (double)ConfigManager.maxSoulDamage;
  79.             } else {
  80.                 return (double)(souls / (double)ConfigManager.soulsPerDamage);
  81.             }
  82.         } else {
  83.             return 0D;
  84.         }
  85.     }
  86.    
  87.     private double getSpeedMod() {
  88.         if(souls > 0) {
  89.             if((double)(souls / ConfigManager.soulsPerSpeed) - 3.5D >= ConfigManager.maxSoulSpeed) {
  90.                 return (double)ConfigManager.maxSoulSpeed;
  91.             } else {
  92.                 return (double)(souls / (double)ConfigManager.soulsPerSpeed);
  93.             }
  94.         } else {
  95.             return 0D;
  96.         }
  97.     }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement