2015-11-08 22:42:02 +00:00
|
|
|
package WayofTime.bloodmagic.item.armour;
|
|
|
|
|
2016-01-03 03:04:51 +00:00
|
|
|
import java.util.HashMap;
|
2016-01-05 16:12:56 +00:00
|
|
|
import java.util.List;
|
2016-01-03 03:04:51 +00:00
|
|
|
import java.util.Map;
|
2016-01-05 16:12:56 +00:00
|
|
|
import java.util.Map.Entry;
|
2016-01-03 03:04:51 +00:00
|
|
|
|
2015-11-08 22:42:02 +00:00
|
|
|
import net.minecraft.entity.Entity;
|
2016-01-02 22:07:11 +00:00
|
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
2016-01-03 03:04:51 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-11-08 22:42:02 +00:00
|
|
|
import net.minecraft.item.ItemArmor;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-01-02 22:07:11 +00:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-03 03:04:51 +00:00
|
|
|
import net.minecraft.world.World;
|
2016-01-05 16:12:56 +00:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-01-02 22:07:11 +00:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-01-05 16:12:56 +00:00
|
|
|
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
|
2016-01-02 22:07:11 +00:00
|
|
|
import WayofTime.bloodmagic.livingArmour.LivingArmour;
|
|
|
|
import WayofTime.bloodmagic.registry.ModItems;
|
2016-01-05 16:12:56 +00:00
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2016-01-02 22:07:11 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.Multimap;
|
2015-11-08 22:42:02 +00:00
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class ItemLivingArmour extends ItemArmor
|
|
|
|
{
|
|
|
|
public static String[] names = { "helmet", "chest", "legs", "boots" };
|
2015-11-08 22:42:02 +00:00
|
|
|
|
2016-01-04 14:15:15 +00:00
|
|
|
//TODO: Save/delete cache periodically.
|
2016-01-03 03:04:51 +00:00
|
|
|
public static Map<ItemStack, LivingArmour> armourMap = new HashMap<ItemStack, LivingArmour>();
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public ItemLivingArmour(int armorType)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
super(ItemArmor.ArmorMaterial.IRON, 0, armorType);
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".livingArmour.");
|
|
|
|
setMaxDamage(250);
|
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
}
|
|
|
|
|
2016-01-05 16:12:56 +00:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
|
|
|
{
|
|
|
|
if (this == ModItems.livingArmourChest)
|
|
|
|
{
|
|
|
|
LivingArmour armour = this.getLivingArmour(stack);
|
|
|
|
for (Entry<String, LivingArmourUpgrade> entry : armour.upgradeMap.entrySet())
|
|
|
|
{
|
|
|
|
LivingArmourUpgrade upgrade = entry.getValue();
|
|
|
|
if (upgrade != null)
|
|
|
|
{
|
|
|
|
tooltip.add(TextHelper.localize(upgrade.getUnlocalizedName()) + " " + TextHelper.localize("tooltip.BloodMagic.livingArmour.upgrade.level", (upgrade.getUpgradeLevel() + 1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.addInformation(stack, player, tooltip, advanced);
|
|
|
|
}
|
|
|
|
|
2015-11-29 02:25:46 +00:00
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
|
|
|
|
{
|
|
|
|
if (this == ModItems.livingArmourChest || this == ModItems.livingArmourHelmet || this == ModItems.livingArmourBoots)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
return "bloodmagic:models/armor/boundArmour_layer_1.png";
|
|
|
|
}
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (this == ModItems.livingArmourLegs)
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
return "bloodmagic:models/armor/boundArmour_layer_2.png";
|
2015-12-30 20:34:40 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-11-29 02:25:46 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-11-08 22:42:02 +00:00
|
|
|
|
2016-01-03 03:04:51 +00:00
|
|
|
@Override
|
|
|
|
public void onArmorTick(World world, EntityPlayer player, ItemStack stack)
|
|
|
|
{
|
|
|
|
super.onArmorTick(world, player, stack);
|
|
|
|
|
|
|
|
if (world.isRemote)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this == ModItems.livingArmourChest)
|
|
|
|
{
|
|
|
|
if (!armourMap.containsKey(stack))
|
|
|
|
{
|
|
|
|
armourMap.put(stack, getLivingArmour(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
LivingArmour armour = armourMap.get(stack);
|
|
|
|
armour.onTick(world, player);
|
|
|
|
setLivingArmour(stack, armour, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 22:07:11 +00:00
|
|
|
@Override
|
|
|
|
public Multimap<String, AttributeModifier> getAttributeModifiers(ItemStack stack)
|
|
|
|
{
|
|
|
|
if (this == ModItems.livingArmourChest)
|
|
|
|
{
|
|
|
|
LivingArmour armour = getLivingArmour(stack);
|
|
|
|
|
|
|
|
return armour.getAttributeModifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getAttributeModifiers(stack);
|
|
|
|
}
|
|
|
|
|
2015-11-29 02:25:46 +00:00
|
|
|
@Override
|
2015-12-30 20:34:40 +00:00
|
|
|
public String getUnlocalizedName(ItemStack stack)
|
|
|
|
{
|
2015-11-08 22:42:02 +00:00
|
|
|
return super.getUnlocalizedName(stack) + names[armorType];
|
|
|
|
}
|
2016-01-02 22:07:11 +00:00
|
|
|
|
|
|
|
public LivingArmour getLivingArmour(ItemStack stack)
|
2016-01-03 03:04:51 +00:00
|
|
|
{
|
|
|
|
NBTTagCompound livingTag = getArmourTag(stack);
|
|
|
|
|
|
|
|
LivingArmour livingArmour = new LivingArmour();
|
|
|
|
livingArmour.readFromNBT(livingTag);
|
|
|
|
|
|
|
|
return livingArmour;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLivingArmour(ItemStack stack, LivingArmour armour, boolean forceWrite)
|
|
|
|
{
|
|
|
|
NBTTagCompound livingTag = new NBTTagCompound();
|
|
|
|
|
|
|
|
if (!forceWrite)
|
|
|
|
{
|
|
|
|
livingTag = getArmourTag(stack);
|
|
|
|
armour.writeDirtyToNBT(livingTag);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
armour.writeToNBT(livingTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
setArmourTag(stack, livingTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NBTTagCompound getArmourTag(ItemStack stack)
|
2016-01-02 22:07:11 +00:00
|
|
|
{
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
{
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
2016-01-03 03:04:51 +00:00
|
|
|
return tag.getCompoundTag(Constants.NBT.LIVING_ARMOUR);
|
|
|
|
}
|
2016-01-02 22:07:11 +00:00
|
|
|
|
2016-01-03 03:04:51 +00:00
|
|
|
public void setArmourTag(ItemStack stack, NBTTagCompound livingTag)
|
|
|
|
{
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
{
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
2016-01-02 22:07:11 +00:00
|
|
|
|
2016-01-03 03:04:51 +00:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
|
|
|
|
tag.setTag(Constants.NBT.LIVING_ARMOUR, livingTag);
|
2016-01-02 22:07:11 +00:00
|
|
|
}
|
2016-01-05 16:12:56 +00:00
|
|
|
|
|
|
|
public LivingArmourUpgrade getUpgrade(String uniqueIdentifier, ItemStack stack)
|
|
|
|
{
|
|
|
|
if (!armourMap.containsKey(stack))
|
|
|
|
{
|
|
|
|
armourMap.put(stack, getLivingArmour(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
LivingArmour armour = armourMap.get(stack);
|
|
|
|
|
|
|
|
for (Entry<String, LivingArmourUpgrade> entry : armour.upgradeMap.entrySet())
|
|
|
|
{
|
|
|
|
if (entry.getKey().equals(uniqueIdentifier))
|
|
|
|
{
|
|
|
|
return entry.getValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-08 22:42:02 +00:00
|
|
|
}
|