TypeConverter: avoid repeated calls to getId() and getMeta()

This commit is contained in:
Dylan K. Taylor 2023-04-18 15:02:52 +01:00
parent 6102740ee3
commit a77fc8109f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -143,7 +143,9 @@ class TypeConverter{
$nbt = clone $nbt;
}
$idMeta = ItemTranslator::getInstance()->toNetworkIdQuiet($itemStack->getId(), $itemStack->getMeta());
$internalId = $itemStack->getId();
$internalMeta = $itemStack->getMeta();
$idMeta = ItemTranslator::getInstance()->toNetworkIdQuiet($internalId, $internalMeta);
if($idMeta === null){
//Display unmapped items as INFO_UPDATE, but stick something in their NBT to make sure they don't stack with
//other unmapped items.
@ -151,8 +153,8 @@ class TypeConverter{
if($nbt === null){
$nbt = new CompoundTag();
}
$nbt->setInt(self::PM_ID_TAG, $itemStack->getId());
$nbt->setInt(self::PM_META_TAG, $itemStack->getMeta());
$nbt->setInt(self::PM_ID_TAG, $internalId);
$nbt->setInt(self::PM_META_TAG, $internalMeta);
}else{
[$id, $meta] = $idMeta;
@ -171,7 +173,7 @@ class TypeConverter{
}
$blockRuntimeId = 0;
if($itemStack->getId() < 256){
if($internalId < 256){
$block = $itemStack->getBlock();
if($block->getId() !== BlockLegacyIds::AIR){
$blockRuntimeId = RuntimeBlockMapping::getInstance()->toRuntimeId($block->getFullId());