@Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (!formed) return 0;
   if (master() != null) {
     if (pos != 15 && pos != 19) return 0;
     return master().fill(from, resource, doFill);
   } else if (resource != null) {
     int fill = 0;
     if (resource.isFluidEqual(tank0.getFluid())) fill = tank0.fill(resource, doFill);
     else if (resource.isFluidEqual(tank1.getFluid())) fill = tank1.fill(resource, doFill);
     else if (tank0.getFluidAmount() <= 0 && tank1.getFluidAmount() <= 0)
       fill =
           (DieselHandler.findIncompleteRefineryRecipe(resource, null) != null
               ? tank0.fill(resource, doFill)
               : 0);
     else {
       if (tank0.getFluidAmount() > 0)
         fill =
             (DieselHandler.findIncompleteRefineryRecipe(resource, tank0.getFluid()) != null
                 ? tank1.fill(resource, doFill)
                 : 0);
       else if (tank1.getFluidAmount() > 0)
         fill =
             (DieselHandler.findIncompleteRefineryRecipe(resource, tank1.getFluid()) != null
                 ? tank0.fill(resource, doFill)
                 : 0);
     }
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     return fill;
   }
   return 0;
 }
Ejemplo n.º 2
0
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    FluidStack resourceCopy = resource.copy();
    int totalUsed = 0;

    FluidStack liquid = tank.getFluid();
    if (liquid != null && liquid.amount > 0 && !liquid.isFluidEqual(resourceCopy)) {
      return 0;
    }

    while (resourceCopy.amount > 0) {
      int used = tank.fill(resourceCopy, doFill);
      resourceCopy.amount -= used;
      if (used > 0) {
        markDirty();
      }

      totalUsed += used;
    }

    return totalUsed;
  }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource != null)
     for (FluidTank _tank : (FluidTank[]) getTanks())
       if (_tank.getFluidAmount() == 0 || resource.isFluidEqual(_tank.getFluid()))
         return _tank.fill(resource, doFill);
   return 0;
 }
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (from == ForgeDirection.UP && resource.getFluid().canBePlacedInWorld()) {
      return fluidTank.fill(resource, true);
    }

    return 0;
  }
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource.getFluidID() == FluidRegistry.LAVA.getID()
        && from != ForgeDirection.getOrientation(facing)) {
      return lavaTank.fill(resource, doFill);
    }

    return 0;
  }
Ejemplo n.º 6
0
 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;
 }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource == null) return 0;
   TileEntityBottlingMachine master = master();
   if (master != null && canFill(from, resource.getFluid()))
     return master.fill(from, resource, doFill);
   int fill = tank.fill(resource, doFill);
   if (fill > 0) {
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
   }
   return fill < 0 ? 0 : fill;
 }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (!canFill(from, resource != null ? resource.getFluid() : null)) return 0;
   if (master() != null) return master().fill(from, resource, doFill);
   updateComparatorValuesPart1();
   int f = tank.fill(resource, doFill);
   if (f > 0 && doFill) {
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     updateComparatorValuesPart2();
   }
   return f;
 }
Ejemplo n.º 9
0
  @Override
  public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
    // this is where all the action happens
    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    // if empty, find a new recipe
    if (this.tank.getFluidAmount() == 0) {
      CastingRecipe recipe = findRecipe(resource.getFluid());
      if (recipe == null) {
        // no recipe found -> can't fill
        return 0;
      }

      int capacity = recipe.fluid.amount;
      IFluidTank calcTank = new FluidTank(capacity);

      // no extra checks needed for the tank since it's empty and we have to set the capacity anyway
      if (doFill) {
        this.recipe = recipe;
        tank.setCapacity(capacity);
        calcTank = tank;
      }

      int filled = calcTank.fill(resource, doFill);
      if (filled > 0 && doFill) {
        renderOffset = filled;
        if (!worldObj.isRemote && worldObj instanceof WorldServer) {
          TinkerNetwork.sendToClients(
              (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
        }
      }
      return filled;
    }

    // non-empty tank. just try to fill
    int filled = tank.fill(resource, doFill);
    if (filled > 0 && doFill) {
      renderOffset += filled;
      if (!worldObj.isRemote && worldObj instanceof WorldServer) {
        TinkerNetwork.sendToClients(
            (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
      }
    }

    return filled;
  }
Ejemplo n.º 10
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--;
    }
  }
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (worldObj.isRemote) return 0;
    if (resource == null) // What!?
    return 0;
    if (resource.getFluid() == null) return 0;
    if (resource.getFluid().getID() != FluidRegistry.LAVA.getID()) {
      return 0;
    }

    if (tank != null && tank.getFluid() != null && tank.getFluidAmount() > 0) {
      if (resource.getFluid().getID() != tank.getFluid().getFluid().getID()) {
        return 0;
      }
    } else if (tank == null) {
      setTier(getTier());
    }

    return tank.fill(resource, doFill);
  }
Ejemplo n.º 12
0
  @Override
  public int fill(ItemStack container, FluidStack resource, boolean doFill) {
    if (resource == null) return 0;

    FluidTank tank = readTank(container);
    if (tank == null) return 0;

    final int count = container.stackSize;
    if (count == 0) return 0;

    final int amountPerTank = resource.amount / count;
    if (amountPerTank == 0) return 0;

    FluidStack resourcePerTank = resource.copy();
    resourcePerTank.amount = amountPerTank;

    int filledPerTank = tank.fill(resourcePerTank, doFill);
    if (doFill) saveTank(container, tank);
    return filledPerTank * count;
  }
Ejemplo n.º 13
0
  @Override
  public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
    if (resource != null && canFill(from, resource.getFluid())) {
      int filled = fluidTank.fill(resource, doFill);

      if (filled < resource.amount && !isActive) {
        filled += pushUp(PipeUtils.copy(resource, resource.amount - filled), doFill);
      }

      if (filled > 0 && from == EnumFacing.UP) {
        if (valve == 0) {
          needsPacket = true;
        }

        valve = 20;
        valveFluid = resource.getFluid();
      }

      return filled;
    }

    return 0;
  }
  @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;
    }
  }
Ejemplo n.º 15
0
  public boolean suck(boolean take) {
    List<Object3D> tempPumpList =
        Arrays.asList(recurringNodes.toArray(new Object3D[recurringNodes.size()]));
    Collections.shuffle(tempPumpList);

    for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
      Object3D wrapper = Object3D.get(this).getFromSide(orientation);

      if (MekanismUtils.isFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)) {
        if (fluidTank.getFluid() == null
            || MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)
                .isFluidEqual(fluidTank.getFluid())) {
          if (take) {
            setEnergy(getEnergy() - 100);
            recurringNodes.add(new Object3D(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord));
            fluidTank.fill(
                MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord),
                true);
            worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
          }

          return true;
        }
      }
    }

    for (Object3D wrapper : cleaningNodes) {
      if (MekanismUtils.isFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)) {
        if (fluidTank.getFluid() != null
            && MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)
                .isFluidEqual(fluidTank.getFluid())) {
          if (take) {
            setEnergy(getEnergy() - 100);
            fluidTank.fill(
                MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord),
                true);
            worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
          }

          return true;
        }
      }
    }

    for (Object3D wrapper : tempPumpList) {
      if (MekanismUtils.isFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)) {
        if (fluidTank.getFluid() == null
            || MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord)
                .isFluidEqual(fluidTank.getFluid())) {
          if (take) {
            setEnergy(electricityStored - 100);
            fluidTank.fill(
                MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord),
                true);
            worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
          }

          return true;
        }
      }

      for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
        Object3D side = wrapper.getFromSide(orientation);

        if (Object3D.get(this).distanceTo(side) <= 80) {
          if (MekanismUtils.isFluid(worldObj, side.xCoord, side.yCoord, side.zCoord)) {
            if (fluidTank.getFluid() == null
                || MekanismUtils.getFluid(worldObj, side.xCoord, side.yCoord, side.zCoord)
                    .isFluidEqual(fluidTank.getFluid())) {
              if (take) {
                setEnergy(electricityStored - 100);
                recurringNodes.add(side);
                fluidTank.fill(
                    MekanismUtils.getFluid(worldObj, side.xCoord, side.yCoord, side.zCoord), true);
                worldObj.setBlockToAir(side.xCoord, side.yCoord, side.zCoord);
              }

              return true;
            }
          }
        }
      }

      cleaningNodes.add(wrapper);
      recurringNodes.remove(wrapper);
    }

    return 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 int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   return tank.fill(resource, doFill);
 }
  @Override
  public void updateEntity() {
    if (!formed || pos != 17) return;

    if (!worldObj.isRemote) {
      boolean update = false;
      int prevAmount = tank2.getFluidAmount();
      boolean enabled;
      if (computerControlled) enabled = computerOn;
      else
        enabled =
            !worldObj.isBlockIndirectlyGettingPowered(
                xCoord + (facing == 4 ? -1 : facing == 5 ? 1 : facing == 2 ? -2 : 2),
                yCoord + 1,
                zCoord + (facing == 2 ? -1 : facing == 3 ? 1 : facing == 4 ? 2 : -2));
      if (enabled) {
        RefineryRecipe recipe = getRecipe(true);
        if (recipe != null) {
          int consumed = Config.getInt("refinery_consumption");
          if (energyStorage.extractEnergy(consumed, true) == consumed
              && tank2.fill(recipe.output.copy(), false) == recipe.output.amount) {
            int drain0 =
                tank0.getFluid().isFluidEqual(recipe.input0)
                    ? recipe.input0.amount
                    : recipe.input1.amount;
            int drain1 =
                tank0.getFluid().isFluidEqual(recipe.input0)
                    ? recipe.input1.amount
                    : recipe.input0.amount;
            if (tank0.getFluidAmount() >= drain0 && tank1.getFluidAmount() >= drain1) {
              energyStorage.extractEnergy(consumed, false);
              tank0.drain(drain0, true);
              tank1.drain(drain1, true);
              tank2.fill(recipe.output.copy(), true);
              update = true;
            }
          }
        }
      }
      if (tank2.getFluidAmount() > 0) {
        ItemStack filledContainer = Utils.fillFluidContainer(tank2, inventory[4], inventory[5]);
        if (filledContainer != null) {
          if (inventory[5] != null
              && OreDictionary.itemMatches(inventory[5], filledContainer, true))
            inventory[5].stackSize += filledContainer.stackSize;
          else if (inventory[5] == null) inventory[5] = filledContainer.copy();
          this.decrStackSize(4, filledContainer.stackSize);
          update = true;
        }
        if (tank2.getFluidAmount() > 0) {
          ForgeDirection f = ForgeDirection.getOrientation(facing);
          int out = Math.min(144, tank2.getFluidAmount());
          TileEntity te =
              Utils.getExistingTileEntity(
                  worldObj, xCoord + f.offsetX * 2, yCoord, zCoord + f.offsetZ * 2);
          if (te instanceof IFluidHandler
              && ((IFluidHandler) te).canFill(f.getOpposite(), tank2.getFluid().getFluid())) {
            int accepted =
                ((IFluidHandler) te)
                    .fill(f.getOpposite(), new FluidStack(tank2.getFluid().getFluid(), out), false);
            FluidStack drained = this.tank2.drain(accepted, true);
            ((IFluidHandler) te).fill(f.getOpposite(), drained, true);
          }
        }
      }
      if (tank2.getFluidAmount() != prevAmount) update = true;

      ItemStack emptyContainer = Utils.drainFluidContainer(tank0, inventory[0]);
      if (emptyContainer != null) {
        if (inventory[1] != null && OreDictionary.itemMatches(inventory[1], emptyContainer, true))
          inventory[1].stackSize += emptyContainer.stackSize;
        else if (inventory[1] == null) inventory[1] = emptyContainer.copy();
        this.decrStackSize(0, emptyContainer.stackSize);
        update = true;
      }
      emptyContainer = Utils.drainFluidContainer(tank1, inventory[2]);
      if (emptyContainer != null) {
        if (inventory[3] != null && OreDictionary.itemMatches(inventory[3], emptyContainer, true))
          inventory[3].stackSize += emptyContainer.stackSize;
        else if (inventory[3] == null) inventory[3] = emptyContainer.copy();
        this.decrStackSize(2, emptyContainer.stackSize);
        update = true;
      }

      if (update) {
        this.markDirty();
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      }
    }
  }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.getFluid().getName().equalsIgnoreCase("steam"))
     return _steamTank.fill(resource, doFill);
   return 0;
 }