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

creating Chest and refill it

Comments in 'Plugin Development' started by Bluplayz, Dec 28, 2015.

  1. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    I want to create a chest on Interact and replace the clicked Block with a chest and refill it with random Items , but it dont work :(

    PHP:
    public function onInteract(PlayerInteractEvent $event){
       
            
    $block $event->getBlock();
            
    $blockID $block->getID();
            
    $player $event->getPlayer();
           
            if(
    $blockID === 152){
           
                
    $position $player->getPosition();
               
                
    $player->getLevel()->setBlock($blockBlock::get(540), truetrue);
                
    $nbt = new Compound("", [
                new 
    Enum("Items", []),
                new 
    String("id"Tile::CHEST),
                new 
    Int("x"$position->getX()),
                new 
    Int("y"$position->getY()),
                new 
    Int("z"$position->getZ())
                ]);
                
    $nbt->Items->setTagType(NBT::TAG_Compound);
                
    $tile Tile::createTile("Chest"$player->getLevel()->getChunk($block->getX() >> 4$block->getZ >> 4), $nbt);
               
                
    $chest $player->getLevel()->getTile($block);
                for(
    $i 0$i 6$i++){
                   
                    
    $items = array(
                            
    Item::get(Item::BREAD06),
                            
    Item::get(26004),
                            
    Item::get(26101),
                            
    Item::get(26801),
                            
    Item::get(30601),
                            
    Item::get(30801),
                            
    Item::get(30101),
                            
    Item::get(29901),
                            
    Item::get(26701)
                    );
                    
    $itemRnd mt_rand(0count($items) -1);
                    
    $item $items[$itemRnd];
                   
                    
    $chest->getInventory()->addItem($item);   
                }       
                   
            }
           
        }
    and here the Error , the error comes if i tap on a redstone bloc(ID 152)

    the chest will be created but is empty

    PHP:
    [Server] [17:20:56] [INFO]: Bluplayz[/127.0.0.1:19132logged in with entity id 1 at (world126.024673130.6556)
    [
    Server] [17:20:56] [INFO]: There are 1/20 players online:
    [
    Server] [17:20:56] [INFO]: Bluplayz
    [Server] [17:20:57] [INFO]: Bluplayz joined the game
    [Server] [17:21:00] [CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'JumpLeague v1': Argument 2 passed to pocketmine\tile\Tile::createTile() must implement interface pocketmine\level\format\FullChunk, null given, called in /storage/emulated/0/PocketMine/plugins/JumpLeague/src/Bluplayz/JumpLeague.php on line 54 and defined on Bluplayz\JumpLeague
    [Server] [17:21:00] [NOTICE]: RuntimeException: "
    Argument 2 passed to pocketmine\tile\Tile::createTile() must implement interface pocketmine\level\format\FullChunknull givencalled in /storage/emulated/0/PocketMine/plugins/JumpLeague/src/Bluplayz/JumpLeague.php on line 54 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/tile/Tile" at line 84


  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Mind pointing out that line?
  3. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    xD what? google translate not the correct sentence :D

Share This Page

Advertisement