package pokefenn.totemic.block.totem;

import java.util.Random;
import java.util.stream.Collectors;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import pokefenn.totemic.ModItems;
import pokefenn.totemic.Totemic;
import pokefenn.totemic.api.TotemicStaffUsage;
import pokefenn.totemic.api.ceremony.Ceremony;
import pokefenn.totemic.lib.Strings;
import pokefenn.totemic.lib.WoodVariant;
import pokefenn.totemic.tileentity.totem.*;

public class BlockTotemBase extends Block implements ITileEntityProvider, TotemicStaffUsage
{
    public static final PropertyEnum<WoodVariant> WOOD = PropertyEnum.create("wood", WoodVariant.class);

    public BlockTotemBase()
    {
        super(Material.WOOD);
        setRegistryName(Strings.TOTEM_BASE_NAME);
        setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.TOTEM_BASE_NAME);
        setCreativeTab(Totemic.tabsTotem);
        setHardness(2);
        setSoundType(SoundType.WOOD);
        Blocks.FIRE.setFireInfo(this, 5, 5);
    }

    @Override
    public void onBlockClicked(World world, BlockPos pos, EntityPlayer player)
    {
        if(!world.isRemote)
        {
            TileTotemBase tile = (TileTotemBase) world.getTileEntity(pos);
            if(tile != null)
                if(player.getHeldItemMainhand().getItem() == ModItems.totemic_staff && !(tile.getState() instanceof StateTotemEffect))
                {
                    ((WorldServer) world).spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 16, 0.6D, 0.5D, 0.6D, 0.0D);
                    tile.resetState();
                }
        }
    }

    @Override
    public EnumActionResult onTotemicStaffRightClick(World world, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if(!world.isRemote)
            return EnumActionResult.SUCCESS;
        TileTotemBase tile = (TileTotemBase) world.getTileEntity(pos);

        if(tile.getState() instanceof StateTotemEffect)
        {
            player.sendStatusMessage(new TextComponentTranslation("totemicmisc.isDoingNoCeremony"), true);
        }
        else if(tile.getState() instanceof StateSelection)
        {
            String selectors = ((StateSelection) tile.getState()).getSelectors().stream()
                    .map(instr -> I18n.format(instr.getUnlocalizedName()))
                    .collect(Collectors.joining(", "));
            player.sendMessage(new TextComponentTranslation("totemicmisc.isDoingSelection"));
            player.sendMessage(new TextComponentTranslation("totemicmisc.selection", selectors));
        }
        else if(tile.getState() instanceof StateStartup)
        {
            Ceremony ceremony = ((StateStartup) tile.getState()).getCeremony();
            player.sendMessage(new TextComponentTranslation("totemicmisc.isDoingStartup"));
            player.sendMessage(new TextComponentTranslation(ceremony.getUnlocalizedName()));
        }
        else if(tile.getState() instanceof StateCeremonyEffect)
        {
            Ceremony ceremony = ((StateCeremonyEffect) tile.getState()).getCeremony();
            player.sendMessage(new TextComponentTranslation("totemicmisc.isDoingCeremony"));
            player.sendMessage(new TextComponentTranslation(ceremony.getUnlocalizedName()));
        }

        return EnumActionResult.SUCCESS;
    }

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

    @Override
    public int quantityDropped(Random rand)
    {
        return 0;
    }

    @Override
    public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list)
    {
        for(int i = 0; i < WoodVariant.values().length; i++)
            list.add(new ItemStack(this, 1, i));
    }

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

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return state.getValue(WOOD).ordinal();
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return getDefaultState().withProperty(WOOD, WoodVariant.values()[meta]);
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        return new TileTotemBase();
    }

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return new AxisAlignedBB(0.125F, 0.0F, 0.125F, 0.875F, 1.0F, 0.875F);
    }

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

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

    @Override
    public BlockFaceShape getBlockFaceShape(IBlockAccess world, IBlockState state, BlockPos pos, EnumFacing facing)
    {
        return BlockFaceShape.UNDEFINED;
    }
}

@@ -3301,32 +3301,38 @@
      player.send
+Status
 Message(new Text
@@ -3383,16 +3383,23 @@
 ection%22)
+, false
 );%0A     
@@ -3408,32 +3408,38 @@
      player.send
+Status
 Message(new Text
@@ -3494,16 +3494,23 @@
 lectors)
+, false
 );%0A     
@@ -3676,32 +3676,38 @@
      player.send
+Status
 Message(new Text
@@ -3756,16 +3756,23 @@
 tartup%22)
+, false
 );%0A     
@@ -3781,32 +3781,38 @@
      player.send
+Status
 Message(new Text
@@ -3854,32 +3854,39 @@
 localizedName())
+, false
 );%0A        %7D%0A   
@@ -4058,32 +4058,38 @@
      player.send
+Status
 Message(new Text
@@ -4139,16 +4139,23 @@
 remony%22)
+, false
 );%0A     
@@ -4172,16 +4172,22 @@
 yer.send
+Status
 Message(
@@ -4245,16 +4245,23 @@
 dName())
+, false
 );%0A     

Replace sendMessage with sendStatusMessage, actionBar=false