Implement new 1.21 copper blocks (#6366)

Added the following new blocks:
- All types of Copper Bulb
- All types of Copper Door
- All types of Copper Trapdoor
- All types of Chiseled Copper
- All types of Copper Grate
This commit is contained in:
IvanCraft623
2024-09-24 21:25:10 -05:00
committed by GitHub
parent a4a07a8e5a
commit 4e6b34f573
12 changed files with 436 additions and 1 deletions

View File

@@ -25,7 +25,9 @@ namespace pocketmine\data\bedrock\item;
use pocketmine\block\Bed;
use pocketmine\block\Block;
use pocketmine\block\CopperDoor;
use pocketmine\block\MobHead;
use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\data\bedrock\CompoundTypeIds;
@@ -56,6 +58,7 @@ final class ItemSerializerDeserializerRegistrar{
$this->register1to1BlockWithMetaMappings();
$this->register1to1ItemWithMetaMappings();
$this->register1ToNItemMappings();
$this->registerMiscBlockMappings();
$this->registerMiscItemMappings();
}
@@ -538,4 +541,29 @@ final class ItemSerializerDeserializerRegistrar{
}
$this->serializer?->map(Items::DYE(), fn(Dye $item) => new Data(DyeColorIdMap::getInstance()->toItemId($item->getColor())));
}
/**
* Registers serializers and deserializers for PocketMine-MP blockitems that don't fit any other pattern.
* Ideally we want to get rid of this completely, if possible.
*
* Most of these are single PocketMine-MP blocks which map to multiple IDs depending on their properties, which is
* complex to implement in a generic way.
*/
private function registerMiscBlockMappings() : void{
$copperDoorStateIdMap = [];
foreach ([
[Ids::COPPER_DOOR, CopperOxidation::NONE, false],
[Ids::EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, false],
[Ids::WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, false],
[Ids::OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, false],
[Ids::WAXED_COPPER_DOOR, CopperOxidation::NONE, true],
[Ids::WAXED_EXPOSED_COPPER_DOOR, CopperOxidation::EXPOSED, true],
[Ids::WAXED_WEATHERED_COPPER_DOOR, CopperOxidation::WEATHERED, true],
[Ids::WAXED_OXIDIZED_COPPER_DOOR, CopperOxidation::OXIDIZED, true]
] as [$id, $oxidation, $waxed]) {
$copperDoorStateIdMap[$oxidation->value][$waxed ? 1 : 0] = $id;
$this->deserializer?->mapBlock($id, fn() => Blocks::COPPER_DOOR()->setOxidation($oxidation)->setWaxed($waxed));
}
$this->serializer?->mapBlock(Blocks::COPPER_DOOR(), fn(CopperDoor $block) => new Data($copperDoorStateIdMap[$block->getOxidation()->value][$block->isWaxed() ? 1 : 0]));
}
}