Type-hinted NBT tag constructors, made getValue() and setValue() more strict, fix dozens of assorted related bugs

This commit is contained in:
Dylan K. Taylor
2017-06-08 19:17:41 +01:00
parent 595e1ab52f
commit 890f72dbf2
24 changed files with 348 additions and 65 deletions

View File

@ -72,15 +72,15 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
}
}
public function getName(){
public function getName() : string{
return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Furnace";
}
public function hasName(){
public function hasName() : bool{
return isset($this->namedtag->CustomName);
}
public function setName($str){
public function setName(string $str){
if($str === ""){
unset($this->namedtag->CustomName);
return;
@ -228,11 +228,11 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
}
if($this->namedtag["BurnTime"] > 0){
$this->namedtag->BurnTime = new ShortTag("BurnTime", $this->namedtag["BurnTime"] - 1);
$this->namedtag->BurnTime = new ShortTag("BurnTime", ((int) $this->namedtag["BurnTime"]) - 1);
$this->namedtag->BurnTicks = new ShortTag("BurnTicks", (int) ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200)));
if($smelt instanceof FurnaceRecipe and $canSmelt){
$this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] + 1);
$this->namedtag->CookTime = new ShortTag("CookTime", (int) ($this->namedtag["CookTime"]) + 1);
if($this->namedtag["CookTime"] >= 200){ //10 seconds
$product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
@ -247,7 +247,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
$this->inventory->setSmelting($raw);
}
$this->namedtag->CookTime = new ShortTag("CookTime", $this->namedtag["CookTime"] - 200);
$this->namedtag->CookTime = new ShortTag("CookTime", ((int) $this->namedtag["CookTime"]) - 200);
}
}elseif($this->namedtag["BurnTime"] <= 0){
$this->namedtag->BurnTime = new ShortTag("BurnTime", 0);
@ -297,8 +297,8 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
new IntTag("x", (int) $this->x),
new IntTag("y", (int) $this->y),
new IntTag("z", (int) $this->z),
new ShortTag("BurnTime", $this->namedtag["BurnTime"]),
new ShortTag("CookTime", $this->namedtag["CookTime"])
new ShortTag("BurnTime", (int) $this->namedtag["BurnTime"]),
new ShortTag("CookTime", (int) $this->namedtag["CookTime"])
]);
if($this->hasName()){