Java Code Examples for net.minecraftforge.event.world.BlockEvent#HarvestDropsEvent

The following examples show how to use net.minecraftforge.event.world.BlockEvent#HarvestDropsEvent . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolMetaItemListener.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void onHarvestDrops(BlockEvent.HarvestDropsEvent event) {
    EntityPlayer harvester = event.getHarvester();
    List<ItemStack> drops = event.getDrops();
    if (harvester == null)
        return;
    ItemStack stackInHand = harvester.getHeldItem(EnumHand.MAIN_HAND);
    if (stackInHand.isEmpty() || !(stackInHand.getItem() instanceof ToolMetaItem<?>))
        return;

    ToolMetaItem<? extends MetaToolValueItem> toolMetaItem = (ToolMetaItem<?>) stackInHand.getItem();
    boolean isRecursiveCall = harvesting.get() == DUMMY_OBJECT;
    if (!isRecursiveCall) {
        harvesting.set(DUMMY_OBJECT);
        toolMetaItem.onBlockDropsHarvested(stackInHand, event.getWorld(), event.getPos(), event.getState(), harvester, drops);
        harvesting.set(null);
    }
}
 
Example 2
Source File: HandlerHammer.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@SubscribeEvent(priority=EventPriority.LOWEST)
public void hammer(BlockEvent.HarvestDropsEvent event)
{
	if (event.getWorld().isRemote || event.getHarvester() == null || event.isSilkTouching())
		return;

	ItemStack held = event.getHarvester().getHeldItemMainhand();
	
	if (!isHammer(held))
		return;
	
	List<ItemStack> rewards = HammerRegistry.getRewardDrops(event.getWorld().rand, event.getState(), ((IHammer) held.getItem()).getMiningLevel(held), event.getFortuneLevel());
	
	if (rewards != null && rewards.size() > 0)
	{
		event.getDrops().clear();
		event.setDropChance(1.0F);
		event.getDrops().addAll(rewards);
	}
}
 
Example 3
Source File: ModifierSmashing.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@Override
public void blockHarvestDrops(ItemStack tool, BlockEvent.HarvestDropsEvent event)
{
    List<ItemStack> rewards = HammerRegistry.getRewardDrops(event.getWorld().rand, event.getState(), ToolHelper.getHarvestLevelStat(tool), event.getFortuneLevel());
    
    if (rewards != null && rewards.size() > 0)
    {
        event.getDrops().clear();
        event.setDropChance(1.0F);
        event.getDrops().addAll(rewards);
    }
}
 
Example 4
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@SubscribeEvent
public void harvestEvent(BlockEvent.HarvestDropsEvent event) {
	if (EtFuturum.enableSilkTouchingMushrooms && event.isSilkTouching)
		if (event.block == Blocks.brown_mushroom_block) {
			event.drops.clear();
			event.drops.add(new ItemStack(ModBlocks.brown_mushroom_block));
		} else if (event.block == Blocks.red_mushroom_block) {
			event.drops.clear();
			event.drops.add(new ItemStack(ModBlocks.red_mushroom_block));
		}

	if (EtFuturum.enableSticksFromDeadBushes)
		if (event.block == Blocks.deadbush) {
			boolean isShears = event.harvester != null && event.harvester.getCurrentEquippedItem() != null && event.harvester.getCurrentEquippedItem().getItem() instanceof ItemShears;
			if (event.harvester == null || event.harvester.getCurrentEquippedItem() == null || !isShears)
				for (int i = 0; i < event.world.rand.nextInt(3); i++)
					event.drops.add(new ItemStack(Items.stick));
		}

	if (EtFuturum.enableShearableCobwebs)
		if (event.block == Blocks.web && event.harvester != null) {
			ItemStack stack = event.harvester.getCurrentEquippedItem();
			if (stack != null && stack.getItem() instanceof ItemShears) {
				event.drops.clear();
				event.drops.add(new ItemStack(Blocks.web));
			}
		}
}
 
Example 5
Source File: GrassDropHandler.java    From AgriCraft with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void interceptGrassDrop(BlockEvent.HarvestDropsEvent event) {

    // Skip silk touch.
    if (event.isSilkTouching()) {
        return;
    }

    // Fetch the blockstate.
    final IBlockState state = event.getState();

    // Skip Air or Error
    if (state == null || state.getBlock() == null) {
        return;
    }

    // Fetch the world random.
    final Random rand = event.getWorld().rand;

    // Log
    // This line was oddly ignoring the debug settings...
    //AgriCore.getLogger("agricraft").debug("Intercepted! Block: {0}", state.getBlock());
    // Add grass drops if grass block.
    if (state.getBlock() instanceof BlockTallGrass) {
        // Wipe other drops, if needed.
        if (AgriCraftConfig.wipeGrassDrops) {
            event.getDrops().clear();
        }
        // Log
        // Commenented out to prevent spam.
        //AgriCore.getLogger("agricraft").debug("Inserting Drops!");
        // Add the drops.
        addGrassDrops(event.getDrops(), rand);
    }
}