mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Implement cauldrons (#5163)
the following things are currently not implemented: - particle/sound effects when an entity extinguishes itself - particle/sound effects when mixing different stuff in a cauldron - powder snow cauldron both of these things are contingent on #5169, but for the time being, the PR is functionally complete and I want to move on to something else without being stalled by the particle+sound problem (which I haven't yet decided how to solve).
This commit is contained in:
@ -68,6 +68,7 @@ use pocketmine\block\EndPortalFrame;
|
||||
use pocketmine\block\EndRod;
|
||||
use pocketmine\block\Farmland;
|
||||
use pocketmine\block\FenceGate;
|
||||
use pocketmine\block\FillableCauldron;
|
||||
use pocketmine\block\Fire;
|
||||
use pocketmine\block\FloorBanner;
|
||||
use pocketmine\block\FloorCoralFan;
|
||||
@ -176,6 +177,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
|
||||
|
||||
public function __construct(){
|
||||
$this->registerCandleSerializers();
|
||||
$this->registerCauldronSerializers();
|
||||
$this->registerSimpleSerializers();
|
||||
$this->registerSerializers();
|
||||
}
|
||||
@ -292,6 +294,14 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
|
||||
})->writeBool(StateNames::LIT, $block->isLit()));
|
||||
}
|
||||
|
||||
private function registerCauldronSerializers() : void{
|
||||
$this->map(Blocks::CAULDRON(), fn() => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, 0, new Writer(Ids::CAULDRON)));
|
||||
$this->map(Blocks::LAVA_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_LAVA, $b->getFillLevel(), new Writer(Ids::LAVA_CAULDRON)));
|
||||
//potion cauldrons store their real information in the block actor data
|
||||
$this->map(Blocks::POTION_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, $b->getFillLevel(), new Writer(Ids::CAULDRON)));
|
||||
$this->map(Blocks::WATER_CAULDRON(), fn(FillableCauldron $b) => Helper::encodeCauldron(StringValues::CAULDRON_LIQUID_WATER, $b->getFillLevel(), new Writer(Ids::CAULDRON)));
|
||||
}
|
||||
|
||||
private function registerSimpleSerializers() : void{
|
||||
$this->mapSimple(Blocks::AIR(), Ids::AIR);
|
||||
$this->mapSimple(Blocks::AMETHYST(), Ids::AMETHYST_BLOCK);
|
||||
|
@ -91,6 +91,12 @@ final class BlockStateSerializerHelper{
|
||||
->writeTorchFacing($block->getFacing());
|
||||
}
|
||||
|
||||
public static function encodeCauldron(string $liquid, int $fillLevel, BlockStateWriter $out) : BlockStateWriter{
|
||||
return $out
|
||||
->writeString(BlockStateNames::CAULDRON_LIQUID, $liquid)
|
||||
->writeInt(BlockStateNames::FILL_LEVEL, $fillLevel);
|
||||
}
|
||||
|
||||
public static function selectCopperId(CopperOxidation $oxidation, string $noneId, string $exposedId, string $weatheredId, string $oxidizedId) : string{
|
||||
return match($oxidation){
|
||||
CopperOxidation::NONE() => $noneId,
|
||||
|
@ -60,6 +60,7 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
|
||||
|
||||
public function __construct(){
|
||||
$this->registerCandleDeserializers();
|
||||
$this->registerCauldronDeserializers();
|
||||
$this->registerSimpleDeserializers();
|
||||
$this->registerDeserializers();
|
||||
}
|
||||
@ -136,6 +137,25 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
|
||||
$this->map(Ids::YELLOW_CANDLE_CAKE, $cakeWithDyedCandleDeserializer(DyeColor::YELLOW()));
|
||||
}
|
||||
|
||||
private function registerCauldronDeserializers() : void{
|
||||
$deserializer = function(Reader $in) : Block{
|
||||
$level = $in->readBoundedInt(StateNames::FILL_LEVEL, 0, 6);
|
||||
if($level === 0){
|
||||
$in->ignored(StateNames::CAULDRON_LIQUID);
|
||||
return Blocks::CAULDRON();
|
||||
}
|
||||
|
||||
return (match($liquid = $in->readString(StateNames::CAULDRON_LIQUID)){
|
||||
StringValues::CAULDRON_LIQUID_WATER => Blocks::WATER_CAULDRON(),
|
||||
StringValues::CAULDRON_LIQUID_LAVA => Blocks::LAVA_CAULDRON(),
|
||||
StringValues::CAULDRON_LIQUID_POWDER_SNOW => throw new UnsupportedBlockStateException("Powder snow is not supported yet"),
|
||||
default => throw $in->badValueException(StateNames::CAULDRON_LIQUID, $liquid)
|
||||
})->setFillLevel($level);
|
||||
};
|
||||
$this->map(Ids::CAULDRON, $deserializer);
|
||||
$this->map(Ids::LAVA_CAULDRON, $deserializer);
|
||||
}
|
||||
|
||||
private function registerSimpleDeserializers() : void{
|
||||
$this->map(Ids::AIR, fn() => Blocks::AIR());
|
||||
$this->map(Ids::AMETHYST_BLOCK, fn() => Blocks::AMETHYST());
|
||||
|
@ -198,7 +198,7 @@ final class ItemDeserializer{
|
||||
$this->map(Ids::CARROT, fn() => Items::CARROT());
|
||||
//TODO: minecraft:carrot_on_a_stick
|
||||
//TODO: minecraft:cat_spawn_egg
|
||||
//TODO: minecraft:cauldron
|
||||
$this->map(Ids::CAULDRON, fn() => Blocks::CAULDRON()->asItem());
|
||||
//TODO: minecraft:cave_spider_spawn_egg
|
||||
//TODO: minecraft:chain
|
||||
$this->map(Ids::CHAINMAIL_BOOTS, fn() => Items::CHAINMAIL_BOOTS());
|
||||
|
@ -229,6 +229,7 @@ final class ItemSerializer{
|
||||
$this->mapBlock(Blocks::BIRCH_DOOR(), self::id(Ids::BIRCH_DOOR));
|
||||
$this->mapBlock(Blocks::BREWING_STAND(), self::id(Ids::BREWING_STAND));
|
||||
$this->mapBlock(Blocks::CAKE(), self::id(Ids::CAKE));
|
||||
$this->mapBlock(Blocks::CAULDRON(), self::id(Ids::CAULDRON));
|
||||
$this->mapBlock(Blocks::CRIMSON_DOOR(), self::id(Ids::CRIMSON_DOOR));
|
||||
$this->mapBlock(Blocks::DARK_OAK_DOOR(), self::id(Ids::DARK_OAK_DOOR));
|
||||
$this->mapBlock(Blocks::FLOWER_POT(), self::id(Ids::FLOWER_POT));
|
||||
|
Reference in New Issue
Block a user