diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java index 6e95ab6..29c32f2 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java @@ -8,45 +8,45 @@ import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class BloodStaffUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class BloodStaffUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (Compat.bm && Config.crossWand && player.ticksExisted % 25 == 0) { - try { - if (!checkHotbar(itemstack, player)) return; - - SoulNetworkHandler.checkAndSetItemOwner(itemstack, player); - - int cost; - String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); - if (capTag.equals("alchemical") || capTag.equals("blood_iron")) cost = Config.bloodvis - 1; - else cost = Config.bloodvis; - - cost = Math.max(0, cost); - - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (player.capabilities.isCreativeMode) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - else if (syphonHealth(player)) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - return; - } else return; - } - } - - } catch (Exception ignored) {} + if (!Compat.bm || !Config.crossWand || player.ticksExisted % 25 != 0) { + return; } + try { + if (!checkHotbar(itemstack, player)) return; + + SoulNetworkHandler.checkAndSetItemOwner(itemstack, player); + + String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); + int cost = capTag.equals("alchemical") || capTag.equals("blood_iron") ? Config.bloodvis - 1 + : Config.bloodvis; + + cost = Math.max(0, cost); + + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; + } + deficit = Math.min(deficit, 100); + if (player.capabilities.isCreativeMode) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + else if (syphonHealth(player)) { + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + return; + } else { + return; + } + } + + } catch (Exception ignored) {} } public boolean syphonHealth(EntityPlayer player) { @@ -58,14 +58,8 @@ public class BloodStaffUpdate implements IWandRodOnUpdate { player.setHealth(0); player.onDeath(new DamageSource("blooderp")); return true; - } else return false; - } - - private boolean checkHotbar(ItemStack stack, EntityPlayer player) { - for (int x = 0; x < 9; ++x) { - ItemStack item = player.inventory.getStackInSlot(x); - if (item == stack) return true; + } else { + return false; } - return false; } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java index 1e7a9cf..48038ab 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java @@ -7,49 +7,51 @@ import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class BloodWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class BloodWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (Compat.bm && Config.crossWand && player.ticksExisted % 100 == 0) { - try { - SoulNetworkHandler.checkAndSetItemOwner(itemstack, player); - - int cost; - String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); - if (capTag.equals("alchemical") || capTag.equals("blood_iron")) cost = Config.bloodvis - 1; - else cost = Config.bloodvis; - - cost = Math.max(0, cost); - - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (player.capabilities.isCreativeMode) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - else if (syphonHealth(player)) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - return; - } else return; - } - } - - } catch (Throwable ignored) {} + if (!Compat.bm || !Config.crossWand || player.ticksExisted % 100 != 0) { + return; } + try { + SoulNetworkHandler.checkAndSetItemOwner(itemstack, player); + + String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); + int cost = capTag.equals("alchemical") || capTag.equals("blood_iron") ? Config.bloodvis - 1 + : Config.bloodvis; + + cost = Math.max(0, cost); + + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; + } + deficit = Math.min(deficit, 100); + if (player.capabilities.isCreativeMode) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + else if (syphonHealth(player)) { + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + return; + } else { + return; + } + } + + } catch (Exception ignored) {} } public boolean syphonHealth(EntityPlayer player) { if (player.getHealth() > 6) { player.setHealth(player.getHealth() - 3); return true; - } else return false; + } else { + return false; + } } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/CreativeWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/CreativeWandUpdate.java index bc14fdc..608e758 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/CreativeWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/CreativeWandUpdate.java @@ -4,23 +4,15 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class CreativeWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class CreativeWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { + int maxVis = getMaxVis(itemstack); for (Aspect primal : primals) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack)) { - ((ItemWandCasting) itemstack.getItem()).addVis( - itemstack, - primal, - ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal), - true); + if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) < maxVis) { + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, maxVis, true); } } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/DarkWandRodOnUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/DarkWandRodOnUpdate.java new file mode 100644 index 0000000..1cef96c --- /dev/null +++ b/src/main/java/fox/spiteful/forbidden/items/wands/DarkWandRodOnUpdate.java @@ -0,0 +1,25 @@ +package fox.spiteful.forbidden.items.wands; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.wands.IWandRodOnUpdate; +import thaumcraft.common.items.wands.ItemWandCasting; + +public abstract class DarkWandRodOnUpdate implements IWandRodOnUpdate { + + static final Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); + + protected static int getMaxVis(ItemStack itemstack) { + return ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack); + } + + protected boolean checkHotbar(ItemStack stack, EntityPlayer player) { + for (int x = 0; x < 9; ++x) { + ItemStack item = player.inventory.getStackInSlot(x); + if (item == stack) return true; + } + return false; + } +} diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/InfernalWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/InfernalWandUpdate.java index 67dbd6e..41705f5 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/InfernalWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/InfernalWandUpdate.java @@ -5,26 +5,24 @@ import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class InfernalWandUpdate implements IWandRodOnUpdate { +public class InfernalWandUpdate extends DarkWandRodOnUpdate { - Aspect[] primals = { Aspect.ORDER, Aspect.ENTROPY, Aspect.AIR, Aspect.EARTH, Aspect.WATER }; + static final Aspect[] primals = { Aspect.ORDER, Aspect.ENTROPY, Aspect.AIR, Aspect.EARTH, Aspect.WATER }; public void onUpdate(ItemStack itemstack, EntityPlayer player) { if (player.ticksExisted % 100 == 0) { + int maxVis = getMaxVis(itemstack); if (player.worldObj.provider.dimensionId == -1) { for (Aspect primal : primals) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) / 10) { + if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) < maxVis / 10) { ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); } } } - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, Aspect.FIRE) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) / 5) { + if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, Aspect.FIRE) < maxVis / 5) { ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, Aspect.FIRE, 1, true); } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java index 40dc1d0..c46f15e 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java @@ -8,40 +8,33 @@ import am2.api.IExtendedProperties; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class ManaStaffUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class ManaStaffUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (Compat.am2 && Config.crossWand) { - if (player.ticksExisted % 40 == 0) { - - try { - IExtendedProperties prop = ArsMagicaApi.instance.getExtendedProperties(player); - - float cost; - if (((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("vinteum")) - cost = 0.5F; - else cost = 1.0F; - - if (prop == null || prop.getCurrentMana() <= 0) return; - - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (prop.getCurrentMana() > cost * deficit) { - prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - } - } - } - } catch (Throwable ignored) {} - } + if (!Compat.am2 || !Config.crossWand || player.ticksExisted % 40 != 0) { + return; } + + try { + IExtendedProperties prop = ArsMagicaApi.instance.getExtendedProperties(player); + if (prop == null || prop.getCurrentMana() <= 0) return; + + float cost = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("vinteum") ? 0.5F + : 1.0F; + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; + } + deficit = Math.min(deficit, 100); + if (prop.getCurrentMana() > cost * deficit) { + prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + } + } + } catch (Exception ignored) {} } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java index 9c9ae22..de966a9 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java @@ -8,40 +8,33 @@ import am2.api.IExtendedProperties; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class ManaWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class ManaWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (Compat.am2 && Config.crossWand) { - if (player.ticksExisted % 100 == 0) { - - try { - IExtendedProperties prop = ArsMagicaApi.instance.getExtendedProperties(player); - - float cost; - if (((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("vinteum")) - cost = 0.8F; - else cost = 1.4F; - - if (prop == null || prop.getCurrentMana() <= 0) return; - - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (prop.getCurrentMana() > cost * deficit) { - prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - } - } - } - } catch (Throwable ignored) {} - } + if (!Compat.am2 || !Config.crossWand || player.ticksExisted % 100 != 0) { + return; } + + try { + IExtendedProperties prop = ArsMagicaApi.instance.getExtendedProperties(player); + if (prop == null || prop.getCurrentMana() <= 0) return; + + float cost = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("vinteum") ? 0.8F + : 1.4F; + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; + } + deficit = Math.min(deficit, 100); + if (prop.getCurrentMana() > cost * deficit) { + prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + } + } + } catch (Exception ignored) {} } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java index e7fb3ae..7576824 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java @@ -6,49 +6,51 @@ import net.minecraft.nbt.NBTTagCompound; import fox.spiteful.forbidden.items.ForbiddenItems; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.Thaumcraft; import thaumcraft.common.items.wands.ItemWandCasting; -public class ProfaneWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class ProfaneWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - - if (player.ticksExisted % 20 == 0) { - - NBTTagCompound tag = itemstack.getTagCompound(); - if (!tag.hasKey("contract")) { - Thaumcraft.proxy.getResearchManager().completeResearch(player, "ROD_profane"); - tag.setInteger("contract", 25000); - } else if (tag.getInteger("contract") <= 0) return; - - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - int restore = Math.min(tag.getInteger("contract"), deficit); - ((ItemWandCasting) itemstack.getItem()).addRealVis(itemstack, primal, restore, true); - tag.setInteger("contract", tag.getInteger("contract") - restore); - if (player.worldObj.rand.nextInt(2501) < restore) Thaumcraft.addStickyWarpToPlayer(player, 1); - } - if (tag.getInteger("contract") <= 0) break; - } - - if (tag.getInteger("contract") <= 0) { - ((ItemWandCasting) itemstack.getItem()).setRod(itemstack, ForbiddenItems.WAND_ROD_PROFANED); - Thaumcraft.addStickyWarpToPlayer(player, 1); - player.worldObj.spawnParticle( - "largeexplode", - player.posX, - player.posY + (double) (player.height / 2.0F), - player.posZ, - 0.0D, - 0.0D, - 0.0D); - } - itemstack.setTagCompound(tag); + if (player.ticksExisted % 20 != 0) { + return; } + NBTTagCompound tag = itemstack.getTagCompound(); + int contract = tag.getInteger("contract"); + if (!tag.hasKey("contract")) { + Thaumcraft.proxy.getResearchManager().completeResearch(player, "ROD_profane"); + contract = 25000; + } else if (contract <= 0) { + return; + } + + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; + } + int restore = Math.min(contract, deficit); + ((ItemWandCasting) itemstack.getItem()).addRealVis(itemstack, primal, restore, true); + contract -= restore; + if (player.worldObj.rand.nextInt(2501) < restore) Thaumcraft.addStickyWarpToPlayer(player, 1); + if (contract <= 0) break; + } + + if (contract <= 0) { + ((ItemWandCasting) itemstack.getItem()).setRod(itemstack, ForbiddenItems.WAND_ROD_PROFANED); + Thaumcraft.addStickyWarpToPlayer(player, 1); + player.worldObj.spawnParticle( + "largeexplode", + player.posX, + player.posY + (double) (player.height / 2.0F), + player.posZ, + 0.0D, + 0.0D, + 0.0D); + } + + tag.setInteger("contract", contract); + itemstack.setTagCompound(tag); } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/TaintedWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/TaintedWandUpdate.java index 9e0f909..4e8936e 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/TaintedWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/TaintedWandUpdate.java @@ -2,24 +2,23 @@ package fox.spiteful.forbidden.items.wands; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; -public class TaintedWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class TaintedWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (player.ticksExisted % 100 == 0 - && player.worldObj.getBiomeGenForCoords((int) player.posX, (int) player.posZ).biomeID - == thaumcraft.common.config.Config.biomeTaintID) { - for (Aspect primal : primals) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) / 10) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - } + if (player.ticksExisted % 100 != 0 || player.worldObj.getBiomeGenForCoords( + MathHelper.floor_double(player.posX), + MathHelper.floor_double(player.posZ)).biomeID != thaumcraft.common.config.Config.biomeTaintID) { + return; + } + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal) < maxVis / 10) { + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); } } } diff --git a/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java b/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java index 42add35..04587e0 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java @@ -6,43 +6,32 @@ import net.minecraft.item.ItemStack; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; import thaumcraft.common.items.wands.ItemWandCasting; import vazkii.botania.api.mana.ManaItemHandler; -public class YandereWandUpdate implements IWandRodOnUpdate { - - Aspect[] primals = Aspect.getPrimalAspects().toArray(new Aspect[0]); +public class YandereWandUpdate extends DarkWandRodOnUpdate { public void onUpdate(ItemStack itemstack, EntityPlayer player) { - if (Compat.botan && Config.crossWand && player.ticksExisted % 40 == 0 && checkHotbar(itemstack, player)) { - try { - int cost; - String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); - if (capTag.equals("manasteel") || capTag.equals("elementium")) cost = Config.manavis - 2; - else cost = Config.manavis; + if (!Compat.botan || !Config.crossWand || player.ticksExisted % 40 != 0 || !checkHotbar(itemstack, player)) { + return; + } + try { + int cost; + String capTag = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag(); + cost = capTag.equals("manasteel") || capTag.equals("elementium") ? Config.manavis - 2 : Config.manavis; - cost = Math.max(0, cost); + cost = Math.max(0, cost); - for (Aspect primal : primals) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (ManaItemHandler.requestManaExact(itemstack, player, cost * deficit, true)) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); - } + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + int deficit = maxVis - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primal); + if (deficit <= 0) { + continue; } - - } catch (Throwable ignored) {} - } - } - - private boolean checkHotbar(ItemStack stack, EntityPlayer player) { - for (int x = 0; x < 9; ++x) { - ItemStack item = player.inventory.getStackInSlot(x); - if (item == stack) return true; - } - return false; + deficit = Math.min(deficit, 100); + if (ManaItemHandler.requestManaExact(itemstack, player, cost * deficit, true)) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); + } + } catch (Exception ignored) {} } }