Added API method Block->getItemId(), cleaned up excess wooden stairs and fence-gate classes, added more wooden door types

This commit is contained in:
Dylan K. Taylor 2017-08-04 13:02:24 +01:00
parent 561d8e7a39
commit 3135fe3c69
16 changed files with 87 additions and 431 deletions

View File

@ -1,33 +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\block;
class AcaciaWoodStairs extends WoodStairs{
protected $id = self::ACACIA_STAIRS;
public function getName(){
return "Acacia Wood Stairs";
}
}

View File

@ -1,33 +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\block;
class BirchWoodStairs extends WoodStairs{
protected $id = self::BIRCH_STAIRS;
public function getName(){
return "Birch Wood Stairs";
}
}

View File

@ -59,12 +59,6 @@ class Block extends Position implements BlockIds, Metadatable{
/** @var \SplFixedArray */
public static $diffusesSkyLight = null;
protected $id;
protected $meta = 0;
/** @var AxisAlignedBB */
public $boundingBox = null;
/**
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
* this if you need to reset the block factory back to its original defaults for whatever reason.
@ -134,7 +128,7 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new Torch());
self::registerBlock(new Fire());
self::registerBlock(new MonsterSpawner());
self::registerBlock(new WoodStairs());
self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs"));
self::registerBlock(new Chest());
self::registerBlock(new DiamondOre());
@ -145,7 +139,7 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new Furnace());
self::registerBlock(new BurningFurnace());
self::registerBlock(new SignPost());
self::registerBlock(new WoodenDoor());
self::registerBlock(new WoodenDoor(Block::OAK_DOOR_BLOCK, 0, "Oak Door Block", Item::OAK_DOOR));
self::registerBlock(new Ladder());
self::registerBlock(new Rail());
self::registerBlock(new CobblestoneStairs());
@ -185,7 +179,7 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new PumpkinStem());
self::registerBlock(new MelonStem());
self::registerBlock(new Vine());
self::registerBlock(new FenceGate());
self::registerBlock(new FenceGate(Block::OAK_FENCE_GATE, 0, "Oak Fence Gate"));
self::registerBlock(new BrickStairs());
self::registerBlock(new StoneBrickStairs());
self::registerBlock(new Mycelium());
@ -211,9 +205,9 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new TripwireHook());
self::registerBlock(new Tripwire());
self::registerBlock(new Emerald());
self::registerBlock(new SpruceWoodStairs());
self::registerBlock(new BirchWoodStairs());
self::registerBlock(new JungleWoodStairs());
self::registerBlock(new WoodenStairs(Block::SPRUCE_STAIRS, 0, "Spruce Stairs"));
self::registerBlock(new WoodenStairs(Block::BIRCH_STAIRS, 0, "Birch Stairs"));
self::registerBlock(new WoodenStairs(Block::JUNGLE_STAIRS, 0, "Jungle Stairs"));
self::registerBlock(new CobblestoneWall());
self::registerBlock(new FlowerPot());
@ -237,8 +231,8 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new Leaves2());
self::registerBlock(new Wood2());
self::registerBlock(new AcaciaWoodStairs());
self::registerBlock(new DarkOakWoodStairs());
self::registerBlock(new WoodenStairs(Block::ACACIA_STAIRS, 0, "Acacia Stairs"));
self::registerBlock(new WoodenStairs(Block::DARK_OAK_STAIRS, 0, "Dark Oak Stairs"));
self::registerBlock(new IronTrapdoor());
self::registerBlock(new Prismarine());
@ -250,12 +244,17 @@ class Block extends Position implements BlockIds, Metadatable{
self::registerBlock(new PackedIce());
self::registerBlock(new DoublePlant());
self::registerBlock(new FenceGateSpruce());
self::registerBlock(new FenceGateBirch());
self::registerBlock(new FenceGateJungle());
self::registerBlock(new FenceGateDarkOak());
self::registerBlock(new FenceGateAcacia());
self::registerBlock(new FenceGate(Block::SPRUCE_FENCE_GATE, 0, "Spruce Fence Gate"));
self::registerBlock(new FenceGate(Block::BIRCH_FENCE_GATE, 0, "Birch Fence Gate"));
self::registerBlock(new FenceGate(Block::JUNGLE_FENCE_GATE, 0, "Jungle Fence Gate"));
self::registerBlock(new FenceGate(Block::DARK_OAK_FENCE_GATE, 0, "Dark Oak Fence Gate"));
self::registerBlock(new FenceGate(Block::ACACIA_FENCE_GATE, 0, "Acacia Fence Gate"));
self::registerBlock(new WoodenDoor(Block::SPRUCE_DOOR_BLOCK, 0, "Spruce Door Block", Item::SPRUCE_DOOR));
self::registerBlock(new WoodenDoor(Block::BIRCH_DOOR_BLOCK, 0, "Birch Door Block", Item::BIRCH_DOOR));
self::registerBlock(new WoodenDoor(Block::JUNGLE_DOOR_BLOCK, 0, "Jungle Door Block", Item::JUNGLE_DOOR));
self::registerBlock(new WoodenDoor(Block::ACACIA_DOOR_BLOCK, 0, "Acacia Door Block", Item::ACACIA_DOOR));
self::registerBlock(new WoodenDoor(Block::DARK_OAK_DOOR_BLOCK, 0, "Dark Oak Door Block", Item::DARK_OAK_DOOR));
self::registerBlock(new GrassPath());
self::registerBlock(new ItemFrame());
@ -332,13 +331,66 @@ class Block extends Position implements BlockIds, Metadatable{
return $block;
}
protected $id;
protected $meta = 0;
/** @var string */
protected $fallbackName;
/** @var int|null */
protected $itemId;
/** @var AxisAlignedBB */
public $boundingBox = null;
/**
* @param int $id The block type's ID, 0-255
* @param int $meta Meta value of the block type
* @param string $name English name of the block type (TODO: implement translations)
* @param int $itemId The item ID of the block type, used for block picking and dropping items.
*/
public function __construct(int $id, int $meta = 0, string $name = "Unknown", int $itemId = null){
$this->id = $id;
$this->meta = $meta;
$this->fallbackName = $name;
$this->itemId = $itemId;
}
/**
* @return string
*/
public function getName(){
return $this->fallbackName;
}
/**
* @return int
*/
final public function getId(){
return $this->id;
}
/**
* Returns the ID of the item form of the block.
* Used for drops for blocks (some blocks such as doors have a different item ID).
*
* @return int
*/
public function getItemId() : int{
return $this->itemId ?? $this->getId();
}
/**
* @return int
*/
final public function getDamage(){
return $this->meta;
}
/**
* @param int $id
* @param int $meta
*/
public function __construct($id, $meta = 0){
$this->id = (int) $id;
$this->meta = (int) $meta;
final public function setDamage($meta){
$this->meta = $meta & 0x0f;
}
/**
@ -514,38 +566,11 @@ class Block extends Position implements BlockIds, Metadatable{
return false;
}
/**
* @return string
*/
public function getName(){
return "Unknown";
}
/**
* @return int
*/
final public function getId(){
return $this->id;
}
public function addVelocityToEntity(Entity $entity, Vector3 $vector){
}
/**
* @return int
*/
final public function getDamage(){
return $this->meta;
}
/**
* @param int $meta
*/
final public function setDamage($meta){
$this->meta = $meta & 0x0f;
}
/**
* Sets the block position to a new Position object
*
@ -571,7 +596,7 @@ class Block extends Position implements BlockIds, Metadatable{
return [];
}else{
return [
[$this->getId(), $this->getDamage(), 1],
[$this->getItemId(), $this->getDamage(), 1],
];
}
}

View File

@ -89,7 +89,7 @@ interface BlockIds{
const FURNACE = 61;
const BURNING_FURNACE = 62, LIT_FURNACE = 62;
const SIGN_POST = 63, STANDING_SIGN = 63;
const WOODEN_DOOR_BLOCK = 64;
const OAK_DOOR_BLOCK = 64, WOODEN_DOOR_BLOCK = 64;
const LADDER = 65;
const RAIL = 66;
const COBBLESTONE_STAIRS = 67, STONE_STAIRS = 67;

View File

@ -1,33 +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\block;
class DarkOakWoodStairs extends WoodStairs{
protected $id = self::DARK_OAK_STAIRS;
public function getName(){
return "Dark Oak Wood Stairs";
}
}

View File

@ -31,16 +31,6 @@ use pocketmine\Player;
class FenceGate extends Transparent{
protected $id = self::FENCE_GATE;
public function __construct($meta = 0){
$this->meta = $meta;
}
public function getName(){
return "Oak Fence Gate";
}
public function getHardness(){
return 2;
}

View File

@ -1,34 +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\block;
class FenceGateAcacia extends FenceGate{
protected $id = self::ACACIA_FENCE_GATE;
public function getName(){
return "Acacia Fence Gate";
}
}

View File

@ -1,34 +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\block;
class FenceGateBirch extends FenceGate{
protected $id = self::BIRCH_FENCE_GATE;
public function getName(){
return "Birch Fence Gate";
}
}

View File

@ -1,34 +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\block;
class FenceGateDarkOak extends FenceGate{
protected $id = self::DARK_OAK_FENCE_GATE;
public function getName(){
return "Dark Oak Fence Gate";
}
}

View File

@ -1,34 +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\block;
class FenceGateJungle extends FenceGate{
protected $id = self::JUNGLE_FENCE_GATE;
public function getName(){
return "Jungle Fence Gate";
}
}

View File

@ -1,34 +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\block;
class FenceGateSpruce extends FenceGate{
protected $id = self::SPRUCE_FENCE_GATE;
public function getName(){
return "Spruce Fence Gate";
}
}

View File

@ -1,33 +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\block;
class JungleWoodStairs extends WoodStairs{
protected $id = self::JUNGLE_STAIRS;
public function getName(){
return "Jungle Wood Stairs";
}
}

View File

@ -1,33 +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\block;
class SpruceWoodStairs extends WoodStairs{
protected $id = self::SPRUCE_STAIRS;
public function getName(){
return "Spruce Wood Stairs";
}
}

View File

@ -28,16 +28,6 @@ use pocketmine\item\Tool;
class WoodenDoor extends Door{
protected $id = self::WOODEN_DOOR_BLOCK;
public function __construct($meta = 0){
$this->meta = $meta;
}
public function getName(){
return "Wooden Door Block";
}
public function getHardness(){
return 3;
}
@ -48,7 +38,7 @@ class WoodenDoor extends Door{
public function getDrops(Item $item){
return [
[Item::WOODEN_DOOR, 0, 1],
[$this->getItemId(), 0, 1],
];
}
}

View File

@ -26,17 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
class WoodStairs extends Stair{
protected $id = self::OAK_STAIRS;
public function __construct($meta = 0){
$this->meta = $meta;
}
public function getName(){
return "Oak Wood Stairs";
}
class WoodenStairs extends Stair{
public function getHardness(){
return 2;

View File

@ -246,12 +246,6 @@ class Item implements ItemIds, \JsonSerializable{
self::$list[self::BEETROOT_SOUP] = BeetrootSoup::class;
self::$list[self::ENCHANTED_GOLDEN_APPLE] = GoldenAppleEnchanted::class;
for($i = 0; $i < 256; ++$i){
if(Block::$list[$i] !== null){
self::$list[$i] = Block::$list[$i];
}
}
}
self::initCreativeItems();
@ -333,14 +327,16 @@ class Item implements ItemIds, \JsonSerializable{
*/
public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{
try{
if($id < 256){
return (new ItemBlock(Block::get($id, $meta), $meta, $count))->setCompoundTag($tags);
}else{
$class = self::$list[$id];
if($class === null){
return (new Item($id, $meta, $count))->setCompoundTag($tags);
}elseif($id < 256){
return (new ItemBlock(new $class($meta), $meta, $count))->setCompoundTag($tags);
}else{
return (new $class($meta, $count))->setCompoundTag($tags);
}
}
}catch(\RuntimeException $e){
return (new Item($id, $meta, $count))->setCompoundTag($tags);
}