pumpkinplus/modules/mechanics/entity/bat.rs
1//! Bat module - custom bat drops (phantom membrane).
2//!
3//! ## Configuration
4//!
5//! | Field | Default | Description |
6//! |--------------------------|---------|-----------------------------------------------------|
7//! | `enabled` | `false` | Whether this module is active |
8//! | `drop_chance` | `1.0` | Chance (0.0 - 1.0) for a bat to drop membrane |
9//! | `base_min` | `0` | Minimum base amount of membrane dropped |
10//! | `base_max` | `1` | Maximum base amount of membrane dropped |
11//! | `looting_bonus_per_level`| `1` | Extra membrane granted per level of Looting |
12//!
13//! ## Notes
14//!
15//! This module is currently a stub. The Pumpkin plugin API does not yet expose
16//! an `EntityDeathEvent` (or equivalent), so bat drop mechanics cannot be hooked
17//! until upstream support is added.
18
19use crate::{config::ConfigManager, mechanics::mechanic::Mechanic};
20use pumpkin_plugin_api::Context;
21use serde::{Deserialize, Serialize};
22
23/// Handles bat drop mechanics.
24#[derive(Default)]
25pub struct Bat;
26
27impl Mechanic for Bat {
28 fn enabled(&self) -> bool {
29 ConfigManager::get()
30 .map(|cm| cm.get_config::<BatConfig>().enabled)
31 .unwrap_or(false)
32 }
33
34 fn events(&self, _context: &Context) {
35 // TODO: Implement when EntityDeathEvent (or equivalent) is available
36 // in the Pumpkin plugin API. The intended logic is:
37 //
38 // 1. Listen for entity death events.
39 // 2. Check if the gamerule `spawn_phantoms` is true; if false, return.
40 // 3. If the entity is a bat and the drop chance succeeds:
41 // - Determine the killer.
42 // - Check the killer's main-hand weapon for a Looting enchantment.
43 // - Calculate drops: base + (looting_level * config.looting_bonus_per_level).
44 // - Add `Material::PhantomMembrane` to the event drops.
45 }
46}
47
48/// Configuration for the bat mechanics module.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct BatConfig {
51 /// Whether this module is active.
52 pub enabled: bool,
53 /// Chance (0.0 - 1.0) for a bat to drop phantom membrane.
54 pub drop_chance: f64,
55 /// Minimum base amount of phantom membrane dropped.
56 pub base_min: u32,
57 /// Maximum base amount of phantom membrane dropped.
58 pub base_max: u32,
59 /// Extra membrane granted per level of Looting.
60 pub looting_bonus_per_level: u32,
61}
62
63impl Default for BatConfig {
64 fn default() -> Self {
65 Self {
66 enabled: false,
67 drop_chance: 1.0,
68 base_min: 0,
69 base_max: 1,
70 looting_bonus_per_level: 1,
71 }
72 }
73}