GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
BrewingStand Class Reference

Public Member Functions

 __construct (Level $level, CompoundTag $nbt)
 
 getName ()
 
 hasName ()
 
 setName ($str)
 
 close ()
 
 saveNBT ()
 
 getSize ()
 
 getItem ($index)
 
 setItem ($index, Item $item)
 
 getInventory ()
 
 checkIngredient (Item $item)
 
 updateSurface ()
 
 onUpdate ()
 
 getSpawnCompound ()
 
- Public Member Functions inherited from Spawnable
 spawnTo (Player $player)
 
 __construct (Level $level, CompoundTag $nbt)
 
 spawnToAll ()
 
 getSpawnCompound ()
 
 updateCompoundTag (CompoundTag $nbt, Player $player)
 
- Public Member Functions inherited from Tile
 getSaveId ()
 
 __construct (Level $level, CompoundTag $nbt)
 
 getId ()
 
 saveNBT ()
 
 getBlock ()
 
 onUpdate ()
 
 scheduleUpdate ()
 
 __destruct ()
 
 close ()
 
 getName ()
 
- Public Member Functions inherited from Position
 __construct ($x=0, $y=0, $z=0, Level $level=null)
 
 asPosition ()
 
 add ($x, $y=0, $z=0)
 
 getLevel ()
 
 setLevel (Level $level=null)
 
 isValid ()
 
 getSide ($side, $step=1)
 
 __toString ()
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
- Public Member Functions inherited from Vector3
 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 

Data Fields

const MAX_BREW_TIME = 400
 
- Data Fields inherited from Tile
const BREWING_STAND = "BrewingStand"
 
const CHEST = "Chest"
 
const DL_DETECTOR = "DayLightDetector"
 
const ENCHANT_TABLE = "EnchantTable"
 
const FLOWER_POT = "FlowerPot"
 
const FURNACE = "Furnace"
 
const MOB_SPAWNER = "MobSpawner"
 
const SIGN = "Sign"
 
const SKULL = "Skull"
 
const ITEM_FRAME = "ItemFrame"
 
const DISPENSER = "Dispenser"
 
const DROPPER = "Dropper"
 
const CAULDRON = "Cauldron"
 
const HOPPER = "Hopper"
 
const BEACON = "Beacon"
 
const ENDER_CHEST = "EnderChest"
 
const BED = "Bed"
 
const DAY_LIGHT_DETECTOR = "DLDetector"
 
 $chunk
 
 $name
 
 $id
 
 $x
 
 $y
 
 $z
 
 $attach
 
 $metadata
 
 $closed = false
 
 $namedtag
 
 $tickTimer
 
- Data Fields inherited from Position
 $level = null
 
- Data Fields inherited from Vector3
const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 

Static Public Attributes

static $ingredients
 
- Static Public Attributes inherited from Tile
static $tileCount = 1
 

Protected Member Functions

 getSlotIndex ($index)
 
- Protected Member Functions inherited from Spawnable
 onChanged ()
 

Protected Attributes

 $inventory
 
- Protected Attributes inherited from Tile
 $lastUpdate
 
 $server
 
 $timings
 

Additional Inherited Members

- Static Public Member Functions inherited from Tile
static init ()
 
static createTile ($type, Level $level, CompoundTag $nbt,... $args)
 
static registerTile ($className)
 
- Static Public Member Functions inherited from Position
static fromObject (Vector3 $pos, Level $level=null)
 
- Static Public Member Functions inherited from Vector3
static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
CompoundTag  $nbt 
)

BrewingStand constructor.

Parameters
Level$level
CompoundTag$nbt
68  {
69  if(!isset($nbt->CookedTime) or !($nbt->CookedTime instanceof ShortTag)){
70  $nbt->CookedTime = new ShortTag("CookedTime", 0);
71  }
72  parent::__construct($level, $nbt);
73  $this->inventory = new BrewingInventory($this);
74  if(!isset($this->namedtag->Items) or !($this->namedtag->Items instanceof ListTag)){
75  $this->namedtag->Items = new ListTag("Items", []);
76  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
77  }
78  for($i = 0; $i < $this->getSize(); ++$i){
79  $this->inventory->setItem($i, $this->getItem($i));
80  }
81  /*if($this->namedtag["CookTime"] < self::MAX_BREW_TIME){
82  $this->scheduleUpdate();
83  }*/
84  }

Member Function Documentation

◆ checkIngredient()

checkIngredient ( Item  $item)
Parameters
Item$item
Returns
bool
208  {
209  if(isset(self::$ingredients[$item->getId()])){
210  if(self::$ingredients[$item->getId()] === $item->getDamage()){
211  return true;
212  }
213  }
214  return false;
215  }

◆ close()

close ( )
112  {
113  if(!$this->closed){
114  foreach($this->getInventory()->getViewers() as $player){
115  $player->removeWindow($this->getInventory());
116  }
117  parent::close();
118  }
119  }

◆ getInventory()

getInventory ( )
Returns
BrewingInventory

Implements InventoryHolder.

199  {
200  return $this->inventory;
201  }

◆ getItem()

getItem (   $index)

This method should not be used by plugins, use the Inventory

Parameters
int$index
Returns
Item

Implements Container.

158  {
159  $i = $this->getSlotIndex($index);
160  if($i < 0){
161  return Item::get(Item::AIR, 0, 0);
162  }else{
163  return Item::nbtDeserialize($this->namedtag->Items[$i]);
164  }
165  }

◆ getName()

getName ( )
Returns
string

Implements Nameable.

89  : string{
90  return $this->hasName() ? $this->namedtag->CustomName->getValue() : "Brewing Stand";
91  }

◆ getSize()

getSize ( )
Returns
int

Implements Container.

132  {
133  return 4;
134  }

◆ getSlotIndex()

getSlotIndex (   $index)
protected
Parameters
$index
Returns
int
141  {
142  foreach($this->namedtag->Items as $i => $slot){
143  if($slot["Slot"] === $index){
144  return $i;
145  }
146  }
147 
148  return -1;
149  }

◆ getSpawnCompound()

getSpawnCompound ( )
Returns
CompoundTag
320  {
321  $nbt = new CompoundTag("", [
322  new StringTag("id", Tile::BREWING_STAND),
323  new IntTag("x", (int) $this->x),
324  new IntTag("y", (int) $this->y),
325  new IntTag("z", (int) $this->z),
326  new ShortTag("CookTime", self::MAX_BREW_TIME),
327  $this->namedtag->Items,
328  ]);
329 
330  if($this->hasName()){
331  $nbt->CustomName = $this->namedtag->CustomName;
332  }
333  return $nbt;
334  }

◆ hasName()

hasName ( )
Returns
bool

Implements Nameable.

96  {
97  return isset($this->namedtag->CustomName);
98  }

◆ onUpdate()

onUpdate ( )
Returns
bool
225  {
226  if($this->closed === true){
227  return false;
228  }
229 
230  $this->timings->startTiming();
231 
232  $ret = false;
233 
234  $ingredient = $this->inventory->getIngredient();
235  $canBrew = false;
236 
237  for($i = 1; $i <= 3; $i++){
238  if($this->inventory->getItem($i)->getId() === Item::POTION or
239  $this->inventory->getItem($i)->getId() === Item::SPLASH_POTION
240  ){
241  $canBrew = true;
242  }
243  }
244 
245  if($ingredient->getId() !== Item::AIR and $ingredient->getCount() > 0){
246  if($canBrew){
247  if(!$this->checkIngredient($ingredient)){
248  $canBrew = false;
249  }
250  }
251 
252  if($canBrew){
253  for($i = 1; $i <= 3; $i++){
254  $potion = $this->inventory->getItem($i);
255  $recipe = Server::getInstance()->getCraftingManager()->matchBrewingRecipe($ingredient, $potion);
256  if($recipe !== null){
257  $canBrew = true;
258  break;
259  }
260  $canBrew = false;
261  }
262  }
263  }else{
264  $canBrew = false;
265  }
266 
267  if($canBrew){
268  $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 1);
269 
270  foreach($this->getInventory()->getViewers() as $player){
271  $windowId = $player->getWindowId($this->getInventory());
272  if($windowId > 0){
273  $pk = new ContainerSetDataPacket();
274  $pk->windowid = $windowId;
275  $pk->property = 0; //Brew
276  $pk->value = $this->namedtag["CookTime"];
277  $player->dataPacket($pk);
278  }
279  }
280 
281  if($this->namedtag["CookTime"] <= 0){
282  $this->namedtag->CookTime = new ShortTag("CookTime", self::MAX_BREW_TIME);
283  for($i = 1; $i <= 3; $i++){
284  $potion = $this->inventory->getItem($i);
285  $recipe = Server::getInstance()->getCraftingManager()->matchBrewingRecipe($ingredient, $potion);
286  if($recipe != null and $potion->getId() !== Item::AIR){
287  $this->inventory->setItem($i, $recipe->getResult());
288  }
289  }
290 
291  $ingredient->count--;
292  if($ingredient->getCount() <= 0) $ingredient = Item::get(Item::AIR);
293  $this->inventory->setIngredient($ingredient);
294  }
295 
296  $ret = true;
297  }else{
298  $this->namedtag->CookTime = new ShortTag("CookTime", self::MAX_BREW_TIME);
299  foreach($this->getInventory()->getViewers() as $player){
300  $windowId = $player->getWindowId($this->getInventory());
301  if($windowId > 0){
302  $pk = new ContainerSetDataPacket();
303  $pk->windowid = $windowId;
304  $pk->property = 0; //Brew
305  $pk->value = 0;
306  $player->dataPacket($pk);
307  }
308  }
309  }
310  $this->lastUpdate = microtime(true);
311 
312  $this->timings->stopTiming();
313 
314  return $ret;
315  }

◆ saveNBT()

saveNBT ( )
121  {
122  $this->namedtag->Items = new ListTag("Items", []);
123  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
124  for($index = 0; $index < $this->getSize(); ++$index){
125  $this->setItem($index, $this->inventory->getItem($index));
126  }
127  }

◆ setItem()

setItem (   $index,
Item  $item 
)

This method should not be used by plugins, use the Inventory

Parameters
int$index
Item$item
Returns
bool

Implements Container.

175  {
176  $i = $this->getSlotIndex($index);
177 
178  if($item->getId() === Item::AIR or $item->getCount() <= 0){
179  if($i >= 0){
180  unset($this->namedtag->Items[$i]);
181  }
182  }elseif($i < 0){
183  for($i = 0; $i <= $this->getSize(); ++$i){
184  if(!isset($this->namedtag->Items[$i])){
185  break;
186  }
187  }
188  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
189  }else{
190  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
191  }
192 
193  return true;
194  }

◆ setName()

setName (   $str)
Parameters
void$str

Implements Nameable.

103  {
104  if($str === ""){
105  unset($this->namedtag->CustomName);
106  return;
107  }
108 
109  $this->namedtag->CustomName = new StringTag("CustomName", $str);
110  }

◆ updateSurface()

updateSurface ( )
217  {
218  $this->saveNBT();
219  $this->onChanged();
220  }

Field Documentation

◆ $ingredients

$ingredients
static
Initial value:

◆ $inventory

$inventory
protected

◆ MAX_BREW_TIME

const MAX_BREW_TIME = 400

The documentation for this class was generated from the following file: