Xiyu's Lucky Block

A highly customizable lucky block module provides a lucky block API for making attachments and a convenient method for customizing data packages.

Lucky Block Mod

Discord

Features

  1. Event Handler Module

    • Allows users to define various events in lucky_functions.json file to trigger when lucky blocks are mined
  2. Loot Handler Module

    • Supports obtaining items from any loot table in any data pack
  3. Structure Module

    • Supports loading and generating structures from any data pack
  4. Data Pack Support

  5. Example Block

    • Provides example lucky blocks
    • Lucky value range: 0-200
    • Higher numbers are more likely to trigger lucky effects

API Documentation

Creating Custom Lucky Blocks

  1. Extend Base Lucky Block Class
public class CustomLuckyBlock extends BaseLuckyBlock {
    public CustomLuckyBlock() {
        super(); // Use default properties
    }
}
  1. Customize Block Properties
public class CustomLuckyBlock extends BaseLuckyBlock {
    public CustomLuckyBlock() {
        super(Properties.of()
            .strength(1.0f)
            .sound(SoundType.WOOD)
            // Other properties...
        );
    }
}
  1. Custom Break Effect
@Override
protected void onLuckyBlockBreak(Level level, BlockPos pos, BlockState state, Player player) {
    if (level instanceof ServerLevel serverLevel) {
        // Get lucky value
        int luckyValue = state.getValue(LUCKY);

        // Load and execute effects
        List<LuckyFunctionConfig> configs = LuckyConfigLoader.loadLuckyFunctions(serverLevel, luckyValue);
        if (!configs.isEmpty()) {
            LuckyFunctionConfig config = configs.get(level.random.nextInt(configs.size()));
            JsonObject effect = config.getRandomEffect();
            if (effect != null) {
                executeEffect(new Effect(effect), serverLevel, pos, player, luckyValue);
            }
        }
    }
}

Overridable Methods

  • onLuckyBlockBreak(Level level, BlockPos pos, BlockState state, Player player): Handle block break event
  • onRedStoneActivate(ServerLevel level, BlockPos pos, BlockState state): Handle redstone activation event
  • executeEffect(Effect effect, ServerLevel level, BlockPos pos, @Nullable Player player, int luckyValue): Execute effects

Lucky Value Description

  • Range: 0-200
  • Get method: state.getValue(LUCKY)
  • Default generation: Randomly generates value 0-200 when placed

Trigger Methods

  1. Break Trigger

    • Triggers effect when player breaks the block
  2. Redstone Trigger

    • Triggers effect when receiving redstone signal

Usage Instructions

Configuration File Format

{
  "lucky_functions": [
    {
      "id": "luckyblocks:spawn_items",
      "enabled": true,
      "items": [
        {
          "loot_table": "minecraft:chests/simple_dungeon",
          "enabled": true,
          "count": 1
        },
        {
          "loot_table": "minecraft:chests/desert_pyramid",
          "enabled": false
        }
      ]
    },
    {
      "id": "luckyblocks:spawn_structure",
      "enabled": true,
      "structures": [
        {
          "structure": "minecraft:village/plains/houses/plains_small_house_1",
          "enabled": true,
          "rotation": "NONE"
        }
      ]
    }
  ],
  "unlucky_functions": [
    {
      "id": "luckyblocks:explosion",
      "enabled": true,
      "effects": [
        {
          "power": 4,
          "enabled": true,
          "fire": false
        },
        {
          "power": 8,
          "fire": true,
          "enabled": false
        }
      ]
    },
    {
      "id": "luckyblocks:spawn_mob",
      "enabled": true,
      "mobs": [
        {
          "type": "minecraft:creeper",
          "enabled": true,
          "charged": true,
          "count": 1
        },
        {
          "type": "minecraft:zombie",
          "enabled": true,
          "baby": true,
          "equipment": {
            "mainhand": "minecraft:diamond_sword"
          }
        }
      ]
    }
  ]
}

Configuration Description

  1. Function Structure

    • Each function has a unique id and enabled status
    • Functions can contain multiple sub-functions, each can be enabled/disabled individually
  2. Built-in Functions

    • spawn_items: Generate items (from loot tables)
      • loot_table: Loot table path
      • count: Generation count
    • spawn_structure: Generate structures
      • structure: Structure path
      • rotation: Rotation direction (NONE, CLOCKWISE_90, CLOCKWISE_180, COUNTERCLOCKWISE_90)
    • explosion: Create explosions
      • power: Explosion power
      • fire: Whether to create fire
    • spawn_mob: Spawn entities
      • type: Entity type
      • count: Spawn count
      • charged: Whether charged (Creeper specific)
      • baby: Whether baby
      • equipment: Equipment configuration
  3. Sub-function Configuration

    • Each sub-function must have an enabled property
    • Can include additional properties specific to the function
    • Supports condition configuration and random weights (to be implemented)

Data Pack Customization

WIKI-DataPack

The Xiyu's Lucky Block Team

profile avatar
  • 7
    Followers
  • 16
    Projects
  • 634.9K
    Downloads

More from mai_xiyuView all

  • OneKeyMiner(Neo)Forge  and Fabric| Vein Miner | Chain Vein project image

    OneKeyMiner(Neo)Forge and Fabric| Vein Miner | Chain Vein

    • 324.2K
    • Mods

    This mod adds the ability to chain tools to break blocks and chain farming while holding down the chain button. If you break a block, the adjacent blocks will be destroyed together, or if you hold a seed, the adjacent farmland will also be planted.

    • 324.2K
    • June 28, 2026
    • Mods
    • +2
  • Spartan Weaponry Unofficial project image

    Spartan Weaponry Unofficial

    • 84.8K
    • Mods

    An unofficial NeoForge 1.21.1 port of the iconic Spartan Weaponry mod—featuring swords, polearms, ranged weapons, and more, inspired by Balkon's WeaponMod!

    • 84.8K
    • June 12, 2026
    • Mods
  • Create: Stressbound project image

    Create: Stressbound

    • 2.6K
    • Mods

    A Create addon that allows rotational stress and kinetic power to be transmitted wirelessly across unlimited distances through bindable stress links.

    • 2.6K
    • June 11, 2026
    • Mods
    • +1
  • Totem of Substitution project image

    Totem of Substitution

    • 90
    • Mods

    The Totem of Substitution adds a new totem item to the game. This totem can transfer fatal damage to other creatures, protecting the holder from death.

    • 90
    • April 2, 2026
    • Mods
  • OneKeyMiner(Neo)Forge  and Fabric| Vein Miner | Chain Vein project image

    OneKeyMiner(Neo)Forge and Fabric| Vein Miner | Chain Vein

    • 324.2K
    • Mods

    This mod adds the ability to chain tools to break blocks and chain farming while holding down the chain button. If you break a block, the adjacent blocks will be destroyed together, or if you hold a seed, the adjacent farmland will also be planted.

    • 324.2K
    • June 28, 2026
    • Mods
    • +2
  • Spartan Weaponry Unofficial project image

    Spartan Weaponry Unofficial

    • 84.8K
    • Mods

    An unofficial NeoForge 1.21.1 port of the iconic Spartan Weaponry mod—featuring swords, polearms, ranged weapons, and more, inspired by Balkon's WeaponMod!

    • 84.8K
    • June 12, 2026
    • Mods
  • Create: Stressbound project image

    Create: Stressbound

    • 2.6K
    • Mods

    A Create addon that allows rotational stress and kinetic power to be transmitted wirelessly across unlimited distances through bindable stress links.

    • 2.6K
    • June 11, 2026
    • Mods
    • +1
  • Totem of Substitution project image

    Totem of Substitution

    • 90
    • Mods

    The Totem of Substitution adds a new totem item to the game. This totem can transfer fatal damage to other creatures, protecting the holder from death.

    • 90
    • April 2, 2026
    • Mods