-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* more loot table work * make Loot Tables work
- Loading branch information
Showing
7 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use serde::Deserialize; | ||
|
||
mod survives_explosion; | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(tag = "condition")] | ||
pub enum LootCondition { | ||
#[serde(rename = "minecraft:inverted")] | ||
Inverted, | ||
#[serde(rename = "minecraft:any_of")] | ||
AnyOf, | ||
#[serde(rename = "minecraft:all_of")] | ||
AllOf, | ||
#[serde(rename = "minecraft:random_chance")] | ||
RandomChance, | ||
#[serde(rename = "minecraft:random_chance_with_enchanted_bonus")] | ||
RandomChanceWithEnchantedBonus, | ||
#[serde(rename = "minecraft:entity_properties")] | ||
EntityProperties, | ||
#[serde(rename = "minecraft:killed_by_player")] | ||
KilledByPlayer, | ||
#[serde(rename = "minecraft:entity_scores")] | ||
EntityScores, | ||
#[serde(rename = "minecraft:block_state_property")] | ||
BlockStateProperty, | ||
#[serde(rename = "minecraft:match_tool")] | ||
MatchTool, | ||
#[serde(rename = "minecraft:table_bonus")] | ||
TableBonus, | ||
#[serde(rename = "minecraft:survives_explosion")] | ||
SurvivesExplosion, | ||
#[serde(rename = "minecraft:damage_source_properties")] | ||
DamageSourceProperties, | ||
#[serde(rename = "minecraft:location_check")] | ||
LocationCheck, | ||
#[serde(rename = "minecraft:weather_check")] | ||
WeatherCheck, | ||
#[serde(rename = "minecraft:reference")] | ||
Reference, | ||
#[serde(rename = "minecraft:time_check")] | ||
TimeCheck, | ||
#[serde(rename = "minecraft:value_check")] | ||
ValueCheck, | ||
#[serde(rename = "minecraft:enchantment_active_check")] | ||
EnchantmentActiveCheck, | ||
} | ||
|
||
#[expect(clippy::match_like_matches_macro)] | ||
impl LootCondition { | ||
// TODO: This is trash, Make this right | ||
pub fn test(&self) -> bool { | ||
match self { | ||
LootCondition::SurvivesExplosion => true, | ||
_ => false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use serde::Deserialize; | ||
|
||
use crate::{item::ItemStack, loot::LootPoolEntry}; | ||
|
||
#[derive(Deserialize, Clone)] | ||
pub struct AlternativeEntry { | ||
children: Vec<LootPoolEntry>, | ||
} | ||
|
||
impl AlternativeEntry { | ||
pub fn get_items(&self) -> Vec<ItemStack> { | ||
let mut items = vec![]; | ||
for child in &self.children { | ||
if let Some(conditions) = &child.conditions { | ||
let mut conditions_met = true; | ||
for condition in conditions { | ||
if !condition.test() { | ||
conditions_met = false; | ||
break; | ||
} | ||
} | ||
if !conditions_met { | ||
continue; | ||
} | ||
} | ||
items.extend_from_slice(&child.content.get_items()); | ||
} | ||
items | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use pumpkin_data::item::Item; | ||
use serde::Deserialize; | ||
|
||
use crate::item::ItemStack; | ||
|
||
#[derive(Deserialize, Clone)] | ||
pub struct ItemEntry { | ||
name: String, | ||
} | ||
|
||
impl ItemEntry { | ||
pub fn get_items(&self) -> Vec<ItemStack> { | ||
let item = Item::from_registry_key(&self.name.replace("minecraft:", "")).unwrap(); | ||
vec![ItemStack::new(1, item)] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use alternative::AlternativeEntry; | ||
use item::ItemEntry; | ||
use serde::Deserialize; | ||
|
||
use crate::item::ItemStack; | ||
|
||
mod alternative; | ||
mod item; | ||
|
||
#[derive(Deserialize, Clone)] | ||
#[serde(tag = "type")] | ||
pub enum LootPoolEntryTypes { | ||
#[serde(rename = "minecraft:empty")] | ||
Empty, | ||
#[serde(rename = "minecraft:item")] | ||
Item(ItemEntry), | ||
#[serde(rename = "minecraft:loot_table")] | ||
LootTable, | ||
#[serde(rename = "minecraft:dynamic")] | ||
Dynamic, | ||
#[serde(rename = "minecraft:tag")] | ||
Tag, | ||
#[serde(rename = "minecraft:alternatives")] | ||
Alternatives(AlternativeEntry), | ||
#[serde(rename = "minecraft:sequence")] | ||
Sequence, | ||
#[serde(rename = "minecraft:group")] | ||
Group, | ||
} | ||
|
||
impl LootPoolEntryTypes { | ||
pub fn get_items(&self) -> Vec<ItemStack> { | ||
match self { | ||
LootPoolEntryTypes::Empty => todo!(), | ||
LootPoolEntryTypes::Item(item_entry) => item_entry.get_items(), | ||
LootPoolEntryTypes::LootTable => todo!(), | ||
LootPoolEntryTypes::Dynamic => todo!(), | ||
LootPoolEntryTypes::Tag => todo!(), | ||
LootPoolEntryTypes::Alternatives(alternative) => alternative.get_items(), | ||
LootPoolEntryTypes::Sequence => todo!(), | ||
LootPoolEntryTypes::Group => todo!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters