package com.zivilon.cinder_loe.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRotatedPillar;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import com.zivilon.cinder_loe.util.Utilities;

public abstract class RotatableBlockBase2 extends BlockRotatedPillar {
    public String textureName;
    public IIcon[] icons = new IIcon[3];

    public RotatableBlockBase2(Material material, String blockName) {
        super(material);
        this.textureName = Utilities.toSnakeCase(blockName);
        this.setBlockName(blockName);
        // Get LOTRCreativeTabs.tabBlock without ForgeGradle incorrectly obfuscating it. Uses cached field, not real-time reflection
        this.setCreativeTab((CreativeTabs)Utilities.reflected_tab_block);
    }

    public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta) {
        int orientation = 0;
        switch (side) {
            case 0: // Bottom
            case 1: // Top
                orientation = 0;
                break;
            case 2: // North
            case 3: // South
                orientation = 1;
                break;
            case 4: // West
            case 5: // East
                orientation = 2;
                break;
        }

        return orientation;
    }

    public int damageDropped(int i) {
        return 0;
    }


    @Override
    public IIcon getIcon(int side, int meta) {
        switch(meta) {
            case 0: // Facing up
                if(side == 0 || side == 1) return this.icons[0];
                else return this.icons[1];
            case 1: // Facing North-South
                if(side == 2 || side == 3) return this.icons[0];
                if(side == 4 || side == 5) return this.icons[2];
                else return this.icons[1];
            case 2: // Facing East-West
                if(side == 4 || side == 5) return this.icons[0];
                else return this.icons[2];
            case 3: // Uniform block
                return this.icons[1];
        }

        return this.blockIcon; // Default case, should not happen
    }

    @Override
    public void registerBlockIcons(IIconRegister reg) {
        icons[0] = reg.registerIcon(this.textureName + "_top");
        icons[1] = reg.registerIcon(this.textureName + "_side_0");
        icons[2] = reg.registerIcon(this.textureName + "_side_90");
    }

    @SideOnly(Side.CLIENT)
    protected IIcon getSideIcon(int i) {
        return null;
    }
}