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

Add new block/item

Comments in 'Plugin Development' started by Creeperface, Oct 12, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Hi i want to add Brewing stand to pocketmine. I created two classes but i can not place it.
    PHP:
    <?php

    namespace pocketmine\block;


    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\Tool;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\nbt\tag\Compound;
    use 
    pocketmine\nbt\tag\Enum;
    use 
    pocketmine\nbt\tag\Int;
    use 
    pocketmine\nbt\tag\String;
    use 
    pocketmine\Player;
    use 
    pocketmine\tile\Tile;

    class 
    BrewingStand extends Solid{
        protected 
    $id self::BREWING_BLOCK;

        public function 
    __construct($meta 0){
            
    $this->meta $meta;
        }

        public function 
    getName(){
            return 
    "Brewing Stand";
        }

        public function 
    canBeActivated(){
            return 
    true;
        }

        public function 
    getHardness(){
            return 
    0.5;
        }

        public function 
    getToolType(){
            return 
    Tool::TYPE_PICKAXE;
        }

        public function 
    getLightLevel(){
            return 
    1;
        }

        public function 
    place(Item $itemBlock $blockBlock $target$face$fx$fy$fzPlayer $player null){
            
    $this->meta 0;
            
    $this->getLevel()->setBlock($block$thistruetrue);
            
    $nbt = new Compound("", [
                new 
    Enum("Items", []),
                new 
    String("id"Tile::BREWING_STAND),
                new 
    Int("x"$this->x),
                new 
    Int("y"$this->y),
                new 
    Int("z"$this->z)
            ]);
            
    $nbt->Items->setTagType(NBT::TAG_Compound);

            if(
    $item->hasCustomName()){
                
    $nbt->CustomName = new String("CustomName"$item->getCustomName());
            }

            if(
    $item->hasCustomBlockData()){
                foreach(
    $item->getCustomBlockData() as $key => $v){
                    
    $nbt->{$key} = $v;
                }
            }

            
    Tile::createTile("BrewingStand"$this->getLevel()->getChunk($this->>> 4$this->>> 4), $nbt);

            return 
    true;
        }

        public function 
    onBreak(Item $item){
            
    $this->getLevel()->setBlock($this, new Air(), truetrue);

            return 
    true;
        }

        public function 
    onActivate(Item $itemPlayer $player null){
            if(
    $player instanceof Player){
                
    $t $this->getLevel()->getTile($this);
                if(
    $t instanceof \pocketmine\tile\BrewingStand){
                    
    $brewing $t;
                }else{
                    
    $nbt = new Compound("", [
                        new 
    Enum("Items", []),
                        new 
    String("id"Tile::BREWING_STAND),
                        new 
    Int("x"$this->x),
                        new 
    Int("y"$this->y),
                        new 
    Int("z"$this->z)
                    ]);
                    
    $nbt->Items->setTagType(NBT::TAG_Compound);
                    
    $brewing Tile::createTile("BrewingStand"$this->getLevel()->getChunk($this->>> 4$this->>> 4), $nbt);
                }

                if(isset(
    $brewing->namedtag->Lock) and $brewing->namedtag->Lock instanceof String){
                    if(
    $brewing->namedtag->Lock->getValue() !== $item->getCustomName()){
                        return 
    true;
                    }
                }

                if(
    $player->isCreative()){
                    return 
    true;
                }

                
    $player->addWindow($brewing->getInventory());
            }

            return 
    true;
        }

        public function 
    getDrops(Item $item){
            
    $drops = [];
            if(
    $item->isPickaxe() >= 1){
                
    $drops[] = [Item::BREWING_STAND01];
            }

            return 
    $drops;
        }
    }
    PHP:
    <?php
    /**
     * Created by PhpStorm.
     * User: Honza
     * Date: 10. 10. 2015
     * Time: 12:51
     */

    namespace pocketmine\item;


    use 
    pocketmine\block\Block;

    class 
    BrewingStand extends Item{

        public function 
    __construct($meta 0$count 1){
            
    $this->block Block::get(Item::BREWING_STAND_BLOCK);
            
    parent::__construct(self::BREWING_STAND0$count"Brewing Stand");
        }

        public function 
    getMaxStackSize(){
            return 
    1;
        }
    }
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    brewing is already implemented, but it is brewing block and item and i need to make placing brewing block using brewing item
    Taha_The_Hacker likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Creating the class is useless if you don't register them like Item::init().
    CrazedMiner and Creeperface like this.
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OMG brewing works
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Post it? ;)
    jojoe77777 likes this.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    It is not complete
    Legoboy0215 likes this.
  8. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    You can use this method:
    PHP:
    Item::$list[$id] = YourItem::class;
    Inta likes this.
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Yes i already made that
  10. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    Um.... Standart PocketMine for 0.12 isn't have BrewingStand tile class, please send to me your core. I want to add Brwing Stand and working potions into my PocketMine-Mechanic :)
  11. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Me, I got inspiration from Bukkit&Spigot source code, so look at it.
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    No.. There are some faults
  13. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    Please give me your core... Please :)
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    It is not done
  15. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    What? Why? You tell "OMG its works"
  16. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    It works but e.g. He hasn't added all the potions yet...
  17. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    no, IDK if brewing should extends tile or spawnable
  18. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    I have code to do potions
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why not contribute the code to PocketMine directly?
    PM me if you need help with Git (since it is offtopic) while trying to do so.
    Legoboy0215 likes this.
  20. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I'll submit it to Git (https://github.com/kvetinac97/PocketMine-MP/ once I'll finish it

Share This Page

Advertisement