Skip to content

Commit f66d2d4

Browse files
authored
1.21 (#145)
* 24w18a (data driven enchantments not implemented yet) * 1.21
1 parent 38eab50 commit f66d2d4

File tree

14 files changed

+653
-132
lines changed

14 files changed

+653
-132
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A collection of Rust crates for making Minecraft bots, clients, and tools.
1111

1212
<!-- The line below is automatically read and updated by the migrate script, so don't change it manually. -->
1313

14-
_Currently supported Minecraft version: `1.20.6`._
14+
_Currently supported Minecraft version: `1.21`._
1515

1616
> [!WARNING]
1717
> Azalea is still very unfinished, though most crates are in a somewhat useable state

azalea-client/src/interact.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,7 @@ fn update_modifiers_for_held_item(
365365
};
366366
attributes
367367
.attack_speed
368-
.remove(&azalea_entity::attributes::BASE_ATTACK_SPEED_UUID);
369-
attributes
370-
.attack_speed
371-
.insert(azalea_entity::attributes::tool_attack_speed_modifier(
368+
.insert(azalea_entity::attributes::base_attack_speed_modifier(
372369
added_attack_speed,
373370
))
374371
.unwrap();

azalea-client/src/movement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ fn set_sprinting(
463463
} else {
464464
attributes
465465
.speed
466-
.remove(&azalea_entity::attributes::sprinting_modifier().uuid)
466+
.remove(&azalea_entity::attributes::sprinting_modifier().id)
467467
.is_none()
468468
}
469469
}

azalea-entity/src/attributes.rs

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
//! See <https://minecraft.fandom.com/wiki/Attribute>.
22
3-
use std::{
4-
collections::HashMap,
5-
io::{Cursor, Write},
6-
};
3+
use std::collections::HashMap;
74

8-
use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable};
5+
use azalea_buf::McBuf;
6+
use azalea_core::resource_location::ResourceLocation;
97
use bevy_ecs::component::Component;
108
use thiserror::Error;
11-
use uuid::{uuid, Uuid};
129

1310
#[derive(Clone, Debug, Component)]
1411
pub struct Attributes {
@@ -19,7 +16,7 @@ pub struct Attributes {
1916
#[derive(Clone, Debug)]
2017
pub struct AttributeInstance {
2118
pub base: f64,
22-
modifiers_by_uuid: HashMap<Uuid, AttributeModifier>,
19+
modifiers_by_id: HashMap<ResourceLocation, AttributeModifier>,
2320
}
2421

2522
#[derive(Clone, Debug, Error)]
@@ -30,13 +27,13 @@ impl AttributeInstance {
3027
pub fn new(base: f64) -> Self {
3128
Self {
3229
base,
33-
modifiers_by_uuid: HashMap::new(),
30+
modifiers_by_id: HashMap::new(),
3431
}
3532
}
3633

3734
pub fn calculate(&self) -> f64 {
3835
let mut total = self.base;
39-
for modifier in self.modifiers_by_uuid.values() {
36+
for modifier in self.modifiers_by_id.values() {
4037
match modifier.operation {
4138
AttributeModifierOperation::Addition => total += modifier.amount,
4239
AttributeModifierOperation::MultiplyBase => total += self.base * modifier.amount,
@@ -52,8 +49,8 @@ impl AttributeInstance {
5249
/// Add a new modifier to this attribute.
5350
pub fn insert(&mut self, modifier: AttributeModifier) -> Result<(), AlreadyPresentError> {
5451
if self
55-
.modifiers_by_uuid
56-
.insert(modifier.uuid, modifier)
52+
.modifiers_by_id
53+
.insert(modifier.id.clone(), modifier)
5754
.is_some()
5855
{
5956
Err(AlreadyPresentError)
@@ -62,17 +59,16 @@ impl AttributeInstance {
6259
}
6360
}
6461

65-
/// Remove the modifier with the given UUID from this attribute, returning
62+
/// Remove the modifier with the given ID from this attribute, returning
6663
/// the previous modifier is present.
67-
pub fn remove(&mut self, uuid: &Uuid) -> Option<AttributeModifier> {
68-
self.modifiers_by_uuid.remove(uuid)
64+
pub fn remove(&mut self, id: &ResourceLocation) -> Option<AttributeModifier> {
65+
self.modifiers_by_id.remove(id)
6966
}
7067
}
7168

72-
#[derive(Clone, Debug)]
69+
#[derive(Clone, Debug, McBuf)]
7370
pub struct AttributeModifier {
74-
pub uuid: Uuid,
75-
pub name: String,
71+
pub id: ResourceLocation,
7672
pub amount: f64,
7773
pub operation: AttributeModifierOperation,
7874
}
@@ -86,50 +82,16 @@ pub enum AttributeModifierOperation {
8682

8783
pub fn sprinting_modifier() -> AttributeModifier {
8884
AttributeModifier {
89-
uuid: uuid!("662A6B8D-DA3E-4C1C-8813-96EA6097278D"),
90-
name: "Sprinting speed boost".to_string(),
85+
id: ResourceLocation::new("sprinting"),
9186
amount: 0.30000001192092896,
9287
operation: AttributeModifierOperation::MultiplyTotal,
9388
}
9489
}
9590

96-
pub static BASE_ATTACK_SPEED_UUID: Uuid = uuid!("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
97-
pub fn weapon_attack_speed_modifier(amount: f64) -> AttributeModifier {
98-
AttributeModifier {
99-
uuid: BASE_ATTACK_SPEED_UUID,
100-
name: "Weapon modifier".to_string(),
101-
amount,
102-
operation: AttributeModifierOperation::Addition,
103-
}
104-
}
105-
pub fn tool_attack_speed_modifier(amount: f64) -> AttributeModifier {
91+
pub fn base_attack_speed_modifier(amount: f64) -> AttributeModifier {
10692
AttributeModifier {
107-
uuid: BASE_ATTACK_SPEED_UUID,
108-
name: "Tool modifier".to_string(),
93+
id: ResourceLocation::new("base_attack_speed"),
10994
amount,
11095
operation: AttributeModifierOperation::Addition,
11196
}
11297
}
113-
114-
impl McBufReadable for AttributeModifier {
115-
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
116-
let uuid = Uuid::read_from(buf)?;
117-
let amount = f64::read_from(buf)?;
118-
let operation = AttributeModifierOperation::read_from(buf)?;
119-
Ok(Self {
120-
uuid,
121-
name: "Unknown synced attribute modifier".to_string(),
122-
amount,
123-
operation,
124-
})
125-
}
126-
}
127-
128-
impl McBufWritable for AttributeModifier {
129-
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
130-
self.uuid.write_into(buf)?;
131-
self.amount.write_into(buf)?;
132-
self.operation.write_into(buf)?;
133-
Ok(())
134-
}
135-
}

azalea-inventory/src/components.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub fn from_kind(
4949
kind: azalea_registry::DataComponentKind,
5050
buf: &mut Cursor<&[u8]>,
5151
) -> Result<Box<dyn EncodableDataComponent>, BufReadError> {
52+
// if this is causing a compile-time error, look at DataComponents.java in the
53+
// decompiled vanilla code to see how to implement new components
5254
Ok(match kind {
5355
DataComponentKind::CustomData => Box::new(CustomData::read_from(buf)?),
5456
DataComponentKind::MaxStackSize => Box::new(MaxStackSize::read_from(buf)?),
@@ -114,6 +116,7 @@ pub fn from_kind(
114116
DataComponentKind::Bees => Box::new(Bees::read_from(buf)?),
115117
DataComponentKind::Lock => Box::new(Lock::read_from(buf)?),
116118
DataComponentKind::ContainerLoot => Box::new(ContainerLoot::read_from(buf)?),
119+
DataComponentKind::JukeboxPlayable => todo!(),
117120
})
118121
}
119122

@@ -654,3 +657,10 @@ pub struct ContainerLoot {
654657
pub loot: NbtCompound,
655658
}
656659
impl DataComponent for ContainerLoot {}
660+
661+
#[derive(Clone, PartialEq, McBuf)]
662+
pub struct JukeboxPlayable {
663+
pub song: azalea_registry::JukeboxSong,
664+
pub show_in_tooltip: bool,
665+
}
666+
impl DataComponent for JukeboxPlayable {}

0 commit comments

Comments
 (0)