Skip to content

Commit

Permalink
fix: Fixed wands keeping assigned spells, even after removing spell s…
Browse files Browse the repository at this point in the history
…lots gained from Attunement upgrade scrolls (using Word of Unbinding). Fixes #229
  • Loading branch information
WinDanesz committed Jan 27, 2024
1 parent ab3d7e6 commit 15e7ba6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import electroblob.wizardry.item.ItemWandUpgrade;
import electroblob.wizardry.item.SpellActions;
import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.NBTExtras;
import electroblob.wizardry.util.ParticleBuilder;
Expand Down Expand Up @@ -55,8 +54,7 @@ public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksIn
return true;
}
}
if (world.isRemote)
spawnParticles(world, caster);
if (world.isRemote) {spawnParticles(world, caster);}
return true;
} else {
if (!world.isRemote) {
Expand All @@ -67,51 +65,48 @@ public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksIn
}

if (caster.getHeldItem(hand).isEmpty() || !(caster.getHeldItem(hand).getItem() instanceof ISpellCastingItem)) {
if (!world.isRemote)
caster.sendStatusMessage(new TextComponentTranslation("spell.ancientspellcraft:words_of_unbinding.no_wand"), false);
if (!world.isRemote) {caster.sendStatusMessage(new TextComponentTranslation("spell.ancientspellcraft:words_of_unbinding.no_wand"), false);}
return false;
}

ItemStack stack = caster.getHeldItem(hand);
if (stack.getItem() instanceof ISpellCastingItem) {
if (WandHelper.getTotalUpgrades(stack) > 0) {
if (!world.isRemote) {

if (!caster.getHeldItemOffhand().isEmpty() && caster.getHeldItemOffhand().getItem() instanceof ItemWandUpgrade) {
boolean action = removeUpgrade(caster, stack, caster.getHeldItemOffhand().getItem());
if (action) {
this.playSound(world, caster, ticksInUse, -1, modifiers);
}
return action;
} else {
boolean action = removeUpgrade(caster, stack, null);
if (action) {
this.playSound(world, caster, ticksInUse, -1, modifiers);
}
return action;
if (stack.getItem() instanceof ISpellCastingItem) {
if (WandHelper.getTotalUpgrades(stack) > 0) {
if (!world.isRemote) {

if (!caster.getHeldItemOffhand().isEmpty() && caster.getHeldItemOffhand().getItem() instanceof ItemWandUpgrade) {
boolean action = removeUpgrade(caster, stack, caster.getHeldItemOffhand().getItem());
if (action) {
this.playSound(world, caster, ticksInUse, -1, modifiers);
}
return action;
} else {
boolean action = removeUpgrade(caster, stack, null);
if (action) {
this.playSound(world, caster, ticksInUse, -1, modifiers);
}
return action;
}
}
}

} else {
if (!world.isRemote)
caster.sendStatusMessage(new TextComponentTranslation("spell.ancientspellcraft:words_of_unbinding.no_upgrade_to_remove"), false);
return false;

} else {
if (!world.isRemote) {
caster.sendStatusMessage(new TextComponentTranslation("spell.ancientspellcraft:words_of_unbinding.no_upgrade_to_remove"), false);
}
return false;

}

if (world.isRemote)
spawnParticles(world, caster);
if (world.isRemote) {spawnParticles(world, caster);}

return true;
}

public static boolean removeUpgrade(EntityPlayer player, ItemStack wand, @Nullable Item upgrade) {
boolean returnItem = player.world.rand.nextDouble() < 0.2 && ItemArtefact.isArtefactActive(player, ASItems.ring_unbinding);

if (wand.getTagCompound() == null)
wand.setTagCompound((new NBTTagCompound()));
if (wand.getTagCompound() == null) {wand.setTagCompound((new NBTTagCompound()));}

if (!wand.getTagCompound().hasKey(WandHelper.UPGRADES_KEY)) {
return false;
Expand Down Expand Up @@ -179,12 +174,12 @@ private static void removeRandomUpgrade(EntityPlayer player, ItemStack wand, boo
upgrades.removeTag(upgradeToDecrease);
}

if (upgradeToDecrease == "attunement") {
if (upgradeToDecrease.equals("attunement")) {
if (wand.getItem() instanceof IWorkbenchItem) {
Spell[] spells = WandHelper.getSpells(wand);
Spell[] newSpells = new Spell[((IWorkbenchItem) wand.getItem()).getSpellSlotCount(wand)];

for(int i = 0; i < newSpells.length; i++){
for (int i = 0; i < newSpells.length; i++) {
newSpells[i] = i < spells.length && spells[i] != null ? spells[i] : Spells.none;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"enabled": {
"book": true,
"scroll": true,
"scroll": false,
"wands": true,
"npcs": false,
"dispensers": true,
"commands": true,
"dispensers": false,
"commands": false,
"treasure": false,
"trades": false,
"looting": false
Expand Down

0 comments on commit 15e7ba6

Please sign in to comment.