aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/attribute_modifier_operation.rs
blob: 8418ff22ef691f0bdda4cf3ba7790008b131432b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::str::FromStr;

use azalea_buf::AzBuf;
use serde::Serialize;
use simdnbt::{FromNbtTag, borrow::NbtTag};

#[derive(AzBuf, Clone, Copy, Debug, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum AttributeModifierOperation {
    AddValue,
    AddMultipliedBase,
    AddMultipliedTotal,
}

impl FromStr for AttributeModifierOperation {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let value: AttributeModifierOperation = match s {
            "add_value" => Self::AddValue,
            "add_multiplied_base" => Self::AddMultipliedBase,
            "add_multiplied_total" => Self::AddMultipliedTotal,
            _ => return Err(()),
        };
        Ok(value)
    }
}
impl FromNbtTag for AttributeModifierOperation {
    fn from_nbt_tag(tag: NbtTag) -> Option<Self> {
        let v = tag.string()?;
        Self::from_str(&v.to_str()).ok()
    }
}