Added Living Armour stat tracker for movement. Implemented necessary methods for the armour.
This commit is contained in:
parent
5387770fa6
commit
34335d66cc
6 changed files with 175 additions and 11 deletions
|
@ -1,10 +1,15 @@
|
|||
package WayofTime.bloodmagic.item.armour;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.livingArmour.LivingArmour;
|
||||
|
@ -16,6 +21,8 @@ public class ItemLivingArmour extends ItemArmor
|
|||
{
|
||||
public static String[] names = { "helmet", "chest", "legs", "boots" };
|
||||
|
||||
public static Map<ItemStack, LivingArmour> armourMap = new HashMap<ItemStack, LivingArmour>();
|
||||
|
||||
public ItemLivingArmour(int armorType)
|
||||
{
|
||||
super(ItemArmor.ArmorMaterial.IRON, 0, armorType);
|
||||
|
@ -41,6 +48,29 @@ public class ItemLivingArmour extends ItemArmor
|
|||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap<String, AttributeModifier> getAttributeModifiers(ItemStack stack)
|
||||
{
|
||||
|
@ -62,17 +92,51 @@ public class ItemLivingArmour extends ItemArmor
|
|||
|
||||
public LivingArmour getLivingArmour(ItemStack stack)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
NBTTagCompound livingTag = tag.getCompoundTag(Constants.NBT.LIVING_ARMOUR);
|
||||
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)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
return tag.getCompoundTag(Constants.NBT.LIVING_ARMOUR);
|
||||
}
|
||||
|
||||
public void setArmourTag(ItemStack stack, NBTTagCompound livingTag)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
tag.setTag(Constants.NBT.LIVING_ARMOUR, livingTag);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue