Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Chestfilling [Help]

Comments in 'Plugin Development' started by JackboyPlay, Jun 21, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hello I try to fill chests with this code
    in a Task
    PHP:
     $o $this->getOwner();
    $kiste1 $o->getServer()->getLevelByName("world")->getTile(new Vector3(13655970));
    $stuff = array(271268275272267279283322298299300301302303304305306307308309310311261262);
    $counter count($stuff);
    $rand mt_rand(0$counter);
    $auswahl $stuff[$rand];
    $slot mt_rand(020);
    $kiste1->getInventory()->setItem($slotItem::get($auswahl01));
    But it doesnt work! Why? Errorcode:
    PHP:
    [15:38:02] [Server thread/CRITICAL]: Error"Call to a member function getInventory() on null" (EXCEPTIONin "/QSG/src/JackboyPlay/QSG/Main" at line 365
    PS: On the coordinates is a chest!
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You have to make sure that $kiste1 is actually a ChestTile. After you've added necessary 'if' statements, you can start debugging
    PHP:
    var_dump($kiste1); // What did it return?
    var_dump($level->getBlock(new Vector3(13655970)); // $kiste1  was null? Then let's see what block is there.
    Always check if the return value from function is exactly what you expected it to be!

    As I see, you have written 4 extra lines to do one thing, CPU and RAM waste.
    PHP:
    Inventory::addItem(mt_rand(020), Item::get(array_rand($stuff), 1));
    CraftYourBukkit likes this.
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    PHP:


















    }  int(991)  ["z"]=>  int(5)  ["y"]=>  int(1355)  ["x"]=>  }  object(pocketmine\level\Level)#11824 (0) {  ["level"]=>  NULL  ["boundingBox"]=>  int(0)  ["meta":protected]=>  int(0)  ["id":protected]=>object(pocketmine\block\Air)#12260 (7) {A:
    @Primus ok now another question why disappears the chest? xD
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I fill a chest with a nbt tag?
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What?

Share This Page

Advertisement