Пример #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;
  }
Пример #2
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;
  }
Пример #3
0
 @Override
 public void readFromNBT(NBTTagCompound nbttc) {
   super.readFromNBT(nbttc);
   this.silktouch = nbttc.getBoolean("silktouch");
   this.fortune = nbttc.getByte("fortune");
   this.efficiency = nbttc.getByte("efficiency");
   this.unbreaking = nbttc.getByte("unbreaking");
   this.pp.readFromNBT(nbttc);
   this.src1 = FluidStack.loadFluidStackFromNBT(nbttc.getCompoundTag("src1"));
   this.src2 = FluidStack.loadFluidStackFromNBT(nbttc.getCompoundTag("src2"));
   this.res = FluidStack.loadFluidStackFromNBT(nbttc.getCompoundTag("res"));
   this.animationSpeed = nbttc.getFloat("animationSpeed");
   this.animationStage = nbttc.getInteger("animationStage");
   this.buf = (int) (FluidContainerRegistry.BUCKET_VOLUME * 4 * Math.pow(1.3, this.fortune));
   PowerManager.configureR(this.pp, this.efficiency, this.unbreaking);
 }
Пример #4
0
  @Override
  public void load(NBTTagCompound nbtTags) {
    super.load(nbtTags);

    if (nbtTags.hasKey("cacheFluid")) {
      cacheFluid = FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("cacheFluid"));
    }
  }
Пример #5
0
 public void readFromItemNBT(NBTTagCompound nbt) {
   barrelType = nbt.getInteger("barrelType");
   fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("fluidNBT"));
   sealed = nbt.getBoolean("sealed");
   NBTTagList nbttaglist = nbt.getTagList("Items", 10);
   for (int i = 0; i < nbttaglist.tagCount(); i++) {
     NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i);
     byte byte0 = nbt1.getByte("Slot");
     if (byte0 >= 0 && byte0 < 2)
       setInventorySlotContents(byte0, ItemStack.loadItemStackFromNBT(nbt1));
   }
 }
Пример #6
0
 @Override
 public void onBlockPlacedBy(
     World world, int x, int y, int z, EntityLivingBase entity, ItemStack is) {
   TileEntity _t = world.getTileEntity(x, y, z);
   if (_t != null && _t instanceof TEOilLamp) {
     ((TEOilLamp) _t).create();
     FluidStack fs = FluidStack.loadFluidStackFromNBT(is.getTagCompound());
     if (fs != null) {
       ((TEOilLamp) _t).setFuelFromStack(fs);
     } else {
       // world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z)+8, 0x3);
     }
     ((TEOilLamp) _t).hourPlaced = (int) TFC_Time.getTotalHours();
   }
 }
  private void readFluidsFromNBT(NBTTagCompound tag) {
    // Initialize tanks to empty, as we send sparse updates.
    for (int i = 0; i < tanks.length; i++) {
      tanks[i].setFluid(null);
    }

    if (tag.hasKey("fluids")) {
      NBTTagList tagList = tag.getTagList("fluids", 10);
      for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound fluidTag = tagList.getCompoundTagAt(i);
        int fluidIdx = fluidTag.getInteger("tagIdx");
        FluidStack newFluid = FluidStack.loadFluidStackFromNBT(fluidTag);
        tanks[fluidIdx].setFluid(newFluid);
      }
    }
  }
  /**
   * Standard method to read the fluids data of this TE from the NBTCompound that stores this TE's
   * Data.
   *
   * @param inventoryCompound A NBTBase instance in the form of a TagList containing all the Data of
   *     the fluids in this tileentity.
   */
  protected void readFluidsFromCompound(NBTBase inventoryCompound) {
    if (!(inventoryCompound instanceof NBTTagList))
      throw new IllegalArgumentException("The given store type is not compatible with this TE!");

    IFluidContainingEntity fluidContainingEntity = (IFluidContainingEntity) this;

    NBTTagList inventoryList = (NBTTagList) inventoryCompound;
    ArrayList<FluidStack> fluidStacks = new ArrayList<FluidStack>();

    for (int i = 0; i < inventoryList.tagCount(); i++) {
      NBTTagCompound fluidCompound = (NBTTagCompound) inventoryList.get(i);

      fluidStacks.add(FluidStack.loadFluidStackFromNBT(fluidCompound));
    }

    fluidContainingEntity.setAllFluids(fluidStacks);
  }
Пример #9
0
 public void readFromNBT(NBTTagCompound tag) {
   pressure = tag.getInteger("pressure");
   suction = tag.getInteger("suction");
   NBTTagList list = tag.getTagList("content", NBT.TAG_COMPOUND);
   content.clear();
   if (list != null && list.tagCount() != 0) {
     content.ensureCapacity(list.tagCount());
     for (int i = 0; i < list.tagCount(); i++) {
       NBTTagCompound fluidTag = list.getCompoundTagAt(i);
       FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
       if (stack != null) {
         content.add(stack);
       }
     }
   }
   content.trimToSize();
   recalculateFillLevel();
 }
Пример #10
0
 @Override
 public void readFromNBT(NBTTagCompound nbt) {
   super.readFromNBT(nbt);
   fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("fluidNBT"));
   sealed = nbt.getBoolean("Sealed");
   sealtime = nbt.getInteger("SealTime");
   barrelType = nbt.getInteger("barrelType");
   // mode = nbt.getInteger("mode");
   rotation = nbt.getByte("rotation");
   NBTTagList nbttaglist = nbt.getTagList("Items", 10);
   storage = new ItemStack[getSizeInventory()];
   for (int i = 0; i < nbttaglist.tagCount(); i++) {
     NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
     byte byte0 = nbttagcompound1.getByte("Slot");
     if (byte0 >= 0 && byte0 < storage.length)
       storage[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
   }
 }
 @Override
 public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advInfo) {
   if (stack.getItemDamage() == 4)
     list.add(StatCollector.translateToLocal(Lib.DESC_FLAVOUR + "crate"));
   if (stack.getItemDamage() == 6) {
     if (stack.hasTagCompound()) {
       NBTTagCompound tag = stack.getTagCompound().getCompoundTag("tank");
       if (!tag.hasKey("Empty")) {
         FluidStack fluid = FluidStack.loadFluidStackFromNBT(tag);
         list.add(fluid.getLocalizedName() + ": " + fluid.amount + "mB");
       } else {
         list.add(StatCollector.translateToLocal(Lib.DESC_FLAVOUR + "barrel"));
         list.add(StatCollector.translateToLocal(Lib.DESC_FLAVOUR + "barrelTemp"));
       }
     } else {
       list.add(StatCollector.translateToLocal(Lib.DESC_FLAVOUR + "barrel"));
       list.add(StatCollector.translateToLocal(Lib.DESC_FLAVOUR + "barrelTemp"));
     }
   }
 }
Пример #12
0
 public FluidStack getFluid_(ItemStack container) {
   if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
     return null;
   }
   return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));
 }
 @Override
 public void readSustainedData(ItemStack itemStack) {
   lavaTank.setFluid(
       FluidStack.loadFluidStackFromNBT(itemStack.stackTagCompound.getCompoundTag("lavaTank")));
 }
Пример #14
0
 @Override
 public void load(NBTTagCompound nbtTags) {
   theSolid = ItemStack.loadItemStackFromNBT(nbtTags.getCompoundTag("itemInput"));
   theFluid = FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("fluidInput"));
   theGas = GasStack.readFromNBT(nbtTags.getCompoundTag("gasInput"));
 }
	@Override
	public void readFromNBT(NBTTagCompound tag)
	{
		super.readFromNBT(tag);
		_inventory = new ItemStack[getSizeInventory()];
		NBTTagList nbttaglist;
		if (tag.hasKey("Items"))
		{
			nbttaglist = tag.getTagList("Items");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound slot = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = slot.getByte("Slot") & 0xff;
				if(j >= 0 && j < _inventory.length)
				{
					_inventory[j] = ItemStack.loadItemStackFromNBT(slot);
					if (_inventory[j].stackSize <= 0)
						_inventory[j] = null;
				}
			}
		}
		onInventoryChanged();

		if (tag.hasKey("mTanks")) {
			IFluidTank[] _tanks = getTanks();
			
			nbttaglist = tag.getTagList("mTanks");
			for(int i = 0; i < nbttaglist.tagCount(); i++)
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = nbttagcompound1.getByte("Tank") & 0xff;
				if(j >= 0 && j < _tanks.length)
				{
					FluidStack l = FluidStack.loadFluidStackFromNBT(nbttagcompound1);
					if(l != null)
					{
						((FluidTank)_tanks[j]).setFluid(l);
					}
				}
			}
		}
		else if (_tanks != null)
		{ // TODO: remove in 2.8
			IFluidTank tank = _tanks[0];
			if (tank != null && tag.hasKey("tankFluidName"))
			{
				int tankAmount = tag.getInteger("tankAmount");
				FluidStack fluid = FluidRegistry.
						getFluidStack(tag.getString("tankFluidName"), tankAmount);
				if (fluid != null)
				{
					if(fluid.amount > tank.getCapacity())
					{
						fluid.amount = tank.getCapacity();
					}

					((FluidTank)tank).setFluid(fluid);
				}
				tag.removeTag("tankFluidName");
				tag.removeTag("tankAmount");
			}
		}
		
		if (tag.hasKey("display"))
		{
			NBTTagCompound display = tag.getCompoundTag("display");
			if (display.hasKey("Name"))
			{
				this.setInvName(display.getString("Name"));
			}
		}

		if (tag.hasKey("DropItems"))
		{
			List<ItemStack> drops = new ArrayList<ItemStack>();
			nbttaglist = tag.getTagList("DropItems");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				ItemStack item = ItemStack.loadItemStackFromNBT(nbttagcompound1);
				if (item != null && item.stackSize > 0)
				{
					drops.add(item);
				}
			}
			if (drops.size() != 0)
			{
				failedDrops = drops;
			}
		}
	}
Пример #16
0
  @Override
  public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);

    if (data.hasKey("shareRS")) {
      isRSShared = data.getBoolean("shareRS");
    }

    for (int i = 0; i < 3; i++) {
      if (data.hasKey("tankCap" + i)) {
        tanks[i] = new FluidTank(data.getInteger("tankCap" + i));
      }

      if (data.hasKey("Fluid" + i)) {
        tanks[i].setFluid(FluidStack.loadFluidStackFromNBT(data.getCompoundTag("Fluid" + i)));
      }

      if (data.hasKey("rsControl" + i)) rsControl[i] = data.getBoolean("rsControl" + i);
      if (data.hasKey("rsLatch" + i)) rsLatch[i] = data.getBoolean("rsLatch" + i);
    }

    NBTTagList itemList = data.getTagList("items");

    for (int i = 0; i < itemList.tagCount(); i++) {
      NBTTagCompound itemCompound = (NBTTagCompound) itemList.tagAt(i);
      int slot = itemCompound.getInteger("slot");
      inventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(itemCompound));
    }

    for (int i = 0; i < 6; i++) {
      if (data.hasKey("side" + i)) {
        sides[i] = data.getInteger("side" + i);
      }
      if (data.hasKey("config" + i)) {
        configs[i] = new SideConfig();
        configs[i].readFromNBT(data.getCompoundTag("config" + i));
      }
      if (data.hasKey("rs" + i)) {
        sideRS[i] = data.getBoolean("rs" + i);
      }
      if (data.hasKey("lock" + i)) {
        sideLocked[i] = data.getBoolean("lock" + i);
      }
      if (data.hasKey("facID" + i)) {
        facID[i] = data.getInteger("facID" + i);
      }
      if (data.hasKey("facMeta" + i)) {
        facMeta[i] = data.getInteger("facMeta" + i);
      }
    }

    itemList = data.getTagList("sideItems");

    for (int i = 0; i < itemList.tagCount(); i++) {
      NBTTagCompound itemCompound = (NBTTagCompound) itemList.tagAt(i);
      int slot = itemCompound.getInteger("slot");
      sideInventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(itemCompound));
    }

    capacitor.readFromNBT(data);
    int power = capacitor.getEnergyStored();
    if (data.hasKey("powerCap2")) this.setMaxEnergyStored((int) data.getInteger("powerCap2"));
    if (data.hasKey("realPower")) power = data.getInteger("realPower");
    capacitor.setEnergyStored(power);
  }
Пример #17
0
 @Override
 public void onPlaced(EntityLivingBase entity, ItemStack item) {
   tanks.setFluid(0, FluidStack.loadFluidStackFromNBT(item.stackTagCompound));
 }