Example usage for net.minecraftforge.event.entity.item ItemExpireEvent getEntityItem

List of usage examples for net.minecraftforge.event.entity.item ItemExpireEvent getEntityItem

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.item ItemExpireEvent getEntityItem.

Prototype

public ItemEntity getEntityItem() 

Source Link

Document

The relevant EntityItem for this event, already cast for you.

Usage

From source file:com.lothrazar.cyclicmagic.module.tweaks.EnvironmentTweaksModule.java

License:Open Source License

@SubscribeEvent
public void onItemExpireEvent(ItemExpireEvent event) {
    if (saplingDespawnGrow) {
        EntityItem entityItem = event.getEntityItem();
        BlockPos pos = entityItem.getPosition();
        Entity entity = event.getEntity();
        ItemStack is = entityItem.getItem();
        World world = entity.getEntityWorld();
        if (is.isEmpty()) {
            return;
        }// ww  w .j a v a 2  s.c  o m
        // plant the sapling, replacing the air and on top of dirt/plantable
        if (Block.getBlockFromItem(is.getItem()) == Blocks.RED_MUSHROOM)
            world.setBlockState(entityItem.getPosition(), Blocks.RED_MUSHROOM.getDefaultState());
        else if (Block.getBlockFromItem(is.getItem()) == Blocks.BROWN_MUSHROOM)
            world.setBlockState(entityItem.getPosition(), Blocks.BROWN_MUSHROOM.getDefaultState());
        else if (UtilOreDictionary.doesMatchOreDict(is, "treeSapling")) {
            Block saplingBlock = Block.getBlockFromItem(is.getItem());
            if (saplingBlock != Blocks.AIR && saplingBlock.canPlaceBlockAt(world, pos)) {
                world.setBlockState(pos, UtilItemStack.getStateFromMeta(Block.getBlockFromItem(is.getItem()),
                        is.getItemDamage()));
            }
        }
    }
}