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

    boolean powered = getWorldObj().getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0;
    if (!powered
        && _steamTank.getFluid() != null
        && _steamTank.getFluid().getFluid() != null
        && _steamTank.getFluid().getFluid().getName() != null) {
      String fluidName = _steamTank.getFluid().getFluid().getName();
      PowerSteam.SteamType steamType = powerSteam.getSteamType(fluidName);
      if (steamType != null && _steamTank.getFluidAmount() > 0) {
        lastSubtype = powerSteam.getSteamSubtype(steamType);
        int amount = Math.min(_steamTank.getFluidAmount(), powerSteam.getThrottleConsumer());
        float energy = amount * steamType.energyPerInput;
        energy = (int) storeEnergy(energy, false);
        int toDrain;
        try {
          toDrain =
              (int) (amount - (energy / powerSteam.getInternalEnergyPerInput(this.blockMetadata)));
        } catch (ArithmeticException e) {
          toDrain = 0;
        }
        _steamTank.drain(toDrain, true);
        _mBLastTick = toDrain;
      } else {
        _mBLastTick = 0;
      }
    } else {
      _mBLastTick = 0;
    }
  }
 @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;
 }
 @Override
 public void updateEntity() {
   if (pos == 4
       && !worldObj.isRemote
       && worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
     for (int i = 0; i < 6; i++)
       if (i != 1 && tank.getFluidAmount() > 0) {
         ForgeDirection f = ForgeDirection.getOrientation(i);
         int out = Math.min(144, tank.getFluidAmount());
         TileEntity te =
             this.worldObj.getTileEntity(
                 xCoord + (i == 4 ? -1 : i == 5 ? 1 : 0),
                 yCoord + (i == 0 ? -1 : 0),
                 zCoord + (i == 2 ? -1 : i == 3 ? 1 : 0));
         if (te != null
             && te instanceof IFluidHandler
             && ((IFluidHandler) te).canFill(f.getOpposite(), tank.getFluid().getFluid())) {
           updateComparatorValuesPart1();
           int accepted =
               ((IFluidHandler) te)
                   .fill(f.getOpposite(), new FluidStack(tank.getFluid().getFluid(), out), false);
           FluidStack drained = this.tank.drain(accepted, true);
           ((IFluidHandler) te).fill(f.getOpposite(), drained, true);
           updateComparatorValuesPart2();
         }
       }
 }
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack stack) {
   if (!formed) return false;
   if (master() != null) return master().isItemValidForSlot(slot, stack);
   if (slot == 1 || slot == 3 || slot == 5) return false;
   if (slot == 4)
     return (tank2.getFluidAmount() <= 0
         ? FluidContainerRegistry.isEmptyContainer(stack)
         : FluidContainerRegistry.fillFluidContainer(
                 tank2.getFluid(), Utils.copyStackWithAmount(stack, 1))
             != null);
   FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(stack);
   if (fs == null) return false;
   RefineryRecipe partialRecipe = DieselHandler.findIncompleteRefineryRecipe(fs, null);
   if (partialRecipe == null) return false;
   if (slot == 0)
     return (tank0.getFluidAmount() <= 0 || fs.isFluidEqual(tank0.getFluid()))
         && (tank1.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank1.getFluid()) != null);
   if (slot == 2)
     return (tank1.getFluidAmount() <= 0 || fs.isFluidEqual(tank1.getFluid()))
         && (tank0.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank0.getFluid()) != null);
   return false;
 }
 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();
 }
Esempio n. 6
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;
  }
 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;
 }
  public ItemStack getFilledItem(ItemStack empty, boolean drainTank) {
    if (empty == null || tank.getFluid() == null) return null;
    BottlingMachineRecipe recipe = BottlingMachineRecipe.findRecipe(empty, tank.getFluid());
    if (recipe != null && recipe.output != null) {
      if (drainTank) tank.drain(recipe.fluidInput.amount, true);
      return recipe.output;
    }

    ItemStack filled =
        FluidContainerRegistry.fillFluidContainer(
            new FluidStack(tank.getFluid(), Integer.MAX_VALUE), empty);
    FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filled);
    if (filled != null && fs.amount <= tank.getFluidAmount()) {
      if (drainTank) tank.drain(fs.amount, true);
      return filled;
    }

    if (empty.getItem() instanceof IFluidContainerItem) {
      int accepted = ((IFluidContainerItem) empty.getItem()).fill(empty, tank.getFluid(), false);
      if (accepted > 0) {
        filled = empty.copy();
        ((IFluidContainerItem) filled.getItem())
            .fill(filled, new FluidStack(tank.getFluid(), accepted), true);
        if (drainTank) tank.drain(accepted, true);
        return filled;
      }
    }
    return null;
  }
Esempio n. 9
0
  public void pushFluidOut() {
    int tanks = 0;
    boolean[] sides = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
    for (int i = 0; i < sides.length; i++) {
      ForgeDirection side = ForgeDirection.VALID_DIRECTIONS[i];
      TileEntity tile =
          worldObj.getTileEntity(
              xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
      if (tile != null && tile instanceof IFluidHandler) {
        tanks++;
        sides[i] = true;
      }
    }

    int amountPerSide = lava.getFluidAmount();
    for (int i = 0; i < sides.length; i++) {
      if (sides[i]) {
        ForgeDirection side = ForgeDirection.getOrientation(i);
        TileEntity tile =
            worldObj.getTileEntity(
                xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
        if (tile != null
            && tile instanceof IFluidHandler
            && !(tile instanceof Heater)
            && !(tile instanceof Melter)) {
          IFluidHandler fluid = (IFluidHandler) tile;
          if (fluid.fill(side.getOpposite(), lava.drain(amountPerSide, false), false)
              == amountPerSide) {
            amountPerSide -= fluid.fill(side.getOpposite(), lava.drain(amountPerSide, true), true);
          }
        }
      }
    }
  }
Esempio n. 10
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();
      }
    }
  }
Esempio n. 11
0
  public void interact(EntityPlayer player) {
    // can't interact if liquid inside
    if (tank.getFluidAmount() > 0) {
      return;
    }

    // completely empty -> insert current item into input
    if (!isStackInSlot(0) && !isStackInSlot(1)) {
      ItemStack stack =
          player.inventory.decrStackSize(player.inventory.currentItem, stackSizeLimit);
      setInventorySlotContents(0, stack);
    }
    // take item out
    else {
      // take out of stack 1 if something is in there, 0 otherwise
      int slot = isStackInSlot(1) ? 1 : 0;

      // Additional Info: Only 1 item can only be put into the casting block usually, however
      // recipes
      // can have Itemstacks with stacksize > 1 as output
      // we therefore spill the whole contents on extraction
      ItemStack stack = getStackInSlot(slot);
      if (slot == 1) {
        FMLCommonHandler.instance().firePlayerSmeltedEvent(player, stack);
      }
      PlayerHelper.spawnItemAtPlayer(player, stack);
      setInventorySlotContents(slot, null);
    }
  }
Esempio n. 12
0
 @Override
 public void updateEntity() {
   super.updateEntity();
   if (!worldObj.isRemote) {
     if (tank.getFluidAmount() >= 0 && !(tank.getFluidAmount() == prevAmount)) {
       prevAmount = tank.getFluidAmount();
       markDirty();
     }
     if (initPer >= 0 && tank.getFluid() != null) {
       initPer--;
       if (initPer <= 0) {
         markDirty();
       }
     }
   }
 }
  public static ItemStack fillFluidContainer(FluidTank tank, ItemStack containerIn) {
    if (tank.getFluidAmount() > 0)
      if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
        ItemStack filledContainer =
            FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
        if (filledContainer != null) {
          FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
          if (fs.amount <= tank.getFluidAmount()) {
            tank.drain(fs.amount, true);

            return filledContainer;
          }
        }
      }
    return null;
  }
Esempio n. 14
0
  // called only clientside to sync with the server
  @SideOnly(Side.CLIENT)
  public void updateFluidTo(FluidStack fluid) {
    int oldAmount = tank.getFluidAmount();
    tank.setFluid(fluid);

    if (fluid == null) {
      tank.setCapacity(0);
      recipe = null;
    } else if (recipe == null) {
      recipe = findRecipe(fluid.getFluid());
      if (recipe != null) {
        tank.setCapacity(recipe.fluid.amount);
      }
    }

    renderOffset += tank.getFluidAmount() - oldAmount;
  }
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (_steamTank.getFluidAmount() > 0) {
      int amount = Math.min(_steamTank.getFluidAmount(), PowerConverterCore.throttleSteamConsumer);
      float energy = amount * PowerConverterCore.powerSystemSteam.getInternalEnergyPerInput();
      energy = (int) storeEnergy(energy, false);
      int toDrain =
          (int)
              (amount - (energy / PowerConverterCore.powerSystemSteam.getInternalEnergyPerInput()));
      _steamTank.drain(toDrain, true);
      _mBLastTick = toDrain;
    } else {
      _mBLastTick = 0;
    }
  }
 @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 FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   FluidStack drained = tank.drain(maxDrain, doDrain);
   if (tank.getFluidAmount() == 0 && doDrain) {
     tank.setFluid(null);
   }
   return drained;
 }
 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;
 }
Esempio n. 20
0
 public static ItemStack fillFluidContainer(
     FluidTank tank, ItemStack containerIn, ItemStack containerOut) {
   if (tank.getFluidAmount() > 0 && containerIn != null) {
     if (FluidContainerRegistry.isEmptyContainer(containerIn)) {
       ItemStack filledContainer =
           FluidContainerRegistry.fillFluidContainer(tank.getFluid(), containerIn);
       if (filledContainer != null) {
         FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
         if (fs.amount <= tank.getFluidAmount()
             && (containerOut == null
                 || OreDictionary.itemMatches(containerOut, filledContainer, true))) {
           tank.drain(fs.amount, true);
           return filledContainer;
         }
       }
     } else if (containerIn.getItem() instanceof IFluidContainerItem) {
       IFluidContainerItem iContainer = (IFluidContainerItem) containerIn.getItem();
       int available = tank.getFluidAmount();
       int space =
           iContainer.getCapacity(containerIn)
               - (iContainer.getFluid(containerIn) == null
                   ? 0
                   : iContainer.getFluid(containerIn).amount);
       if (available >= space
           && iContainer.fill(containerIn, tank.getFluid(), false) == space) // Fill in one go
       {
         ItemStack filledContainer = copyStackWithAmount(containerIn, 1);
         int filled = iContainer.fill(filledContainer, tank.getFluid(), true);
         if (containerOut == null
             || (OreDictionary.itemMatches(containerOut, filledContainer, true)
                 && ItemStack.areItemStackTagsEqual(filledContainer, containerOut))) {
           tank.drain(filled, true);
           return filledContainer;
         }
       } else {
         int filled = iContainer.fill(containerIn, tank.getFluid(), true);
         tank.drain(filled, true);
       }
     }
   }
   return null;
 }
 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;
 }
Esempio n. 22
0
  private static void saveTank(ItemStack container, FluidTank tank) {
    if (tank.getFluidAmount() > 0) {
      NBTTagCompound itemTag = ItemUtils.getItemTag(container);

      NBTTagCompound tankTag = new NBTTagCompound();
      tank.writeToNBT(tankTag);
      itemTag.setTag(TANK_TAG, tankTag);
    } else {
      container.stackTagCompound = null;
    }
  }
Esempio n. 23
0
  @Override
  public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
    if (tank.getFluidAmount() == 0) {
      return null;
    }
    if (tank.getFluid().getFluid() != resource.getFluid()) {
      return null;
    }

    // same fluid, k
    return this.drain(from, resource.amount, doDrain);
  }
  @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;
  }
Esempio n. 25
0
 public static ItemStack fillFluidContainer(FluidTank tank, ItemStack emptyFluidContainer) {
   if (tank.getFluidAmount() >= FluidContainerRegistry.BUCKET_VOLUME) {
     FluidStack fluidStack = tank.drain(FluidContainerRegistry.BUCKET_VOLUME, false);
     ItemStack filledFluidContainer =
         FluidContainerRegistry.fillFluidContainer(fluidStack, emptyFluidContainer);
     if (filledFluidContainer != null) {
       tank.drain(FluidContainerRegistry.BUCKET_VOLUME, true);
     }
     return filledFluidContainer;
   } else {
     return null;
   }
 }
Esempio n. 26
0
  private void activeEmit() {
    if (fluidTank.getFluid() != null) {
      TileEntity tileEntity = Coord4D.get(this).offset(EnumFacing.DOWN).getTileEntity(worldObj);

      if (tileEntity != null
          && CapabilityUtils.hasCapability(
              tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP)) {
        IFluidHandler handler =
            CapabilityUtils.getCapability(
                tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP);
        FluidStack toDrain =
            new FluidStack(fluidTank.getFluid(), Math.min(tier.output, fluidTank.getFluidAmount()));
        fluidTank.drain(handler.fill(toDrain, true), true);
      }
    }
  }
 @Override
 public void updateEntity() {
   if (!worldObj.isRemote) {
     if (tank.getFluidAmount() > 2400) {
       if (progress > 0) {
         tank.drainInternal(15, true);
         progress--;
       } else if (progress == 0) {
         ItemStack s = MachineCraftingHandler.getFurnaceRecipe(stack[0]);
         if (s != null) {
           if (stack[1] != null) {
             if (TomsModUtils.areItemStacksEqual(stack[1], s, true, true, false)
                 && stack[1].stackSize + s.stackSize <= s.getMaxStackSize()
                 && stack[0].stackSize >= 1) {
               stack[1].stackSize += s.stackSize;
               progress = -1;
               decrStackSize(0, 1);
             }
           } else {
             progress = -1;
             stack[1] = s;
             decrStackSize(0, 1);
           }
         } else {
           progress = -1;
         }
       } else {
         ItemStack s = MachineCraftingHandler.getFurnaceRecipe(stack[0]);
         if (s != null) {
           if (stack[1] != null) {
             if (TomsModUtils.areItemStacksEqual(stack[1], s, true, true, false)
                 && stack[1].stackSize + s.stackSize <= s.getMaxStackSize()
                 && stack[0].stackSize >= 1) {
               progress = MAX_PROCESS_TIME;
             }
           } else {
             progress = MAX_PROCESS_TIME;
           }
         }
         TomsModUtils.setBlockStateWithCondition(worldObj, pos, SteamFurnace.ACTIVE, progress > 0);
       }
     } else {
       TomsModUtils.setBlockStateWithCondition(worldObj, pos, SteamFurnace.ACTIVE, false);
     }
   }
 }
	public int drain(FluidTank _tank, int maxDrain, boolean doDrain)
	{
		if (_tank.getFluidAmount() > 0)
		{
			FluidStack drained = _tank.drain(maxDrain, doDrain);
			if (drained != null)
			{
				if (doDrain)
				{
					internalChange = true;
					onInventoryChanged();
					internalChange = false;
				}
				return drained.amount;
			}
		}
		return 0;
	}
Esempio n. 29
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--;
    }
  }
Esempio n. 30
0
  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;
  }