package hmggirlfront.block;
 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import javax.annotation.Nullable;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.block.tile.TileEntityHelpBuildingBase;
import hmggirlfront.block.tile.TileEntityM_Crafting;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
//import net.minecraft.world.gen.structure.StructureStrongholdPieces;;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
 
public class Block_HelpBuildingBase extends BlockContainer
{
	public FMLPreInitializationEvent pEvent;
	public String txt;
	public int sizex = 16;
	public int sizez = 16;
	public int sizey = 16;
	public int offsety = 0;
	public boolean setair = false;
	public boolean setbed = false;
	public boolean text_on = true;
	public String information1 = "hmggirlfront.helpebase.1.name";;
	public String information2 = "hmggirlfront.helpebase.2.name";;
	public String information3 = "hmggirlfront.helpebase.3.name";;
	public String information4 = null;
	
    public Block_HelpBuildingBase(String t) {
        super(Material.ROCK);
        txt = t;
        setHardness(1.5F);
        setResistance(1.0F);
        setLightOpacity(1);
        setLightLevel(1.0F);
    }
 
    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, ITooltipFlag advanced)
    {
        super.addInformation(stack, player, tooltip, advanced);
        if(text_on) {
        	TextFormatting information1_color = TextFormatting.WHITE;
        	if(information1 != null) {
    			TextComponentTranslation information = new TextComponentTranslation(information1, new Object[0]);
    			tooltip.add(information1_color + information.getFormattedText());
    		}
    		if(information2 != null) {
    			TextComponentTranslation information = new TextComponentTranslation(information2, new Object[0]);
    			tooltip.add(information1_color + information.getFormattedText());
    		}
    		if(information3 != null) {
    			TextComponentTranslation information = new TextComponentTranslation(information3, new Object[0]);
    			tooltip.add(information1_color + information.getFormattedText());
    		}
    		if(information4 != null) {
    			TextComponentTranslation information = new TextComponentTranslation(information4, new Object[0]);
    			tooltip.add(information1_color + information.getFormattedText());
    		}
        }
        
    }
    
    /**
     * Returns a new instance of a block's tile entity class. Called on placing the block.
     */
    public TileEntity createNewTileEntity(World worldIn, int meta)
    {
        return new TileEntityHelpBuildingBase();
    }
    
    public void Building(World worldIn, BlockPos pos, IBlockState state)
    {
    	BaseBuilding building = new BaseBuilding();
    	{
    		building.txt = txt;
    		building.sizex = sizex;
    		building.sizez = sizez;
    		building.sizey = sizey;
    		building.offsety = offsety;
    		building.setair = setair;
    		building.setbed = setbed; 
    		building.BuildingBase(worldIn, pos, state);
    	}
    }
    
    
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
    	if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
        	TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityHelpBuildingBase)
            {
            	TileEntityHelpBuildingBase building = (TileEntityHelpBuildingBase) tileentity;
            	if(playerIn.isSneaking()) {
            		building.canbuilding = false;
            		building.time = 400;
            		if(FMLCommonHandler.instance().getMinecraftServerInstance() != null) {
        				for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers())
        	            {
        					player.sendMessage(new TextComponentTranslation("Building canceled...", new Object[0]));
        	            }
                    }
            	}else {
            		building.canbuilding = true;
            		building.time = 400;
            	}
            }
        	/*BaseBuilding building = new BaseBuilding();
        	{
        		building.txt = txt;
        		building.sizex = sizex;
        		building.sizez = sizez;
        		building.sizey = sizey;
        		building.offsety = offsety;
        		building.setair = setair;
        		building.setbed = setbed; 
        		building.BuildingBase(worldIn, pos, state);
        	}*/
        	 return true;
        }
    }
    
    /**
     * The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
     * LIQUID for vanilla liquids, INVISIBLE to skip all rendering
     */
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }
}