Implemented coral blocks

there are some complications with coral plants due to the fact we're stuck with R12 worlds right now - and also coral fans are a major pain to implement due to how messed up the metadata is.
This commit is contained in:
Dylan K. Taylor
2020-11-16 18:05:39 +00:00
parent 55a9ce46b9
commit 1eee24f1fa
5 changed files with 178 additions and 2 deletions

View File

@ -0,0 +1,68 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\bedrock;
use pocketmine\block\BlockLegacyMetadata;
use pocketmine\block\utils\CoralType;
use pocketmine\utils\SingletonTrait;
use function array_key_exists;
final class CoralTypeIdMap{
use SingletonTrait;
/**
* @var CoralType[]
* @phpstan-var array<int, CoralType>
*/
private $idToEnum = [];
/**
* @var int[]
* @phpstan-var array<int, int>
*/
private $enumToId = [];
public function __construct(){
$this->register(BlockLegacyMetadata::CORAL_VARIANT_TUBE, CoralType::TUBE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_BRAIN, CoralType::BRAIN());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_BUBBLE, CoralType::BUBBLE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_FIRE, CoralType::FIRE());
$this->register(BlockLegacyMetadata::CORAL_VARIANT_HORN, CoralType::HORN());
}
public function register(int $id, CoralType $type) : void{
$this->idToEnum[$id] = $type;
$this->enumToId[$type->id()] = $id;
}
public function fromId(int $id) : ?CoralType{
return $this->idToEnum[$id] ?? null;
}
public function toId(CoralType $type) : int{
if(!array_key_exists($type->id(), $this->enumToId)){
throw new \InvalidArgumentException("Coral type does not have a mapped ID"); //this should never happen
}
return $this->enumToId[$type->id()];
}
}