From d44ecc2c388df6860a35ff132862129aa9f84899 Mon Sep 17 00:00:00 2001 From: Zereff06 Date: Mon, 13 Feb 2023 23:00:33 +0200 Subject: [PATCH] mage's mace-> increase performance and damage + base damage is 30. Staff with full upgrade have 100 damage. Other max have 61 damage + potency give +20% damage as it should + staff give 1.5x damage + damage settings in config + increase vis consume + fix boodlust icon and vis consume with bloodlust + some code refactoring --- .../common/handler/ConfigHandler.java | 16 ++ .../handler/TaintedMagicEventHandler.java | 187 ++++++++---------- .../common/helper/TaintedMagicHelper.java | 19 ++ .../items/wand/foci/ItemFocusMageMace.java | 43 ++-- 4 files changed, 143 insertions(+), 122 deletions(-) diff --git a/src/main/java/taintedmagic/common/handler/ConfigHandler.java b/src/main/java/taintedmagic/common/handler/ConfigHandler.java index f4bc588..99e3770 100644 --- a/src/main/java/taintedmagic/common/handler/ConfigHandler.java +++ b/src/main/java/taintedmagic/common/handler/ConfigHandler.java @@ -11,6 +11,8 @@ public class ConfigHandler { public static boolean useUpdateHandler = true; public static boolean researchTags = true; public static boolean useCustomResearchTabBackground = false; + public static int magesMaceBaseDamage; + public static float magesMaceStaffMultiple; public static void init() { TaintedMagic.log.info("Loading config"); @@ -29,6 +31,20 @@ public class ConfigHandler { "research", false, "Setting this to true will enable the old custom tab background"); + magesMaceBaseDamage = config.getInt( + "mages_mace_base_damage", + "foci", + 30, + 1, + 300, + "Set damage for Mage's Mace foci. Staff get x2 damage"); + magesMaceStaffMultiple = config.getFloat( + "mages_mace_staff_multiple", + "foci", + 1.5f, + 1, + 5, + "Set damage multiplier for Staff with Mage's Mace"); config.save(); } diff --git a/src/main/java/taintedmagic/common/handler/TaintedMagicEventHandler.java b/src/main/java/taintedmagic/common/handler/TaintedMagicEventHandler.java index ca66e57..9838e28 100644 --- a/src/main/java/taintedmagic/common/handler/TaintedMagicEventHandler.java +++ b/src/main/java/taintedmagic/common/handler/TaintedMagicEventHandler.java @@ -1,5 +1,7 @@ package taintedmagic.common.handler; +import static taintedmagic.common.helper.TaintedMagicHelper.getWandDamageWithPotency; + import java.util.Random; import java.util.UUID; @@ -9,7 +11,6 @@ import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -26,11 +27,8 @@ import taintedmagic.api.IBloodlust; import taintedmagic.common.items.wand.foci.ItemFocusMageMace; import taintedmagic.common.registry.ItemRegistry; import thaumcraft.api.ThaumcraftApiHelper; -import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.aspects.AspectList; import thaumcraft.api.wands.ItemFocusBasic; import thaumcraft.api.wands.StaffRod; -import thaumcraft.api.wands.WandRod; import thaumcraft.common.Thaumcraft; import thaumcraft.common.config.Config; import thaumcraft.common.config.ConfigItems; @@ -49,128 +47,115 @@ public class TaintedMagicEventHandler { @SubscribeEvent public void livingTick(LivingEvent.LivingUpdateEvent event) { if (event.entity instanceof EntityPlayer) { - EntityPlayer p = (EntityPlayer) event.entity; - updateAttackDamage(p); + EntityPlayer player = (EntityPlayer) event.entity; - for (int i = 0; i < p.inventory.getSizeInventory(); i++) { - if (p.inventory.getStackInSlot(i) != null && p.inventory.getStackInSlot(i).stackTagCompound != null - && p.inventory.getStackInSlot(i).stackTagCompound.getBoolean("voidtouched")) { - ItemStack s = p.inventory.getStackInSlot(i); - if (!p.worldObj.isRemote && s.isItemDamaged() && p.ticksExisted % 20 == 0) - s.damageItem(-1, (EntityLivingBase) p); + if ((player.ticksExisted + 6) % 20 == 0 && !player.worldObj.isRemote) { + updateAttackDamage(player); + + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { + if (player.inventory.getStackInSlot(i) != null + && player.inventory.getStackInSlot(i).stackTagCompound != null + && player.inventory.getStackInSlot(i).stackTagCompound.getBoolean("voidtouched")) { + ItemStack stack = player.inventory.getStackInSlot(i); + if (stack.isItemDamaged()) stack.damageItem(-1, (EntityLivingBase) player); + } } } } } /* - * Used to upate the attack damage for the Mage's Mace focus + * Used to update the attack damage for the Mage's Mace focus */ - public void updateAttackDamage(EntityPlayer p) { - if (!p.worldObj.isRemote) { - IInventory inv = p.inventory; + private void updateAttackDamage(EntityPlayer player) { + ItemStack stack = player.getHeldItem(); + if (stack != null && stack.getItem() instanceof ItemWandCasting) { + final ItemWandCasting wand = (ItemWandCasting) stack.getItem(); + boolean isMageMaceActive; + int countOfPotency; + int newDamage; - for (int i = 0; i < inv.getSizeInventory(); i++) { - if (inv.getStackInSlot(i) != null && inv.getStackInSlot(i).getItem() instanceof ItemWandCasting) { - ItemStack s = inv.getStackInSlot(i); - ItemWandCasting wand = (ItemWandCasting) inv.getStackInSlot(i).getItem(); + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("MageMace")) { + isMageMaceActive = stack.getTagCompound().getCompoundTag("MageMace").getBoolean("isMageMaceActive"); + countOfPotency = stack.getTagCompound().getCompoundTag("MageMace").getInteger("potency"); + } else { + isMageMaceActive = false; + countOfPotency = 0; + } - if (wand.getFocus(s) != null && wand.getFocus(s) == ItemRegistry.ItemFocusMageMace - && wand.getRod(s) instanceof WandRod) { - NBTTagList tags = new NBTTagList(); - NBTTagCompound tag = new NBTTagCompound(); - tag.setString( - "AttributeName", - SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); + // set new damage + if (wand.getFocus(stack) == ItemRegistry.ItemFocusMageMace + && (!isMageMaceActive || countOfPotency != wand.getFocusPotency(stack))) { + if (wand.getRod(stack) instanceof StaffRod) + newDamage = (int) (getWandDamageWithPotency(stack, ConfigHandler.magesMaceBaseDamage) + * ConfigHandler.magesMaceStaffMultiple); + else newDamage = getWandDamageWithPotency(stack, ConfigHandler.magesMaceBaseDamage); - UUID u = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - AttributeModifier am = new AttributeModifier( - u, - "Weapon modifier", - 15.0D + wand.getFocusPotency(s), - 0); - - tag.setString("Name", am.getName()); - tag.setDouble("Amount", am.getAmount()); - tag.setInteger("Operation", am.getOperation()); - tag.setLong("UUIDMost", am.getID().getMostSignificantBits()); - tag.setLong("UUIDLeast", am.getID().getLeastSignificantBits()); - - tags.appendTag(tag); - s.stackTagCompound.setTag("AttributeModifiers", tags); - } else if (wand.getRod(s) instanceof WandRod) { - if (!s.hasTagCompound()) { - s.setTagCompound(new NBTTagCompound()); - } - s.stackTagCompound.removeTag("AttributeModifiers"); - } - if (wand.getFocus(s) != null && wand.getFocus(s) == ItemRegistry.ItemFocusMageMace - && wand.getRod(s) instanceof StaffRod) { - NBTTagList tags = new NBTTagList(); - NBTTagCompound tag = new NBTTagCompound(); - tag.setString( - "AttributeName", - SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); - - UUID u = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - AttributeModifier am = new AttributeModifier( - u, - "Weapon modifier", - 21.0D + wand.getFocusPotency(s), - 0); - - tag.setString("Name", am.getName()); - tag.setDouble("Amount", am.getAmount()); - tag.setInteger("Operation", am.getOperation()); - tag.setLong("UUIDMost", am.getID().getMostSignificantBits()); - tag.setLong("UUIDLeast", am.getID().getLeastSignificantBits()); - - tags.appendTag(tag); - s.stackTagCompound.setTag("AttributeModifiers", tags); - } else if (wand.getRod(s) instanceof StaffRod) { - NBTTagList tags = new NBTTagList(); - NBTTagCompound tag = new NBTTagCompound(); - tag.setString( - "AttributeName", - SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); - - UUID u = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - AttributeModifier am = new AttributeModifier(u, "Weapon modifier", 6.0D, 0); - - tag.setString("Name", am.getName()); - tag.setDouble("Amount", am.getAmount()); - tag.setInteger("Operation", am.getOperation()); - tag.setLong("UUIDMost", am.getID().getMostSignificantBits()); - tag.setLong("UUIDLeast", am.getID().getLeastSignificantBits()); - - tags.appendTag(tag); - s.stackTagCompound.setTag("AttributeModifiers", tags); - } - } + setDamage(stack, newDamage, wand.getFocusPotency(stack)); + stack.stackTagCompound.getCompoundTag("MageMace").setBoolean("isMageMaceActive", true); + stack.stackTagCompound.getCompoundTag("MageMace").setInteger("potency", wand.getFocusPotency(stack)); + } + // set base damage + else if (isMageMaceActive && wand.getFocus(stack) != ItemRegistry.ItemFocusMageMace) { + if (wand.getRod(stack) instanceof StaffRod) resetDamage(stack, 6); + else resetDamage(stack, 0); } } } + private void resetDamage(ItemStack stack, int damage) { + setDamage(stack, damage, 0); + stack.stackTagCompound.getCompoundTag("MageMace").setBoolean("isMageMaceActive", false); + stack.stackTagCompound.getCompoundTag("MageMace").setInteger("potency", 0); + } + + private void setDamage(ItemStack stack, int newDamage, int potency) { + + if (stack.hasTagCompound() && !stack.stackTagCompound.hasKey("MageMace")) { + NBTTagCompound tagMageMace = new NBTTagCompound(); + tagMageMace.setBoolean("isMageMaceActive", true); + tagMageMace.setInteger("countOfPotency", potency); + stack.stackTagCompound.setTag("MageMace", tagMageMace); + } else stack.stackTagCompound.getCompoundTag("MageMace").setBoolean("isMageMaceActive", true); + + NBTTagCompound tag = new NBTTagCompound(); + NBTTagList tags = new NBTTagList(); + tag.setString("AttributeName", SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()); + UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); + AttributeModifier modifier = new AttributeModifier(uuid, "Weapon modifier", newDamage, 0); + + tag.setString("Name", modifier.getName()); + tag.setDouble("Amount", modifier.getAmount()); + tag.setInteger("Operation", modifier.getOperation()); + tag.setLong("UUIDMost", modifier.getID().getMostSignificantBits()); + tag.setLong("UUIDLeast", modifier.getID().getLeastSignificantBits()); + + tags.appendTag(tag); + stack.stackTagCompound.setTag("AttributeModifiers", tags); + } + @SubscribeEvent public void entityAttacked(LivingAttackEvent event) { if (event.source.getEntity() instanceof EntityPlayer) { - EntityPlayer p = (EntityPlayer) event.source.getEntity(); - if (p.getHeldItem() != null && p.getHeldItem().getItem() instanceof ItemWandCasting) { - ItemStack s = p.getHeldItem(); - ItemWandCasting wand = (ItemWandCasting) s.getItem(); + EntityPlayer player = (EntityPlayer) event.source.getEntity(); + if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemWandCasting) { + final ItemStack stack = player.getHeldItem(); + final ItemWandCasting wand = (ItemWandCasting) stack.getItem(); + final ItemStack cap = wand.getFocusItem(stack); - if (wand.getFocus(s) != null && wand.getFocus(s) instanceof ItemFocusMageMace) { - final AspectList aspects = new AspectList().add(Aspect.EARTH, 20).add(Aspect.ENTROPY, 20) - .add(Aspect.ORDER, 20); - if (wand.consumeAllVis(s, p, aspects, true, false)) { - wand.consumeAllVis(s, p, aspects, true, false); - } else { + if (wand.getFocus(stack) instanceof ItemFocusMageMace) { + final ItemFocusMageMace itemFocusMageMace = (ItemFocusMageMace) wand.getFocus(stack); + final boolean isEnoughVis = wand + .consumeAllVis(stack, player, itemFocusMageMace.getVisCost(cap), true, false); + + if (!isEnoughVis) { event.setCanceled(true); } } } } } + // End @SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { diff --git a/src/main/java/taintedmagic/common/helper/TaintedMagicHelper.java b/src/main/java/taintedmagic/common/helper/TaintedMagicHelper.java index d337aed..773394b 100644 --- a/src/main/java/taintedmagic/common/helper/TaintedMagicHelper.java +++ b/src/main/java/taintedmagic/common/helper/TaintedMagicHelper.java @@ -2,10 +2,14 @@ package taintedmagic.common.helper; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import taintedmagic.common.items.wand.foci.ItemFocusMageMace; import thaumcraft.api.aspects.Aspect; import thaumcraft.api.aspects.AspectList; +import thaumcraft.api.wands.FocusUpgradeType; import thaumcraft.codechicken.lib.vec.Vector3; +import thaumcraft.common.items.wands.ItemWandCasting; public class TaintedMagicHelper { @@ -28,4 +32,19 @@ public class TaintedMagicHelper { double var11 = p.posZ + 0.5D - z; return var7 * var7 + var9 * var9 + var11 * var11; } + + /** get damage with 20% * potency level **/ + public static int getFocusDamageWithPotency(ItemStack stack, int damage) { + if (stack != null && stack.getItem() instanceof ItemFocusMageMace) { + final ItemFocusMageMace cap = (ItemFocusMageMace) stack.getItem(); + return (int) ((damage + damage * cap.getUpgradeLevel(stack, FocusUpgradeType.potency) * 0.2) + 0.5); + } else return damage; + } + + public static int getWandDamageWithPotency(ItemStack stack, int damage) { + if (stack != null && stack.getItem() instanceof ItemWandCasting) { + final ItemWandCasting wand = (ItemWandCasting) stack.getItem(); + return (int) ((damage + damage * wand.getFocusPotency(stack) * 0.2) + 0.5); + } else return damage; + } } diff --git a/src/main/java/taintedmagic/common/items/wand/foci/ItemFocusMageMace.java b/src/main/java/taintedmagic/common/items/wand/foci/ItemFocusMageMace.java index 79f5512..69302ad 100644 --- a/src/main/java/taintedmagic/common/items/wand/foci/ItemFocusMageMace.java +++ b/src/main/java/taintedmagic/common/items/wand/foci/ItemFocusMageMace.java @@ -1,5 +1,7 @@ package taintedmagic.common.items.wand.foci; +import static taintedmagic.common.helper.TaintedMagicHelper.getFocusDamageWithPotency; + import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; @@ -13,6 +15,7 @@ import net.minecraft.util.StatCollector; import net.minecraft.world.World; import taintedmagic.common.TaintedMagic; +import taintedmagic.common.handler.ConfigHandler; import thaumcraft.api.ThaumcraftApiHelper; import thaumcraft.api.aspects.Aspect; import thaumcraft.api.aspects.AspectList; @@ -26,17 +29,15 @@ public class ItemFocusMageMace extends ItemFocusBasic { public IIcon depthIcon = null; public IIcon ornIcon = null; - public int dmg; - public static FocusUpgradeType bloodlust = new FocusUpgradeType( 58, - new ResourceLocation("taintedmagic", "textures/misc/IconBloodlust.png"), + new ResourceLocation("taintedmagic", "textures/foci/IconBloodlust.png"), "focus.upgrade.bloodlust.name", "focus.upgrade.bloodlust.text", new AspectList().add(Aspect.WEAPON, 1).add(Aspect.HEAL, 1)); - public static final AspectList costBase = new AspectList().add(Aspect.ENTROPY, 50); - public static final AspectList costBloodlust = new AspectList().add(Aspect.ENTROPY, 50).add(Aspect.ORDER, 20) - .add(Aspect.FIRE, 50); + public final AspectList mageMaceCostBase = new AspectList().add(Aspect.EARTH, 120).add(Aspect.ENTROPY, 120) + .add(Aspect.ORDER, 80); + public final AspectList mageMAceCostBloodlust = mageMaceCostBase.copy().add(Aspect.FIRE, 80); public ItemFocusMageMace() { this.setCreativeTab(TaintedMagic.tabTaintedMagic); @@ -66,8 +67,8 @@ public class ItemFocusMageMace extends ItemFocusBasic { return 3289650; } - public AspectList getVisCost(ItemStack s) { - return this.isUpgradedWith(s, bloodlust) ? this.costBloodlust : this.costBase; + public AspectList getVisCost(ItemStack stack) { + return this.isUpgradedWith(stack, bloodlust) ? mageMAceCostBloodlust : mageMaceCostBase; } public int getActivationCooldown(ItemStack s) { @@ -87,33 +88,33 @@ public class ItemFocusMageMace extends ItemFocusBasic { } @Override - public void addInformation(ItemStack s, EntityPlayer p, List l, boolean b) { - super.addInformation(s, p, l, b); - l.add(" "); - l.add( + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { + super.addInformation(stack, player, list, b); + list.add(""); + list.add( EnumChatFormatting.BLUE + "+" - + new String( - this.isUpgradedWith(s, FocusUpgradeType.potency) - ? Integer.toString(15 + this.getUpgradeLevel(s, FocusUpgradeType.potency)) - : "15") + + getFocusDamageWithPotency(stack, ConfigHandler.magesMaceBaseDamage) + " " + StatCollector.translateToLocal("text.attackdamageequipped")); + list.add( + EnumChatFormatting.BLUE + + String.format("Staff gives x%.1f Damage", ConfigHandler.magesMaceStaffMultiple)); + list.add(""); } public FocusUpgradeType[] getPossibleUpgradesByRank(ItemStack s, int rank) { switch (rank) { case 1: - return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency }; case 2: - return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency }; case 3: - return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency }; case 4: return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency }; case 5: - return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency, this.bloodlust }; + return new FocusUpgradeType[] { FocusUpgradeType.frugal, FocusUpgradeType.potency, bloodlust }; + default: + return null; } - return null; + } public boolean canApplyUpgrade(ItemStack s, EntityPlayer p, FocusUpgradeType t, int rank) {