@Override
  public void onBlockPlacedBy(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityLivingBase par5EntityLivingBase,
      ItemStack par6ItemStack) {
    int playerFacing =
        MathHelper.floor_double((double) ((par5EntityLivingBase.rotationYaw * 4F) / 360F) + 0.5D)
            & 3;

    boolean facing = false;
    if (playerFacing == 0) {
      facing = false;
    }
    if (playerFacing == 1) {
      facing = true;
    }
    if (playerFacing == 2) {
      facing = false;
    }
    if (playerFacing == 3) {
      facing = true;
    }

    // ItemStackのNBT
    NBTTagCompound nbt = par6ItemStack.getTagCompound();
    ItemStack input = null;
    byte rem = 0;

    if (nbt != null && nbt.hasKey("input")) {
      input = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("input"));
      rem = nbt.getByte("remain");
    }

    TileEntity tileEntity = par1World.getTileEntity(par2, par3, par4);
    if (tileEntity != null && tileEntity instanceof TilePanG) {
      TilePanG pan = (TilePanG) tileEntity;
      pan.setDirection(facing);
      pan.setItemStack(input);
      pan.setRemainByte(rem);
      pan.markDirty();
      par1World.markBlockForUpdate(par2, par3, par4);
    }
  }
  @Override
  public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
    TileEntity tile = par1World.getTileEntity(par2, par3, par4);

    if (tile instanceof TilePanG) {
      TilePanG tileentity = (TilePanG) tile;
      byte rem = tileentity.getRemainByte();
      ItemStack input = tileentity.getItemStack();
      String disp = tileentity.getDisplayName();

      ItemStack block = new ItemStack(this, 1, 0);

      float a = par1World.rand.nextFloat() * 0.8F + 0.1F;
      float a1 = par1World.rand.nextFloat() * 0.8F + 0.1F;
      float a2 = par1World.rand.nextFloat() * 0.8F + 0.1F;
      EntityItem drop =
          new EntityItem(
              par1World,
              (double) ((float) par2 + a),
              (double) ((float) par3 + a1),
              (double) ((float) par4 + a2),
              block);

      if (input != null) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setByte("remain", rem);
        tag.setString("display", disp);
        tag.setTag("input", input.writeToNBT(new NBTTagCompound()));
        drop.getEntityItem().setTagCompound(tag);
      }

      float a3 = 0.05F;
      drop.motionX = (double) ((float) par1World.rand.nextGaussian() * a3);
      drop.motionY = (double) ((float) par1World.rand.nextGaussian() * a3 + 0.2F);
      drop.motionZ = (double) ((float) par1World.rand.nextGaussian() * a3);
      par1World.spawnEntityInWorld(drop);
    }
  }
  @SideOnly(Side.CLIENT)
  @Override
  public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    int l = par1World.getBlockMetadata(par2, par3, par4);
    Block i = par1World.getBlock(par2, par3 - 1, par2);
    double d0 = (double) ((float) par2 + 0.25F + par5Random.nextFloat() / 2);
    double d1 = (double) ((float) par3 + par5Random.nextFloat());
    double d2 = (double) ((float) par4 + 0.25F + par5Random.nextFloat() / 2);
    double d3 = 0.0199999988079071D;
    double d4 = 0.27000001072883606D;

    TilePanG tile = (TilePanG) par1World.getTileEntity(par2, par3, par4);
    boolean flag = false;

    if (tile != null) {
      flag = (tile.getRemainByte() > 0);
    }

    if (!DCsConfig.noRenderFoodsSteam && flag) {
      EntityDCCloudFX cloud = new EntityDCCloudFX(par1World, d0, d1, d2, 0.0D, d3, 0.0D);
      cloud.setParticleIcon(ParticleTex.getInstance().getIcon("cloud"));
      FMLClientHandler.instance().getClient().effectRenderer.addEffect(cloud);
    }
  }
  @Override
  public boolean onBlockActivated(
      World par1World,
      int par2,
      int par3,
      int par4,
      EntityPlayer par5EntityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    ItemStack itemstack = par5EntityPlayer.inventory.getCurrentItem();
    TilePanG tile = (TilePanG) par1World.getTileEntity(par2, par3, par4);
    if (tile == null) return false;

    if (itemstack == null || itemstack.getItem() == Item.getItemFromBlock(this)) {
      ItemStack drop = new ItemStack(DCsAppleMilk.emptyPanGaiden, 1, 0);

      ItemStack input = tile.getItemStack();
      byte rem = tile.getRemainByte();
      String disp = tile.getDisplayName();

      if (input != null) {
        NBTTagCompound tag = new NBTTagCompound();

        tag.setByte("remain", rem);
        tag.setString("display", disp);
        tag.setTag("input", input.writeToNBT(new NBTTagCompound()));

        drop.setTagCompound(tag);
      }

      if (!par1World.isRemote) {
        EntityItem entity =
            new EntityItem(
                par1World,
                par5EntityPlayer.posX,
                par5EntityPlayer.posY,
                par5EntityPlayer.posZ,
                drop);
        par1World.spawnEntityInWorld(entity);
      }

      par1World.removeTileEntity(par2, par3, par4);
      par1World.setBlockToAir(par2, par3, par4);
      par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
      return true;
    } else if (itemstack.getItem() == Items.bowl) // 木のボウル:ノーマルのoutputを返し、remainを1減らす。
    {
      if (tile.getOutput() != null && tile.getRemainByte() > 0) {
        ItemStack ret = tile.getOutput().copy();
        int rem = tile.getRemainByte() - 1;

        if (!par5EntityPlayer.capabilities.isCreativeMode && --itemstack.stackSize <= 0) {
          par5EntityPlayer.inventory.setInventorySlotContents(
              par5EntityPlayer.inventory.currentItem, (ItemStack) null);
        }

        if (!par1World.isRemote) {
          EntityItem entity =
              new EntityItem(
                  par1World,
                  par5EntityPlayer.posX,
                  par5EntityPlayer.posY,
                  par5EntityPlayer.posZ,
                  ret);
          par1World.spawnEntityInWorld(entity);
        }
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
        if (ret.getItem() == Item.getItemFromBlock(DCsAppleMilk.bowlBlock)) {
          par5EntityPlayer.triggerAchievement(AchievementRegister.getSoup);
        }

        tile.setRemainByte((byte) rem);
        if (rem < 1) {
          tile.setItemStack(null);
          tile.setRemainByte((byte) 0);
          tile.markDirty();
          par1World.markBlockForUpdate(par2, par3, par4);
        }
      }
      return true;
    } else if (!LoadBambooPlugin.getBasket().isEmpty()
        && LoadBambooPlugin.isBasketItem(itemstack) >= 0) // 竹のボウル:和風のoutputを返し、remainを1減らす。
    {
      if (tile.getOutput() != null && tile.getRemainByte() > 0) {
        ItemStack ret = tile.getOutputJP().copy();
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setByte("BowlNum", (byte) LoadBambooPlugin.isBasketItem(itemstack));
        ret.setTagCompound(nbt);

        int rem = tile.getRemainByte() - 1;

        if (!par5EntityPlayer.capabilities.isCreativeMode && --itemstack.stackSize <= 0) {
          par5EntityPlayer.inventory.setInventorySlotContents(
              par5EntityPlayer.inventory.currentItem, (ItemStack) null);
        }

        if (!par1World.isRemote) {
          EntityItem entity =
              new EntityItem(
                  par1World,
                  par5EntityPlayer.posX,
                  par5EntityPlayer.posY,
                  par5EntityPlayer.posZ,
                  ret);
          par1World.spawnEntityInWorld(entity);
        }
        par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);

        tile.setRemainByte((byte) rem);
        if (rem < 1) {
          tile.setItemStack(null);
          tile.setRemainByte((byte) 0);
          tile.markDirty();
          par1World.markBlockForUpdate(par2, par3, par4);
        }
      }
      return true;
    } else // その他のアイテムはすべて材料判定に回す
    {
      Item ID = itemstack.getItem();
      int IDm = itemstack.getItemDamage();

      if (this.onFurnace(par1World, par2, par3 - 1, par4) && tile.getItemStack() == null) {
        ItemStack input = new ItemStack(ID, 1, IDm);

        if (ID == DCsAppleMilk.mincedFoods && IDm == 8) // チョコ鍋だけは旧仕様
        {
          par1World.removeTileEntity(par2, par3, par4);
          par1World.setBlock(par2, par3, par4, DCsAppleMilk.filledChocoPan);
          TileChocoPan tile2 = (TileChocoPan) par1World.getTileEntity(par2, par3, par4);
          tile2.setRemainByte((byte) 11);

          if (!par5EntityPlayer.capabilities.isCreativeMode && --itemstack.stackSize <= 0) {
            par5EntityPlayer.inventory.setInventorySlotContents(
                par5EntityPlayer.inventory.currentItem, (ItemStack) null);
          }

          par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
          return true;
        } else {
          IPanRecipe recipe = RecipeRegisterManager.panRecipe.getRecipe(input);
          if (recipe != null) {
            tile.setItemStack(input);
            tile.setRemainByte((byte) 3);
            tile.markDirty();
            par1World.markBlockForUpdate(par2, par3, par4);

            if (!par5EntityPlayer.capabilities.isCreativeMode && --itemstack.stackSize <= 0) {
              par5EntityPlayer.inventory.setInventorySlotContents(
                  par5EntityPlayer.inventory.currentItem, (ItemStack) null);
            }

            par1World.playSoundAtEntity(par5EntityPlayer, "random.pop", 0.4F, 1.8F);
            par5EntityPlayer.triggerAchievement(AchievementRegister.makeRice);
            return true;
          } else {
            if (par1World.isRemote)
              par5EntityPlayer.addChatMessage(
                  new ChatComponentText(StatCollector.translateToLocal("dc.panMessage.noRecipe")));
            return true;
          }
        }
      } else {
        if (!this.onFurnace(par1World, par2, par3 - 1, par4)) {
          if (par1World.isRemote)
            par5EntityPlayer.addChatMessage(
                new ChatComponentText(
                    StatCollector.translateToLocal("dc.panMessage.noHeatSource")));
          return true;
        } else if (tile.getItemStack() != null) {
          if (par1World.isRemote)
            par5EntityPlayer.addChatMessage(
                new ChatComponentText(
                    StatCollector.translateToLocal("dc.panMessage.alreadyHasRecipe")));
          return true;
        }
        return false;
      }
    }
  }