aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShayne Hartford <shaybox@shaybox.com>2024-10-21 20:21:38 -0400
committerGitHub <noreply@github.com>2024-10-21 19:21:38 -0500
commitcd2f298a62819a3fabc52ef17560c2124a74d555 (patch)
tree3e32e4ccc7d9f095696c8e23b688b06cf1188f76
parent5535877a4bddcdc30ef8f752a90e6845b308c3c2 (diff)
downloadazalea-drasl-cd2f298a62819a3fabc52ef17560c2124a74d555.tar.xz
Rename InventoryComponent to Inventory to match other components (#177)
(cherry picked from commit 266058a8d441169b46ef819595eee62337ab324c)
-rw-r--r--azalea-client/src/client.rs4
-rw-r--r--azalea-client/src/interact.rs9
-rw-r--r--azalea-client/src/inventory.rs22
-rw-r--r--azalea-client/src/mining.rs12
-rw-r--r--azalea-client/src/packet_handling/configuration.rs2
-rw-r--r--azalea-client/src/packet_handling/game.rs8
-rw-r--r--azalea/src/auto_tool.rs4
-rw-r--r--azalea/src/container.rs16
-rw-r--r--azalea/src/pathfinder/mod.rs15
-rw-r--r--azalea/src/pathfinder/simulation.rs10
10 files changed, 42 insertions, 60 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 6cb590df..0d0b18f0 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -6,7 +6,7 @@ use crate::{
disconnect::{DisconnectEvent, DisconnectPlugin},
events::{Event, EventPlugin, LocalPlayerEvents},
interact::{CurrentSequenceNumber, InteractPlugin},
- inventory::{InventoryComponent, InventoryPlugin},
+ inventory::{Inventory, InventoryPlugin},
local_player::{
death_event, GameProfileComponent, Hunger, InstanceHolder, PermissionLevel,
PlayerAbilities, TabList,
@@ -688,7 +688,7 @@ pub struct LocalPlayerBundle {
pub struct JoinedClientBundle {
// note that InstanceHolder isn't here because it's set slightly before we fully join the world
pub physics_state: PhysicsState,
- pub inventory: InventoryComponent,
+ pub inventory: Inventory,
pub tab_list: TabList,
pub current_sequence_number: CurrentSequenceNumber,
pub last_sent_direction: LastSentLookDirection,
diff --git a/azalea-client/src/interact.rs b/azalea-client/src/interact.rs
index 7b14be09..94b60ddc 100644
--- a/azalea-client/src/interact.rs
+++ b/azalea-client/src/interact.rs
@@ -33,7 +33,7 @@ use tracing::warn;
use crate::{
attack::handle_attack_event,
- inventory::{InventoryComponent, InventorySet},
+ inventory::{Inventory, InventorySet},
local_player::{LocalGameMode, PermissionLevel, PlayerAbilities},
movement::MoveEventsSet,
packet_handling::game::{handle_send_packet_event, SendPacketEvent},
@@ -237,7 +237,7 @@ pub fn check_is_interaction_restricted(
instance: &Instance,
block_pos: &BlockPos,
game_mode: &GameMode,
- inventory: &InventoryComponent,
+ inventory: &Inventory,
) -> bool {
match game_mode {
GameMode::Adventure => {
@@ -314,10 +314,7 @@ pub fn handle_swing_arm_event(
#[allow(clippy::type_complexity)]
fn update_modifiers_for_held_item(
- mut query: Query<
- (&mut Attributes, &InventoryComponent),
- (With<LocalEntity>, Changed<InventoryComponent>),
- >,
+ mut query: Query<(&mut Attributes, &Inventory), (With<LocalEntity>, Changed<Inventory>)>,
) {
for (mut attributes, inventory) in &mut query {
let held_item = inventory.held_item();
diff --git a/azalea-client/src/inventory.rs b/azalea-client/src/inventory.rs
index 97eb98ea..d4ccab14 100644
--- a/azalea-client/src/inventory.rs
+++ b/azalea-client/src/inventory.rs
@@ -67,14 +67,14 @@ impl Client {
/// have the player's inventory.
pub fn menu(&self) -> Menu {
let mut ecs = self.ecs.lock();
- let inventory = self.query::<&InventoryComponent>(&mut ecs);
+ let inventory = self.query::<&Inventory>(&mut ecs);
inventory.menu().clone()
}
}
/// A component present on all local players that have an inventory.
#[derive(Component, Debug, Clone)]
-pub struct InventoryComponent {
+pub struct Inventory {
/// A component that contains the player's inventory menu. This is
/// guaranteed to be a `Menu::Player`.
///
@@ -118,7 +118,7 @@ pub struct InventoryComponent {
pub selected_hotbar_slot: u8,
}
-impl InventoryComponent {
+impl Inventory {
/// Returns a reference to the currently active menu. If a container is open
/// it'll return [`Self::container_menu`], otherwise
/// [`Self::inventory_menu`].
@@ -563,9 +563,9 @@ fn get_quick_craft_slot_count(
item.count += slot_item_count;
}
-impl Default for InventoryComponent {
+impl Default for Inventory {
fn default() -> Self {
- InventoryComponent {
+ Inventory {
inventory_menu: Menu::Player(azalea_inventory::Player::default()),
id: 0,
container_menu: None,
@@ -591,7 +591,7 @@ pub struct MenuOpenedEvent {
}
fn handle_menu_opened_event(
mut events: EventReader<MenuOpenedEvent>,
- mut query: Query<&mut InventoryComponent>,
+ mut query: Query<&mut Inventory>,
) {
for event in events.read() {
let mut inventory = query.get_mut(event.entity).unwrap();
@@ -613,7 +613,7 @@ pub struct CloseContainerEvent {
pub id: u8,
}
fn handle_container_close_event(
- query: Query<(Entity, &InventoryComponent)>,
+ query: Query<(Entity, &Inventory)>,
mut events: EventReader<CloseContainerEvent>,
mut client_side_events: EventWriter<ClientSideCloseContainerEvent>,
mut send_packet_events: EventWriter<SendPacketEvent>,
@@ -650,7 +650,7 @@ pub struct ClientSideCloseContainerEvent {
}
pub fn handle_client_side_close_container_event(
mut events: EventReader<ClientSideCloseContainerEvent>,
- mut query: Query<&mut InventoryComponent>,
+ mut query: Query<&mut Inventory>,
) {
for event in events.read() {
let mut inventory = query.get_mut(event.entity).unwrap();
@@ -667,7 +667,7 @@ pub struct ContainerClickEvent {
pub operation: ClickOperation,
}
pub fn handle_container_click_event(
- mut query: Query<(Entity, &mut InventoryComponent)>,
+ mut query: Query<(Entity, &mut Inventory)>,
mut events: EventReader<ContainerClickEvent>,
mut send_packet_events: EventWriter<SendPacketEvent>,
) {
@@ -722,7 +722,7 @@ pub struct SetContainerContentEvent {
}
fn handle_set_container_content_event(
mut events: EventReader<SetContainerContentEvent>,
- mut query: Query<&mut InventoryComponent>,
+ mut query: Query<&mut Inventory>,
) {
for event in events.read() {
let mut inventory = query.get_mut(event.entity).unwrap();
@@ -753,7 +753,7 @@ pub struct SetSelectedHotbarSlotEvent {
fn handle_set_selected_hotbar_slot_event(
mut events: EventReader<SetSelectedHotbarSlotEvent>,
mut send_packet_events: EventWriter<SendPacketEvent>,
- mut query: Query<&mut InventoryComponent>,
+ mut query: Query<&mut Inventory>,
) {
for event in events.read() {
let mut inventory = query.get_mut(event.entity).unwrap();
diff --git a/azalea-client/src/mining.rs b/azalea-client/src/mining.rs
index bda14db0..86a0193c 100644
--- a/azalea-client/src/mining.rs
+++ b/azalea-client/src/mining.rs
@@ -16,7 +16,7 @@ use crate::{
can_use_game_master_blocks, check_is_interaction_restricted, CurrentSequenceNumber,
HitResultComponent, SwingArmEvent,
},
- inventory::{InventoryComponent, InventorySet},
+ inventory::{Inventory, InventorySet},
local_player::{LocalGameMode, PermissionLevel, PlayerAbilities},
movement::MoveEventsSet,
packet_handling::game::SendPacketEvent,
@@ -99,7 +99,7 @@ fn handle_auto_mine(
&HitResultComponent,
Entity,
Option<&Mining>,
- &InventoryComponent,
+ &Inventory,
&MineBlockPos,
&MineItem,
),
@@ -193,7 +193,7 @@ fn handle_start_mining_block_with_direction_event(
mut query: Query<(
&InstanceName,
&LocalGameMode,
- &InventoryComponent,
+ &Inventory,
&FluidOnEyes,
&Physics,
Option<&Mining>,
@@ -359,7 +359,7 @@ pub struct AttackBlockEvent {
/// mining.
fn is_same_mining_target(
target_block: BlockPos,
- inventory: &InventoryComponent,
+ inventory: &Inventory,
current_mining_pos: &MineBlockPos,
current_mining_item: &MineItem,
) -> bool {
@@ -423,7 +423,7 @@ fn handle_finish_mining_block_event(
mut query: Query<(
&InstanceName,
&LocalGameMode,
- &InventoryComponent,
+ &Inventory,
&PlayerAbilities,
&PermissionLevel,
&mut CurrentSequenceNumber,
@@ -522,7 +522,7 @@ fn continue_mining_block(
Entity,
&InstanceName,
&LocalGameMode,
- &InventoryComponent,
+ &Inventory,
&MineBlockPos,
&MineItem,
&FluidOnEyes,
diff --git a/azalea-client/src/packet_handling/configuration.rs b/azalea-client/src/packet_handling/configuration.rs
index 1be34a12..de365394 100644
--- a/azalea-client/src/packet_handling/configuration.rs
+++ b/azalea-client/src/packet_handling/configuration.rs
@@ -123,7 +123,7 @@ pub fn process_packet_events(ecs: &mut World) {
.remove::<InConfigurationState>()
.insert(crate::JoinedClientBundle {
physics_state: crate::PhysicsState::default(),
- inventory: crate::inventory::InventoryComponent::default(),
+ inventory: crate::inventory::Inventory::default(),
tab_list: crate::local_player::TabList::default(),
current_sequence_number: crate::interact::CurrentSequenceNumber::default(),
last_sent_direction: crate::movement::LastSentLookDirection::default(),
diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs
index daa420c3..13183e7a 100644
--- a/azalea-client/src/packet_handling/game.rs
+++ b/azalea-client/src/packet_handling/game.rs
@@ -39,8 +39,7 @@ use crate::{
chunks,
disconnect::DisconnectEvent,
inventory::{
- ClientSideCloseContainerEvent, InventoryComponent, MenuOpenedEvent,
- SetContainerContentEvent,
+ ClientSideCloseContainerEvent, Inventory, MenuOpenedEvent, SetContainerContentEvent,
},
local_player::{
GameProfileComponent, Hunger, InstanceHolder, LocalGameMode, PlayerAbilities, TabList,
@@ -1144,7 +1143,7 @@ pub fn process_packet_events(ecs: &mut World) {
debug!("Got container set content packet {p:?}");
let mut system_state: SystemState<(
- Query<&mut InventoryComponent>,
+ Query<&mut Inventory>,
EventWriter<SetContainerContentEvent>,
)> = SystemState::new(ecs);
let (mut query, mut events) = system_state.get_mut(ecs);
@@ -1183,8 +1182,7 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::ContainerSetSlot(p) => {
debug!("Got container set slot packet {p:?}");
- let mut system_state: SystemState<Query<&mut InventoryComponent>> =
- SystemState::new(ecs);
+ let mut system_state: SystemState<Query<&mut Inventory>> = SystemState::new(ecs);
let mut query = system_state.get_mut(ecs);
let mut inventory = query.get_mut(player_entity).unwrap();
diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs
index 77345acc..e5a627ba 100644
--- a/azalea/src/auto_tool.rs
+++ b/azalea/src/auto_tool.rs
@@ -1,5 +1,5 @@
use azalea_block::{Block, BlockState};
-use azalea_client::{inventory::InventoryComponent, Client};
+use azalea_client::{inventory::Inventory, Client};
use azalea_entity::{FluidOnEyes, Physics};
use azalea_inventory::{ItemSlot, Menu};
use azalea_registry::{DataComponentKind, Fluid};
@@ -18,7 +18,7 @@ impl AutoToolClientExt for Client {
fn best_tool_in_hotbar_for_block(&self, block: BlockState) -> BestToolResult {
let mut ecs = self.ecs.lock();
let (inventory, physics, fluid_on_eyes) =
- self.query::<(&InventoryComponent, &Physics, &FluidOnEyes)>(&mut ecs);
+ self.query::<(&Inventory, &Physics, &FluidOnEyes)>(&mut ecs);
let menu = &inventory.inventory_menu;
accurate_best_tool_in_hotbar_for_block(block, menu, physics, fluid_on_eyes)
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index c354390e..c9283b6b 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -1,7 +1,7 @@
use std::fmt::Formatter;
use azalea_client::{
- inventory::{CloseContainerEvent, ContainerClickEvent, InventoryComponent},
+ inventory::{CloseContainerEvent, ContainerClickEvent, Inventory},
packet_handling::game::PacketEvent,
Client,
};
@@ -65,9 +65,7 @@ impl ContainerClientExt for Client {
}
let ecs = self.ecs.lock();
- let inventory = ecs
- .get::<InventoryComponent>(self.entity)
- .expect("no inventory");
+ let inventory = ecs.get::<Inventory>(self.entity).expect("no inventory");
if inventory.id == 0 {
None
} else {
@@ -87,9 +85,7 @@ impl ContainerClientExt for Client {
/// and [`Menu::slots`].
fn open_inventory(&mut self) -> Option<ContainerHandle> {
let ecs = self.ecs.lock();
- let inventory = ecs
- .get::<InventoryComponent>(self.entity)
- .expect("no inventory");
+ let inventory = ecs.get::<Inventory>(self.entity).expect("no inventory");
if inventory.id == 0 {
Some(ContainerHandle::new(0, self.clone()))
@@ -105,9 +101,7 @@ impl ContainerClientExt for Client {
/// your own inventory.
fn get_open_container(&self) -> Option<ContainerHandleRef> {
let ecs = self.ecs.lock();
- let inventory = ecs
- .get::<InventoryComponent>(self.entity)
- .expect("no inventory");
+ let inventory = ecs.get::<Inventory>(self.entity).expect("no inventory");
if inventory.id == 0 {
None
@@ -157,7 +151,7 @@ impl ContainerHandleRef {
pub fn menu(&self) -> Option<Menu> {
let ecs = self.client.ecs.lock();
let inventory = ecs
- .get::<InventoryComponent>(self.client.entity)
+ .get::<Inventory>(self.client.entity)
.expect("no inventory");
// this also makes sure we can't access the inventory while a container is open
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index becc163d..cb6ba2bb 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -25,7 +25,7 @@ use crate::ecs::{
};
use crate::pathfinder::moves::PathfinderCtx;
use crate::pathfinder::world::CachedWorld;
-use azalea_client::inventory::{InventoryComponent, InventorySet, SetSelectedHotbarSlotEvent};
+use azalea_client::inventory::{Inventory, InventorySet, SetSelectedHotbarSlotEvent};
use azalea_client::mining::{Mining, StartMiningBlockEvent};
use azalea_client::movement::MoveEventsSet;
use azalea_client::{InstanceHolder, StartSprintEvent, StartWalkEvent};
@@ -201,7 +201,7 @@ fn goto_listener(
Option<&ExecutingPath>,
&Position,
&InstanceName,
- &InventoryComponent,
+ &Inventory,
)>,
instance_container: Res<InstanceContainer>,
) {
@@ -364,7 +364,7 @@ fn path_found_listener(
&mut Pathfinder,
Option<&mut ExecutingPath>,
&InstanceName,
- &InventoryComponent,
+ &Inventory,
)>,
instance_container: Res<InstanceContainer>,
mut commands: Commands,
@@ -576,12 +576,7 @@ fn check_node_reached(
}
fn check_for_path_obstruction(
- mut query: Query<(
- &Pathfinder,
- &mut ExecutingPath,
- &InstanceName,
- &InventoryComponent,
- )>,
+ mut query: Query<(&Pathfinder, &mut ExecutingPath, &InstanceName, &Inventory)>,
instance_container: Res<InstanceContainer>,
) {
for (pathfinder, mut executing_path, instance_name, inventory) in &mut query {
@@ -688,7 +683,7 @@ fn tick_execute_path(
&Physics,
Option<&Mining>,
&InstanceHolder,
- &InventoryComponent,
+ &Inventory,
)>,
mut look_at_events: EventWriter<LookAtEvent>,
mut sprint_events: EventWriter<StartSprintEvent>,
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index e8ba4dbd..a24a1acb 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -2,9 +2,7 @@
use std::sync::Arc;
-use azalea_client::{
- inventory::InventoryComponent, packet_handling::game::SendPacketEvent, PhysicsState,
-};
+use azalea_client::{inventory::Inventory, packet_handling::game::SendPacketEvent, PhysicsState};
use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick};
use azalea_entity::{
attributes::AttributeInstance, Attributes, EntityDimensions, LookDirection, Physics, Position,
@@ -22,7 +20,7 @@ pub struct SimulatedPlayerBundle {
pub physics_state: PhysicsState,
pub look_direction: LookDirection,
pub attributes: Attributes,
- pub inventory: InventoryComponent,
+ pub inventory: Inventory,
}
impl SimulatedPlayerBundle {
@@ -41,7 +39,7 @@ impl SimulatedPlayerBundle {
speed: AttributeInstance::new(0.1),
attack_speed: AttributeInstance::new(4.0),
},
- inventory: InventoryComponent::default(),
+ inventory: Inventory::default(),
}
}
}
@@ -108,7 +106,7 @@ fn create_simulation_player_complete_bundle(
partial_instance: Arc::new(RwLock::new(PartialInstance::default())),
instance: instance.clone(),
},
- InventoryComponent::default(),
+ Inventory::default(),
)
}