Java 类net.minecraftforge.fluids.FluidUtil 实例源码

项目:pnc-repressurized    文件:EventHandlerPneumaticCraft.java   
@SubscribeEvent
public void onFillBucket(FillBucketEvent event) {
    RayTraceResult rtr = event.getTarget();
    if (rtr != null) {
        Block b = event.getWorld().getBlockState(rtr.getBlockPos()).getBlock();
        if (b instanceof IFluidBlock) {
            Fluid fluid = ((IFluidBlock) b).getFluid();
            ItemStack filled = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000));
            if (!filled.isEmpty()) {
                event.setFilledBucket(FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)));
                event.getWorld().setBlockToAir(rtr.getBlockPos());
                event.setResult(Result.ALLOW);
                if (TileEntityRefinery.isInputFluidValid(fluid, 4) && event.getEntityPlayer() instanceof EntityPlayerMP) {
                    AdvancementTriggers.OIL_BUCKET.trigger((EntityPlayerMP) event.getEntityPlayer());
                }
            }
        }
    }
}
项目:pnc-repressurized    文件:FluidUtils.java   
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;
}
项目:pnc-repressurized    文件:TileEntityBase.java   
public void autoExportLiquid() {
    if (hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
        IFluidHandler handler = getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
        FluidStack toDrain = handler.drain(1000, false);
        if (toDrain != null && toDrain.amount > 0) {
            for (EnumFacing d : EnumFacing.VALUES) {
                TileEntity te = getTileCache()[d.ordinal()].getTileEntity();
                if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite())) {
                    IFluidHandler destHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite());
                    FluidStack sent = FluidUtil.tryFluidTransfer(destHandler, handler, toDrain, true);
                    toDrain.amount -= sent == null ? 0 : sent.amount;
                    if (toDrain.amount <= 0) break;
                }
            }
        }
    }
}
项目:Metalworks    文件:Registry.java   
@SubscribeEvent
public static void registerGeoBurnables(RegistryEvent.Register<IGeoburnable> event){
    IForgeRegistry<IGeoburnable> reg = event.getRegistry();
    reg.register(new BlockGeoburnable(Blocks.MAGMA, 40, 1));
    reg.register(new BlockGeoburnable(Blocks.FIRE, 80, 2){
        @Override
        public ItemStack getJEIIcon() {
            return new ItemStack(Items.FLINT_AND_STEEL);
        }
    });
    reg.register(new BlockGeoburnable(Blocks.LAVA, 160, 3){
        @Override
        public ItemStack getJEIIcon() {
            return FluidUtil.getFilledBucket(new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME));
        }
    });
}
项目:customstuff4    文件:BlockMixin.java   
private boolean interactWithFluidItem(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing)
{
    if (getContent().canInteractWithFluidItem.get(getSubtype(state)).orElse(true))
    {
        TileEntity tile = worldIn.getTileEntity(pos);
        if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing))
        {
            if (worldIn.isRemote)
            {
                return true;
            }

            if (FluidUtil.interactWithFluidHandler(playerIn, hand, worldIn, pos, facing))
            {
                playerIn.inventoryContainer.detectAndSendChanges();
                return true;
            }
        }
    }
    return false;
}
项目:ModularMachinery    文件:BlockFluidOutputHatch.java   
@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;
}
项目:ModularMachinery    文件:BlockFluidInputHatch.java   
@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;
}
项目:Wizardry    文件:RecipeManaSyringe.java   
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
    boolean foundSyringe = false;
    boolean foundBucket = false;

    ItemStack bucket = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_MANA.getFluid(), 1));

    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) {
                foundSyringe = true;
        }
        if (ItemStack.areItemStacksEqual(bucket, stack))
            foundBucket = true;
    }
    return foundSyringe && foundBucket;
}
项目:Wizardry    文件:RecipeSteroidSyringe.java   
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
    boolean foundSyringe = false;
    boolean foundMana = false;
    boolean foundNacre = false;
    boolean foundLava = false;
    boolean foundDevilDust = false;

    ItemStack mana = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_MANA.getFluid(), 1));
    ItemStack nacre = FluidUtil.getFilledBucket(new FluidStack(ModBlocks.FLUID_NACRE.getFluid(), 1));

    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack.getItem() == ModItems.SYRINGE && stack.getItemDamage() == 0) foundSyringe = true;
        if (ItemStack.areItemStacksEqual(mana, stack)) foundMana = true;
        if (ItemStack.areItemStacksEqual(nacre, stack)) foundNacre = true;
        if (stack.getItem() == Items.LAVA_BUCKET) foundLava = true;
        if (stack.getItem() == ModItems.DEVIL_DUST) foundDevilDust = true;
    }
    return foundSyringe && foundMana && foundDevilDust && foundLava && foundNacre;
}
项目:Toms-Mod    文件:TMResource.java   
@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;
}
项目:ExNihiloAdscensio    文件:TileCrucible.java   
public boolean onBlockActivated(ItemStack stack, EntityPlayer player) {
    if (stack == null)
        return false;

    //Bucketing out the fluid.
    if (stack != null && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
        boolean result = FluidUtil.interactWithFluidHandler(stack, tank, player);
        if (result) {
            PacketHandler.sendNBTUpdate(this);
        }
        return true;
    }

    //Adding a meltable.
    ItemStack addStack = stack.copy(); addStack.stackSize = 1;
    ItemStack insertStack = itemHandler.insertItem(0, addStack, true);
    if (!ItemStack.areItemStacksEqual(addStack, insertStack)) {
        itemHandler.insertItem(0, addStack, false);
        stack.stackSize--;
        PacketHandler.sendNBTUpdate(this);
        return true;
    }
    return true;
}
项目:Culinary-Cultivation    文件:BlockModCauldron.java   
@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;
}
项目:Culinary-Cultivation    文件:BlockModCauldron.java   
@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);
                }
            }
        }
    }
}
项目:Cyclic    文件:UtilFluid.java   
/**
 * 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;
}
项目:Cyclic    文件:FluidsRegistry.java   
public static void addPoisonRecipe() {
  try {
    //dont do this, FluidsRegistry.fluid_poison , some other mod might have added poison first, then we get rejected --> null
    Fluid poison = FluidRegistry.getFluid(FluidsRegistry.fluid_poison.getName());
    if (poison == null) {
      return;
    }
    RecipeRegistry.addShapelessRecipe(FluidUtil.getFilledBucket(new FluidStack(poison, Fluid.BUCKET_VOLUME)),
        FluidUtil.getFilledBucket(new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME)),
        Items.SPIDER_EYE, Items.POISONOUS_POTATO, Items.SUGAR);
  }
  catch (Exception e) {
    //if another mod adds poison fluid (such as biomes o plenty), then our fluid gets rejected
    ModCyclic.logger.error("Error: Cyclic failed to add recipe for Poison Bucket");
    e.printStackTrace();
  }
}
项目:Cyclic    文件:BlockItemCable.java   
@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);
}
项目:Cyclic    文件:BlockFluidCable.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
  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);
}
项目:Cyclic    文件:BlockFluidPump.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
  TileEntityBaseMachineFluid te = (TileEntityBaseMachineFluid) world.getTileEntity(pos);
  boolean success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
  if (te != null) {
    if (world.isRemote == false) { //server side
      String message = null;
      FluidStack fs = te.getCurrentFluidStack();
      if (fs != null) {
        String amtStr = fs.amount + " / " + te.getCapacity() + " ";
        message = UtilChat.lang("cyclic.fluid.amount") + amtStr + fs.getLocalizedName();
      }
      else {
        message = UtilChat.lang("cyclic.fluid.empty");
      }
      String powered = world.isBlockPowered(pos) ? "cyclic.redstone.on" : "cyclic.redstone.off";
      UtilChat.sendStatusMessage(player, message + "; " + UtilChat.lang(powered));
    }
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
项目:Cyclic    文件:BlockBucketStorage.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
  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);
}
项目:Cyclic    文件:BlockFluidPlacer.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
  TileEntityBaseMachineFluid te = (TileEntityBaseMachineFluid) world.getTileEntity(pos);
  boolean success = FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
  if (te != null) {
    if (world.isRemote == false) { //server side
      String message = null;
      FluidStack fs = te.getCurrentFluidStack();
      if (fs != null) {
        String amtStr = fs.amount + " / " + te.getCapacity() + " ";
        message = UtilChat.lang("cyclic.fluid.amount") + amtStr + fs.getLocalizedName();
      }
      else {
        message = UtilChat.lang("cyclic.fluid.empty");
      }
      String powered = world.isBlockPowered(pos) ? "cyclic.redstone.on" : "cyclic.redstone.off";
      UtilChat.sendStatusMessage(player, message + "; " + UtilChat.lang(powered));
    }
  }
  // otherwise return true if it is a fluid handler to prevent in world placement
  return success || super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
项目:Cyclic    文件:BlockHydrator.java   
/**
 * 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);
}
项目:ClockworkPhase2    文件:TileClockworkCrystallizer.java   
@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();
}
项目:Hard-Science    文件:ModularTankBlock.java   
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) 
{
    // allow fluid handling logic to happen
    if(!world.isRemote && player.getHeldItem(hand).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null))
    {
        TileEntity te = world.getTileEntity(pos);
        if(te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
        {
            IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
            if(FluidUtil.interactWithFluidHandler(player, hand, fluidHandler))
                return true;
        }
    }
    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
项目:BetterChests    文件:UpgradeCobbestone.java   
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;
        }
    };
}
项目:BetterChests    文件:BlockBTank.java   
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack original = player.getHeldItem(hand);
    if (!original.isEmpty()) {
        ItemStack stack = original.copy();
        stack.setCount(1);
        TileEntity tank = getTileEntity(world, pos);
        if (tank instanceof TileEntityBTank) {
            IFluidHandler handler = ((TileEntityBTank) tank).getFluidHandler();
            FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
            if (!result.success) {
                result = FluidUtil.tryFillContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
            }
            if (result.success) {
                original.setCount(original.getCount() - 1);
                stack = InvUtil.putStackInInventory(result.result, player.inventory, true, false, false, null);
                if (!stack.isEmpty()) {
                    WorldUtil.dropItemsRandom(world, stack, player.getPosition());
                }
                return true;
            }
        }
    }
    return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
项目:pnc-repressurized    文件:JEI.java   
@Override
public void register(IModRegistry registry) {
    IJeiHelpers jeiHelpers = registry.getJeiHelpers();

    registry.addRecipes(BasicThermopneumaticProcessingPlantRecipe.recipes, ModCategoryUid.THERMO_PNEUMATIC);
    registry.addRecipes(PressureChamberRecipe.chamberRecipes, ModCategoryUid.PRESSURE_CHAMBER);
    registry.addRecipes(new JEIPlasticMixerCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.PLASTIC_MIXER);
    registry.addRecipes(new JEIRefineryCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.REFINERY);
    registry.addRecipes(new JEIEtchingAcidCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.ETCHING_ACID);
    registry.addRecipes(new JEICompressedIronCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.COMPRESSED_IRON_EXPLOSION);
    registry.addRecipes(new JEIUVLightBoxCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.UV_LIGHT_BOX);
    registry.addRecipes(AssemblyRecipe.drillRecipes, ModCategoryUid.ASSEMBLY_CONTROLLER);
    registry.addRecipes(AssemblyRecipe.laserRecipes, ModCategoryUid.ASSEMBLY_CONTROLLER);
    registry.addRecipes(AssemblyRecipe.drillLaserRecipes, ModCategoryUid.ASSEMBLY_CONTROLLER);
    registry.addRecipes(new JEIAmadronTradeCategory(jeiHelpers).getAllRecipes(), ModCategoryUid.AMADRON_TRADE);

    registry.handleRecipes(PressureChamberRecipe.class,
            JEIPressureChamberRecipeCategory.ChamberRecipeWrapper::new, ModCategoryUid.PRESSURE_CHAMBER);
    registry.handleRecipes(BasicThermopneumaticProcessingPlantRecipe.class,
            JEIThermopneumaticProcessingPlantCategory.ThermopneumaticRecipeWrapper::new, ModCategoryUid.THERMO_PNEUMATIC);
    registry.handleRecipes(AssemblyRecipe.class,
            JEIAssemblyControllerCategory.AssemblyRecipeWrapper::new, ModCategoryUid.ASSEMBLY_CONTROLLER);

    registry.addRecipeClickArea(GuiAssemblyController.class, 68, 75, 24, 17, ModCategoryUid.ASSEMBLY_CONTROLLER);
    registry.addRecipeClickArea(GuiPressureChamber.class, 100, 7, 40, 40, ModCategoryUid.PRESSURE_CHAMBER);
    registry.addRecipeClickArea(GuiRefinery.class, 47, 21, 27, 47, ModCategoryUid.REFINERY);
    registry.addRecipeClickArea(GuiThermopneumaticProcessingPlant.class, 30, 31, 48, 20, ModCategoryUid.THERMO_PNEUMATIC);

    registry.addRecipeCatalyst(new ItemStack(Itemss.AMADRON_TABLET), ModCategoryUid.AMADRON_TRADE);
    registry.addRecipeCatalyst(new ItemStack(Blockss.ASSEMBLY_CONTROLLER), ModCategoryUid.ASSEMBLY_CONTROLLER);
    registry.addRecipeCatalyst(FluidUtil.getFilledBucket(new FluidStack(Fluids.ETCHING_ACID, 1000)), ModCategoryUid.ETCHING_ACID);
    registry.addRecipeCatalyst(new ItemStack(Blockss.PLASTIC_MIXER), ModCategoryUid.PLASTIC_MIXER);
    registry.addRecipeCatalyst(new ItemStack(Blockss.PRESSURE_CHAMBER_WALL), ModCategoryUid.PRESSURE_CHAMBER);
    registry.addRecipeCatalyst(new ItemStack(Blockss.REFINERY), ModCategoryUid.REFINERY);
    registry.addRecipeCatalyst(new ItemStack(Blockss.THERMOPNEUMATIC_PROCESSING_PLANT), ModCategoryUid.THERMO_PNEUMATIC);
    registry.addRecipeCatalyst(new ItemStack(Blockss.UV_LIGHT_BOX), ModCategoryUid.UV_LIGHT_BOX);

    registry.addAdvancedGuiHandlers(new GuiTabHandler());
}
项目:pnc-repressurized    文件:IGWHandler.java   
/**
 * TODO: raise a PR to get this into IGW.  This adds support for Forge filled buckets (use "item/bucket/{fluid_name}")
 *
 * @param stack
 * @return
 */
static String getNameFromStack(ItemStack stack) {
    if (stack.getItem().getRegistryName().toString().equals("forge:bucketfilled")) {
        FluidStack fluidStack = FluidUtil.getFluidContained(stack);
        if (fluidStack != null) {
            return "item/bucket/" + fluidStack.getFluid().getName();
        } else {
            return "item/bucket";
        }
    }
    return stack.getUnlocalizedName().replace("tile.", "block/").replace("item.", "item/");
}
项目:pnc-repressurized    文件:CraftingRegistrator.java   
private static void scanForFluids(ShapedOreRecipe recipe) {
    for (int i = 0; i < recipe.getIngredients().size(); i++) {
        Ingredient ingredient = recipe.getIngredients().get(i);
        for (ItemStack stack : ingredient.getMatchingStacks()) {
            FluidStack fluid = FluidUtil.getFluidContained(stack);
            if (fluid != null) {
                ForgeRegistries.RECIPES.register(new RecipeFluid(recipe, i));
            }
        }
    }
}
项目:pnc-repressurized    文件:RecipeFluid.java   
public RecipeFluid(ShapedOreRecipe recipe, int fluidIndex) {
    super("fluid_recipe_" + recipeIndex++);
    this.recipe = recipe;
    Ingredient ingredient = recipe.getIngredients().get(fluidIndex);
    originalStack = ingredient.getMatchingStacks()[0];
    fluidStack = FluidUtil.getFluidContained(originalStack);
    if (fluidStack == null)
        throw new IllegalArgumentException("Recipe doesn't have fluid item at index " + fluidIndex + ". Item: " + originalStack);
    this.fluidIndex = fluidIndex;
}
项目:pnc-repressurized    文件:EventHandlerPneumaticCraft.java   
@SubscribeEvent
public void handleFuelEvent(FurnaceFuelBurnTimeEvent event) {
    FluidStack fluidStack = FluidUtil.getFluidContained(event.getItemStack());
    if (fluidStack != null) {
        int value = PneumaticCraftAPIHandler.getInstance().liquidFuels.getOrDefault(fluidStack.getFluid().getName(), -1);
        event.setBurnTime(value > 0 ? (int)(value * ConfigHandler.general.fuelBucketEfficiencyMultiplier) : -1);
    }
}
项目:pnc-repressurized    文件:ItemAmadronTablet.java   
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;
}
项目:pnc-repressurized    文件:FluidUtils.java   
/**
 * Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
 *
 * @param srcHandler fluid handler into which to place the fluid
 * @param destStack the fluid container item to extract from
 * @param returnedItems the modified fluid container after extraction
 * @return true if any fluid was moved, false otherwise
 */
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
    FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
    if (result.isSuccess()) {
        returnedItems.add(result.getResult());
        destStack.shrink(1);
        return true;
    } else {
        return false;
    }
}
项目:pnc-repressurized    文件:FluidUtils.java   
/**
 * Attempt to insert fluid into the given fluid handler from the given fluid container item.
 *
 * @param handler the handler to extract from
 * @param srcStack the fluid container item to insert to
 * @param returnedItems the modified fluid container after insertion
 * @return true if any fluid was moved, false otherwise
 */
public static boolean tryFluidInsertion(IFluidHandler handler, ItemStack srcStack, NonNullList<ItemStack> returnedItems) {
    FluidActionResult result = FluidUtil.tryEmptyContainer(srcStack, handler, 1000, null, true);
    if (result.isSuccess()) {
        returnedItems.add(result.getResult());
        srcStack.shrink(1);
        return true;
    } else {
        return false;
    }
}
项目:pnc-repressurized    文件:SemiBlockTransferGadget.java   
private void tryTransferFluid(TileEntity inputTE, TileEntity outputTE){
    IFluidHandler input = inputTE.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
    IFluidHandler output = outputTE.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite());
    if(input != null && output != null){
        FluidUtil.tryFluidTransfer(output, input, 100, true);
    }
}
项目:Soot    文件:ItemMug.java   
public CaskLiquid getCaskLiquid(ItemStack stack) {
    FluidStack fluid = FluidUtil.getFluidContained(stack);
    if(fluid != null) {
        CaskLiquid liquid = CaskManager.getFromFluid(fluid.getFluid());
        return liquid;
    }
    return null;
}
项目:Soot    文件:ItemMug.java   
@Override
public String getItemStackDisplayName(ItemStack stack) {
    FluidStack fluid = FluidUtil.getFluidContained(stack);
    if(fluid != null)
        return I18n.translateToLocalFormatted("item.mug.name",fluid.getLocalizedName());
    else
        return I18n.translateToLocal("item.mug.empty.name");
}
项目:harshencastle    文件:HarshenUtils.java   
public static ItemStack phaseBucket(Block block)
{
    if(block instanceof BlockLiquid || block instanceof IFluidBlock)
    {
        Fluid fluid = block instanceof BlockLiquid ? FluidRegistry.lookupFluidForBlock(block) : ((IFluidBlock)block).getFluid();
        if(fluid == null)
            return new ItemStack(block);
        ItemStack stack = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000));
        return stack.isEmpty() ? new ItemStack(block) : stack; 
    }

    return new ItemStack(block);
}
项目:CharcoalPit    文件:BlockCreosoteCollector.java   
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileCreosoteCollector tile=(TileCreosoteCollector) worldIn.getTileEntity(pos);
    if(worldIn.isRemote)
        return playerIn.getHeldItem(hand).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    return FluidUtil.interactWithFluidHandler(playerIn, hand, tile.creosote);
}
项目:Thermionics    文件:FluidTransport.java   
public static FluidActionResult tryEmptyOrFillContainer(ItemStack stack, IFluidHandler handler, int maxTransfer, EntityPlayer player) {
    FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, maxTransfer, player, true);
    if (result.success) {
        return result;
    } else {
        FluidActionResult resultFill = FluidUtil.tryFillContainer(stack, handler, maxTransfer, player, true);
        return resultFill;
    }
}
项目:BetterBeginningsReborn    文件:Util.java   
public static boolean isEmptyFluidContainer(ItemStack stack)
   {
//If the stack has a fluid cap, but no contained fluid, it's probably empty
if(stack != null && CapUtils.hasFluidHandler(stack) && FluidUtil.getFluidContained(stack) == null)
    return true;
else
    return false;
   }