mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Cleaned up some copy-pasted code for coloured blocks names
This commit is contained in:
parent
8510be062c
commit
021dbd65d7
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColorBlockMetaHelper;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -46,25 +47,7 @@ class Carpet extends Flowable{
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "White Carpet",
|
||||
1 => "Orange Carpet",
|
||||
2 => "Magenta Carpet",
|
||||
3 => "Light Blue Carpet",
|
||||
4 => "Yellow Carpet",
|
||||
5 => "Lime Carpet",
|
||||
6 => "Pink Carpet",
|
||||
7 => "Gray Carpet",
|
||||
8 => "Light Gray Carpet",
|
||||
9 => "Cyan Carpet",
|
||||
10 => "Purple Carpet",
|
||||
11 => "Blue Carpet",
|
||||
12 => "Brown Carpet",
|
||||
13 => "Green Carpet",
|
||||
14 => "Red Carpet",
|
||||
15 => "Black Carpet",
|
||||
];
|
||||
return $names[$this->meta & 0x0f];
|
||||
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Carpet";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
|
@ -49,11 +49,9 @@ class DoubleWoodenSlab extends Solid{
|
||||
2 => "Birch",
|
||||
3 => "Jungle",
|
||||
4 => "Acacia",
|
||||
5 => "Dark Oak",
|
||||
6 => "",
|
||||
7 => ""
|
||||
5 => "Dark Oak"
|
||||
];
|
||||
return "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
|
||||
return "Double " . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -55,19 +55,11 @@ class Flower extends Flowable{
|
||||
self::TYPE_ORANGE_TULIP => "Orange Tulip",
|
||||
self::TYPE_WHITE_TULIP => "White Tulip",
|
||||
self::TYPE_PINK_TULIP => "Pink Tulip",
|
||||
self::TYPE_OXEYE_DAISY => "Oxeye Daisy",
|
||||
9 => "Unknown",
|
||||
10 => "Unknown",
|
||||
11 => "Unknown",
|
||||
12 => "Unknown",
|
||||
13 => "Unknown",
|
||||
14 => "Unknown",
|
||||
15 => "Unknown"
|
||||
self::TYPE_OXEYE_DAISY => "Oxeye Daisy"
|
||||
];
|
||||
return $names[$this->meta];
|
||||
return $names[$this->meta] ?? "Unknown";
|
||||
}
|
||||
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||
if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){
|
||||
|
@ -46,10 +46,9 @@ class Sandstone extends Solid{
|
||||
static $names = [
|
||||
self::NORMAL => "Sandstone",
|
||||
self::CHISELED => "Chiseled Sandstone",
|
||||
self::SMOOTH => "Smooth Sandstone",
|
||||
3 => "",
|
||||
self::SMOOTH => "Smooth Sandstone"
|
||||
];
|
||||
return $names[$this->meta & 0x03];
|
||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
|
@ -51,11 +51,9 @@ class Sapling extends Flowable{
|
||||
2 => "Birch Sapling",
|
||||
3 => "Jungle Sapling",
|
||||
4 => "Acacia Sapling",
|
||||
5 => "Dark Oak Sapling",
|
||||
6 => "",
|
||||
7 => "",
|
||||
5 => "Dark Oak Sapling"
|
||||
];
|
||||
return $names[$this->meta & 0x07];
|
||||
return $names[$this->meta & 0x07] ?? "Unknown";
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColorBlockMetaHelper;
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class StainedClay extends Solid{
|
||||
@ -42,25 +43,7 @@ class StainedClay extends Solid{
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "White Stained Clay",
|
||||
1 => "Orange Stained Clay",
|
||||
2 => "Magenta Stained Clay",
|
||||
3 => "Light Blue Stained Clay",
|
||||
4 => "Yellow Stained Clay",
|
||||
5 => "Lime Stained Clay",
|
||||
6 => "Pink Stained Clay",
|
||||
7 => "Gray Stained Clay",
|
||||
8 => "Light Gray Stained Clay",
|
||||
9 => "Cyan Stained Clay",
|
||||
10 => "Purple Stained Clay",
|
||||
11 => "Blue Stained Clay",
|
||||
12 => "Brown Stained Clay",
|
||||
13 => "Green Stained Clay",
|
||||
14 => "Red Stained Clay",
|
||||
15 => "Black Stained Clay",
|
||||
];
|
||||
return $names[$this->meta & 0x0f];
|
||||
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Clay";
|
||||
}
|
||||
|
||||
}
|
@ -57,10 +57,9 @@ class Stone extends Solid{
|
||||
self::DIORITE => "Diorite",
|
||||
self::POLISHED_DIORITE => "Polished Diorite",
|
||||
self::ANDESITE => "Andesite",
|
||||
self::POLISHED_ANDESITE => "Polished Andesite",
|
||||
7 => "Unknown Stone",
|
||||
self::POLISHED_ANDESITE => "Polished Andesite"
|
||||
];
|
||||
return $names[$this->meta & 0x07];
|
||||
return $names[$this->meta & 0x07] ?? "Unknown";
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -44,10 +44,9 @@ class TallGrass extends Flowable{
|
||||
static $names = [
|
||||
0 => "Dead Shrub",
|
||||
1 => "Tall Grass",
|
||||
2 => "Fern",
|
||||
3 => ""
|
||||
2 => "Fern"
|
||||
];
|
||||
return $names[$this->meta & 0x03];
|
||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
|
@ -34,10 +34,8 @@ class Wood2 extends Wood{
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "Acacia Wood",
|
||||
1 => "Dark Oak Wood",
|
||||
2 => "Unknown",
|
||||
3 => "Unknown"
|
||||
1 => "Dark Oak Wood"
|
||||
];
|
||||
return $names[$this->meta & 0x03];
|
||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
||||
}
|
||||
}
|
||||
|
@ -49,11 +49,9 @@ class WoodenSlab extends Transparent{
|
||||
2 => "Birch",
|
||||
3 => "Jungle",
|
||||
4 => "Acacia",
|
||||
5 => "Dark Oak",
|
||||
6 => "",
|
||||
7 => ""
|
||||
5 => "Dark Oak"
|
||||
];
|
||||
return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Wooden Slab";
|
||||
return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab";
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\ColorBlockMetaHelper;
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class Wool extends Solid{
|
||||
@ -42,25 +43,7 @@ class Wool extends Solid{
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
static $names = [
|
||||
0 => "White Wool",
|
||||
1 => "Orange Wool",
|
||||
2 => "Magenta Wool",
|
||||
3 => "Light Blue Wool",
|
||||
4 => "Yellow Wool",
|
||||
5 => "Lime Wool",
|
||||
6 => "Pink Wool",
|
||||
7 => "Gray Wool",
|
||||
8 => "Light Gray Wool",
|
||||
9 => "Cyan Wool",
|
||||
10 => "Purple Wool",
|
||||
11 => "Blue Wool",
|
||||
12 => "Brown Wool",
|
||||
13 => "Green Wool",
|
||||
14 => "Red Wool",
|
||||
15 => "Black Wool",
|
||||
];
|
||||
return $names[$this->meta & 0x0f];
|
||||
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Wool";
|
||||
}
|
||||
|
||||
}
|
50
src/pocketmine/block/utils/ColorBlockMetaHelper.php
Normal file
50
src/pocketmine/block/utils/ColorBlockMetaHelper.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?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\utils;
|
||||
|
||||
class ColorBlockMetaHelper{
|
||||
|
||||
public static function getColorFromMeta(int $meta) : string{
|
||||
static $names = [
|
||||
0 => "White",
|
||||
1 => "Orange",
|
||||
2 => "Magenta",
|
||||
3 => "Light Blue",
|
||||
4 => "Yellow",
|
||||
5 => "Lime",
|
||||
6 => "Pink",
|
||||
7 => "Gray",
|
||||
8 => "Light Gray",
|
||||
9 => "Cyan",
|
||||
10 => "Purple",
|
||||
11 => "Blue",
|
||||
12 => "Brown",
|
||||
13 => "Green",
|
||||
14 => "Red",
|
||||
15 => "Black",
|
||||
];
|
||||
|
||||
return $names[$meta] ?? "Unknown";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user