@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;
  }
Exemplo n.º 2
0
 @Override
 public void createInitNBT(NBTTagCompound nbt) {
   nbt.setByte("rotation", rotation);
   nbt.setBoolean("sealed", sealed);
   nbt.setInteger("SealTime", sealtime);
   nbt.setInteger("fluid", fluid != null ? fluid.getFluidID() : -1);
   nbt.setInteger("fluidAmount", fluid != null ? fluid.amount : 0);
   nbt.setInteger("barrelType", barrelType);
 }
  @Override
  public boolean canDrain(ForgeDirection from, Fluid fluid) {
    // Check that the drain is coming from the from the front of the block
    // and that the fluid to be drained is in the smeltery.
    if (!hasValidMaster()) return false;

    boolean containsFluid = fluid == null;
    if (fluid != null) {
      SmelteryLogic smeltery =
          (SmelteryLogic)
              worldObj.getTileEntity(
                  getMasterPosition().x, getMasterPosition().y, getMasterPosition().z);
      for (FluidStack fstack : smeltery.moltenMetal) {
        if (fstack.getFluidID() == fluid.getID()) {
          containsFluid = true;
          break;
        }
      }
    }
    // return from == getForgeDirection().getOpposite() && containsFluid;
    return containsFluid;
  }
  @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;
    }
  }