Added Living Armour stat tracker for movement. Implemented necessary methods for the armour.
This commit is contained in:
parent
5387770fa6
commit
34335d66cc
|
@ -17,6 +17,7 @@ import WayofTime.bloodmagic.api.Constants;
|
|||
import WayofTime.bloodmagic.api.util.helper.LogHelper;
|
||||
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
|
||||
import WayofTime.bloodmagic.proxy.CommonProxy;
|
||||
import WayofTime.bloodmagic.registry.ModArmourTrackers;
|
||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import WayofTime.bloodmagic.registry.ModCompatibility;
|
||||
import WayofTime.bloodmagic.registry.ModEntities;
|
||||
|
@ -73,6 +74,7 @@ public class BloodMagic
|
|||
ModRituals.initRituals();
|
||||
ModRituals.initImperfectRituals();
|
||||
ModCompatibility.registerModCompat();
|
||||
ModArmourTrackers.init();
|
||||
ConfigHandler.checkRituals();
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(BloodMagic.instance, new GuiHandler());
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
|
||||
public class LivingArmourHandler
|
||||
{
|
||||
public static List<Class<? extends StatTracker>> trackers = new ArrayList();
|
||||
public static HashMap<String, Class<? extends LivingArmourUpgrade>> upgradeMap = new HashMap();
|
||||
public static HashMap<String, Constructor<? extends LivingArmourUpgrade>> upgradeConstructorMap = new HashMap();
|
||||
public static List<Class<? extends StatTracker>> trackers = new ArrayList<Class<? extends StatTracker>>();
|
||||
public static HashMap<String, Class<? extends LivingArmourUpgrade>> upgradeMap = new HashMap<String, Class<? extends LivingArmourUpgrade>>();
|
||||
public static HashMap<String, Constructor<? extends LivingArmourUpgrade>> upgradeConstructorMap = new HashMap<String, Constructor<? extends LivingArmourUpgrade>>();
|
||||
|
||||
public static void registerStatTracker(Class<? extends StatTracker> tracker)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package WayofTime.bloodmagic.api.livingArmour;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -35,7 +37,7 @@ public abstract class StatTracker
|
|||
*/
|
||||
public abstract boolean onTick(World world, EntityPlayer player, LivingArmour livingArmour);
|
||||
|
||||
public abstract LivingArmourUpgrade[] getUpgrades();
|
||||
public abstract List<LivingArmourUpgrade> getUpgrades();
|
||||
|
||||
public final boolean isDirty()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package WayofTime.bloodmagic.livingArmour;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
|
||||
import WayofTime.bloodmagic.api.livingArmour.StatTracker;
|
||||
|
||||
public class StatTrackerMovement extends StatTracker
|
||||
{
|
||||
public static Map<EntityPlayer, Double> lastPosX = new HashMap<EntityPlayer, Double>();
|
||||
public static Map<EntityPlayer, Double> lastPosZ = new HashMap<EntityPlayer, Double>();
|
||||
|
||||
public double totalMovement = 0;
|
||||
|
||||
@Override
|
||||
public String getUniqueIdentifier()
|
||||
{
|
||||
return Constants.Mod.MODID + ".tracker.movement";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTracker()
|
||||
{
|
||||
this.totalMovement = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
totalMovement = tag.getDouble(Constants.Mod.MODID + ".tracker.movement");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
tag.setDouble(Constants.Mod.MODID + ".tracker.movement", totalMovement);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTick(World world, EntityPlayer player, LivingArmour livingArmour)
|
||||
{
|
||||
if (!lastPosX.containsKey(player))
|
||||
{
|
||||
lastPosX.put(player, player.posX);
|
||||
lastPosZ.put(player, player.posZ);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.isAirBorne)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double distanceTravelled = Math.sqrt(Math.pow(lastPosX.get(player) - player.posX, 2) + Math.pow(lastPosZ.get(player) - player.posZ, 2));
|
||||
|
||||
if (distanceTravelled > 0.0001)
|
||||
{
|
||||
totalMovement += distanceTravelled;
|
||||
|
||||
lastPosX.put(player, player.posX);
|
||||
lastPosZ.put(player, player.posZ);
|
||||
|
||||
markDirty();
|
||||
}
|
||||
|
||||
// System.out.println("Total movement since activated: " + totalMovement);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LivingArmourUpgrade> getUpgrades()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<LivingArmourUpgrade>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package WayofTime.bloodmagic.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.livingArmour.LivingArmourHandler;
|
||||
import WayofTime.bloodmagic.livingArmour.StatTrackerMovement;
|
||||
|
||||
public class ModArmourTrackers
|
||||
{
|
||||
public static void init()
|
||||
{
|
||||
LivingArmourHandler.registerStatTracker(StatTrackerMovement.class);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue