package net.machinemuse.powersuits.event;

import net.machinemuse.api.ModularCommon;
import net.machinemuse.api.MuseItemUtils;
import net.machinemuse.api.ModuleManager;
import net.machinemuse.powersuits.item.IModularItem;
import net.machinemuse.powersuits.item.ItemPowerTool;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;

public class EventHandler {
	@ForgeSubscribe
	public void handleHarvestCheck(PlayerEvent.HarvestCheck event) {
		EntityPlayer player = event.entityPlayer;
		Block block = event.block;
		ItemStack stack = player.inventory.getCurrentItem();
		if (stack != null && stack.getItem() instanceof ItemPowerTool && ItemPowerTool.canHarvestBlock(stack, block, 0, player)) {
			event.success = true;
		}
	}

	@ForgeSubscribe
	public void handleBreakSpeed(PlayerEvent.BreakSpeed event) {
		Block block = event.block;
		EntityPlayer player = event.entityPlayer;
		double harvestSpeed = event.newSpeed;
		double energy = MuseItemUtils.getPlayerEnergy(player);
		int meta = event.metadata;
		ItemStack stack = player.getCurrentEquippedItem();
		if (stack != null && stack.getItem() instanceof ItemPowerTool) {
			if (ItemPowerTool.useIronPickaxe(stack, block, meta)
					&& energy > ModuleManager.computeModularProperty(stack, ModularCommon.PICKAXE_ENERGY_CONSUMPTION)) {

				harvestSpeed *= ModuleManager.computeModularProperty(stack, ModularCommon.PICKAXE_HARVEST_SPEED);

			} else if (ItemPowerTool.useIronShovel(stack, block, meta)
					&& energy > ModuleManager.computeModularProperty(stack, ModularCommon.SHOVEL_ENERGY_CONSUMPTION)) {

				harvestSpeed *= ModuleManager.computeModularProperty(stack, ModularCommon.SHOVEL_HARVEST_SPEED);

			} else if (ItemPowerTool.useIronAxe(stack, block, meta)
					&& energy > ModuleManager.computeModularProperty(stack, ModularCommon.AXE_ENERGY_CONSUMPTION)) {

				harvestSpeed *= ModuleManager.computeModularProperty(stack, ModularCommon.AXE_HARVEST_SPEED);

			} else if (ItemPowerTool.useDiamondPickaxe(stack, block, meta)
					&& energy > ModuleManager.computeModularProperty(stack, ModularCommon.PICKAXE_ENERGY_CONSUMPTION)) {

				harvestSpeed *= ModuleManager.computeModularProperty(stack, ModularCommon.PICKAXE_HARVEST_SPEED);

			} else {

				harvestSpeed = 1;

			}
			if (harvestSpeed > 1
					&& player.isInsideOfMaterial(Material.water)
					&& MuseItemUtils.itemHasActiveModule(stack, ModularCommon.MODULE_AQUA_AFFINITY)
					&& energy > ModuleManager.computeModularProperty(stack, ModularCommon.AQUA_AFFINITY_ENERGY_CONSUMPTION)) {
				harvestSpeed *= 5 * ModuleManager.computeModularProperty(stack, ModularCommon.UNDERWATER_HARVEST_SPEED);
			}
			event.newSpeed = (float) harvestSpeed;
		}

	}

	@ForgeSubscribe
	public void handleLivingUpdateEvent(LivingEvent.LivingUpdateEvent event) {
		if (event.entityLiving instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) event.entityLiving;
			ItemStack helmet = player.getCurrentArmor(3);
			if (helmet != null && helmet.getItem() instanceof IModularItem
					&& MuseItemUtils.itemHasActiveModule(helmet, ModularCommon.MODULE_WATER_ELECTROLYZER)) {
				double energy = MuseItemUtils.getPlayerEnergy(player);
				double energyConsumption = ModuleManager.computeModularProperty(helmet, ModularCommon.WATERBREATHING_ENERGY_CONSUMPTION);
				if (energy > energyConsumption && player.getAir() < 10) {
					MuseItemUtils.drainPlayerEnergy(player, energyConsumption);
					player.setAir(300);
				}
			}
			ItemStack legs = player.getCurrentArmor(1);
			if (legs != null && legs.getItem() instanceof IModularItem
					&& MuseItemUtils.itemHasActiveModule(legs,
							ModularCommon.MODULE_CLIMB_ASSIST)) {
				player.stepHeight = 1.01F;
			} else if (player.stepHeight == 1.01F) {
				player.stepHeight = 0F;
			}
		}
	}

}

@@ -106,28 +106,28 @@
 se.api.M
-useItemUtils
+oduleManager
 ;%0Aimport
@@ -144,36 +144,36 @@
 nemuse.api.M
-oduleManager
+useItemUtils
 ;%0Aimport net
@@ -2534,22 +2534,17 @@
 peed %3E 1
-%0A%09%09%09%09%09
+ 
 && playe
@@ -3804,38 +3804,33 @@
 eof IModularItem
-%0A%09%09%09%09%09
+ 
 && MuseItemUtils
@@ -3859,16 +3859,9 @@
 egs,
-%0A%09%09%09%09%09%09%09
+ 
 Modu
@@ -3920,16 +3920,17 @@
 ght = 1.
+0
 01F;%0A%09%09%09
@@ -3963,16 +3963,17 @@
 ht == 1.
+0
 01F) %7B%0A%09
@@ -3996,16 +3996,21 @@
 ight = 0
+.5001
 F;%0A%09%09%09%7D%0A

fix step height