Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Fix ring effects becoming permanent under some circumstances #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/main/java/vazkii/potionfingers/ItemRing.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,33 @@ public int getColorFromItemstack(ItemStack stack, int i) {
if(p != null)
return p.getLiquidColor();
}

return 0xFFFFFF;
}
};
}

@Override
public void onEquipped(ItemStack itemstack, EntityLivingBase player) {
updatePotionStatus(player, getPotion(itemstack));
updatePotionStatus(player, itemstack, false);
}

@Override
public void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
updatePotionStatus(player, getPotion(itemstack));
updatePotionStatus(player, itemstack, true);
}

public void updatePotionStatus(EntityLivingBase player, Potion potion) {
public void updatePotionStatus(EntityLivingBase player, ItemStack ring, boolean unequipping) {
Potion potion = getPotion(ring);
if(potion == null || !(player instanceof EntityPlayer))
return;

IInventory inv = BaublesApi.getBaubles((EntityPlayer) player);
ItemStack ring1 = inv.getStackInSlot(1);
ItemStack ring2 = inv.getStackInSlot(2);

Potion potion1 = getPotion(ring1);
Potion potion2 = getPotion(ring2);
Potion potion1 = unequipping && ring == ring1 ? null : getPotion(ring1);
Potion potion2 = unequipping && ring == ring2 ? null : getPotion(ring2);

int level = -1;
if(potion1 == potion)
Expand All @@ -134,8 +135,8 @@ public void updatePotionStatus(EntityLivingBase player, Potion potion) {

PotionEffect currentEffect = player.getActivePotionEffect(potion);
int currentLevel = currentEffect != null ? currentEffect.getAmplifier() : -1;
if(currentLevel != level) {
player.removeActivePotionEffect(potion);
if (currentLevel != level) {
player.removePotionEffect(potion);
if(level != -1 && !player.world.isRemote)
player.addPotionEffect(new PotionEffect(potion, Integer.MAX_VALUE, level, true, false));
}
Expand Down