Okay, I searched through forum, but I can't find an exact solution for this... How can i set items to a chest? Im doing like this: is this correct? PHP: public function fillChest(){ $coord = new Vector3(12 , 34, 56); $chest = $this->level->getTile($coord); $chest->getInventory()->addItem(Item::get(258, 0 ,1));} Correct??
Code: 12.11 02:26:23 [Server] INFO Fatal error: Call to a member function getInventory() on null in phar:///plugins/MinedoxCore-Smash_v1.0.0.phar/src/MDCore/MDCore.php on line 368 There's a problem with $chest... where did I wrong? Pls help....
PHP: $this->level = $this->getServer()->getDefaultLevel(); This is how I get the level... I still don't know why it crashed.... getBlock()->getTile()?? Is this possible? xD getBlock and getTile? LOL
I figured out... There's something wrong with my coordinates... zzz How can I get coordinates correctly?
You have to floor() the given values. I know there are some "not cleen" things in this code, but it fills the chest. PHP: $position = $player->getPosition(); //replace with the vector you use to get the chest $position instanceof Position; $chest = $position->getLevel()->getBlock(new Vector3(floor($position->getX()), 30 + (69 - 64), floor($position->getZ()))); $position->getLevel()->setBlock(new Vector3(floor($position->getX()), 30 + (69 - 64), floor($position->getZ())), new Block(Block::CHEST), true, true); $nbt = new Compound("", [new Enum("Items", []),new String("id", Tile::CHEST),new Int("x", floor($position->getX())),new Int("y", floor($position->getY())),new Int("z", floor($position->getZ()))]); // here floor() is important, in the other lines not, but still, i used it $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $sender->getLevel()->getChunk($position->getX() >> 4, $position->getZ() >> 4), $nbt); if(!($tile instanceof \pocketmine\tile\Chest)) continue; $tile->getInventory()->addItem(new Item(Item::ICE, 0, 2), new Item(Item::BUCKET, 10, 1)); by the way, with this code i create a new chest at the players feet. So you might need to modify the code.
Nope My code is working, just the coordinates i obtained is wrong Anyway, still thank you but i already fixed it yesterday
That code won't work... As you cant use Item(Item::BUCKET); Please use Item:get . It is more efficient and less likely to get changed in the future
What a wonder THAT it works. . Check it before you post. and get() wont work, because it has meta and i wanted to keep it short. Item::BUCKET just returns the id, as Item->get() does.
It is? i don't think so. Item::BUCKET will get the id directly from the Item list (Item[]), item get will call a subfunction of Item::class, which will then return the id. I am sure that 1 step less will not change the performance alot, but a task less is always less time.
What do u mean by wasnt totally solved? Yes, it is totally solved Messages are sent to damager and victim now, i tested it