Пример #1
0
  @Override
  public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
    // this is where all the action happens
    if (!canFill(from, resource.getFluid())) {
      return 0;
    }

    // if empty, find a new recipe
    if (this.tank.getFluidAmount() == 0) {
      CastingRecipe recipe = findRecipe(resource.getFluid());
      if (recipe == null) {
        // no recipe found -> can't fill
        return 0;
      }

      int capacity = recipe.fluid.amount;
      IFluidTank calcTank = new FluidTank(capacity);

      // no extra checks needed for the tank since it's empty and we have to set the capacity anyway
      if (doFill) {
        this.recipe = recipe;
        tank.setCapacity(capacity);
        calcTank = tank;
      }

      int filled = calcTank.fill(resource, doFill);
      if (filled > 0 && doFill) {
        renderOffset = filled;
        if (!worldObj.isRemote && worldObj instanceof WorldServer) {
          TinkerNetwork.sendToClients(
              (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
        }
      }
      return filled;
    }

    // non-empty tank. just try to fill
    int filled = tank.fill(resource, doFill);
    if (filled > 0 && doFill) {
      renderOffset += filled;
      if (!worldObj.isRemote && worldObj instanceof WorldServer) {
        TinkerNetwork.sendToClients(
            (WorldServer) worldObj, pos, new FluidUpdatePacket(pos, tank.getFluid()));
      }
    }

    return filled;
  }
Пример #2
0
 public void drawFluidTank(IFluidTank tank, int x, int y) {
   FluidStack fluid = tank.getFluid();
   TextureManager manager = Minecraft.getMinecraft().renderEngine;
   if (fluid != null) {
     manager.bindTexture(manager.getResourceLocation(0));
     float amount = fluid.amount;
     float capacity = tank.getCapacity();
     float scale = amount / capacity;
     int fluidTankHeight = 60;
     int fluidAmount = (int) (scale * fluidTankHeight);
     drawFluid(
         x, y + fluidTankHeight - fluidAmount, fluid.getFluid().getIcon(fluid), 16, fluidAmount);
     manager.bindTexture(PymParticleProducerGuiTextures);
     drawTexturedModalRect(x - 1, y - 1, 238, 0, 18, 62);
   }
 }
  /**
   * Returns true if the given fluid can be extracted from the given direction.
   *
   * <p>More formally, this should return true if fluid is able to leave from the given direction.
   */
  public boolean canDrain(ForgeDirection from, Fluid fluid) {
    int tankIdx = 0;
    if (from != ForgeDirection.UNKNOWN) {
      tankIdx = getExposedTankFromSide(from.ordinal());
    }

    if (tankIdx == FLUIDTANK_NONE) {
      return false;
    }

    IFluidTank tank = tanks[tankIdx];
    if (tank.getFluidAmount() <= 0) {
      return false;
    } else {
      return tank.getFluid().fluidID == fluid.getID();
    }
  }
	public int getComparatorOutput(int side)
	{
		IFluidTank[] tanks = getTanks();
		IFluidTank tank = null;
		if (tanks.length > 0)
			tank = tanks[0];
		float tankPercent = 0, invPercent = 0;
		boolean hasTank = false, hasInventory = false;
		if (tank != null)
		{
			hasTank = true;
			if (tank.getFluid() != null)
			{
				tankPercent = ((float)tank.getFluid().amount) / tank.getCapacity();
			}
		}
		int[] accSlots = getAccessibleSlotsFromSide(side);
		if (accSlots.length > 0)
		{
			hasInventory = true;
			int[] slots = accSlots;
			int len = 0;
			float ret = 0;
			for (int i = slots.length; i --> 0; )
			{
				if (canInsertItem(slots[i], null, side))
				{
					ItemStack stack = getStackInSlot(slots[i]);
					if (stack != null)
					{
						float maxStack = Math.min(stack.getMaxStackSize(), getInventoryStackLimit()); 
						ret += Math.max(Math.min(stack.stackSize / maxStack, 1), 0);
					}
					++len;
				}
			}
			invPercent = ret / len;
		}
		float mult = hasTank & hasInventory ? (tankPercent + invPercent) / 2 : hasTank ? tankPercent : hasInventory ? invPercent : 0f;
		return (int)Math.ceil(15 * mult);
	}
	@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;
			}
		}
	}