1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

ItemSlot -> ItemStack for more consistency with mojmap

This commit is contained in:
mat 2024-11-26 22:08:35 +00:00
parent 4dcd95e182
commit eabb329085
30 changed files with 180 additions and 180 deletions

View file

@ -10,7 +10,7 @@ use azalea_core::{
use azalea_entity::{
clamp_look_direction, view_vector, Attributes, EyeHeight, LocalEntity, LookDirection, Position,
};
use azalea_inventory::{ItemSlot, ItemSlotData};
use azalea_inventory::{ItemStack, ItemStackData};
use azalea_physics::clip::{BlockShapeType, ClipContext, FluidPickType};
use azalea_protocol::packets::game::{
s_interact::InteractionHand,
@ -245,7 +245,7 @@ pub fn check_is_interaction_restricted(
// way of modifying that
let held_item = inventory.held_item();
if let ItemSlot::Present(item) = &held_item {
if let ItemStack::Present(item) = &held_item {
let block = instance.chunks.get_block_state(block_pos);
let Some(block) = block else {
// block isn't loaded so just say that it is restricted
@ -263,7 +263,7 @@ pub fn check_is_interaction_restricted(
/// Check if the item has the `CanDestroy` tag for the block.
pub fn check_block_can_be_broken_by_item_in_adventure_mode(
item: &ItemSlotData,
item: &ItemStackData,
_block: &BlockState,
) -> bool {
// minecraft caches the last checked block but that's kind of an unnecessary

View file

@ -97,7 +97,7 @@ pub struct Inventory {
///
/// This is different from [`Self::selected_hotbar_slot`], which is the
/// item that's selected in the hotbar.
pub carried: ItemSlot,
pub carried: ItemStack,
/// An identifier used by the server to track client inventory desyncs. This
/// is sent on every container click, and it's only ever updated when the
/// server sends a new container update.
@ -182,7 +182,7 @@ impl Inventory {
if let QuickCraftStatus::Add { slot } = quick_craft.status {
let slot_item = self.menu().slot(slot as usize);
if let Some(slot_item) = slot_item {
if let ItemSlot::Present(carried) = &self.carried {
if let ItemStack::Present(carried) = &self.carried {
// minecraft also checks slot.may_place(carried) and
// menu.can_drag_to(slot)
// but they always return true so they're not relevant for us
@ -221,7 +221,7 @@ impl Inventory {
return;
}
let ItemSlot::Present(mut carried) = self.carried.clone() else {
let ItemStack::Present(mut carried) = self.carried.clone() else {
// this should never happen
return self.reset_quick_craft();
};
@ -230,14 +230,14 @@ impl Inventory {
let mut quick_craft_slots_iter = self.quick_craft_slots.iter();
loop {
let mut slot: &ItemSlot;
let mut slot: &ItemStack;
let mut slot_index: u16;
let mut item_stack: &ItemSlot;
let mut item_stack: &ItemStack;
loop {
let Some(&next_slot) = quick_craft_slots_iter.next() else {
carried.count = carried_count;
self.carried = ItemSlot::Present(carried);
self.carried = ItemStack::Present(carried);
return self.reset_quick_craft();
};
@ -258,8 +258,8 @@ impl Inventory {
}
}
// get the ItemSlotData for the slot
let ItemSlot::Present(slot) = slot else {
// get the ItemStackData for the slot
let ItemStack::Present(slot) = slot else {
unreachable!("the loop above requires the slot to be present to break")
};
@ -292,7 +292,7 @@ impl Inventory {
&mut self.inventory_menu
};
*menu.slot_mut(slot_index as usize).unwrap() =
ItemSlot::Present(new_carried);
ItemStack::Present(new_carried);
}
}
} else {
@ -315,7 +315,7 @@ impl Inventory {
// implementation
// player.drop(self.carried, true);
self.carried = ItemSlot::Empty;
self.carried = ItemStack::Empty;
}
}
ClickOperation::Pickup(PickupClick::Right { slot: None }) => {
@ -335,8 +335,8 @@ impl Inventory {
// here
// i don't understand it so i didn't implement it
match slot_item {
ItemSlot::Empty => if carried.is_present() {},
ItemSlot::Present(_) => todo!(),
ItemStack::Empty => if carried.is_present() {},
ItemStack::Present(_) => todo!(),
}
}
ClickOperation::QuickMove(
@ -373,7 +373,7 @@ impl Inventory {
*target_slot = source_slot;
}
} else if source_slot.is_empty() {
let ItemSlot::Present(target_item) = target_slot else {
let ItemStack::Present(target_item) = target_slot else {
unreachable!("target slot is not empty but is not present");
};
if self.menu().may_place(source_slot_index, target_item) {
@ -385,7 +385,7 @@ impl Inventory {
*self.menu_mut().slot_mut(source_slot_index).unwrap() = new_source_slot;
}
} else if self.menu().may_pickup(source_slot_index) {
let ItemSlot::Present(target_item) = target_slot else {
let ItemStack::Present(target_item) = target_slot else {
unreachable!("target slot is not empty but is not present");
};
if self.menu().may_place(source_slot_index, target_item) {
@ -420,12 +420,12 @@ impl Inventory {
let Some(source_slot) = self.menu().slot(*slot as usize) else {
return;
};
let ItemSlot::Present(source_item) = source_slot else {
let ItemStack::Present(source_item) = source_slot else {
return;
};
let mut new_carried = source_item.clone();
new_carried.count = new_carried.kind.max_stack_size();
self.carried = ItemSlot::Present(new_carried);
self.carried = ItemStack::Present(new_carried);
}
ClickOperation::Throw(c) => {
if self.carried.is_present() {
@ -439,7 +439,7 @@ impl Inventory {
let Some(slot) = self.menu_mut().slot_mut(slot_index) else {
return;
};
let ItemSlot::Present(slot_item) = slot else {
let ItemStack::Present(slot_item) = slot else {
return;
};
@ -466,7 +466,7 @@ impl Inventory {
return;
}
let ItemSlot::Present(target_slot_item) = &target_slot else {
let ItemStack::Present(target_slot_item) = &target_slot else {
unreachable!("target slot is not empty but is not present");
};
@ -480,7 +480,7 @@ impl Inventory {
for i in iterator {
if target_slot_item.count < target_slot_item.kind.max_stack_size() {
let checking_slot = self.menu().slot(i).unwrap();
if let ItemSlot::Present(checking_item) = checking_slot {
if let ItemStack::Present(checking_item) = checking_slot {
if can_item_quick_replace(checking_slot, &target_slot, true)
&& self.menu().may_pickup(i)
&& (round != 0
@ -495,7 +495,7 @@ impl Inventory {
// now extend the carried item
let target_slot = &mut self.carried;
let ItemSlot::Present(target_slot_item) = target_slot else {
let ItemStack::Present(target_slot_item) = target_slot else {
unreachable!("target slot is not empty but is not present");
};
target_slot_item.count += taken_item.count();
@ -515,7 +515,7 @@ impl Inventory {
}
/// Get the item in the player's hotbar that is currently being held.
pub fn held_item(&self) -> ItemSlot {
pub fn held_item(&self) -> ItemStack {
let inventory = &self.inventory_menu;
let hotbar_items = &inventory.slots()[inventory.hotbar_slots_range()];
hotbar_items[self.selected_hotbar_slot as usize].clone()
@ -523,14 +523,14 @@ impl Inventory {
}
fn can_item_quick_replace(
target_slot: &ItemSlot,
item: &ItemSlot,
target_slot: &ItemStack,
item: &ItemStack,
ignore_item_count: bool,
) -> bool {
let ItemSlot::Present(target_slot) = target_slot else {
let ItemStack::Present(target_slot) = target_slot else {
return false;
};
let ItemSlot::Present(item) = item else {
let ItemStack::Present(item) = item else {
// i *think* this is what vanilla does
// not 100% sure lol probably doesn't matter though
return false;
@ -551,7 +551,7 @@ fn can_item_quick_replace(
fn get_quick_craft_slot_count(
quick_craft_slots: &HashSet<u16>,
quick_craft_kind: &QuickCraftKind,
item: &mut ItemSlotData,
item: &mut ItemStackData,
slot_item_count: i32,
) {
item.count = match quick_craft_kind {
@ -569,7 +569,7 @@ impl Default for Inventory {
id: 0,
container_menu: None,
container_menu_title: None,
carried: ItemSlot::Empty,
carried: ItemStack::Empty,
state_id: 0,
quick_craft_status: QuickCraftStatusKind::Start,
quick_craft_kind: QuickCraftKind::Middle,
@ -687,7 +687,7 @@ pub fn handle_container_click_event(
// see which slots changed after clicking and put them in the hashmap
// the server uses this to check if we desynced
let mut changed_slots: HashMap<u16, ItemSlot> = HashMap::new();
let mut changed_slots: HashMap<u16, ItemStack> = HashMap::new();
for (slot_index, old_slot) in old_slots.iter().enumerate() {
let new_slot = &menu.slots()[slot_index];
if old_slot != new_slot {
@ -716,7 +716,7 @@ pub fn handle_container_click_event(
#[derive(Event)]
pub struct SetContainerContentEvent {
pub entity: Entity,
pub slots: Vec<ItemSlot>,
pub slots: Vec<ItemStack>,
pub container_id: u8,
}
fn handle_set_container_content_event(

View file

@ -1,7 +1,7 @@
use azalea_block::{Block, BlockState, FluidState};
use azalea_core::{direction::Direction, game_type::GameMode, position::BlockPos, tick::GameTick};
use azalea_entity::{mining::get_mine_progress, FluidOnEyes, Physics};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_physics::PhysicsSet;
use azalea_protocol::packets::game::s_player_action::{self, ServerboundPlayerAction};
use azalea_world::{InstanceContainer, InstanceName};
@ -405,9 +405,9 @@ pub struct MineTicks(pub f32);
pub struct MineBlockPos(pub Option<BlockPos>);
/// A component that contains the item we're currently using to mine. If we're
/// not mining anything, it'll be [`ItemSlot::Empty`].
/// not mining anything, it'll be [`ItemStack::Empty`].
#[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
pub struct MineItem(pub ItemSlot);
pub struct MineItem(pub ItemStack);
/// Sent when we completed mining a block.
#[derive(Event)]

View file

@ -10,7 +10,7 @@ use azalea_core::{
direction::Direction,
position::{BlockPos, GlobalPos, Vec3},
};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use bevy_ecs::component::Component;
use derive_more::Deref;
use enum_as_inner::EnumAsInner;
@ -73,7 +73,7 @@ pub enum EntityDataValue {
String(String),
FormattedText(FormattedText),
OptionalFormattedText(Option<FormattedText>),
ItemStack(ItemSlot),
ItemStack(ItemStack),
Boolean(bool),
Rotations(Rotations),
BlockPos(BlockPos),

View file

@ -8,7 +8,7 @@ use azalea_core::{
direction::Direction,
position::{BlockPos, Vec3},
};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use bevy_ecs::{bundle::Bundle, component::Component};
use derive_more::{Deref, DerefMut};
use thiserror::Error;
@ -3242,7 +3242,7 @@ impl Default for DrownedMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct EggItemStack(pub ItemSlot);
pub struct EggItemStack(pub ItemStack);
#[derive(Component)]
pub struct Egg;
impl Egg {
@ -3499,7 +3499,7 @@ impl Default for EnderDragonMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct EnderPearlItemStack(pub ItemSlot);
pub struct EnderPearlItemStack(pub ItemStack);
#[derive(Component)]
pub struct EnderPearl;
impl EnderPearl {
@ -3835,7 +3835,7 @@ impl Default for EvokerFangsMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ExperienceBottleItemStack(pub ItemSlot);
pub struct ExperienceBottleItemStack(pub ItemStack);
#[derive(Component)]
pub struct ExperienceBottle;
impl ExperienceBottle {
@ -3932,7 +3932,7 @@ impl Default for ExperienceOrbMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct EyeOfEnderItemStack(pub ItemSlot);
pub struct EyeOfEnderItemStack(pub ItemStack);
#[derive(Component)]
pub struct EyeOfEnder;
impl EyeOfEnder {
@ -4036,7 +4036,7 @@ impl Default for FallingBlockMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct FireballItemStack(pub ItemSlot);
pub struct FireballItemStack(pub ItemStack);
#[derive(Component)]
pub struct Fireball;
impl Fireball {
@ -4088,7 +4088,7 @@ impl Default for FireballMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct FireworksItem(pub ItemSlot);
pub struct FireworksItem(pub ItemStack);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct AttachedToTarget(pub OptionalUnsignedInt);
#[derive(Component, Deref, DerefMut, Clone)]
@ -4623,7 +4623,7 @@ impl Default for GiantMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ItemFrameItem(pub ItemSlot);
pub struct ItemFrameItem(pub ItemStack);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct Rotation(pub i32);
#[derive(Component)]
@ -4669,7 +4669,7 @@ impl Default for GlowItemFrameMetadataBundle {
pose: Pose::default(),
ticks_frozen: TicksFrozen(Default::default()),
},
item_frame_item: ItemFrameItem(ItemSlot::Empty),
item_frame_item: ItemFrameItem(ItemStack::Empty),
rotation: Rotation(0),
},
}
@ -5462,7 +5462,7 @@ impl Default for IronGolemMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ItemItem(pub ItemSlot);
pub struct ItemItem(pub ItemStack);
#[derive(Component)]
pub struct Item;
impl Item {
@ -5508,7 +5508,7 @@ impl Default for ItemMetadataBundle {
pose: Pose::default(),
ticks_frozen: TicksFrozen(Default::default()),
},
item_item: ItemItem(ItemSlot::Empty),
item_item: ItemItem(ItemStack::Empty),
}
}
}
@ -5544,7 +5544,7 @@ pub struct ItemDisplayHeight(pub f32);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ItemDisplayGlowColorOverride(pub i32);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ItemDisplayItemStack(pub ItemSlot);
pub struct ItemDisplayItemStack(pub ItemStack);
#[derive(Component, Deref, DerefMut, Clone)]
pub struct ItemDisplayItemDisplay(pub u8);
#[derive(Component)]
@ -5699,7 +5699,7 @@ impl Default for ItemDisplayMetadataBundle {
item_display_width: ItemDisplayWidth(0.0),
item_display_height: ItemDisplayHeight(0.0),
item_display_glow_color_override: ItemDisplayGlowColorOverride(-1),
item_display_item_stack: ItemDisplayItemStack(ItemSlot::Empty),
item_display_item_stack: ItemDisplayItemStack(ItemStack::Empty),
item_display_item_display: ItemDisplayItemDisplay(Default::default()),
}
}
@ -5754,7 +5754,7 @@ impl Default for ItemFrameMetadataBundle {
pose: Pose::default(),
ticks_frozen: TicksFrozen(Default::default()),
},
item_frame_item: ItemFrameItem(ItemSlot::Empty),
item_frame_item: ItemFrameItem(ItemStack::Empty),
rotation: Rotation(0),
}
}
@ -6974,7 +6974,7 @@ impl Default for OcelotMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct OminousItemSpawnerItem(pub ItemSlot);
pub struct OminousItemSpawnerItem(pub ItemStack);
#[derive(Component)]
pub struct OminousItemSpawner;
impl OminousItemSpawner {
@ -7020,7 +7020,7 @@ impl Default for OminousItemSpawnerMetadataBundle {
pose: Pose::default(),
ticks_frozen: TicksFrozen(Default::default()),
},
ominous_item_spawner_item: OminousItemSpawnerItem(ItemSlot::Empty),
ominous_item_spawner_item: OminousItemSpawnerItem(ItemStack::Empty),
}
}
}
@ -8052,7 +8052,7 @@ impl Default for PolarBearMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct PotionItemStack(pub ItemSlot);
pub struct PotionItemStack(pub ItemStack);
#[derive(Component)]
pub struct Potion;
impl Potion {
@ -8937,7 +8937,7 @@ impl Default for SlimeMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct SmallFireballItemStack(pub ItemSlot);
pub struct SmallFireballItemStack(pub ItemStack);
#[derive(Component)]
pub struct SmallFireball;
impl SmallFireball {
@ -9148,7 +9148,7 @@ impl Default for SnowGolemMetadataBundle {
}
#[derive(Component, Deref, DerefMut, Clone)]
pub struct SnowballItemStack(pub ItemSlot);
pub struct SnowballItemStack(pub ItemStack);
#[derive(Component)]
pub struct Snowball;
impl Snowball {

View file

@ -1,6 +1,6 @@
use azalea_buf::McBuf;
use azalea_core::position::BlockPos;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_registry::ParticleKind;
use bevy_ecs::component::Component;
@ -286,7 +286,7 @@ pub struct DustColorTransitionParticle {
#[derive(Debug, Clone, McBuf, Default)]
pub struct ItemParticle {
pub item: ItemSlot,
pub item: ItemStack,
}
#[derive(Debug, Clone, McBuf, Default)]

View file

@ -34,11 +34,11 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
}
/// Player {
/// craft_result: ItemSlot,
/// craft: [ItemSlot; 4],
/// armor: [ItemSlot; 4],
/// inventory: [ItemSlot; 36],
/// offhand: ItemSlot,
/// craft_result: ItemStack,
/// craft: [ItemStack; 4],
/// armor: [ItemStack; 4],
/// inventory: [ItemStack; 36],
/// offhand: ItemStack,
/// },
fn generate_variant_for_menu(menu: &Menu) -> TokenStream {
let name = &menu.name;
@ -56,7 +56,7 @@ fn generate_fields(fields: &[Field], public: bool) -> TokenStream {
for field in fields {
let field_length = field.length;
let field_type = if field.length == 1 {
quote! { ItemSlot }
quote! { ItemStack }
} else {
quote! { SlotList<#field_length> }
};

View file

@ -95,11 +95,11 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
impl Menu {
#menu_consts
/// Get a mutable reference to the [`ItemSlot`] at the given protocol index.
/// Get a mutable reference to the [`ItemStack`] at the given protocol index.
///
/// If you're trying to get an item in a menu without caring about
/// protocol indexes, you should just `match` it and index the
/// [`ItemSlot`] you get.
/// [`ItemStack`] you get.
///
/// Use [`Menu::slot`] if you don't need a mutable reference to the slot.
///
@ -107,24 +107,24 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
///
/// Returns `None` if the index is out of bounds.
#[inline]
pub fn slot_mut(&mut self, i: usize) -> Option<&mut ItemSlot> {
pub fn slot_mut(&mut self, i: usize) -> Option<&mut ItemStack> {
Some(match self {
#slot_mut_match_variants
})
}
/// Get a reference to the [`ItemSlot`] at the given protocol index.
/// Get a reference to the [`ItemStack`] at the given protocol index.
///
/// If you're trying to get an item in a menu without caring about
/// protocol indexes, you should just `match` it and index the
/// [`ItemSlot`] you get.
/// [`ItemStack`] you get.
///
/// Use [`Menu::slot_mut`] if you need a mutable reference to the slot.
///
/// # Errors
///
/// Returns `None` if the index is out of bounds.
pub fn slot(&self, i: usize) -> Option<&ItemSlot> {
pub fn slot(&self, i: usize) -> Option<&ItemStack> {
Some(match self {
#slot_match_variants
})
@ -153,7 +153,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
///
/// If you *only* want to include the players inventory, then you can filter by only
/// using the slots in [`Self::player_slots_range`].
pub fn slots(&self) -> Vec<ItemSlot> {
pub fn slots(&self) -> Vec<ItemStack> {
match self {
#slots_match_variants
}
@ -162,7 +162,7 @@ pub fn generate(input: &DeclareMenus) -> TokenStream {
/// Return the contents of the menu, not including the player's inventory.
///
/// If you want to include the player's inventory, use [`Menu::slots`] instead.
pub fn contents(&self) -> Vec<ItemSlot> {
pub fn contents(&self) -> Vec<ItemStack> {
match self {
#contents_match_variants
}

View file

@ -11,7 +11,7 @@ use azalea_registry::{
use simdnbt::owned::{Nbt, NbtCompound};
use uuid::Uuid;
use crate::ItemSlot;
use crate::ItemStack;
pub trait DataComponent: Send + Sync + Any {}
@ -427,13 +427,13 @@ impl DataComponent for MapPostProcessing {}
#[derive(Clone, PartialEq, McBuf)]
pub struct ChargedProjectiles {
pub items: Vec<ItemSlot>,
pub items: Vec<ItemStack>,
}
impl DataComponent for ChargedProjectiles {}
#[derive(Clone, PartialEq, McBuf)]
pub struct BundleContents {
pub items: Vec<ItemSlot>,
pub items: Vec<ItemStack>,
}
impl DataComponent for BundleContents {}
@ -629,7 +629,7 @@ impl DataComponent for PotDecorations {}
#[derive(Clone, PartialEq, McBuf)]
pub struct Container {
pub items: Vec<ItemSlot>,
pub items: Vec<ItemStack>,
}
impl DataComponent for Container {}
@ -699,7 +699,7 @@ pub enum ItemUseAnimation {
#[derive(Clone, PartialEq, McBuf)]
pub struct UseRemainder {
pub convert_into: ItemSlot,
pub convert_into: ItemStack,
}
impl DataComponent for UseRemainder {}

View file

@ -2,9 +2,9 @@ pub trait MaxStackSizeExt {
/// Get the maximum stack size for this item.
///
/// This is a signed integer to be consistent with the `count` field of
/// [`ItemSlotData`].
/// [`ItemStackData`].
///
/// [`ItemSlotData`]: crate::ItemSlotData
/// [`ItemStackData`]: crate::ItemStackData
fn max_stack_size(&self) -> i32;
/// Whether this item can be stacked with other items.

View file

@ -9,17 +9,17 @@ mod slot;
use std::ops::{Deref, DerefMut, RangeInclusive};
use azalea_inventory_macros::declare_menus;
pub use slot::{DataComponentPatch, ItemSlot, ItemSlotData};
pub use slot::{DataComponentPatch, ItemStack, ItemStackData};
// TODO: remove this here and in azalea-inventory-macros when rust makes
// Default be implemented for all array sizes
// https://github.com/rust-lang/rust/issues/61415
/// A fixed-size list of [`ItemSlot`]s.
/// A fixed-size list of [`ItemStack`]s.
#[derive(Debug, Clone)]
pub struct SlotList<const N: usize>([ItemSlot; N]);
pub struct SlotList<const N: usize>([ItemStack; N]);
impl<const N: usize> Deref for SlotList<N> {
type Target = [ItemSlot; N];
type Target = [ItemStack; N];
fn deref(&self) -> &Self::Target {
&self.0
}
@ -31,7 +31,7 @@ impl<const N: usize> DerefMut for SlotList<N> {
}
impl<const N: usize> Default for SlotList<N> {
fn default() -> Self {
SlotList([(); N].map(|_| ItemSlot::Empty))
SlotList([(); N].map(|_| ItemStack::Empty))
}
}

View file

@ -8,7 +8,7 @@ use crate::{
CraftingMenuLocation, EnchantmentMenuLocation, FurnaceMenuLocation, Generic3x3MenuLocation,
Generic9x1MenuLocation, Generic9x2MenuLocation, Generic9x3MenuLocation, Generic9x4MenuLocation,
Generic9x5MenuLocation, Generic9x6MenuLocation, GrindstoneMenuLocation, HopperMenuLocation,
ItemSlot, ItemSlotData, LecternMenuLocation, LoomMenuLocation, Menu, MenuLocation,
ItemStack, ItemStackData, LecternMenuLocation, LoomMenuLocation, Menu, MenuLocation,
MerchantMenuLocation, Player, PlayerMenuLocation, ShulkerBoxMenuLocation, SmithingMenuLocation,
SmokerMenuLocation, StonecutterMenuLocation,
};
@ -266,10 +266,10 @@ impl Menu {
///
/// Keep in mind that this doesn't send any packets to the server, it just
/// mutates this specific `Menu`.
pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemSlot {
pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemStack {
let slot = self.slot(slot_index);
if slot.is_none() {
return ItemSlot::Empty;
return ItemStack::Empty;
};
let slot_location = self
@ -587,7 +587,7 @@ impl Menu {
},
}
ItemSlot::Empty
ItemStack::Empty
}
fn try_move_item_to_slots_or_toggle_hotbar(
@ -610,7 +610,7 @@ impl Menu {
/// Whether the given item could be placed in this menu.
///
/// TODO: right now this always returns true
pub fn may_place(&self, _target_slot_index: usize, _item: &ItemSlotData) -> bool {
pub fn may_place(&self, _target_slot_index: usize, _item: &ItemStackData) -> bool {
true
}
@ -662,14 +662,14 @@ impl Menu {
/// slot is present and the same item.
fn move_item_to_slot_if_stackable(
&mut self,
item_slot: &mut ItemSlot,
item_slot: &mut ItemStack,
target_slot_index: usize,
) {
let ItemSlot::Present(item) = item_slot else {
let ItemStack::Present(item) = item_slot else {
return;
};
let target_slot = self.slot(target_slot_index).unwrap();
if let ItemSlot::Present(target_item) = target_slot {
if let ItemStack::Present(target_item) = target_slot {
// the target slot is empty, so we can just move the item there
if self.may_place(target_slot_index, item)
&& target_item.is_same_item_and_components(item)
@ -679,15 +679,15 @@ impl Menu {
// get the target slot again but mut this time so we can update it
let target_slot = self.slot_mut(target_slot_index).unwrap();
*target_slot = ItemSlot::Present(new_target_slot_data);
*target_slot = ItemStack::Present(new_target_slot_data);
item_slot.update_empty();
}
}
}
fn move_item_to_slot_if_empty(&mut self, item_slot: &mut ItemSlot, target_slot_index: usize) {
let ItemSlot::Present(item) = item_slot else {
fn move_item_to_slot_if_empty(&mut self, item_slot: &mut ItemStack, target_slot_index: usize) {
let ItemStack::Present(item) = item_slot else {
return;
};
let target_slot = self.slot(target_slot_index).unwrap();
@ -696,7 +696,7 @@ impl Menu {
let new_target_slot_data = item.split(u32::min(slot_item_limit, item.count as u32));
let target_slot = self.slot_mut(target_slot_index).unwrap();
*target_slot = ItemSlot::Present(new_target_slot_data);
*target_slot = ItemStack::Present(new_target_slot_data);
item_slot.update_empty();
}
}

View file

@ -11,27 +11,27 @@ use crate::components::{self};
/// Either an item in an inventory or nothing.
#[derive(Debug, Clone, Default, PartialEq)]
pub enum ItemSlot {
pub enum ItemStack {
#[default]
Empty,
Present(ItemSlotData),
Present(ItemStackData),
}
impl ItemSlot {
/// Check if the slot is ItemSlot::Empty, if the count is <= 0, or if the
impl ItemStack {
/// Check if the slot is ItemStack::Empty, if the count is <= 0, or if the
/// item is air.
///
/// This is the opposite of [`ItemSlot::is_present`].
/// This is the opposite of [`ItemStack::is_present`].
pub fn is_empty(&self) -> bool {
match self {
ItemSlot::Empty => true,
ItemSlot::Present(item) => item.is_empty(),
ItemStack::Empty => true,
ItemStack::Present(item) => item.is_empty(),
}
}
/// Check if the slot is not ItemSlot::Empty, if the count is > 0, and if
/// Check if the slot is not ItemStack::Empty, if the count is > 0, and if
/// the item is not air.
///
/// This is the opposite of [`ItemSlot::is_empty`].
/// This is the opposite of [`ItemStack::is_empty`].
pub fn is_present(&self) -> bool {
!self.is_empty()
}
@ -42,21 +42,21 @@ impl ItemSlot {
/// slot is present.
pub fn count(&self) -> i32 {
match self {
ItemSlot::Empty => 0,
ItemSlot::Present(i) => i.count,
ItemStack::Empty => 0,
ItemStack::Present(i) => i.count,
}
}
/// Remove `count` items from this slot, returning the removed items.
pub fn split(&mut self, count: u32) -> ItemSlot {
pub fn split(&mut self, count: u32) -> ItemStack {
match self {
ItemSlot::Empty => ItemSlot::Empty,
ItemSlot::Present(i) => {
ItemStack::Empty => ItemStack::Empty,
ItemStack::Present(i) => {
let returning = i.split(count);
if i.is_empty() {
*self = ItemSlot::Empty;
*self = ItemStack::Empty;
}
ItemSlot::Present(returning)
ItemStack::Present(returning)
}
}
}
@ -65,33 +65,33 @@ impl ItemSlot {
/// [`azalea_registry::Item::Air`]
pub fn kind(&self) -> azalea_registry::Item {
match self {
ItemSlot::Empty => azalea_registry::Item::Air,
ItemSlot::Present(i) => i.kind,
ItemStack::Empty => azalea_registry::Item::Air,
ItemStack::Present(i) => i.kind,
}
}
/// Update whether this slot is empty, based on the count.
pub fn update_empty(&mut self) {
if let ItemSlot::Present(i) = self {
if let ItemStack::Present(i) = self {
if i.is_empty() {
*self = ItemSlot::Empty;
*self = ItemStack::Empty;
}
}
}
/// Convert this slot into an [`ItemSlotData`], if it's present.
pub fn as_present(&self) -> Option<&ItemSlotData> {
/// Convert this slot into an [`ItemStackData`], if it's present.
pub fn as_present(&self) -> Option<&ItemStackData> {
match self {
ItemSlot::Empty => None,
ItemSlot::Present(i) => Some(i),
ItemStack::Empty => None,
ItemStack::Present(i) => Some(i),
}
}
}
/// An item in an inventory, with a count and NBT. Usually you want [`ItemSlot`]
/// or [`azalea_registry::Item`] instead.
/// An item in an inventory, with a count and NBT. Usually you want
/// [`ItemStack`] or [`azalea_registry::Item`] instead.
#[derive(Debug, Clone, PartialEq)]
pub struct ItemSlotData {
pub struct ItemStackData {
/// The amount of the item in this slot.
///
/// The count can be zero or negative, but this is rare.
@ -100,9 +100,9 @@ pub struct ItemSlotData {
pub components: DataComponentPatch,
}
impl ItemSlotData {
impl ItemStackData {
/// Remove `count` items from this slot, returning the removed items.
pub fn split(&mut self, count: u32) -> ItemSlotData {
pub fn split(&mut self, count: u32) -> ItemStackData {
let returning_count = i32::min(count as i32, self.count);
let mut returning = self.clone();
returning.count = returning_count;
@ -118,14 +118,14 @@ impl ItemSlotData {
/// Whether this item is the same as another item, ignoring the count.
///
/// ```
/// # use azalea_inventory::ItemSlotData;
/// # use azalea_inventory::ItemStackData;
/// # use azalea_registry::Item;
/// let mut a = ItemSlotData {
/// let mut a = ItemStackData {
/// kind: Item::Stone,
/// count: 1,
/// components: Default::default(),
/// };
/// let mut b = ItemSlotData {
/// let mut b = ItemStackData {
/// kind: Item::Stone,
/// count: 2,
/// components: Default::default(),
@ -135,20 +135,20 @@ impl ItemSlotData {
/// b.kind = Item::Dirt;
/// assert!(!a.is_same_item_and_components(&b));
/// ```
pub fn is_same_item_and_components(&self, other: &ItemSlotData) -> bool {
pub fn is_same_item_and_components(&self, other: &ItemStackData) -> bool {
self.kind == other.kind && self.components == other.components
}
}
impl McBufReadable for ItemSlot {
impl McBufReadable for ItemStack {
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let count = i32::var_read_from(buf)?;
if count <= 0 {
Ok(ItemSlot::Empty)
Ok(ItemStack::Empty)
} else {
let kind = azalea_registry::Item::read_from(buf)?;
let components = DataComponentPatch::read_from(buf)?;
Ok(ItemSlot::Present(ItemSlotData {
Ok(ItemStack::Present(ItemStackData {
count,
kind,
components,
@ -157,11 +157,11 @@ impl McBufReadable for ItemSlot {
}
}
impl McBufWritable for ItemSlot {
impl McBufWritable for ItemStack {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
match self {
ItemSlot::Empty => 0.var_write_into(buf)?,
ItemSlot::Present(i) => {
ItemStack::Empty => 0.var_write_into(buf)?,
ItemStack::Present(i) => {
i.count.var_write_into(buf)?;
i.kind.write_into(buf)?;
i.components.write_into(buf)?;

View file

@ -5,7 +5,7 @@ use azalea_core::{
math::{self, lerp, EPSILON},
position::{BlockPos, Vec3},
};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_world::ChunkStorage;
use bevy_ecs::entity::Entity;
@ -52,7 +52,7 @@ pub enum FluidPickType {
pub struct EntityCollisionContext {
pub descending: bool,
pub entity_bottom: f64,
pub held_item: ItemSlot,
pub held_item: ItemStack,
// pub can_stand_on_fluid: Box<dyn Fn(&FluidState) -> bool>,
pub entity: Entity,
}

View file

@ -128,8 +128,8 @@ pub enum BrigadierParser {
ScoreHolder { allows_multiple: bool },
Swizzle,
Team,
ItemSlot,
ItemSlots,
ItemStack,
ItemStacks,
ResourceLocation,
Function,
EntityAnchor,

View file

@ -1,5 +1,5 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@ -7,6 +7,6 @@ pub struct ClientboundContainerSetContent {
pub container_id: i8,
#[var]
pub state_id: u32,
pub items: Vec<ItemSlot>,
pub carried_item: ItemSlot,
pub items: Vec<ItemStack>,
pub carried_item: ItemStack,
}

View file

@ -1,5 +1,5 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@ -8,5 +8,5 @@ pub struct ClientboundContainerSetSlot {
#[var]
pub state_id: u32,
pub slot: u16,
pub item_stack: ItemSlot,
pub item_stack: ItemStack,
}

View file

@ -1,5 +1,5 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@ -17,9 +17,9 @@ pub struct ClientboundMerchantOffers {
#[derive(Clone, Debug, McBuf)]
pub struct MerchantOffer {
pub base_cost_a: ItemSlot,
pub result: ItemSlot,
pub cost_b: ItemSlot,
pub base_cost_a: ItemStack,
pub result: ItemStack,
pub cost_b: ItemStack,
pub out_of_stock: bool,
pub uses: u32,
pub max_uses: u32,

View file

@ -1,8 +1,8 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundSetCursorItem {
pub contents: Option<ItemSlot>,
pub contents: Option<ItemStack>,
}

View file

@ -2,7 +2,7 @@ use std::io::Cursor;
use azalea_buf::{BufReadError, McBuf};
use azalea_buf::{McBufReadable, McBufWritable};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@ -14,7 +14,7 @@ pub struct ClientboundSetEquipment {
#[derive(Clone, Debug)]
pub struct EquipmentSlots {
pub slots: Vec<(EquipmentSlot, ItemSlot)>,
pub slots: Vec<(EquipmentSlot, ItemStack)>,
}
impl McBufReadable for EquipmentSlots {
@ -29,7 +29,7 @@ impl McBufReadable for EquipmentSlots {
id: equipment_byte.into(),
}
})?;
let item = ItemSlot::read_from(buf)?;
let item = ItemStack::read_from(buf)?;
slots.push((equipment_slot, item));
if equipment_byte & 128 == 0 {
break;

View file

@ -1,10 +1,10 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
pub struct ClientboundSetPlayerInventory {
#[var]
pub slot: i32,
pub contents: Option<ItemSlot>,
pub contents: Option<ItemStack>,
}

View file

@ -4,7 +4,7 @@ use std::io::Cursor;
use azalea_buf::McBuf;
use azalea_chat::FormattedText;
use azalea_core::resource_location::ResourceLocation;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
#[derive(Clone, Debug, McBuf, ClientboundGamePacket)]
@ -27,7 +27,7 @@ pub struct Advancement {
pub struct DisplayInfo {
pub title: FormattedText,
pub description: FormattedText,
pub icon: ItemSlot,
pub icon: ItemStack,
pub frame: FrameType,
pub show_toast: bool,
pub hidden: bool,
@ -133,7 +133,7 @@ mod tests {
display: Some(DisplayInfo {
title: FormattedText::from("title".to_string()),
description: FormattedText::from("description".to_string()),
icon: ItemSlot::Empty,
icon: ItemStack::Empty,
frame: FrameType::Task,
show_toast: true,
hidden: false,

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use azalea_buf::McBuf;
use azalea_core::resource_location::ResourceLocation;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ClientboundGamePacket;
use azalea_registry::HolderSet;
@ -27,7 +27,7 @@ pub struct SelectableRecipe {
pub enum SlotDisplayData {
Empty,
AnyFuel,
Item(ItemSlotDisplay),
Item(ItemStackDisplay),
ItemStack(ItemStackSlotDisplay),
Tag(ResourceLocation),
SmithingTrim(Box<SmithingTrimDemoSlotDisplay>),
@ -36,12 +36,12 @@ pub enum SlotDisplayData {
}
#[derive(Clone, Debug, PartialEq, McBuf)]
pub struct ItemSlotDisplay {
pub struct ItemStackDisplay {
pub item: azalea_registry::Item,
}
#[derive(Clone, Debug, PartialEq, McBuf)]
pub struct ItemStackSlotDisplay {
pub stack: ItemSlot,
pub stack: ItemStack,
}
#[derive(Clone, Debug, PartialEq, McBuf)]
pub struct TagSlotDisplay {

View file

@ -1,7 +1,7 @@
use std::collections::HashMap;
use azalea_buf::McBuf;
use azalea_inventory::{operations::ClickType, ItemSlot};
use azalea_inventory::{operations::ClickType, ItemStack};
use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, McBuf, ServerboundGamePacket)]
@ -12,6 +12,6 @@ pub struct ServerboundContainerClick {
pub slot_num: i16,
pub button_num: u8,
pub click_type: ClickType,
pub changed_slots: HashMap<u16, ItemSlot>,
pub carried_item: ItemSlot,
pub changed_slots: HashMap<u16, ItemStack>,
pub carried_item: ItemStack,
}

View file

@ -1,9 +1,9 @@
use azalea_buf::McBuf;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use azalea_protocol_macros::ServerboundGamePacket;
#[derive(Clone, Debug, McBuf, ServerboundGamePacket)]
pub struct ServerboundSetCreativeModeSlot {
pub slot_num: u16,
pub item_stack: ItemSlot,
pub item_stack: ItemStack,
}

View file

@ -1504,8 +1504,8 @@ enum CommandArgumentKind {
ScoreHolder => "minecraft:score_holder",
Swizzle => "minecraft:swizzle",
Team => "minecraft:team",
ItemSlot => "minecraft:item_slot",
ItemSlots => "minecraft:item_slots",
ItemStack => "minecraft:item_slot",
ItemStacks => "minecraft:item_slots",
ResourceLocation => "minecraft:resource_location",
Function => "minecraft:function",
EntityAnchor => "minecraft:entity_anchor",

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use azalea::{prelude::*, BlockPos};
use azalea_inventory::operations::QuickMoveClick;
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use parking_lot::Mutex;
#[tokio::main]
@ -59,7 +59,7 @@ async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<(
.enumerate()
{
println!("Checking slot {index}: {slot:?}");
if let ItemSlot::Present(item) = slot {
if let ItemStack::Present(item) = slot {
if item.kind == azalea::registry::Item::Diamond {
println!("clicking slot ^");
chest.click(QuickMoveClick::Left { slot: index as u16 });

View file

@ -1,7 +1,7 @@
use azalea_block::{Block, BlockState};
use azalea_client::{inventory::Inventory, Client};
use azalea_entity::{FluidOnEyes, Physics};
use azalea_inventory::{ItemSlot, Menu};
use azalea_inventory::{ItemStack, Menu};
use azalea_registry::{DataComponentKind, Fluid};
#[derive(Debug)]
@ -80,7 +80,7 @@ pub fn accurate_best_tool_in_hotbar_for_block(
for (i, item_slot) in hotbar_slots.iter().enumerate() {
let this_item_speed;
match item_slot {
ItemSlot::Empty => {
ItemStack::Empty => {
this_item_speed = Some(azalea_entity::mining::get_mine_progress(
block.as_ref(),
azalea_registry::Item::Air,
@ -89,7 +89,7 @@ pub fn accurate_best_tool_in_hotbar_for_block(
physics,
));
}
ItemSlot::Present(item_slot) => {
ItemStack::Present(item_slot) => {
// lazy way to avoid checking durability since azalea doesn't have durability
// data yet
if item_slot
@ -119,7 +119,7 @@ pub fn accurate_best_tool_in_hotbar_for_block(
// now check every item
for (i, item_slot) in hotbar_slots.iter().enumerate() {
if let ItemSlot::Present(item_slot) = item_slot {
if let ItemStack::Present(item_slot) = item_slot {
let this_item_speed = azalea_entity::mining::get_mine_progress(
block.as_ref(),
item_slot.kind,

View file

@ -7,7 +7,7 @@ use azalea_client::{
Client,
};
use azalea_core::position::BlockPos;
use azalea_inventory::{operations::ClickOperation, ItemSlot, Menu};
use azalea_inventory::{operations::ClickOperation, ItemStack, Menu};
use azalea_protocol::packets::game::ClientboundGamePacket;
use bevy_app::{App, Plugin, Update};
use bevy_ecs::{component::Component, prelude::EventReader, system::Commands};
@ -168,7 +168,7 @@ impl ContainerHandleRef {
/// Returns the item slots in the container, not including the player's
/// inventory. If the container is closed, this will return `None`.
pub fn contents(&self) -> Option<Vec<ItemSlot>> {
pub fn contents(&self) -> Option<Vec<ItemStack>> {
self.menu().map(|menu| menu.contents())
}
@ -222,7 +222,7 @@ impl ContainerHandle {
/// Returns the item slots in the container, not including the player's
/// inventory. If the container is closed, this will return `None`.
pub fn contents(&self) -> Option<Vec<ItemSlot>> {
pub fn contents(&self) -> Option<Vec<ItemStack>> {
self.0.contents()
}

View file

@ -111,7 +111,7 @@ use azalea_core::{
direction::Direction,
position::{BlockPos, Vec3},
};
use azalea_inventory::ItemSlot;
use azalea_inventory::ItemStack;
use bevy_ecs::{bundle::Bundle, component::Component};
use derive_more::{Deref, DerefMut};
use thiserror::Error;
@ -428,7 +428,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
elif type_name == 'OptionalUnsignedInt':
default = f'OptionalUnsignedInt(Some({default}))' if default != 'Empty' else 'OptionalUnsignedInt(None)'
elif type_name == 'ItemStack':
default = f'ItemSlot::Present({default})' if default != 'Empty' else 'ItemSlot::Empty'
default = f'ItemStack::Present({default})' if default != 'Empty' else 'ItemStack::Empty'
elif type_name == 'BlockState':
default = f'{default}' if default != 'Empty' else 'azalea_block::BlockState::AIR'
elif type_name == 'OptionalBlockState':