Exterminate legacy item IDs

This commit is contained in:
Dylan K. Taylor
2022-07-05 15:12:55 +01:00
parent c5282b059b
commit 68cbe46600
19 changed files with 375 additions and 1180 deletions

View File

@ -142,6 +142,7 @@ use function max;
use function mb_strlen;
use function microtime;
use function min;
use function morton2d_encode;
use function preg_match;
use function spl_object_id;
use function sqrt;
@ -641,7 +642,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
*/
public function getItemCooldownExpiry(Item $item) : int{
$this->checkItemCooldowns();
return $this->usedItemsCooldown[$item->getId()] ?? 0;
return $this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())] ?? 0;
}
/**
@ -649,7 +650,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
*/
public function hasItemCooldown(Item $item) : bool{
$this->checkItemCooldowns();
return isset($this->usedItemsCooldown[$item->getId()]);
return isset($this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())]);
}
/**
@ -658,7 +659,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function resetItemCooldown(Item $item, ?int $ticks = null) : void{
$ticks = $ticks ?? $item->getCooldownTicks();
if($ticks > 0){
$this->usedItemsCooldown[$item->getId()] = $this->server->getTick() + $ticks;
$this->usedItemsCooldown[morton2d_encode($item->getTypeId(), $item->computeTypeData())] = $this->server->getTick() + $ticks;
}
}