package teamasm.moh.block;

import codechicken.lib.block.property.PropertyString;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import teamasm.moh.tile.TileProcessorBase;

import static teamasm.moh.reference.VariantReference.machinesList;

/**
 * Created by covers1624 on 8/6/2016.
 */
public class BlockMachine extends BaseBlock {//TODO More stuff.

    public static final PropertyString TYPE = new PropertyString("type", machinesList);
    //public static final PropertyBool ACTIVE = PropertyBool.create("active");

    public BlockMachine() {
        super(Material.ROCK);
        setHardness(2.0F);
    }

    //region Render

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
        return false;
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return false;
    }

    @Override
    public EnumBlockRenderType getRenderType(IBlockState state) {
        return EnumBlockRenderType.INVISIBLE;
    }

    //endregion

    //region Blockstate

    @Override
    public int damageDropped(IBlockState state) {
        return getMetaFromState(state);
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        return getBlockState().getBaseState().withProperty(TYPE, machinesList.get(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state) {
        return machinesList.indexOf(String.valueOf(state.getValue(TYPE)));
    }

    @Override
    protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, TYPE);
    }

    //endregion

    //region Place

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        super.onBlockPlacedBy(world, pos, state, placer, stack);

        EnumFacing rotation = placer.getHorizontalFacing().getOpposite();
        TileEntity tile = world.getTileEntity(pos);

        if (!world.isRemote && tile instanceof TileProcessorBase) {
            ((TileProcessorBase) tile).setRotation(rotation);
            ((TileProcessorBase) tile).updateBlock();
        }
    }

    //endregion
}

@@ -246,31 +246,32 @@
 aft.
-entity.EntityLivingBase
+creativetab.CreativeTabs
 ;%0Aim
@@ -298,21 +298,16 @@
 tem.Item
-Stack
 ;%0Aimport
@@ -325,29 +325,22 @@
 aft.
-tileentity.TileEntity
+item.ItemStack
 ;%0Aim
@@ -388,46 +388,8 @@
 pe;%0A
-import net.minecraft.util.EnumFacing;%0A
 impo
@@ -477,76 +477,60 @@
 ort 
-net.minecraft.world.World;%0Aimport teamasm.moh.tile.TileProcessorBase
+teamasm.moh.MinablesOverhaul;%0A%0Aimport java.util.List
 ;%0A%0Ai
@@ -960,16 +960,286 @@
 (2.0F);%0A
+        setCreativeTab(MinablesOverhaul.MOH_TAB);%0A    %7D%0A%0A    @Override%0A    public void getSubBlocks(Item itemIn, CreativeTabs tab, List%3CItemStack%3E list) %7B%0A        for (int i = 0; i %3C machinesList.size(); i++) %7B%0A            list.add(new ItemStack(this, 1, i));%0A        %7D%0A
     %7D%0A%0A 
@@ -1257,17 +1257,16 @@
  Render%0A
-%0A
     @Ove
@@ -1701,33 +1701,32 @@
 NVISIBLE;%0A    %7D%0A
-%0A
     //endregion%0A
@@ -1750,17 +1750,16 @@
 ckstate%0A
-%0A
     @Ove
@@ -2304,576 +2304,8 @@
   %7D%0A
-%0A    //endregion%0A%0A    //region Place%0A%0A    @Override%0A    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) %7B%0A        super.onBlockPlacedBy(world, pos, state, placer, stack);%0A%0A        EnumFacing rotation = placer.getHorizontalFacing().getOpposite();%0A        TileEntity tile = world.getTileEntity(pos);%0A%0A        if (!world.isRemote && tile instanceof TileProcessorBase) %7B%0A            ((TileProcessorBase) tile).setRotation(rotation);%0A            ((TileProcessorBase) tile).updateBlock();%0A        %7D%0A    %7D%0A%0A
     

Add stuff to the creatve tab.