package bunyan.blocks;

import bunyan.api.Direction;
import bunyan.api.DirectionalBlock;
import java.util.ArrayList;
import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.MathHelper;
import net.minecraft.server.World;

public class WideLogBarkOnTop extends WideLog
{
    public WideLogBarkOnTop(int var1)
    {
        super(var1);
    }

    public void addCreativeItems(ArrayList var1) {}

    /**
     * The type of render function that is called for this block
     */
    public int c()
    {
        return RenderManager.getRenderID();
    }

    public int getTextureOffsetFromFacingSideAndMetadata(Direction var1, Direction var2, int var3)
    {
        byte var4 = 0;
        byte var5 = 0;

        if (var2 == Direction.DOWN)
        {
            var4 = 3;
        }
        else if (var2 != Direction.UP)
        {
            if (var2 == var1.rightSide())
            {
                var4 = 3;
            }
            else if (var2 == var1)
            {
                var4 = 1;
                var5 = 1;
            }
            else if (var2 == var1.oppositeSide())
            {
                var4 = 1;
            }
            else
            {
                var5 = 1;
            }
        }

        int var6 = getDataFromMetadata(var3);
        return var4 * 16 + var5 + var6 * 2;
    }

    /**
     * Called when the block is placed in the world.
     */
    public void postPlace(World var1, int var2, int var3, int var4, EntityLiving var5)
    {
        Direction var6 = Direction.NORTH;

        if (var5 != null)
        {
            int var7 = MathHelper.floor((double)(var5.yaw * 4.0F / 360.0F) + 0.5D) & 3;

            switch (var7)
            {
                case 0:
                    var6 = Direction.SOUTH;
                    break;

                case 1:
                    var6 = Direction.WEST;
                    break;

                case 2:
                    var6 = Direction.NORTH;
                    break;

                case 3:
                    var6 = Direction.EAST;
            }

            setFacing(var1, var2, var3, var4, var6, true);
        }
    }

    public void onLogTurner(EntityHuman var1, World var2, int var3, int var4, int var5, Direction var6)
    {
        if (var6 != Direction.UP && var6 != Direction.DOWN)
        {
            DirectionalBlock.setFacing(var2, var3, var4, var5, var6.oppositeSide(), true);
        }
        else
        {
            int var7 = DirectionalBlock.getDataFromMetadata(var2.getData(var3, var4, var5));
            var2.setRawTypeIdAndData(var3, var4, var5, BunyanBlock.widewood.id, var7);
            BunyanBlock.widewood.postPlace(var2, var3, var4, var5, var1);
        }
    }
}
