package bunyan.items;

import bunyan.KeyPressManager;
import bunyan.api.Direction;
import bunyan.api.DirectionalBlock;
import bunyan.api.ITurnable;
import bunyan.blocks.BunyanBlock;
import net.minecraft.server.Block;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.Item;
import net.minecraft.server.ItemStack;
import net.minecraft.server.World;

public class LogTurner extends Item
{
    public LogTurner(int var1)
    {
        super(var1);
        this.d(0);
        this.e(1);
    }

    public String getTextureFile()
    {
        return "/bunyan/items/items.png";
    }

    public boolean g()
    {
        return false;
    }

    /**
     * Checks isDamagable and if it cannot be stacked
     */
    public boolean f(ItemStack var1)
    {
        return true;
    }

    public boolean onItemUseFirst(ItemStack var1, EntityHuman var2, World var3, int var4, int var5, int var6, int var7)
    {
        int var8 = var3.getTypeId(var4, var5, var6);

        if (var8 != 0 && (var8 == Block.LOG.id || Block.byId[var8] instanceof ITurnable))
        {
            Direction var9 = Direction.fromValue(var7);

            if (KeyPressManager.isModeKeyPressed())
            {
                var9 = var9.oppositeSide();
            }

            if (var8 == Block.LOG.id)
            {
                if (var7 != 0 && var7 != 1)
                {
                    int var10 = var3.getData(var4, var5, var6);
                    var3.setRawTypeId(var4, var5, var6, BunyanBlock.turnableVanillaWood.id);
                    DirectionalBlock.setDataAndFacing(var3, var4, var5, var6, var10, var9, true);
                }
            }
            else
            {
                ((ITurnable)Block.byId[var8]).onLogTurner(var2, var3, var4, var5, var6, var9);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
