mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Added missing tile for Note Block
this doesn't come with a full impl because that requires some further changes like adding materials, which is out of the scope of this commit. This is here to prevent additional data loss in imported worlds.
This commit is contained in:
parent
ece4d99c1e
commit
f18da8d879
@ -36,6 +36,7 @@ use pocketmine\block\tile\EnderChest as TileEnderChest;
|
||||
use pocketmine\block\tile\FlowerPot as TileFlowerPot;
|
||||
use pocketmine\block\tile\Furnace as TileFurnace;
|
||||
use pocketmine\block\tile\ItemFrame as TileItemFrame;
|
||||
use pocketmine\block\tile\Note as TileNote;
|
||||
use pocketmine\block\tile\Sign as TileSign;
|
||||
use pocketmine\block\tile\Skull as TileSkull;
|
||||
use pocketmine\block\tile\TileFactory;
|
||||
@ -241,7 +242,7 @@ class BlockFactory{
|
||||
self::register(new Solid(new BID(Ids::NETHER_WART_BLOCK), "Nether Wart Block", new BlockBreakInfo(1.0)));
|
||||
self::register(new NetherWartPlant(new BID(Ids::NETHER_WART_PLANT, 0, ItemIds::NETHER_WART), "Nether Wart"));
|
||||
self::register(new Netherrack(new BID(Ids::NETHERRACK), "Netherrack"));
|
||||
self::register(new NoteBlock(new BID(Ids::NOTEBLOCK), "Note Block"));
|
||||
self::register(new Note(new BID(Ids::NOTEBLOCK, 0, null, TileNote::class), "Note Block"));
|
||||
self::register(new Solid(new BID(Ids::OBSIDIAN), "Obsidian", new BlockBreakInfo(35.0 /* 50 in PC */, BlockToolType::TYPE_PICKAXE, TieredTool::TIER_DIAMOND, 6000.0)));
|
||||
self::register(new PackedIce(new BID(Ids::PACKED_ICE), "Packed Ice"));
|
||||
self::register(new Podzol(new BID(Ids::PODZOL), "Podzol"));
|
||||
|
@ -23,15 +23,57 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
class NoteBlock extends Solid{
|
||||
use pocketmine\block\tile\Note as TileNote;
|
||||
use function assert;
|
||||
|
||||
class Note extends Solid{
|
||||
public const MIN_PITCH = 0;
|
||||
public const MAX_PITCH = 24;
|
||||
|
||||
/** @var int */
|
||||
private $pitch = self::MIN_PITCH;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.8, BlockToolType::TYPE_AXE));
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : void{
|
||||
parent::readStateFromWorld();
|
||||
$tile = $this->world->getTile($this);
|
||||
if($tile instanceof TileNote){
|
||||
$this->pitch = $tile->getPitch();
|
||||
}else{
|
||||
$this->pitch = self::MIN_PITCH;
|
||||
}
|
||||
}
|
||||
|
||||
public function writeStateToWorld() : void{
|
||||
parent::writeStateToWorld();
|
||||
$tile = $this->world->getTile($this);
|
||||
assert($tile instanceof TileNote);
|
||||
$tile->setPitch($this->pitch);
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
return 300;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPitch() : int{
|
||||
return $this->pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pitch
|
||||
*/
|
||||
public function setPitch(int $pitch) : void{
|
||||
if($pitch < self::MIN_PITCH or $pitch > self::MAX_PITCH){
|
||||
throw new \InvalidArgumentException("Pitch must be in range " . self::MIN_PITCH . " - " . self::MAX_PITCH);
|
||||
}
|
||||
$this->pitch = $pitch;
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
62
src/pocketmine/block/tile/Note.php
Normal file
62
src/pocketmine/block/tile/Note.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\block\tile;
|
||||
|
||||
use pocketmine\block\Note as BlockNote;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class Note extends Tile{
|
||||
/** @var int */
|
||||
private $pitch = 0;
|
||||
|
||||
public function readSaveData(CompoundTag $nbt) : void{
|
||||
if(($pitch = $nbt->getByte("note", $this->pitch)) > BlockNote::MIN_PITCH and $pitch <= BlockNote::MAX_PITCH){
|
||||
$this->pitch = $pitch;
|
||||
}
|
||||
}
|
||||
|
||||
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||
$nbt->setByte("note", $this->pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPitch() : int{
|
||||
return $this->pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pitch
|
||||
*/
|
||||
public function setPitch(int $pitch) : void{
|
||||
if($pitch < BlockNote::MIN_PITCH or $pitch > BlockNote::MAX_PITCH){
|
||||
throw new \InvalidArgumentException("Pitch must be in range " . BlockNote::MIN_PITCH . " - " . BlockNote::MAX_PITCH);
|
||||
}
|
||||
$this->pitch = $pitch;
|
||||
}
|
||||
}
|
@ -55,6 +55,7 @@ final class TileFactory{
|
||||
self::register(FlowerPot::class, ["FlowerPot", "minecraft:flower_pot"]);
|
||||
self::register(Furnace::class, ["Furnace", "minecraft:furnace"]);
|
||||
self::register(ItemFrame::class, ["ItemFrame"]); //this is an entity in PC
|
||||
self::register(Note::class, ["Music", "minecraft:noteblock"]);
|
||||
self::register(Sign::class, ["Sign", "minecraft:sign"]);
|
||||
self::register(Skull::class, ["Skull", "minecraft:skull"]);
|
||||
|
||||
@ -80,7 +81,6 @@ final class TileFactory{
|
||||
//TODO: Lectern
|
||||
//TODO: MobSpawner
|
||||
//TODO: MovingBlock
|
||||
//TODO: Music
|
||||
//TODO: NetherReactor
|
||||
//TODO: PistonArm
|
||||
//TODO: ShulkerBox
|
||||
|
Loading…
x
Reference in New Issue
Block a user