Search in sources :

Example 1 with ItemTossEvent

use of net.minecraftforge.event.entity.item.ItemTossEvent in project MinecraftForge by MinecraftForge.

the class ForgeHooks method onPlayerTossEvent.

@Nullable
public static EntityItem onPlayerTossEvent(@Nonnull EntityPlayer player, @Nonnull ItemStack item, boolean includeName) {
    player.captureDrops = true;
    EntityItem ret = player.dropItem(item, false, includeName);
    player.capturedDrops.clear();
    player.captureDrops = false;
    if (ret == null) {
        return null;
    }
    ItemTossEvent event = new ItemTossEvent(ret, player);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        return null;
    }
    if (!player.world.isRemote) {
        player.getEntityWorld().spawnEntity(event.getEntityItem());
    }
    return event.getEntityItem();
}
Also used : ItemTossEvent(net.minecraftforge.event.entity.item.ItemTossEvent) EntityItem(net.minecraft.entity.item.EntityItem) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemTossEvent (net.minecraftforge.event.entity.item.ItemTossEvent)1