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

Public Member Functions

 __construct (Level $level, CompoundTag $nbt)
 
 getName ()
 
 hasName ()
 
 setName ($str)
 
 close ()
 
 saveNBT ()
 
 getSize ()
 
 getItem ($index)
 
 setItem ($index, Item $item)
 
 getInventory ()
 
 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 ()
 

Protected Member Functions

 getSlotIndex ($index)
 
 checkFuel (Item $fuel)
 
- 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)
 
- 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 inherited from Tile
static $tileCount = 1
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
CompoundTag  $nbt 
)

Furnace constructor.

Parameters
Level$level
CompoundTag$nbt
50  {
51  if(!isset($nbt->BurnTime) or $nbt["BurnTime"] < 0){
52  $nbt->BurnTime = new ShortTag("BurnTime", 0);
53  }
54  if(!isset($nbt->CookTime) or !($nbt->CookTime instanceof ShortTag) or $nbt["CookTime"] < 0 or ($nbt["BurnTime"] === 0 and $nbt["CookTime"] > 0)){
55  $nbt->CookTime = new ShortTag("CookTime", 0);
56  }
57  if(!isset($nbt->MaxTime) or !($nbt->MaxTime instanceof ShortTag)){
58  $nbt->MaxTime = new ShortTag("BurnTime", $nbt["BurnTime"]);
59  $nbt->BurnTicks = new ShortTag("BurnTicks", 0);
60  }
61 
62  parent::__construct($level, $nbt);
63  $this->inventory = new FurnaceInventory($this);
64  if(!isset($this->namedtag->Items) or !($this->namedtag->Items instanceof ListTag)){
65  $this->namedtag->Items = new ListTag("Items", []);
66  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
67  }
68  for($i = 0; $i < $this->getSize(); ++$i){
69  $this->inventory->setItem($i, $this->getItem($i));
70  }
71  if($this->namedtag["BurnTime"] > 0){
72  $this->scheduleUpdate();
73  }
74  }

Member Function Documentation

◆ checkFuel()

checkFuel ( Item  $fuel)
protected
Parameters
Item$fuel
196  {
197  $this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime()));
198 
199  if($ev->isCancelled()){
200  return;
201  }
202 
203  $this->namedtag->MaxTime = new ShortTag("MaxTime", $ev->getBurnTime());
204  $this->namedtag->BurnTime = new ShortTag("BurnTime", $ev->getBurnTime());
205  $this->namedtag->BurnTicks = new ShortTag("BurnTicks", 0);
206  if($this->getBlock()->getId() === Item::FURNACE){
207  $this->getLevel()->setBlock($this, Block::get(Item::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
208  }
209 
210  if($this->namedtag["BurnTime"] > 0 and $ev->isBurning()){
211  if($fuel->getId() === Item::BUCKET and $fuel->getDamage() === Item::LAVA){
212  $fuel = Item::get(Item::BUCKET, 0, 1);
213  $this->inventory->setFuel($fuel);
214  }else{
215  $fuel->setCount($fuel->getCount() - 1);
216  if($fuel->getCount() === 0){
217  $fuel = Item::get(Item::AIR, 0, 0);
218  }
219  $this->inventory->setFuel($fuel);
220  }
221  }
222  }

◆ close()

close ( )
102  {
103  if($this->closed === false){
104  foreach($this->getInventory()->getViewers() as $player){
105  $player->removeWindow($this->getInventory());
106  }
107  parent::close();
108  }
109  }

◆ getInventory()

getInventory ( )
Returns
FurnaceInventory

Implements InventoryHolder.

189  {
190  return $this->inventory;
191  }

◆ getItem()

getItem (   $index)

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

Parameters
int$index
Returns
Item

Implements Container.

148  {
149  $i = $this->getSlotIndex($index);
150  if($i < 0){
151  return Item::get(Item::AIR, 0, 0);
152  }else{
153  return Item::nbtDeserialize($this->namedtag->Items[$i]);
154  }
155  }

◆ getName()

getName ( )
Returns
string

Implements Nameable.

79  : string{
80  return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Furnace";
81  }

◆ getSize()

getSize ( )
Returns
int

Implements Container.

122  {
123  return 3;
124  }

◆ getSlotIndex()

getSlotIndex (   $index)
protected
Parameters
$index
Returns
int
131  {
132  foreach($this->namedtag->Items as $i => $slot){
133  if($slot["Slot"] === $index){
134  return $i;
135  }
136  }
137 
138  return -1;
139  }

◆ getSpawnCompound()

getSpawnCompound ( )
Returns
CompoundTag
313  {
314  $nbt = new CompoundTag("", [
315  new StringTag("id", Tile::FURNACE),
316  new IntTag("x", (int) $this->x),
317  new IntTag("y", (int) $this->y),
318  new IntTag("z", (int) $this->z),
319  new ShortTag("BurnTime", $this->namedtag["BurnTime"]),
320  new ShortTag("CookTime", $this->namedtag["CookTime"]),
321  //new ShortTag("BurnDuration", $this->namedtag["BurnTicks"])
322  ]);
323 
324  if($this->hasName()){
325  $nbt->CustomName = $this->namedtag->CustomName;
326  }
327  return $nbt;
328  }

◆ hasName()

hasName ( )
Returns
bool

Implements Nameable.

86  {
87  return isset($this->namedtag->CustomName);
88  }

◆ onUpdate()

onUpdate ( )
Returns
bool
227  {
228  if($this->closed === true){
229  return false;
230  }
231 
232  $this->timings->startTiming();
233 
234  $ret = false;
235 
236  $fuel = $this->inventory->getFuel();
237  $raw = $this->inventory->getSmelting();
238  $product = $this->inventory->getResult();
239  $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw);
240  $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->getId() === Item::AIR));
241 
242  if($this->namedtag["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0){
243  $this->checkFuel($fuel);
244  }
245 
246  if($this->namedtag["BurnTime"] > 0){
247  $this->namedtag->BurnTime = new ShortTag("BurnTime", $this->namedtag["BurnTime"] - 1);
248  $this->namedtag->BurnTicks = new ShortTag("BurnTicks", ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200)));
249 
250  if($smelt instanceof FurnaceRecipe and $canSmelt){
251  $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] + 1);
252  if($this->namedtag["CookTime"] >= 200){ //10 seconds
253  $product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
254 
255  $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product));
256 
257  if(!$ev->isCancelled()){
258  $this->inventory->setResult($ev->getResult());
259  $raw->setCount($raw->getCount() - 1);
260  if($raw->getCount() === 0){
261  $raw = Item::get(Item::AIR, 0, 0);
262  }
263  $this->inventory->setSmelting($raw);
264  }
265 
266  $this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 200);
267  }
268  }elseif($this->namedtag["BurnTime"] <= 0){
269  $this->namedtag->BurnTime = new ShortTag("BurnTime", 0);
270  $this->namedtag->CookTime = new ShortTag("CookTime", 0);
271  $this->namedtag->BurnTicks = new ShortTag("BurnTicks", 0);
272  }else{
273  $this->namedtag->CookTime = new ShortTag("CookTime", 0);
274  }
275  $ret = true;
276  }else{
277  if($this->getBlock()->getId() === Item::BURNING_FURNACE){
278  $this->getLevel()->setBlock($this, Block::get(Item::FURNACE, $this->getBlock()->getDamage()), true);
279  }
280  $this->namedtag->BurnTime = new ShortTag("BurnTime", 0);
281  $this->namedtag->CookTime = new ShortTag("CookTime", 0);
282  $this->namedtag->BurnTicks = new ShortTag("BurnTicks", 0);
283  }
284 
285  foreach($this->getInventory()->getViewers() as $player){
286  $windowId = $player->getWindowId($this->getInventory());
287  if($windowId > 0){
288  $pk = new ContainerSetDataPacket();
289  $pk->windowid = $windowId;
290  $pk->property = 0; //Smelting
291  $pk->value = floor($this->namedtag["CookTime"]);
292  $player->dataPacket($pk);
293 
294  $pk = new ContainerSetDataPacket();
295  $pk->windowid = $windowId;
296  $pk->property = 1; //Fire icon
297  $pk->value = $this->namedtag["BurnTicks"];
298  $player->dataPacket($pk);
299  }
300 
301  }
302 
303  $this->lastUpdate = microtime(true);
304 
305  $this->timings->stopTiming();
306 
307  return $ret;
308  }

◆ saveNBT()

saveNBT ( )
111  {
112  $this->namedtag->Items = new ListTag("Items", []);
113  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
114  for($index = 0; $index < $this->getSize(); ++$index){
115  $this->setItem($index, $this->inventory->getItem($index));
116  }
117  }

◆ 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.

165  {
166  $i = $this->getSlotIndex($index);
167 
168  if($item->getId() === Item::AIR or $item->getCount() <= 0){
169  if($i >= 0){
170  unset($this->namedtag->Items[$i]);
171  }
172  }elseif($i < 0){
173  for($i = 0; $i <= $this->getSize(); ++$i){
174  if(!isset($this->namedtag->Items[$i])){
175  break;
176  }
177  }
178  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
179  }else{
180  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
181  }
182 
183  return true;
184  }

◆ setName()

setName (   $str)
Parameters
void$str

Implements Nameable.

93  {
94  if($str === ""){
95  unset($this->namedtag->CustomName);
96  return;
97  }
98 
99  $this->namedtag->CustomName = new StringTag("CustomName", $str);
100  }

Field Documentation

◆ $inventory

$inventory
protected

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