diff --git a/gradle.properties b/gradle.properties index 50dbc0a..d6d4177 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,11 +41,11 @@ developmentEnvironmentUserName = Developer # Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8. # See https://github.com/bsideup/jabel for details on how this works. -enableModernJavaSyntax = false +enableModernJavaSyntax = true # Enables injecting missing generics into the decompiled source code for a better coding experience. # Turns most publicly visible List, Map, etc. into proper List, Map types. -enableGenericInjection = false +enableGenericInjection = true # Generate a class with a String field for the mod version named as defined below. # If generateGradleTokenClass is empty or not missing, no such class will be generated. diff --git a/src/main/java/fox/spiteful/forbidden/FMEventHandler.java b/src/main/java/fox/spiteful/forbidden/FMEventHandler.java index 1a11cca..f64809e 100644 --- a/src/main/java/fox/spiteful/forbidden/FMEventHandler.java +++ b/src/main/java/fox/spiteful/forbidden/FMEventHandler.java @@ -68,6 +68,7 @@ import fox.spiteful.forbidden.potions.DarkPotions; import thaumcraft.api.aspects.Aspect; import thaumcraft.api.entities.ITaintedMob; +import thaumcraft.api.wands.WandCap; import thaumcraft.common.config.ConfigItems; import thaumcraft.common.items.wands.ItemWandCasting; import thaumcraft.common.lib.utils.Utils; @@ -481,7 +482,7 @@ public void onGetHurt(LivingHurtEvent event) { ItemStack wand = ((EntityPlayer) event.entityLiving).getCurrentEquippedItem(); if (event.source.getDamageType().equals("taint") - && ((ItemWandCasting) wand.getItem()).getRod(wand).getTag().equals("tainted")) { + && ((ItemWandCasting) wand.getItem()).getRod(wand) == ForbiddenItems.WAND_ROD_TAINTED) { for (int x = 0; x < 3; x++) { ((ItemWandCasting) wand.getItem()).addVis(wand, primals[randy.nextInt(6)], 1, true); @@ -489,17 +490,19 @@ public void onGetHurt(LivingHurtEvent event) { } if ((event.source.getDamageType().equals("wither") || event.source.isFireDamage()) - && ((ItemWandCasting) wand.getItem()).getRod(wand).getTag().equals("infernal")) { + && ((ItemWandCasting) wand.getItem()).getRod(wand) == ForbiddenItems.WAND_ROD_INFERNAL) { event.setCanceled(true); } } - if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer) { - ItemStack equip = ((EntityPlayer) event.source.getEntity()).getCurrentEquippedItem(); - if (equip != null && equip.getItem() instanceof ItemWandCasting) { - if (((ItemWandCasting) equip.getItem()).getCap(equip).getTag().equals("alchemical") - && ((ItemWandCasting) equip.getItem()).getRod(equip).getTag().startsWith("blood")) { + if (event.source.getEntity() instanceof EntityPlayer player) { + ItemStack equip = player.getCurrentEquippedItem(); + if (equip != null && equip.getItem() instanceof ItemWandCasting wand) { + WandCap cap = wand.getCap(equip); + // "blood_iron" is the Blood Iron Infused Cap from Blood Arsenal + if ((cap == ForbiddenItems.WAND_CAP_ALCHEMICAL || cap.getTag().equals("blood_iron")) + && wand.getRod(equip).getTag().startsWith("blood")) { event.entityLiving.addPotionEffect(new PotionEffect(Potion.weakness.id, 60, 2)); } } 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 72d450f..dbc98c7 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/BloodStaffUpdate.java @@ -4,53 +4,20 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; -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 BloodWandUpdate { + @Override 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; - if (((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("alchemical")) - cost = Config.bloodvis - 1; - else cost = Config.bloodvis; - - cost = Math.max(0, cost); - - for (int x = 0; x < primals.length; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (player.capabilities.isCreativeMode) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - else if (syphonHealth(player)) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - return; - } else return; - } - } + if (!(checkHotbar(itemstack, player))) return; + super.onUpdate(itemstack, player); + } - } catch (Exception e) { - return; - } - } + @Override + protected int regenTimer() { + return 25; } + @Override public boolean syphonHealth(EntityPlayer player) { if (player.getHealth() > 3) { player.setHealth(player.getHealth() - 3); @@ -60,14 +27,8 @@ public boolean syphonHealth(EntityPlayer player) { 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 54085f0..597e440 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/BloodWandUpdate.java @@ -6,52 +6,56 @@ import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; +import fox.spiteful.forbidden.items.ForbiddenItems; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; +import thaumcraft.api.wands.WandCap; 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; - if (((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("alchemical")) - cost = Config.bloodvis - 1; - else cost = Config.bloodvis; - - cost = Math.max(0, cost); - - for (int x = 0; x < primals.length; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (player.capabilities.isCreativeMode) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - else if (SoulNetworkHandler.syphonFromNetwork(itemstack, cost * deficit) > 0) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - else if (syphonHealth(player)) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - return; - } else return; - } + if (!Compat.bm || !Config.crossWand || player.ticksExisted % regenTimer() != 0) { + return; + } + try { + SoulNetworkHandler.checkAndSetItemOwner(itemstack, player); + + WandCap cap = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack); + // "blood_iron" is the Blood Iron Infused Cap from Blood Arsenal + int cost = cap == ForbiddenItems.WAND_CAP_ALCHEMICAL || cap.getTag().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 (Throwable e) { - 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 b3db8c1..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.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) { - for (int x = 0; x < primals.length; x++) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack)) { - ((ItemWandCasting) itemstack.getItem()).addVis( - itemstack, - primals[x], - ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]), - true); + int maxVis = getMaxVis(itemstack); + for (Aspect primal : primals) { + 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..4b8cf0c --- /dev/null +++ b/src/main/java/fox/spiteful/forbidden/items/wands/DarkWandRodOnUpdate.java @@ -0,0 +1,32 @@ +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; + } + + /** + * The number of ticks between when the wand core regenerates vis + */ + protected int regenTimer() { + return 100; + } +} 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 b7b4a87..6186bf0 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.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) { + if (player.ticksExisted % regenTimer() == 0) { + int maxVis = getMaxVis(itemstack); if (player.worldObj.provider.dimensionId == -1) { - for (int x = 0; x < primals.length; x++) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) / 10) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); + for (Aspect primal : primals) { + 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 62b1529..af2134a 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ManaStaffUpdate.java @@ -3,45 +3,20 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import am2.api.ArsMagicaApi; -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 ManaWandUpdate { 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 (!(checkHotbar(itemstack, player))) return; + super.onUpdate(itemstack, player); + } - if (prop == null || prop.getCurrentMana() <= 0) return; + @Override + protected int regenTimer() { + return 40; + } - for (int x = 0; x < primals.length; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (prop.getCurrentMana() > cost * deficit) { - prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - } - } - } - } catch (Throwable e) {} - } - } + @Override + protected float getCost(boolean hasVinteumCaps) { + return hasVinteumCaps ? 0.5F : 1.0F; } } 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 fcf8410..3e24e20 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ManaWandUpdate.java @@ -7,41 +7,39 @@ import am2.api.IExtendedProperties; import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; +import fox.spiteful.forbidden.items.ForbiddenItems; 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; + if (!Compat.am2 || !Config.crossWand || player.ticksExisted % regenTimer() != 0) { + return; + } - for (int x = 0; x < primals.length; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (prop.getCurrentMana() > cost * deficit) { - prop.setCurrentMana(prop.getCurrentMana() - cost * deficit); - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - } - } - } - } catch (Throwable e) {} + try { + IExtendedProperties prop = ArsMagicaApi.instance.getExtendedProperties(player); + if (prop == null || prop.getCurrentMana() <= 0) return; + + float cost = getCost( + ((ItemWandCasting) itemstack.getItem()).getCap(itemstack) == ForbiddenItems.WAND_CAP_VINTEUM); + 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) {} + } + + protected float getCost(boolean hasVinteumCaps) { + return hasVinteumCaps ? 0.8F : 1.4F; } } 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 d5b61f7..7379010 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/ProfaneWandUpdate.java @@ -6,48 +6,57 @@ 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 % regenTimer() != 0) { + return; + } + NBTTagCompound tag = itemstack.getTagCompound(); + int contract; + if (!tag.hasKey("contract")) { + Thaumcraft.proxy.getResearchManager().completeResearch(player, "ROD_profane"); + contract = 25000; + } else { + contract = tag.getInteger("contract"); + if (contract <= 0) return; + } - 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 (int x = 0; x < primals.length && tag.getInteger("contract") > 0; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - int restore = Math.min(tag.getInteger("contract"), deficit); - ((ItemWandCasting) itemstack.getItem()).addRealVis(itemstack, primals[x], restore, true); - tag.setInteger("contract", tag.getInteger("contract") - restore); - if (player.worldObj.rand.nextInt(2501) < restore) Thaumcraft.addStickyWarpToPlayer(player, 1); - } + 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 (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 (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); + } + + @Override + protected int regenTimer() { + return 20; } } 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 58ce8c0..fcbde62 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 @@ 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 (int x = 0; x < primals.length; x++) { - if (((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]) - < ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) / 10) { - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - } + if (player.ticksExisted % regenTimer() != 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 605e940..6157d20 100644 --- a/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java +++ b/src/main/java/fox/spiteful/forbidden/items/wands/YandereWandUpdate.java @@ -5,47 +5,44 @@ import fox.spiteful.forbidden.Config; import fox.spiteful.forbidden.compat.Compat; +import fox.spiteful.forbidden.items.ForbiddenItems; import thaumcraft.api.aspects.Aspect; -import thaumcraft.api.wands.IWandRodOnUpdate; +import thaumcraft.api.wands.WandCap; 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; - if (((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("manasteel") - || ((ItemWandCasting) itemstack.getItem()).getCap(itemstack).getTag().equals("elementium")) - cost = Config.manavis - 2; - else cost = Config.manavis; - - cost = Math.max(0, cost); - - for (int x = 0; x < primals.length; x++) { - int deficit = ((ItemWandCasting) itemstack.getItem()).getMaxVis(itemstack) - - ((ItemWandCasting) itemstack.getItem()).getVis(itemstack, primals[x]); - if (deficit > 0) { - deficit = Math.min(deficit, 100); - if (ManaItemHandler.requestManaExact(itemstack, player, cost * deficit, true)) - ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primals[x], 1, true); - } + if (!Compat.botan || !Config.crossWand + || player.ticksExisted % regenTimer() != 0 + || !checkHotbar(itemstack, player)) { + return; + } + try { + int cost; + WandCap cap = ((ItemWandCasting) itemstack.getItem()).getCap(itemstack); + cost = cap == ForbiddenItems.WAND_CAP_MANASTEEL || cap == ForbiddenItems.WAND_CAP_ELEMENTIUM + ? Config.manavis - 2 + : Config.manavis; + + 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; } - - } catch (Throwable e) { - return; + deficit = Math.min(deficit, 100); + if (ManaItemHandler.requestManaExact(itemstack, player, cost * deficit, true)) + ((ItemWandCasting) itemstack.getItem()).addVis(itemstack, primal, 1, true); } - } + } catch (Exception 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; + @Override + protected int regenTimer() { + return 40; } }