i recently working on a plugin project related to chest But when i try PHP: $tile = $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z"))); $tile = $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z"))); $this->getServer()->getPlayer("Jons"))->addWindow($tile->getInventory());//tile has been confirmed as a chest so i can use $tile->getInventory() Nothing happen, none chest window open or any console errors Please help
It is always good to simplify your code in your question if you are sure about certain values so that others can concentrate on the part that is not working. For example, the part about PHP: $tile = $this->getServer()->getPlayer($pname)->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z"))); is meaningless to us if you have already confirmed that it is working correctly, since you are asking about particular code. (Of course, if your problem is related to the rest of your plugin, you should show more information)
PHP: public function openChest($playername) { $conf = new Config($this->getDataFolder() ."players/". strtolower($playername) .".yml", Config::YAML, [ "x" => 10000, "y" => 78, "z" => 10000, "level" => "world" ]); $tile = $this->getServer()->getPlayer("Jons")->getLevel()->getTile(new Vector3($conf->get("x"), $conf->get("y"), $conf->get("z"))); $this->getServer()->getPlayer("Jons")->addWindow($tile->getInventory());}
You cant addWindow() on a chest that is more than 6 blocks far from the player, id recommend setting a chest 3 blocks under the player and removing it when he closes it, most efficient way kinda wish there was a plugin that controls that and you can use its functions to add chest or remove
is there any way to add window without adding a chest ex using packets since it is quite inconvenient to add chest below player ex some other player can open it(just because it is under dosent mean it cant be accessed) and what would happen if TWO players use it in the same place wont that interfere with it?
PHP: public function openChest($player,$playername){ $block = Block::get(54); $config = new Config($this->getDataFolder() ."players/". strtolower($playername) .".yml", Config::YAML); $player->getLevel()->setBlock(new Vector3($config['x'], $config['y'], $config['z']), $block, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $config['x']), new IntTag("y", $config['y']), new IntTag("z", $config['z']) ]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $player->getLevel()->getChunk($config['x'] >> 4, $config['z'] >> 4), $nbt); if($player->getName() === $playername){ $player->addWindow($tile->getInventory()); } }
I think it wont work since the code might ran before it set block and add tile, tried this before but failed