mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Added a hack to allow tiles to trigger client-side render updates on blocks without actually changing the block
Bedrock block entity updates don't directly trigger block rendering updates. This is a problem when the block entity data affects the block's appearance directly (e.g. cauldron water colour, flower pot contents), because it means changing them won't directly result in a client-side render update. This hack allows tiles to spoof block updates without actually changing the server-side block, keeping the internals and API clean of random shitbox workarounds. fixes #5174 fixes #4944
This commit is contained in:
parent
f64e306fb8
commit
87b840ff97
@ -27,7 +27,9 @@ use pocketmine\block\Air;
|
|||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
|
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
|
||||||
|
use pocketmine\data\bedrock\block\BlockStateNames;
|
||||||
use pocketmine\data\SavedDataLoadingException;
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
|
use pocketmine\nbt\tag\ByteTag;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\ShortTag;
|
use pocketmine\nbt\tag\ShortTag;
|
||||||
@ -92,4 +94,8 @@ class FlowerPot extends Spawnable{
|
|||||||
$nbt->setTag(self::TAG_PLANT_BLOCK, RuntimeBlockMapping::getInstance()->toStateData($this->plant->getStateId())->toNbt());
|
$nbt->setTag(self::TAG_PLANT_BLOCK, RuntimeBlockMapping::getInstance()->toStateData($this->plant->getStateId())->toNbt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRenderUpdateBugWorkaroundStateProperties(Block $block) : array{
|
||||||
|
return [BlockStateNames::UPDATE_BIT => new ByteTag(1)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block\tile;
|
namespace pocketmine\block\tile;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\nbt\tag\ByteTag;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\nbt\tag\IntTag;
|
||||||
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
|
|
||||||
@ -49,6 +53,22 @@ abstract class Spawnable extends Tile{
|
|||||||
$this->spawnCompoundCache = null;
|
$this->spawnCompoundCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Bedrock client won't re-render a block if the block's state properties didn't change. This is a problem when
|
||||||
|
* the tile may affect the block's appearance. For example, a cauldron's liquid changes colour based on the dye
|
||||||
|
* inside.
|
||||||
|
*
|
||||||
|
* This is worked around in vanilla by modifying one of the block's state properties to a different value, and then
|
||||||
|
* changing it back again. Since we don't want to litter core implementation with hacks like this, we brush it under
|
||||||
|
* the rug into Tile.
|
||||||
|
*
|
||||||
|
* @return ByteTag[]|IntTag[]|StringTag[]
|
||||||
|
* @phpstan-return array<string, IntTag|StringTag|ByteTag>
|
||||||
|
*/
|
||||||
|
public function getRenderUpdateBugWorkaroundStateProperties(Block $block) : array{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns encoded NBT (varint, little-endian) used to spawn this tile to clients. Uses cache where possible,
|
* Returns encoded NBT (varint, little-endian) used to spawn this tile to clients. Uses cache where possible,
|
||||||
* populates cache if it is null.
|
* populates cache if it is null.
|
||||||
|
@ -907,7 +907,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
|
|||||||
});
|
});
|
||||||
$this->map(Blocks::FLOWER_POT(), function() : Writer{
|
$this->map(Blocks::FLOWER_POT(), function() : Writer{
|
||||||
return Writer::create(Ids::FLOWER_POT)
|
return Writer::create(Ids::FLOWER_POT)
|
||||||
->writeBool(StateNames::UPDATE_BIT, true); //to keep MCPE happy
|
->writeBool(StateNames::UPDATE_BIT, false); //to keep MCPE happy
|
||||||
});
|
});
|
||||||
$this->map(Blocks::FROSTED_ICE(), function(FrostedIce $block) : Writer{
|
$this->map(Blocks::FROSTED_ICE(), function(FrostedIce $block) : Writer{
|
||||||
return Writer::create(Ids::FROSTED_ICE)
|
return Writer::create(Ids::FROSTED_ICE)
|
||||||
|
@ -36,6 +36,7 @@ use pocketmine\block\tile\TileFactory;
|
|||||||
use pocketmine\block\UnknownBlock;
|
use pocketmine\block\UnknownBlock;
|
||||||
use pocketmine\block\VanillaBlocks;
|
use pocketmine\block\VanillaBlocks;
|
||||||
use pocketmine\data\bedrock\BiomeIds;
|
use pocketmine\data\bedrock\BiomeIds;
|
||||||
|
use pocketmine\data\bedrock\block\BlockStateData;
|
||||||
use pocketmine\data\SavedDataLoadingException;
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\EntityFactory;
|
use pocketmine\entity\EntityFactory;
|
||||||
@ -948,6 +949,22 @@ class World implements ChunkManager{
|
|||||||
|
|
||||||
$fullBlock = $this->getBlockAt($b->x, $b->y, $b->z);
|
$fullBlock = $this->getBlockAt($b->x, $b->y, $b->z);
|
||||||
$blockPosition = BlockPosition::fromVector3($b);
|
$blockPosition = BlockPosition::fromVector3($b);
|
||||||
|
|
||||||
|
$tile = $this->getTileAt($b->x, $b->y, $b->z);
|
||||||
|
if($tile instanceof Spawnable && ($fakeStateProperties = $tile->getRenderUpdateBugWorkaroundStateProperties($fullBlock)) !== null){
|
||||||
|
$originalStateData = $blockMapping->toStateData($fullBlock->getStateId());
|
||||||
|
$fakeStateData = new BlockStateData(
|
||||||
|
$originalStateData->getName(),
|
||||||
|
array_merge($originalStateData->getStates(), $fakeStateProperties),
|
||||||
|
$originalStateData->getVersion()
|
||||||
|
);
|
||||||
|
$packets[] = UpdateBlockPacket::create(
|
||||||
|
$blockPosition,
|
||||||
|
$blockMapping->getBlockStateDictionary()->lookupStateIdFromData($fakeStateData) ?? throw new AssumptionFailedError("Unmapped fake blockstate data: " . $fakeStateData->toNbt()),
|
||||||
|
UpdateBlockPacket::FLAG_NETWORK,
|
||||||
|
UpdateBlockPacket::DATA_LAYER_NORMAL
|
||||||
|
);
|
||||||
|
}
|
||||||
$packets[] = UpdateBlockPacket::create(
|
$packets[] = UpdateBlockPacket::create(
|
||||||
$blockPosition,
|
$blockPosition,
|
||||||
$blockMapping->toRuntimeId($fullBlock->getStateId()),
|
$blockMapping->toRuntimeId($fullBlock->getStateId()),
|
||||||
@ -955,7 +972,6 @@ class World implements ChunkManager{
|
|||||||
UpdateBlockPacket::DATA_LAYER_NORMAL
|
UpdateBlockPacket::DATA_LAYER_NORMAL
|
||||||
);
|
);
|
||||||
|
|
||||||
$tile = $this->getTileAt($b->x, $b->y, $b->z);
|
|
||||||
if($tile instanceof Spawnable){
|
if($tile instanceof Spawnable){
|
||||||
$packets[] = BlockActorDataPacket::create($blockPosition, $tile->getSerializedSpawnCompound());
|
$packets[] = BlockActorDataPacket::create($blockPosition, $tile->getSerializedSpawnCompound());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user