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

The following examples show how to use net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent#getHarvester() . 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: BlockEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onHarvestDropsEvent(HarvestDropsEvent event)
{
    if (event.getHarvester() != null)
    {
        ItemStack stack = event.getHarvester().getHeldItemMainhand();

        if (stack.isEmpty() == false && stack.getItem() instanceof ItemEnderTool)
        {
            ((ItemEnderTool) stack.getItem()).handleHarvestDropsEvent(stack, event);
        }
    }
}
 
Example 2
Source File: MobSpawnEventHandler.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@SubscribeEvent
public void onBlockHarvest(HarvestDropsEvent event) {

  if (!Config.direSlimeEnabled || event.isCanceled() || event.getWorld() == null || event.getWorld().isRemote) {
    return;
  }
  if (event.getHarvester() == null || event.getHarvester().capabilities.isCreativeMode) {
    return;
  }

  if (!(event.getState().getBlock() instanceof BlockDirt || event.getState().getBlock() instanceof BlockGrass)) {
    return;
  }

  if (!isToolEffective(event.getState(), event.getHarvester().getHeldItemMainhand())) {

    if (Config.direSlimeChance < event.getWorld().rand.nextFloat()) {
      return;
    }

    EntityDireSlime direSlime = new EntityDireSlime(event.getWorld());
    direSlime.setPosition(event.getPos().getX() + 0.5, event.getPos().getY() + 0.0, event.getPos().getZ() + 0.5);
    event.getWorld().spawnEntity(direSlime);
    direSlime.playLivingSound();
    for (ItemStack drop : event.getDrops()) {
      if (drop != null && drop.getItem() != null && drop.getItem() == Item.getItemFromBlock(Blocks.DIRT)) {
        if (drop.getCount() > 1) {
          drop.shrink(1);
        } else if (event.getDrops().size() == 1) {
          event.getDrops().clear();
        } else {
          event.getDrops().remove(drop);
        }
        return;
      }
    }
  }
}
 
Example 3
Source File: ItemPickaxeOfGreed.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private boolean thisToolWasUsed(HarvestDropsEvent event) {
	return event.getHarvester() != null && event.getHarvester().getHeldItemMainhand() != null
			&& event.getHarvester().getHeldItemMainhand().getItem() == INSTANCE && !event.getWorld().isRemote;
}
 
Example 4
Source File: QuestMine.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onMine(HarvestDropsEvent event) {
	if (event.getHarvester() == null) {
		return;
	}

	EntityPlayer player = event.getHarvester();
	Province inProvince = loadProvince(event.getHarvester().world, event.getPos());

	if (inProvince == null || inProvince.civilization == null) {
		return;
	}

	ItemStack tool = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);

	if (!tool.hasTagCompound()) {
		return;
	}

	String questId = tool.getTagCompound().getString("mine_quest");
	String provinceId = tool.getTagCompound().getString("province");

	if (questId == null || provinceId == null || !provinceId.equals(inProvince.id.toString())) {
		return;
	}

	QuestData data = getQuestById(player, questId);

	if (data == null) {
		return;
	}

	if (notCurrentDepth(event, data)) {
		return;
	}

	if (event.getState().getBlock() != BLOCK_TYPES[getBlockType(data)]) {
		return;
	}

	event.setDropChance(1f);
	for (ItemStack drop : event.getDrops()) {
		drop.setTagInfo("mine_quest", new NBTTagString(questId));
		drop.setTagInfo("province", new NBTTagString(provinceId));
		drop.setStackDisplayName(drop.getDisplayName() + " for " + inProvince.name);
	}
}