/*
 * Copyright  2014 - 2016 | 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.mods;

import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.play.client.CPacketCreativeInventoryAction;
import tk.wurst_client.gui.mods.GuiCmdBlock;
import tk.wurst_client.utils.ChatUtils;

@Mod.Info(
	description = "Allows you to make a Command Block without having OP.\n"
		+ "Appears to be patched on Spigot.",
	name = "CMD-Block",
	tags = "CmdBlock, CommandBlock, cmd block, command block",
	help = "Mods/CMD-Block")
@Mod.Bypasses
public class CmdBlockMod extends Mod
{
	@Override
	public void onEnable()
	{
		if(mc.player.inventory.getStackInSlot(0) != null)
		{
			ChatUtils.error("Please clear the first slot in your hotbar.");
			setEnabled(false);
			return;
		}else if(!mc.player.capabilities.isCreativeMode)
		{
			ChatUtils.error("Creative mode only.");
			setEnabled(false);
			return;
		}
		mc.displayGuiScreen(new GuiCmdBlock(this, mc.currentScreen));
		setEnabled(false);
	}
	
	public void createCmdBlock(String cmd)
	{
		ItemStack stack = new ItemStack(Blocks.COMMAND_BLOCK);
		NBTTagCompound nbtTagCompound = new NBTTagCompound();
		nbtTagCompound.setTag("Command", new NBTTagString(cmd));
		stack.writeToNBT(nbtTagCompound);
		stack.setTagInfo("BlockEntityTag", nbtTagCompound);
		mc.player.connection
			.sendPacket(new CPacketCreativeInventoryAction(36, stack));
		ChatUtils.message("Command Block created.");
	}
}

@@ -458,81 +458,8 @@
 ng;%0A
-import net.minecraft.network.play.client.CPacketCreativeInventoryAction;%0A
 impo
@@ -538,16 +538,61 @@
 atUtils;
+%0Aimport tk.wurst_client.utils.InventoryUtils;
 %0A%0A@Mod.I
@@ -672,16 +672,46 @@
 .%5Cn%22%0A%09%09+
+ %22Requires creative mode.%5Cn%22 +
  %22Appear
@@ -943,170 +943,28 @@
 %7B%0A%09%09
-if(mc.player.inventory.getStackInSlot(0) != null)%0A%09%09%7B%0A%09%09%09ChatUtils.error(%22Please clear the first slot in your hotbar.%22);%0A%09%09%09setEnabled(false);%0A%09%09%09return;%0A%09%09%7Delse 
+// check gamemode%0A%09%09
 if(!
@@ -1086,16 +1086,46 @@
 rn;%0A%09%09%7D%0A
+%09%09%0A%09%09// show cmd-block screen%0A
 %09%09mc.dis
@@ -1249,16 +1249,40 @@
 cmd)%0A%09%7B%0A
+%09%09// generate cmd-block%0A
 %09%09ItemSt
@@ -1541,92 +1541,77 @@
 ;%0A%09%09
-mc.player.connection%0A%09%09%09.sendPacket(new CPacketCreativeInventoryAction(36, 
+%0A%09%09// give cmd-block%0A%09%09if(InventoryUtils.placeStackInHotbar(
 stack))
-;
 %0A
+%09
 %09%09Ch
@@ -1653,13 +1653,79 @@
 ted.%22);%0A
+%09%09else%0A%09%09%09ChatUtils.error(%22Please clear a slot in your hotbar.%22);%0A
 %09%7D%0A%7D%0A

Fix CmdBlockMod not giving items