Block: change confusing naming of decode/computeStateData

these actually accept a combination of type and state data, so it's a bit inconsistent with other references to 'state data'.
This commit is contained in:
Dylan K. Taylor 2023-03-02 17:42:44 +00:00
parent 972f107972
commit 95c18ef99a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 8 additions and 8 deletions

View File

@ -132,7 +132,7 @@ class Block{
* This ID can be used to later obtain a copy of this block using {@link RuntimeBlockStateRegistry::fromStateId()}.
*/
public function getStateId() : int{
return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->computeStateData();
return ($this->getTypeId() << self::INTERNAL_STATE_DATA_BITS) | $this->computeTypeAndStateData();
}
/**
@ -214,7 +214,7 @@ class Block{
/**
* @internal
*/
final public function decodeStateData(int $data) : void{
final public function decodeTypeAndStateData(int $data) : void{
$typeBits = $this->getRequiredTypeDataBits();
$stateBits = $this->getRequiredStateDataBits();
$reader = new RuntimeDataReader($typeBits + $stateBits, $data);
@ -246,7 +246,7 @@ class Block{
/**
* @internal
*/
final public function computeStateData() : int{
final public function computeTypeAndStateData() : int{
$typeBits = $this->getRequiredTypeDataBits();
$stateBits = $this->getRequiredStateDataBits();
$writer = new RuntimeDataWriter($typeBits + $stateBits);
@ -720,7 +720,7 @@ class Block{
* @return string
*/
public function __toString(){
return "Block[" . $this->getName() . "] (" . $this->getTypeId() . ":" . $this->computeStateData() . ")";
return "Block[" . $this->getName() . "] (" . $this->getTypeId() . ":" . $this->computeTypeAndStateData() . ")";
}
/**

View File

@ -97,10 +97,10 @@ class RuntimeBlockStateRegistry{
for($stateData = 0; $stateData < (1 << $bits); ++$stateData){
$v = clone $block;
try{
$v->decodeStateData($stateData);
if($v->computeStateData() !== $stateData){
$v->decodeTypeAndStateData($stateData);
if($v->computeTypeAndStateData() !== $stateData){
//TODO: this should probably be a hard error
throw new \LogicException(get_class($block) . "::decodeStateData() accepts invalid state data (returned " . $v->computeStateData() . " for input $stateData)");
throw new \LogicException(get_class($block) . "::decodeStateData() accepts invalid state data (returned " . $v->computeTypeAndStateData() . " for input $stateData)");
}
}catch(InvalidSerializedRuntimeDataException){ //invalid property combination, leave it
continue;

View File

@ -126,7 +126,7 @@ class BlockTest extends TestCase{
$states = $this->blockFactory->getAllKnownStates();
foreach($states as $stateId => $state){
self::assertArrayHasKey($stateId, $knownStates, "New block state $stateId (" . $state->getTypeId() . ":" . $state->computeStateData() . ", " . print_r($state, true) . ") - consistency check may need regenerating");
self::assertArrayHasKey($stateId, $knownStates, "New block state $stateId (" . $state->getTypeId() . ":" . $state->computeTypeAndStateData() . ", " . print_r($state, true) . ") - consistency check may need regenerating");
self::assertSame($knownStates[$stateId], $state->getName());
}
asort($knownStates, SORT_STRING);