当前位置: 首页>>代码示例>>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;未经允许,请勿转载。