/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package tk.wurst_client.features.mods;

import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import tk.wurst_client.events.listeners.UpdateListener;
import tk.wurst_client.utils.BlockUtils;
import tk.wurst_client.utils.InventoryUtils;

@Mod.Info(description = "Automatically places blocks below your feet.",
	name = "ScaffoldWalk",
	tags = "scaffold walk, tower")
@Mod.Bypasses(ghostMode = false)
public class ScaffoldWalkMod extends Mod implements UpdateListener
{
	@Override
	public void onEnable()
	{
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
	}
	
	@Override
	public void onUpdate()
	{
		BlockPos belowPlayer = new BlockPos(mc.player).down();
		
		// check if block is already placed
		if(!BlockUtils.getMaterial(belowPlayer).isReplaceable())
			return;
		
		// search blocks in hotbar
		int newSlot = -1;
		for(int i = 0; i < 9; i++)
		{
			// filter out non-block items
			ItemStack stack = mc.player.inventory.getStackInSlot(i);
			if(InventoryUtils.isEmptySlot(stack)
				|| !(stack.getItem() instanceof ItemBlock))
				continue;
			
			newSlot = i;
			break;
		}
		
		// check if any blocks were found
		if(newSlot == -1)
			return;
		
		// set slot
		int oldSlot = mc.player.inventory.currentItem;
		mc.player.inventory.currentItem = newSlot;
		
		// place block
		BlockUtils.placeBlockLegit(belowPlayer);
		
		// reset slot
		mc.player.inventory.currentItem = oldSlot;
	}
}

@@ -483,16 +483,57 @@
 stener;%0A
+import tk.wurst_client.features.Feature;%0A
 import t
@@ -844,32 +844,157 @@
 er%0A%7B%0A%09@Override%0A
+%09public Feature%5B%5D getSeeAlso()%0A%09%7B%0A%09%09return new Feature%5B%5D%7Bwurst.mods.safeWalkMod, wurst.mods.buildRandomMod%7D;%0A%09%7D%0A%09%0A%09@Override%0A
 %09public void onE

Add "see also" to ScaffoldWalk