private void updateComparatorValuesPart1() {
   oldComps = new int[4];
   int vol = tank.getCapacity() / 4;
   for (int i = 0; i < 4; i++) {
     int filled = tank.getFluidAmount() - i * vol;
     oldComps[i] = Math.min(15, Math.max((15 * filled) / vol, 0));
   }
   masterCompOld = (15 * tank.getFluidAmount()) / tank.getCapacity();
 }
 public int getComparatorOutput() {
   if (pos == 4) {
     return (15 * tank.getFluidAmount()) / tank.getCapacity();
   }
   if (offset[1] >= 1 && offset[1] <= 4 && master() != null) { // 4 layers of storage
     FluidTank t = master().tank;
     int layer = offset[1] - 1;
     int vol = t.getCapacity() / 4;
     int filled = t.getFluidAmount() - layer * vol;
     int ret = Math.min(15, Math.max(0, (15 * filled) / vol));
     return ret;
   }
   return 0;
 }
Example #3
0
  @Override
  public void update() {
    // no recipeeeh
    if (recipe == null) {
      return;
    }

    // fully filled
    if (tank.getFluidAmount() == tank.getCapacity()) {
      timer++;
      if (timer >= recipe.getTime()) {
        TinkerCastingEvent.OnCasted event = TinkerCastingEvent.OnCasted.fire(recipe, this);
        // done, finish!
        if (event.consumeCast) {
          setInventorySlotContents(0, null);
        }

        // put result into output
        if (event.switchOutputs) {
          setInventorySlotContents(1, getStackInSlot(0));
          setInventorySlotContents(0, event.output);
        } else {
          setInventorySlotContents(1, event.output);
        }

        // reset state
        reset();
      }
    }
  }
  private void manageInventory() {
    if (FluidContainerUtils.isFluidContainer(inventory[0])) {
      FluidStack ret =
          FluidContainerUtils.handleContainerItem(
              this, inventory, editMode, fluidTank.getFluid(), getCurrentNeeded(), 0, 1, null);

      if (ret != null) {
        fluidTank.setFluid(PipeUtils.copy(ret, Math.min(fluidTank.getCapacity(), ret.amount)));

        int rejects = Math.max(0, ret.amount - fluidTank.getCapacity());

        if (rejects > 0) {
          pushUp(PipeUtils.copy(ret, rejects), true);
        }
      }
    }
  }
 public RefineryRecipe getRecipe(boolean checkCapacity) {
   RefineryRecipe recipe = DieselHandler.findRefineryRecipe(tank0.getFluid(), tank1.getFluid());
   if (recipe == null) return null;
   if (tank2.getFluid() == null
       || (tank2.getFluid().isFluidEqual(recipe.output)
           && (!checkCapacity
               || tank2.getFluidAmount() + recipe.output.amount <= tank2.getCapacity())))
     return recipe;
   return null;
 }
 public static ItemStack drainFluidContainer(FluidTank tank, ItemStack containerIn) {
   if (FluidContainerRegistry.isFilledContainer(containerIn)) {
     FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(containerIn);
     if (fs != null && tank.getFluidAmount() + fs.amount <= tank.getCapacity()) {
       ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(containerIn);
       if (emptyContainer != null && tank.fill(fs, true) == fs.amount) return emptyContainer;
     }
   }
   return null;
 }
 @SuppressWarnings({"rawtypes", "unchecked"})
 @Override
 public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
   FluidTank fakeTank = readTank(stack);
   FluidStack fluidStack = fakeTank.getFluid();
   if (fluidStack != null && fluidStack.amount > 0) {
     float percent = Math.max(100.0f / fakeTank.getCapacity() * fluidStack.amount, 1);
     list.add(String.format("%d mB (%.0f%%)", fluidStack.amount, percent));
   }
 }
 private void updateComparatorValuesPart2() {
   int vol = tank.getCapacity() / 6;
   if ((15 * tank.getFluidAmount()) / tank.getCapacity() != masterCompOld)
     worldObj.func_147453_f(xCoord, yCoord, zCoord, getBlockType());
   for (int i = 0; i < 4; i++) {
     int filled = tank.getFluidAmount() - i * vol;
     int now = Math.min(15, Math.max((15 * filled) / vol, 0));
     if (now != oldComps[i]) {
       int y = yCoord - offset[1] + i + 1;
       for (int x = -1; x < 2; x++)
         for (int z = -1; z < 2; z++)
           worldObj.func_147453_f(
               xCoord - offset[0] + x,
               y,
               zCoord - offset[2] + z,
               worldObj.getBlock(xCoord - offset[0] + x, y, zCoord - offset[2] + z));
     }
   }
   oldComps = null;
 }
  @Override
  public ArrayList getNetworkedData(ArrayList data) {
    super.getNetworkedData(data);

    data.add(getReactor() != null && getReactor().isFormed());

    if (getReactor() != null) {
      data.add(getReactor().getPlasmaTemp());
      data.add(getReactor().getCaseTemp());
      data.add(getReactor().getInjectionRate());
      data.add(getReactor().isBurning());
      data.add(fuelTank.getStored());
      data.add(deuteriumTank.getStored());
      data.add(tritiumTank.getStored());
      data.add(waterTank.getCapacity());
      data.add(waterTank.getFluidAmount());
      data.add(steamTank.getCapacity());
      data.add(steamTank.getFluidAmount());
    }

    return data;
  }
Example #10
0
  /* Fluid Management */
  @Override
  public boolean canFill(EnumFacing from, Fluid fluid) {
    // can only fill if no output in the inventory
    if (isStackInSlot(1)) {
      return false;
    }
    // can only fill if same fluid or empty and recipe present
    if (tank.getFluidAmount() > 0) {
      // if we have a fluid we also have a recipe
      return tank.getFluid().getFluid() == fluid && tank.getFluidAmount() < tank.getCapacity();
    }

    return findRecipe(fluid) != null;
  }
Example #11
0
  @Override
  public FluidTankInfo[] getTankInfo(ForgeDirection direction) {
    FluidTank compositeTank = new FluidTank(tank.getCapacity());

    int capacity = tank.getCapacity();

    if (tank.getFluid() != null) {
      compositeTank.setFluid(tank.getFluid().copy());
    } else {
      return new FluidTankInfo[] {compositeTank.getInfo()};
    }

    FluidStack liquid = tank.getFluid();
    if (liquid == null || liquid.amount == 0) {

    } else {
      compositeTank.getFluid().amount += liquid.amount;
    }

    capacity += tank.getCapacity();

    compositeTank.setCapacity(capacity);
    return new FluidTankInfo[] {compositeTank.getInfo()};
  }
Example #12
0
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (worldObj.isRemote) {
      return;
    }

    if (heat > 1500) {
      if (inv[0] != null
          && inv[0].itemID == BaconItems.rawBacon.itemID
          && lava.getCapacity() - 100 >= lava.getFluidAmount()) {
        progress++;
        if (progress > 100) {
          progress = 0;
          lava.fill(new FluidStack(BaconItems.liquidBacon, 100), true);
        }
      }
    }
    pushFluidOut();

    if (worldObj.isRemote) // || worldObj.getWorldTime() % 20 != 0)
    {
      return;
    }

    int HottestHeat = 20;
    for (int i = 0; i < 6; i++) {
      TileEntity tile = BaconWorld.getTileEntity(worldObj, xCoord, yCoord, zCoord, i);
      if (tile != null && tile instanceof Heater) {
        Heater heat = (Heater) tile;
        HottestHeat = Math.max(HottestHeat, heat.getHeat());
      }
    }

    if (HottestHeat > heat) {
      heat++;
    } else if (HottestHeat == heat) {
    } else {
      heat--;
    }
  }
  public int getCurrentNeeded() {
    int needed = fluidTank.getCapacity() - fluidTank.getFluidAmount();

    Coord4D top = Coord4D.get(this).offset(EnumFacing.UP);
    TileEntity topTile = top.getTileEntity(worldObj);

    if (topTile instanceof TileEntityFluidTank) {
      TileEntityFluidTank topTank = (TileEntityFluidTank) topTile;

      if (fluidTank.getFluid() != null && topTank.fluidTank.getFluid() != null) {
        if (fluidTank.getFluid().getFluid() != topTank.fluidTank.getFluid().getFluid()) {
          return needed;
        }
      }

      needed += topTank.getCurrentNeeded();
    }

    return needed;
  }
 @Override
 public Object[] invoke(int method, Object[] arguments) throws Exception {
   switch (method) {
     case 0:
       return new Object[] {electricityStored};
     case 1:
       return new Object[] {output};
     case 2:
       return new Object[] {BASE_MAX_ENERGY};
     case 3:
       return new Object[] {(BASE_MAX_ENERGY - electricityStored)};
     case 4:
       return new Object[] {lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0};
     case 5:
       return new Object[] {
         lavaTank.getCapacity() - (lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0)
       };
     default:
       throw new NoSuchMethodException();
   }
 }
 /**
  * Gets the scaled fuel level for the GUI.
  *
  * @param i - multiplier
  * @return
  */
 public int getScaledFuelLevel(int i) {
   return (lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0)
       * i
       / lavaTank.getCapacity();
 }
 public int getRedstoneLevel() {
   double fractionFull = (float) fluidTank.getFluidAmount() / (float) fluidTank.getCapacity();
   return MathHelper.floor_float((float) (fractionFull * 14.0F)) + (fractionFull > 0 ? 1 : 0);
 }
 @Override
 public int getCapacity(ItemStack container) {
   FluidTank tank = readTank(container);
   return tank != null ? tank.getCapacity() * container.stackSize : 0;
 }
  @Override
  public void onUpdate() {
    if (worldObj.isRemote) {
      if (updateDelay > 0) {
        updateDelay--;

        if (updateDelay == 0 && clientActive != isActive) {
          isActive = clientActive;
          MekanismUtils.updateBlock(worldObj, getPos());
        }
      }

      float targetScale =
          (float) (fluidTank.getFluid() != null ? fluidTank.getFluid().amount : 0)
              / fluidTank.getCapacity();

      if (Math.abs(prevScale - targetScale) > 0.01) {
        prevScale = (9 * prevScale + targetScale) / 10;
      }
    } else {
      if (updateDelay > 0) {
        updateDelay--;

        if (updateDelay == 0 && clientActive != isActive) {
          needsPacket = true;
        }
      }

      if (valve > 0) {
        valve--;

        if (valve == 0) {
          valveFluid = null;
          needsPacket = true;
        }
      }

      if (fluidTank.getFluidAmount() != prevAmount) {
        MekanismUtils.saveChunk(this);
        needsPacket = true;
      }

      prevAmount = fluidTank.getFluidAmount();

      if (inventory[0] != null) {
        manageInventory();
      }

      if (isActive) {
        activeEmit();
      }

      int newRedstoneLevel = getRedstoneLevel();

      if (newRedstoneLevel != currentRedstoneLevel) {
        markDirty();
        currentRedstoneLevel = newRedstoneLevel;
      }

      if (needsPacket) {
        Mekanism.packetHandler.sendToAllAround(
            new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())),
            Coord4D.get(this).getTargetPoint(50));
      }

      needsPacket = false;
    }
  }
  @Override
  public void onUpdate() {
    if (!worldObj.isRemote) {
      ChargeUtils.discharge(2, this);

      if (inventory[0] != null) {
        if (inventory[0].getItem() instanceof IFluidContainerItem
            && ((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) != null) {
          if (((IFluidContainerItem) inventory[0].getItem())
              .getFluid(inventory[0])
              .getFluid()
              .canBePlacedInWorld()) {
            fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0]), true);

            if (((IFluidContainerItem) inventory[0].getItem()).getFluid(inventory[0]) == null
                || fluidTank.getFluidAmount() == fluidTank.getCapacity()) {
              if (inventory[1] == null) {
                inventory[1] = inventory[0].copy();
                inventory[0] = null;

                markDirty();
              }
            }
          }
        } else if (FluidContainerRegistry.isFilledContainer(inventory[0])) {
          FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);

          if ((fluidTank.getFluid() == null && itemFluid.amount <= fluidTank.getCapacity())
              || fluidTank.getFluid().amount + itemFluid.amount <= fluidTank.getCapacity()) {
            if ((fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid))
                || !itemFluid.getFluid().canBePlacedInWorld()) {
              return;
            }

            ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);

            boolean filled = false;

            if (containerItem != null) {
              if (inventory[1] == null
                  || (inventory[1].isItemEqual(containerItem)
                      && inventory[1].stackSize + 1 <= containerItem.getMaxStackSize())) {
                inventory[0] = null;

                if (inventory[1] == null) {
                  inventory[1] = containerItem;
                } else {
                  inventory[1].stackSize++;
                }

                filled = true;
              }
            } else {
              inventory[0].stackSize--;

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

              filled = true;
            }

            if (filled) {
              fluidTank.fill(itemFluid, true);
              markDirty();
            }
          }
        }
      }

      if (getEnergy() >= usage.fluidicPlenisherUsage
          && worldObj.getWorldTime() % 10 == 0
          && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
          if (!finishedCalc) {
            doPlenish();
          } else {
            Coord4D below = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);

            if (canReplace(below, false, false)
                && getEnergy() >= usage.fluidicPlenisherUsage
                && fluidTank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
              if (fluidTank.getFluid().getFluid().canBePlacedInWorld()) {
                worldObj.setBlock(
                    below.xCoord,
                    below.yCoord,
                    below.zCoord,
                    MekanismUtils.getFlowingBlock(fluidTank.getFluid().getFluid()),
                    0,
                    3);

                setEnergy(getEnergy() - usage.fluidicPlenisherUsage);
                fluidTank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
              }
            }
          }
        }
      }
    }
  }
  @Override
  public void updateEntity() {

    super.updateEntity();

    oldCurX = curX;
    oldCurY = curY;
    oldCurZ = curZ;
    if (PneumaticCraftUtils.distBetween(getPosition(), targetX, targetY, targetZ) <= getSpeed()) {
      curX = targetX;
      curY = targetY;
      curZ = targetZ;
    } else {
      Vec3 vec =
          Vec3.createVectorHelper(targetX - curX, targetY - curY, targetZ - curZ).normalize();
      curX += vec.xCoord * getSpeed();
      curY += vec.yCoord * getSpeed();
      curZ += vec.zCoord * getSpeed();
    }

    if (!worldObj.isRemote) {
      getAIManager();
      if (worldObj.getTotalWorldTime() % 40 == 0) {
        dispenserUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE);
        speedUpgrades = getUpgrades(ItemMachineUpgrade.UPGRADE_SPEED_DAMAGE);

        for (int i = getDroneSlots(); i < 36; i++) {
          ItemStack stack = getFakePlayer().inventory.getStackInSlot(i);
          if (stack != null) {
            worldObj.spawnEntityInWorld(
                new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack));
            getFakePlayer().inventory.setInventorySlotContents(i, null);
          }
        }

        tank.setCapacity((dispenserUpgrades + 1) * 16000);
        if (tank.getFluidAmount() > tank.getCapacity()) {
          tank.getFluid().amount = tank.getCapacity();
        }
      }
      for (int i = 0; i < 4; i++) {
        getFakePlayer().theItemInWorldManager.updateBlockRemoving();
      }
      if (getPressure(ForgeDirection.UNKNOWN) >= getMinWorkingPressure()) {
        if (!aiManager.isIdling()) addAir(-10, ForgeDirection.UNKNOWN);
        aiManager.onUpdateTasks();
      }
    } else {
      if (drone == null || drone.isDead) {
        drone = new EntityProgrammableController(worldObj, this);
        drone.posX = curX;
        drone.posY = curY;
        drone.posZ = curZ;
        worldObj.spawnEntityInWorld(drone);
      }
      drone.setPosition(curX, curY, curZ);
      // drone.getMoveHelper().setMoveTo(curX, curY, curZ, 0);
      /*   drone.prevPosX = oldCurX;
      drone.prevPosY = oldCurY;
      drone.prevPosZ = oldCurZ;*/
      // drone.getMoveHelper().setMoveTo(curX, curY, curZ, getSpeed());
    }
  }
  private void termoOperation() {

    int x = coordinates[0];
    int y = coordinates[1];
    int z = coordinates[2];

    TileEntity tileEntity = worldObj.getTileEntity(x, y, z);

    if (tileEntity == null || !(tileEntity instanceof UpgCtileentityTermoFluidFurnace)) {
      if (searchingTick == 6) {
        coolDown = 5;
        searchingTick = 0;
        return;
      }

      switch (searchingTick) {
        case 0:
          coordinates[0] = this.xCoord + 1;
          coordinates[1] = this.yCoord;
          coordinates[2] = this.zCoord;
          break;
        case 1:
          coordinates[0] = this.xCoord - 1;
          coordinates[1] = this.yCoord;
          coordinates[2] = this.zCoord;
          break;
        case 2:
          coordinates[0] = this.xCoord;
          coordinates[1] = this.yCoord + 1;
          coordinates[2] = this.zCoord;
          break;
        case 3:
          coordinates[0] = this.xCoord;
          coordinates[1] = this.yCoord - 1;
          coordinates[2] = this.zCoord;
          break;
        case 4:
          coordinates[0] = this.xCoord;
          coordinates[1] = this.yCoord;
          coordinates[2] = this.zCoord + 1;
          break;
        case 5:
          coordinates[0] = this.xCoord;
          coordinates[1] = this.yCoord;
          coordinates[2] = this.zCoord - 1;
          break;
        default:
          coordinates[0] = this.xCoord + 1;
          coordinates[1] = this.yCoord;
          coordinates[2] = this.zCoord;
      }

      searchingTick++;
      searchingTick %= 7;

    } else {

      UpgCtileentityTermoFluidFurnace termoFluidFurnace =
          (UpgCtileentityTermoFluidFurnace) tileEntity;

      FluidTank inputTank = termoFluidFurnace.tank[0];

      int amount = inputTank.getCapacity() - inputTank.getFluidAmount();
      if (amount > 0) {

        if (amount > FluidContainerRegistry.BUCKET_VOLUME)
          amount = FluidContainerRegistry.BUCKET_VOLUME;

        FluidStack fluidStack = this.tank[1].drain(amount, true);
        if (fluidStack != null) termoFluidFurnace.fill(ForgeDirection.UNKNOWN, fluidStack, true);

        amount = this.tank[1].getCapacity() - this.tank[1].getFluidAmount();
        if (amount > 0) {

          if (amount > FluidContainerRegistry.BUCKET_VOLUME)
            amount = FluidContainerRegistry.BUCKET_VOLUME;

          fluidStack = termoFluidFurnace.drain(ForgeDirection.UNKNOWN, amount, true);
          if (fluidStack != null) this.tank[1].fill(fluidStack, true);
        }
      }
    }
  }
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (!worldObj.isRemote) {
      ChargeUtils.charge(1, this);

      if (inventory[0] != null) {
        FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);

        if (inventory[0].getItem() instanceof IFluidContainerItem) {
          lavaTank.fill(
              FluidContainerUtils.extractFluid(
                  lavaTank, inventory[0], FluidChecker.check(FluidRegistry.LAVA)),
              true);
        } else if (fluid != null) {
          if (fluid != null && fluid.getFluidID() == FluidRegistry.LAVA.getID()) {
            if (lavaTank.getFluid() == null
                || lavaTank.getFluid().amount + fluid.amount <= lavaTank.getCapacity()) {
              lavaTank.fill(fluid, true);

              if (inventory[0].getItem().getContainerItem(inventory[0]) != null) {
                inventory[0] = inventory[0].getItem().getContainerItem(inventory[0]);
              } else {
                inventory[0].stackSize--;
              }

              if (inventory[0].stackSize == 0) {
                inventory[0] = null;
              }
            }
          }
        } else {
          int fuel = getFuel(inventory[0]);

          if (fuel > 0) {
            int fuelNeeded =
                lavaTank.getCapacity()
                    - (lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0);

            if (fuel <= fuelNeeded) {
              lavaTank.fill(new FluidStack(FluidRegistry.LAVA, fuel), true);

              if (inventory[0].getItem().getContainerItem(inventory[0]) != null) {
                inventory[0] = inventory[0].getItem().getContainerItem(inventory[0]);
              } else {
                inventory[0].stackSize--;
              }

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

      double prev = getEnergy();

      transferHeatTo(getBoost());

      if (canOperate()) {
        setActive(true);

        lavaTank.drain(10, true);
        transferHeatTo(generators.heatGeneration);
      } else {
        setActive(false);
      }

      double[] loss = simulateHeat();
      applyTemperatureChange();

      lastTransferLoss = loss[0];
      lastEnvironmentLoss = loss[1];

      producingEnergy = getEnergy() - prev;
    }
  }