Skip to content
RustPluginGenerator

OnQuarryConsumeFuel

OnQuarryConsumeFuel is called from MiningQuarry.FuelCheck each time a quarry looks up a diesel barrel to burn, before deciding whether it has fuel to keep running.

Signature
object OnQuarryConsumeFuel(MiningQuarry miningQuarry, Item item)

Parameters

Hook parameters
ParameterTypeDescription
miningQuarryMiningQuarryThe MiningQuarry entity whose fuel check is running. Use it to read its position, owner, or storage contents when deciding how to treat the fuel item.
itemItemThe diesel barrel item found in the quarry's fuel storage, or null when the storage holds no diesel barrel. Returning a different Item replaces what the game consumes.

Return value

Return an Item instance to replace the diesel barrel the quarry will check and consume; the game then evaluates that item's amount. Return null (or any non-Item value) to leave the fuel lookup result untouched and let vanilla behavior continue.

How it works

MiningQuarry.FuelCheck runs when the quarry needs to confirm it can keep operating. The game locates a diesel barrel in the quarry's fuel storage, then calls OnQuarryConsumeFuel with the quarry and that item (null if no diesel barrel was found). The hook fires before the amount check, so your code always sees the lookup result first.

Returning an Item object replaces the item the quarry will evaluate: the method then checks that item's amount and continues normal fuel consumption. Return anything that is not an Item (including null) and the original value from the storage lookup is used unchanged. This makes the hook useful for swapping in a custom fuel item, granting fuel from an external source, or reading quarry activity.

Because the hook fires on the quarry's own fuel check routine, it can run repeatedly while the quarry is active. Keep handlers cheap: no chat output, no Puts/logging. The parameter is a MiningQuarry, so declaring that exact type is the correct narrow signature; there is no player-derived narrowing to apply here since the argument is always the quarry entity.

Example plugin: Swap quarry fuel for a custom barrel and track consumption

QuarryFuelSwap.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Quarry Fuel Swap", "RustPluginGenerator", "1.0.0")]
    [Description("Substitutes a custom fuel item for diesel barrels in quarries and tracks consumption")]
    public class QuarryFuelSwap : RustPlugin
    {
        private const string PermAdmin = "quarryfuelswap.admin";

        private PluginConfig config;
        private QuarryFuelData data;
        private bool dirty;

        private class PluginConfig
        {
            [JsonProperty("Custom fuel shortname (blank = vanilla diesel only)")]
            public string CustomFuelShortname = "lowgradefuel";

            [JsonProperty("Allow custom fuel substitution")]
            public bool EnableSubstitution = false;
        }

        private class QuarryFuelData
        {
            [JsonProperty("Consumed per quarry id")]
            public Dictionary<string, int> Consumed = new Dictionary<string, int>();
        }

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["Status"] = "Custom fuel: {0} | Substitution: {1}",
                ["Consumed"] = "This quarry has consumed {0} custom fuel barrels.",
                ["NoQuarry"] = "Could not resolve a quarry from your aim.",
                ["Denied"] = "You do not have permission to use this command."
            }, this);
        }

        private string Msg(string key, string userId = null, params object[] args)
            => string.Format(lang.GetMessage(key, this, userId), args);

        private void Init()
        {
            permission.RegisterPermission(PermAdmin, this);
            data = Interface.Oxide.DataFileSystem.ReadObject<QuarryFuelData>(Name) ?? new QuarryFuelData();
        }

        private void Unload()
        {
            if (dirty) SaveData();
        }

        private void SaveData()
        {
            Interface.Oxide.DataFileSystem.WriteObject(Name, data);
            dirty = false;
        }

        private object OnQuarryConsumeFuel(MiningQuarry miningQuarry, Item item)
        {
            if (miningQuarry == null || item == null || item.info == null) return null;
            if (!config.EnableSubstitution || string.IsNullOrEmpty(config.CustomFuelShortname)) return null;

            string custom = config.CustomFuelShortname.Trim().ToLowerInvariant();
            if (item.info.shortname != custom) return null;

            string id = miningQuarry.net.ID.Value.ToString();
            int count;
            data.Consumed.TryGetValue(id, out count);
            data.Consumed[id] = count + 1;
            dirty = true;

            return item;
        }

        [ChatCommand("quarryfuel")]
        private void CmdQuarryFuel(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, PermAdmin))
            {
                player.ChatMessage(Msg("Denied", player.UserIDString));
                return;
            }

            if (args != null && args.Length > 0 && args[0].ToLowerInvariant() == "status")
            {
                player.ChatMessage(Msg("Status", player.UserIDString,
                    string.IsNullOrEmpty(config.CustomFuelShortname) ? "none" : config.CustomFuelShortname,
                    config.EnableSubstitution ? "enabled" : "disabled"));
                return;
            }

            RaycastHit hit;
            string quarryId = null;
            if (Physics.Raycast(player.eyes.HeadRay(), out hit, 8f))
            {
                MiningQuarry quarry = hit.GetEntity() as MiningQuarry;
                if (quarry != null) quarryId = quarry.net.ID.Value.ToString();
            }

            if (quarryId == null)
            {
                player.ChatMessage(Msg("NoQuarry", player.UserIDString));
                return;
            }

            int consumed;
            data.Consumed.TryGetValue(quarryId, out consumed);
            player.ChatMessage(Msg("Consumed", player.UserIDString, consumed));
        }
    }
}

Substitution is off by default. When an admin enables Allow custom fuel substitution and sets a custom shortname (default lowgradefuel), OnQuarryConsumeFuel compares the consumed item's shortname against that value. On a match it returns the same item so the quarry burns it and increments a per-quarry consumption counter, which is written to the plugin data file on unload when changed. Setting the shortname to empty disables matching. The quarryfuel chat command requires the quarryfuelswap.admin permission: with no arguments it raycasts the player's aim for a quarry and reports that quarry's consumed count, while quarryfuel status reports the current shortname and whether substitution is enabled.

Common use cases

  • Allow alternative fuel barrels

    Return a replacement Item when you want the quarry to accept a custom barrel shortname as fuel, provided your storage still holds one to substitute.

  • Audit quarry fuel use

    Count how often the hook fires per quarry to measure how much diesel your quarry network consumes over an hour or wipe.

  • Gate fuel by ownership or location

    Return null to let vanilla proceed, or intercept by inspecting the quarry's position and owner to decide whether custom logic should apply.

Pitfalls

  • Frequent calls, no logging

    FuelCheck runs on the quarry's operating loop, so the hook can fire many times per minute. Avoid PrintWarning, Puts, or chat messages inside it.

  • Item may be null

    The diesel barrel lookup can return null when storage is empty. Guard against null before reading item.info or item.amount.

  • Returning unrelated types

    Only an Item return changes behavior; strings, bools, or numbers are ignored. Return null when you want vanilla fuel handling to continue.

Build a plugin with OnQuarryConsumeFuel

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Allow alternative fuel barrels using the OnQuarryConsumeFuel hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnQuarryConsumeFuel

Generate