Remove obsolete shim items for Bed and Skull

now that the colour and skull type are included in the block type data, it's no longer necessary to maintain shim items to retain this information in the item data.
This commit is contained in:
Dylan K. Taylor 2022-07-03 00:47:42 +01:00
parent 017ebb9b47
commit db9c7de35c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
10 changed files with 18 additions and 156 deletions

View File

@ -33,7 +33,6 @@ use pocketmine\data\runtime\block\BlockDataWriter;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
@ -220,8 +219,5 @@ class Bed extends Transparent{
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
}
public function asItem() : Item{
//TODO: we might be able to get rid of this
return VanillaItems::BED()->setColor($this->color);
}
public function getMaxStackSize() : int{ return 1; }
}

View File

@ -31,7 +31,6 @@ use pocketmine\data\runtime\block\BlockDataReaderHelper;
use pocketmine\data\runtime\block\BlockDataWriter;
use pocketmine\data\runtime\block\BlockDataWriterHelper;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
@ -153,9 +152,4 @@ class Skull extends Flowable{
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function asItem() : Item{
//TODO: we might be able to get rid of this
return VanillaItems::MOB_HEAD()->setSkullType($this->skullType);
}
}

View File

@ -536,7 +536,7 @@ final class ItemDeserializer{
}catch(\InvalidArgumentException $e){
throw new ItemTypeDeserializeException($e->getMessage(), 0, $e);
}
return Items::MOB_HEAD()->setSkullType($skullType);
return Blocks::MOB_HEAD()->setSkullType($skullType)->asItem();
});
//TODO: minecraft:skull_banner_pattern
$this->map(Ids::SLIME_BALL, fn() => Items::SLIMEBALL());

View File

@ -23,7 +23,9 @@ declare(strict_types=1);
namespace pocketmine\data\bedrock\item;
use pocketmine\block\Bed;
use pocketmine\block\Block;
use pocketmine\block\Skull;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\data\bedrock\block\BlockStateSerializeException;
@ -34,13 +36,11 @@ use pocketmine\data\bedrock\item\ItemTypeIds as Ids;
use pocketmine\data\bedrock\item\SavedItemData as Data;
use pocketmine\data\bedrock\PotionTypeIdMap;
use pocketmine\item\Banner;
use pocketmine\item\Bed;
use pocketmine\item\CoralFan;
use pocketmine\item\Dye;
use pocketmine\item\Item;
use pocketmine\item\ItemBlock;
use pocketmine\item\Potion;
use pocketmine\item\Skull;
use pocketmine\item\SplashPotion;
use pocketmine\item\VanillaItems as Items;
use pocketmine\utils\AssumptionFailedError;
@ -240,6 +240,9 @@ final class ItemSerializer{
$this->mapBlock(Blocks::REDSTONE_REPEATER(), self::id(Ids::REPEATER));
$this->mapBlock(Blocks::SPRUCE_DOOR(), self::id(Ids::SPRUCE_DOOR));
$this->mapBlock(Blocks::SUGARCANE(), self::id(Ids::SUGAR_CANE));
$this->mapBlock(Blocks::BED(), fn(Bed $block) => new Data(Ids::BED, DyeColorIdMap::getInstance()->toId($block->getColor())));
$this->mapBlock(Blocks::MOB_HEAD(), fn(Skull $block) => new Data(Ids::SKULL, $block->getSkullType()->getMagicNumber()));
}
private function registerSerializers() : void{
@ -256,7 +259,6 @@ final class ItemSerializer{
$this->map(Items::ARROW(), self::id(Ids::ARROW));
$this->map(Items::BAKED_POTATO(), self::id(Ids::BAKED_POTATO));
$this->map(Items::BANNER(), fn(Banner $item) => new Data(Ids::BANNER, DyeColorIdMap::getInstance()->toInvertedId($item->getColor())));
$this->map(Items::BED(), fn(Bed $item) => new Data(Ids::BED, DyeColorIdMap::getInstance()->toId($item->getColor())));
$this->map(Items::BEETROOT(), self::id(Ids::BEETROOT));
$this->map(Items::BEETROOT_SEEDS(), self::id(Ids::BEETROOT_SEEDS));
$this->map(Items::BEETROOT_SOUP(), self::id(Ids::BEETROOT_SOUP));
@ -419,7 +421,6 @@ final class ItemSerializer{
$this->map(Items::MELON_SEEDS(), self::id(Ids::MELON_SEEDS));
$this->map(Items::MILK_BUCKET(), self::id(Ids::MILK_BUCKET));
$this->map(Items::MINECART(), self::id(Ids::MINECART));
$this->map(Items::MOB_HEAD(), fn(Skull $item) => new Data(Ids::SKULL, $item->getSkullType()->getMagicNumber()));
$this->map(Items::MUSHROOM_STEW(), self::id(Ids::MUSHROOM_STEW));
$this->map(Items::NAUTILUS_SHELL(), self::id(Ids::NAUTILUS_SHELL));
$this->map(Items::NETHER_BRICK(), self::id(Ids::NETHERBRICK));

View File

@ -1,62 +0,0 @@
<?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\DyeColor;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\bedrock\DyeColorIdMap;
class Bed extends Item{
private DyeColor $color;
public function __construct(ItemIdentifier $identifier, string $name){
$this->color = DyeColor::WHITE();
parent::__construct($identifier, $name);
}
public function getMeta() : int{
return DyeColorIdMap::getInstance()->toId($this->color);
}
public function getColor() : DyeColor{
return $this->color;
}
/**
* @return $this
*/
public function setColor(DyeColor $color) : self{
$this->color = $color;
return $this;
}
public function getBlock(?int $clickedFace = null) : Block{
return VanillaBlocks::BED()->setColor($this->color);
}
public function getMaxStackSize() : int{
return 1;
}
}

View File

@ -27,7 +27,6 @@ use pocketmine\block\BlockFactory;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\RecordType;
use pocketmine\block\utils\SkullType;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
@ -268,15 +267,10 @@ class ItemFactory{
$this->register(new WritableBook(new IID(Ids::WRITABLE_BOOK, LegacyIds::WRITABLE_BOOK, 0), "Book & Quill"));
$this->register(new WrittenBook(new IID(Ids::WRITTEN_BOOK, LegacyIds::WRITTEN_BOOK, 0), "Written Book"));
foreach(SkullType::getAll() as $skullType){
$this->register((new Skull(new IID(Ids::MOB_HEAD, LegacyIds::SKULL, 0), "Mob Head"))->setSkullType($skullType));
}
foreach(DyeColor::getAll() as $color){
//TODO: use colour object directly
//TODO: add interface to dye-colour objects
$this->register((new Dye(new IID(Ids::DYE, LegacyIds::DYE, 0), "Dye"))->setColor($color));
$this->register((new Bed(new IID(Ids::BED, LegacyIds::BED, 0), "Bed"))->setColor($color));
$this->register((new Banner(
new IID(Ids::BANNER, LegacyIds::BANNER, 0),
Blocks::BANNER(),

View File

@ -43,7 +43,7 @@ final class ItemTypeIds{
public const BAKED_POTATO = 20004;
public const BAMBOO = 20005;
public const BANNER = 20006;
public const BED = 20007;
public const BEETROOT = 20008;
public const BEETROOT_SEEDS = 20009;
public const BEETROOT_SOUP = 20010;
@ -189,7 +189,7 @@ final class ItemTypeIds{
public const MELON_SEEDS = 20150;
public const MILK_BUCKET = 20151;
public const MINECART = 20152;
public const MOB_HEAD = 20153;
public const MUSHROOM_STEW = 20154;
public const NAUTILUS_SHELL = 20155;
public const NETHER_BRICK = 20156;

View File

@ -1,57 +0,0 @@
<?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\SkullType;
use pocketmine\block\VanillaBlocks;
class Skull extends Item{
private SkullType $skullType;
public function __construct(ItemIdentifier $identifier, string $name){
$this->skullType = SkullType::SKELETON();
parent::__construct($identifier, $name);
}
public function getMeta() : int{
return $this->skullType->getMagicNumber();
}
public function getBlock(?int $clickedFace = null) : Block{
//TODO: we ought to be able to represent this as a regular ItemBlock
//but that's not currently possible because the skulltype isn't part of the internal block runtimeID
return VanillaBlocks::MOB_HEAD()->setSkullType($this->skullType);
}
public function getSkullType() : SkullType{
return $this->skullType;
}
/** @return $this */
public function setSkullType(SkullType $skullType) : self{
$this->skullType = $skullType;
return $this;
}
}

View File

@ -117,6 +117,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("barrier", fn() => Blocks::BARRIER());
$result->registerBlock("basalt", fn() => Blocks::BASALT());
$result->registerBlock("beacon", fn() => Blocks::BEACON());
$result->registerBlock("bed", fn() => Blocks::BED());
$result->registerBlock("bed_block", fn() => Blocks::BED());
$result->registerBlock("bedrock", fn() => Blocks::BEDROCK());
$result->registerBlock("beetroot_block", fn() => Blocks::BEETROOTS());
@ -215,6 +216,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("cracked_polished_blackstone_bricks", fn() => Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS());
$result->registerBlock("cracked_stone_bricks", fn() => Blocks::CRACKED_STONE_BRICKS());
$result->registerBlock("crafting_table", fn() => Blocks::CRAFTING_TABLE());
$result->registerBlock("creeper_head", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::CREEPER()));
$result->registerBlock("cut_red_sandstone", fn() => Blocks::CUT_RED_SANDSTONE());
$result->registerBlock("cut_red_sandstone_slab", fn() => Blocks::CUT_RED_SANDSTONE_SLAB());
$result->registerBlock("cut_sandstone", fn() => Blocks::CUT_SANDSTONE());
@ -275,6 +277,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("double_wooden_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE()));
$result->registerBlock("double_wooden_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE()));
$result->registerBlock("dragon_egg", fn() => Blocks::DRAGON_EGG());
$result->registerBlock("dragon_head", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::DRAGON()));
$result->registerBlock("dried_kelp_block", fn() => Blocks::DRIED_KELP());
$result->registerBlock("dyed_shulker_box", fn() => Blocks::DYED_SHULKER_BOX());
$result->registerBlock("element_0", fn() => Blocks::ELEMENT_ZERO());
@ -667,6 +670,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("material_reducer", fn() => Blocks::MATERIAL_REDUCER());
$result->registerBlock("melon_block", fn() => Blocks::MELON());
$result->registerBlock("melon_stem", fn() => Blocks::MELON_STEM());
$result->registerBlock("mob_head", fn() => Blocks::MOB_HEAD());
$result->registerBlock("mob_head_block", fn() => Blocks::MOB_HEAD());
$result->registerBlock("mob_spawner", fn() => Blocks::MONSTER_SPAWNER());
$result->registerBlock("monster_egg", fn() => Blocks::INFESTED_STONE());
@ -730,6 +734,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("pink_tulip", fn() => Blocks::PINK_TULIP());
$result->registerBlock("plank", fn() => Blocks::OAK_PLANKS());
$result->registerBlock("planks", fn() => Blocks::OAK_PLANKS());
$result->registerBlock("player_head", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::PLAYER()));
$result->registerBlock("podzol", fn() => Blocks::PODZOL());
$result->registerBlock("polished_andesite", fn() => Blocks::POLISHED_ANDESITE());
$result->registerBlock("polished_andesite_slab", fn() => Blocks::POLISHED_ANDESITE_SLAB());
@ -826,6 +831,8 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("shulker_box", fn() => Blocks::SHULKER_BOX());
$result->registerBlock("sign", fn() => Blocks::OAK_SIGN());
$result->registerBlock("sign_post", fn() => Blocks::OAK_SIGN());
$result->registerBlock("skeleton_skull", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::SKELETON()));
$result->registerBlock("skull", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::SKELETON()));
$result->registerBlock("skull_block", fn() => Blocks::MOB_HEAD());
$result->registerBlock("slab", fn() => Blocks::SMOOTH_STONE_SLAB());
$result->registerBlock("slabs", fn() => Blocks::SMOOTH_STONE_SLAB());
@ -946,6 +953,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("weighted_pressure_plate_light", fn() => Blocks::WEIGHTED_PRESSURE_PLATE_LIGHT());
$result->registerBlock("wheat_block", fn() => Blocks::WHEAT());
$result->registerBlock("white_tulip", fn() => Blocks::WHITE_TULIP());
$result->registerBlock("wither_skeleton_skull", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::WITHER_SKELETON()));
$result->registerBlock("wood", fn() => Blocks::OAK_LOG()->setStripped(false));
$result->registerBlock("wood2", fn() => Blocks::ACACIA_LOG()->setStripped(false));
$result->registerBlock("wood_door_block", fn() => Blocks::OAK_DOOR());
@ -965,6 +973,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("wool", fn() => Blocks::WOOL());
$result->registerBlock("workbench", fn() => Blocks::CRAFTING_TABLE());
$result->registerBlock("yellow_flower", fn() => Blocks::DANDELION());
$result->registerBlock("zombie_head", fn() => Blocks::MOB_HEAD()->setSkullType(SkullType::ZOMBIE()));
$result->register("acacia_boat", fn() => Items::ACACIA_BOAT());
$result->register("apple", fn() => Items::APPLE());
@ -975,7 +984,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("awkward_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::AWKWARD()));
$result->register("baked_potato", fn() => Items::BAKED_POTATO());
$result->register("baked_potatoes", fn() => Items::BAKED_POTATO());
$result->register("bed", fn() => Items::BED());
$result->register("beef", fn() => Items::RAW_BEEF());
$result->register("beetroot", fn() => Items::BEETROOT());
$result->register("beetroot_seed", fn() => Items::BEETROOT_SEEDS());
@ -1065,7 +1073,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("cooked_rabbit", fn() => Items::COOKED_RABBIT());
$result->register("cooked_salmon", fn() => Items::COOKED_SALMON());
$result->register("cookie", fn() => Items::COOKIE());
$result->register("creeper_head", fn() => Items::MOB_HEAD()->setSkullType(SkullType::CREEPER()));
$result->register("dark_oak_boat", fn() => Items::DARK_OAK_BOAT());
$result->register("diamond", fn() => Items::DIAMOND());
$result->register("diamond_axe", fn() => Items::DIAMOND_AXE());
@ -1078,7 +1085,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("diamond_shovel", fn() => Items::DIAMOND_SHOVEL());
$result->register("diamond_sword", fn() => Items::DIAMOND_SWORD());
$result->register("dragon_breath", fn() => Items::DRAGON_BREATH());
$result->register("dragon_head", fn() => Items::MOB_HEAD()->setSkullType(SkullType::DRAGON()));
$result->register("dried_kelp", fn() => Items::DRIED_KELP());
$result->register("dye", fn() => Items::INK_SAC());
$result->register("egg", fn() => Items::EGG());
@ -1190,7 +1196,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("melon_slice", fn() => Items::MELON());
$result->register("milk_bucket", fn() => Items::MILK_BUCKET());
$result->register("minecart", fn() => Items::MINECART());
$result->register("mob_head", fn() => Items::MOB_HEAD());
$result->register("mundane_potion", fn() => Items::POTION()->setType(PotionType::MUNDANE()));
$result->register("mundane_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::MUNDANE()));
$result->register("mushroom_stew", fn() => Items::MUSHROOM_STEW());
@ -1210,7 +1215,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("oak_boat", fn() => Items::OAK_BOAT());
$result->register("painting", fn() => Items::PAINTING());
$result->register("paper", fn() => Items::PAPER());
$result->register("player_head", fn() => Items::MOB_HEAD()->setSkullType(SkullType::PLAYER()));
$result->register("poison_potion", fn() => Items::POTION()->setType(PotionType::POISON()));
$result->register("poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::POISON()));
$result->register("poisonous_potato", fn() => Items::POISONOUS_POTATO());
@ -1259,8 +1263,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("seeds", fn() => Items::WHEAT_SEEDS());
$result->register("shears", fn() => Items::SHEARS());
$result->register("shulker_shell", fn() => Items::SHULKER_SHELL());
$result->register("skeleton_skull", fn() => Items::MOB_HEAD()->setSkullType(SkullType::SKELETON()));
$result->register("skull", fn() => Items::MOB_HEAD()->setSkullType(SkullType::SKELETON()));
$result->register("slime_ball", fn() => Items::SLIMEBALL());
$result->register("slimeball", fn() => Items::SLIMEBALL());
$result->register("slow_falling_potion", fn() => Items::POTION()->setType(PotionType::SLOW_FALLING()));
@ -1321,7 +1323,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("wheat", fn() => Items::WHEAT());
$result->register("wheat_seeds", fn() => Items::WHEAT_SEEDS());
$result->register("wither_potion", fn() => Items::POTION()->setType(PotionType::WITHER()));
$result->register("wither_skeleton_skull", fn() => Items::MOB_HEAD()->setSkullType(SkullType::WITHER_SKELETON()));
$result->register("wither_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WITHER()));
$result->register("wooden_axe", fn() => Items::WOODEN_AXE());
$result->register("wooden_hoe", fn() => Items::WOODEN_HOE());
@ -1330,7 +1331,6 @@ final class StringToItemParser extends StringToTParser{
$result->register("wooden_sword", fn() => Items::WOODEN_SWORD());
$result->register("writable_book", fn() => Items::WRITABLE_BOOK());
$result->register("written_book", fn() => Items::WRITTEN_BOOK());
$result->register("zombie_head", fn() => Items::MOB_HEAD()->setSkullType(SkullType::ZOMBIE()));
$result->register("zombie_spawn_egg", fn() => Items::ZOMBIE_SPAWN_EGG());
return $result;

View File

@ -40,7 +40,6 @@ use pocketmine\utils\CloningRegistryTrait;
* @method static BakedPotato BAKED_POTATO()
* @method static Bamboo BAMBOO()
* @method static Banner BANNER()
* @method static Bed BED()
* @method static Beetroot BEETROOT()
* @method static BeetrootSeeds BEETROOT_SEEDS()
* @method static BeetrootSoup BEETROOT_SOUP()
@ -186,7 +185,6 @@ use pocketmine\utils\CloningRegistryTrait;
* @method static MelonSeeds MELON_SEEDS()
* @method static MilkBucket MILK_BUCKET()
* @method static Minecart MINECART()
* @method static Skull MOB_HEAD()
* @method static MushroomStew MUSHROOM_STEW()
* @method static Item NAUTILUS_SHELL()
* @method static Item NETHER_BRICK()
@ -294,7 +292,6 @@ final class VanillaItems{
self::register("baked_potato", $factory->get(Ids::BAKED_POTATO));
self::register("bamboo", $factory->get(Ids::BAMBOO));
self::register("banner", $factory->get(Ids::BANNER));
self::register("bed", $factory->get(Ids::BED));
self::register("beetroot", $factory->get(Ids::BEETROOT));
self::register("beetroot_seeds", $factory->get(Ids::BEETROOT_SEEDS));
self::register("beetroot_soup", $factory->get(Ids::BEETROOT_SOUP));
@ -440,7 +437,6 @@ final class VanillaItems{
self::register("melon_seeds", $factory->get(Ids::MELON_SEEDS));
self::register("milk_bucket", $factory->get(Ids::BUCKET, 1));
self::register("minecart", $factory->get(Ids::MINECART));
self::register("mob_head", $factory->get(Ids::MOB_HEAD));
self::register("mushroom_stew", $factory->get(Ids::MUSHROOM_STEW));
self::register("nautilus_shell", $factory->get(Ids::NAUTILUS_SHELL));
self::register("nether_brick", $factory->get(Ids::NETHERBRICK));