Boat: use BoatType enum instead of TreeType

TreeType really belongs in the generator package. Not all types of tree may have their own boat type (e.g. azalea).
We can't use WoodType for this either, because some types of wood also don't have associated boat types (crimson, warped).
This commit is contained in:
Dylan K. Taylor 2023-05-04 16:35:31 +01:00
parent f1417e8dc9
commit 896dd2ec9d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 83 additions and 16 deletions

View File

@ -23,18 +23,16 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\utils\TreeType;
class Boat extends Item{
private TreeType $woodType;
private BoatType $boatType;
public function __construct(ItemIdentifier $identifier, string $name, TreeType $woodType){
public function __construct(ItemIdentifier $identifier, string $name, BoatType $boatType){
parent::__construct($identifier, $name);
$this->woodType = $woodType;
$this->boatType = $boatType;
}
public function getWoodType() : TreeType{
return $this->woodType;
public function getType() : BoatType{
return $this->boatType;
}
public function getFuelTime() : int{

70
src/item/BoatType.php Normal file
View File

@ -0,0 +1,70 @@
<?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\item;
use pocketmine\block\utils\WoodType;
use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static BoatType ACACIA()
* @method static BoatType BIRCH()
* @method static BoatType DARK_OAK()
* @method static BoatType JUNGLE()
* @method static BoatType OAK()
* @method static BoatType SPRUCE()
*/
final class BoatType{
use EnumTrait {
__construct as Enum___construct;
}
protected static function setup() : void{
self::registerAll(
new self("oak", WoodType::OAK()),
new self("spruce", WoodType::SPRUCE()),
new self("birch", WoodType::BIRCH()),
new self("jungle", WoodType::JUNGLE()),
new self("acacia", WoodType::ACACIA()),
new self("dark_oak", WoodType::DARK_OAK()),
);
}
private function __construct(
string $enumName,
private WoodType $woodType,
){
$this->Enum___construct($enumName);
}
public function getWoodType() : WoodType{ return $this->woodType; }
public function getDisplayName() : string{
return $this->woodType->getDisplayName();
}
}

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\utils\RecordType;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\entity\Entity;
@ -539,15 +538,15 @@ final class VanillaItems{
self::register("writable_book", new WritableBook(new IID(Ids::WRITABLE_BOOK), "Book & Quill"));
self::register("written_book", new WrittenBook(new IID(Ids::WRITTEN_BOOK), "Written Book"));
foreach(TreeType::getAll() as $type){
//TODO: tree type should be dynamic in the future, but we're staying static for now for the sake of consistency
foreach(BoatType::getAll() as $type){
//boat type is static, because different types of wood may have different properties
self::register($type->name() . "_boat", new Boat(new IID(match($type){
TreeType::OAK() => Ids::OAK_BOAT,
TreeType::SPRUCE() => Ids::SPRUCE_BOAT,
TreeType::BIRCH() => Ids::BIRCH_BOAT,
TreeType::JUNGLE() => Ids::JUNGLE_BOAT,
TreeType::ACACIA() => Ids::ACACIA_BOAT,
TreeType::DARK_OAK() => Ids::DARK_OAK_BOAT,
BoatType::OAK() => Ids::OAK_BOAT,
BoatType::SPRUCE() => Ids::SPRUCE_BOAT,
BoatType::BIRCH() => Ids::BIRCH_BOAT,
BoatType::JUNGLE() => Ids::JUNGLE_BOAT,
BoatType::ACACIA() => Ids::ACACIA_BOAT,
BoatType::DARK_OAK() => Ids::DARK_OAK_BOAT,
default => throw new AssumptionFailedError("Unhandled tree type " . $type->name())
}), $type->getDisplayName() . " Boat", $type));
}