Java Code Examples for net.minecraft.entity.player.EntityPlayer#addPotionEffect()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#addPotionEffect() . These examples are extracted from open source projects. 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 Project: TofuCraftReload   File: DrinkSoymilkRamune.java    License: MIT License 6 votes vote down vote up
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	if(!worldIn.isRemote){
	if(getEffectList()!=null&&getEffectList().length>0){
		Random rand = worldIn.rand;
		PotionEffect effect1 = getEffectList()[rand.nextInt(getEffectList().length)];
				if (effect1 != null && effect1.getPotion() != null) {
					Potion por = effect1.getPotion();
					int amp = effect1.getAmplifier();
					int dur = effect1.getDuration();
					if (player.isPotionActive(effect1.getPotion())) {
						PotionEffect check = player.getActivePotionEffect(por);
						dur += check.getDuration();
						amp ++;
					}
					player.addPotionEffect(new PotionEffect(effect1.getPotion(), dur, amp));
				}
		
		}
	}
}
 
Example 2
Source Project: Ex-Aliquo   File: BlockEndCake.java    License: MIT License 6 votes vote down vote up
private void nomEndCake(World world, int x, int y, int z, EntityPlayer player)
{
    if (player.canEat(false))
    {
        int l = world.getBlockMetadata(x, y, z) + 1;

        if (l >= 6)
        {
        	return;
        }
        else
        {
        	player.getFoodStats().addStats(2, 0.1F);
            world.setBlockMetadataWithNotify(x, y, z, l, 2);
            if (world.provider.dimensionId == 0)
            {
            	if (!BlockEndPortal.bossDefeated) player.addPotionEffect(new PotionEffect(Potion.resistance.id, 200, 1));
            	player.travelToDimension(1);
            }
        }
    }
}
 
Example 3
Source Project: Sakura_mod   File: DrinksAlcoholic.java    License: MIT License 5 votes vote down vote up
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	Random rand = worldIn.rand;
	if(rand.nextInt(10)<=7) 
		player.addPotionEffect(new PotionEffect(ForgeRegistries.POTIONS.getValue(new ResourceLocation("minecraft", "nausea")), 600, 0));
	super.onFoodEaten(stack, worldIn, player);
}
 
Example 4
@Override
public void onEaten(ItemStack itemStack, EntityPlayer player) {
    if (!player.world.isRemote) {
        for (RandomPotionEffect potionEffect : potionEffects) {
            if (Math.random() * 100 > potionEffect.chance) {
                player.addPotionEffect(GTUtility.copyPotionEffect(potionEffect.effect));
            }
        }
    }
}
 
Example 5
@Override
public boolean onItemActive(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean selected) {
	if (entityIn instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) entityIn;
		player.addPotionEffect(new PotionEffect(MobEffects.INVISIBILITY, 5, 0, false, false));
		player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 18, 0, false, false));
	}
	return true;
}
 
Example 6
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
	Potion jump = MobEffects.JUMP_BOOST;
	if (!player.isPotionActive(jump)) {
		player.addPotionEffect(new PotionEffect(jump, 10, 2, false, false));
	}
	if (player.onGround && player.isSprinting()) {
		player.jump();
		player.playSound(GTSounds.SPRING, 1.0F, 1.0F + world.rand.nextFloat());
		if (world.rand.nextInt(2) == 0) {
			stack.damageItem(1, player);
		}
	}
}
 
Example 7
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player)
{
    WrappedPotionEffect effect = content.potionEffect.get(stack.getMetadata()).orElse(WrappedPotionEffect.of(null));
    float probability = content.potionEffectProbability.get(stack.getMetadata()).orElse(1f);
    PotionEffect potion = effect.getPotionEffect();

    if (!worldIn.isRemote && potion != null && worldIn.rand.nextFloat() < probability)
    {
        player.addPotionEffect(new PotionEffect(potion));
    }
}
 
Example 8
public void setThirsty(EntityPlayer player, boolean b)
{
	if (b)
	{
		player.setSprinting(false);
		if(!player.isPotionActive(PotionTFC.THIRST_POTION))
			player.addPotionEffect(new PotionEffect(PotionTFC.THIRST_POTION, Integer.MAX_VALUE, 0, false, false));
	}
	else
	{
		player.removePotionEffect(PotionTFC.THIRST_POTION);
	}
}
 
Example 9
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	if(!worldIn.isRemote) {
		player.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 60*20, 0, false, true));
		player.addPotionEffect(new PotionEffect(MobEffects.JUMP_BOOST, 60*20, 1, false, true));
		player.addPotionEffect(new PotionEffect(MobEffects.SPEED, 60*20, 0, false, true));
		player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 3*20, 3, false, true));
	}
}
 
Example 10
@Override
protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) {
	if (!worldIn.isRemote) {
		int burnSeconds = 30;
		player.addPotionEffect(new PotionEffect(Potion.getPotionById(12), burnSeconds * 20));
		player.setFire(burnSeconds);
	}
}
 
Example 11
Source Project: Cyberware   File: ItemLowerOrgansUpgrade.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleEatFoodEnd(LivingEntityUseItemEvent.Finish event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack stack = event.getItem();
	
	if (e instanceof EntityPlayer && CyberwareAPI.hasCapability(e) && stack != null && (stack.getItem().getItemUseAction(stack) == EnumAction.EAT || stack.getItem().getItemUseAction(stack) == EnumAction.DRINK))
	{
		EntityPlayer p = (EntityPlayer) e;
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)))
		{
			Collection<PotionEffect> toRemove = new ArrayList<PotionEffect>(p.getActivePotionEffects());
			for (PotionEffect pE : toRemove)
			{
				if (pE.getPotion().isBadEffect())
				{
					p.removePotionEffect(pE.getPotion());
				}
			}
			
			Collection<PotionEffect> toAdd = potions.keySet().contains(p.getEntityId()) ? potions.get(p.getEntityId()) : new ArrayList<PotionEffect>();

			for (PotionEffect add : toAdd)
			{
				for (PotionEffect removed : toRemove)
				{
					if (removed.getPotion() == add.getPotion())
					{
						p.addPotionEffect(add);
						break;
					}
				}
			}
		}
	}
}
 
Example 12
@Override
protected void onFoodEaten(ItemStack pStack, World pWorld, EntityPlayer pPlayer)
{
    pPlayer.getFoodStats().addStats(10, 1.0F);
    pPlayer.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20 * 60, 2));
    pPlayer.addPotionEffect(new PotionEffect(Potion.jump.id, 20 * 60, 2));
    pPlayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 20 * 60, 2));
    super.onFoodEaten(pStack, pWorld, pPlayer);
}
 
Example 13
private void DoHIEffects( IDamageEffectContainer pHI, EntityPlayer pPlayer )
{
  // Attack player based on all defined items
  for( HazardousItems.ItmDamageEffect iDE : pHI.getDamageEffects() ) {
      pPlayer.attackEntityFrom(DamageTypeHelper.ParseStringToDamageSource(iDE.getDamageSource()), iDE.getAmount());
  }

  for( HazardousItems.ItmPotionEffect iPE : pHI.getPotionEffects() ) {
      pPlayer.addPotionEffect(new PotionEffect(iPE.getId(), iPE.getDuration(), iPE.getLevel()));
  }
}
 
Example 14
Source Project: Artifacts   File: ComponentObscurity.java    License: MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,	EntityPlayer player) {
	UtilsForComponents.sendPotionPacket(14, 600, 0, player);
	player.addPotionEffect(new PotionEffect(14, 600, 0));
	ArtifactClientEventHandler.cloaked = true;
	//System.out.println("Cloaking player.");
	UtilsForComponents.sendItemDamagePacket(player, player.inventory.currentItem, 1); //itemStack.damageItem(1, player);
	itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 200);
	return itemStack;
}
 
Example 15
@Override
public void setInstantConfusionOnPlayer(EntityPlayer ent, int duration) {
  ent.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, duration, 1, false, true));
  Minecraft.getMinecraft().player.timeInPortal = 1;
}
 
Example 16
public static void updatePlayerArmorEffects(EntityPlayer player)
{
    //List<EntityPlayer> playerList = player.worldObj.playerEntities;

    ItemStack mystack[] = new ItemStack[4];
    mystack[0] = player.inventory.armorItemInSlot(0); //boots
    mystack[1] = player.inventory.armorItemInSlot(1); //legs
    mystack[2] = player.inventory.armorItemInSlot(2); //plate
    mystack[3] = player.inventory.armorItemInSlot(3); //helmet

    //full scorpion cave armor set, enable night vision
    if (mystack[0] != null && mystack[0].itemID == MoCreatures.bootsScorpCave.itemID && mystack[1] != null && mystack[1].itemID == MoCreatures.legsScorpCave.itemID && mystack[2] != null && mystack[2].itemID == MoCreatures.plateScorpCave.itemID && mystack[3] != null && mystack[3].itemID == MoCreatures.helmetScorpCave.itemID)
    {
        //System.out.println("adding effect night vision to player " + player);
        player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 300, 0));
        return;
    }

    //full scorpion nether armor set, enable fire resistance
    if (mystack[0] != null && mystack[0].itemID == MoCreatures.bootsScorpNether.itemID && mystack[1] != null && mystack[1].itemID == MoCreatures.legsScorpNether.itemID && mystack[2] != null && mystack[2].itemID == MoCreatures.plateScorpNether.itemID && mystack[3] != null && mystack[3].itemID == MoCreatures.helmetScorpNether.itemID)
    {
        //System.out.println("adding effect fire resistance to player " + player);
        player.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 300, 0));
        return;
    }

    //full scorpion frost armor set, enable water breathing
    if (mystack[0] != null && mystack[0].itemID == MoCreatures.bootsScorpFrost.itemID && mystack[1] != null && mystack[1].itemID == MoCreatures.legsScorpFrost.itemID && mystack[2] != null && mystack[2].itemID == MoCreatures.plateScorpFrost.itemID && mystack[3] != null && mystack[3].itemID == MoCreatures.helmetScorpFrost.itemID)
    {
        //System.out.println("adding effect water breathing to player " + player);
        player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 300, 0));
        return;
    }

    //full scorpion armor set, regeneration effect
    if (mystack[0] != null && mystack[0].itemID == MoCreatures.bootsScorpDirt.itemID && mystack[1] != null && mystack[1].itemID == MoCreatures.legsScorpDirt.itemID && mystack[2] != null && mystack[2].itemID == MoCreatures.plateScorpDirt.itemID && mystack[3] != null && mystack[3].itemID == MoCreatures.helmetScorpDirt.itemID)
    {
        //System.out.println("adding regeneration to player " + player);
        player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 70, 0));
        return;
    }
}
 
Example 17
@Override
public void applyPlayerBuffs(EntityPlayer player) {
    player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 20, 0));
    player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 21 * 20, 0));
    player.addPotionEffect(new PotionEffect(Potion.jump.id, 2 * 20, 2));
}
 
Example 18
Source Project: ExNihiloAdscensio   File: BlockFluidWitchwater.java    License: MIT License 4 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
	
	if (world.isRemote)
		return;
	
	if (entity.isDead)
		return;
	
	if (entity instanceof EntitySkeleton) {
		
		EntitySkeleton skeleton = (EntitySkeleton) entity;
		if (skeleton.getSkeletonType() == SkeletonType.NORMAL) {
			skeleton.setSkeletonType(SkeletonType.WITHER);
			skeleton.setHealth(skeleton.getMaxHealth());
			
			return;
		}
	}
	
	if (entity instanceof EntityCreeper) {
		EntityCreeper creeper = (EntityCreeper) entity;
		if (!creeper.getPowered()) {
			creeper.onStruckByLightning(null);
			creeper.setHealth(creeper.getMaxHealth());
			
			return;
		}
	}
	
	if (entity instanceof EntitySpider && !(entity instanceof EntityCaveSpider)) {
		EntitySpider spider = (EntitySpider) entity;
		spider.setDead();
		
		EntityCaveSpider caveSpider = new EntityCaveSpider(world);
		caveSpider.setLocationAndAngles(spider.posX, spider.posY, spider.posZ, spider.rotationYaw, spider.rotationPitch);
		caveSpider.renderYawOffset = spider.renderYawOffset;
		caveSpider.setHealth(caveSpider.getMaxHealth());
		
		world.spawnEntity(caveSpider);
		
		return;
	}
	
	if (entity instanceof EntitySquid) {
		EntitySquid squid = (EntitySquid) entity;
		squid.setDead();
		
		EntityGhast ghast = new EntityGhast(world);
		ghast.setLocationAndAngles(squid.posX, squid.posY, squid.posZ, squid.rotationYaw, squid.rotationPitch);
		ghast.renderYawOffset = squid.renderYawOffset;
		ghast.setHealth(ghast.getMaxHealth());
		
		world.spawnEntity(ghast);
		
		return;
	}
	
	if (entity instanceof EntityAnimal) {
		((EntityAnimal) entity).onStruckByLightning(null);
		return;
	}
	
	if (entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) entity;
		player.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 210, 0));
		player.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, 210, 2));
		player.addPotionEffect(new PotionEffect(MobEffects.WITHER, 210, 0));
		player.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 210, 0));
	}
}
 
Example 19
@Override
public void onWornTick( ItemStack arg0, EntityLivingBase pEntity )
{
  try
  {
    if( !( pEntity instanceof EntityPlayer ) ) {
      return;
    }

    if( arg0.getItemDamage() == 1 ) // MetaItem 0 is running this loop only
    {
      return;
    }

    EntityPlayer tPlayer = (EntityPlayer) pEntity;
    InventoryBaubles tBaubles = PlayerHandler.getPlayerBaubles( tPlayer );

    if( tPlayer.isBurning() ) // no fire/lava cheat!
    {
      if( isGlovesResistActive( tPlayer ) ) {
        RemoveFireProtection(pEntity);
      }
      return;
    }

    if( _mRnd.nextInt( 20 ) == 0 )
    {
      // Player must wear OvenGloves in both slots
      ItemStack tBaubleRing1 = tBaubles.stackList[1];
      ItemStack tBaubleRing2 = tBaubles.stackList[2];

      if( tBaubleRing1 == null || tBaubleRing2 == null )
      {
        // Log("Bauble 1 or 2 is null");
        return;
      }

      if( tBaubleRing1.getUnlocalizedName().contains( _mItemName ) && tBaubleRing2.getUnlocalizedName().contains( _mItemName ) )
      {
        if( tBaubleRing1.getItemDamage() != 0 || tBaubleRing2.getItemDamage() != 1 )
        {
          if( FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT )
          {
            if( !WrongSidePopupShown )
            {
              WrongSidePopupShown = true;
              Notification noti = new Notification( tBaubleRing1, "Wrong place", "The gloves feel weird..." );
              NotificationTickHandler.guiNotification.queueNotification( noti );
            }
          }
          // Log("Gloves in wrong spots");
          return;
        }
        
        if( tBaubleRing1.stackTagCompound == null || tBaubleRing2.stackTagCompound == null ) // Cheated gloves don't have NBT tags sometimes
        {
          return;
        }

        if( tBaubleRing1.stackTagCompound.getInteger( NBTTAG_DURABILITY ) <= 1 || tBaubleRing2.stackTagCompound.getInteger( NBTTAG_DURABILITY ) <= 1 ) {
          return;
        }

        ItemStack tHeldItem = tPlayer.getCurrentEquippedItem();
        if( tHeldItem != null )
        {
          // Update 12.01.2017: Player must hold any item containing Lava
          if( isValidLavaContainerItem( tHeldItem ) )
          {
            if( !isResistActive( tPlayer ) || isGlovesResistActive( tPlayer ) )
            {
              tPlayer.addPotionEffect( new PotionEffect( Potion.fireResistance.id, potionDuration, potionAmplifier, potionAmbient ) );

              int tRandomDamage = _mRnd.nextInt( 10 ); // Randomly damage gloves while giving the protection effect

              if( tRandomDamage == 1 ) {
                DamageItem(tBaubleRing1);
              } else if( tRandomDamage == 2 ) {
                DamageItem(tBaubleRing2);
              }
            }
          }
        }
      }
    }
  }
  catch (Exception e) // Fail-safe for all future crashes
  {
    e.printStackTrace();
  }
}
 
Example 20
public void updateEncumb(EntityPlayer player)
{
	float encumb = Core.getEncumbrance(player.inventory.mainInventory) / 80f;
	if(encumb >= 1.0)
	{
		if(player.isPotionActive(PotionTFC.ENCUMB_HEAVY_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_HEAVY_POTION);
		if(player.isPotionActive(PotionTFC.ENCUMB_MEDIUM_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MEDIUM_POTION);

		if(player.isPotionActive(PotionTFC.ENCUMB_MAX_POTION))
			return;

		player.addPotionEffect(new PotionEffect(PotionTFC.ENCUMB_MAX_POTION, Integer.MAX_VALUE, 0, false, false));
	}
	else if(encumb >= 0.75)
	{
		if(player.isPotionActive(PotionTFC.ENCUMB_MAX_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MAX_POTION);
		if(player.isPotionActive(PotionTFC.ENCUMB_MEDIUM_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MEDIUM_POTION);

		if(player.isPotionActive(PotionTFC.ENCUMB_HEAVY_POTION))
			return;

		player.addPotionEffect(new PotionEffect(PotionTFC.ENCUMB_HEAVY_POTION, Integer.MAX_VALUE, 0, false, false));
	}
	else if(encumb >= 0.5)
	{
		if(player.isPotionActive(PotionTFC.ENCUMB_MAX_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MAX_POTION);
		if(player.isPotionActive(PotionTFC.ENCUMB_HEAVY_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_HEAVY_POTION);

		if(player.isPotionActive(PotionTFC.ENCUMB_MEDIUM_POTION))
			return;

		player.addPotionEffect(new PotionEffect(PotionTFC.ENCUMB_MEDIUM_POTION, Integer.MAX_VALUE, 0, false, false));
	}
	else
	{
		if(player.isPotionActive(PotionTFC.ENCUMB_MAX_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MAX_POTION);
		if(player.isPotionActive(PotionTFC.ENCUMB_HEAVY_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_HEAVY_POTION);
		if(player.isPotionActive(PotionTFC.ENCUMB_MEDIUM_POTION))
			player.removeActivePotionEffect(PotionTFC.ENCUMB_MEDIUM_POTION);
	}
}