Removed Generic block class

This commit is contained in:
Shoghi Cervantes 2014-10-13 18:12:34 +02:00
parent da23cf685d
commit a10ad42a13
4 changed files with 67 additions and 105 deletions

View File

@ -39,7 +39,7 @@ use pocketmine\Player;
use pocketmine\plugin\Plugin;
abstract class Block extends Position implements Metadatable{
class Block extends Position implements Metadatable{
const AIR = 0;
const STONE = 1;
const GRASS = 2;
@ -684,7 +684,7 @@ abstract class Block extends Position implements Metadatable{
$block = self::$list[$id];
$block = new $block($meta);
}else{
$block = new Generic($id, $meta);
$block = new Block($id, $meta);
}
if($pos instanceof Position){
@ -708,6 +708,69 @@ abstract class Block extends Position implements Metadatable{
$this->name = $name;
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
* @param Player $player = null
*
* @return bool
*/
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
return $this->getLevel()->setBlock($this, $this, true, true);
}
/**
* Returns if the item can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
public function isBreakable(Item $item){
return $this->breakable;
}
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item $item
*
* @return mixed
*/
public function onBreak(Item $item){
return $this->getLevel()->setBlock($this, new Air(), true, true);
}
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
public function onUpdate($type){
}
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item $item
* @param Player $player
*
* @return bool
*/
public function onActivate(Item $item, Player $player = null){
return $this->isActivable;
}
/**
* @return int
*/
@ -811,24 +874,6 @@ abstract class Block extends Position implements Metadatable{
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
}
/**
* Returns if the item can be broken with an specific Item
*
* @param Item $item
*
* @return bool
*/
abstract function isBreakable(Item $item);
/**
* Do the actions needed so the block is broken with the Item
*
* @param Item $item
*
* @return mixed
*/
abstract function onBreak(Item $item);
/**
* Checks for collision against an AxisAlignedBB
*
@ -945,41 +990,6 @@ abstract class Block extends Position implements Metadatable{
return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
}
/**
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
*
* @param Item $item
* @param Block $block
* @param Block $target
* @param int $face
* @param float $fx
* @param float $fy
* @param float $fz
* @param Player $player = null
*
* @return bool
*/
abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null);
/**
* Do actions when activated by Item. Returns if it has done anything
*
* @param Item $item
* @param Player $player
*
* @return bool
*/
abstract function onActivate(Item $item, Player $player = null);
/**
* Fires a block update on the Block
*
* @param int $type
*
* @return void
*/
abstract function onUpdate($type);
public function setMetadata($metadataKey, MetadataValue $metadataValue){
if($this->getLevel() instanceof Level){
$this->getLevel()->getBlockMetadata()->setMetadata($this, $metadataKey, $metadataValue);

View File

@ -1,48 +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/
*
*
*/
namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\Player;
class Generic extends Block{
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
return $this->getLevel()->setBlock($this, $this, true, true);
}
public function isBreakable(Item $item){
return $this->breakable;
}
public function onBreak(Item $item){
return $this->getLevel()->setBlock($this, new Air(), true, true);
}
public function onUpdate($type){
return false;
}
public function onActivate(Item $item, Player $player = null){
return $this->isActivable;
}
}

View File

@ -22,7 +22,7 @@
namespace pocketmine\block;
abstract class Solid extends Generic{
abstract class Solid extends Block{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);

View File

@ -23,7 +23,7 @@ namespace pocketmine\block;
abstract class Transparent extends Generic{
abstract class Transparent extends Block{
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;