Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating a tile does not seem to work to me

Comments in 'Plugin Development' started by TheDiamondMan, Aug 15, 2016.

  1. TheDiamondMan
    Offline

    TheDiamondMan New Member

    Joined:
    Dec 14, 2015
    Posts:
    4
    Minecraft User:
    XxDiamondLoverxX
    I created a chest tile, and it doesnt seem to work, heres my code:
    PHP:
        public function onPlayerTouch(PlayerInteractEvent $event){
            
    $b $event->getBlock();
            
    $pl $event->getPlayer();
            if(
    $this->task[$pl->getName()] === 4){
                
    $this->task[$pl->getName()] = 0;
                if(
    $pl-><= 0){
                        
    $this->id[$pl->getName()] = $pl->getLevel()->getBlockIdAt($pl->x$pl->2$pl->z);
                        
    $pl->getLevel()->setBlock(new Vector3($pl->x$pl->2$pl->z), Block::get(Block::CHEST));
                        
    $nbt = new CompoundTag("", [
                        new 
    ListTag("Items", []),
                        new 
    StringTag("id"Tile::CHEST),
                        new 
    IntTag("x"$pl->x),
                        new 
    IntTag("y"$pl->2),
                        new 
    IntTag("z"$pl->z)
                        ]);
                        
    $nbt->Items->setTagType(NBT::TAG_Compound);
                        
    Tile::createTile("Chest"$pl->getLevel()->getChunk($pl->>> 4$pl->>> 4), $nbt);
                        
    $tile $pl->getLevel()->getTile($b);
                        
    $this->task[$pl->getName()] = 1;
                        if(
    $tile instanceof Chest){
                            
    $pl->addWindow($tile->getInventory());
                            
    $this->getEchestInventory($pl$tile->getInventory());
                        }
                    }else{
                        
    $this->id[$pl->getName()] = $pl->getLevel()->getBlockIdAt($pl->x$pl->2$pl->z);
                        
    $pl->getLevel()->setBlock(new Vector3($pl->x$pl->2$pl->z), Block::get(Block::CHEST));
                        
    $nbt = new CompoundTag("", [
                        new 
    ListTag("Items", []),
                        new 
    StringTag("id"Tile::CHEST),
                        new 
    IntTag("x"$pl->x),
                        new 
    IntTag("y"$pl->2),
                        new 
    IntTag("z"$pl->z)
                        ]);
                        
    $nbt->Items->setTagType(NBT::TAG_Compound);
                        
    $tile Tile::createTile("Chest"$pl->getLevel()->getChunk($pl->>> 4$pl->>> 4), $nbt);
                        
    $chest $pl->getLevel()->getTile(new Vector3($pl->x$pl->2$pl->z));
                        
    $this->task[$pl->getName()] = 2;
                        
    $pl->getLevel()->addTile($chest);
                        
    $pl->addWindow($tile->getInventory());
                        
    $this->getEchestInventory($pl$tile->getInventory());
                    }
            }
        }
    }
    the console doesnt show any errors, whats my problem?
    thanks :)
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Maybe this is the error :D
    PHP:
    $pl->getLevel()->getBlockIdAt(new Vector3($pl->x$pl->2$pl->z));
  3. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    Using Tile::createTile without assigning result to any variable seems odd to me
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Which part of the code doesnt work?
    PHP:
    Tile::createTile("Chest"$pl->getLevel()->getChunk($pl->>> 4$pl->>> 4), $nbt);
    $tile $pl->getLevel()->getTile($b); 
    Seems like you created a Tile at the player's position but you tried to get the tile at the block's location
  5. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    Im not good at nbt, sorry but
    Code:
    $nbt = new CompoundTag("", [
                        new ListTag("Items", []),
                        new StringTag("id", Tile::CHEST),
                        new IntTag("x", $pl->x),
                        new IntTag("y", $pl->y - 2),
                        new IntTag("z", $pl->z)
                        ]);
    doesnt it says where is the chest?
  6. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    PHP:
     $nbt = new CompoundTag("", [
                        new 
    ListTag("Items", []),
                        new 
    StringTag("id"Tile::CHEST),
                        new 
    IntTag("x"$pl->x),
                        new 
    IntTag("y"$pl->2),
                        new 
    IntTag("z"$pl->z)
                        ]);
                        
    $nbt->Items->setTagType(NBT::TAG_Compound);
                        
    Tile::createTile("Chest"$pl->getLevel()->getChunk($pl->>> 4$pl->>> 4), $nbt);
                        
    $tile $pl->getLevel()->getTile(new Vector3($pl->x$pl->2,  $pl->z));
    i changed the code still doesnt work
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    do a var_dump like so just to make sure
    PHP:
    public function onPlayerTouch(PlayerInteractEvent $event){
    $b $event->getBlock();
    $pl $event->getPlayer();
    var_dump($this->task[$pl->getName()]);//here
     
    if($this->task[$pl->getName()] === 4){
  8. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    ok, i did played around a little and found these, it works after changing
    PHP:
    $pl->getLevel()->setBlock(new Vector3($pl->x$pl->2$pl->z), Block::get(Block::CHEST),true,false);
    and
    PHP:
    $nbt = new CompoundTag("", [
      new 
    ListTag("Items", []),
      new 
    StringTag("id"Tile::CHEST),
      new 
    IntTag("x"floor($pl->x)),
      new 
    IntTag("y"floor($pl->y) - 2),
      new 
    IntTag("z"floor($pl->z))
      ]);
    Survingo likes this.

Share This Page

Advertisement