Fixed fix for flowers, removed corrupted flower state, added proper identifiers that do not collide, added remaining IDs everywhere for consistency, removed magic number for constants, closes #3058

This commit is contained in:
Shoghi Cervantes 2015-05-23 22:49:06 +02:00
parent f91a3a2666
commit c4d63326be
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
3 changed files with 44 additions and 33 deletions

View File

@ -84,6 +84,8 @@ class Block extends Position implements Metadatable{
const DEAD_BUSH = 32; const DEAD_BUSH = 32;
const WOOL = 35; const WOOL = 35;
const DANDELION = 37; const DANDELION = 37;
const ROSE = 38;
const POPPY = 38;
const RED_FLOWER = 38; const RED_FLOWER = 38;
const BROWN_MUSHROOM = 39; const BROWN_MUSHROOM = 39;
const RED_MUSHROOM = 40; const RED_MUSHROOM = 40;

View File

@ -23,47 +23,53 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
class Flower extends Flowable{ class Flower extends Flowable{
const POPPY = 0; const TYPE_POPPY = 0;
const BLUE_ORCHID = 1; const TYPE_BLUE_ORCHID = 1;
const ALLIUM = 2; const TYPE_ALLIUM = 2;
const AZURE_BLUET = 3; const TYPE_AZURE_BLUET = 3;
const RED_TULIP = 4; const TYPE_RED_TULIP = 4;
const ORANGE_TULIP = 5; const TYPE_ORANGE_TULIP = 5;
const WHITE_TULIP = 6; const TYPE_WHITE_TULIP = 6;
const PINK_TULIP = 7; const TYPE_PINK_TULIP = 7;
const OXEYE_DAISY = 8; const TYPE_OXEYE_DAISY = 8;
protected $id = self::RED_FLOWER; protected $id = self::RED_FLOWER;
public function __construct($meta = 0){ public function __construct($meta = 0){
$this->meta = $meta; $this->meta = $meta;
} }
public function getName(){ public function getName(){
static $names = [ static $names = [
self::POPPY => "Poppy", self::TYPE_POPPY => "Poppy",
self::BLUE_ORCHID => "Blue Orchid", self::TYPE_BLUE_ORCHID => "Blue Orchid",
self::ALLIUM => "Allium", self::TYPE_ALLIUM => "Allium",
self::AZURE_BLUET => "Azure Bluet", self::TYPE_AZURE_BLUET => "Azure Bluet",
self::RED_TULIP => "Red Tulip", self::TYPE_RED_TULIP => "Red Tulip",
self::ORANGE_TULIP => "Orange Tulip", self::TYPE_ORANGE_TULIP => "Orange Tulip",
self::WHITE_TULIP => "White Tulip", self::TYPE_WHITE_TULIP => "White Tulip",
self::PINK_TULIP => "Pink Tulip", self::TYPE_PINK_TULIP => "Pink Tulip",
self::OXEYE_DAISY => "Oxeye Daisy", self::TYPE_OXEYE_DAISY => "Oxeye Daisy",
9 => "Unknown Flower", 9 => "Unknown",
10 => "Unknown",
11 => "Unknown",
12 => "Unknown",
13 => "Unknown",
14 => "Unknown",
15 => "Unknown"
]; ];
return $names[$this->meta & 0x09]; return $names[$this->meta];
} }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){ if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($block, $this, true, true); $this->getLevel()->setBlock($block, $this, true);
return true; return true;
} }
@ -73,7 +79,7 @@ class Flower extends Flowable{
public function onUpdate($type){ public function onUpdate($type){
if($type === Level::BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent() === true){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
$this->getLevel()->useBreakOn($this); $this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;

View File

@ -25,6 +25,7 @@
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\Flower;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\entity\Squid; use pocketmine\entity\Squid;
use pocketmine\entity\Villager; use pocketmine\entity\Villager;
@ -78,6 +79,8 @@ class Item{
const DEAD_BUSH = 32; const DEAD_BUSH = 32;
const WOOL = 35; const WOOL = 35;
const DANDELION = 37; const DANDELION = 37;
const POPPY = 38;
const ROSE = 38;
const RED_FLOWER = 38; const RED_FLOWER = 38;
const BROWN_MUSHROOM = 39; const BROWN_MUSHROOM = 39;
const RED_MUSHROOM = 40; const RED_MUSHROOM = 40;
@ -643,15 +646,15 @@ class Item{
self::addCreativeItem(Item::get(Item::FURNACE, 0)); self::addCreativeItem(Item::get(Item::FURNACE, 0));
self::addCreativeItem(Item::get(Item::END_PORTAL, 0)); self::addCreativeItem(Item::get(Item::END_PORTAL, 0));
self::addCreativeItem(Item::get(Item::DANDELION, 0)); self::addCreativeItem(Item::get(Item::DANDELION, 0));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 0)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_POPPY));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 1)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_BLUE_ORCHID));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 2)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_ALLIUM));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 3)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_AZURE_BLUET));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 4)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_RED_TULIP));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 5)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_ORANGE_TULIP));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 6)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_WHITE_TULIP));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 7)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_PINK_TULIP));
self::addCreativeItem(Item::get(Item::RED_FLOWER, 8)); self::addCreativeItem(Item::get(Item::RED_FLOWER, Flower::TYPE_OXEYE_DAISY));
//TODO: Lilac //TODO: Lilac
//TODO: Double Tallgrass //TODO: Double Tallgrass
//TODO: Large Fern //TODO: Large Fern