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

Container API first pass refactor and cleanup #85

Closed

Conversation

StripedMonkey
Copy link
Contributor

This is a refactor of the Container API to make it a little nicer.

I'm looking for feedback from @Bryntet above anything, but we'll see when we get there.

Once changes have been discussed, I will chunk out commits a little better.

@StripedMonkey StripedMonkey changed the title first pass refactor and cleanup Container API first pass refactor and cleanup Sep 8, 2024
@Bryntet

This comment was marked as outdated.

Copy link
Contributor

@Bryntet Bryntet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice PR, still a few todo!():s that need to be sorted out, and a few places where you can shorten what's being written. but overall very good, all the structural changes have my full approval!

}

fn internal_pumpkin_id(&self) -> u64 {
0
}

fn get_slot(&self, slot: usize) -> Option<&Option<ItemStack>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put a doc comment here, explaining the difference between the two Option

pumpkin-inventory/src/lib.rs Outdated Show resolved Hide resolved
*container.all_slots()[slot] = item_slot;
}
let all_slots = container.iter_slots_mut().enumerate();
// let slots = if slot > 35 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code works, but only for the case of being inside of Inventory. Implementing this should be easy now if we use Container::size

@@ -57,13 +57,19 @@ impl PlayerInventory {
if !(0..=45).contains(&slot) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed, as you added a check below

@@ -57,13 +57,19 @@ impl PlayerInventory {
if !(0..=45).contains(&slot) {
Err(InventoryError::InvalidSlot)?
}
*self.all_slots()[slot] = item;
let Some(slot) = self.get_slot_mut(slot) else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to let slot = self.get_slot_mut(slot).ok_or(Err(InventoryError::InvalidSlot))?;

return Ok(());
}
let slot_condition = self.slot_condition(slot)?;
if let Some(item) = item {
if slot_condition(&item) {
*self.all_slots()[slot] = Some(item);
let Some(slot) = self.get_slot_mut(slot) else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to let slot = self.get_slot_mut(slot).ok_or(Err(InventoryError::InvalidSlot))?;

pumpkin-inventory/src/player.rs Outdated Show resolved Hide resolved
pumpkin-inventory/src/lib.rs Outdated Show resolved Hide resolved
pumpkin-inventory/src/lib.rs Outdated Show resolved Hide resolved
pumpkin-inventory/src/open_container.rs Outdated Show resolved Hide resolved
Some(container) => Box::new(
container
.iter_slots_mut()
.chain(self.inventory.iter_slots_mut()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If container is Some on OptionallyCombinedContainer only chain it with the main inventory slots on PlayerInventory. The client is not able to change things (like armour) while inside of a container.

See https://wiki.vg/Inventory for a nice visualisation of where each slot goes, depending on which container that is opened.

return self.inventory.get_slot(slot);
}
if let Some(container) = &self.container {
return container.get_slot(slot);

This comment was marked as outdated.

Copy link
Contributor

@Bryntet Bryntet Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a match statement, looking something like:

match &self.container {
    Some(container) => {
        if (0..container.size()).contains(&slot) {
            container.get_slot(slot)
        } else {
            self.inventory.items.get(slot-self.container.size())
        }
    None => self.inventory.get_slot(slot)
}

see https://wiki.vg/Inventory#Chest

this also fixes ordering issue

return self.inventory.get_slot_mut(slot);
}
if let Some(container) = &mut self.container {
return container.get_slot_mut(slot);

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a match statement, looking something like:

match &mut self.container {
    Some(container) => {
        if (0..container.size()).contains(&slot) {
            container.get_slot_mut(slot)
        } else {
            self.inventory.items.get_mut(slot-self.container.size())
        }
    None => self.inventory.get_slot_mut(slot)
}

see https://wiki.vg/Inventory#Chest

this also fixes ordering issue

@Bryntet
Copy link
Contributor

Bryntet commented Oct 8, 2024

Hey, I'd love to help getting this refactor and cleanup merged. Would you like some help?

@StripedMonkey
Copy link
Contributor Author

I'd like some,

I've been working on other things since this PR. I'll give you access if you don't already this afternoon.

@Bryntet Bryntet force-pushed the container_refactor branch from 52b6a98 to 3518c49 Compare October 14, 2024 10:19
@Bryntet Bryntet force-pushed the container_refactor branch from 3518c49 to 87b5300 Compare October 14, 2024 10:22
@Bryntet
Copy link
Contributor

Bryntet commented Oct 14, 2024

@StripedMonkey I have now fixed all the major issues with this PR, so the whole system works once again!

I still want to polish up a few things, but very close to wanting this merged :)

@Snowiiii
Copy link
Member

I will close this for now, Feel free to reopen. I think that there are already so many conflicts that it would be easier to Start from scratch again

@Snowiiii Snowiiii closed this Nov 12, 2024
@Bryntet
Copy link
Contributor

Bryntet commented Nov 12, 2024

I'd like this not to be closed, I'll solve the merge conflicts.

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

Successfully merging this pull request may close these issues.

3 participants