Event Handler Module
lucky_functions.json file to trigger when lucky blocks are minedLoot Handler Module
Structure Module
Data Pack Support
Example Block
public class CustomLuckyBlock extends BaseLuckyBlock {
public CustomLuckyBlock() {
super(); // Use default properties
}
}
public class CustomLuckyBlock extends BaseLuckyBlock {
public CustomLuckyBlock() {
super(Properties.of()
.strength(1.0f)
.sound(SoundType.WOOD)
// Other properties...
);
}
}
@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);
}
}
}
}
onLuckyBlockBreak(Level level, BlockPos pos, BlockState state, Player player): Handle block break eventonRedStoneActivate(ServerLevel level, BlockPos pos, BlockState state): Handle redstone activation eventexecuteEffect(Effect effect, ServerLevel level, BlockPos pos, @Nullable Player player, int luckyValue): Execute effectsstate.getValue(LUCKY)Break Trigger
Redstone Trigger
data/[datapack]/lucky_functions/lucky_functions.json{
"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"
}
}
]
}
]
}
Function Structure
id and enabled statusBuilt-in Functions
spawn_items: Generate items (from loot tables)loot_table: Loot table pathcount: Generation countspawn_structure: Generate structuresstructure: Structure pathrotation: Rotation direction (NONE, CLOCKWISE_90, CLOCKWISE_180, COUNTERCLOCKWISE_90)explosion: Create explosionspower: Explosion powerfire: Whether to create firespawn_mob: Spawn entitiestype: Entity typecount: Spawn countcharged: Whether charged (Creeper specific)baby: Whether babyequipment: Equipment configurationSub-function Configuration
enabled property