当前位置: 首页>>代码示例>>Java>>正文


Java IFluidHandler.drain方法代码示例

本文整理汇总了Java中net.minecraftforge.fluids.IFluidHandler.drain方法的典型用法代码示例。如果您正苦于以下问题:Java IFluidHandler.drain方法的具体用法?Java IFluidHandler.drain怎么用?Java IFluidHandler.drain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraftforge.fluids.IFluidHandler的用法示例。


在下文中一共展示了IFluidHandler.drain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadTank

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
public void loadTank() {
    final int dir = this.getBlockMetadata() % 6;
    if (this.worldObj.getTileEntity(this.xCoord + Facing.offsetsXForSide[dir], this.yCoord + Facing.offsetsYForSide[dir], this.zCoord + Facing.offsetsZForSide[dir]) instanceof IFluidHandler) {
        final IFluidHandler source = (IFluidHandler)this.worldObj.getTileEntity(this.xCoord + Facing.offsetsXForSide[dir], this.yCoord + Facing.offsetsYForSide[dir], this.zCoord + Facing.offsetsZForSide[dir]);
        final FluidStack liquid = source.drain(ForgeDirection.getOrientation(dir).getOpposite(), (this.upgradeNo(3) == 0) ? 200 : ((FluidTank)this.buffer.getBuffer()).getCapacity(), false);
        final int k = this.fill(this.getNodeDir(), liquid, false);
        if (k > 0) {
            this.fill(this.getNodeDir(), source.drain(ForgeDirection.getOrientation(dir).getOpposite(), k, true), true);
        }
    }
    else if (!ExtraUtils.disableInfiniteWater && this.upgradeNo(2) > 0) {
        if (this.worldObj.getTotalWorldTime() - this.checkTimer > 20L) {
            this.checkTimer = this.worldObj.getTotalWorldTime();
            this.nearSource = false;
            if (this.isWaterSource(this.xCoord + Facing.offsetsXForSide[dir], this.yCoord + Facing.offsetsYForSide[dir], this.zCoord + Facing.offsetsZForSide[dir])) {
                int n = 0;
                for (int i = 2; i < 6; ++i) {
                    if (this.isWaterSource(this.xCoord + Facing.offsetsXForSide[dir] + Facing.offsetsXForSide[i], this.yCoord + Facing.offsetsYForSide[dir], this.zCoord + Facing.offsetsZForSide[dir] + Facing.offsetsZForSide[i])) {
                        ++n;
                    }
                }
                if (n >= 2) {
                    this.nearSource = true;
                }
            }
        }
        if (this.nearSource) {
            final long t = this.worldObj.getTotalWorldTime() / TileEntityTransferNode.baseMaxCoolDown * TileEntityTransferNode.baseMaxCoolDown;
            int a = 1000 * TileEntityTransferNode.baseMaxCoolDown / (20 * this.stepCoolDown);
            final float b = 1000.0f * TileEntityTransferNode.baseMaxCoolDown / (20 * this.stepCoolDown);
            if (a != b && b - a > this.worldObj.rand.nextFloat()) {
                ++a;
            }
            if (a > 0) {
                this.fill(this.getNodeDir(), new FluidStack(FluidRegistry.WATER, a * (1 + this.upgradeNo(2))), true);
            }
        }
    }
}
 
开发者ID:sameer,项目名称:ExtraUtilities,代码行数:40,代码来源:TileEntityTransferNodeLiquid.java

示例2: emptyTankIntoContainer

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
public static boolean emptyTankIntoContainer(IFluidHandler tank, EntityPlayer player, FluidStack tankLiquid)
{
    ItemStack stack = player.getCurrentEquippedItem();

    if(!FluidContainerRegistry.isEmptyContainer(stack))
        return false;
    
    ItemStack filled = FluidContainerRegistry.fillFluidContainer(tankLiquid, stack);
    FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(filled);

    if(liquid == null || filled == null)
        return false;
    
    tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);

    if(!player.capabilities.isCreativeMode)
    {
        if(stack.stackSize == 1)
            player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
        else if(player.inventory.addItemStackToInventory(filled))
            stack.stackSize--;
        else
            return false;
    }
    
    player.inventoryContainer.detectAndSendChanges();        
    return true;
}
 
开发者ID:4Space,项目名称:4Space-5,代码行数:29,代码来源:FluidUtils.java

示例3: 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

示例4: update

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void update()
{
	if(!world().isRemote)
	{
		if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
		{
			FluidStack last = getSaveShare();

			if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getFluid() == last.getFluid())) || (last == null && lastWrite != null))
			{
				lastWrite = last;
				MekanismUtils.saveChunk(tile());
			}
		}

		IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(tile());

		for(ForgeDirection side : getConnections(ConnectionType.PULL))
		{
			if(connectedAcceptors[side.ordinal()] != null)
			{
				IFluidHandler container = connectedAcceptors[side.ordinal()];

				if(container != null)
				{
					FluidStack received = container.drain(side.getOpposite(), getPullAmount(), false);

					if(received != null && received.amount != 0)
					{
						container.drain(side.getOpposite(), takeFluid(received, true), true);
					}
				}
			}
		}
	}

	super.update();
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:40,代码来源:PartMechanicalPipe.java

示例5: drain

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
	IFluidHandler handler = this.getFluidTankInDirection(ForgeDirection.UP);

	FluidStack stack = null;
	if(handler != null && handler.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid != null && 
			fluidTank.getFluid() != null && fluidTank.getFluid().getFluidID() ==
			handler.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.getFluidID()) {

		stack = handler.drain(from, maxDrain, doDrain);
	}
	
	if(stack != null)
		return stack;

	FluidStack stack2 = super.drain(from, maxDrain - (stack != null ? stack.amount : 0), doDrain);

	if(stack != null && stack2 != null)
		stack2.amount += stack.amount;

	
	if(stack2 != null && doDrain) {
		fluidChanged = true;
	}
	checkForUpdate();
	
	
	return stack2;
}
 
开发者ID:zmaster587,项目名称:AdvancedRocketry,代码行数:30,代码来源:TileFluidTank.java

示例6: updateEntity

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void updateEntity() {
	super.updateEntity();

	//Move a stack of items
	if(rocket != null ) {
		List<TileEntity> tiles = rocket.storage.getFluidTiles();
		boolean foundStack = false;
		boolean rocketContainsItems = false;

		//Function returns if something can be moved
		for(TileEntity tile : tiles) {
			IFluidHandler handler = (IFluidHandler)tile;

			//See if we have anything to fill because redstone output
			FluidStack stack = handler.drain(ForgeDirection.DOWN, 1, false);
			if(stack == null || handler.fill(ForgeDirection.UP, stack, false) > 0)
				rocketContainsItems = true;

			stack = fluidTank.drain(fluidTank.getCapacity(), false);
			if(stack != null && stack.amount > 0)
				fluidTank.drain(handler.fill(ForgeDirection.UP, stack, true), true);
		}

		//Update redstone state
		setRedstoneState(!rocketContainsItems);
	}
}
 
开发者ID:zmaster587,项目名称:AdvancedRocketry,代码行数:29,代码来源:TileRocketFluidLoader.java

示例7: updateEntity

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void updateEntity() {
	super.updateEntity();

	//Move a stack of items
	if(rocket != null ) {
		List<TileEntity> tiles = rocket.storage.getFluidTiles();
		boolean rocketContainsItems = false;
		//Function returns if something can be moved
		for(TileEntity tile : tiles) {
			IFluidHandler handler = (IFluidHandler)tile;

			if(handler.drain(ForgeDirection.DOWN, 1, false) != null)
				rocketContainsItems = true;
			
			FluidStack stack = fluidTank.getFluid();
			if(stack == null) {
				this.fill(ForgeDirection.UNKNOWN, handler.drain(ForgeDirection.DOWN, fluidTank.getCapacity(), true), true);
			}
			else {
				stack = stack.copy();
				stack.amount = fluidTank.getCapacity() - fluidTank.getFluidAmount();
				
				if(stack.amount != 0) {
					this.fill(ForgeDirection.UNKNOWN, handler.drain(ForgeDirection.DOWN, stack, true), true);
				}
			}
		}

		//Update redstone state
		setRedstoneState(!rocketContainsItems);

	}
}
 
开发者ID:zmaster587,项目名称:AdvancedRocketry,代码行数:35,代码来源:TileRocketFluidUnloader.java

示例8: canProcessRecipe

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public boolean canProcessRecipe(IRecipe recipe) {
	if(!fluidInPorts.isEmpty()) {
		IFluidHandler fluidHandler = fluidInPorts.get(0);
		FluidStack fluid;
		if(fluidHandler == null || (fluid = fluidHandler.drain(ForgeDirection.UNKNOWN, new FluidStack(FluidRegistry.WATER, 100), false)) == null 
				|| fluid.amount != 100)
			return false;
	}

	return super.canProcessRecipe(recipe);
}
 
开发者ID:zmaster587,项目名称:AdvancedRocketry,代码行数:13,代码来源:TileRollingMachine.java

示例9: powerUpdate

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void powerUpdate() {
	for(int i = 0; i < 6; i++){
		if(neighbors[i] == null) continue;
		IFluidHandler n = neighbors[i];
		EnumFacing face = faces[i].getOpposite();
		FluidStack available = n.drain(face, Integer.MAX_VALUE, false);
		if(available != null && available.getFluid() != null && available.amount > 0){
			int delta = transmitFluidToConsumers(available,PowerRequest.LOW_PRIORITY);
			n.drain(face, delta, true);
		}
	}
}
 
开发者ID:cyanobacterium,项目名称:PowerAdvantageAPI,代码行数:14,代码来源:TerminalFluidPipeTileEntity.java

示例10: fillContainerFromHandler

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
public static boolean fillContainerFromHandler(World world, IFluidHandler handler, EntityPlayer player, FluidStack tankFluid) {

		ItemStack container = player.getCurrentEquippedItem();

		if (FluidContainerRegistry.isEmptyContainer(container)) {
			ItemStack returnStack = FluidContainerRegistry.fillFluidContainer(tankFluid, container);
			FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(returnStack);

			if (fluid == null || returnStack == null) {
				return false;
			}
			if (!player.capabilities.isCreativeMode) {
				if (container.stackSize == 1) {
					container = container.copy();
					player.inventory.setInventorySlotContents(player.inventory.currentItem, returnStack);
				} else if (!player.inventory.addItemStackToInventory(returnStack)) {
					return false;
				}
				handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
				container.stackSize--;

				if (container.stackSize <= 0) {
					container = null;
				}
			} else {
				handler.drain(ForgeDirection.UNKNOWN, fluid.amount, true);
			}
			return true;
		}
		return false;
	}
 
开发者ID:PaleoCrafter,项目名称:R0b0ts,代码行数:32,代码来源:FluidHelper.java

示例11: emptyTank

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
private boolean emptyTank(ChunkPosition pos, boolean simulate){
    if(drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) {
        drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank");
        abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if(te instanceof IFluidHandler) {
            IFluidHandler tank = (IFluidHandler)te;
            for(int i = 0; i < 6; i++) {
                if(((ISidedWidget)widget).getSides()[i]) {
                    FluidStack importedFluid = tank.drain(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false);
                    if(importedFluid != null && ((ILiquidFiltered)widget).isFluidValid(importedFluid.getFluid())) {
                        int filledAmount = drone.getTank().fill(importedFluid, false);
                        if(filledAmount > 0) {
                            if(((ICountWidget)widget).useCount()) filledAmount = Math.min(filledAmount, getRemainingCount());
                            if(!simulate) {
                                decreaseCount(drone.getTank().fill(tank.drain(ForgeDirection.getOrientation(i), filledAmount, true), true));
                            }
                            return true;
                        }
                    }
                }
            }
            drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos);
        } else if(!((ICountWidget)widget).useCount() || getRemainingCount() >= 1000) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.getWorld().getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ));
            if(fluid != null && ((ILiquidFiltered)widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.getWorld(), pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ)) {
                if(!simulate) {
                    decreaseCount(1000);
                    drone.getTank().fill(new FluidStack(fluid, 1000), true);
                    drone.getWorld().setBlockToAir(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
                }
                return true;
            }
        }
        return false;
    }
}
 
开发者ID:MineMaarten,项目名称:PneumaticCraft,代码行数:40,代码来源:DroneAILiquidImport.java

示例12: onNexusImportCall

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void onNexusImportCall(TileEntityTransporter nexus)
{
    TileEntity tile = nexus.getAttachedTileEntity();
    ForgeDirection nexusOrientation = ForgeDirection.getOrientation(nexus.getBlockMetadata());

    if (tile != null && tile instanceof IFluidHandler)
    {
        IFluidHandler inv = (IFluidHandler) tile;

        FluidTankInfo[] tankInfo = nexus.getTankInfo(nexusOrientation);
        FluidStack nexusFluid = tankInfo[0].fluid;

        FluidStack drained = null;

        if (nexusFluid == null) // no fluid
        {
            drained = inv.drain(nexusOrientation, nexus.isHighCapacity() ?
                    ConfigValues.highCapacityFluidPickup :
                    ConfigValues.standardFluidPickup, true);

        } else // has fluid
        {
            int remainingSpace = tankInfo[0].capacity - nexusFluid.amount;
            if (remainingSpace != 0)
            {
                int toDrain = Math.min(remainingSpace, nexus.isHighCapacity() ?
                        ConfigValues.highCapacityFluidPickup :
                        ConfigValues.standardFluidPickup);
                drained = inv.drain(nexusOrientation, new FluidStack(nexusFluid.getFluid(), toDrain), true);
            }
        }

        if (drained != null && drained.amount > 0)
        {
            nexus.fill(nexusOrientation, drained, true);
            nexus.resetCounter();
            return;
        }
    }

    attemptTeleport(nexus, nexusOrientation);

}
 
开发者ID:samvbeckmann,项目名称:network,代码行数:45,代码来源:ItemFluidCore.java

示例13: 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

示例14: consumeItems

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void consumeItems(IRecipe recipe) {
	super.consumeItems(recipe);
	IFluidHandler fluidHandler = fluidInPorts.get(0);
	fluidHandler.drain(ForgeDirection.UNKNOWN, new FluidStack(FluidRegistry.WATER, 100), true);
}
 
开发者ID:zmaster587,项目名称:AdvancedRocketry,代码行数:7,代码来源:TileRollingMachine.java

示例15: onUsingTick

import net.minecraftforge.fluids.IFluidHandler; //导入方法依赖的package包/类
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
            
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
 
开发者ID:Tonius,项目名称:SimplyJetpacks,代码行数:50,代码来源:ItemJetpackFueller.java


注:本文中的net.minecraftforge.fluids.IFluidHandler.drain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。