コード例 #1
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;
  }
	@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);
		}
	}
コード例 #3
0
ファイル: PipeInfo.java プロジェクト: Glease/taam
 public void writeToNBT(NBTTagCompound tag) {
   tag.setInteger("pressure", pressure);
   tag.setInteger("suction", suction);
   NBTTagList list = new NBTTagList();
   for (FluidStack stack : content) {
     NBTTagCompound fluidTag = new NBTTagCompound();
     stack.writeToNBT(fluidTag);
     list.appendTag(fluidTag);
   }
   tag.setTag("content", list);
 }
コード例 #4
0
  /**
   * Standard method to write the fluid data of this TE to the NBTCompound that stores this TE's
   * Data.
   *
   * @return A NBTTagList with all fluids in the Tile.
   */
  protected NBTBase writeFluidsToCompound() {
    IFluidContainingEntity fluidContainingEntity = (IFluidContainingEntity) this;

    NBTTagList fluidData = new NBTTagList();

    for (FluidStack stack : fluidContainingEntity.getAllFluids()) {
      fluidData.appendTag(stack.writeToNBT(new NBTTagCompound()));
    }

    return fluidData;
  }
コード例 #5
0
ファイル: TEBarrel.java プロジェクト: rjdunlap/TFCraft
  public static ItemStack createFullBarrel(FluidStack f, ItemStack is) {
    if (!is.hasTagCompound()) is.setTagCompound(new NBTTagCompound());

    is.getTagCompound().setBoolean("Sealed", true);
    // nbt.setInteger("mode", mode);
    NBTTagCompound fluidNBT = new NBTTagCompound();
    if (f != null) f.writeToNBT(fluidNBT);
    is.getTagCompound().setTag("fluidNBT", fluidNBT);

    return is;
  }
コード例 #6
0
  private static void setupCrafting() {
    NBTTagCompound toSend = new NBTTagCompound();
    toSend.setInteger("energy", 4000);
    toSend.setTag("input", new NBTTagCompound());
    toSend.setTag("output", new NBTTagCompound());
    ItemStack carbonDrop = Config.drops.getStackForType(DropType.CARBON);
    carbonDrop.writeToNBT(toSend.getCompoundTag("input"));
    fluidCoal.writeToNBT(toSend.getCompoundTag("output"));
    FMLInterModComms.sendMessage("ThermalExpansion", "CrucibleRecipe", toSend);

    toSend = new NBTTagCompound();
    toSend.setInteger("energy", 4000);
    toSend.setTag("input", new NBTTagCompound());
    toSend.setTag("output", new NBTTagCompound());
    ItemStack destabilizedDrop = Config.drops.getStackForType(DropType.DESTABILIZED);
    destabilizedDrop.writeToNBT(toSend.getCompoundTag("input"));
    fluidRedstone.writeToNBT(toSend.getCompoundTag("output"));
    FMLInterModComms.sendMessage("ThermalExpansion", "CrucibleRecipe", toSend);

    toSend = new NBTTagCompound();
    toSend.setInteger("energy", 4000);
    toSend.setTag("input", new NBTTagCompound());
    toSend.setTag("output", new NBTTagCompound());
    ItemStack endearingDrop = Config.drops.getStackForType(DropType.ENDEARING);
    endearingDrop.writeToNBT(toSend.getCompoundTag("input"));
    fluidEnder.writeToNBT(toSend.getCompoundTag("output"));
    FMLInterModComms.sendMessage("ThermalExpansion", "CrucibleRecipe", toSend);

    toSend = new NBTTagCompound();
    toSend.setInteger("energy", 4000);
    toSend.setTag("input", new NBTTagCompound());
    toSend.setTag("output", new NBTTagCompound());
    ItemStack luxDrop = Config.drops.getStackForType(DropType.LUX);
    luxDrop.writeToNBT(toSend.getCompoundTag("input"));
    fluidGlowstone.writeToNBT(toSend.getCompoundTag("output"));
    FMLInterModComms.sendMessage("ThermalExpansion", "CrucibleRecipe", toSend);
  }
コード例 #7
0
  @Override
  public void save(NBTTagCompound nbtTags) {
    super.save(nbtTags);

    if (getTransmitterNetwork().fluidStored != null) {
      int remain =
          getTransmitterNetwork().fluidStored.amount % getTransmitterNetwork().transmitters.size();
      int toSave =
          getTransmitterNetwork().fluidStored.amount / getTransmitterNetwork().transmitters.size();

      if (getTransmitterNetwork().isFirst((IGridTransmitter<FluidNetwork>) tile())) {
        toSave += remain;
      }

      if (toSave > 0) {
        FluidStack stack = new FluidStack(getTransmitterNetwork().fluidStored.getFluid(), toSave);
        lastWrite = stack;
        nbtTags.setCompoundTag("cacheFluid", stack.writeToNBT(new NBTTagCompound()));
      }
    }
  }
コード例 #8
0
ファイル: TEBarrel.java プロジェクト: Kittychanley/TFCraft
 @Override
 public void writeToNBT(NBTTagCompound nbt) {
   super.writeToNBT(nbt);
   nbt.setBoolean("Sealed", sealed);
   nbt.setInteger("SealTime", sealtime);
   nbt.setInteger("barrelType", barrelType);
   // nbt.setInteger("mode", mode);
   NBTTagCompound fluidNBT = new NBTTagCompound();
   if (fluid != null) fluid.writeToNBT(fluidNBT);
   nbt.setTag("fluidNBT", fluidNBT);
   nbt.setByte("rotation", rotation);
   NBTTagList nbttaglist = new NBTTagList();
   for (int i = 0; i < storage.length; i++) {
     if (storage[i] != null) {
       NBTTagCompound nbttagcompound1 = new NBTTagCompound();
       nbttagcompound1.setByte("Slot", (byte) i);
       storage[i].writeToNBT(nbttagcompound1);
       nbttaglist.appendTag(nbttagcompound1);
     }
   }
   nbt.setTag("Items", nbttaglist);
 }