@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;
 }
Пример #2
0
  public boolean addLiquid(FluidStack inFS) {
    if (inFS != null) {
      // We dont want very hot liquids stored here so if they are much hotter than boiling water, we
      // prevent it.
      if (inFS.getFluid() != null && inFS.getFluid().getTemperature(inFS) > 385) return false;

      if (fluid == null) {
        fluid = inFS.copy();
        if (fluid.amount > this.getMaxLiquid()) {
          fluid.amount = getMaxLiquid();
          inFS.amount = inFS.amount - this.getMaxLiquid();

        } else inFS.amount = 0;
      } else {
        // check if the barrel is full or if the fluid being added does not match the barrel liquid
        if (fluid.amount == getMaxLiquid() || !fluid.isFluidEqual(inFS)) return false;

        int a = fluid.amount + inFS.amount - getMaxLiquid();
        fluid.amount = Math.min(fluid.amount + inFS.amount, getMaxLiquid());
        if (a > 0) inFS.amount = a;
        else inFS.amount = 0;
      }
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      return true;
    }

    return false;
  }
Пример #3
0
  private static int findFuelValue(ItemStack stack) {
    try {
      Item item = stack.getItem();

      if (item instanceof ItemBlock) {
        Block block = InvTools.getBlockFromStack(stack);

        String name = block.getUnlocalizedName();
        if (name != null && name.contains("blockScaffold")) return 0;
      }

      //            if (itemID == Item.coal.itemID && stack.getItemDamage() == 0)
      //                return 1600;

      if (item == Items.blaze_rod) return 1000;

      FluidStack liquid = FluidItemHelper.getFluidStackInContainer(stack);
      if (liquid != null && Fluids.LAVA.get() == liquid.getFluid()) return liquid.amount;

      String name = stack.getItem().getUnlocalizedName();
      if (name != null && name.contains("itemScrap")) return 0;

      return TileEntityFurnace.getItemBurnTime(stack);
    } catch (Exception ex) {
      Game.logThrowable(
          "Error in Fuel Handler! Is some mod creating items that are not compliant with standards?",
          ex);
    }
    return 0;
  }
Пример #4
0
  public FluidStack drain_(ItemStack container, int maxDrain, boolean doDrain) {
    if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
      return null;
    }

    FluidStack stack =
        FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
    if (stack == null) {
      return null;
    }

    int currentAmount = stack.amount;
    stack.amount = Math.min(stack.amount, maxDrain);
    if (doDrain) {
      if (currentAmount == stack.amount) {
        container.stackTagCompound.removeTag("Fluid");

        if (container.stackTagCompound.hasNoTags()) {
          container.stackTagCompound = null;
        }
        return stack;
      }

      NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
      fluidTag.setInteger("Amount", currentAmount - stack.amount);
      container.stackTagCompound.setTag("Fluid", fluidTag);
    }
    return stack;
  }
Пример #5
0
  @Override
  public void onNetworksCreated(List<FluidNetwork> networks) {
    if (fluidStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
      int[] caps = new int[networks.size()];
      int cap = 0;

      for (FluidNetwork network : networks) {
        caps[networks.indexOf(network)] = network.getCapacity();
        cap += network.getCapacity();
      }

      fluidStored.amount = Math.min(cap, fluidStored.amount);

      int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), fluidStored.amount);

      for (FluidNetwork network : networks) {
        int index = networks.indexOf(network);

        if (values[index] > 0) {
          network.fluidStored = new FluidStack(fluidStored.getFluid(), values[index]);
          network.fluidScale = network.getScale();
          network.refFluid = fluidStored.getFluid();
        }
      }
    }

    fluidScale = 0;
    fluidStored = null;
    refFluid = null;
  }
Пример #6
0
  @Override
  protected void mouseClicked(int i, int j, int k) {
    super.mouseClicked(i, j, k);

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;

    int position = getSlotAtLocation(i - cornerX, j - cornerY);

    if (position >= 0 && position < 2) {
      if (k == 0) {
        if (!isShiftKeyDown()) {
          FluidStack liquid =
              FluidContainerRegistry.getFluidForFilledItem(mc.thePlayer.inventory.getItemStack());

          if (liquid == null) {
            return;
          }

          container.setFilter(position, liquid.getFluid());
        } else {
          container.setFilter(position, null);
        }
      } else {
        TileRefinery ref = (TileRefinery) this.tile;

        if (position == 0) container.setFilter(position, ref.tank1.getFluidType());
        else if (position == 1) container.setFilter(position, ref.tank2.getFluidType());
      }
    }
  }
  /** @return a string representation of the object. */
  @Override
  public String toString() {
    if (wrappedStack instanceof ItemStack) {
      ItemStack itemStack = (ItemStack) wrappedStack;
      String unlocalizedName = "";
      try {
        unlocalizedName = itemStack.getUnlocalizedName();
      } catch (ArrayIndexOutOfBoundsException e) {
        unlocalizedName = "no-name";
      }

      if (itemStack.hasTagCompound()) {
        return String.format(
            "%sxitemStack[%s@%s:%s]",
            stackSize, unlocalizedName, itemStack.getItemDamage(), itemStack.getTagCompound());
      } else {
        return String.format(
            "%sxitemStack[%s@%s]", stackSize, unlocalizedName, itemStack.getItemDamage());
      }
    } else if (wrappedStack instanceof OreStack) {
      OreStack oreStack = (OreStack) wrappedStack;
      return String.format("%sxoreStack.%s", stackSize, oreStack.oreName);
    } else if (wrappedStack instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) wrappedStack;
      return String.format("%sxfluidStack.%s", stackSize, fluidStack.getFluid().getName());
    } else {
      return "null-wrappedstack";
    }
  }
Пример #8
0
  public static ItemStack toItemStack(FluidStack fluidStack) {
    if (fluidStack == null
        || fluidStack.getFluid() == null
        || fluidStack.getFluid().getBlock() == null) return null;

    return new ItemStack(fluidStack.getFluid().getBlock());
  }
Пример #9
0
  public void ProcessItems() {
    if (this.getInvCount() == 0) {
      if (getFluidStack() != null) {
        recipe =
            BarrelManager.getInstance()
                .findMatchingRecipe(getInputStack(), getFluidStack(), this.sealed);
        if (recipe != null && !worldObj.isRemote) {
          int time = 0;
          if (sealtime > 0) time = (int) TFC_Time.getTotalHours() - sealtime;
          else if (unsealtime > 0) time = (int) TFC_Time.getTotalHours() - unsealtime;

          // Make sure that the recipe meets the time requirements
          if (recipe.isSealedRecipe() && time < recipe.sealTime) return;

          ItemStack origIS = getInputStack().copy();
          FluidStack origFS = getFluidStack().copy();
          if (fluid.isFluidEqual(recipe.getResultFluid(origIS, origFS, time))) {
            fluid.amount -= recipe.getResultFluid(origIS, origFS, time).amount;
          } else {
            this.fluid = recipe.getResultFluid(origIS, origFS, time);
            this.fluid.amount = origFS.amount;
          }
          this.setInventorySlotContents(0, recipe.getResult(origIS, origFS, time));
        }
      }
    }
  }
  private WrappedStack(Object object, int stackSize) {
    if (object instanceof Item) {
      object = new ItemStack((Item) object);
    } else if (object instanceof Block) {
      object = new ItemStack((Block) object);
    } else if (object instanceof Fluid) {
      object = new FluidStack((Fluid) object, 1000);
    }

    if (object instanceof ItemStack) {
      ItemStack itemStack = ((ItemStack) object).copy();
      objectType = "itemstack";
      this.stackSize = stackSize;
      itemStack.stackSize = 1;
      wrappedStack = itemStack;
    } else if (object instanceof OreStack) {
      OreStack oreStack = (OreStack) object;
      objectType = "orestack";
      this.stackSize = stackSize;
      oreStack.stackSize = 1;
      wrappedStack = oreStack;
    } else if (object instanceof ArrayList) {
      ArrayList<?> objectList = (ArrayList<?>) object;

      OreStack possibleOreStack = OreStack.getOreStackFromList(objectList);

      if (possibleOreStack != null) {
        objectType = "orestack";
        this.stackSize = stackSize;
        possibleOreStack.stackSize = 1;
        wrappedStack = possibleOreStack;
      } else {
        objectType = null;
        this.stackSize = -1;
        wrappedStack = null;
      }
    } else if (object instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) object;
      objectType = "fluidstack";
      this.stackSize = stackSize;
      fluidStack.amount = 1;
      wrappedStack = fluidStack;
    } else if (object instanceof WrappedStack) {
      WrappedStack wrappedStackObject = (WrappedStack) object;

      if (wrappedStackObject.getWrappedObject() != null) {
        this.objectType = wrappedStackObject.objectType;
        this.stackSize = stackSize;
        this.wrappedStack = wrappedStackObject.wrappedStack;
      } else {
        objectType = null;
        this.stackSize = -1;
        wrappedStack = null;
      }
    } else {
      objectType = null;
      this.stackSize = -1;
      wrappedStack = null;
    }
  }
 @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;
 }
Пример #12
0
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.isFluidEqual(this.src1)) {
     int ret = Math.min(this.buf - this.src1.amount, resource.amount);
     if (doFill) this.src1.amount += ret;
     return ret;
   } else if (resource.isFluidEqual(this.src2)) {
     int ret = Math.min(this.buf - this.src2.amount, resource.amount);
     if (doFill) this.src2.amount += ret;
     return ret;
   } else if (this.src1 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src1 = resource.copy();
       this.src1.amount = ret;
     }
     return ret;
   } else if (this.src2 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src2 = resource.copy();
       this.src2.amount = ret;
     }
     return ret;
   }
   return 0;
 }
Пример #13
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;
  }
Пример #14
0
  public int fill(
      ForgeDirection from, FluidStack resource, boolean doFill, boolean doPush, int pushToken) {
    if (resource == null || resource.amount <= 0) {
      return 0;
    }

    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    if (network == null) {
      return 0;
    }
    if (network.canAcceptLiquid(resource)) {
      network.setFluidType(resource);
    } else {
      return 0;
    }
    resource = resource.copy();
    resource.amount = Math.min(MAX_IO_PER_TICK, resource.amount);

    if (doPush) {
      return pushLiquid(from, resource, doFill, pushToken);
    } else {
      return tank.fill(resource, doFill);
    }
  }
Пример #15
0
  public static boolean canInteractWithFluid(
      DockingStation station, IFluidFilter filter, Class<?> actionClass) {
    boolean actionFound = false;

    for (StatementSlot s : station.getActiveActions()) {
      if (actionClass.isAssignableFrom(s.statement.getClass())) {
        StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);

        if (!param.hasFilter()) {
          actionFound = true;
          break;
        } else {
          for (ItemStack stack : param.getStacks()) {
            if (stack != null) {
              FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(stack);

              if (fluid != null && filter.matches(fluid.getFluid())) {
                actionFound = true;
                break;
              }
            }
          }
        }
      }
    }

    return actionFound;
  }
  /** @return a string representation of the object. */
  @Override
  public String toString() {

    StringBuilder stringBuilder = new StringBuilder();

    if (wrappedStack instanceof ItemStack) {
      ItemStack itemStack = (ItemStack) wrappedStack;
      try {
        stringBuilder.append(
            String.format(
                "%sxitemStack[%s:%s:%s:%s]",
                stackSize,
                itemStack.itemID,
                itemStack.getItemDamage(),
                itemStack.getUnlocalizedName(),
                itemStack.getItem().getClass().getCanonicalName()));
      } catch (ArrayIndexOutOfBoundsException e) {
        // NOOP
      }
    } else if (wrappedStack instanceof OreStack) {
      OreStack oreStack = (OreStack) wrappedStack;
      stringBuilder.append(String.format("%sxoreStack.%s", stackSize, oreStack.oreName));
    } else if (wrappedStack instanceof EnergyStack) {
      EnergyStack energyStack = (EnergyStack) wrappedStack;
      stringBuilder.append(String.format("%sxenergyStack.%s", stackSize, energyStack.energyName));
    } else if (wrappedStack instanceof FluidStack) {
      FluidStack fluidStack = (FluidStack) wrappedStack;
      stringBuilder.append(
          String.format("%sxfluidStack.%s", stackSize, fluidStack.getFluid().getName()));
    } else {
      stringBuilder.append("null");
    }

    return stringBuilder.toString();
  }
Пример #17
0
  /* ITANKCONTAINER */
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    resource = resource.copy();
    int totalUsed = 0;
    TileTank tankToFill = getBottomTank();

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

    while (tankToFill != null && resource.amount > 0) {
      int used = tankToFill.tank.fill(resource, doFill);
      resource.amount -= used;
      if (used > 0) {
        tankToFill.hasUpdate = true;
      }

      totalUsed += used;
      tankToFill = getTankAbove(tankToFill);
    }
    return totalUsed;
  }
 public ItemStack tryPlaceContainedLiquid(
     World world, ItemStack bucket, int x, int y, int z, int side) {
   if (world.isRemote) return bucket;
   CarbonContainer item = (CarbonContainer) bucket.getItem();
   int id = bucket.getItemDamage();
   if (id != 0) {
     if (!item.canPlaceInWorld) return bucket;
     FluidStack liquid = LiquidRegistry.getLiquid(id);
     if (world.setBlock(x, y, z, liquid.getFluid().getBlock(), 0, 3))
       return item.getContainerItem(bucket);
     return bucket;
   }
   if (!item.canBeFilledFromWorld) return bucket;
   Block block = world.getBlock(x, y, z);
   if (block instanceof IFluidBlock) {
     FluidStack liquid = ((IFluidBlock) block).drain(world, x, y, z, false);
     if (liquid != null && FluidRegistry.isFluidRegistered(liquid.getFluid())) {
       ItemStack r = FluidContainerRegistry.fillFluidContainer(liquid, bucket);
       if (r != null && FluidContainerRegistry.isFilledContainer(r)) {
         ((IFluidBlock) block).drain(world, x, y, z, true);
         return r;
       }
     }
   }
   return bucket;
 }
Пример #19
0
  public void autoOutputToSides(
      IOpenModsProxy proxy, int amountPerTick, TileEntity currentTile, SyncableFlags sides) {

    if (currentTile.worldObj == null) return;
    // every 10 ticks refresh the surrounding tanks
    if (proxy.getTicks(currentTile.worldObj) % 10 == 0) {
      refreshSurroundingTanks(currentTile, sides);
    }

    if (getFluidAmount() > 0 && surroundingTanks.size() > 0) {
      FluidStack drainedFluid = drain(Math.min(getFluidAmount(), amountPerTick), true);
      if (drainedFluid != null) {
        Collections.shuffle(surroundingTanks);
        // for each surrounding tank
        for (ForgeDirection side : surroundingTanks) {
          TileEntity otherTank = BlockUtils.getTileInDirection(currentTile, side);
          if (drainedFluid.amount > 0) {
            drainedFluid = drainedFluid.copy();
            if (otherTank instanceof IFluidHandler) {
              drainedFluid.amount -=
                  ((IFluidHandler) otherTank).fill(side.getOpposite(), drainedFluid, true);
            } else {
              drainedFluid.amount -=
                  ModuleBuildCraft.tryAcceptIntoPipe(otherTank, drainedFluid, side.getOpposite());
            }
          }
        }
        // fill any remainder
        if (drainedFluid.amount > 0) {
          fill(drainedFluid, true);
        }
      }
    }
  }
Пример #20
0
  public int fill_(ItemStack container, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    if (!doFill) {
      if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
        return Math.min(fluidCapacity, resource.amount);
      }

      FluidStack stack =
          FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));

      if (stack == null) {
        return Math.min(fluidCapacity, resource.amount);
      }

      if (!stack.isFluidEqual(resource)) {
        return 0;
      }

      return Math.min(fluidCapacity - stack.amount, resource.amount);
    }

    if (container.stackTagCompound == null) {
      container.stackTagCompound = new NBTTagCompound();
    }

    if (!container.stackTagCompound.hasKey("Fluid")) {
      NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());

      if (fluidCapacity < resource.amount) {
        fluidTag.setInteger("Amount", fluidCapacity);
        container.stackTagCompound.setTag("Fluid", fluidTag);
        return fluidCapacity;
      }

      container.stackTagCompound.setTag("Fluid", fluidTag);
      return resource.amount;
    }

    NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
    FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);

    if (!stack.isFluidEqual(resource)) {
      return 0;
    }

    int filled = fluidCapacity - stack.amount;
    if (resource.amount < filled) {
      stack.amount += resource.amount;
      filled = resource.amount;
    } else {
      stack.amount = fluidCapacity;
    }

    container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag));
    return filled;
  }
Пример #21
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) {
      return true;
    }

    ItemStack held = player.getHeldItem();
    FluidStack fluidHeld = FluidContainerRegistry.getFluidForFilledItem(held);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (fluidHeld != null
        && fluidHeld.getFluid() == FluidRegistry.getFluid("water")
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canReceiveWaterBucket()) {
        tank.addBucketOfWater();
        if (FluidContainerRegistry.isBucket(held)
            && !(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          int heldLocation = player.inventory.currentItem;
          player.inventory.decrStackSize(heldLocation, 1);
          world.spawnEntityInWorld(
              new EntityItem(
                  world, player.posX, player.posY, player.posZ, new ItemStack(Items.bucket, 1)));
          //                    player.inventory.setInventorySlotContents(heldLocation, new
          // ItemStack(Items.bucket, 1));
        }
      }
      return true;
    }
    if (held != null
        && held.getItem() == Items.bucket
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canGiveSolarWater()) {
        ItemStack filledBucket =
            FluidContainerRegistry.fillFluidContainer(
                new FluidStack(ModFluids.fluidSolarWater, 1000), new ItemStack(Items.bucket, 1));
        tank.removeBucketOfSolarWater();
        if (!(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          player.inventory.decrStackSize(player.inventory.currentItem, 1);
          // player.inventory.setInventorySlotContents(player.inventory.getFirstEmptyStack(),
          // filledBucket);
          world.spawnEntityInWorld(
              new EntityItem(world, player.posX, player.posY, player.posZ, filledBucket));
        }
        return true;
      }
    }

    return false;
  }
	@Override
	public void writeToNBT(NBTTagCompound tag)
	{
		super.writeToNBT(tag);
		NBTTagList nbttaglist;
		if (_inventory.length > 0)
		{
			nbttaglist = new NBTTagList();
			for(int i = 0; i < _inventory.length; i++)
			{
				if (_inventory[i] != null && _inventory[i].stackSize > 0)
				{
					NBTTagCompound slot = new NBTTagCompound();
					slot.setByte("Slot", (byte)i);
					_inventory[i].writeToNBT(slot);
					nbttaglist.appendTag(slot);
				}
			}
			tag.setTag("Items", nbttaglist);
		}
		
		IFluidTank[] _tanks = getTanks();
		if (_tanks.length > 0)
		{
			NBTTagList tanks = new NBTTagList();
			for(int i = 0, n = _tanks.length; i < n; i++)
			{
				if(_tanks[i].getFluid() != null)
				{
					NBTTagCompound nbttagcompound1 = new NBTTagCompound();
					nbttagcompound1.setByte("Tank", (byte)i);
					
					FluidStack l = _tanks[i].getFluid();
					l.writeToNBT(nbttagcompound1);
					tanks.appendTag(nbttagcompound1);
				}
			}
			tag.setTag("mTanks", tanks);
		}
		
		if (this.isInvNameLocalized())
		{
			NBTTagCompound display = new NBTTagCompound();
			display.setString("Name", getInvName());
			tag.setCompoundTag("display", display);
		}
		
		if (failedDrops != null)
		{
			nbttaglist = new NBTTagList();
			for (ItemStack item : failedDrops)
			{
				NBTTagCompound nbttagcompound1 = new NBTTagCompound();
				item.writeToNBT(nbttagcompound1);
				nbttaglist.appendTag(nbttagcompound1);
			}
			tag.setTag("DropItems", nbttaglist);
		}
	}
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.getFluid() == null) return 0;
   int toadd = Math.min(resource.amount, this.getCapacity(resource.getFluid()) - tank.getLevel());
   if (toadd <= 0) return 0;
   FluidStack fs = new FluidStack(resource.getFluid(), toadd);
   return this.canFill(from, resource.getFluid()) ? tank.fill(fs, doFill) : 0;
 }
 public static void setFluidStack(ItemStack stack, String key, FluidStack val) {
   if (val != null && val.getFluid() != null) {
     NBTTagCompound tag = getTagCompound(stack, key);
     tag.setString("fluid", val.getFluid().getName());
     tag.setInteger("amount", val.amount);
     setTagCompound(stack, key, tag);
   } else remove(stack, "fluid");
 }
Пример #25
0
 @Override
 public FluidStack getFluid(ItemStack container) {
   FluidTank tank = readTank(container);
   if (tank == null) return null;
   FluidStack result = tank.getFluid();
   if (result != null) result.amount *= container.stackSize;
   return result;
 }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   int maxDrain = resource.amount;
   if (this.canDrain(from, resource.getFluid()) && this.isValidFluid(resource.getFluid())) {
     return tank.drain(maxDrain, doDrain);
   }
   return null;
 }
Пример #27
0
 public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
   List<ItemStack> containers = new ArrayList<ItemStack>();
   for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
     FluidStack inContainer = FluidItemHelper.getFluidStackInContainer(data.filledContainer);
     if (inContainer != null && inContainer.containsFluid(fluidStack))
       containers.add(data.filledContainer.copy());
   }
   return containers;
 }
 public static void registerAsContainer(Fluid fluid) {
   FluidStack stack =
       FluidRegistry.getFluidStack(fluid.getName(), FluidContainerRegistry.BUCKET_VOLUME);
   stack = stack.copy();
   stack.amount = cell.volume;
   FluidContainerRegistry.registerFluidContainer(
       new FluidContainerData(
           stack, new ItemStack(cell, 1, LiquidRegistry.getID(stack)), new ItemStack(cell, 1, 0)));
 }
Пример #29
0
  public boolean addLiquid(FluidStack f) {
    if (fluid == null) fluid = f;
    else {
      if (fluid.amount == 10000 || !fluid.isFluidEqual(f)) return false;

      fluid.amount = Math.min(fluid.amount + f.amount, 10000);
    }
    return true;
  }
Пример #30
0
 @Override
 public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
   if (this.res == null) return null;
   FluidStack ret = this.res.copy();
   ret.amount = Math.min(maxDrain, ret.amount);
   if (doDrain) {
     this.res.amount -= ret.amount;
     if (this.res.amount == 0) this.res = null;
   }
   return ret;
 }