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


Java FluidTank.drain方法代码示例

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


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

示例1: drain

import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
@Override
@Nullable
public FluidStack drain(FluidStack resource, boolean doDrain) {
  if (ItemStackTools.getStackSize(container) != 1) {
    return null;
  }
  FluidTank tank = loadTank(container);
  if(tank == null)return null;
  
  boolean infi = container.getMetadata() == TankType.CREATIVE.getMeta();
  if(infi){
	  return resource.copy();
  }
  FluidStack ret = tank.drain(resource, doDrain);
  saveTank(container, tank);
  return ret;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:18,代码来源:ItemBlockTank.java

示例2: consumeFluids

import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
public void consumeFluids(ArrayList<FluidStack> fluids, FluidMixingRecipe recipe) {
    for (FluidTank tank : tanks) {
        FluidStack tankFluid = tank.getFluid();
        boolean doContinue = true;
        for (int j = 0; j < recipe.inputs.size() && doContinue; j++) {
            FluidStack recipeFluid = recipe.inputs.get(j);
            if (recipeFluid != null && tankFluid != null && recipeFluid.getFluid() == tankFluid.getFluid()) {
                doContinue = false;
                tank.drain(recipeFluid.amount,true);
            }
        }
    }
}
 
开发者ID:DaedalusGame,项目名称:Soot,代码行数:14,代码来源:TileEntityMixerBottomImproved.java

示例3: tryFillContainer

import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
/**
 * This tries to fill the given container (at inventory[slot]) with fluid from the specified tank
 * If successful, it places the resulting filled container in inventory[slot]
 * 
 * Note: this deals with the issue where FluidContainerRegistry.fillFluidContainer() returns null for failed fills
 * 
 * @param tank		The tank to take the fluid from
 * @param liquid   The type of liquid in that tank (the calling method will normally have checked this already)
 * @param inventory
 * @param slot
 * @param canisterType  The type of canister to return, if it's a canister being filled (pre-matched with the liquid type)
 * 
 */
   public static void tryFillContainer(FluidTank tank, FluidStack liquid, ItemStack[] inventory, int slot, Item canisterType)
{
	ItemStack slotItem = inventory[slot];
	boolean isCanister = slotItem.getItem() instanceof ItemCanisterGeneric;
	final int amountToFill = Math.min(liquid.amount, isCanister ? slotItem.getItemDamage() - 1 : FluidContainerRegistry.BUCKET_VOLUME);

	if (amountToFill <= 0 || (isCanister && slotItem.getItem() != canisterType && slotItem.getItemDamage() != ItemCanisterGeneric.EMPTY))
		return;
	
	if (isCanister)
	{
		inventory[slot] = new ItemStack(canisterType, 1, slotItem.getItemDamage() - amountToFill);
		tank.drain(amountToFill, true);
	}
	else if (amountToFill == FluidContainerRegistry.BUCKET_VOLUME)
	{
		inventory[slot] = FluidContainerRegistry.fillFluidContainer(liquid, inventory[slot]);

		if (inventory[slot] == null)
		{
			//Failed to fill container: restore item that was there before
			inventory[slot] = slotItem;
		}
		else
		{
			tank.drain(amountToFill, true);
		}
	}
}
 
开发者ID:4Space,项目名称:4Space-5,代码行数:43,代码来源:FluidUtil.java

示例4: consumeIngredients

import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
public boolean consumeIngredients(FluidTank input) {
	if (!recipe.apply(input.getFluid())) return false;
	return input.drain(recipe.getAmount(), true)!=null;
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:5,代码来源:PotStillRecipe.java

示例5: update

import net.minecraftforge.fluids.FluidTank; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void update(TileBarrel barrel) {
	// Fluids on top.
	if (barrel.getTank().getFluid() != null) {
		FluidTank tank = barrel.getTank();
		if (tank.getFluid().amount != tank.getCapacity())
			return;

		Fluid fluidInBarrel = tank.getFluid().getFluid();

		BlockPos barrelPos = barrel.getPos();
		BlockPos pos = new BlockPos(barrelPos.getX(), barrelPos.getY() + 1, barrelPos.getZ());
		Block onTop = barrel.getWorld().getBlockState(pos).getBlock();

		Fluid fluidOnTop = null;
		if (onTop instanceof BlockLiquid) {
			fluidOnTop = onTop.getMaterial(barrel.getWorld().getBlockState(pos)) == Material.WATER
					? FluidRegistry.WATER : FluidRegistry.LAVA;
		}

		if (onTop != null && onTop instanceof IFluidBlock) {
			fluidOnTop = ((BlockFluidBase) onTop).getFluid();
		}

		if (FluidOnTopRegistry.isValidRecipe(fluidInBarrel, fluidOnTop)) {
			ItemInfo info = FluidOnTopRegistry.getTransformedBlock(fluidInBarrel, fluidOnTop);
			tank.drain(tank.getCapacity(), true);
			barrel.setMode("block");
			PacketHandler.sendToAllAround(new MessageBarrelModeUpdate("block", barrel.getPos()), barrel);

			barrel.getMode().addItem(info.getItemStack(), barrel);

			return;
		}

		// Fluid transforming time!
		if (FluidTransformRegistry.containsKey(barrel.getTank().getFluid().getFluid().getName())) {
			List<FluidTransformer> transformers = FluidTransformRegistry
					.getFluidTransformers(barrel.getTank().getFluid().getFluid().getName());

			boolean found = false;
			for (int radius = 0; radius <= 2; radius++) {
				for (FluidTransformer transformer : transformers) {
					if (!BarrelLiquidBlacklistRegistry.isBlacklisted(barrel.getTier(), transformer.getOutputFluid())
							&& (Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
									barrel.getPos().add(0, -1, 0), barrel.getWorld(), radius)
									|| Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
											barrel.getPos(), barrel.getWorld(), radius))) {
						// Time to start the process.
						FluidStack fstack = tank.getFluid();
						tank.setFluid(null);

						barrel.setMode("fluidTransform");
						BarrelModeFluidTransform mode = (BarrelModeFluidTransform) barrel.getMode();

						mode.setTransformer(transformer);
						mode.setInputStack(fstack);
						mode.setOutputStack(FluidRegistry.getFluidStack(transformer.getOutputFluid(), 1000));

						PacketHandler.sendNBTUpdate(barrel);
						found = true;
					}
				}
				if (found) break;
			}
		}
	}
}
 
开发者ID:MikeLydeamore,项目名称:ExNihiloAdscensio,代码行数:70,代码来源:BarrelModeFluid.java


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