22declare(strict_types=1);
24namespace pocketmine\data\bedrock\block\convert;
46use pocketmine\block\utils\CopperOxidation;
47use pocketmine\block\utils\SlabType;
59 public static function encodeButton(
Button $block, Writer $out) : Writer{
61 ->writeFacingDirection($block->getFacing())
62 ->writeBool(BlockStateNames::BUTTON_PRESSED_BIT, $block->isPressed());
65 public static function encodeCandle(
Candle $block, Writer $out) : Writer{
67 ->writeBool(StateNames::LIT, $block->isLit())
68 ->writeInt(StateNames::CANDLES, $block->getCount() - 1);
71 public static function encodeChemistryTable(
ChemistryTable $block,
string $chemistryTableType, Writer $out) : Writer{
73 ->writeString(BlockStateNames::CHEMISTRY_TABLE_TYPE, $chemistryTableType)
77 public static function encodeCrops(
Crops $block, Writer $out) : Writer{
78 return $out->writeInt(BlockStateNames::GROWTH, $block->getAge());
81 public static function encodeColoredTorch(
Torch $block,
bool $highBit, Writer $out) : Writer{
83 ->writeBool(BlockStateNames::COLOR_BIT, $highBit)
84 ->writeTorchFacing($block->getFacing());
87 public static function encodeCauldron(
string $liquid,
int $fillLevel) : Writer{
88 return Writer::create(Ids::CAULDRON)
89 ->writeString(BlockStateNames::CAULDRON_LIQUID, $liquid)
90 ->writeInt(BlockStateNames::FILL_LEVEL, $fillLevel);
93 public static function selectCopperId(CopperOxidation $oxidation,
string $noneId,
string $exposedId,
string $weatheredId,
string $oxidizedId) :
string{
94 return match($oxidation){
95 CopperOxidation::NONE => $noneId,
96 CopperOxidation::EXPOSED => $exposedId,
97 CopperOxidation::WEATHERED => $weatheredId,
98 CopperOxidation::OXIDIZED => $oxidizedId,
102 public static function encodeDoor(
Door $block, Writer $out) : Writer{
104 ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop())
105 ->writeLegacyHorizontalFacing(
Facing::rotateY($block->getFacing(),
true))
106 ->writeBool(BlockStateNames::DOOR_HINGE_BIT, $block->isHingeRight())
107 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
110 public static function encodeDoublePlant(
DoublePlant $block, Writer $out) : Writer{
112 ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop());
115 public static function encodeFenceGate(
FenceGate $block, Writer $out) : Writer{
117 ->writeLegacyHorizontalFacing($block->getFacing())
118 ->writeBool(BlockStateNames::IN_WALL_BIT, $block->isInWall())
119 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
122 public static function encodeFloorSign(
FloorSign $block, Writer $out) : Writer{
124 ->writeInt(BlockStateNames::GROUND_SIGN_DIRECTION, $block->getRotation());
127 public static function encodeFurnace(
Furnace $block,
string $unlitId,
string $litId) : Writer{
128 return Writer::create($block->isLit() ? $litId : $unlitId)
129 ->writeCardinalHorizontalFacing($block->getFacing());
132 public static function encodeItemFrame(
ItemFrame $block,
string $id) : Writer{
133 return Writer::create($id)
134 ->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap())
135 ->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT,
false)
136 ->writeFacingDirection($block->getFacing());
139 public static function encodeLeaves(
Leaves $block, Writer $out) : Writer{
141 ->writeBool(BlockStateNames::PERSISTENT_BIT, $block->isNoDecay())
142 ->writeBool(BlockStateNames::UPDATE_BIT, $block->isCheckDecay());
145 public static function encodeLiquid(
Liquid $block,
string $stillId,
string $flowingId) : Writer{
146 return Writer::create($block->isStill() ? $stillId : $flowingId)
147 ->writeInt(BlockStateNames::LIQUID_DEPTH, $block->getDecay() | ($block->isFalling() ? 0x8 : 0));
150 public static function encodeLog(
Wood $block,
string $unstrippedId,
string $strippedId) : Writer{
151 $out = $block->isStripped() ?
152 Writer::create($strippedId) :
153 Writer::create($unstrippedId);
155 ->writePillarAxis($block->getAxis());
158 public static function encodeMushroomBlock(
RedMushroomBlock $block, Writer $out) : Writer{
160 ->writeInt(BlockStateNames::HUGE_MUSHROOM_BITS, MushroomBlockTypeIdMap::getInstance()->toId($block->getMushroomBlockType()));
163 public static function encodeQuartz(
int $axis, Writer $out) : Writer{
165 ->writePillarAxis($axis);
168 public static function encodeSapling(
Sapling $block, Writer $out) : Writer{
170 ->writeBool(BlockStateNames::AGE_BIT, $block->isReady());
173 public static function encodeSimplePressurePlate(
SimplePressurePlate $block, Writer $out) : Writer{
177 ->writeInt(BlockStateNames::REDSTONE_SIGNAL, $block->isPressed() ? 15 : 0);
180 private static function encodeSingleSlab(
Slab $block,
string $id) : Writer{
181 return Writer::create($id)
182 ->writeSlabPosition($block->getSlabType());
185 private static function encodeDoubleSlab(
Slab $block,
string $id) : Writer{
186 return Writer::create($id)
188 ->writeSlabPosition(SlabType::BOTTOM);
191 public static function encodeSlab(
Slab $block,
string $singleId,
string $doubleId) : Writer{
192 return $block->getSlabType() === SlabType::DOUBLE ?
193 self::encodeDoubleSlab($block, $doubleId) :
194 self::encodeSingleSlab($block, $singleId);
197 public static function encodeStairs(
Stair $block, Writer $out) : Writer{
199 ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isUpsideDown())
200 ->writeWeirdoHorizontalFacing($block->getFacing());
203 public static function encodeStem(
Stem $block, Writer $out) : Writer{
207 $facing = $block->getFacing();
208 return self::encodeCrops($block, $out)
209 ->writeFacingWithoutUp($facing === Facing::UP ? Facing::DOWN : $facing);
212 public static function encodeTrapdoor(
Trapdoor $block, Writer $out) : Writer{
214 ->write5MinusHorizontalFacing($block->getFacing())
215 ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isTop())
216 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
219 public static function encodeWall(
Wall $block, Writer $out) : Writer{
221 ->writeBool(BlockStateNames::WALL_POST_BIT, $block->isPost())
222 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_EAST, $block->getConnection(Facing::EAST))
223 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_NORTH, $block->getConnection(Facing::NORTH))
224 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_SOUTH, $block->getConnection(Facing::SOUTH))
225 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_WEST, $block->getConnection(Facing::WEST));
228 public static function encodeLegacyWall(
Wall $block,
string $type) : Writer{
229 return self::encodeWall($block, Writer::create(Ids::COBBLESTONE_WALL))
230 ->writeString(BlockStateNames::WALL_BLOCK_TYPE, $type);
233 public static function encodeWallSign(
WallSign $block, Writer $out) : Writer{
235 ->writeHorizontalFacing($block->getFacing());
static opposite(int $direction)
static rotateY(int $direction, bool $clockwise)