libcraft icon indicating copy to clipboard operation
libcraft copied to clipboard

Migrating and enhancing Item related code

Open PauMAVA opened this issue 4 years ago • 1 comments

This issue is to track all item-related code implemented in the feather repo that should be migrated to libcraft.

If I'm not wrong that would be the code under the core/items crate and the definition of Item in definitions. This would also require the migration of the code generator under feather/definitions.

It would also be great to add the Enchantments to the ItemStack struct and other related ItemStack data.

PauMAVA avatar Feb 20 '21 21:02 PauMAVA

Added ItemStack struct.

Changes to existing functions:

  • has_same_type no longer checks for the item damage.
  • remove will return Result<u32, ()> instead of a bool being the Ok variant the current count of the ItemStack.
  • take returns Result<ItemStack, ()> as the take might fail if there are not enough items to be taken.
  • take_half uses the take function to take half the stack. It returns ItemStack by unwrapping the result as the take function will never fail if we call it with an amount of (self.count as f64 / 2 as f64).ceil() as u32
  • merge_with returns a bool instead of ()
  • Replaced &mut ItemStack with &mut Self

Added functions:

  • has_same_damage: Checks if two ItemStack structs have the same damage value.
  • has_same_count: Checks if two ItemStack structs have the same count.
  • has_same_type_and_count: Checks if two ItemStack structs have the same type and count.
  • has_same_type_and_damage: The old has_same_type. Checks if two ItemStack structs have the same type and damage.

TODO:

  • Add the codegen for Item. For now, I am using a dummy Item struct.
  • Create a separate crate for items in core.
  • Add enchantments and other item data such as title, lore, etc., and its functions.

I will continue with these missing features tomorrow.

Commit

PauMAVA avatar Feb 20 '21 23:02 PauMAVA