PEMapModder / PocketMine-Plugin-Tutorials

See wiki for old version. See this website for new version:
https://pemapmodder.github.io/PocketMine-Plugin-Tutorials/
Other
36 stars 15 forks source link

Generator #16

Open Ivanzar opened 9 years ago

Ivanzar commented 9 years ago

how to make my generation of the world, so that some part of world hung in the air? I used Generator but not understood it

Ivanzar commented 9 years ago
use pocketmine\level\generator\Generator;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;

use pocketmine\math\Vector3;
use pocketmine\block\Block;

class TWWGenerator extends Generator{

    private $random,$level;

    public function __construct(array $settings=array()){

    }

    public function getName(){
        return "tww";

    }

    public function getSettings(){

    }

    public function getSpawn(){
        return new Vector3(128.5, 64, 128.5);
    }

    public function init(ChunkManager $level,Random $random){
        $this->random = $rnadom;
        $this->level = $level;

    }

    public function generateChunk($chunkX,$chunkZ){

        $chunk = $this->level->getChunk($chunkX, $chunkZ);
        $startX = min($selection[0][0] = 0, $selection[1][0] = 128);
        $endX = max($selection[0][0] = 0, $selection[1][0] = 128);
        $startY = min($selection[0][1] = 0, $selection[1][1] = 128);
        $endY = max($selection[0][1] = 0, $selection[1][1] = 128);
        $startZ = min($selection[0][2] = 0, $selection[1][2] = 128);
        $endZ = max($selection[0][2] = 0, $selection[1][2] = 128);
        for($x = $startX; $x < $endX; ++$x){
                for($y = $startY; $y < $endY; ++$y){
                for($z = $startZ; $z < $endZ; ++$z){
            $chunk->setBlockId($x,$y,$z,1);
        }
        }
        }
    }

    public function populateChunk($chunkX,$chunkZ){

    }

}

I used it as an experiment. Ignore if you did not understand me, give me example a generation

PEMapModder commented 9 years ago

What if I am not sure? :P

Ivanzar commented 9 years ago

Just to explain the principle of generation. I honestly didn't quite understand what i write xD

Ivanzar commented 9 years ago

i forgot load: STARTUP )

xpyctum commented 9 years ago

@Ivanzar Айайай, плахой!! :D

Ivanzar commented 9 years ago

it`s progress line 15, construct() 16:47:49 [CRITICAL] Could not execute asynchronous task GenerationTask: Argument 1 passed to Ivanzar\TheTwoTowerns\TWWGenerator::construct() must be of the type array, null given, called in phar://C:/Users/ivanzar/PocketMine Progect/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/level/generator/GenerationTask.php on line 63 and defined

xpyctum commented 9 years ago

@Ivanzar

public function __construct(){
     private $settings = array();
}
Ivanzar commented 9 years ago

да я знаю

Ivanzar commented 9 years ago

это есть

xpyctum commented 9 years ago

@Ivanzar Fixed. Исправил коммент

xpyctum commented 9 years ago

@Ivanzar попробуй моё. вдруг поможет

Ivanzar commented 9 years ago

это ты про это public function __construct(array $settings=array()){

}

xpyctum commented 9 years ago

@Ivanzar угу, замени мое на твоё и попробуй.

Ivanzar commented 9 years ago

может вместо приват php private $settings = array(); поставить php return

xpyctum commented 9 years ago

@Ivanzar попробуй.

Ivanzar commented 9 years ago

нет Declaration of Ivanzar\TheTwoTowerns\TWWGenerator::construct() must be compatible with pocketmine\level\generator\Generator::construct(array $settings = Array) in C:\Users\ivanzar\PocketMine Progect\PocketMine-MP\plugins\DevTools\src\Ivanzar\TheTwoTowerns\TWWGenerator.php on line 0

Ivanzar commented 9 years ago

сразу на 0 <php ему не нравиться )

xpyctum commented 9 years ago

@Ivanzar <?php или <? сделай

Ivanzar commented 9 years ago

<php

xpyctum commented 9 years ago

@Ivanzar <?php надо, лал

Ivanzar commented 9 years ago

ой у меня <?php

xpyctum commented 9 years ago

@Ivanzar скинь весь код

Ivanzar commented 9 years ago

вот

<?php
namespace Ivanzar\TheTwoTowerns;

use pocketmine\level\generator\Generator;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;

use pocketmine\math\Vector3;
use pocketmine\block\Block;

class TWWGenerator extends Generator{

    private $random,$level;

    public function __construct(array $settings=array()){
        return $settings = array();
}

    public function getName(){
        return "tww";

    }

    public function getSettings(){

    }

    public function getSpawn(){
        return new Vector3(128, 64, 128);
    }

    public function init(ChunkManager $level,Random $random){
        $this->random = $random;
        $this->level = $level;

    }

    public function generateChunk($chunkX,$chunkZ){

        $chunk = $this->level->getChunk($chunkX, $chunkZ);
        $startX = min($selection[0][0] = 0, $selection[1][0] = 128);
        $endX = max($selection[0][0] = 0, $selection[1][0] = 128);
        $startY = min($selection[0][1] = 0, $selection[1][1] = 128);
        $endY = max($selection[0][1] = 0, $selection[1][1] = 128);
        $startZ = min($selection[0][2] = 0, $selection[1][2] = 128);
        $endZ = max($selection[0][2] = 0, $selection[1][2] = 128);
        for($x = $startX; $x < $endX; ++$x){
                for($y = $startY; $y < $endY; ++$y){
                for($z = $startZ; $z < $endZ; ++$z){
            $chunk->setBlockId($x,$y,$z,1);
        }
        }
        }
    }

    public function populateChunk($chunkX,$chunkZ){

    }

}
Ivanzar commented 9 years ago

сейчас жалуется на __construct

xpyctum commented 9 years ago

@Ivanzar мля.. сделай так:


public function __construct(){
    private $settings = array();
}
Ivanzar commented 9 years ago

private не может быть в функции

xpyctum commented 9 years ago

@Ivanzar тогда сделай ее не в конструкте. А выше, где другие переменные. В конструкте ничего тогда не пиши. И можно её удалить

Ivanzar commented 9 years ago

нет, то же самое

xpyctum commented 9 years ago

@Ivanzar что теперь?

Ivanzar commented 9 years ago

Declaration of Ivanzar\TheTwoTowerns\TWWGenerator::construct() must be compatible with pocketmine\level\generator\Generator::construct(array $settings = Array) in C:\Users\ivanzar\PocketMine Progect\PocketMine-MP\plugins\DevTools\src\Ivanzar\TheTwoTowerns\TWWGenerator.php on line 0

xpyctum commented 9 years ago

@Ivanzar как ты сделал, скинь код

Ivanzar commented 9 years ago
use pocketmine\level\generator\Generator;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;

use pocketmine\math\Vector3;
use pocketmine\block\Block;

class TWWGenerator extends Generator{

    private $random,$level;

    public function __construct(){
}

    public function getName(){
        return "tww";

    }

    public function getSettings(){

    }

    public function getSpawn(){
        return new Vector3(128, 64, 128);
    }

    public function init(ChunkManager $level,Random $random){
        $this->random = $random;
        $this->level = $level;

    }

    public function generateChunk($chunkX,$chunkZ){

        $chunk = $this->level->getChunk($chunkX, $chunkZ);
        $startX = min($selection[0][0] = 0, $selection[1][0] = 128);
        $endX = max($selection[0][0] = 0, $selection[1][0] = 128);
        $startY = min($selection[0][1] = 0, $selection[1][1] = 128);
        $endY = max($selection[0][1] = 0, $selection[1][1] = 128);
        $startZ = min($selection[0][2] = 0, $selection[1][2] = 128);
        $endZ = max($selection[0][2] = 0, $selection[1][2] = 128);
        for($x = $startX; $x < $endX; ++$x){
                for($y = $startY; $y < $endY; ++$y){
                for($z = $startZ; $z < $endZ; ++$z){
            $chunk->setBlockId($x,$y,$z,1);
        }
        }
        }
    }

    public function populateChunk($chunkX,$chunkZ){

    }

}
Ivanzar commented 9 years ago

ура

private $random,$level,$options;

    public function getSettings(){
        return $this->options;
    }
    public function getName(){
        return "tww";
    }

    public function __construct(array $options = []){
        $this->options = $options;
    }

    public function getSpawn(){
        return new Vector3(128, 64, 128);
    }
PEMapModder commented 9 years ago

Use English please.

PEMapModder commented 9 years ago

And avoid doing PocketMine API-related things (like setting blocks) in other threads (including worker threads like AsyncTask), otherwise it will be dangerous.

alejzeis commented 9 years ago

Set blocks in tasks ran by the main thread or scheduler. Spigot doesn't allow you to do world related things in async threads.

On Thursday, April 16, 2015, PEMapModder notifications@github.com wrote:

And avoid doing PocketMine API-related things (like setting blocks) in other threads (including worker threads like AsyncTask), otherwise it will be dangerous.

— Reply to this email directly or view it on GitHub https://github.com/PEMapModder/PocketMine-Plugin-Tutorials/issues/16#issuecomment-93756176 .

falkirks commented 9 years ago

If you want to modify chunks asynchronously the best you can get is what MineReset does. It blocks update events to the chunk, serializes it on the main thread, unserializes it on an AsyncTask, calculates chunk updates and then passes it back to the main thread for sending to clients.

Ivanzar commented 9 years ago

thanks