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, Writer $out) : Writer{
73 ->writeLegacyHorizontalFacing(Facing::opposite($block->getFacing()));
76 public static function encodeCrops(
Crops $block, Writer $out) : Writer{
77 return $out->writeInt(BlockStateNames::GROWTH, $block->getAge());
80 public static function encodeTorch(
Torch $block, Writer $out) : Writer{
82 ->writeTorchFacing($block->getFacing());
85 public static function encodeCauldron(
string $liquid,
int $fillLevel) : Writer{
86 return Writer::create(Ids::CAULDRON)
87 ->writeString(BlockStateNames::CAULDRON_LIQUID, $liquid)
88 ->writeInt(BlockStateNames::FILL_LEVEL, $fillLevel);
91 public static function selectCopperId(CopperOxidation $oxidation,
string $noneId,
string $exposedId,
string $weatheredId,
string $oxidizedId) :
string{
92 return match($oxidation){
93 CopperOxidation::NONE => $noneId,
94 CopperOxidation::EXPOSED => $exposedId,
95 CopperOxidation::WEATHERED => $weatheredId,
96 CopperOxidation::OXIDIZED => $oxidizedId,
100 public static function encodeDoor(
Door $block, Writer $out) : Writer{
102 ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop())
103 ->writeLegacyHorizontalFacing(Facing::rotateY($block->getFacing(),
true))
104 ->writeBool(BlockStateNames::DOOR_HINGE_BIT, $block->isHingeRight())
105 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
108 public static function encodeDoublePlant(
DoublePlant $block, Writer $out) : Writer{
110 ->writeBool(BlockStateNames::UPPER_BLOCK_BIT, $block->isTop());
113 public static function encodeFenceGate(
FenceGate $block, Writer $out) : Writer{
115 ->writeLegacyHorizontalFacing($block->getFacing())
116 ->writeBool(BlockStateNames::IN_WALL_BIT, $block->isInWall())
117 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
120 public static function encodeFloorSign(
FloorSign $block, Writer $out) : Writer{
122 ->writeInt(BlockStateNames::GROUND_SIGN_DIRECTION, $block->getRotation());
125 public static function encodeFurnace(
Furnace $block,
string $unlitId,
string $litId) : Writer{
126 return Writer::create($block->isLit() ? $litId : $unlitId)
127 ->writeCardinalHorizontalFacing($block->getFacing());
130 public static function encodeItemFrame(
ItemFrame $block,
string $id) : Writer{
131 return Writer::create($id)
132 ->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap())
133 ->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT,
false)
134 ->writeFacingDirection($block->getFacing());
137 public static function encodeLeaves(
Leaves $block, Writer $out) : Writer{
139 ->writeBool(BlockStateNames::PERSISTENT_BIT, $block->isNoDecay())
140 ->writeBool(BlockStateNames::UPDATE_BIT, $block->isCheckDecay());
143 public static function encodeLiquid(
Liquid $block,
string $stillId,
string $flowingId) : Writer{
144 return Writer::create($block->isStill() ? $stillId : $flowingId)
145 ->writeInt(BlockStateNames::LIQUID_DEPTH, $block->getDecay() | ($block->isFalling() ? 0x8 : 0));
148 public static function encodeLog(
Wood $block,
string $unstrippedId,
string $strippedId) : Writer{
149 $out = $block->isStripped() ?
150 Writer::create($strippedId) :
151 Writer::create($unstrippedId);
153 ->writePillarAxis($block->getAxis());
156 public static function encodeMushroomBlock(
RedMushroomBlock $block, Writer $out) : Writer{
158 ->writeInt(BlockStateNames::HUGE_MUSHROOM_BITS, MushroomBlockTypeIdMap::getInstance()->toId($block->getMushroomBlockType()));
161 public static function encodeQuartz(
int $axis, Writer $out) : Writer{
163 ->writePillarAxis($axis);
166 public static function encodeSapling(
Sapling $block, Writer $out) : Writer{
168 ->writeBool(BlockStateNames::AGE_BIT, $block->isReady());
171 public static function encodeSimplePressurePlate(
SimplePressurePlate $block, Writer $out) : Writer{
175 ->writeInt(BlockStateNames::REDSTONE_SIGNAL, $block->isPressed() ? 15 : 0);
178 private static function encodeSingleSlab(
Slab $block,
string $id) : Writer{
179 return Writer::create($id)
180 ->writeSlabPosition($block->getSlabType());
183 private static function encodeDoubleSlab(
Slab $block,
string $id) : Writer{
184 return Writer::create($id)
186 ->writeSlabPosition(SlabType::BOTTOM);
189 public static function encodeSlab(
Slab $block,
string $singleId,
string $doubleId) : Writer{
190 return $block->getSlabType() === SlabType::DOUBLE ?
191 self::encodeDoubleSlab($block, $doubleId) :
192 self::encodeSingleSlab($block, $singleId);
195 public static function encodeStairs(
Stair $block, Writer $out) : Writer{
197 ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isUpsideDown())
198 ->writeWeirdoHorizontalFacing($block->getFacing());
201 public static function encodeStem(
Stem $block, Writer $out) : Writer{
205 $facing = $block->getFacing();
206 return self::encodeCrops($block, $out)
207 ->writeFacingWithoutUp($facing === Facing::UP ? Facing::DOWN : $facing);
210 public static function encodeTrapdoor(
Trapdoor $block, Writer $out) : Writer{
212 ->write5MinusHorizontalFacing($block->getFacing())
213 ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isTop())
214 ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen());
217 public static function encodeWall(
Wall $block, Writer $out) : Writer{
219 ->writeBool(BlockStateNames::WALL_POST_BIT, $block->isPost())
220 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_EAST, $block->getConnection(Facing::EAST))
221 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_NORTH, $block->getConnection(Facing::NORTH))
222 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_SOUTH, $block->getConnection(Facing::SOUTH))
223 ->writeWallConnectionType(BlockStateNames::WALL_CONNECTION_TYPE_WEST, $block->getConnection(Facing::WEST));
226 public static function encodeWallSign(
WallSign $block, Writer $out) : Writer{
228 ->writeHorizontalFacing($block->getFacing());