Hacks for banners and coral fans

This commit is contained in:
Dylan K. Taylor 2022-05-24 15:07:38 +01:00
parent a2ea0cea86
commit 81eafde074
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
6 changed files with 115 additions and 21 deletions

View File

@ -68,7 +68,7 @@ final class ItemSerializer{
if($item->hasAnyDamageValue()){
throw new \InvalidArgumentException("Cannot serialize a recipe wildcard");
}
$index = ($item->getId() << 16) | $item->getMeta();
$index = $item->getTypeId();
if(isset($this->serializers[$index])){
//TODO: REMOVE ME
throw new AssumptionFailedError("Registering the same item twice!");
@ -89,7 +89,7 @@ final class ItemSerializer{
if($item instanceof ItemBlock){
$data = self::standardBlock($item->getBlock());
}else{
$index = ($item->getId() << 16) | ($item instanceof Durable ? 0 : $item->getMeta());
$index = $item->getTypeId();
$locatedSerializer = $this->serializers[$index][get_class($item)] ?? null;
if($locatedSerializer === null){

61
src/item/CoralFan.php Normal file
View File

@ -0,0 +1,61 @@
<?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\Block;
use pocketmine\block\utils\CoralTypeTrait;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\math\Axis;
use pocketmine\math\Facing;
final class CoralFan extends Item{
use CoralTypeTrait;
public function __construct(private ItemIdentifierFlattened $identifierFlattened){
parent::__construct($this->identifierFlattened, VanillaBlocks::CORAL_FAN()->getName());
}
public function getId() : int{
return $this->dead ? $this->identifierFlattened->getAdditionalIds()[0] : $this->identifierFlattened->getId();
}
public function getMeta() : int{
return CoralTypeIdMap::getInstance()->toId($this->coralType);
}
public function getBlock(?int $clickedFace = null) : Block{
$block = $clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y ? VanillaBlocks::WALL_CORAL_FAN() : VanillaBlocks::CORAL_FAN();
return $block->setCoralType($this->coralType)->setDead($this->dead);
}
public function getFuelTime() : int{
return $this->getBlock()->getFuelTime();
}
public function getMaxStackSize() : int{
return $this->getBlock()->getMaxStackSize();
}
}

View File

@ -439,7 +439,12 @@ class Item implements \JsonSerializable{
return VanillaBlocks::AIR();
}
final public function getId() : int{
final public function getTypeId() : int{
//don't use Item::getMeta(), since it might be overridden for non-type information (e.g. durability)
return ($this->identifier->getId() << 16) | $this->identifier->getMeta();
}
public function getId() : int{
return $this->identifier->getId();
}

View File

@ -82,23 +82,10 @@ class ItemFactory{
$this->register(new Clownfish(new ItemIdentifier(ItemIds::CLOWNFISH, 0), "Clownfish"));
$this->register(new Coal(new ItemIdentifier(ItemIds::COAL, 0), "Coal"));
foreach([
0 => CoralType::TUBE(),
1 => CoralType::BRAIN(),
2 => CoralType::BUBBLE(),
3 => CoralType::FIRE(),
4 => CoralType::HORN()
] as $meta => $coralType){
$this->register(new ItemBlockWallOrFloor(
new ItemIdentifier(ItemIds::CORAL_FAN, $meta),
VanillaBlocks::CORAL_FAN()->setCoralType($coralType)->setDead(false),
VanillaBlocks::WALL_CORAL_FAN()->setCoralType($coralType)->setDead(false)
), true);
$this->register(new ItemBlockWallOrFloor(
new ItemIdentifier(ItemIds::CORAL_FAN_DEAD, $meta),
VanillaBlocks::CORAL_FAN()->setCoralType($coralType)->setDead(true),
VanillaBlocks::WALL_CORAL_FAN()->setCoralType($coralType)->setDead(true)
), true);
$identifier = new ItemIdentifierFlattened(ItemIds::CORAL_FAN, 0, [ItemIds::CORAL_FAN_DEAD]);
foreach(CoralType::getAll() as $coralType){
$this->register((new CoralFan($identifier))->setCoralType($coralType)->setDead(false), true);
$this->register((new CoralFan($identifier))->setCoralType($coralType)->setDead(true), true);
}
$this->register(new Coal(new ItemIdentifier(ItemIds::COAL, 1), "Charcoal"));

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\item;
final class ItemIdentifier{
class ItemIdentifier{
private int $id;
private int $meta;

View File

@ -0,0 +1,41 @@
<?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;
final class ItemIdentifierFlattened extends ItemIdentifier{
/**
* @param int[] $additionalIds
*/
public function __construct(int $id, int $meta, private array $additionalIds){
parent::__construct($id, $meta);
}
/** @return int[] */
public function getAdditionalIds() : array{ return $this->additionalIds; }
public function getAllIds() : array{
return [$this->getId(), ...$this->additionalIds];
}
}