diff --git a/src/data/bedrock/blockstate/BlockStateDeserializerHelper.php b/src/data/bedrock/blockstate/BlockStateDeserializerHelper.php index d026e0773..225df7c2b 100644 --- a/src/data/bedrock/blockstate/BlockStateDeserializerHelper.php +++ b/src/data/bedrock/blockstate/BlockStateDeserializerHelper.php @@ -186,7 +186,7 @@ final class BlockStateDeserializerHelper{ /** @throws BlockStateDeserializeException */ public static function decodeTrapdoor(Trapdoor $block, BlockStateReader $in) : Trapdoor{ return $block - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->read5MinusHorizontalFacing()) ->setTop($in->readBool(BlockStateNames::UPSIDE_DOWN_BIT)) ->setOpen($in->readBool(BlockStateNames::OPEN_BIT)); } diff --git a/src/data/bedrock/blockstate/BlockStateReader.php b/src/data/bedrock/blockstate/BlockStateReader.php index 043b16ef1..6d2eeb929 100644 --- a/src/data/bedrock/blockstate/BlockStateReader.php +++ b/src/data/bedrock/blockstate/BlockStateReader.php @@ -158,6 +158,19 @@ final class BlockStateReader{ ]); } + /** + * This is for trapdoors, because Mojang botched the conversion in 1.13 + * @throws BlockStateDeserializeException + */ + public function read5MinusHorizontalFacing() : int{ + return $this->parseFacingValue($this->readInt(BlockStateNames::DIRECTION), [ + 0 => Facing::EAST, + 1 => Facing::WEST, + 2 => Facing::SOUTH, + 3 => Facing::NORTH + ]); + } + /** @throws BlockStateDeserializeException */ public function readColor() : DyeColor{ // * color (StringTag) = black, blue, brown, cyan, gray, green, light_blue, lime, magenta, orange, pink, purple, red, silver, white, yellow diff --git a/src/data/bedrock/blockstate/BlockStateSerializerHelper.php b/src/data/bedrock/blockstate/BlockStateSerializerHelper.php index 0dbb28af0..e4a1ffaf3 100644 --- a/src/data/bedrock/blockstate/BlockStateSerializerHelper.php +++ b/src/data/bedrock/blockstate/BlockStateSerializerHelper.php @@ -237,7 +237,7 @@ final class BlockStateSerializerHelper{ public static function encodeTrapdoor(Trapdoor $block, BlockStateWriter $out) : BlockStateWriter{ return $out - ->writeLegacyHorizontalFacing($block->getFacing()) + ->write5MinusHorizontalFacing($block->getFacing()) ->writeBool(BlockStateNames::UPSIDE_DOWN_BIT, $block->isTop()) ->writeBool(BlockStateNames::OPEN_BIT, $block->isOpen()); } diff --git a/src/data/bedrock/blockstate/BlockStateWriter.php b/src/data/bedrock/blockstate/BlockStateWriter.php index 907db99c2..ef726c0a5 100644 --- a/src/data/bedrock/blockstate/BlockStateWriter.php +++ b/src/data/bedrock/blockstate/BlockStateWriter.php @@ -118,6 +118,20 @@ final class BlockStateWriter{ return $this; } + /** + * This is for trapdoors, because Mojang botched the conversion in 1.13 + * @return $this + */ + public function write5MinusHorizontalFacing(int $value) : self{ + return $this->writeInt(BlockStateNames::DIRECTION, match($value){ + Facing::EAST => 0, + Facing::WEST => 1, + Facing::SOUTH => 2, + Facing::NORTH => 3, + default => throw new BlockStateSerializeException("Invalid horizontal facing $value") + }); + } + /** @return $this */ public function writeColor(DyeColor $color) : self{ $this->writeString(BlockStateNames::COLOR, match($color->id()){