/FileExtraction/Java_unseen/trychen_ChinaCraft/src/main/java/unstudio/chinacraft/block/especial/BlockBuhrimill.java
package unstudio.chinacraft.block.especial;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import unstudio.chinacraft.client.gui.GuiID;
import unstudio.chinacraft.client.waila.WailaCompatibility.CCWailaInfoProvider;
import unstudio.chinacraft.common.ChinaCraft;
import unstudio.chinacraft.tileentity.TileBuhrimill;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;

public class BlockBuhrimill extends BlockContainer implements CCWailaInfoProvider {

    private IIcon icon;

    public BlockBuhrimill() {
        super(Material.rock);
        setBlockName("buhrimill");
        setHardness(3.0F);
        setResistance(10.0F);
        setCreativeTab(ChinaCraft.tabCore);
        setStepSound(soundTypeStone);
        setHarvestLevel("pickaxe", 1);
    }

    @Override
    public void addCollisionBoxesToList(World p_149743_1_, int p_149743_2_,
                                        int p_149743_3_, int p_149743_4_, AxisAlignedBB p_149743_5_,
                                        List p_149743_6_, Entity p_149743_7_) {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
        super.addCollisionBoxesToList(p_149743_1_, p_149743_2_, p_149743_3_,
                p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_);
        this.setBlockBounds(0.25F, 0.5F, 0.25F, 0.75F, 0.875F, 0.75F);
        super.addCollisionBoxesToList(p_149743_1_, p_149743_2_, p_149743_3_,
                p_149743_4_, p_149743_5_, p_149743_6_, p_149743_7_);
        this.setBlockBoundsForItemRender();
    }

    @Override
    public void setBlockBoundsForItemRender() {
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
    }

    @Override
    public int getRenderType() {
        return -1;
    }

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

    @Override
    public boolean renderAsNormalBlock() {
        return false;
    }

    @Override
    public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_,
                                EntityLivingBase p_149689_5_, ItemStack p_149689_6_) {
        int l = MathHelper.floor_double(p_149689_5_.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;

        if (l == 0) {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 4, 2);
        }

        if (l == 1) {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 5, 2);
        }

        if (l == 2) {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 2, 2);
        }

        if (l == 3) {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 3, 2);
        }
    }

    @Override
    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) {
        return Item.getItemFromBlock(ChinaCraft.buhrimill);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) {
        return Item.getItemFromBlock(ChinaCraft.buhrimill);
    }

    @Override
    public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
        TileBuhrimill tileentity = (TileBuhrimill) world.getTileEntity(x, y, z);
        ArrayList<ItemStack> is = new ArrayList<>();
        if (tileentity != null) {
            for (int i1 = 0; i1 < tileentity.getSizeInventory(); ++i1) {
                ItemStack itemstack = tileentity.getStackInSlot(i1);
                if (itemstack != null && itemstack.stackSize > 0) {
                        is.add(itemstack);
                }
            }
        }
        return is;
    }

    @Override
    public TileEntity createNewTileEntity(World var1, int var2) {
        return new TileBuhrimill();
    }

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p_149727_5_, int p_149727_6_,
                                    float p_149727_7_, float p_149727_8_, float p_149727_9_) {
        if (!world.isRemote)
            if (p_149727_5_.isSneaking())
                p_149727_5_.openGui(ChinaCraft.instance, GuiID.GUI_Buhrimill, world, x, y, z);
            else if (world.getTileEntity(x, y, z) instanceof TileBuhrimill)
                ((TileBuhrimill) world.getTileEntity(x, y, z)).addAngle(10);
        return true;
    }

    @Override
    public void breakBlock(World World, int x, int y, int z, Block Block, int var1) {
        super.breakBlock(World, x, y, z, Block, var1);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_) {
        icon = p_149651_1_.registerIcon("Minecraft:stone");
    }

    @Override
    public IIcon getIcon(int p_149691_1_, int p_149691_2_) {
        return icon;
    }

    @Override
    public List<String> addWailaBodyInfo(ItemStack stack, List<String> tipList, TileEntity tile) {
        if (tile instanceof TileBuhrimill) {
            TileBuhrimill tileBuhrimill = (TileBuhrimill) tile;
            int maxSchedule = tileBuhrimill.getMaxSchedule();
            switch (maxSchedule) {
            case -1:
                tipList.add(EnumChatFormatting.GRAY + I18n.format("waila.noneInput.info"));
                break;
            case 0:
                tipList.add(EnumChatFormatting.YELLOW + I18n.format("waila.invalidInput.info"));
                break;
            default:
                tipList.add(EnumChatFormatting.GREEN + I18n.format("waila.progress.info") + 100 * tileBuhrimill.schedule / maxSchedule + "%");
            }
        }
        return tipList;
    }
}
