當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。