package net.wizardsoflua.lua.classes.event;

import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.wizardsoflua.annotation.GenerateLuaClass;
import net.wizardsoflua.annotation.GenerateLuaDoc;
import net.wizardsoflua.annotation.LuaProperty;
import net.wizardsoflua.lua.classes.DelegatorLuaClass;

/**
 * The <span class="notranslate">UseItemFinishEvent</span> class is fired after a
 * [Mob](/modules/Mob) or [Player](/modules/Player) finishes using an [Item](/modules/Item). The
 * [item](/modules/UseItemEvent#item) and [resultItem](#resultItem) reflect the state after item
 * use. If the item in use had a [count](/modules/Item#count) of 1 then the item in this event is
 * air.
 *
 * #### Example
 *
 * Print a message when the player finishes eating a golden apple.
 *
 * <code>
 * local itemsInUse = {}
 * Events.on('UseItemStartEvent'):call(function(event)
 *   itemsInUse[event.entity] = event.item.id
 * end)
 * Events.on('UseItemStopEvent'):call(function(event)
 *   itemsInUse[event.entity] = nil
 * end)
 * Events.on('UseItemFinishEvent'):call(function(event)
 *   local itemInUse = itemsInUse[event.entity]
 *   itemsInUse[event.entity] = nil
 *   if itemInUse == 'golden_apple' then
 *     print('That was delicious!')
 *   end
 * end)
 * </code>
 */
@GenerateLuaClass(name = UseItemFinishEventApi.NAME)
@GenerateLuaDoc(subtitle = "When an Entity finishes using an Item")
public class UseItemFinishEventApi<D extends LivingEntityUseItemEvent.Finish>
    extends UseItemEventApi<D> {
  public static final String NAME = "UseItemFinishEvent";

  public UseItemFinishEventApi(DelegatorLuaClass<?, ?> luaClass, D delegate) {
    super(luaClass, delegate);
  }

  /**
   * This item is placed in the players inventory in replacement of the item that is currently used.
 *
 * #### Example
 *
 * Print a message when the player finishes eating a golden apple.
 *
 * <code>
 * local itemsInUse = {}
 * Events.on('UseItemStartEvent'):call(function(event)
 *   itemsInUse[event.entity] = event.item.id
 * end)
 * Events.on('UseItemStopEvent'):call(function(event)
 *   itemsInUse[event.entity] = nil
 * end)
 * Events.on('UseItemFinishEvent'):call(function(event)
 *   local itemInUse = itemsInUse[event.entity]
 *   itemsInUse[event.entity] = nil
 *   if itemInUse == 'golden_apple' then
 *     event.resultItem = Items.get('apple')
 *   end
 * end)
 * </code>
   */
  @LuaProperty
  public ItemStack getResultItem() {
    return delegate.getResultStack();
  }

  @LuaProperty
  public void setResultItem(ItemStack result) {
    delegate.setResultStack(result);
  }
}

@@ -1838,18 +1838,22 @@
  used.%0A 
-*%0A
+  *%0A  
  * #### 
@@ -1853,34 +1853,38 @@
 * #### Example%0A 
-*%0A
+  *%0A  
  * Print a messa
@@ -1926,35 +1926,39 @@
 a golden apple.%0A
+  
  *%0A
+  
  * %3Ccode%3E%0A * loc
@@ -1943,32 +1943,34 @@
   *%0A   * %3Ccode%3E%0A
+  
  * local itemsIn
@@ -1970,32 +1970,34 @@
 itemsInUse = %7B%7D%0A
+  
  * Events.on('Us
@@ -2027,32 +2027,34 @@
 function(event)%0A
+  
  *   itemsInUse%5B
@@ -2079,32 +2079,34 @@
 ent.item.id%0A
+  
  * end)%0A
  * Events.on
@@ -2085,32 +2085,34 @@
 em.id%0A   * end)%0A
+  
  * Events.on('Us
@@ -2141,32 +2141,34 @@
 function(event)%0A
+  
  *   itemsInUse%5B
@@ -2183,32 +2183,34 @@
 tity%5D = nil%0A
+  
  * end)%0A
  * Events.on
@@ -2189,32 +2189,34 @@
 = nil%0A   * end)%0A
+  
  * Events.on('Us
@@ -2247,32 +2247,34 @@
 function(event)%0A
+  
  *   local itemI
@@ -2297,32 +2297,34 @@
 e%5Bevent.entity%5D%0A
+  
  *   itemsInUse%5B
@@ -2335,32 +2335,34 @@
 t.entity%5D = nil%0A
+  
  *   if itemInUs
@@ -2382,24 +2382,26 @@
 apple' then%0A
+  
  *     event
@@ -2433,16 +2433,18 @@
 apple')%0A
+  
  *   end
@@ -2440,32 +2440,34 @@
 %0A   *   end%0A
+  
  * end)%0A
  * %3C/code%3E%0A 
@@ -2446,32 +2446,34 @@
   end%0A   * end)%0A
+  
  * %3C/code%3E%0A   */

Format UseItemFinishEventApi