Java Code Examples for net.minecraft.item.EnumAction#EAT

The following examples show how to use net.minecraft.item.EnumAction#EAT . 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: ItemLowerOrgansUpgrade.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleEatFoodTick(LivingEntityUseItemEvent.Tick 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)))
		{
			potions.put(p.getEntityId(), new ArrayList<PotionEffect>(p.getActivePotionEffects()));

		}
	}
	else
	{
		//potions.remove(e);
	}
}
 
Example 2
Source File: EssentialsMissingHandler.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleEatFoodTick(LivingEntityUseItemEvent.Tick event)
{
	EntityLivingBase e = event.getEntityLiving();
	ItemStack stack = event.getItem();
	
	if (e instanceof EntityPlayer && CyberwareAPI.hasCapability(e) && stack != null && stack.getItem().getItemUseAction(stack) == EnumAction.EAT)
	{
		EntityPlayer p = (EntityPlayer) e;
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		
		if (!cyberware.hasEssential(EnumSlot.LOWER_ORGANS))
		{
			hunger.put(p.getEntityId(), p.getFoodStats().getFoodLevel());
			saturation.put(p.getEntityId(), p.getFoodStats().getSaturationLevel());
		}
	}
	else
	{
		hunger.remove(e.getEntityId());
		saturation.remove(e.getEntityId());
	}
}
 
Example 3
Source File: EssentialsMissingHandler.java    From Cyberware with MIT License 6 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)
	{
		EntityPlayer p = (EntityPlayer) e;
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		
		if (!cyberware.hasEssential(EnumSlot.LOWER_ORGANS))
		{
			int hungerVal = hunger.keySet().contains(p) ? hunger.get(p) : p.getFoodStats().getFoodLevel();
			float satVal = saturation.keySet().contains(p) ? saturation.get(p) : p.getFoodStats().getSaturationLevel();

			p.getFoodStats().setFoodLevel(hungerVal);
			p.getFoodStats().setFoodSaturationLevel(satVal);
		}
	}
}
 
Example 4
Source File: ItemLowerOrgansUpgrade.java    From Cyberware with 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 5
Source File: ItemGrowingTofu.java    From TofuCraftReload with MIT License 4 votes vote down vote up
@Override
public EnumAction getItemUseAction(ItemStack stack) {
    return EnumAction.EAT;
}
 
Example 6
Source File: FoodStats.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public EnumAction getFoodAction(ItemStack itemStack) {
    return isDrink ? EnumAction.DRINK : EnumAction.EAT;
}
 
Example 7
Source File: ItemPLFood.java    From Production-Line with MIT License 4 votes vote down vote up
/**
 * returns the action that specifies what animation to play when the items is being used
 */
@Override
@Nonnull
public EnumAction getItemUseAction(ItemStack itemStack) {
    return EnumAction.EAT;
}
 
Example 8
Source File: ItemFoodTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * returns the action that specifies what animation to play when the items is being used
 */
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
	return EnumAction.EAT;
}