net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent Java Examples

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: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void harvestDrops(HarvestDropsEvent event) {
	if (!ToroQuestConfiguration.cropsAffectRep) {
		return;
	}
	if (isCrop(event.getState().getBlock())) {
		BlockPos pos = event.getPos();
		AxisAlignedBB bb = new AxisAlignedBB(pos);
		List<EntityPlayer> players = event.getWorld().getEntitiesWithinAABB(EntityPlayer.class, bb);
		if (players != null && players.size() > 0) {
			for (EntityPlayer player : players) {
				adjustPlayerRep(player, pos.getX() / 16, pos.getZ() / 16, -getFarmRepAmount(event.getWorld().rand));
			}
		}
	}
}
 
Example #2
Source File: QuestMine.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected boolean notCurrentDepth(HarvestDropsEvent event, QuestData data) {
	int max = getMaxDepth(data);
	int min = getMinDepth(data);
	int y = event.getPos().getY();

	if (min > 0 && y < min) {
		return true;
	}

	if (max > 0 && y > max) {
		return true;
	}

	return false;
}
 
Example #3
Source File: BlockHarvestHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onBlockHarvest(HarvestDropsEvent event)
{
	Block block = event.getState().getBlock();
	if(block == aridGarden || block == frostGarden || block == tropicalGarden || block == windyGarden || block == shadedGarden || block == soggyGarden)
		Food.addDecayTimerForCreative(event.getWorld(), event.getDrops());
}
 
Example #4
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 #5
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 #6
Source File: ItemPickaxeOfGreed.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onHarvest(HarvestDropsEvent event) {
	if (thisToolWasUsed(event)) {
		alterDrops(event.getWorld().rand, event.getDrops(), event.getHarvester());
	}
}
 
Example #7
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 #8
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);
	}
}
 
Example #9
Source File: ArtifactServerEventHandler.java    From Artifacts with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onBlockHarvested(HarvestDropsEvent event) {
	if(!ignore && blockUnderAntibuilderInfluence(event.world, event.x, event.y, event.z)) {
		event.drops.clear();
	}
}