1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to pass data across threads "Main instance"

Discussion in 'Development' started by Atomization, Sep 23, 2019.

  1. Atomization

    Atomization Baby Zombie

    Messages:
    120
    GitHub:
    iAtomPlaza
    I'm trying to get the plugins data folder from a populator class which is running on the generator thread.
    Someone told me on discord to "just pass the path string in the constructor", but this isn't going to work because I'll then have to pass the string though the generators constructor, then to the biomes constructor, then to the populators constructor.
    Here is an example of what I mean;
    PHP:
    class Main extends PluginBase {
        public function 
    onEnable():void {
        
    /*
            can't even pass "$this" to the generator class...
            I need to get "$this->getDataFolder();" to the generator thread
        */
            
    GeneratorManager::addGenerator(TestGenerator::class, "testGenerator");
        }
    }

    class 
    TestGenerator extends Generator {
        public function 
    __construct(array $options = []) {
            
    $reflect = new \ReflectionMethod(Biome::class, 'register');
            
    $reflect->invoke(nullBiomeIds::PLAINS, new PlainsBiome());
        
    /*
            I cant pass the Main instance to the biome and then onto the populator because Idk how to get it into the generator
            It would look something like "new PlainsBiome(Main::getInstance())" if there was a static method in main that returned the main plugin instance
        */
        
    }
    }

    class 
    PlainsBiome extends Biome {
        public function 
    __construct() {
            
    $populator = new TestPopulator(/*should pass populator settings from datafolder in config here*/);
            
    $this->addPopulator($populator);
        }
    }

    class 
    TestPopulator extends Populator {
        private 
    $plugin
        
    public function __construct(Main $plugin /*receive settings from previous class*/) {
            
    $this->plugin $plugin;
        }
        public function 
    populate(ChunkManager $level$chunkX$chunkZRandom $random) {
            
    var_dump($this->plugin->getDataFolder());
        }
    }
    The closest thing I've found on how to achieve what I'm looking for is in this post by Jack Noordhuis
    Could someone explain how I can go about serializing the data and how to send it to the generator thread?
     
    Last edited: Sep 24, 2019
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    look to MultiWorld plugin, there is functional system, that adds new biomes
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.