Merge changes from master

This commit is contained in:
Dylan K. Taylor 2017-08-22 14:13:31 +01:00
commit 445a67954d
131 changed files with 690 additions and 505 deletions

View File

@ -1,5 +1,9 @@
### Issue description ### Issue description
<!--- use our forum https://forums.pmmp.io for questions --> <!---
THIS ISSUE TRACKER IS FOR BUG REPORTING, NOT FOR HELP & SUPPORT. If you need help, use the links below.
- http://pmmp.readthedocs.io/en/rtfd/ - Documentation
- https://forums.pmmp.io - PMMP Forums
-->
<!--- Any issues requesting updates to new versions of MCPE will be treated as spam. We do not need issues to tell us that there is a new version available. --> <!--- Any issues requesting updates to new versions of MCPE will be treated as spam. We do not need issues to tell us that there is a new version available. -->
<!--- <!---
Write a short description about the issue Write a short description about the issue

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine; namespace pocketmine;
use pocketmine\block\Air;
use pocketmine\block\Bed; use pocketmine\block\Bed;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\BlockFactory; use pocketmine\block\BlockFactory;
@ -84,6 +83,7 @@ use pocketmine\inventory\ShapedRecipe;
use pocketmine\inventory\ShapelessRecipe; use pocketmine\inventory\ShapelessRecipe;
use pocketmine\inventory\transaction\SimpleInventoryTransaction; use pocketmine\inventory\transaction\SimpleInventoryTransaction;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\ChunkLoader; use pocketmine\level\ChunkLoader;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\Level; use pocketmine\level\Level;
@ -1425,7 +1425,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
if($entity instanceof Arrow and $entity->hadCollision){ if($entity instanceof Arrow and $entity->hadCollision){
$item = Item::get(Item::ARROW, 0, 1); $item = ItemFactory::get(Item::ARROW, 0, 1);
if($this->isSurvival() and !$this->inventory->canAddItem($item)){ if($this->isSurvival() and !$this->inventory->canAddItem($item)){
continue; continue;
} }
@ -2314,7 +2314,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$snowball->setMotion($snowball->getMotion()->multiply($f)); $snowball->setMotion($snowball->getMotion()->multiply($f));
if($this->isSurvival()){ if($this->isSurvival()){
$item->setCount($item->getCount() - 1); $item->setCount($item->getCount() - 1);
$this->inventory->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); $this->inventory->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR));
} }
if($snowball instanceof Projectile){ if($snowball instanceof Projectile){
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball)); $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball));
@ -2439,7 +2439,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$ev->setCancelled(); $ev->setCancelled();
} }
$target->attack($ev->getFinalDamage(), $ev); $target->attack($ev);
if($ev->isCancelled()){ if($ev->isCancelled()){
if($item->isTool() and $this->isSurvival()){ if($item->isTool() and $this->isSurvival()){
@ -2451,7 +2451,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->isSurvival()){ if($this->isSurvival()){
if($item->isTool()){ if($item->isTool()){
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1));
}else{ }else{
$this->inventory->setItemInHand($item); $this->inventory->setItemInHand($item);
} }
@ -2473,7 +2473,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){ if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){
if($this->inventory->getItemInHand()->getId() === Item::BOW){ if($this->inventory->getItemInHand()->getId() === Item::BOW){
$bow = $this->inventory->getItemInHand(); $bow = $this->inventory->getItemInHand();
if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ if($this->isSurvival() and !$this->inventory->contains(ItemFactory::get(Item::ARROW, 0, 1))){
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
return false; return false;
} }
@ -2514,10 +2514,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}else{ }else{
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if($this->isSurvival()){ if($this->isSurvival()){
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); $this->inventory->removeItem(ItemFactory::get(Item::ARROW, 0, 1));
$bow->setDamage($bow->getDamage() + 1); $bow->setDamage($bow->getDamage() + 1);
if($bow->getDamage() >= 385){ if($bow->getDamage() >= 385){
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 0));
}else{ }else{
$this->inventory->setItemInHand($bow); $this->inventory->setItemInHand($bow);
} }
@ -2574,7 +2574,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$slot = $this->inventory->getItemInHand(); $slot = $this->inventory->getItemInHand();
--$slot->count; --$slot->count;
$this->inventory->setItemInHand($slot); $this->inventory->setItemInHand($slot);
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 1)); $this->inventory->addItem(ItemFactory::get(Item::BUCKET, 0, 1));
} }
$this->removeAllEffects(); $this->removeAllEffects();
@ -3016,7 +3016,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$newItem = clone $item; $newItem = clone $item;
$newItem->setCount($item->getCount() - $count); $newItem->setCount($item->getCount() - $count);
}else{ }else{
$newItem = Item::get(Item::AIR, 0, 0); $newItem = ItemFactory::get(Item::AIR, 0, 0);
} }
$this->inventory->setItem($slot, $newItem); $this->inventory->setItem($slot, $newItem);
@ -3048,7 +3048,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
case Item::CAKE: case Item::CAKE:
//TODO: detect complex recipes like cake that leave remains //TODO: detect complex recipes like cake that leave remains
$this->awardAchievement("bakeCake"); $this->awardAchievement("bakeCake");
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 3)); $this->inventory->addItem(ItemFactory::get(Item::BUCKET, 0, 3));
break; break;
case Item::STONE_PICKAXE: case Item::STONE_PICKAXE:
case Item::GOLDEN_PICKAXE: case Item::GOLDEN_PICKAXE:
@ -3734,7 +3734,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if(!$this->isAlive()){ if(!$this->isAlive()){
return; return;
} }
@ -3749,7 +3749,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$source->setCancelled(); $source->setCancelled();
} }
parent::attack($damage, $source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;

View File

@ -49,7 +49,7 @@ use pocketmine\event\TranslationContainer;
use pocketmine\inventory\CraftingManager; use pocketmine\inventory\CraftingManager;
use pocketmine\inventory\Recipe; use pocketmine\inventory\Recipe;
use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item; use pocketmine\item\ItemFactory;
use pocketmine\lang\BaseLang; use pocketmine\lang\BaseLang;
use pocketmine\level\format\io\leveldb\LevelDB; use pocketmine\level\format\io\leveldb\LevelDB;
use pocketmine\level\format\io\LevelProvider; use pocketmine\level\format\io\LevelProvider;
@ -1584,7 +1584,7 @@ class Server{
Tile::init(); Tile::init();
BlockFactory::init(); BlockFactory::init();
Enchantment::init(); Enchantment::init();
Item::init(); ItemFactory::init();
Biome::init(); Biome::init();
Effect::init(); Effect::init();
Attribute::init(); Attribute::init();

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\inventory\AnvilInventory; use pocketmine\inventory\AnvilInventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -83,7 +84,7 @@ class Anvil extends Fallable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return [
Item::get($this->getItemId(), $this->getDamage() & 0x0c, 1), ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1),
]; ];
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -205,10 +206,10 @@ class Bed extends Transparent{
return false; return false;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
if(($other = $this->getOtherHalf()) !== null){ if(($other = $this->getOtherHalf()) !== null){
$this->getLevel()->useBreakOn($other); //make sure tiles get removed $this->getLevel()->useBreakOn($other, $item, $player, $player !== null); //make sure tiles get removed
} }
return true; return true;
@ -219,11 +220,11 @@ class Bed extends Transparent{
$tile = $this->getLevel()->getTile($this); $tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){ if($tile instanceof TileBed){
return [ return [
Item::get($this->getItemId(), $tile->getColor(), 1) ItemFactory::get($this->getItemId(), $tile->getColor(), 1)
]; ];
}else{ }else{
return [ return [
Item::get($this->getItemId(), 14, 1) //Red ItemFactory::get($this->getItemId(), 14, 1) //Red
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class Beetroot extends Crops{ class Beetroot extends Crops{
@ -40,13 +41,13 @@ class Beetroot extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($this->meta >= 0x07){ if($this->meta >= 0x07){
return [ return [
Item::get(Item::BEETROOT, 0, 1), ItemFactory::get(Item::BEETROOT, 0, 1),
Item::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3)) ItemFactory::get(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3))
]; ];
} }
return [ return [
Item::get(Item::BEETROOT_SEEDS, 0, 1) ItemFactory::get(Item::BEETROOT_SEEDS, 0, 1)
]; ];
} }
} }

View File

@ -28,6 +28,7 @@ namespace pocketmine\block;
use pocketmine\entity\Entity; use pocketmine\entity\Entity;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition; use pocketmine\level\MovingObjectPosition;
@ -42,7 +43,9 @@ use pocketmine\plugin\Plugin;
class Block extends Position implements BlockIds, Metadatable{ class Block extends Position implements BlockIds, Metadatable{
/** /**
* @deprecated This functionality has moved to {@link BlockFactory#get} * Returns a new Block instance with the specified ID, meta and position.
*
* This function redirects to {@link BlockFactory#get}.
* *
* @param int $id * @param int $id
* @param int $meta * @param int $meta
@ -160,11 +163,12 @@ class Block extends Position implements BlockIds, Metadatable{
/** /**
* Do the actions needed so the block is broken with the Item * Do the actions needed so the block is broken with the Item
* *
* @param Item $item * @param Item $item
* @param Player|null $player
* *
* @return bool * @return bool
*/ */
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
} }
@ -338,7 +342,7 @@ class Block extends Position implements BlockIds, Metadatable{
*/ */
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1), ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1),
]; ];
} }

View File

@ -360,6 +360,8 @@ class BlockFactory{
} }
/** /**
* Returns a new Block instance with the specified ID, meta and position.
*
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param Position $pos * @param Position $pos

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Bookshelf extends Solid{ class Bookshelf extends Solid{
@ -48,7 +49,7 @@ class Bookshelf extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::BOOK, 0, 3) ItemFactory::get(Item::BOOK, 0, 3)
]; ];
} }

View File

@ -67,8 +67,4 @@ class BrownMushroom extends Flowable{
return false; return false;
} }
protected function recalculateBoundingBox(){
return null;
}
} }

View File

@ -68,7 +68,7 @@ class Cactus extends Transparent{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
public function onUpdate(int $type){ public function onUpdate(int $type){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class Carrot extends Crops{ class Carrot extends Crops{
@ -39,7 +40,7 @@ class Carrot extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1) ItemFactory::get(Item::CARROT, 0, $this->meta >= 0x07 ? mt_rand(1, 4) : 1)
]; ];
} }
} }

View File

@ -124,7 +124,7 @@ class Chest extends Transparent{
return true; return true;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
$t = $this->getLevel()->getTile($this); $t = $this->getLevel()->getTile($this);
if($t instanceof TileChest){ if($t instanceof TileChest){
$t->unpair(); $t->unpair();

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Clay extends Solid{ class Clay extends Solid{
@ -48,7 +49,7 @@ class Clay extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::CLAY_BALL, 0, 4) ItemFactory::get(Item::CLAY_BALL, 0, 4)
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class CoalOre extends Solid{ class CoalOre extends Solid{
@ -49,7 +50,7 @@ class CoalOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return [
Item::get(Item::COAL, 0, 1) ItemFactory::get(Item::COAL, 0, 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class DiamondOre extends Solid{ class DiamondOre extends Solid{
@ -49,7 +50,7 @@ class DiamondOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){ if($item->isPickaxe() >= Tool::TIER_IRON){
return [ return [
Item::get(Item::DIAMOND, 0, 1) ItemFactory::get(Item::DIAMOND, 0, 1)
]; ];
} }

View File

@ -246,7 +246,7 @@ abstract class Door extends Transparent{
return false; return false;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
if(($this->getDamage() & 0x08) === 0x08){ if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === $this->getId()){ if($down->getId() === $this->getId()){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -96,9 +97,9 @@ class DoublePlant extends Flowable{
return false; return false;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
if(parent::onBreak($item) and $this->isValidHalfPlant()){ if(parent::onBreak($item, $player) and $this->isValidHalfPlant()){
return $this->getLevel()->setBlock($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), BlockFactory::get(Block::AIR)); $this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null);
} }
return false; return false;
@ -109,16 +110,20 @@ class DoublePlant extends Flowable{
} }
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern if($this->meta & self::BITFLAG_TOP){
if(mt_rand(0, 24) === 0){ if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
return [ if(mt_rand(0, 24) === 0){
Item::get(Item::SEEDS, 0, 1) return [
]; ItemFactory::get(Item::SEEDS, 0, 1)
];
}
return [];
} }
return []; return parent::getDrops($item);
} }
return parent::getDrops($item); return [];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class DoubleStoneSlab extends Solid{ class DoubleStoneSlab extends Solid{
@ -59,7 +60,7 @@ class DoubleStoneSlab extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return [
Item::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2), ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2),
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class DoubleWoodenSlab extends Solid{ class DoubleWoodenSlab extends Solid{
@ -56,7 +57,7 @@ class DoubleWoodenSlab extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2) ItemFactory::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class EmeraldOre extends Solid{ class EmeraldOre extends Solid{
@ -49,7 +50,7 @@ class EmeraldOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){ if($item->isPickaxe() >= Tool::TIER_IRON){
return [ return [
Item::get(Item::EMERALD, 0, 1), ItemFactory::get(Item::EMERALD, 0, 1),
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
@ -60,7 +61,7 @@ class Farmland extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::DIRT, 0, 1) ItemFactory::get(Item::DIRT, 0, 1)
]; ];
} }
} }

View File

@ -63,7 +63,7 @@ class Fire extends Flowable{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 8); $ev = new EntityCombustByBlockEvent($this, $entity, 8);
if($entity instanceof Arrow){ if($entity instanceof Arrow){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -116,7 +117,7 @@ class FlowerPot extends Flowable{
if($player instanceof Player){ if($player instanceof Player){
if($player->isSurvival()){ if($player->isSurvival()){
$item->setCount($item->getCount() - 1); $item->setCount($item->getCount() - 1);
$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); $player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR));
} }
} }
return true; return true;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Glowstone extends Transparent{ class Glowstone extends Transparent{
@ -52,7 +53,7 @@ class Glowstone extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)) ItemFactory::get(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4))
]; ];
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent; use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\level\generator\object\TallGrass as TallGrassObject;
use pocketmine\level\Level; use pocketmine\level\Level;
@ -54,7 +55,7 @@ class Grass extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::DIRT, 0, 1), ItemFactory::get(Item::DIRT, 0, 1),
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
@ -60,7 +61,7 @@ class GrassPath extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::DIRT, 0, 1) ItemFactory::get(Item::DIRT, 0, 1)
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Gravel extends Fallable{ class Gravel extends Fallable{
@ -49,7 +50,7 @@ class Gravel extends Fallable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if(mt_rand(1, 10) === 1){ if(mt_rand(1, 10) === 1){
return [ return [
Item::get(Item::FLINT, 0, 1) ItemFactory::get(Item::FLINT, 0, 1)
]; ];
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\Player;
class Ice extends Transparent{ class Ice extends Transparent{
@ -51,7 +52,7 @@ class Ice extends Transparent{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
$this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
return true; return true;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\{ use pocketmine\nbt\tag\{
@ -69,7 +70,7 @@ class ItemFrame extends Flowable{
$item->setCount($item->getCount() - 1); $item->setCount($item->getCount() - 1);
$tile->setItem($frameItem); $tile->setItem($frameItem);
if($player instanceof Player and $player->isSurvival()){ if($player instanceof Player and $player->isSurvival()){
$player->getInventory()->setItemInHand($item->getCount() <= 0 ? Item::get(Item::AIR) : $item); $player->getInventory()->setItemInHand($item->getCount() <= 0 ? ItemFactory::get(Item::AIR) : $item);
} }
} }
} }
@ -77,7 +78,7 @@ class ItemFrame extends Flowable{
return true; return true;
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item, Player $player = null) : bool{
$tile = $this->level->getTile($this); $tile = $this->level->getTile($this);
if($tile instanceof TileItemFrame){ if($tile instanceof TileItemFrame){
//TODO: add events //TODO: add events
@ -85,7 +86,7 @@ class ItemFrame extends Flowable{
$this->level->dropItem($tile->getBlock(), $tile->getItem()); $this->level->dropItem($tile->getBlock(), $tile->getItem());
} }
} }
return parent::onBreak($item); return parent::onBreak($item, $player);
} }
public function onUpdate(int $type){ public function onUpdate(int $type){

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class LapisOre extends Solid{ class LapisOre extends Solid{
@ -49,7 +50,7 @@ class LapisOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_STONE){ if($item->isPickaxe() >= Tool::TIER_STONE){
return [ return [
Item::get(Item::DYE, 4, mt_rand(4, 8)) ItemFactory::get(Item::DYE, 4, mt_rand(4, 8))
]; ];
} }

View File

@ -52,7 +52,7 @@ class Lava extends Liquid{
$entity->fallDistance *= 0.5; $entity->fallDistance *= 0.5;
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 15); $ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev); Server::getInstance()->getPluginManager()->callEvent($ev);

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\LeavesDecayEvent; use pocketmine\event\block\LeavesDecayEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -170,13 +171,13 @@ class Leaves extends Transparent{
$variantMeta = $this->getDamage() & 0x03; $variantMeta = $this->getDamage() & 0x03;
if($item->isShears()){ if($item->isShears()){
$drops[] = Item::get($this->getItemId(), $variantMeta, 1); $drops[] = ItemFactory::get($this->getItemId(), $variantMeta, 1);
}else{ }else{
if(mt_rand(1, 20) === 1){ //Saplings if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = Item::get(Item::SAPLING, $variantMeta, 1); $drops[] = ItemFactory::get(Item::SAPLING, $variantMeta, 1);
} }
if($variantMeta === self::OAK and mt_rand(1, 200) === 1){ //Apples if($variantMeta === self::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = Item::get(Item::APPLE, 0, 1); $drops[] = ItemFactory::get(Item::APPLE, 0, 1);
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class Leaves2 extends Leaves{ class Leaves2 extends Leaves{
@ -43,11 +44,11 @@ class Leaves2 extends Leaves{
if($item->isShears()){ if($item->isShears()){
return [ return [
Item::get($this->getItemId(), $variantMeta, 1) ItemFactory::get($this->getItemId(), $variantMeta, 1)
]; ];
}elseif(mt_rand(1, 20) === 1){ //Saplings }elseif(mt_rand(1, 20) === 1){ //Saplings
return [ return [
Item::get(Item::SAPLING, $variantMeta + 4, 1) ItemFactory::get(Item::SAPLING, $variantMeta + 4, 1)
]; ];
} }

View File

@ -60,7 +60,7 @@ class Magma extends Solid{
public function onEntityCollide(Entity $entity){ public function onEntityCollide(Entity $entity){
if(!$entity->isSneaking()){ if(!$entity->isSneaking()){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Melon extends Transparent{ class Melon extends Transparent{
@ -48,7 +49,7 @@ class Melon extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::MELON_SLICE, 0, mt_rand(3, 7)) ItemFactory::get(Item::MELON_SLICE, 0, mt_rand(3, 7))
]; ];
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server; use pocketmine\Server;
@ -84,7 +85,7 @@ class MelonStem extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::MELON_SEEDS, 0, mt_rand(0, 2)) ItemFactory::get(Item::MELON_SEEDS, 0, mt_rand(0, 2))
]; ];
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockSpreadEvent; use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -52,7 +53,7 @@ class Mycelium extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::DIRT, 0, 1) ItemFactory::get(Item::DIRT, 0, 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class NetherQuartzOre extends Solid{ class NetherQuartzOre extends Solid{
@ -49,7 +50,7 @@ class NetherQuartzOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return [
Item::get(Item::QUARTZ, 0, 1) ItemFactory::get(Item::QUARTZ, 0, 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class NetherReactor extends Solid{ class NetherReactor extends Solid{
@ -53,8 +54,8 @@ class NetherReactor extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return [
Item::get(Item::IRON_INGOT, 0, 6), ItemFactory::get(Item::IRON_INGOT, 0, 6),
Item::get(Item::DIAMOND, 0, 3) ItemFactory::get(Item::DIAMOND, 0, 3)
]; ];
} }

View File

@ -26,6 +26,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -78,7 +79,7 @@ class NetherWartPlant extends Flowable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1)) ItemFactory::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1))
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class Potato extends Crops{ class Potato extends Crops{
@ -39,7 +40,7 @@ class Potato extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1) ItemFactory::get(Item::POTATO, 0, $this->getDamage() >= 0x07 ? mt_rand(1, 4) : 1)
]; ];
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\block\BlockGrowEvent;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Server; use pocketmine\Server;
@ -84,7 +85,7 @@ class PumpkinStem extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)) ItemFactory::get(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2))
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -66,7 +67,7 @@ class RedstoneOre extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_IRON){ if($item->isPickaxe() >= Tool::TIER_IRON){
return [ return [
Item::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5)) ItemFactory::get(Item::REDSTONE_DUST, 0, mt_rand(4, 5))
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\generator\object\Tree; use pocketmine\level\generator\object\Tree;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -109,7 +110,7 @@ class Sapling extends Flowable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get($this->getItemId(), $this->getDamage() & 0x07, 1) ItemFactory::get($this->getItemId(), $this->getDamage() & 0x07, 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class SeaLantern extends Transparent{ class SeaLantern extends Transparent{
@ -47,7 +48,7 @@ class SeaLantern extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get(Item::PRISMARINE_CRYSTALS, 0, 3) ItemFactory::get(Item::PRISMARINE_CRYSTALS, 0, 3)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
@ -94,7 +95,7 @@ class Skull extends Flowable{
$tile = $this->level->getTile($this); $tile = $this->level->getTile($this);
if($tile instanceof SkullTile){ if($tile instanceof SkullTile){
return [ return [
Item::get(Item::SKULL, $tile->getType(), 1) ItemFactory::get(Item::SKULL, $tile->getType(), 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -86,7 +87,7 @@ class SnowLayer extends Flowable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isShovel() !== false){ if($item->isShovel() !== false){
return [ return [
Item::get(Item::SNOWBALL, 0, 1) //TODO: check layer count ItemFactory::get(Item::SNOWBALL, 0, 1) //TODO: check layer count
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class Stone extends Solid{ class Stone extends Solid{
@ -66,7 +67,7 @@ class Stone extends Solid{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
if($this->getDamage() === self::NORMAL){ if($this->getDamage() === self::NORMAL){
return [ return [
Item::get(Item::COBBLESTONE, $this->getDamage(), 1) ItemFactory::get(Item::COBBLESTONE, $this->getDamage(), 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -76,7 +77,7 @@ class TallGrass extends Flowable{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if(mt_rand(0, 15) === 0){ if(mt_rand(0, 15) === 0){
return [ return [
Item::get(Item::WHEAT_SEEDS, 0, 1) ItemFactory::get(Item::WHEAT_SEEDS, 0, 1)
]; ];
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
class Wheat extends Crops{ class Wheat extends Crops{
@ -40,12 +41,12 @@ class Wheat extends Crops{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($this->meta >= 0x07){ if($this->meta >= 0x07){
return [ return [
Item::get(Item::WHEAT, 0, 1), ItemFactory::get(Item::WHEAT, 0, 1),
Item::get(Item::WHEAT_SEEDS, 0, mt_rand(0, 3)) ItemFactory::get(Item::WHEAT_SEEDS, 0, mt_rand(0, 3))
]; ];
}else{ }else{
return [ return [
Item::get(Item::WHEAT_SEEDS, 0, 1) ItemFactory::get(Item::WHEAT_SEEDS, 0, 1)
]; ];
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class WoodenStairs extends Stair{ class WoodenStairs extends Stair{
@ -43,7 +44,7 @@ class WoodenStairs extends Stair{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
//TODO: Hierarchy problem (base class is for stone stairs) //TODO: Hierarchy problem (base class is for stone stairs)
return [ return [
Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1) ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1)
]; ];
} }
} }

View File

@ -31,7 +31,7 @@ use pocketmine\Player;
class BanCommand extends VanillaCommand{ class BanCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.ban.player.description", "%pocketmine.command.ban.player.description",

View File

@ -31,7 +31,7 @@ use pocketmine\Player;
class BanIpCommand extends VanillaCommand{ class BanIpCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.ban.ip.description", "%pocketmine.command.ban.ip.description",
@ -71,7 +71,7 @@ class BanIpCommand extends VanillaCommand{
return true; return true;
} }
private function processIPBan($ip, CommandSender $sender, $reason){ private function processIPBan(string $ip, CommandSender $sender, string $reason){
$sender->getServer()->getIPBans()->addBan($ip, $reason, null, $sender->getName()); $sender->getServer()->getIPBans()->addBan($ip, $reason, null, $sender->getName());
foreach($sender->getServer()->getOnlinePlayers() as $player){ foreach($sender->getServer()->getOnlinePlayers() as $player){

View File

@ -30,7 +30,7 @@ use pocketmine\permission\BanEntry;
class BanListCommand extends VanillaCommand{ class BanListCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.banlist.description", "%pocketmine.command.banlist.description",

View File

@ -30,7 +30,7 @@ use pocketmine\Server;
class DefaultGamemodeCommand extends VanillaCommand{ class DefaultGamemodeCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.defaultgamemode.description", "%pocketmine.command.defaultgamemode.description",

View File

@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat;
class DeopCommand extends VanillaCommand{ class DeopCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.deop.description", "%pocketmine.command.deop.description",

View File

@ -32,7 +32,7 @@ use pocketmine\Server;
class DifficultyCommand extends VanillaCommand{ class DifficultyCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.difficulty.description", "%pocketmine.command.difficulty.description",

View File

@ -29,7 +29,7 @@ class DumpMemoryCommand extends VanillaCommand{
private static $executions = 0; private static $executions = 0;
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"Dumps the memory", "Dumps the memory",

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class EffectCommand extends VanillaCommand{ class EffectCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.effect.description", "%pocketmine.command.effect.description",

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class EnchantCommand extends VanillaCommand{ class EnchantCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.enchant.description", "%pocketmine.command.enchant.description",

View File

@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat;
class GamemodeCommand extends VanillaCommand{ class GamemodeCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.gamemode.description", "%pocketmine.command.gamemode.description",

View File

@ -28,7 +28,7 @@ use pocketmine\utils\TextFormat;
class GarbageCollectorCommand extends VanillaCommand{ class GarbageCollectorCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.gc.description", "%pocketmine.command.gc.description",

View File

@ -27,7 +27,7 @@ use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\ItemFactory;
use pocketmine\nbt\JsonNBTParser; use pocketmine\nbt\JsonNBTParser;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player; use pocketmine\Player;
@ -35,7 +35,7 @@ use pocketmine\utils\TextFormat;
class GiveCommand extends VanillaCommand{ class GiveCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.give.description", "%pocketmine.command.give.description",
@ -54,7 +54,7 @@ class GiveCommand extends VanillaCommand{
} }
$player = $sender->getServer()->getPlayer($args[0]); $player = $sender->getServer()->getPlayer($args[0]);
$item = Item::fromString($args[1]); $item = ItemFactory::fromString($args[1]);
if(!isset($args[2])){ if(!isset($args[2])){
$item->setCount($item->getMaxStackSize()); $item->setCount($item->getMaxStackSize());

View File

@ -30,7 +30,7 @@ use pocketmine\utils\TextFormat;
class HelpCommand extends VanillaCommand{ class HelpCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.help.description", "%pocketmine.command.help.description",

View File

@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat;
class KickCommand extends VanillaCommand{ class KickCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.kick.description", "%pocketmine.command.kick.description",

View File

@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat;
class KillCommand extends VanillaCommand{ class KillCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.kill.description", "%pocketmine.command.kill.description",

View File

@ -29,7 +29,7 @@ use pocketmine\Player;
class ListCommand extends VanillaCommand{ class ListCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.list.description", "%pocketmine.command.list.description",

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class MeCommand extends VanillaCommand{ class MeCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.me.description", "%pocketmine.command.me.description",

View File

@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat;
class OpCommand extends VanillaCommand{ class OpCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.op.description", "%pocketmine.command.op.description",

View File

@ -30,7 +30,7 @@ use pocketmine\event\TranslationContainer;
class PardonCommand extends VanillaCommand{ class PardonCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.unban.player.description", "%pocketmine.command.unban.player.description",

View File

@ -30,7 +30,7 @@ use pocketmine\event\TranslationContainer;
class PardonIpCommand extends VanillaCommand{ class PardonIpCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.unban.ip.description", "%pocketmine.command.unban.ip.description",

View File

@ -28,6 +28,7 @@ use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\particle\AngryVillagerParticle; use pocketmine\level\particle\AngryVillagerParticle;
use pocketmine\level\particle\BlockForceFieldParticle; use pocketmine\level\particle\BlockForceFieldParticle;
use pocketmine\level\particle\BubbleParticle; use pocketmine\level\particle\BubbleParticle;
@ -63,7 +64,7 @@ use pocketmine\utils\TextFormat;
class ParticleCommand extends VanillaCommand{ class ParticleCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.particle.description", "%pocketmine.command.particle.description",
@ -125,7 +126,6 @@ class ParticleCommand extends VanillaCommand{
/** /**
* @param string $name * @param string $name
*
* @param Vector3 $pos * @param Vector3 $pos
* @param float $xd * @param float $xd
* @param float $yd * @param float $yd
@ -134,7 +134,7 @@ class ParticleCommand extends VanillaCommand{
* *
* @return Particle|null * @return Particle|null
*/ */
private function getParticle($name, Vector3 $pos, $xd, $yd, $zd, $data){ private function getParticle(string $name, Vector3 $pos, float $xd, float $yd, float $zd, int $data = null){
switch($name){ switch($name){
case "explode": case "explode":
return new ExplodeParticle($pos); return new ExplodeParticle($pos);
@ -173,12 +173,12 @@ class ParticleCommand extends VanillaCommand{
case "reddust": case "reddust":
return new RedstoneParticle($pos, $data ?? 1); return new RedstoneParticle($pos, $data ?? 1);
case "snowballpoof": case "snowballpoof":
return new ItemBreakParticle($pos, Item::get(Item::SNOWBALL)); return new ItemBreakParticle($pos, ItemFactory::get(Item::SNOWBALL));
case "slime": case "slime":
return new ItemBreakParticle($pos, Item::get(Item::SLIMEBALL)); return new ItemBreakParticle($pos, ItemFactory::get(Item::SLIMEBALL));
case "itembreak": case "itembreak":
if($data !== null and $data !== 0){ if($data !== null and $data !== 0){
return new ItemBreakParticle($pos, Item::get($data)); return new ItemBreakParticle($pos, ItemFactory::get($data));
} }
break; break;
case "terrain": case "terrain":
@ -206,7 +206,7 @@ class ParticleCommand extends VanillaCommand{
if(strpos($name, "iconcrack_") === 0){ if(strpos($name, "iconcrack_") === 0){
$d = explode("_", $name); $d = explode("_", $name);
if(count($d) === 3){ if(count($d) === 3){
return new ItemBreakParticle($pos, Item::get((int) $d[1], (int) $d[2])); return new ItemBreakParticle($pos, ItemFactory::get((int) $d[1], (int) $d[2]));
} }
}elseif(strpos($name, "blockcrack_") === 0){ }elseif(strpos($name, "blockcrack_") === 0){
$d = explode("_", $name); $d = explode("_", $name);

View File

@ -29,7 +29,7 @@ use pocketmine\utils\TextFormat;
class PluginsCommand extends VanillaCommand{ class PluginsCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.plugins.description", "%pocketmine.command.plugins.description",

View File

@ -30,7 +30,7 @@ use pocketmine\utils\TextFormat;
class ReloadCommand extends VanillaCommand{ class ReloadCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.reload.description", "%pocketmine.command.reload.description",

View File

@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer;
class SaveCommand extends VanillaCommand{ class SaveCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.save.description", "%pocketmine.command.save.description",

View File

@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer;
class SaveOffCommand extends VanillaCommand{ class SaveOffCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.saveoff.description", "%pocketmine.command.saveoff.description",

View File

@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer;
class SaveOnCommand extends VanillaCommand{ class SaveOnCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.saveon.description", "%pocketmine.command.saveon.description",

View File

@ -32,7 +32,7 @@ use pocketmine\utils\TextFormat;
class SayCommand extends VanillaCommand{ class SayCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.say.description", "%pocketmine.command.say.description",

View File

@ -29,7 +29,7 @@ use pocketmine\Player;
class SeedCommand extends VanillaCommand{ class SeedCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.seed.description", "%pocketmine.command.seed.description",

View File

@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat;
class SetWorldSpawnCommand extends VanillaCommand{ class SetWorldSpawnCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.setworldspawn.description", "%pocketmine.command.setworldspawn.description",

View File

@ -34,7 +34,7 @@ use pocketmine\utils\TextFormat;
class SpawnpointCommand extends VanillaCommand{ class SpawnpointCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.spawnpoint.description", "%pocketmine.command.spawnpoint.description",

View File

@ -29,7 +29,7 @@ use pocketmine\utils\Utils;
class StatusCommand extends VanillaCommand{ class StatusCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.status.description", "%pocketmine.command.status.description",

View File

@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer;
class StopCommand extends VanillaCommand{ class StopCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.stop.description", "%pocketmine.command.stop.description",

View File

@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat;
class TeleportCommand extends VanillaCommand{ class TeleportCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.tp.description", "%pocketmine.command.tp.description",

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class TellCommand extends VanillaCommand{ class TellCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.tell.description", "%pocketmine.command.tell.description",

View File

@ -33,7 +33,7 @@ use pocketmine\utils\TextFormat;
class TimeCommand extends VanillaCommand{ class TimeCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.time.description", "%pocketmine.command.time.description",

View File

@ -35,7 +35,7 @@ class TimingsCommand extends VanillaCommand{
public static $timingStart = 0; public static $timingStart = 0;
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.timings.description", "%pocketmine.command.timings.description",

View File

@ -29,7 +29,7 @@ use pocketmine\event\TranslationContainer;
class TitleCommand extends VanillaCommand{ class TitleCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.title.description", "%pocketmine.command.title.description",

View File

@ -31,7 +31,7 @@ use pocketmine\Player;
class TransferServerCommand extends VanillaCommand{ class TransferServerCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.transferserver.description", "%pocketmine.command.transferserver.description",

View File

@ -30,11 +30,15 @@ abstract class VanillaCommand extends Command{
const MAX_COORD = 30000000; const MAX_COORD = 30000000;
const MIN_COORD = -30000000; const MIN_COORD = -30000000;
public function __construct($name, $description = "", $usageMessage = null, array $aliases = []){ /**
parent::__construct($name, $description, $usageMessage, $aliases); * @param CommandSender $sender
} * @param mixed $value
* @param int $min
protected function getInteger(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){ * @param int $max
*
* @return int
*/
protected function getInteger(CommandSender $sender, $value, int $min = self::MIN_COORD, int $max = self::MAX_COORD) : int{
$i = (int) $value; $i = (int) $value;
if($i < $min){ if($i < $min){
@ -46,7 +50,16 @@ abstract class VanillaCommand extends Command{
return $i; return $i;
} }
protected function getRelativeDouble($original, CommandSender $sender, $input, $min = self::MIN_COORD, $max = self::MAX_COORD){ /**
* @param float $original
* @param CommandSender $sender
* @param string $input
* @param float $min
* @param float $max
*
* @return float
*/
protected function getRelativeDouble(float $original, CommandSender $sender, string $input, float $min = self::MIN_COORD, float $max = self::MAX_COORD) : float{
if($input{0} === "~"){ if($input{0} === "~"){
$value = $this->getDouble($sender, substr($input, 1)); $value = $this->getDouble($sender, substr($input, 1));
@ -56,7 +69,15 @@ abstract class VanillaCommand extends Command{
return $this->getDouble($sender, $input, $min, $max); return $this->getDouble($sender, $input, $min, $max);
} }
protected function getDouble(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){ /**
* @param CommandSender $sender
* @param mixed $value
* @param float $min
* @param float $max
*
* @return float
*/
protected function getDouble(CommandSender $sender, $value, float $min = self::MIN_COORD, float $max = self::MAX_COORD) : float{
$i = (double) $value; $i = (double) $value;
if($i < $min){ if($i < $min){

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class VersionCommand extends VanillaCommand{ class VersionCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.version.description", "%pocketmine.command.version.description",

View File

@ -31,7 +31,7 @@ use pocketmine\utils\TextFormat;
class WhitelistCommand extends VanillaCommand{ class WhitelistCommand extends VanillaCommand{
public function __construct($name){ public function __construct(string $name){
parent::__construct( parent::__construct(
$name, $name,
"%pocketmine.command.whitelist.description", "%pocketmine.command.whitelist.description",
@ -108,7 +108,7 @@ class WhitelistCommand extends VanillaCommand{
return true; return true;
} }
private function badPerm(CommandSender $sender, $perm){ private function badPerm(CommandSender $sender, string $perm) : bool{
if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){ if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission")); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));

View File

@ -337,19 +337,19 @@ class Effect{
case Effect::POISON: case Effect::POISON:
if($entity->getHealth() > 1){ if($entity->getHealth() > 1){
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
} }
break; break;
case Effect::WITHER: case Effect::WITHER:
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev->getFinalDamage(), $ev); $entity->attack($ev);
break; break;
case Effect::REGENERATION: case Effect::REGENERATION:
if($entity->getHealth() < $entity->getMaxHealth()){ if($entity->getHealth() < $entity->getMaxHealth()){
$ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC); $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC);
$entity->heal($ev->getAmount(), $ev); $entity->heal($ev);
} }
break; break;
@ -362,13 +362,13 @@ class Effect{
//TODO: add particles (witch spell) //TODO: add particles (witch spell)
if($entity->getHealth() < $entity->getMaxHealth()){ if($entity->getHealth() < $entity->getMaxHealth()){
$amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); $entity->heal(new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC));
} }
break; break;
case Effect::INSTANT_DAMAGE: case Effect::INSTANT_DAMAGE:
//TODO: add particles (witch spell) //TODO: add particles (witch spell)
$amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $amount = 2 * (2 ** ($this->getEffectLevel() % 32));
$entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); $entity->attack(new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount));
break; break;
} }
} }

View File

@ -890,11 +890,9 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* @param float $damage
* @param EntityDamageEvent $source * @param EntityDamageEvent $source
*
*/ */
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -920,11 +918,9 @@ abstract class Entity extends Location implements Metadatable{
} }
/** /**
* @param float $amount
* @param EntityRegainHealthEvent $source * @param EntityRegainHealthEvent $source
*
*/ */
public function heal($amount, EntityRegainHealthEvent $source){ public function heal(EntityRegainHealthEvent $source){
$this->server->getPluginManager()->callEvent($source); $this->server->getPluginManager()->callEvent($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -1108,7 +1104,6 @@ abstract class Entity extends Location implements Metadatable{
public function entityBaseTick(int $tickDiff = 1) : bool{ public function entityBaseTick(int $tickDiff = 1) : bool{
//TODO: check vehicles //TODO: check vehicles
$this->blocksAround = null;
$this->justCreated = false; $this->justCreated = false;
if(!$this->isAlive()){ if(!$this->isAlive()){
@ -1132,7 +1127,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->y <= -16 and $this->isAlive()){ if($this->y <= -16 and $this->isAlive()){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
$hasUpdate = true; $hasUpdate = true;
} }
@ -1180,7 +1175,7 @@ abstract class Entity extends Location implements Metadatable{
*/ */
protected function dealFireDamage(){ protected function dealFireDamage(){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
protected function updateMovement(){ protected function updateMovement(){
@ -1347,6 +1342,8 @@ abstract class Entity extends Location implements Metadatable{
final public function setForceMovementUpdate(bool $value = true){ final public function setForceMovementUpdate(bool $value = true){
$this->forceMovementUpdate = $value; $this->forceMovementUpdate = $value;
$this->onGround = false; $this->onGround = false;
$this->blocksAround = null;
} }
/** /**
@ -1507,6 +1504,8 @@ abstract class Entity extends Location implements Metadatable{
} }
public function fastMove(float $dx, float $dy, float $dz) : bool{ public function fastMove(float $dx, float $dy, float $dz) : bool{
$this->blocksAround = null;
if($dx == 0 and $dz == 0 and $dy == 0){ if($dx == 0 and $dz == 0 and $dy == 0){
return true; return true;
} }
@ -1546,13 +1545,12 @@ abstract class Entity extends Location implements Metadatable{
} }
public function move(float $dx, float $dy, float $dz) : bool{ public function move(float $dx, float $dy, float $dz) : bool{
$this->blocksAround = null;
if($dx == 0 and $dz == 0 and $dy == 0){ if($dx == 0 and $dz == 0 and $dy == 0){
return true; return true;
} }
$this->blocksAround = null;
if($this->keepMovement){ if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz); $this->boundingBox->offset($dx, $dy, $dz);
$this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));

View File

@ -27,6 +27,7 @@ use pocketmine\block\BlockFactory;
use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityBlockChangeEvent;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;
use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
@ -74,9 +75,9 @@ class FallingSand extends Entity{
return false; return false;
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($damage, $source); parent::attack($source);
} }
} }
@ -95,7 +96,7 @@ class FallingSand extends Entity{
$block = $this->level->getBlock($pos); $block = $this->level->getBlock($pos);
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
//FIXME: anvils are supposed to destroy torches //FIXME: anvils are supposed to destroy torches
$this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1)); $this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage(), 1));
}else{ }else{
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, BlockFactory::get($this->getBlock(), $this->getDamage()))); $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, BlockFactory::get($this->getBlock(), $this->getDamage())));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){

View File

@ -405,19 +405,19 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->addFood(1.0); $this->addFood(1.0);
} }
if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){ if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->heal(new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
} }
} }
if($this->foodTickTimer === 0){ if($this->foodTickTimer === 0){
if($food >= 18){ if($food >= 18){
if($health < $this->getMaxHealth()){ if($health < $this->getMaxHealth()){
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); $this->heal(new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
} }
}elseif($food <= 0){ }elseif($food <= 0){
if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){ if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){
$this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); $this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
} }
} }
} }

View File

@ -87,14 +87,14 @@ class Item extends Entity{
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if( if(
$source->getCause() === EntityDamageEvent::CAUSE_VOID or $source->getCause() === EntityDamageEvent::CAUSE_VOID or
$source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK or
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION or
$source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION $source->getCause() === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION
){ ){
parent::attack($damage, $source); parent::attack($source);
} }
} }

View File

@ -157,8 +157,8 @@ abstract class Living extends Entity implements Damageable{
//return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null;
} }
public function heal($amount, EntityRegainHealthEvent $source){ public function heal(EntityRegainHealthEvent $source){
parent::heal($amount, $source); parent::heal($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
} }
@ -321,14 +321,14 @@ abstract class Living extends Entity implements Damageable{
$damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0)); $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
if($damage > 0){ if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
} }
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($this->attackTime > 0 or $this->noDamageTicks > 0){ if($this->attackTime > 0 or $this->noDamageTicks > 0){
$lastCause = $this->getLastDamageCause(); $lastCause = $this->getLastDamageCause();
if($lastCause !== null and $lastCause->getDamage() >= $damage){ if($lastCause !== null and $lastCause->getDamage() >= $source->getDamage()){
$source->setCancelled(); $source->setCancelled();
} }
} }
@ -346,7 +346,7 @@ abstract class Living extends Entity implements Damageable{
$source->setDamage(-($source->getDamage(EntityDamageEvent::MODIFIER_BASE) * 0.20 * $this->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE); $source->setDamage(-($source->getDamage(EntityDamageEvent::MODIFIER_BASE) * 0.20 * $this->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
} }
parent::attack($damage, $source); parent::attack($source);
if($source->isCancelled()){ if($source->isCancelled()){
return; return;
@ -365,7 +365,7 @@ abstract class Living extends Entity implements Damageable{
$deltaX = $this->x - $e->x; $deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z; $deltaZ = $this->z - $e->z;
$this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack()); $this->knockBack($e, $source->getDamage(), $deltaX, $deltaZ, $source->getKnockBack());
} }
} }
@ -428,7 +428,7 @@ abstract class Living extends Entity implements Damageable{
if($this->isInsideOfSolid()){ if($this->isInsideOfSolid()){
$hasUpdate = true; $hasUpdate = true;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){ if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){
@ -441,7 +441,7 @@ abstract class Living extends Entity implements Damageable{
$airTicks = 0; $airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
} }
@ -453,7 +453,7 @@ abstract class Living extends Entity implements Damageable{
$airTicks = 0; $airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev);
} }
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
}else{ }else{

View File

@ -48,9 +48,9 @@ class PrimedTNT extends Entity implements Explosive{
public $canCollide = false; public $canCollide = false;
public function attack($damage, EntityDamageEvent $source){ public function attack(EntityDamageEvent $source){
if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){
parent::attack($damage, $source); parent::attack($source);
} }
} }

Some files were not shown because too many files have changed in this diff Show More