private int func_70452_e(ItemStack p_70452_1_) {
    int var2 = p_70452_1_.field_77993_c;
    int var3 = p_70452_1_.field_77994_a;
    int var4;
    if (p_70452_1_.func_77976_d() == 1) {
      var4 = this.func_70447_i();
      if (var4 < 0) {
        return var3;
      } else {
        if (this.field_70462_a[var4] == null) {
          this.field_70462_a[var4] = ItemStack.func_77944_b(p_70452_1_);
        }

        return 0;
      }
    } else {
      var4 = this.func_70432_d(p_70452_1_);
      if (var4 < 0) {
        var4 = this.func_70447_i();
      }

      if (var4 < 0) {
        return var3;
      } else {
        if (this.field_70462_a[var4] == null) {
          this.field_70462_a[var4] = new ItemStack(var2, 0, p_70452_1_.func_77960_j());
          if (p_70452_1_.func_77942_o()) {
            this.field_70462_a[var4].func_77982_d(
                (NBTTagCompound) p_70452_1_.func_77978_p().func_74737_b());
          }
        }

        int var5 = var3;
        if (var3
            > this.field_70462_a[var4].func_77976_d() - this.field_70462_a[var4].field_77994_a) {
          var5 = this.field_70462_a[var4].func_77976_d() - this.field_70462_a[var4].field_77994_a;
        }

        if (var5 > this.func_70297_j_() - this.field_70462_a[var4].field_77994_a) {
          var5 = this.func_70297_j_() - this.field_70462_a[var4].field_77994_a;
        }

        if (var5 == 0) {
          return var3;
        } else {
          var3 -= var5;
          this.field_70462_a[var4].field_77994_a += var5;
          this.field_70462_a[var4].field_77992_b = 5;
          return var3;
        }
      }
    }
  }
  public void func_71852_a(
      World p_71852_1_,
      int p_71852_2_,
      int p_71852_3_,
      int p_71852_4_,
      int p_71852_5_,
      int p_71852_6_) {
    TileEntityChest var7 =
        (TileEntityChest) p_71852_1_.func_72796_p(p_71852_2_, p_71852_3_, p_71852_4_);
    if (var7 != null) {
      for (int var8 = 0; var8 < var7.func_70302_i_(); ++var8) {
        ItemStack var9 = var7.func_70301_a(var8);
        if (var9 != null) {
          float var10 = this.field_72293_a.nextFloat() * 0.8F + 0.1F;
          float var11 = this.field_72293_a.nextFloat() * 0.8F + 0.1F;

          EntityItem var14;
          for (float var12 = this.field_72293_a.nextFloat() * 0.8F + 0.1F;
              var9.field_77994_a > 0;
              p_71852_1_.func_72838_d(var14)) {
            int var13 = this.field_72293_a.nextInt(21) + 10;
            if (var13 > var9.field_77994_a) {
              var13 = var9.field_77994_a;
            }

            var9.field_77994_a -= var13;
            var14 =
                new EntityItem(
                    p_71852_1_,
                    (double) ((float) p_71852_2_ + var10),
                    (double) ((float) p_71852_3_ + var11),
                    (double) ((float) p_71852_4_ + var12),
                    new ItemStack(var9.field_77993_c, var13, var9.func_77960_j()));
            float var15 = 0.05F;
            var14.field_70159_w = (double) ((float) this.field_72293_a.nextGaussian() * var15);
            var14.field_70181_x =
                (double) ((float) this.field_72293_a.nextGaussian() * var15 + 0.2F);
            var14.field_70179_y = (double) ((float) this.field_72293_a.nextGaussian() * var15);
            if (var9.func_77942_o()) {
              var14
                  .func_92059_d()
                  .func_77982_d((NBTTagCompound) var9.func_77978_p().func_74737_b());
            }
          }
        }
      }
    }

    super.func_71852_a(p_71852_1_, p_71852_2_, p_71852_3_, p_71852_4_, p_71852_5_, p_71852_6_);
  }
  public void func_72501_a(Packet250CustomPayload p_72501_1_) {
    DataInputStream var2;
    ItemStack var3;
    ItemStack var4;
    if ("MC|BEdit".equals(p_72501_1_.field_73630_a)) {
      try {
        var2 = new DataInputStream(new ByteArrayInputStream(p_72501_1_.field_73629_c));
        var3 = Packet.func_73276_c(var2);
        if (!ItemWritableBook.func_77829_a(var3.func_77978_p())) {
          throw new IOException("Invalid book tag!");
        }

        var4 = this.field_72574_e.field_71071_by.func_70448_g();
        if (var3 != null
            && var3.field_77993_c == Item.field_77821_bF.field_77779_bT
            && var3.field_77993_c == var4.field_77993_c) {
          var4.func_77983_a("pages", var3.func_77978_p().func_74761_m("pages"));
        }
      } catch (Exception var14) {
        var14.printStackTrace();
      }
    } else if ("MC|BSign".equals(p_72501_1_.field_73630_a)) {
      try {
        var2 = new DataInputStream(new ByteArrayInputStream(p_72501_1_.field_73629_c));
        var3 = Packet.func_73276_c(var2);
        if (!ItemEditableBook.func_77828_a(var3.func_77978_p())) {
          throw new IOException("Invalid book tag!");
        }

        var4 = this.field_72574_e.field_71071_by.func_70448_g();
        if (var3 != null
            && var3.field_77993_c == Item.field_77823_bG.field_77779_bT
            && var4.field_77993_c == Item.field_77821_bF.field_77779_bT) {
          var4.func_77983_a(
              "author", new NBTTagString("author", this.field_72574_e.field_71092_bJ));
          var4.func_77983_a(
              "title", new NBTTagString("title", var3.func_77978_p().func_74779_i("title")));
          var4.func_77983_a("pages", var3.func_77978_p().func_74761_m("pages"));
          var4.field_77993_c = Item.field_77823_bG.field_77779_bT;
        }
      } catch (Exception var13) {
        var13.printStackTrace();
      }
    } else {
      int var5;
      if ("MC|TrSel".equals(p_72501_1_.field_73630_a)) {
        try {
          var2 = new DataInputStream(new ByteArrayInputStream(p_72501_1_.field_73629_c));
          var5 = var2.readInt();
          Container var6 = this.field_72574_e.field_71070_bA;
          if (var6 instanceof ContainerMerchant) {
            ((ContainerMerchant) var6).func_75175_c(var5);
          }
        } catch (Exception var12) {
          var12.printStackTrace();
        }
      } else {
        String var8;
        int var15;
        if ("MC|AdvCdm".equals(p_72501_1_.field_73630_a)) {
          if (!this.field_72573_d.func_82356_Z()) {
            this.field_72574_e.func_70006_a(
                this.field_72574_e.func_70004_a("advMode.notEnabled", new Object[0]));
          } else if (this.field_72574_e.func_70003_b(2, "")
              && this.field_72574_e.field_71075_bZ.field_75098_d) {
            try {
              var2 = new DataInputStream(new ByteArrayInputStream(p_72501_1_.field_73629_c));
              var5 = var2.readInt();
              var15 = var2.readInt();
              int var7 = var2.readInt();
              var8 = Packet.func_73282_a(var2, 256);
              TileEntity var9 = this.field_72574_e.field_70170_p.func_72796_p(var5, var15, var7);
              if (var9 != null && var9 instanceof TileEntityCommandBlock) {
                ((TileEntityCommandBlock) var9).func_82352_b(var8);
                this.field_72574_e.field_70170_p.func_72845_h(var5, var15, var7);
                this.field_72574_e.func_70006_a("Command set: " + var8);
              }
            } catch (Exception var11) {
              var11.printStackTrace();
            }
          } else {
            this.field_72574_e.func_70006_a(
                this.field_72574_e.func_70004_a("advMode.notAllowed", new Object[0]));
          }
        } else if ("MC|Beacon".equals(p_72501_1_.field_73630_a)) {
          if (this.field_72574_e.field_71070_bA instanceof ContainerBeacon) {
            try {
              var2 = new DataInputStream(new ByteArrayInputStream(p_72501_1_.field_73629_c));
              var5 = var2.readInt();
              var15 = var2.readInt();
              ContainerBeacon var16 = (ContainerBeacon) this.field_72574_e.field_71070_bA;
              Slot var18 = var16.func_75139_a(0);
              if (var18.func_75216_d()) {
                var18.func_75209_a(1);
                TileEntityBeacon var19 = var16.func_82863_d();
                var19.func_82128_d(var5);
                var19.func_82127_e(var15);
                var19.func_70296_d();
              }
            } catch (Exception var10) {
              var10.printStackTrace();
            }
          }
        } else if ("MC|ItemName".equals(p_72501_1_.field_73630_a)
            && this.field_72574_e.field_71070_bA instanceof ContainerRepair) {
          ContainerRepair var17 = (ContainerRepair) this.field_72574_e.field_71070_bA;
          if (p_72501_1_.field_73629_c != null && p_72501_1_.field_73629_c.length >= 1) {
            var8 = ChatAllowedCharacters.func_71565_a(new String(p_72501_1_.field_73629_c));
            if (var8.length() <= 30) {
              var17.func_82850_a(var8);
            }
          } else {
            var17.func_82850_a("");
          }
        } else {
          ModLoader.serverCustomPayload(this, p_72501_1_);
        }
      }
    }
  }