So i know how to make a chest inv. But i tried to add a item but it does not work heres my code. PHP: public function sendInventory (Player $player) { $nbt = new CompoundTag ( "", [ new StringTag ( "id", Tile::CHEST ), new IntTag ( "Inventory", 1 ), new IntTag ( "x", ( int ) $player->getX () ), new IntTag ( "y", ( int ) $player->getY () ), new IntTag ( "z", ( int ) $player->getZ () ) ] ); /** @var Chest $tile */ $tile = Tile::createTile ( "Chest", $player->getLevel (), $nbt ); $block = Block::get ( Block::CHEST ); $block->x = ( int ) $tile->x; $block->y = ( int ) $tile->y; $block->z = ( int ) $tile->z; $block->level = $tile->getLevel (); $block->level->sendBlocks ( [ $player ], [ $block ] ); if ($tile instanceof Chest) { // Items $i = $tile->getInventory(); $i->addItem(Item::get(Item::STONE, 0, 1)); } $player->addWindow($tile->getInventory()); } Can you please help me.
OFF TOPIC: why do you check if $tile is a instanceof Chest? your creating it so i suppose its a chest already
*facepalm* He can not put anything in his inventory. Do you believe in seeing chest on the createTile () function that its will work? If it does not put instanceof a Chest it considered it as a Sign or everything that comes in the function Tile.php.
The instanceof check is indeed useless, but I sometimes do it too to silence my IDE. Even PHPStorm isn't smart enough to understand you're making a chest tile there. You could just add a doc above it too, though.
Any errors? Remove the variable declaration and the instanceof check in the ending. It's kinda confusing. PHP: //REPLACE THIS: if ($tile instanceof Chest) { // Items $i = $tile->getInventory(); $i->addItem(Item::get(Item::STONE, 0, 1)); } $player->addWindow($tile->getInventory());//WITH THIS $tile->getInventory()->addItem(Item::get(Item::STONE)); $player->addWindow($tile->getInventory()); That might barely be the problem. I believe the problem is you trying to create the chest where the PLAYER STANDS. According to your code, the chest would be created right where the player is standing, and that would force the player to move a little away from the chest due to bounding box collision. Try creating the chest 2 blocks above the player, so it's right above the player's head. PHP: new IntTag("y", (int) $player->getY() + 2),
Now i see why they call Muqsit the great coder. Thank you so much everyone. And god luck on your servers Muqsit.
Didn't expect someone to wish me god luck Thank you, but I am not a "great coder". There are many other people better than me in programming stuff. I'm still learning and have no idea about more than a 100 topics that a person having an year of experience in the development field should know of.