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

Migrating and enhancing Item related code #6

Open
PauMAVA opened this issue Feb 20, 2021 · 1 comment
Open

Migrating and enhancing Item related code #6

PauMAVA opened this issue Feb 20, 2021 · 1 comment

Comments

@PauMAVA
Copy link
Member

PauMAVA commented Feb 20, 2021

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
Copy link
Member Author

PauMAVA commented Feb 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant