當前位置: 首頁>>代碼示例>>Java>>正文


Java IFluidHandler.canFill方法代碼示例

本文整理匯總了Java中net.minecraftforge.fluids.IFluidHandler.canFill方法的典型用法代碼示例。如果您正苦於以下問題:Java IFluidHandler.canFill方法的具體用法?Java IFluidHandler.canFill怎麽用?Java IFluidHandler.canFill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraftforge.fluids.IFluidHandler的用法示例。


在下文中一共展示了IFluidHandler.canFill方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pushUp

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
public int pushUp(FluidStack fluid, boolean doFill)
{
	Coord4D up = Coord4D.get(this).getFromSide(ForgeDirection.UP);
	
	if(up.getTileEntity(worldObj) instanceof TileEntityPortableTank)
	{
		IFluidHandler handler = (IFluidHandler)up.getTileEntity(worldObj);
		
		if(handler.canFill(ForgeDirection.DOWN, fluid.getFluid()))
		{
			return handler.fill(ForgeDirection.DOWN, fluid, doFill);
		}
	}
	
	return 0;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:17,代碼來源:TileEntityPortableTank.java

示例2: isValidAcceptorOnSide

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
public static boolean isValidAcceptorOnSide(TileEntity tile, ForgeDirection side)
{
	if(tile instanceof ITransmitterTile || !(tile instanceof IFluidHandler))
		return false;

	IFluidHandler container = (IFluidHandler)tile;
	FluidTankInfo[] infoArray = container.getTankInfo(side.getOpposite());

	if(container.canDrain(side.getOpposite(), FluidRegistry.WATER)
		|| container.canFill(side.getOpposite(), FluidRegistry.WATER)) //I hesitate to pass null to these.
	{
		return true;
	}
	else if(infoArray != null && infoArray.length > 0)
	{
		for(FluidTankInfo info : infoArray)
		{
			if(info != null)
			{
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:26,代碼來源:PipeUtils.java

示例3: onNexusExportCall

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
public void onNexusExportCall(TileEntityTransporter nexus)
{
    ForgeDirection nexusOrientation = ForgeDirection.getOrientation(nexus.getBlockMetadata());
    FluidTankInfo[] tankInfo = nexus.getTankInfo(nexusOrientation);
    FluidStack nexusFluid = tankInfo[0].fluid;

    if (nexusFluid != null && nexusFluid.amount > 0)
    {
        TileEntity tile = nexus.getAttachedTileEntity();
        if (tile instanceof IFluidHandler)
        {
            IFluidHandler inv = (IFluidHandler) tile;
            if (inv.canFill(nexusOrientation, nexusFluid.getFluid()))
            {
                FluidStack toFill = new FluidStack(nexusFluid.getFluid(), Math.min(nexusFluid.amount,
                        nexus.isHighCapacity() ?
                                ConfigValues.highCapacityFluidPickup :
                                ConfigValues.standardFluidPickup));
                int filled = inv.fill(nexusOrientation, toFill, true);
                nexus.drain(nexusOrientation, filled, true);

                if (filled != 0)
                {
                    nexus.resetCounter();
                    return;
                }
            }
        }
        attemptTeleport(nexus, nexusOrientation);
    }
}
 
開發者ID:samvbeckmann,項目名稱:network,代碼行數:33,代碼來源:ItemFluidCore.java

示例4: doPull

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
public static boolean doPull(IFluidHandler into, ForgeDirection fromDir, int maxVolume) {
  TileEntity te = (TileEntity) into;
  BlockCoord loc = new BlockCoord(te).getLocation(fromDir);
  IFluidHandler target = FluidUtil.getFluidHandler(te.getWorldObj(), loc);
  if (target != null) {
    FluidTankInfo[] infos = target.getTankInfo(fromDir.getOpposite());
    if (infos != null) {
      for (FluidTankInfo info : infos) {
        if (info.fluid != null && info.fluid.amount > 0) {
          if (into.canFill(fromDir, info.fluid.getFluid())) {
            FluidStack canPull = info.fluid.copy();
            canPull.amount = Math.min(maxVolume, canPull.amount);
            FluidStack drained = target.drain(fromDir.getOpposite(), canPull, false);
            if (drained != null && drained.amount > 0) {
              int filled = into.fill(fromDir, drained, false);
              if (filled > 0) {
                drained = target.drain(fromDir.getOpposite(), filled, true);
                into.fill(fromDir, drained, true);
                return true;
              }
            }
          }
        }
      }
    }
  }
  return false;
}
 
開發者ID:SleepyTrousers,項目名稱:EnderCore,代碼行數:29,代碼來源:FluidUtil.java

示例5: getAcceptors

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
public Set<IFluidHandler> getAcceptors(Object data)
{
	FluidStack fluidToSend = (FluidStack)data;
	Set<IFluidHandler> toReturn = new HashSet<>();
	
	if(FMLCommonHandler.instance().getEffectiveSide().isClient())
	{
		return toReturn;
	}

	for(Coord4D coord : possibleAcceptors.keySet())
	{
		EnumSet<ForgeDirection> sides = acceptorDirections.get(coord);

		if(sides == null || sides.isEmpty())
		{
			continue;
		}

		IFluidHandler acceptor = (IFluidHandler)coord.getTileEntity(getWorld());

		for(ForgeDirection side : sides)
		{
			if(acceptor != null && acceptor.canFill(side, fluidToSend.getFluid()))
			{
				toReturn.add(acceptor);
				break;
			}
		}
	}

	return toReturn;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:35,代碼來源:FluidNetwork.java

示例6: doPush

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
protected boolean doPush(@Nullable ForgeDirection dir) {
  if (dir == null || isSideDisabled(dir.ordinal())) {
    return false;
  }

  boolean res = super.doPush(dir);
  if (outputTank.getFluidAmount() > 0) {

    BlockCoord loc = getLocation().getLocation(dir);
    IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
    if (target != null) {
      if (target.canFill(dir.getOpposite(), outputTank.getFluid().getFluid())) {
        FluidStack push = outputTank.getFluid().copy();
        push.amount = Math.min(push.amount, IO_MB_TICK);
        int filled = target.fill(dir.getOpposite(), push, true);
        if (filled > 0) {
          outputTank.drain(filled, true);
          tanksDirty = true;
          return res;
        }
      }
    }

  }
  return res;
}
 
開發者ID:HenryLoenwind,項目名稱:EnderIOAddons,代碼行數:28,代碼來源:TileWaterworks.java

示例7: doPush

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
protected boolean doPush(@Nullable ForgeDirection dir) {

  if (dir == null || isSideDisabled(dir.ordinal())) {
    return false;
  }

  boolean res = super.doPush(dir);
  if(tank.getFluidAmount() > 0) {

    BlockCoord loc = getLocation().getLocation(dir);
    IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
    if(target != null) {
      if(target.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
        FluidStack push = tank.getFluid().copy();
        push.amount = Math.min(push.amount, IO_MB_TICK);
        int filled = target.fill(dir.getOpposite(), push, true);
        if(filled > 0) {
          tank.drain(filled, true);
          tankDirty = true;
          return res;
        }
      }
    }

  }
  return res;
}
 
開發者ID:HenryLoenwind,項目名稱:EnderIOAddons,代碼行數:29,代碼來源:TileDrain.java

示例8: importContents

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
protected void importContents() {
	if (!this.worldObj.isRemote) {
		
		// export to tank below:
		if (this.getTank().getFluidAmount() > 0 && this.openSides[EnumFacing.DOWN.ordinal()] == 1) {
			final Vector3<Integer> vec = worldVec();
			vec.y--;
			TileEntity te = worldObj.getTileEntity(VectorHelper.toBlockPos(vec));
			if (te != null && te instanceof IFluidHandler) {
				IFluidHandler tank = (IFluidHandler) te;
				
				if (this.getTank().getFluid() != null && this.getTank().getFluid().getFluid() != null
						&& tank.canFill(EnumFacing.UP, this.getTank().getFluid().getFluid())) {
					FluidStack thisStack = this.getTank().getFluid();
					int amount = getAmountFromTank(tank, thisStack, EnumFacing.UP);
					
					// if destination tank is empty set to default size.
					if (amount == 0) amount = Reference.Constants.BASE_FLUID_TRANSFER_RATE;
					
					amount = Math.min(amount, thisStack.amount);
					amount = Math.min(amount, Reference.Constants.BASE_FLUID_TRANSFER_RATE);
					
					if (amount > 0) {
						FluidStack sendStack = thisStack.copy();
						sendStack.amount = amount;
						
						amount = sendStack.amount = tank.fill(EnumFacing.UP, sendStack, false);
						
						this.getTank().drain(amount, true);
						tank.fill(EnumFacing.UP, sendStack, true);
					}
					
				}
			}
		}
		
	}
}
 
開發者ID:hockeyhurd,項目名稱:Project-Zed,代碼行數:40,代碼來源:TileEntityFluidTankBase.java

示例9: emit

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
/**
 * Emits fluid from a central block by splitting the received stack among the sides given.
 * @param sides - the list of sides to output from
 * @param stack - the stack to output
 * @param from - the TileEntity to output from
 * @return the amount of gas emitted
 */
public static int emit(List<ForgeDirection> sides, FluidStack stack, TileEntity from)
{
	if(stack == null)
	{
		return 0;
	}
	
	List<IFluidHandler> availableAcceptors = new ArrayList<IFluidHandler>();
	IFluidHandler[] possibleAcceptors = getConnectedAcceptors(from);
	
	for(int i = 0; i < possibleAcceptors.length; i++)
	{
		IFluidHandler handler = possibleAcceptors[i];
		
		if(handler != null && handler.canFill(ForgeDirection.getOrientation(i).getOpposite(), stack.getFluid()))
		{
			availableAcceptors.add(handler);
		}
	}

	Collections.shuffle(availableAcceptors);

	int toSend = stack.amount;
	int prevSending = toSend;

	if(!availableAcceptors.isEmpty())
	{
		int divider = availableAcceptors.size();
		int remaining = toSend % divider;
		int sending = (toSend-remaining)/divider;

		for(IFluidHandler acceptor : availableAcceptors)
		{
			int currentSending = sending;

			if(remaining > 0)
			{
				currentSending++;
				remaining--;
			}
			
			ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
			toSend -= acceptor.fill(dir, new FluidStack(stack.getFluid(), currentSending), true);
		}
	}

	return prevSending-toSend;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:56,代碼來源:PipeUtils.java

示例10: transferFluid

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@LuaFunction
public int transferFluid(String source, ForgeDirection sourceSide, int sourceTankId, String target, ForgeDirection targetSide, int amount) throws Exception {
	sourceTankId--;

	if (!posByName.containsKey(source)) {
		throw new Exception("Invalid source '" + source + "'. Not specified, use setName(x,y,z,name) first.");
	}

	if (!posByName.containsKey(target)) {
		throw new Exception("Invalid target '" + target + "'. Not specified, use setName(x,y,z,name) first.");
	}

	if (amount <= 0) {
		throw new Exception("At least 1mb needs to be transferred.");
	}

	RelativePos sourcePos = posByName.get(source);
	TileEntity sourceTile = worldObj.getTileEntity(xCoord + sourcePos.x, yCoord + sourcePos.y, zCoord + sourcePos.z);
	if (!(sourceTile instanceof IFluidHandler)) {
		throw new Exception("Source tile is no fluid handler.");
	}

	RelativePos targetPos = posByName.get(target);
	TileEntity targetTile = worldObj.getTileEntity(xCoord + targetPos.x, yCoord + targetPos.y, zCoord + targetPos.z);
	if (!(targetTile instanceof IFluidHandler)) {
		throw new Exception("Target tile is no fluid handler.");
	}

	IFluidHandler sourceHandler = (IFluidHandler) sourceTile;
	FluidTankInfo sourceTankInfos[] = sourceHandler.getTankInfo(sourceSide);
	if (sourceTankInfos.length == 0) {
		return 0;
	}

	if (sourceTankId >= sourceTankInfos.length) {
		throw new Exception("Source tile has no tank " + sourceTankId + " on side '" + sourceSide + "'.");
	}

	FluidTankInfo sourceTankInfo = sourceTankInfos[sourceTankId];
	if (sourceTankInfo.fluid == null) {
		return 0;
	}

	FluidStack sourceFluid = sourceTankInfo.fluid.copy();

	if (sourceHandler.canDrain(sourceSide, sourceFluid.getFluid())) {
		sourceFluid.amount = amount;
		FluidStack sourceDrainageSim = sourceHandler.drain(sourceSide, sourceFluid, false);
		if (sourceDrainageSim.amount > 0) {
			// Drain simulation successful

			IFluidHandler targetHandler = (IFluidHandler) targetTile;
			if (targetHandler.canFill(targetSide, sourceFluid.getFluid())) {
				int filledSim = targetHandler.fill(targetSide, sourceDrainageSim, false);
				if (filledSim > 0) {
					// Fill simulation successful

					FluidStack sourceDrainage = sourceHandler.drain(sourceSide, sourceFluid, true);
					int filled = targetHandler.fill(targetSide, sourceDrainage, true);
					sourceTile.markDirty();
					targetTile.markDirty();
					return filled;
				}
			}
		}
	}

	return 0;
}
 
開發者ID:thraaawn,項目名稱:CCFactoryManager,代碼行數:70,代碼來源:TileEntityFactoryController.java

示例11: pushFluid

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
public void pushFluid()
{
	int sideAttached = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) ^ 1;
 if(this.tank.getFluidAmount()>= 1000)
 	{
 		lastDir[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)] = 0;
 		for(int ix = 0; ix < 6; ix++)
 		{
 			if(lastDir[0] == 0 && lastDir[1] == 0 &&  lastDir[2] == 0 && lastDir[3] == 0 && lastDir[4] == 0 && lastDir[5] == 0)
 			{
 				
 				lastDir[0] = 1;
 				lastDir[1] = 1;
 				lastDir[2] = 1;
 				lastDir[3] = 1;
 				lastDir[4] = 1;
 				lastDir[5] = 1;
 				lastDir[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)] = 0;
 			}
 			ForgeDirection dir = ForgeDirection.getOrientation(ix);
 			if(lastDir[ix] == 0 || worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ) == null || !(worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ) instanceof IFluidHandler))
  			{
  				lastDir[ix] = 0;
  				continue;
  			}
 			else if(worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ) != null && worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ) instanceof IFluidHandler)
 			{
 				try
  			{
  				IFluidHandler tile = (IFluidHandler) (worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, dir.offsetZ+zCoord));
  				if(tile.canFill(dir, this.tank.getFluid().getFluid())   && this.canDrain(dir.getOpposite(), tank.getFluid().getFluid()))
  				{
  					if(!(tile instanceof TileEntityTank) && tile.getTankInfo(dir)[0]!=null && tile.getTankInfo(dir)[0].fluid != null)
  					{
  						if(tile.getTankInfo(dir)[0].fluid.amount+this.transferAmount <= tile.getTankInfo(dir)[0].capacity)
  						{
  							tile.fill(dir, this.drain(dir.getOpposite(), new FluidStack(tank.getFluid().getFluid(), this.transferAmount), true), true);
  							lastDir[ix] = 0;
  						}
  					}
  					else
  					{
  						lastDir[ix] = 0;
  						tile.fill(dir, this.drain(dir.getOpposite(), new FluidStack(tank.getFluid().getFluid(), this.transferAmount), true), true);
  					}
  				}
  			}
  			catch(Exception e)
  			{
  				
  			}
 			}
 		}
	}
}
 
開發者ID:Sudwood,項目名稱:AdvancedUtilities,代碼行數:56,代碼來源:TileEntitySplitterFluidTube.java

示例12: exportItem

import net.minecraftforge.fluids.IFluidHandler; //導入方法依賴的package包/類
@Override
protected boolean exportItem(int maxItems){
    ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata());
    if(tank.getFluid() != null) {
        TileEntity neighbor = IOHelper.getNeighbor(this, dir);
        if(neighbor instanceof IFluidHandler) {
            IFluidHandler fluidHandler = (IFluidHandler)neighbor;
            if(fluidHandler.canFill(dir.getOpposite(), tank.getFluid().getFluid())) {
                FluidStack fluid = tank.getFluid().copy();
                fluid.amount = Math.min(maxItems * 100, tank.getFluid().amount - (leaveMaterial ? 1000 : 0));
                if(fluid.amount > 0) {
                    tank.getFluid().amount -= fluidHandler.fill(dir.getOpposite(), fluid, true);
                    if(tank.getFluidAmount() <= 0) tank.setFluid(null);
                    return true;
                }
            }
        }
    }

    if(worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
        for(EntityItem entity : getNeighborItems(this, dir)) {
            if(!entity.isDead) {
                List<ItemStack> returnedItems = new ArrayList<ItemStack>();
                if(FluidUtils.tryExtractingLiquid(this, entity.getEntityItem(), returnedItems)) {
                    if(entity.getEntityItem().stackSize <= 0) entity.setDead();
                    for(ItemStack stack : returnedItems) {
                        EntityItem item = new EntityItem(worldObj, entity.posX, entity.posY, entity.posZ, stack);
                        item.motionX = entity.motionX;
                        item.motionY = entity.motionY;
                        item.motionZ = entity.motionZ;
                        worldObj.spawnEntityInWorld(item);
                    }
                    return true;
                }
            }
        }
    }

    if(getUpgrades(ItemMachineUpgrade.UPGRADE_DISPENSER_DAMAGE) > 0) {
        if(worldObj.isAirBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)) {
            FluidStack extractedFluid = drain(ForgeDirection.UNKNOWN, 1000, false);
            if(extractedFluid != null && extractedFluid.amount == 1000) {
                Block fluidBlock = extractedFluid.getFluid().getBlock();
                if(fluidBlock != null) {
                    drain(ForgeDirection.UNKNOWN, 1000, true);
                    worldObj.setBlock(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, fluidBlock);
                }
            }
        }
    }

    return false;
}
 
開發者ID:MineMaarten,項目名稱:PneumaticCraft,代碼行數:54,代碼來源:TileEntityLiquidHopper.java


注:本文中的net.minecraftforge.fluids.IFluidHandler.canFill方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。