mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
Block breaking part 1
This commit is contained in:
parent
b14d14d3d5
commit
f3c46b12c5
@ -2223,7 +2223,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$oldItem = clone $item;
|
||||
|
||||
if($this->canInteract($vector->add(0.5, 0.5, 0.5), 13) and $this->level->useBreakOn($vector, $item, $this, true)){
|
||||
if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this)){
|
||||
if($this->isSurvival()){
|
||||
if(!$item->equals($oldItem, true) or $item->getCount() !== $oldItem->getCount()){
|
||||
$this->inventory->setItemInHand($item, $this);
|
||||
|
@ -22,6 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class AcaciaWoodStairs extends Stair{
|
||||
|
||||
@ -40,4 +41,16 @@ class AcaciaWoodStairs extends Stair{
|
||||
[$this->id, 0, 1],
|
||||
];
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
}
|
@ -68,4 +68,12 @@ class Air extends Transparent{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -40,7 +40,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 1;
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
|
@ -36,6 +36,10 @@ class Bedrock extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 18000000;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class BirchWoodStairs extends Stair{
|
||||
|
||||
@ -40,4 +41,16 @@ class BirchWoodStairs extends Stair{
|
||||
[$this->id, 0, 1],
|
||||
];
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 15;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ use pocketmine\entity\Squid;
|
||||
use pocketmine\entity\Villager;
|
||||
use pocketmine\entity\Zombie;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\MovingObjectPosition;
|
||||
use pocketmine\level\Position;
|
||||
@ -605,7 +606,14 @@ class Block extends Position implements Metadatable{
|
||||
* @return int
|
||||
*/
|
||||
public function getResistance(){
|
||||
return 1;
|
||||
return $this->getHardness() * 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -747,7 +755,42 @@ class Block extends Position implements Metadatable{
|
||||
* @return float
|
||||
*/
|
||||
public function getBreakTime(Item $item){
|
||||
return 0.20;
|
||||
$base = $this->getHardness() * 1.5;
|
||||
if($this->canBeBrokenWith($item)){
|
||||
if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){
|
||||
$base /= 15;
|
||||
}elseif(
|
||||
($this->getToolType() === Tool::TYPE_PICKAXE and ($tier = $item->isPickaxe()) !== false) or
|
||||
($this->getToolType() === Tool::TYPE_AXE and ($tier = $item->isAxe()) !== false) or
|
||||
($this->getToolType() === Tool::TYPE_SHOVEL and ($tier = $item->isShovel()) !== false)
|
||||
){
|
||||
switch($tier){
|
||||
case Tool::TIER_WOODEN:
|
||||
$base /= 2;
|
||||
break;
|
||||
case Tool::TIER_STONE:
|
||||
$base /= 4;
|
||||
break;
|
||||
case Tool::TIER_IRON:
|
||||
$base /= 6;
|
||||
break;
|
||||
case Tool::TIER_DIAMOND:
|
||||
$base /= 8;
|
||||
break;
|
||||
case Tool::TIER_GOLD:
|
||||
$base /= 12;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$base *= 3.33;
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
|
||||
public function canBeBrokenWith(Item $item){
|
||||
return $this->getHardness() !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +22,8 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class Bookshelf extends Solid{
|
||||
|
||||
protected $id = self::BOOKSHELF;
|
||||
@ -35,7 +37,11 @@ class Bookshelf extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 7.5;
|
||||
return 1.5;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_AXE;
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,8 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class BrickStairs extends Stair{
|
||||
|
||||
protected $id = self::BRICK_STAIRS;
|
||||
@ -30,6 +32,18 @@ class BrickStairs extends Stair{
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Brick Stairs";
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
|
||||
class Bricks extends Solid{
|
||||
|
||||
@ -32,30 +33,21 @@ class Bricks extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return "Bricks";
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
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){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return [
|
||||
|
@ -22,6 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
@ -48,7 +49,11 @@ class BurningFurnace extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 17.5;
|
||||
return 3.5;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
public function getLightLevel(){
|
||||
|
@ -41,7 +41,7 @@ class Cactus extends Transparent{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2;
|
||||
return 0.4;
|
||||
}
|
||||
|
||||
public function hasEntityCollision(){
|
||||
|
@ -22,6 +22,7 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Dirt extends Solid{
|
||||
@ -37,7 +38,11 @@ class Dirt extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 2.5;
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_SHOVEL;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
|
@ -30,7 +30,11 @@ abstract class Flowable extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getBreakTime(Item $item){
|
||||
public function getHardness(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getResistance(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -41,8 +45,4 @@ abstract class Flowable extends Transparent{
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\event\block\BlockSpreadEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Tool;
|
||||
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -47,7 +48,11 @@ class Grass extends Solid{
|
||||
}
|
||||
|
||||
public function getHardness(){
|
||||
return 3;
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
public function getToolType(){
|
||||
return Tool::TYPE_SHOVEL;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -27,10 +27,6 @@ use pocketmine\Player;
|
||||
|
||||
abstract class Stair extends Transparent{
|
||||
|
||||
public function getHardness(){
|
||||
return 30;
|
||||
}
|
||||
|
||||
/*
|
||||
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
|
||||
$damage = $this->getDamage();
|
||||
|
@ -32,6 +32,13 @@ abstract class Tool extends Item{
|
||||
const TIER_IRON = 4;
|
||||
const TIER_DIAMOND = 5;
|
||||
|
||||
const TYPE_NONE = 0;
|
||||
const TYPE_SWORD = 1;
|
||||
const TYPE_SHOVEL = 2;
|
||||
const TYPE_PICKAXE = 3;
|
||||
const TYPE_AXE = 4;
|
||||
const TYPE_SHEARS = 5;
|
||||
|
||||
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $count, $name);
|
||||
}
|
||||
|
@ -1513,10 +1513,16 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
|
||||
if($player->hasEffect(Effect::SWIFTNESS)){
|
||||
$breakTime *= 0.80 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
|
||||
$breakTime *= 1 - (0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1));
|
||||
}
|
||||
|
||||
if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) >= microtime(true)){
|
||||
if($player->hasEffect(Effect::MINING_FATIGUE)){
|
||||
$breakTime *= 1 + (0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1));
|
||||
}
|
||||
|
||||
$breakTime -= 0.05; //1 tick compensation
|
||||
|
||||
if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) > microtime(true)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1532,7 +1538,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$drops[$k] = Item::get($i[0], $i[1], $i[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
|
||||
if($above !== null){
|
||||
if($above->getId() === Item::FIRE){
|
||||
|
Loading…
x
Reference in New Issue
Block a user