@Override
  public void updateEntity() {
    super.updateEntity();

    if (items[0] != null && items[1] != null && ticksLeft == 0) {
      FluidRecipe2_1 r = RecipesLiquifier.getRecipeFromStack(items[0], items[1]);
      if (r != null) {
        maxTicks = r.getTime();
      }
    }

    if (ticksLeft < maxTicks && RecipesLiquifier.getRecipeFromStack(items[0], items[1]) != null) {
      if (RecipesLiquifier.getRecipeFromStack(items[0], items[1])
          .getOutput()
          .getFluid()
          .equals(tank.getFluid())) {
        ticksLeft++;
        worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
      } else {
        ticksLeft = 0;
        resetTimeAndTexture();
      }
    }
    if (RecipesLiquifier.getRecipeFromStack(items[0], items[1]) == null && ticksLeft > 0) {
      ticksLeft = 0;
      resetTimeAndTexture();
    }
    if (ticksLeft == maxTicks && maxTicks != 0) {
      ticksLeft = 0;
      liquify();
    }
  }
Example #2
0
 public static void injectEnergy(TileEntityMachineBase tileEntity, ForgeDirection dir) {
   TileEntity connectedTileEntity =
       tileEntity.worldObj.getBlockTileEntity(
           tileEntity.xCoord + dir.offsetX,
           tileEntity.yCoord + dir.offsetY,
           tileEntity.zCoord + dir.offsetZ);
   if (connectedTileEntity != null) {
     if (connectedTileEntity instanceof ILargeEnergyStorage) {
       ILargeEnergyStorage storage = (ILargeEnergyStorage) connectedTileEntity;
       if (tileEntity instanceof ILargeEnergyStorage) {
         ILargeEnergyStorage source = (ILargeEnergyStorage) tileEntity;
         BigInteger demand =
             source
                 .getAllStoredEnergy()
                 .min(storage.getFullCapacity().subtract(storage.getAllStoredEnergy()));
         storage.setAllEnergy(storage.getAllStoredEnergy().add(demand));
         source.useLargeEnergy(demand);
       } else {
         BigInteger demand =
             Util.toBigInteger(tileEntity.getStored())
                 .min(storage.getFullCapacity().subtract(storage.getAllStoredEnergy()));
         storage.setAllEnergy(storage.getAllStoredEnergy().add(demand));
         tileEntity.useEnergy(demand.intValue());
       }
     } else if (connectedTileEntity instanceof IEnergyStorage) {
       IEnergyStorage storage = (IEnergyStorage) connectedTileEntity;
       int demand = Math.min(tileEntity.getStored(), storage.getCapacity() - storage.getStored());
       storage.setStored(storage.getStored() + demand);
       tileEntity.useEnergy(demand);
     } else if (connectedTileEntity instanceof IEnergySink) {
       IEnergySink sink = (IEnergySink) connectedTileEntity;
       int demand = 0;
       int prevStoredEnergy = 0;
       while ((demand = Math.min(sink.getMaxSafeInput() - 1, tileEntity.getStored())) > 0
           && tileEntity.getStored() != prevStoredEnergy) {
         prevStoredEnergy = tileEntity.getStored();
         sink.injectEnergy(DIRECTION_MAP.get(dir.getOpposite()), demand);
         tileEntity.useEnergy(demand);
       }
     }
   }
 }