Java Code Examples for net.minecraft.potion.Potion#getIdFromPotion()

The following examples show how to use net.minecraft.potion.Potion#getIdFromPotion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftTippedArrow.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
    int effectId = effect.getType().getId();
    net.minecraft.potion.PotionEffect existing = null;
    for (net.minecraft.potion.PotionEffect mobEffect : getHandle().customPotionEffects) {
        if (Potion.getIdFromPotion(mobEffect.getPotion()) == effectId) {
            existing = mobEffect;
        }
    }
    if (existing != null) {
        if (!override) {
            return false;
        }
        getHandle().customPotionEffects.remove(existing);
    }
    getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
    getHandle().refreshEffects();
    return true;
}
 
Example 2
Source File: CraftTippedArrow.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
    int effectId = effect.getId();
    net.minecraft.potion.PotionEffect existing = null;
    for (net.minecraft.potion.PotionEffect mobEffect : getHandle().customPotionEffects) {
        if (Potion.getIdFromPotion(mobEffect.getPotion()) == effectId) {
            existing = mobEffect;
        }
    }
    if (existing == null) {
        return false;
    }
    Validate.isTrue(getBasePotionData().getType() != PotionType.UNCRAFTABLE || !getHandle().customPotionEffects.isEmpty(), "Tipped Arrows must have at least 1 effect");
    getHandle().customPotionEffects.remove(existing);
    getHandle().refreshEffects();
    return true;
}
 
Example 3
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean addCustomEffect(PotionEffect effect, boolean override) {
    int effectId = effect.getType().getId();
    net.minecraft.potion.PotionEffect existing = null;
    for (net.minecraft.potion.PotionEffect mobEffect : getHandle().effects) {
        if (Potion.getIdFromPotion(mobEffect.getPotion()) == effectId) {
            existing = mobEffect;
        }
    }
    if (existing != null) {
        if (!override) {
            return false;
        }
        getHandle().effects.remove(existing);
    }
    getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
    getHandle().refreshEffects();
    return true;
}
 
Example 4
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean removeCustomEffect(PotionEffectType effect) {
    int effectId = effect.getId();
    net.minecraft.potion.PotionEffect existing = null;
    for (net.minecraft.potion.PotionEffect mobEffect : getHandle().effects) {
        if (Potion.getIdFromPotion(mobEffect.getPotion()) == effectId) {
            existing = mobEffect;
        }
    }
    if (existing == null) {
        return false;
    }
    getHandle().effects.remove(existing);
    getHandle().refreshEffects();
    return true;
}
 
Example 5
Source File: EntityJoinWorld.java    From minecraft-roguelike with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void OnEntityJoinWorld(EntityJoinWorldEvent event) {
	
	World world = event.getWorld();
	if(world.isRemote) return;
	
	Entity entity = event.getEntity();
	
	// slimes do not extend EntityMob for some reason
	if(!(entity instanceof EntityMob || entity instanceof EntitySlime)){
		return;
	}
	
	EntityLiving mob = (EntityLiving) entity;
	
	Collection<?> effects = mob.getActivePotionEffects();
	for(Object buff : effects){
		if(Potion.getIdFromPotion(((PotionEffect) buff).getPotion()) == 4){
			int level = ((PotionEffect) buff).getAmplifier();
			
			IEntity metaEntity = new MetaEntity((Entity)mob);
			MonsterProfile.equip(world, world.rand, level, metaEntity);
			if(entity.isDead) event.setCanceled(true);
			return;
		}
	}
}
 
Example 6
Source File: CraftPotionEffectType.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftPotionEffectType(Potion handle) {
    super(Potion.getIdFromPotion(handle));
    this.handle = handle;
}