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

@ -91,7 +91,7 @@ class CraftingManager{
*/
public static function sort(Item $i1, Item $i2) : int{
//Use spaceship operator to compare each property, then try the next one if they are equivalent.
($retval = $i1->getId() <=> $i2->getId()) === 0 && ($retval = $i1->getMeta() <=> $i2->getMeta()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()) === 0;
($retval = $i1->getTypeId() <=> $i2->getTypeId()) === 0 && ($retval = $i1->computeTypeData() <=> $i2->computeTypeData()) === 0 && ($retval = $i1->getCount() <=> $i2->getCount()) === 0;
return $retval;
}
@ -130,8 +130,7 @@ class CraftingManager{
foreach($outputs as $o){
//count is not written because the outputs might be from multiple repetitions of a single recipe
//this reduces the accuracy of the hash, but it won't matter in most cases.
$result->putVarInt($o->getId());
$result->putVarInt($o->getMeta());
$result->putVarInt(morton2d_encode($o->getTypeId(), $o->computeTypeData()));
$result->put((new LittleEndianNbtSerializer())->write(new TreeRoot($o->getNamedTag())));
}
@ -256,8 +255,8 @@ class CraftingManager{
}
public function matchBrewingRecipe(Item $input, Item $ingredient) : ?BrewingRecipe{
$inputHash = morton2d_encode($input->getId(), $input->getMeta());
$ingredientHash = morton2d_encode($ingredient->getId(), $ingredient->getMeta());
$inputHash = morton2d_encode($input->getTypeId(), $input->computeTypeData());
$ingredientHash = morton2d_encode($ingredient->getTypeId(), $ingredient->computeTypeData());
$cached = $this->brewingRecipeCache[$inputHash][$ingredientHash] ?? null;
if($cached !== null){
return $cached;