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

[PMMP] Creating chest tile v1.8 upon level generation

Discussion in 'Development' started by BruhLol, Dec 28, 2018.

  1. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    This code used to work on v1.7 pmmp 3.4 releases, but isnt working on pmmp 3.5 releases for v1.8, whats the changed thing? i cant find anything wrong and theres no error... hmmmmm, weird
    Code:
    public function spawnChest($levelname) {
            $level = $this->plugin->getServer()->getLevelByName($levelname);
            $level->setBlock(new Vector3(4, 6, 4), new Block(0, 0));
            $chest = Tile::createTile("Chest",$level, new CompoundTag(" ", [
                new ListTag("Items", []),
                new StringTag("id", Tile::CHEST),
                new StringTag("CustomName", "§b§lKit"),
                new IntTag("x", 4),
                new IntTag("y", 6),
                new IntTag("z", 4)
            ]));
            $level->setBlock(new Vector3(4, 6, 4), new Block(54, 0));
            $level->addTile($chest);
            $inventory = $chest->getInventory();
            $inventory->addItem(Item::get(Item::STEAK, 0, 1));
    }
    NOTE: I am generating the level by a custom generator i made, and loading the level and calling this spawnChest function, it was working in 3.4, and now i dont have any error in 3.5 and its not working, is this internal pmmp level glitch?
    If you want to see the generating level code, Click below:
    Code:
    $server = $this->plugin->getServer();
    $server->generateLevel('ggh', null, GeneratorManager::getGenerator("basic"));
    $server->loadLevel('ggh');
    $level = $this->plugin->getServer()->getLevelByName('ggh');
    $pos = new Position(3, 6, 2, $level);
    $level->setSpawnLocation($pos);
    $this->spawnChest($level);
    EDIT: Forget adding chest tile and block, can't even setBlock a basic dirt block either by
    Code:
    $level->setBlock(new Vector3(4, 6, 4), new Block(3));
    All classes are being used from the right sources.
    Doesn't work from ChunkLoadEvent either...
    Used this ->
    Code:
    public function onChunkLoad(ChunkLoadEvent $event) {
            $level = $event->getLevel();
            $position = new Position(4,6,4,$level);
            if($level->getChunk($position->x >> 4, $position->z >> 4) === $event->getChunk() and $event->isNewChunk()) {
                echo "hi";
                $level->setBlock(new Vector3(4, 6, 4), new Block(3));
                echo "hi1";
            }
        }
    didn't work, output came hi and hi1... but no block, teleported to that postion and checked too...
     
    Last edited: Dec 28, 2018
  2. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    if someone finds an error, lemme know.
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try by replacing
    PHP:
    new Block(3)
    with
    PHP:
    Block::get(3)
    Anyway, you should use the latter as opposed to the former. The latter returns a cloned instance of the former initialized in the BlockFactory if that makes sense. The former will return a block instance with an invalid block name, bounding box etc. (you can try by var_dump()ing the two block instances).
     
    corytortoise and BruhLol like this.
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Also, don't use the latter. Use
    PHP:
    Block::get(Block::DIRT)
     
    corytortoise and Muqsit like this.
  5. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    No changes :'(
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Are you sure you are using release 3.5?
    Before 3.5.0 was released, there was this commit that removed Tile::createTile()
    use Tile::createFromData() instead (note its not just renaming the function)
     
    BruhLol likes this.
  7. BruhLol

    BruhLol Baby Zombie

    Messages:
    122
    Yes, its createTile() and im using v3.5.0
     
  8. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    i've had similar issues regarding this, it seems as if the level needs to be loaded, then wait a minimum of 10 seconds, then you can use setBlock()

    try using Tile::createFromData()

    focus on trying to make setBlock() working first, maybe the generated level is corrupted, use a pre-existing world, also make sure you're in the right coordinates of where the block should be set:D
     
    BruhLol likes this.
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    If you were paying attention you'd notice that was committed to the bleeding edge branch, not to the release branch.

    If you were paying even more attention, you'd have noticed that that change was not mentioned in the changelogs. It's a pretty significant API break so it would be quite serious to find it unmentioned in the release notes, wouldn't it?

    Finally, I'll remind everyone that public API breaks are disallowed on non-major version bumps. See https://github.com/pmmp/DeveloperDocs/blob/master/api-version-spec.md

    Please make sure you have your facts straight before posting misinformation. Thank you.
     
  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.