Pocketmine-mp: The item of craft item event outputs has randomized index

Created on 30 Jan 2021  路  3Comments  路  Source: pmmp/PocketMine-MP

Issue description

The item of craft item event outputs has randomized index

  • Expected result: CraftItemEvent->getOutputs()[0] returns the crafted item isntance
  • Actual result: Undefined index, find out the array index is not fixed.

Steps to reproduce the issue

  1. Use CraftItemEvent->getOutputs()[0] in an event handler function
  2. Craft an item
  3. The code get runs
  4. Gets the error

OS and versions

  • PocketMine-MP: PocketMine-MP 3.17.3 (b296ae1b872aa0dbb6d118993aaab70913326b13)
  • PHP: PHP 7.3.8 (cli) (built: Aug 16 2019 11:30:39) ( ZTS MSVC15 (Visual C++ 2017) x64 )
  • Server OS: Windows 10 version 1909 build 18363.1316

Plugins

CraftLock v1.0.0, DEVirion v1.2.7, DevTools v1.14.2, LevelSystem v1.0.0, MultiWorld v1.5.1, PureChat v1.4.11, PurePerms v1.4.3, Specter v0.9, WebGetPM v0.0.1-lite
  • If you remove all plugins, does the issue still occur? No
  • If the issue is not reproducible without plugins:

    • Have you asked for help on our forums before creating an issue? No, Discord

    • Can you provide sample, minimal reproducing code for the issue? If so, paste it in the bottom section

      CraftItemEvent->getOutputs()[0]

Crashdump, backtrace or other files

Var dump result of the code above:

array(1) {
  [2]=>
  object(pocketmine\item\Stick)#15782 (5) {
    ["id":protected]=>
    int(280)
    ["meta":protected]=>
    int(0)
    ["nbt":"pocketmine\item\Item":private]=>
    object(pocketmine\nbt\tag\CompoundTag)#15508 (3) {
      ["value":"pocketmine\nbt\tag\CompoundTag":private]=>
      array(0) {
      }
      ["__name":protected]=>
      string(0) ""
      ["cloning":protected]=>
      bool(false)
    }
    ["count"]=>
    int(4)
    ["name":protected]=>
    string(5) "Stick"
  }
}
API Core Fixed

Most helpful comment

why don't you walk instead of taking a bus?

All 3 comments

why u don't use array_shift() or array_pop()?

why don't you walk instead of taking a bus?

I can address this for the simple case, but the list still won't be ordered if there are multiple outputs (e.g. cake + buckets).

Was this page helpful?
0 / 5 - 0 ratings