package src.enigma.calin.items;
import cpw.mods.fml.common.Mod;
import jdk.nashorn.internal.ir.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import org.lwjgl.input.Keyboard;
import src.enigma.mod.EnigmaMod;
import net.minecraft.world.World;

/**
 * Created by Calin on 8/17/2015.
 **/
public class ItemFlyingCarpet extends Item
{
    boolean isEnabled;
    boolean toggle;
    int y;
    int toggleBlock;

    public ItemFlyingCarpet()
    {
        super();
        this.maxStackSize = 1;
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.setTextureName(EnigmaMod.MODID + ":" + "flying carpet");
    }

    public void init()
    {
        this.isEnabled = false;
        this.toggle = false;
        this.y = -3;
        this.toggleBlock = 0;
    }

    @Override
    public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer thePlayer)
    {

        if (thePlayer.worldObj.isRemote)
        {
            return itemstack;
        }

        this.toggle = !this.toggle;

        return itemstack;
    }

    @Override
    public void onUpdate(ItemStack stack, World world, Entity thePlayer, int par4, boolean par5)
    {
        super.onUpdate(stack, world, thePlayer, par4, par5);
        {
            EntityPlayer player = (EntityPlayer) thePlayer;
            this.y = -1;


            //=== Possible implementation ===

            /*int sneak = Minecraft.getMinecraft().gameSettings.keyBindSneak.getKeyCode();

            if (Keyboard.isKeyDown(sneak))
            {

            }
            else
            {

            }*/
            //===============================


            if (thePlayer.worldObj.isRemote)
            {
                return;
            }

            if(this.toggle)
            {
                    this.toggleBlock = 0;

                    world.setBlock((int) player.posX, (int) player.posY + y, (int) (player.posZ), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX) + 1, (int) Math.round(player.posY) + y, (int) Math.round(player.posZ), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX) - 1, (int) Math.round(player.posY) + y, (int) Math.round(player.posZ), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ + 1), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ - 1), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX + 1), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ + 1), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX + 1), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ - 1), Blocks.glass);
                    world.setBlock((int) Math.round(player.posX - 1), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ - 1), Blocks.glass);
                world.setBlock((int) Math.round(player.posX - 1), (int) Math.round(player.posY) + y, (int) Math.round(player.posZ + 1), Blocks.glass);

                //=== Possible implementation ===
                //player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 15, 3));
                //player.addPotionEffect(new PotionEffect(Potion.jump.id, 3, 3));
                //===============================
            }
        }
    }
}
@@ -29,117 +29,8 @@
 ms;%0A
-import cpw.mods.fml.common.Mod;%0Aimport jdk.nashorn.internal.ir.Block;%0Aimport net.minecraft.client.Minecraft;%0A
 impo
@@ -112,54 +112,8 @@
 ty;%0A
-import net.minecraft.entity.EntityLivingBase;%0A
 impo
@@ -285,196 +285,51 @@
 aft.
-potion.Potion;%0Aimport net.minecraft.potion.PotionEffect;%0Aimport net.minecraft.world.World;%0Aimport org.lwjgl.input.Keyboard;%0Aimport src.enigma.mod.EnigmaMod;%0Aimport net.minecraft.world.Worl
+world.World;%0Aimport src.enigma.mod.EnigmaMo
 d;%0A%0A
@@ -371,16 +371,17 @@
 5.%0A **/%0A
+%0A
 public c
@@ -421,31 +421,8 @@
 m%0A%7B%0A
-    boolean isEnabled;%0A
     
@@ -451,29 +451,8 @@
 t y;
-%0A    int toggleBlock;
 %0A%0A  
@@ -696,40 +696,8 @@
   %7B%0A
-        this.isEnabled = false;%0A
     
@@ -743,39 +743,9 @@
  = -
-3;%0A        this.toggleBlock = 0
+1
 ;%0A  
@@ -1754,51 +1754,8 @@
   %7B%0A
-                    this.toggleBlock = 0;%0A%0A
     

Clean up!