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

Set chest block and fill with items

Comments in 'Plugin Development' started by thebigsmileXD, Oct 15, 2015.

  1. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I want to set a chest at the players feet when they do /chesttome

    This is what i got so far, i can see the chest, but when i tap it it disappears.

    PHP:
    $position $player->getPosition();
                    
    $position instanceof Position;
                    
    $chest $position->getLevel()->getBlock(new Vector3($position->getX(), 30 + (69 64), $position->getZ()));
                    
    $position->getLevel()->setBlock(new Vector3($position->getX(), 30 + (69 64), $position->getZ()), new Block(Block::CHEST), truetrue);
                    
    $nbt = new Compound("", [new Enum("Items", []),new String("id"Tile::CHEST),new Int("x"$position->getX()),new Int("y"$position->getY()),new Int("z"$position->getZ())]);
                    
    $nbt->Items->setTagType(NBT::TAG_Compound);
                    
    $tile Tile::createTile("Chest"$sender->getLevel()->getChunk($position->getX() >> 4$position->getZ() >> 4), $nbt);
                   
                    if(!(
    $tile instanceof \pocketmine\tile\Chest)) continue;
                    
    $tile->getInventory()->addItem(new Item(Item::ENDER_PEARL02));
                    
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Code from chest.php
    PHP:
    $this->getLevel()->setBlock($block$thistruetrue);
    $nbt = new Compound("", [
    new 
    Enum("Items", []),
    new 
    String("id"Tile::CHEST),
    new 
    Int("x"$this->x),
    new 
    Int("y"$this->y),
    new 
    Int("z"$this->z)
    ]);
    $nbt->Items->setTagType(NBT::TAG_Compound);
    $tile Tile::createTile("Chest"$this->getLevel()->getChunk($this->>> 4$this->>> 4), $nbt);
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Look at my snippet.
    Its the same, except for the position and $this->x/y/z.
    What do you think where i got that snippet from? :p
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Try this?
    PHP:
    $position $player->getPosition();
                    
    $chest $position->getLevel()->getBlock(new Vector3($position->getX()->floor(), 30 + (69 64), $position->getZ())->floor());
                    
    $position->getLevel()->setBlock(new Vector3($position->getX()->floor(), 30 + (69 64), $position->getZ())->floor(), new Block(Block::CHEST), truetrue);
                    
    $nbt = new Compound("", [new Enum("Items", []),new String("id"Tile::CHEST),new Int("x"$position->getX()->floor()),new Int("y"$position->getY()->floor()),new Int("z"$position->getZ()->floor())]);
                    
    $nbt->Items->setTagType(NBT::TAG_Compound);
                    
    $tile Tile::createTile("Chest"$sender->getLevel()->getChunk($position->getX() >> 4$position->getZ() >> 4), $nbt);
                
                    if(!(
    $tile instanceof \pocketmine\tile\Chest)) continue;
                    
    $tile->getInventory()->addItem(new Item(Item::ENDER_PEARL02));
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Uhm.. that was what i wrote..
  6. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    No, there is a ->floor() after every of the coords
  7. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Oh, right. Hard to see.
    I've thought this would work without rounding.

Share This Page

Advertisement