MinecraftForge/MinecraftForge — pull request #148 by Grenadier (2012-09-02 20:03:54+00:00)
Title: Entity Item Events

Created various EntityItem events:
---

*ItemEvent* is an abstract base class and never occurs directly.

*ItemSpawn* occurs whenever an EntityItem enters the world.

*ItemExpire* occurs when an EntityItem reaches its maximum age.

*ItemToss* occurs whenever a player moves an item from an inventory to the
ground. (Hitting Q, dragging an item off-GUI, leaving items in
workbench, etc.)

*ItemDrop* occurs for each item that enters the world upon a player's
death.

I left *EntityItemPickupEvent* in net.minecraftforge.event.entity.player
even though it probably makes more sense in the new package.
Refactoring it would (likely) break someone's mod, so I guess save it
for a major update.

Altered:
---

*World.spawnEntityInWorld()* - added a simple type check to throw
ItemSpawnEvent when EntityItems are passed in. Cancelling the event
stops the entity being added to the world.

*EntityItem* - added an additional field, lifespan, which is defaulted to
6000. This field is used when checking for item expiration, rather than
being hardcoded to 6000.

*EntityItem.onUpdate()* - expiration comparison now uses lifespan field.
When expiration is triggered, an ItemExpireEvent is fired before the
EntityItem is flagged as dead. Cancelling the event stops the call to
setDead()

*EntityPlayer.dropPlayerItemWithRandomChoice()* - added firing for both
ItemTossEvent and ItemDropEvent. When the random motion flag is true,
the items are being dropped on death. When false, the items are being
thrown out. Cancelling either event prevents the EntityItem from
spawning in the World.

*ItemSeeds.tryPlaceIntoWorld()* - tangentially related. I wanted to test
events by having seeds plant themselves on soil when they expire.
Simplfied the method a bit, and added ability to pass in null as the
PlayerEntity.