Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename InventoryComponent to Inventory to match other components #177

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions azalea-client/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions azalea-client/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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`].
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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>,
Expand Down Expand Up @@ -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();
Expand All @@ -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>,
) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions azalea-client/src/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -99,7 +99,7 @@ fn handle_auto_mine(
&HitResultComponent,
Entity,
Option<&Mining>,
&InventoryComponent,
&Inventory,
&MineBlockPos,
&MineItem,
),
Expand Down Expand Up @@ -193,7 +193,7 @@ fn handle_start_mining_block_with_direction_event(
mut query: Query<(
&InstanceName,
&LocalGameMode,
&InventoryComponent,
&Inventory,
&FluidOnEyes,
&Physics,
Option<&Mining>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -423,7 +423,7 @@ fn handle_finish_mining_block_event(
mut query: Query<(
&InstanceName,
&LocalGameMode,
&InventoryComponent,
&Inventory,
&PlayerAbilities,
&PermissionLevel,
&mut CurrentSequenceNumber,
Expand Down Expand Up @@ -522,7 +522,7 @@ fn continue_mining_block(
Entity,
&InstanceName,
&LocalGameMode,
&InventoryComponent,
&Inventory,
&MineBlockPos,
&MineItem,
&FluidOnEyes,
Expand Down
2 changes: 1 addition & 1 deletion azalea-client/src/packet_handling/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 3 additions & 5 deletions azalea-client/src/packet_handling/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions azalea/src/auto_tool.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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)
Expand Down
16 changes: 5 additions & 11 deletions azalea/src/container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Formatter;

use azalea_client::{
inventory::{CloseContainerEvent, ContainerClickEvent, InventoryComponent},
inventory::{CloseContainerEvent, ContainerClickEvent, Inventory},
packet_handling::game::PacketEvent,
Client,
};
Expand Down Expand Up @@ -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 {
Expand All @@ -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()))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions azalea/src/pathfinder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -201,7 +201,7 @@ fn goto_listener(
Option<&ExecutingPath>,
&Position,
&InstanceName,
&InventoryComponent,
&Inventory,
)>,
instance_container: Res<InstanceContainer>,
) {
Expand Down Expand Up @@ -364,7 +364,7 @@ fn path_found_listener(
&mut Pathfinder,
Option<&mut ExecutingPath>,
&InstanceName,
&InventoryComponent,
&Inventory,
)>,
instance_container: Res<InstanceContainer>,
mut commands: Commands,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>,
Expand Down
10 changes: 4 additions & 6 deletions azalea/src/pathfinder/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -41,7 +39,7 @@ impl SimulatedPlayerBundle {
speed: AttributeInstance::new(0.1),
attack_speed: AttributeInstance::new(4.0),
},
inventory: InventoryComponent::default(),
inventory: Inventory::default(),
}
}
}
Expand Down Expand Up @@ -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(),
)
}

Expand Down
Loading