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

Ags on CreatTile

Discussion in 'Development' started by romainbizet46, Jan 7, 2018.

  1. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    This function do not work
    PHP:
    public function loadVault(Player $player$number) {
            
    $itemblock Item::fromString("chest");
            
    $block $itemblock->getBlock();
            
    $player->getLevel()->setBlock(new Vector3($player->getX(), 128$player->getZ()), $block);
            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Items", []),
                new 
    StringTag("id"Tile::CHEST),
                new 
    IntTag("x"$player->getX()),
                new 
    IntTag("y"$player->getY()),
                new 
    IntTag("z"$player->getZ())
            ]);
            
    $nbt->Items->setTagType(NBT::TAG_Compound);
            
    $tile Tile::createTile("Chest"$player->getLevel()->getChunk($player->getX() >> 4$player->getZ() >> 4), $nbt);
            if(
    $player instanceof Player) {
                
    $player $player->getName();
            }
            
    $player strtolower($player);
            
    $cfg = new Config($this->getDataFolder() . "players/" $player ".yml"Config::YAML);
            
    $tile->getInventory()->clearAll();
            for (
    $i 0$i 26$i++) {
                
    $ite $cfg->getNested("$number.items." $i);
                
    $item Item::get($ite[0]);
                
    $item->setDamage($ite[1]);
                
    $item->setCount($ite[2]);
                foreach (
    $ite[3] as $key => $en) {
                    
    $enchantment Enchantment::getEnchantment($en[0]);
                    
    $enchantment->setLevel($en[1]);
                    
    $item->addEnchantment($enchantment);
                }
                
    $tile->getInventory()->setItem($i$item);
            }
            return 
    $tile->getInventory();
        }

    Line error:
    $tile Tile::createTile("Chest"$player->getLevel()->getChunk($player->getX() >> 4$player->getZ() >> 4), $nbt);
     
  2. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    you do not have to copy old code, try looking at the new API and learn instead of copying old code
     
  3. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Fix but when i close the fake chest keep displayed
     

    Attached Files:

  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    so it does work now? show your current code then please.
     
  5. romainbizet46

    romainbizet46 Witch

    Messages:
    52
    Of course but the chest keep visible after close
    PHP:
    public function loadVault(Player $player$number) {
            
    $itemblock Item::fromString("chest");
            
    $block $itemblock->getBlock();
            
    $player->getLevel()->setBlock(new Vector3($player->getX(), 128$player->getZ()), $block);
            
    $nbt = new CompoundTag("", [
                new 
    ListTag("Items", []),
                new 
    StringTag("id"Tile::CHEST),
                new 
    IntTag("x"$player->getX()),
                new 
    IntTag("y"$player->getY()),
                new 
    IntTag("z"$player->getZ())
            ]);
            
    $nbt->Items->setTagType(NBT::TAG_Compound);
            
    $tile Tile::createTile "Chest"$player->getLevel (), $nbt );
            
    $block Block::get Block::CHEST );
            
    $block->= ( int ) $tile->x;
            
    $block->= ( int ) $tile->y;
            
    $block->= ( int ) $tile->z;
            
    $block->level $tile->getLevel ();
            
    $block->level->sendBlocks ( [
                    
    $player
            
    ], [
                    
    $block
            
    ] );
            if(
    $player instanceof Player) {
                
    $player $player->getName();
            }
            
    $player strtolower($player);
            
    $cfg = new Config($this->getDataFolder() . "players/" $player ".yml"Config::YAML);
            
    $tile->getInventory()->clearAll();
            for (
    $i 0$i 26$i++) {
                
    $ite $cfg->getNested("$number.items." $i);
                
    $item Item::get($ite[0]);
                
    $item->setDamage($ite[1]);
                
    $item->setCount($ite[2]);
                foreach (
    $ite[3] as $key => $en) {
                    
    $enchantment Enchantment::getEnchantment($en[0]);
                    
    $enchantment->setLevel($en[1]);
                    
    $item->addEnchantment($enchantment);
                }
                
    $tile->getInventory()->setItem($i$item);
            }
            return 
    $tile->getInventory();
        }
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    well, you need to remove the chest&tile afterwards again
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Marabou likes this.
  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.