public void readFromNBT(NBTTagCompound nbttagcompound) {
   super.readFromNBT(nbttagcompound);
   fuel = nbttagcompound.getShort("fuel");
   heat = nbttagcompound.getShort("heat");
   energy = nbttagcompound.getShort("energy");
   fueltype = nbttagcompound.getShort("fueltype");
   bred = nbttagcompound.getInteger("bred");
 }
 public void writeToNBT(NBTTagCompound nbttagcompound) {
   super.writeToNBT(nbttagcompound);
   nbttagcompound.setShort("heat", heat);
   nbttagcompound.setShort("fuel", (short) fuel);
   nbttagcompound.setShort("fueltype", fueltype);
   nbttagcompound.setShort("energy", energy);
   nbttagcompound.setInteger("bred", bred);
 }
  public void updateEntity() {
    if (!reallyAddedToEnergyNet && ignited()) {
      EnergyNet.getForWorld(worldObj).addTileEntity(this);
      reallyAddedToEnergyNet = true;
    }

    if (fuel <= 0) {
      gainFuel();
    }

    if (!ignited() && hasCoils() && fuel > 0) {
      if (energy <= 0 && inventory[0] != null) {
        int i = inventory[0].itemID;
        Item item = Item.itemsList[i];

        if (item instanceof ItemBattery) {
          energy += ((ItemBattery) item).discharge(inventory[0], 1000 - energy, 1, false, false);
        }

        if (i == Item.redstone.shiftedIndex) {
          energy += 500;
          inventory[0].stackSize--;

          if (inventory[0].stackSize <= 0) {
            inventory[0] = null;
          }
        }

        if (i == Ic2Items.suBattery.itemID) {
          energy += 1000;
          inventory[0].stackSize--;

          if (inventory[0].stackSize <= 0) {
            inventory[0] = null;
          }
        }
      }

      if (energy > 0 && hasHeaters() && hasCoils() && fuel > 0) {
        for (int panda = 4; panda <= 6; panda++) {
          if (energy > 0
              && inventory[panda] != null
              && inventory[panda].itemID == mod_RocketScience.itemRfHeaterId + 256) {
            energy -= 15;
            heat += 10;
          } else if (energy > 0
              && inventory[panda] != null
              && inventory[panda].itemID == mod_RocketScience.itemNeutralHeaterId + 256) {
            energy -= 20;
            heat += 10;
          } else if (energy > 0
              && inventory[panda] != null
              && inventory[panda].itemID == mod_RocketScience.itemOhmicHeaterId + 256) {
            int i = (5000 - heat) / 500;
            energy -= i;
            heat += i;
          }
        }
      }
    }

    if (ignited()) {
      if (fueltype == 0) {
        production = 0;
      } else if (fueltype == 1) {
        production = 32;
      } else if (fueltype == 3) {
        production = 128;
      }

      // other fuels here

      if (inventory[3] != null && inventory[3].itemID != mod_RocketScience.itemSuperCoilsId + 256) {
        production -= 10;
      }

      if (inventory[7] != null
          && inventory[7].itemID == mod_RocketScience.itemLithium6Cell.shiftedIndex) {
        bred += 1;

        if (bred >= 9500) {
          bred = 0;
          inventory[7].stackSize--;

          if (inventory[7].stackSize <= 0) {
            inventory[7] = null;
          }

          boolean tritty = false;

          if (inventory[1] != null && inventory[2] != null) {
            if (inventory[1].itemID == mod_RocketScience.itemDeuteriumCell.shiftedIndex
                && inventory[2].itemID == mod_RocketScience.itemDeuteriumCell.shiftedIndex
                && inventory[2].stackSize + inventory[1].stackSize <= 64) {
              inventory[1].stackSize += inventory[2].stackSize;
              inventory[2] = new ItemStack(mod_RocketScience.itemTritiumCell);
              tritty = true;
            } else if (inventory[1].itemID == mod_RocketScience.itemDeuteriumCell.shiftedIndex
                && inventory[2].itemID == mod_RocketScience.itemTritiumCell.shiftedIndex
                && inventory[2].stackSize < 64) {
              inventory[2].stackSize++;
              tritty = true;
            } else if (inventory[2].itemID == mod_RocketScience.itemDeuteriumCell.shiftedIndex
                && inventory[1].itemID == mod_RocketScience.itemTritiumCell.shiftedIndex
                && inventory[1].stackSize < 64) {
              inventory[1].stackSize++;
              tritty = true;
            }
          } else if (inventory[1] == null) {
            if (inventory[2] != null
                && inventory[2].itemID == mod_RocketScience.itemTritiumCell.shiftedIndex
                && inventory[2].stackSize < 64) {
              inventory[2].stackSize++;
              tritty = true;
            } else {
              inventory[1] = new ItemStack(mod_RocketScience.itemTritiumCell);
              tritty = true;
            }
          } else if (inventory[2] == null) {
            if (inventory[1] != null
                && inventory[1].itemID == mod_RocketScience.itemTritiumCell.shiftedIndex
                && inventory[1].stackSize < 64) {
              inventory[1].stackSize++;
              tritty = true;
            } else {
              inventory[2] = new ItemStack(mod_RocketScience.itemTritiumCell);
              tritty = true;
            }
          }

          if (!tritty && inventory[7] == null) {
            inventory[7] = new ItemStack(mod_RocketScience.itemTritiumCell);
            tritty = true;
          }

          // If we haven't placed the tritium yet, drop it.
          if (!tritty) {
            ArrayList list = new ArrayList();
            list.add(new ItemStack(mod_RocketScience.itemTritiumCell));
            StackUtil.distributeDrop(this, list);
          }
        }
      }
    } else {
      production = 0;
    }

    super.updateEntity();

    if ((fuel <= 0
            || inventory[3] == null
            || (inventory[3].itemID != mod_RocketScience.itemSuperCoilsId + 256
                && inventory[3].itemID != mod_RocketScience.itemCopperCoilsId + 256))
        && heat > 0) {
      heat -= 100;
      storage += 100;

      if (storage > maxStorage) {
        storage = maxStorage;
      }
    }
  }