-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
Container API first pass refactor and cleanup #85
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this 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>>; |
There was a problem hiding this comment.
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/src/client/container.rs
Outdated
*container.all_slots()[slot] = item_slot; | ||
} | ||
let all_slots = container.iter_slots_mut().enumerate(); | ||
// let slots = if slot > 35 { |
There was a problem hiding this comment.
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
pumpkin-inventory/src/player.rs
Outdated
@@ -57,13 +57,19 @@ impl PlayerInventory { | |||
if !(0..=45).contains(&slot) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
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 { |
There was a problem hiding this comment.
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))?;
72c4df9
to
4adac0d
Compare
pumpkin-inventory/src/lib.rs
Outdated
Some(container) => Box::new( | ||
container | ||
.iter_slots_mut() | ||
.chain(self.inventory.iter_slots_mut()), |
There was a problem hiding this comment.
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.
pumpkin-inventory/src/lib.rs
Outdated
return self.inventory.get_slot(slot); | ||
} | ||
if let Some(container) = &self.container { | ||
return container.get_slot(slot); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
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
pumpkin-inventory/src/lib.rs
Outdated
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.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
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
4adac0d
to
52b6a98
Compare
Hey, I'd love to help getting this refactor and cleanup merged. Would you like some help? |
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. |
52b6a98
to
3518c49
Compare
3518c49
to
87b5300
Compare
@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 :) |
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 |
I'd like this not to be closed, I'll solve the merge conflicts. |
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.