List of usage examples for net.minecraftforge.event.entity.item ItemExpireEvent getEntity
public Entity getEntity()
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; }//w ww .j a va 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())); } } } }