Fixed #270 Blocks that need to be broken with a pickaxe now give correct drops & items

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-20 16:33:09 +02:00
parent 713f16771f
commit 47b54cfd28
30 changed files with 636 additions and 31 deletions

View File

@ -266,13 +266,12 @@ class BlockAPI{
return $this->cancelAction($target, $player); return $this->cancelAction($target, $player);
} }
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or ($player->lastBreak + $target->getBreakTime($item, $player)) >= microtime(true)){ if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - 0.02) + $target->getBreakTime($item, $player)) >= microtime(true)){
return $this->cancelAction($target, $player); return $this->cancelAction($target, $player);
} }
$player->lastBreak = microtime(true);
if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){ if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){
$player->lastBreak = microtime(true);
$drops = $target->getDrops($item, $player); $drops = $target->getDrops($item, $player);
$target->onBreak($item, $player); $target->onBreak($item, $player);
}else{ }else{

View File

@ -188,7 +188,7 @@ abstract class Block extends Position{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.25; return 0.20;
} }
return $this->breakTime; return $this->breakTime;
} }

View File

@ -108,15 +108,15 @@ class Item{
final public function isPickaxe(){ //Returns false or level of the pickaxe final public function isPickaxe(){ //Returns false or level of the pickaxe
switch($this->id){ switch($this->id){
case IRON_PICKAXE: case IRON_PICKAXE:
return 3; return 4;
case WOODEN_PICKAXE: case WOODEN_PICKAXE:
return 1; return 1;
case STONE_PICKAXE: case STONE_PICKAXE:
return 2;
case DIAMOND_PICKAXE:
return 4;
case GOLD_PICKAXE:
return 3; return 3;
case DIAMOND_PICKAXE:
return 5;
case GOLD_PICKAXE:
return 2;
default: default:
return false; return false;
} }

View File

@ -46,8 +46,12 @@ class StairBlock extends TransparentBlock{
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( if($item->isPickaxe() >= 1){
array($this->id, 0, 1), return array(
); array($this->id, 0, 1),
);
}else{
return array();
}
} }
} }

View File

@ -30,10 +30,30 @@ class CoalOreBlock extends SolidBlock{
parent::__construct(COAL_ORE, 0, "Coal Ore"); parent::__construct(COAL_ORE, 0, "Coal Ore");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
case 2:
return 0.4;
case 1:
return 2.25;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){ if($item->isPickaxe() >= 1){
return array( return array(
array(263, 0, 1), //Coal array(COAL, 0, 1),
); );
}else{ }else{
return array(); return array();

View File

@ -30,13 +30,27 @@ class DiamondOreBlock extends SolidBlock{
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore"); parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 3){ if($item->isPickaxe() >= 4){
return array( return array(
array(264, 0, 1), array(DIAMOND, 0, 1),
); );
}else{ }else{
return array(); return array();
} }
} }
} }

View File

@ -40,8 +40,23 @@ class GlowingRedstoneOreBlock extends SolidBlock{
return false; return false;
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 2){ if($item->isPickaxe() >= 4){
return array( return array(
//array(331, 4, mt_rand(4, 5)), //array(331, 4, mt_rand(4, 5)),
); );

View File

@ -29,5 +29,28 @@ class GoldOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(GOLD_ORE, 0, "Gold Ore"); parent::__construct(GOLD_ORE, 0, "Gold Ore");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_ORE, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -29,5 +29,30 @@ class IronOreBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(IRON_ORE, 0, "Iron Ore"); parent::__construct(IRON_ORE, 0, "Iron Ore");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_ORE, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -30,10 +30,26 @@ class LapisOreBlock extends SolidBlock{
parent::__construct(LAPIS_ORE, 0, "Lapis Ore"); parent::__construct(LAPIS_ORE, 0, "Lapis Ore");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 2){ if($item->isPickaxe() >= 3){
return array( return array(
array(351, 4, mt_rand(4, 8)), array(DYE, 4, mt_rand(4, 8)),
); );
}else{ }else{
return array(); return array();

View File

@ -29,5 +29,34 @@ class BricksBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(BRICKS_BLOCK, 0, "Bricks"); parent::__construct(BRICKS_BLOCK, 0, "Bricks");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(BRICKS_BLOCK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -110,6 +110,26 @@ class BurningFurnaceBlock extends SolidBlock{
return true; return true;
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){ if($item->isPickaxe() >= 1){
return array( return array(

View File

@ -29,5 +29,34 @@ class CobblestoneBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(COBBLESTONE, 0, "Cobblestone"); parent::__construct(COBBLESTONE, 0, "Cobblestone");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -30,4 +30,27 @@ class DiamondBlock extends SolidBlock{
parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block"); parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.95;
case 4:
return 1.25;
default:
return 25;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(DIAMOND_BLOCK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -40,10 +40,35 @@ class DoubleSlabBlock extends SolidBlock{
); );
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; $this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( if($item->isPickaxe() >= 1){
array(SLAB, $this->meta & 0x07, 2), return array(
); array(SLAB, $this->meta & 0x07, 2),
);
}else{
return array();
}
} }
} }

View File

@ -37,5 +37,4 @@ class FurnaceBlock extends BurningFurnaceBlock{
$this->name = "Furnace"; $this->name = "Furnace";
$this->isActivable = true; $this->isActivable = true;
} }
} }

View File

@ -29,5 +29,28 @@ class GoldBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(GOLD_BLOCK, 0, "Gold Block"); parent::__construct(GOLD_BLOCK, 0, "Gold Block");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_BLOCK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -30,4 +30,27 @@ class IceBlock extends TransparentBlock{
parent::__construct(ICE, 0, "Ice"); parent::__construct(ICE, 0, "Ice");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.1;
case 4:
return 0.15;
case 3:
return 0.2;
case 2:
return 0.1;
case 1:
return 0.4;
default:
return 0.75;
}
}
public function getDrops(Item $item, Player $player){
return array();
}
} }

View File

@ -29,5 +29,30 @@ class IronBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(IRON_BLOCK, 0, "Iron Block"); parent::__construct(IRON_BLOCK, 0, "Iron Block");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
default:
return 25;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_BLOCK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -30,9 +30,34 @@ class IronDoorBlock extends DoorBlock{
parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block"); parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block");
//$this->isActivable = true; //$this->isActivable = true;
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( if($item->isPickaxe() >= 1){
array(IRON_DOOR, 0, 1), return array(
); array(IRON_DOOR, 0, 1),
} );
}else{
return array();
}
}
} }

View File

@ -29,5 +29,31 @@ class LapisBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(LAPIS_BLOCK, 0, "Lapis Block"); parent::__construct(LAPIS_BLOCK, 0, "Lapis Block");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 3){
return array(
array(LAPIS_BLOCK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -29,5 +29,34 @@ class MossStoneBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(MOSS_STONE, 0, "Moss Stone"); parent::__construct(MOSS_STONE, 0, "Moss Stone");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(MOSS_STONE, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -29,5 +29,34 @@ class NetherBricksBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(NETHER_BRICKS, 0, "Nether Bricks"); parent::__construct(NETHER_BRICKS, 0, "Nether Bricks");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHER_BRICKS, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -30,4 +30,33 @@ class NetherrackBlock extends SolidBlock{
parent::__construct(NETHERRACK, 0, "Netherrack"); parent::__construct(NETHERRACK, 0, "Netherrack");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.1;
case 4:
return 0.1;
case 3:
return 0.15;
case 2:
return 0.05;
case 1:
return 0.3;
default:
return 2;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHERRACK, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -28,6 +28,27 @@ the Free Software Foundation, either version 3 of the License, or
class ObsidianBlock extends SolidBlock{ class ObsidianBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(OBSIDIAN, 0, "Obsidian"); parent::__construct(OBSIDIAN, 0, "Obsidian");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
if($item->isPickaxe() >= 5){
return 9.4;
}else{
return 250;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 5){
return array(
array(OBSIDIAN, 0, 1),
);
}else{
return array();
}
}
} }

View File

@ -36,5 +36,34 @@ class QuartzBlock extends SolidBlock{
); );
$this->name = $names[$this->meta & 0x03]; $this->name = $names[$this->meta & 0x03];
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(QUARTZ_BLOCK, $this->meta & 0x03, 1),
);
}else{
return array();
}
}
} }

View File

@ -36,4 +36,34 @@ class SandstoneBlock extends SolidBlock{
$this->name = $names[$this->meta & 0x03]; $this->name = $names[$this->meta & 0x03];
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(SANDSTONE, $this->meta & 0x03, 1),
);
}else{
return array();
}
}
} }

View File

@ -76,9 +76,34 @@ class SlabBlock extends TransparentBlock{
$this->level->setBlock($block, $this); $this->level->setBlock($block, $this);
return true; return true;
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
return array( if($item->isPickaxe() >= 1){
array($this->id, $this->meta & 0x07, 1), return array(
); array($this->id, $this->meta & 0x07, 1),
} );
}else{
return array();
}
}
} }

View File

@ -29,6 +29,26 @@ class StoneBlock extends SolidBlock{
public function __construct(){ public function __construct(){
parent::__construct(STONE, 0, "Stone"); parent::__construct(STONE, 0, "Stone");
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){ if($item->isPickaxe() >= 1){

View File

@ -36,5 +36,35 @@ class StoneBricksBlock extends SolidBlock{
); );
$this->name = $names[$this->meta & 0x03]; $this->name = $names[$this->meta & 0x03];
} }
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isPickaxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe() >= 1){
return array(
array(STONE_BRICKS, $this->meta & 0x03, 1),
);
}else{
return array();
}
}
} }