From 3edfc3a8ac755fa40e7c0df7b5838472ddd71646 Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sat, 9 Jan 2016 15:05:41 -0500 Subject: [PATCH] Some work on the armour --- .../item/armour/ItemSentientArmour.java | 66 ++++++++++-- .../item/soul/ItemSentientArmourGem.java | 97 ++++++++++++++++++ .../bloodmagic/registry/ModItems.java | 5 + .../models/item/ItemSentientArmourGem0.json | 11 ++ .../models/item/ItemSentientArmourGem1.json | 12 +++ .../items/SentientArmourGem_activated.png | Bin 0 -> 475 bytes .../items/SentientArmourGem_deactivated.png | Bin 0 -> 472 bytes 7 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java create mode 100644 src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem0.json create mode 100644 src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem1.json create mode 100644 src/main/resources/assets/bloodmagic/textures/items/SentientArmourGem_activated.png create mode 100644 src/main/resources/assets/bloodmagic/textures/items/SentientArmourGem_deactivated.png diff --git a/src/main/java/WayofTime/bloodmagic/item/armour/ItemSentientArmour.java b/src/main/java/WayofTime/bloodmagic/item/armour/ItemSentientArmour.java index 7b7acf18..0d7bc76d 100644 --- a/src/main/java/WayofTime/bloodmagic/item/armour/ItemSentientArmour.java +++ b/src/main/java/WayofTime/bloodmagic/item/armour/ItemSentientArmour.java @@ -15,6 +15,8 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler; +import WayofTime.bloodmagic.api.util.helper.NBTHelper; import WayofTime.bloodmagic.registry.ModItems; public class ItemSentientArmour extends ItemArmor implements ISpecialArmor @@ -78,6 +80,7 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor if (helmet.getItem() instanceof ItemSentientArmour && leggings.getItem() instanceof ItemSentientArmour && boots.getItem() instanceof ItemSentientArmour) { double remainder = 1; // Multiply this number by the armour upgrades for protection + remainder *= (1 - this.getArmourModifier(stack)); armourReduction = armourReduction + (1 - remainder) * (1 - armourReduction); damageAmount *= (armourReduction); @@ -131,14 +134,27 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor @Override public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) { - return; // Armour shouldn't get damaged... for now + if (entity instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) entity; + + double willRequired = this.getCostModifier(stack) * damage; + double willLeft = PlayerDemonWillHandler.getTotalDemonWill(player); + if (willLeft >= willRequired) + { + PlayerDemonWillHandler.consumeDemonWill(player, willRequired); + } else + { + this.revertArmour(player, stack); + } + } + return; } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { - super.addInformation(stack, player, tooltip, advanced); } @@ -168,8 +184,38 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor { return; } + } - //TODO: Consume will - if the will drops to 0, return the contained item + public double getCostModifier(ItemStack stack) + { + NBTHelper.checkNBT(stack); + NBTTagCompound tag = stack.getTagCompound(); + + return tag.getDouble("costModifier"); + } + + public void setCostModifier(ItemStack stack, double modifier) + { + NBTHelper.checkNBT(stack); + NBTTagCompound tag = stack.getTagCompound(); + + tag.setDouble("costModifier", modifier); + } + + public double getArmourModifier(ItemStack stack) + { + NBTHelper.checkNBT(stack); + NBTTagCompound tag = stack.getTagCompound(); + + return tag.getDouble("armourModifier"); + } + + public void setArmourModifier(ItemStack stack, double modifier) + { + NBTHelper.checkNBT(stack); + NBTTagCompound tag = stack.getTagCompound(); + + tag.setDouble("armourModifier", modifier); } @Override @@ -230,7 +276,7 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor return armourStack; } - public static boolean convertPlayerArmour(EntityPlayer player) + public static boolean convertPlayerArmour(EntityPlayer player, double recurringCost, double protection) { ItemStack[] armours = player.inventory.armorInventory; @@ -240,10 +286,10 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor ItemStack bootsStack = armours[0]; { - ItemStack omegaHelmetStack = ((ItemSentientArmour) ModItems.sentientArmourHelmet).getSubstituteStack(helmetStack); - ItemStack omegaChestStack = ((ItemSentientArmour) ModItems.sentientArmourChest).getSubstituteStack(chestStack); - ItemStack omegaLeggingsStack = ((ItemSentientArmour) ModItems.sentientArmourLegs).getSubstituteStack(leggingsStack); - ItemStack omegaBootsStack = ((ItemSentientArmour) ModItems.sentientArmourBoots).getSubstituteStack(bootsStack); + ItemStack omegaHelmetStack = ((ItemSentientArmour) ModItems.sentientArmourHelmet).getSubstituteStack(helmetStack, recurringCost, protection); + ItemStack omegaChestStack = ((ItemSentientArmour) ModItems.sentientArmourChest).getSubstituteStack(chestStack, recurringCost, protection); + ItemStack omegaLeggingsStack = ((ItemSentientArmour) ModItems.sentientArmourLegs).getSubstituteStack(leggingsStack, recurringCost, protection); + ItemStack omegaBootsStack = ((ItemSentientArmour) ModItems.sentientArmourBoots).getSubstituteStack(bootsStack, recurringCost, protection); armours[3] = omegaHelmetStack; armours[2] = omegaChestStack; @@ -254,11 +300,13 @@ public class ItemSentientArmour extends ItemArmor implements ISpecialArmor } } - public ItemStack getSubstituteStack(ItemStack previousArmour) + public ItemStack getSubstituteStack(ItemStack previousArmour, double recurringCost, double protection) { ItemStack newArmour = new ItemStack(this); this.setContainedArmourStack(newArmour, previousArmour); + this.setCostModifier(newArmour, recurringCost); + this.setArmourModifier(newArmour, protection); return newArmour; } diff --git a/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java new file mode 100644 index 00000000..dff4be0d --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/item/soul/ItemSentientArmourGem.java @@ -0,0 +1,97 @@ +package WayofTime.bloodmagic.item.soul; + +import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.soul.PlayerDemonWillHandler; +import WayofTime.bloodmagic.item.armour.ItemSentientArmour; + +public class ItemSentientArmourGem extends Item +{ + public static double[] willBracket = new double[] { 30, 200, 600, 1500, 4000, 6000, 8000 }; + public static double[] consumptionPerHit = new double[] { 0.1, 0.12, 0.15, 0.2, 0.3, 0.35, 0.4 }; + public static double[] extraProtectionLevel = new double[] { 0, 0.25, 0.5, 0.6, 0.7, 0.75, 0.85 }; + + public ItemSentientArmourGem() + { + super(); + + this.setCreativeTab(BloodMagic.tabBloodMagic); + setUnlocalizedName(Constants.Mod.MODID + ".sentientArmourGem"); + this.setMaxStackSize(1); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + boolean hasSentientArmour = false; + ItemStack[] armourInventory = player.inventory.armorInventory; + for (ItemStack armourStack : armourInventory) + { + if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour) + { + hasSentientArmour = true; + } + } + + if (hasSentientArmour) + { + ItemSentientArmour.revertAllArmour(player); + } else + { + double will = PlayerDemonWillHandler.getTotalDemonWill(player); + + int bracket = getWillBracket(will); + + if (bracket >= 0) + { + PlayerDemonWillHandler.consumeDemonWill(player, willBracket[bracket]); + ItemSentientArmour.convertPlayerArmour(player, consumptionPerHit[bracket], extraProtectionLevel[bracket]); + } + } + + return stack; + } + + public int getWillBracket(double will) + { + int bracket = -1; + + for (int i = 0; i < willBracket.length; i++) + { + if (will >= willBracket[i]) + { + bracket = i; + } + } + + return bracket; + } + + @SideOnly(Side.CLIENT) + public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) + { + boolean hasSentientArmour = false; + ItemStack[] armourInventory = player.inventory.armorInventory; + for (ItemStack armourStack : armourInventory) + { + if (armourStack != null && armourStack.getItem() instanceof ItemSentientArmour) + { + hasSentientArmour = true; + } + } + + if (hasSentientArmour) + { + return new ModelResourceLocation("bloodmagic:ItemSentientArmourGem1", "inventory"); + } + + return null; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModItems.java b/src/main/java/WayofTime/bloodmagic/registry/ModItems.java index 0c48af42..229f6b04 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModItems.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModItems.java @@ -48,6 +48,7 @@ import WayofTime.bloodmagic.item.sigil.ItemSigilVoid; import WayofTime.bloodmagic.item.sigil.ItemSigilWater; import WayofTime.bloodmagic.item.sigil.ItemSigilWhirlwind; import WayofTime.bloodmagic.item.soul.ItemMonsterSoul; +import WayofTime.bloodmagic.item.soul.ItemSentientArmourGem; import WayofTime.bloodmagic.item.soul.ItemSentientBow; import WayofTime.bloodmagic.item.soul.ItemSentientSword; import WayofTime.bloodmagic.item.soul.ItemSoulGem; @@ -125,6 +126,7 @@ public class ModItems public static Item sentientSword; public static Item sentientBow; + public static Item sentientArmourGem; public static Item.ToolMaterial boundToolMaterial = EnumHelper.addToolMaterial("BoundToolMaterial", 4, 0, 10, 8, 50); public static Item.ToolMaterial soulToolMaterial = EnumHelper.addToolMaterial("SoulToolMaterial", 4, 0, 7, 8, 50); @@ -208,6 +210,7 @@ public class ModItems sentientSword = registerItem(new ItemSentientSword()); sentientBow = registerItem(new ItemSentientBow()); + sentientArmourGem = registerItem(new ItemSentientArmourGem()); } public static void initRenders() @@ -326,6 +329,8 @@ public class ModItems renderHelper.itemRender(sentientBow, 2, "ItemSentientBow_pulling_1"); renderHelper.itemRender(sentientBow, 3, "ItemSentientBow_pulling_2"); + renderHelper.itemRender(sentientArmourGem, 0, "ItemSentientArmourGem0"); + renderHelper.itemRender(sentientArmourGem, 1, "ItemSentientArmourGem1"); } private static Item registerItem(Item item, String name) diff --git a/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem0.json b/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem0.json new file mode 100644 index 00000000..60cf7592 --- /dev/null +++ b/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem0.json @@ -0,0 +1,11 @@ +{ + "parent":"bloodmagic:item/ItemModelBase", + "textures": { + "layer0":"bloodmagic:items/SentientArmourGem_deactivated" + } +} + + + + + diff --git a/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem1.json b/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem1.json new file mode 100644 index 00000000..5998ca9e --- /dev/null +++ b/src/main/resources/assets/bloodmagic/models/item/ItemSentientArmourGem1.json @@ -0,0 +1,12 @@ +{ + "parent":"bloodmagic:item/ItemModelBase", + "textures": { + "layer0":"bloodmagic:items/SentientArmourGem_activated" + } +} + + + + + + diff --git a/src/main/resources/assets/bloodmagic/textures/items/SentientArmourGem_activated.png b/src/main/resources/assets/bloodmagic/textures/items/SentientArmourGem_activated.png new file mode 100644 index 0000000000000000000000000000000000000000..0ae2ddb90073abf0caa2355f80f744be59c50793 GIT binary patch literal 475 zcmV<10VMv3P)=v;$ zgAhv%*V~&m=5)A8+Qd{8ec{02{rf!Uc~7L2{EJ;%c61_iBK)a8yPN=<=piB&pgkdG zc@?TD@<=J^MA)1r?ovk{e`a__Iii2e(ZhM89uB5W7AWkJ-22G0L;62zd?ypun{@W* z>|G34rqG*R?%rg-pcQqrk%&Z|t$f6osSpv#(=YTZii&1Kdt(a}uXo5AlqVD=!>*K4 z{HnqP$0Kg6X>V-#HhQ7|{<(H{oAJ0V{;iA$1$i*8QC0f`<%h3z?C3kKW__-taOWL@ zJZJJ#`_apq!mI7tf4xC5;_$(oLR{X&h)8a|VSSD9ge6P)s&xYu38+JK8t zYq(8s+IWwPo1{&efTFV+X1@9Jo%v3rl>CcbTMl$0bRzs|Ji82lZS)Wk3#&aRX1EgN zbn{3l=|tF`0{5sh&%QD|XEdgN%+cd{qaF^XO%^EZk=*~pt3&!H^?s)nn@u|VboMU> zEK}&soO?IH5i>zj2L#Ml;Y|Y zDjbiwv7x=SqkQqi=+Ry6?k>`59bu(vJxXAx%HmS4JH*?R+DUIv~va{zC4&0U!?%$8Ci~0 z^FE(2I9n^_SpExh1>XL^sJuuFyRa~QWdmqM7%vH?Nt7$F@!x;r-`a2eIg?W=+4!0O O0000