mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-25 00:18:34 +01:00
Don't add an effect multiple times
This commit is contained in:
parent
0d27a4a304
commit
90cecc8ed8
1 changed files with 22 additions and 8 deletions
|
@ -109,18 +109,32 @@ public class MethodHandler implements IMethodHandler {
|
||||||
@Override
|
@Override
|
||||||
public void addEffectProperties(ItemStack stack, MobEffectInstance effect, boolean addDur, boolean addAmp) {
|
public void addEffectProperties(ItemStack stack, MobEffectInstance effect, boolean addDur, boolean addAmp) {
|
||||||
MobEffectInstance[] effects = this.getEffectsFromStack(stack);
|
MobEffectInstance[] effects = this.getEffectsFromStack(stack);
|
||||||
|
boolean effectUpdated = false;
|
||||||
for (int i = 0; i < effects.length; i++) {
|
for (int i = 0; i < effects.length; i++) {
|
||||||
if (effects[i].getEffect() == effect.getEffect()) {
|
if (effects[i].getEffect() == effect.getEffect()) {
|
||||||
effects[i] = new MobEffectInstance(effects[i].getEffect(), effects[i].getDuration() + (addDur
|
effects[i] = new MobEffectInstance(effects[i].getEffect(),
|
||||||
? effect.getDuration()
|
effects[i].getDuration() + (addDur ? effect.getDuration() : 0),
|
||||||
: 0), effects[i].getAmplifier() + (addAmp
|
effects[i].getAmplifier() + (addAmp ? effect.getAmplifier() > 0 ? effect.getAmplifier() : 1 : 0));
|
||||||
? effect.getAmplifier() > 0
|
effectUpdated = true;
|
||||||
? effect.getAmplifier()
|
break;
|
||||||
: 1
|
|
||||||
: 0));
|
|
||||||
}
|
}
|
||||||
this.addEffectToStack(stack, effects[i]);
|
|
||||||
}
|
}
|
||||||
|
if (!effectUpdated) {
|
||||||
|
this.addEffectToStack(stack, effect);
|
||||||
|
} else {
|
||||||
|
// Clear existing effects from the stack
|
||||||
|
this.clearEffectsFromStack(stack);
|
||||||
|
// Add updated effects to the stack
|
||||||
|
for (MobEffectInstance updatedEffect : effects) {
|
||||||
|
this.addEffectToStack(stack, updatedEffect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearEffectsFromStack(ItemStack stack) {
|
||||||
|
CompoundTag tag = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
|
||||||
|
tag.remove("Counter");
|
||||||
|
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue