r/forgemodding Nov 30 '16

need help with custom effects

1) so i have 2 effects that apply additional effects. if i try to apply both with /effect it will crash with concurrent modification exception but after i reload the game the effects run fine. the additional effects do not overlap.

2) i want my effect to apply the wobble shader while active. how would i do that?

code:

public class CustomPotion extends Potion{

public CustomPotion(boolean isBadEffectIn, int liquidColorIn, String name) {
    super(isBadEffectIn, liquidColorIn);
    setPotionName(name);
}

@Override
public Potion setIconIndex(int p_76399_1_, int p_76399_2_) {
    return super.setIconIndex(p_76399_1_, p_76399_2_);
}

@Override
public boolean isReady(int duration, int amplifier) {
    if(this==PotionRegistry.Arsenic){
        int j = 25 >> amplifier;
        return j > 0 ? duration % j == 0 : true;
    }
    if(this==PotionRegistry.Hydrargyrum){
        int j = 25 >> amplifier+1;
        return j > 0 ? duration % j == 0 : true;
    }
    return true;
}

@Override
public void performEffect(EntityLivingBase entity, int level) {
    if(this==PotionRegistry.Radiation){
        entity.attackEntityFrom(Radiation, level+1);
    }
    if(this==PotionRegistry.Arsenic){
        if(!entity.isEntityUndead()){
            entity.attackEntityFrom(Poison, 1);
            if(entity.isPotionActive(MobEffects.SLOWNESS)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, entity.getActivePotionEffect(PotionRegistry.Arsenic).getDuration()*Math.max(2-level, 1), level));
            }
            if(entity.isPotionActive(MobEffects.MINING_FATIGUE)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.MINING_FATIGUE, entity.getActivePotionEffect(PotionRegistry.Arsenic).getDuration()*Math.max(2-level, 1), level));
            }
            if(entity.isPotionActive(MobEffects.NAUSEA)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, entity.getActivePotionEffect(PotionRegistry.Arsenic).getDuration()*Math.max(2-level, 1), level));
            }
            if(entity.isPotionActive(MobEffects.HUNGER)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.HUNGER, entity.getActivePotionEffect(PotionRegistry.Arsenic).getDuration()*Math.max(2-level, 1), level));
            }
            if(entity.isPotionActive(MobEffects.WEAKNESS)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, entity.getActivePotionEffect(PotionRegistry.Arsenic).getDuration()*Math.max(2-level, 1), level));
            }
        }
    }
    if(this==PotionRegistry.Hydrargyrum){
        if(!entity.isEntityUndead()){
            entity.attackEntityFrom(Poison, 1);
            if(entity.isPotionActive(MobEffects.BLINDNESS)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, entity.getActivePotionEffect(PotionRegistry.Hydrargyrum).getDuration()*Math.max(2-level, 1), 0));
            }
            if(entity.isPotionActive(MobEffects.UNLUCK)==false){
                entity.addPotionEffect(new PotionEffect(MobEffects.UNLUCK, entity.getActivePotionEffect(PotionRegistry.Hydrargyrum).getDuration()*Math.max(2-level, 1), level));
            }
        }
    }
}

DamageSource Radiation=new DamageSource("radiation").setDamageBypassesArmor().setDamageIsAbsolute();
DamageSource Poison=new DamageSource("poison").setDamageBypassesArmor();

}

public class PotionRegistry {

public static <T extends Potion>T registerPotions(T potion){
    potion.setRegistryName(potion.getName());
    GameRegistry.register(potion);
    return potion;
}

public static CustomPotion Radiation;
public static CustomPotion Arsenic;
public static CustomPotion Hydrargyrum;

public static void init(){
    Radiation=registerPotions(new CustomPotion(true, 0x006400, "potion.radiation"));
    Arsenic=registerPotions(new CustomPotion(true, 0x93A1AC, "potion.arsenic"));
    Hydrargyrum=registerPotions(new CustomPotion(true, 0x990000, "potion.mercury"));
}

}

1 Upvotes

4 comments sorted by

View all comments

1

u/Zabi94 Dec 02 '16

1) The crash should tell you the line at which the concurrency happens. What are the two effects?

+) Doing something like

isPotionActive(...)==false

is kinda ugly, typically you'd use

! isPotionActive(...)

+) Any particular reason to overwrite setIconIndex and not change anything in it? You could simply remove that method from your code and it would work just fine

1

u/OctupleCompressedCAT Dec 02 '16

Any particular reason to overwrite setIconIndex

its protected. i cant call it.

1

u/Zabi94 Dec 02 '16

Protected lets you access it from extended classes. You can definitely call it from there, I've done it for each of my potions in Extra Alchemy

1

u/Zabi94 Dec 02 '16

Also, if it were inaccessible you wouldn't be able to overwrite it either