mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Consistently use 'mob head' terminology in the API
previously, we were sometimes using 'mob head' and other times 'skull', sometimes even within the same file.
This commit is contained in:
@ -23,8 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\tile\Skull as TileSkull;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\tile\MobHead as TileMobHead;
|
||||
use pocketmine\block\utils\MobHeadType;
|
||||
use pocketmine\data\runtime\RuntimeDataDescriber;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -35,22 +35,22 @@ use pocketmine\world\BlockTransaction;
|
||||
use function assert;
|
||||
use function floor;
|
||||
|
||||
class Skull extends Flowable{
|
||||
class MobHead extends Flowable{
|
||||
public const MIN_ROTATION = 0;
|
||||
public const MAX_ROTATION = 15;
|
||||
|
||||
protected SkullType $skullType;
|
||||
protected MobHeadType $mobHeadType;
|
||||
|
||||
protected int $facing = Facing::NORTH;
|
||||
protected int $rotation = self::MIN_ROTATION; //TODO: split this into floor skull and wall skull handling
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
|
||||
$this->skullType = SkullType::SKELETON(); //TODO: this should be a parameter
|
||||
$this->mobHeadType = MobHeadType::SKELETON(); //TODO: this should be a parameter
|
||||
parent::__construct($idInfo, $name, $typeInfo);
|
||||
}
|
||||
|
||||
public function describeBlockItemState(RuntimeDataDescriber $w) : void{
|
||||
$w->skullType($this->skullType);
|
||||
$w->mobHeadType($this->mobHeadType);
|
||||
}
|
||||
|
||||
protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
||||
@ -60,8 +60,8 @@ class Skull extends Flowable{
|
||||
public function readStateFromWorld() : Block{
|
||||
parent::readStateFromWorld();
|
||||
$tile = $this->position->getWorld()->getTile($this->position);
|
||||
if($tile instanceof TileSkull){
|
||||
$this->skullType = $tile->getSkullType();
|
||||
if($tile instanceof TileMobHead){
|
||||
$this->mobHeadType = $tile->getMobHeadType();
|
||||
$this->rotation = $tile->getRotation();
|
||||
}
|
||||
|
||||
@ -72,18 +72,18 @@ class Skull extends Flowable{
|
||||
parent::writeStateToWorld();
|
||||
//extra block properties storage hack
|
||||
$tile = $this->position->getWorld()->getTile($this->position);
|
||||
assert($tile instanceof TileSkull);
|
||||
assert($tile instanceof TileMobHead);
|
||||
$tile->setRotation($this->rotation);
|
||||
$tile->setSkullType($this->skullType);
|
||||
$tile->setMobHeadType($this->mobHeadType);
|
||||
}
|
||||
|
||||
public function getSkullType() : SkullType{
|
||||
return $this->skullType;
|
||||
public function getMobHeadType() : MobHeadType{
|
||||
return $this->mobHeadType;
|
||||
}
|
||||
|
||||
/** @return $this */
|
||||
public function setSkullType(SkullType $skullType) : self{
|
||||
$this->skullType = $skullType;
|
||||
public function setMobHeadType(MobHeadType $mobHeadType) : self{
|
||||
$this->mobHeadType = $mobHeadType;
|
||||
return $this;
|
||||
}
|
||||
|
@ -48,11 +48,11 @@ use pocketmine\block\tile\Hopper as TileHopper;
|
||||
use pocketmine\block\tile\ItemFrame as TileItemFrame;
|
||||
use pocketmine\block\tile\Jukebox as TileJukebox;
|
||||
use pocketmine\block\tile\Lectern as TileLectern;
|
||||
use pocketmine\block\tile\MobHead as TileMobHead;
|
||||
use pocketmine\block\tile\MonsterSpawner as TileMonsterSpawner;
|
||||
use pocketmine\block\tile\NormalFurnace as TileNormalFurnace;
|
||||
use pocketmine\block\tile\Note as TileNote;
|
||||
use pocketmine\block\tile\ShulkerBox as TileShulkerBox;
|
||||
use pocketmine\block\tile\Skull as TileSkull;
|
||||
use pocketmine\block\tile\Smoker as TileSmoker;
|
||||
use pocketmine\block\utils\LeavesType;
|
||||
use pocketmine\block\utils\SaplingType;
|
||||
@ -503,7 +503,7 @@ use function mb_strtolower;
|
||||
* @method static ChemistryTable MATERIAL_REDUCER()
|
||||
* @method static Melon MELON()
|
||||
* @method static MelonStem MELON_STEM()
|
||||
* @method static Skull MOB_HEAD()
|
||||
* @method static MobHead MOB_HEAD()
|
||||
* @method static MonsterSpawner MONSTER_SPAWNER()
|
||||
* @method static Opaque MOSSY_COBBLESTONE()
|
||||
* @method static Slab MOSSY_COBBLESTONE_SLAB()
|
||||
@ -981,7 +981,7 @@ final class VanillaBlocks{
|
||||
|
||||
self::register("sea_lantern", new SeaLantern(new BID(Ids::SEA_LANTERN), "Sea Lantern", new Info(new BreakInfo(0.3))));
|
||||
self::register("sea_pickle", new SeaPickle(new BID(Ids::SEA_PICKLE), "Sea Pickle", new Info(BreakInfo::instant())));
|
||||
self::register("mob_head", new Skull(new BID(Ids::MOB_HEAD, TileSkull::class), "Mob Head", new Info(new BreakInfo(1.0))));
|
||||
self::register("mob_head", new MobHead(new BID(Ids::MOB_HEAD, TileMobHead::class), "Mob Head", new Info(new BreakInfo(1.0))));
|
||||
self::register("slime", new Slime(new BID(Ids::SLIME), "Slime Block", new Info(BreakInfo::instant())));
|
||||
self::register("snow", new Snow(new BID(Ids::SNOW), "Snow Block", new Info(BreakInfo::shovel(0.2, ToolTier::WOOD()))));
|
||||
self::register("snow_layer", new SnowLayer(new BID(Ids::SNOW_LAYER), "Snow Layer", new Info(BreakInfo::shovel(0.1, ToolTier::WOOD()))));
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\tile;
|
||||
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\block\utils\MobHeadType;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@ -31,60 +31,60 @@ use pocketmine\world\World;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see \pocketmine\block\Skull
|
||||
* @see \pocketmine\block\MobHead
|
||||
*/
|
||||
class Skull extends Spawnable{
|
||||
class MobHead extends Spawnable{
|
||||
|
||||
private const TAG_SKULL_TYPE = "SkullType"; //TAG_Byte
|
||||
private const TAG_ROT = "Rot"; //TAG_Byte
|
||||
private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte
|
||||
private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int
|
||||
|
||||
private SkullType $skullType;
|
||||
private int $skullRotation = 0;
|
||||
private MobHeadType $mobHeadType;
|
||||
private int $rotation = 0;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->skullType = SkullType::SKELETON();
|
||||
$this->mobHeadType = MobHeadType::SKELETON();
|
||||
parent::__construct($world, $pos);
|
||||
}
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){
|
||||
try{
|
||||
$this->skullType = SkullType::fromMagicNumber($skullTypeTag->getValue());
|
||||
$this->mobHeadType = MobHeadType::fromMagicNumber($skullTypeTag->getValue());
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//bad data, drop it
|
||||
}
|
||||
}
|
||||
$rotation = $nbt->getByte(self::TAG_ROT, 0);
|
||||
if($rotation >= 0 && $rotation <= 15){
|
||||
$this->skullRotation = $rotation;
|
||||
$this->rotation = $rotation;
|
||||
}
|
||||
}
|
||||
|
||||
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||
$nbt->setByte(self::TAG_SKULL_TYPE, $this->skullType->getMagicNumber());
|
||||
$nbt->setByte(self::TAG_ROT, $this->skullRotation);
|
||||
$nbt->setByte(self::TAG_SKULL_TYPE, $this->mobHeadType->getMagicNumber());
|
||||
$nbt->setByte(self::TAG_ROT, $this->rotation);
|
||||
}
|
||||
|
||||
public function setSkullType(SkullType $type) : void{
|
||||
$this->skullType = $type;
|
||||
public function setMobHeadType(MobHeadType $type) : void{
|
||||
$this->mobHeadType = $type;
|
||||
}
|
||||
|
||||
public function getSkullType() : SkullType{
|
||||
return $this->skullType;
|
||||
public function getMobHeadType() : MobHeadType{
|
||||
return $this->mobHeadType;
|
||||
}
|
||||
|
||||
public function getRotation() : int{
|
||||
return $this->skullRotation;
|
||||
return $this->rotation;
|
||||
}
|
||||
|
||||
public function setRotation(int $rotation) : void{
|
||||
$this->skullRotation = $rotation;
|
||||
$this->rotation = $rotation;
|
||||
}
|
||||
|
||||
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||
$nbt->setByte(self::TAG_SKULL_TYPE, $this->skullType->getMagicNumber());
|
||||
$nbt->setByte(self::TAG_ROT, $this->skullRotation);
|
||||
$nbt->setByte(self::TAG_SKULL_TYPE, $this->mobHeadType->getMagicNumber());
|
||||
$nbt->setByte(self::TAG_ROT, $this->rotation);
|
||||
}
|
||||
}
|
@ -75,7 +75,7 @@ final class TileFactory{
|
||||
$this->register(Sign::class, ["Sign", "minecraft:sign"]);
|
||||
$this->register(Smoker::class, ["Smoker", "minecraft:smoker"]);
|
||||
$this->register(SporeBlossom::class, ["SporeBlossom", "minecraft:spore_blossom"]);
|
||||
$this->register(Skull::class, ["Skull", "minecraft:skull"]);
|
||||
$this->register(MobHead::class, ["Skull", "minecraft:skull"]);
|
||||
$this->register(GlowingItemFrame::class, ["GlowItemFrame"]);
|
||||
|
||||
//TODO: Campfire
|
||||
|
@ -31,34 +31,34 @@ use pocketmine\utils\EnumTrait;
|
||||
* @see build/generate-registry-annotations.php
|
||||
* @generate-registry-docblock
|
||||
*
|
||||
* @method static SkullType CREEPER()
|
||||
* @method static SkullType DRAGON()
|
||||
* @method static SkullType PLAYER()
|
||||
* @method static SkullType SKELETON()
|
||||
* @method static SkullType WITHER_SKELETON()
|
||||
* @method static SkullType ZOMBIE()
|
||||
* @method static MobHeadType CREEPER()
|
||||
* @method static MobHeadType DRAGON()
|
||||
* @method static MobHeadType PLAYER()
|
||||
* @method static MobHeadType SKELETON()
|
||||
* @method static MobHeadType WITHER_SKELETON()
|
||||
* @method static MobHeadType ZOMBIE()
|
||||
*/
|
||||
final class SkullType{
|
||||
final class MobHeadType{
|
||||
use EnumTrait {
|
||||
register as Enum_register;
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
/** @var SkullType[] */
|
||||
/** @var MobHeadType[] */
|
||||
private static array $numericIdMap = [];
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new SkullType("skeleton", "Skeleton Skull", 0),
|
||||
new SkullType("wither_skeleton", "Wither Skeleton Skull", 1),
|
||||
new SkullType("zombie", "Zombie Head", 2),
|
||||
new SkullType("player", "Player Head", 3),
|
||||
new SkullType("creeper", "Creeper Head", 4),
|
||||
new SkullType("dragon", "Dragon Head", 5)
|
||||
new MobHeadType("skeleton", "Skeleton Skull", 0),
|
||||
new MobHeadType("wither_skeleton", "Wither Skeleton Skull", 1),
|
||||
new MobHeadType("zombie", "Zombie Head", 2),
|
||||
new MobHeadType("player", "Player Head", 3),
|
||||
new MobHeadType("creeper", "Creeper Head", 4),
|
||||
new MobHeadType("dragon", "Dragon Head", 5)
|
||||
);
|
||||
}
|
||||
|
||||
protected static function register(SkullType $type) : void{
|
||||
protected static function register(MobHeadType $type) : void{
|
||||
self::Enum_register($type);
|
||||
self::$numericIdMap[$type->getMagicNumber()] = $type;
|
||||
}
|
||||
@ -68,7 +68,7 @@ final class SkullType{
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromMagicNumber(int $magicNumber) : SkullType{
|
||||
public static function fromMagicNumber(int $magicNumber) : MobHeadType{
|
||||
if(!isset(self::$numericIdMap[$magicNumber])){
|
||||
throw new \InvalidArgumentException("Unknown skull type magic number $magicNumber");
|
||||
}
|
Reference in New Issue
Block a user