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

brewing stand

Comments in 'Plugin Development' started by Creeperface, Nov 28, 2015.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    im trying to create working brewing stand, but onUpdate() function doesn't run and idk why :/
    i registered block, item and tile too.

    PHP:
    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;
        }
    }
    PHP:
    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){
            
    $faces = [
                
    => 4,
                
    => 2,
                
    => 5,
                
    => 3,
            ];

            
    $this->meta $faces[$player instanceof Player $player->getDirection() : 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 BrewingStandTile){
                    
    $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 
    false;
                    }
                }

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

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

            return 
    true;
        }

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

            return 
    $drops;
        }
    }
    PHP:
    class BrewingStand extends Tile implements InventoryHolderContainerNameable{
        
    /** @var BrewingInventory */
        
    protected $inventory;

        const 
    MAX_BREW_TIME 400;

        public static 
    $ingredients = [Item::NETHER_WARTItem::GOLD_NUGGETItem::GHAST_TEARItem::GLOWSTONE_DUSTItem::REDSTONE_DUSTItem::GUNPOWDERItem::MAGMA_CREAMItem::BLAZE_POWDERItem::GOLDEN_CARROTItem::SPIDER_EYEItem::FERMENTED_SPIDER_EYEItem::GLISTERING_MELON];

        public function 
    __construct(FullChunk $chunkCompound $nbt){
            
    parent::__construct($chunk$nbt);
            
    $this->inventory = new BrewingInventory($this);

            if(!isset(
    $this->namedtag->Items) or !($this->namedtag->Items instanceof Enum)){
                
    $this->namedtag->Items = new Enum("Items", []);
                
    $this->namedtag->Items->setTagType(NBT::TAG_Compound);
            }

            for(
    $i 0$i $this->getSize(); ++$i){
                
    $this->inventory->setItem($i$this->getItem($i));
            }

            if(!isset(
    $this->namedtag->BrewTime) or $this->namedtag["BrewTime"] < 0){
                
    $this->namedtag->BrewTime = new Short("BrewTime"0);
            }
            if(
    $this->namedtag["BrewTime"] > 0){
                
    $this->scheduleUpdate();
            }

            echo 
    " constructing ";
        }

        public function 
    getName(){
            return isset(
    $this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Brewing Stand";
        }

        public function 
    hasName(){
            return isset(
    $this->namedtag->CustomName);
        }

        public function 
    setName($str){
            if(
    $str === ""){
                unset(
    $this->namedtag->CustomName);
                return;
            }

            
    $this->namedtag->CustomName = new String("CustomName"$str);
        }

        public function 
    close(){
            if(
    $this->closed === false){
                foreach(
    $this->getInventory()->getViewers() as $player){
                    
    $player->removeWindow($this->getInventory());
                }
                
    parent::close();
            }
        }

        public function 
    saveNBT(){
            
    $this->namedtag->Items = new Enum("Items", []);
            
    $this->namedtag->Items->setTagType(NBT::TAG_Compound);
            for(
    $index 0$index $this->getSize(); ++$index){
                
    $this->setItem($index$this->inventory->getItem($index));
            }
        }

        
    /**
         * @return int
         */
        
    public function getSize(){
            return 
    4;
        }

        
    /**
         * @param $index
         *
         * @return int
         */
        
    protected function getSlotIndex($index){
            foreach(
    $this->namedtag->Items as $i => $slot){
                if(
    $slot["Slot"] === $index){
                    return 
    $i;
                }
            }

            return -
    1;
        }

        
    /**
         * This method should not be used by plugins, use the Inventory
         *
         * @param int $index
         *
         * @return Item
         */
        
    public function getItem($index){
            
    $i $this->getSlotIndex($index);
            if(
    $i 0){
                return 
    Item::get(Item::AIR00);
            }else{
                return 
    NBT::getItemHelper($this->namedtag->Items[$i]);
            }
        }

        
    /**
         * This method should not be used by plugins, use the Inventory
         *
         * @param int  $index
         * @param Item $item
         *
         * @return bool
         */
        
    public function setItem($indexItem $item){
            
    $i $this->getSlotIndex($index);

            
    $d NBT::putItemHelper($item$index);

            if(
    $item->getId() === Item::AIR or $item->getCount() <= 0){
                if(
    $i >= 0){
                    unset(
    $this->namedtag->Items[$i]);
                }
            }elseif(
    $i 0){
                for(
    $i 0$i <= $this->getSize(); ++$i){
                    if(!isset(
    $this->namedtag->Items[$i])){
                        break;
                    }
                }
                
    $this->namedtag->Items[$i] = $d;
            }else{
                
    $this->namedtag->Items[$i] = $d;
            }

            return 
    true;
        }

        
    /**
         * @return BrewingInventory
         */
        
    public function getInventory(){
            return 
    $this->inventory;
        }

        protected function 
    checkIngredient(Item $ingredient){
            if(
    in_array($ingredient->getId(), self::$ingredients)){
                
    $this->namedtag->BrewTime = new Short("BrewTime"self::MAX_BREW_TIME);
                
    $ingredient->setCount($ingredient->getCount() - 1);
                
    $this->inventory->setIngredient($ingredient);
                return 
    true;
            }

            return 
    false;
        }

        public function 
    onUpdate(){
            if(
    $this->closed === true){
                echo 
    "closed";
                return 
    false;
            }

            
    $this->timings->startTiming();

            
    $ret false;

            
    $ingredient $this->inventory->getIngredient();
            
    $potions $this->inventory->getPotions();
            
    $canBrew false;

            foreach(
    $potions as $pot){
                if(
    $pot->getId() === Item::POTION){
                    
    $canBrew true;
                }
            }

            
    print_r($canBrew);

            if(
    $this->namedtag["BrewTime"] <= and $canBrew and $ingredient->getCount() > 0){
                
    $this->checkIngredient($ingredient);
            }

            if(
    $canBrew){
                
    $this->namedtag->BrewTime = new Short("BrewTime"$this->namedtag["BrewTime"] + 1);
                echo 
    " brewinguji... ";
                if (
    $this->namedtag["BrewTime"] >= self::MAX_BREW_TIME) { //20 seconds

                    /*foreach($recipes as $key => $recipe){
                        if(!$recipe || !$recipe instanceof BrewingRecipe){
                            continue;
                        }
                        $this->inventory->setPotion($key, $recipe->getResult());
                    }*/

                    
    echo " brewing hotovo! ";

                    
    $this->namedtag->BrewTime = new Short("BrewTime"$this->namedtag["BrewTime"] - 400);
                }
            }else {
                
    $this->namedtag->BrewTime = new Short("BrewTime"0);
            }
            
    $ret true;

            foreach(
    $this->getInventory()->getViewers() as $player){
                
    $windowId $player->getWindowId($this->getInventory());
                if(
    $windowId 0){
                    
    $pk = new ContainerSetDataPacket();
                    
    $pk->windowid $windowId;
                    
    $pk->property 0//Brewing
                    
    $pk->value floor($this->namedtag["BrewTime"]);
                    
    $player->dataPacket($pk);
                }

            }

            
    $this->lastUpdate microtime(true);

            
    $this->timings->stopTiming();

            return 
    $ret;
        }
    }
    minebuilder0110 likes this.
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OMG now it works!!!!! :D
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Can't you commit to at least PM?
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    no they don't merge any pull request and idk why there are 44 pull requests
    Legoboy0215 likes this.
  5. SlowByStep
    Offline

    SlowByStep New Member

    Joined:
    Nov 4, 2015
    Posts:
    14
    Minecraft User:
    PandaYTB
    Post it pls? :)
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I am telling him another alternative to posting on PM github. IK IG Repo is a mess, but hey! Tried our best.
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    WTF!!?? This code doesn'T work but players can brew all potions and server dont remove it! and it works perfectly WTF??? how? xDDD can you explain me this? :D
  8. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    You can pretty much do anything with php so..eh :p

    A post from Google

    PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. There are three main areas where PHPscripts are used. Server-side scripting.

    So to me it's unexplainable, what do you think?
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but i didnt add any brewing recipe :D and onUpdate() doesn't run :D but players can brew potions, but pocketmine checks items so idk how :D
  10. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    The recipes were probably already added to pocketmine but the ability to brew them or even drink them was probably disabled or super buggy. And the plug in probably became a substitute for the coding and fixed any or all the bugs regarding brewing.

    Example: PlayHarder, and Entity manager

    Hunger and experience

    Mobs..HOW?
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    no recipes were not added. and I added drinking potions :D
  12. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    idk it is steadfast not normal pocketmine
  14. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    *off-topic* can you share the code?
  15. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    ok there is also fixed crafting
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    :)

    Attached Files:

    • src.zip
      File size:
      852.8 KB
      Views:
      47
    TryoneLegendZzz likes this.
  17. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Thank You !
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but i disabled item moving too because it is a bit buggy in steadfast
  19. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    thank you sir ;)
  20. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    You have magic.. lucky Creeper :D
    Creeperface likes this.

Share This Page

Advertisement