Implemented Hopper pushing, pulling and picking up items logic#4416
Implemented Hopper pushing, pulling and picking up items logic#4416ColinHDev wants to merge 23 commits intopmmp:masterfrom
Conversation
…while pushing into the furnace
|
I don't have the time to do an in-depth review right now, but one quick note: setting an |
|
Oh, yeah, I see that now. |
… pushing into one # the shulkerbox inventory has already its own check if the item is a shulkerbox in the ShulkerboxInventory::canAddItem() function
sylvrs
left a comment
There was a problem hiding this comment.
The PR overall seems good, but there are some nitpicks that I thought I'd point out 😄
dktapps
left a comment
There was a problem hiding this comment.
Not a depth review, but I have quite a few PRs to go over. Overall doesn't look bad, but I do find a lot of the comments unnecessary and there are a few other things I'm not too stoked about. I'll come back to this.
…ponding block, it won't count that as success
… if more blocks are added to that logic
|
Changed everything except the bitwise operator for now. $success |= $this->pickup($inventory);to if($success){
$this->pickup($inventory);
}else{
$success = $this->pickup($inventory);
} |
|
It can be written as |
It shouldn't at least according to both my knowledge and the wiki (I looked it up for that https://www.php.net/manual/en/language.operators.logical.php). |
|
Oops. I meant |
|
But then the functions wouldn't be called if the pushing succeeded and |
|
You're right. I guess the condition order would have to be flipped. |
|
Yes $success = $this->pickup($inventory) || $success;should do it. |
|
Changed everything, also bitwise operators. I would leave this PR open until #4413 is merged (or rejected) because its implementations of the BrewingStand and the improvements of the BrewingStandInventory would help m4e to also implement pushing and pulling logic for BrewingStands |
|
I still don't have a good idea how to ditch dependency on Container files in the pickup logic.. It works for now, but how stated in the TODO in the future, not all blocks a hopper can pull from are containers |
Introduction
In pm4 hopper blocks were implemented to have an inventory. But the logic for pushing, pulling and picking up items was missing nonetheless.
This PR aims to add this logic to the hopper.
This PR contains many comments because the hopper logic is very complex. To prevent future developers from getting confused about how certain things were done, most parts were commented to explain what was done and why.
Relevant issues
Sources
Changes
API changes
Hopper::push(HopperInventory) : boolwhich handles pushing items from the hopper to a tile in the direction the hopper is facing.Hopper::pull(HopperInventory, Container) : boolwhich handles pulling items by the hopper from a container above.Hopper::pickup(HopperInventory) : boolwhich handles picking up items by the hopper.Hopper::getTransferCooldown() : intto get the transfer cooldown of that hopper.Hopper::setTransferCooldown(int)to set the transfer cooldown of that hopper.Behavioural changes
TODOs
Backwards compatibility
Tests
Functionality tests
https://www.youtube.com/watch?v=4gSyuViaPaU
https://www.youtube.com/watch?v=6NWvr6Kv88E
https://www.youtube.com/watch?v=hVEPiK9KWkA
"Performance" tests
https://timings.pmmp.io/?id=158627