public function __construct(FullChunk $chunk, Compound $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));
     }
 }
 public function __construct(FullChunk $chunk, CompoundTag $nbt)
 {
     parent::__construct($chunk, $nbt);
     $this->inventory = new BrewingInventory($this);
     if (!isset($this->namedtag->Items) or !$this->namedtag->Items instanceof ListTag) {
         $this->namedtag->Items = new ListTag("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"] > self::MAX_BREW_TIME) {
         $this->namedtag->BrewTime = new ShortTag("BrewTime", self::MAX_BREW_TIME);
     }
     if ($this->namedtag["BrewTime"] < self::MAX_BREW_TIME) {
         $this->scheduleUpdate();
     }
 }
Exemple #3
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $ret = false;
     $ingredient = $this->inventory->getIngredient();
     $canBrew = false;
     for ($i = 1; $i <= 3; $i++) {
         if ($this->inventory->getItem($i)->getId() == Item::POTION) {
             $canBrew = true;
             break;
         }
     }
     if ($this->namedtag["CookTime"] <= self::MAX_BREW_TIME and $canBrew and $ingredient->getCount() > 0) {
         //if(!$this->checkIngredient($ingredient)) $canBrew = false;
         //TODO: check ingredients
     } else {
         $canBrew = false;
     }
     if ($canBrew) {
         $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 1);
         if ($this->namedtag["CookTime"] <= 0) {
             for ($i = 1; $i <= 3; $i++) {
                 $potion = $this->inventory->getItem($i);
                 $recipe = Server::getInstance()->getCraftingManager()->matchBrewingRecipe($ingredient, $potion);
                 if ($recipe != null) {
                     $this->inventory->setItem($i, $recipe->getResult());
                 }
             }
             $ingredient->count--;
             if ($ingredient->getCount() <= 0) {
                 $ingredient = Item::get(Item::AIR);
             }
             $this->inventory->setIngredient($ingredient);
         }
         foreach ($this->getInventory()->getViewers() as $player) {
             $windowId = $player->getWindowId($this->getInventory());
             if ($windowId > 0) {
                 $pk = new ContainerSetDataPacket();
                 $pk->windowid = $windowId;
                 $pk->property = 0;
                 //Brew
                 $pk->value = $this->namedtag["CookTime"];
                 $player->dataPacket($pk);
             }
         }
         $ret = true;
     } else {
         $this->namedtag->CookTime = new ShortTag("CookTime", self::MAX_BREW_TIME);
     }
     $this->lastUpdate = microtime(true);
     $this->timings->stopTiming();
     return $ret;
 }