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_STAND, 0, $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 $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ $faces = [ 0 => 4, 1 => 2, 2 => 5, 3 => 3, ]; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; $this->getLevel()->setBlock($block, $this, true, true); $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->x >> 4, $this->z >> 4), $nbt); return true; } public function onBreak(Item $item){ $this->getLevel()->setBlock($this, new Air(), true, true); return true; } public function onActivate(Item $item, Player $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->x >> 4, $this->z >> 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_STAND, 0, 1]; } return $drops; }} PHP: class BrewingStand extends Tile implements InventoryHolder, Container, Nameable{ /** @var BrewingInventory */ protected $inventory; const MAX_BREW_TIME = 400; public static $ingredients = [Item::NETHER_WART, Item::GOLD_NUGGET, Item::GHAST_TEAR, Item::GLOWSTONE_DUST, Item::REDSTONE_DUST, Item::GUNPOWDER, Item::MAGMA_CREAM, Item::BLAZE_POWDER, Item::GOLDEN_CARROT, Item::SPIDER_EYE, Item::FERMENTED_SPIDER_EYE, Item::GLISTERING_MELON]; 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)); } 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::AIR, 0, 0); }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($index, Item $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"] <= 0 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; }}
I am telling him another alternative to posting on PM github. IK IG Repo is a mess, but hey! Tried our best.
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?
You can pretty much do anything with php so..eh 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?
but i didnt add any brewing recipe and onUpdate() doesn't run but players can brew potions, but pocketmine checks items so idk how
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?