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


Java FluidUtil.getFluidHandler方法代码示例

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


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

示例1: doFluidInteraction

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) {
    ItemStack stack = player.getHeldItem(hand);
    IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack);
    if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) {
        int capacity = stackHandler.getTankProperties()[0].getCapacity();
        IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face);
        PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory);
        FluidActionResult result = isInserting ?
                FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) :
                FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player);
        if (result.isSuccess()) {
            player.setHeldItem(hand, result.getResult());
            return true;
        }
    }
    return false;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:18,代码来源:FluidUtils.java

示例2: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if(!worldIn.isRemote) {
        TileEntity te = worldIn.getTileEntity(pos);
        if(te != null && te instanceof TileFluidTank) {
            ItemStack activeHand = playerIn.getHeldItem(hand);
            if(!activeHand.isEmpty() && FluidUtil.getFluidHandler(activeHand) !=  null) {
                FluidTank ft = ((TileFluidTank) te).getTank();
                boolean canFillPrev = ft.canFill();
                boolean canDrainPrev = ft.canDrain();
                ft.setCanFill(true);
                ft.setCanDrain(true);
                try {
                    FluidUtil.interactWithFluidHandler(playerIn, hand, ft);
                } finally {
                    ft.setCanFill(canFillPrev);
                    ft.setCanDrain(canDrainPrev);
                }
                return true;
            }
            playerIn.openGui(ModularMachinery.MODID, CommonProxy.GuiType.TANK_INVENTORY.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
    }
    return true;
}
 
开发者ID:HellFirePvP,项目名称:ModularMachinery,代码行数:26,代码来源:BlockFluidOutputHatch.java

示例3: onItemUse

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
	if (world.isRemote)
		return null;
	IFluidHandler h = FluidUtil.getFluidHandler(world, pos, side);
	if (h != null) {
		for (Entry<FluidStack, ItemStack> e : fluidToItem.entrySet()) {
			FluidStack drain = h.drain(new FluidStack(e.getKey(), e.getKey().amount), false);
			if (e.getKey().isFluidStackIdentical(drain)) {
				h.drain(drain, true);
				ItemStack s = e.getValue().copy();
				stack.shrink(1);
				player.setHeldItem(hand, stack);
				if (!player.inventory.addItemStackToInventory(s)) {
					InventoryHelper.spawnItemStack(world, player.posX, player.posY, player.posZ, s);
				}
				player.inventoryContainer.detectAndSendChanges();
				return EnumActionResult.SUCCESS;
			}
		}
	}
	return null;
}
 
开发者ID:tom5454,项目名称:Toms-Mod,代码行数:24,代码来源:TMResource.java

示例4: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldStack = player.getHeldItem(hand);
    ItemStack cauldron = getDrops(world, pos, state, 0).get(0);

    if (player.isSneaking() && (player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty())) {
        this.onBlockDestroyedByPlayer(world, pos, state);
        InventoryHandlerHelper.giveItem(player, hand, cauldron);
        world.setBlockToAir(pos);
    }
    TileFluidTank tank = new TileFluidTank(0);
    if (cauldron.getTagCompound() != null) {
        tank.readFromNBT(cauldron.getTagCompound());
    }

    if (removeDye(world, pos, player, hand, heldStack, tank)) {
        return true;
    }

    //Fluid handling
    FluidUtil.interactWithFluidHandler(player, hand, world, pos, facing);

    return FluidUtil.getFluidHandler(heldStack) != null;
}
 
开发者ID:GirafiStudios,项目名称:Culinary-Cultivation,代码行数:25,代码来源:BlockModCauldron.java

示例5: fillWithRain

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public void fillWithRain(World world, BlockPos pos) {
    if (world.rand.nextInt(10) == 1) {
        IFluidHandler handler = FluidUtil.getFluidHandler(world, pos, null);
        ItemStack cauldron = getDrops(world, pos, world.getBlockState(pos), 0).get(0);
        TileFluidTank tank = new TileFluidTank(0);
        tank.readFromNBT(NBTHelper.getTag(cauldron));

        float temperature = world.getBiome(pos).getFloatTemperature(pos);
        if (world.getBiomeProvider().getTemperatureAtHeight(temperature, pos.getY()) >= 0.15F) {

            if ((tank.getFluidAmount() == 0 || tank.getFluid() != null && tank.getFluid().getFluid() == FluidRegistry.WATER) && tank.getFluidAmount() < Fluid.BUCKET_VOLUME) {
                if (handler != null) {
                    handler.fill(new FluidStack(FluidRegistry.WATER, 250), true);
                }
            }
        }
    }
}
 
开发者ID:GirafiStudios,项目名称:Culinary-Cultivation,代码行数:20,代码来源:BlockModCauldron.java

示例6: dumpContainer

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
 * Drains a filled container and places the fluid.
 * 
 * RETURN new item stack that has been drained after placing in world if it works null otherwise
 */
public static ItemStack dumpContainer(World world, BlockPos pos, ItemStack stackIn) {
  //    BlockSourceImpl blocksourceimpl = new BlockSourceImpl(world, pos);
  ItemStack dispensedStack = stackIn.copy();
  dispensedStack.setCount(1);
  IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(dispensedStack);
  if (fluidHandler == null) {
    return null;
  }
  FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false);
  if (fluidStack != null && fluidStack.amount >= Fluid.BUCKET_VOLUME) {
    //      FluidActionResult placeResult = FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack);
    if (FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack).isSuccess()) {
      //http://www.minecraftforge.net/forum/topic/56265-1112-fluidhandler-capability-on-buckets/
      fluidHandler.drain(Fluid.BUCKET_VOLUME, true);
      ItemStack returnMe = fluidHandler.getContainer();
      //        stackIn.deserializeNBT(returnMe.serializeNBT());
      return returnMe;
    }
  }
  return null;
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:27,代码来源:UtilFluid.java

示例7: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  // TODO: display text if any
  boolean success = false;
  TileEntityItemCable te = (TileEntityItemCable) world.getTileEntity(pos);
  if (te != null && world.isRemote == false) {
    String msg = null;
    if (te.getLabelText() != "") {
      msg = te.getLabelText();
      if (te.getIncomingStrings() != "") {
        msg += " (" + UtilChat.lang("cyclic.item.flowing") + te.getIncomingStrings() + ")";
      }
    }
    else {
      msg = UtilChat.lang("cyclic.item.empty");
    }
    UtilChat.sendStatusMessage(player, msg);
    success = true;
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || FluidUtil.getFluidHandler(player.getHeldItem(hand)) != null || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:23,代码来源:BlockItemCable.java

示例8: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  // check the TE
  TileEntityFluidCable te = (TileEntityFluidCable) world.getTileEntity(pos);
  boolean success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
  if (te != null) {
    if (world.isRemote == false) { //server side
      FluidStack fs = te.getCurrentFluidStack();
      String msg = null;
      if (fs != null) {
        // UtilChat.lang("cyclic.fluid.amount") +
        msg = fs.getLocalizedName();
        if (te.getIncomingStrings() != "") {
          msg += " (" + UtilChat.lang("cyclic.fluid.flowing") + te.getIncomingStrings() + ")";
        }
      }
      else {
        msg = UtilChat.lang("cyclic.fluid.empty");
      }
      UtilChat.sendStatusMessage(player, msg);
    }
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || FluidUtil.getFluidHandler(player.getHeldItem(hand)) != null || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:26,代码来源:BlockFluidCable.java

示例9: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  // check the TE
  TileEntityBucketStorage te = (TileEntityBucketStorage) world.getTileEntity(pos);
  boolean success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
  if (te != null) {
    if (world.isRemote == false) { //server side
      FluidStack fs = te.getCurrentFluidStack();
      if (fs != null) {
        String amtStr = fs.amount + " / " + te.getCapacity() + " ";
        UtilChat.sendStatusMessage(player, UtilChat.lang("cyclic.fluid.amount") + amtStr + fs.getLocalizedName());
      }
      else {
        UtilChat.sendStatusMessage(player, UtilChat.lang("cyclic.fluid.empty"));
      }
    }
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || FluidUtil.getFluidHandler(player.getHeldItem(hand)) != null || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:21,代码来源:BlockBucketStorage.java

示例10: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
 * with thanks and gratitude @KnightMiner https://github.com/KnightMiner/Ceramics/blob/1.11/src/main/java/knightminer/ceramics/blocks/BlockBarrel.java
 * 
 * 
 */
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
  // check the TE
  TileEntityHydrator te = (TileEntityHydrator) world.getTileEntity(pos);
  FluidStack bucket = FluidUtil.getFluidContained(player.getHeldItem(hand));
  boolean success = false;
  if (bucket == null || bucket.getFluid() == FluidRegistry.WATER) {//THEN let fluid insert happen
    success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
  }
  if (te != null) {
    if (!world.isRemote) {
      int currentFluid = te.getField(Fields.FLUID.ordinal());
      UtilChat.sendStatusMessage(player, UtilChat.lang("cyclic.fluid.amount") + currentFluid);
    }
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || FluidUtil.getFluidHandler(player.getHeldItem(hand)) != null || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
开发者ID:PrinceOfAmber,项目名称:Cyclic,代码行数:24,代码来源:BlockHydrator.java

示例11: update

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public void update()
{
    ItemStack stack = inventory.get(0);
    if(!stack.isEmpty() && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN))
    {
        IFluidHandlerItem fh = FluidUtil.getFluidHandler(stack);
        FluidStack fluid = FluidUtil.getFluidContained(stack);
        if(fh != null && fluid != null)
        {
            int amountFilled = fluidTanks[0].fillInternal(fluid, false);
            FluidStack amountDrained = fh.drain(amountFilled, true);

            if(amountDrained != null && amountDrained.amount > 0)
            {
                fluidTanks[0].fillInternal(amountDrained, true);
                inventory.set(0, fh.getContainer());
            }
        }
    }
    super.update();
}
 
开发者ID:Lumaceon,项目名称:ClockworkPhase2,代码行数:23,代码来源:TileClockworkCrystallizer.java

示例12: getFluidPredicate

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public static Predicate<ItemStack> getFluidPredicate(Fluid fluid) {
	return new Predicate<ItemStack>() {
		@Override
		public boolean test(ItemStack itemStack) {
			IFluidHandlerItem handler = FluidUtil.getFluidHandler(itemStack);
			if (handler == null) {
				return false;
			}
			for (IFluidTankProperties properties : handler.getTankProperties()) {
				FluidStack stack = properties.getContents();
				if (stack != null && stack.getFluid() == fluid) {
					return true;
				}
			}
			return false;
		}
	};
}
 
开发者ID:Aroma1997,项目名称:BetterChests,代码行数:19,代码来源:UpgradeCobbestone.java

示例13: getLiquidProvider

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public static IFluidHandler getLiquidProvider(ItemStack tablet) {
    BlockPos pos = getLiquidProvidingLocation(tablet);
    if (pos != null) {
        int dimension = getLiquidProvidingDimension(tablet);
        return FluidUtil.getFluidHandler(DimensionManager.getWorld(dimension), pos, null);
    }
    return null;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:9,代码来源:ItemAmadronTablet.java

示例14: onBlockActivated

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumHand hand, EnumFacing side, float par7, float par8,
        float par9) {

    ItemStack current = entityplayer.getHeldItem(hand);
    TileEntity tile = world.getTileEntity(pos);

    if (tile instanceof TileEntityTank) {
    	TileEntityTank tank = (TileEntityTank) tile;
    	if (ItemStackTools.isValid(current)) {
        	if(ToolUtil.isToolEquipped(entityplayer, hand)){
        		return ToolUtil.breakBlockWithTool(this, world, pos, entityplayer, hand);
        	}            

        	IFluidHandlerItem containerFluidHandler = FluidUtil.getFluidHandler(current);
        	if (containerFluidHandler != null)
        	{
        		if(FluidUtil.interactWithFluidHandler(entityplayer, hand, world, pos, side)){
        			return true;
        		}
        	}
    	}
    	
        if(!world.isRemote){
    		if(tank.tank !=null){
    			FluidStack fluid = tank.tank.getFluid();
    			if(fluid == null){
    				ChatUtil.sendNoSpam(entityplayer, "Fluid: (Empty) 0 mB / "+tank.tank.getCapacity()+" mB");
    			}
    			else ChatUtil.sendNoSpam(entityplayer, "Fluid: ("+fluid.getLocalizedName()+") "+fluid.amount+" mB / "+tank.tank.getCapacity()+" mB");
    		}
		}
		return true;
    } 
    return false;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:37,代码来源:BlockTank.java

示例15: getRemainingItems

import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
	NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv);
	for (int i = 0; i < height * width; i++)
	{
		ItemStack stack = inv.getStackInSlot(i);
		NonNullList<Ingredient> matchedIngredients = this.input;
		if (matchedIngredients.get(i) instanceof IngredientFluidStack)
		{
			if (!stack.isEmpty())
			{
				ItemStack copy = stack.copy();
				copy.setCount(1);
				remains.set(i, copy);
			}
			IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i));
			if (handler != null)
			{
				FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid();
				handler.drain(fluid.amount, true);
				remains.set(i, handler.getContainer());
			}
		}
	}
	return remains;
}
 
开发者ID:TeamWizardry,项目名称:Wizardry,代码行数:28,代码来源:RecipeShapedFluid.java


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