diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d4c4322dd..6b4ac7a0e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -38,7 +38,6 @@ use pocketmine\entity\Projectile; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\event\entity\EntityShootBowEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\event\inventory\CraftItemEvent; use pocketmine\event\inventory\InventoryCloseEvent; @@ -103,7 +102,6 @@ use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\LongTag; -use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\PlayerNetworkSessionAdapter; use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; @@ -765,6 +763,29 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->inAirTicks; } + /** + * Returns whether the player is currently using an item (right-click and hold). + * @return bool + */ + public function isUsingItem() : bool{ + return $this->getGenericFlag(self::DATA_FLAG_ACTION) and $this->startAction > -1; + } + + public function setUsingItem(bool $value){ + $this->startAction = $value ? $this->server->getTick() : -1; + $this->setGenericFlag(self::DATA_FLAG_ACTION, $value); + } + + /** + * Returns how long the player has been using their currently-held item for. Used for determining arrow shoot force + * for bows. + * + * @return int + */ + public function getItemUseDuration() : int{ + return $this->startAction === -1 ? -1 : ($this->server->getTick() - $this->startAction); + } + protected function switchLevel(Level $targetLevel) : bool{ $oldLevel = $this->level; if(parent::switchLevel($targetLevel)){ @@ -2362,35 +2383,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; } - $item = $this->inventory->getItemInHand(); - $damageTable = [ - Item::WOODEN_SWORD => 4, - Item::GOLDEN_SWORD => 4, - Item::STONE_SWORD => 5, - Item::IRON_SWORD => 6, - Item::DIAMOND_SWORD => 7, - - Item::WOODEN_AXE => 3, - Item::GOLDEN_AXE => 3, - Item::STONE_AXE => 3, - Item::IRON_AXE => 5, - Item::DIAMOND_AXE => 6, - - Item::WOODEN_PICKAXE => 2, - Item::GOLDEN_PICKAXE => 2, - Item::STONE_PICKAXE => 3, - Item::IRON_PICKAXE => 4, - Item::DIAMOND_PICKAXE => 5, - - Item::WOODEN_SHOVEL => 1, - Item::GOLDEN_SHOVEL => 1, - Item::STONE_SHOVEL => 2, - Item::IRON_SHOVEL => 3, - Item::DIAMOND_SHOVEL => 4, - ]; + $heldItem = $this->inventory->getItemInHand(); $damage = [ - EntityDamageEvent::MODIFIER_BASE => $damageTable[$item->getId()] ?? 1, + EntityDamageEvent::MODIFIER_BASE => $heldItem->getAttackPoints(), ]; if(!$this->canInteract($target, 8)){ @@ -2402,33 +2398,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $cancelled = true; } - $armorValues = [ - Item::LEATHER_CAP => 1, - Item::LEATHER_TUNIC => 3, - Item::LEATHER_PANTS => 2, - Item::LEATHER_BOOTS => 1, - Item::CHAINMAIL_HELMET => 1, - Item::CHAINMAIL_CHESTPLATE => 5, - Item::CHAINMAIL_LEGGINGS => 4, - Item::CHAINMAIL_BOOTS => 1, - Item::GOLDEN_HELMET => 1, - Item::GOLDEN_CHESTPLATE => 5, - Item::GOLDEN_LEGGINGS => 3, - Item::GOLDEN_BOOTS => 1, - Item::IRON_HELMET => 2, - Item::IRON_CHESTPLATE => 6, - Item::IRON_LEGGINGS => 5, - Item::IRON_BOOTS => 2, - Item::DIAMOND_HELMET => 3, - Item::DIAMOND_CHESTPLATE => 8, - Item::DIAMOND_LEGGINGS => 6, - Item::DIAMOND_BOOTS => 3, - ]; $points = 0; - foreach($target->getInventory()->getArmorContents() as $index => $i){ - if(isset($armorValues[$i->getId()])){ - $points += $armorValues[$i->getId()]; - } + foreach($target->getInventory()->getArmorContents() as $armorItem){ + $points += $armorItem->getDefensePoints(); } $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); @@ -2442,18 +2414,18 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $target->attack($ev); if($ev->isCancelled()){ - if($item->isTool() and $this->isSurvival()){ + if($heldItem->isTool() and $this->isSurvival()){ $this->inventory->sendContents($this); } return true; } if($this->isSurvival()){ - if($item->isTool()){ - if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ + if($heldItem->isTool()){ + if($heldItem->useOn($target) and $heldItem->getDamage() >= $heldItem->getMaxDurability()){ $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1)); }else{ - $this->inventory->setItemInHand($item); + $this->inventory->setItemInHand($heldItem); } } @@ -2470,70 +2442,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $type = $packet->transactionData->releaseItemActionType; switch($type){ case InventoryTransactionPacket::RELEASE_ITEM_ACTION_RELEASE: - if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){ - if($this->inventory->getItemInHand()->getId() === Item::BOW){ - $bow = $this->inventory->getItemInHand(); - if($this->isSurvival() and !$this->inventory->contains(ItemFactory::get(Item::ARROW, 0, 1))){ - $this->inventory->sendContents($this); - return false; - } - - $nbt = new CompoundTag("", [ - new ListTag("Pos", [ - new DoubleTag("", $this->x), - new DoubleTag("", $this->y + $this->getEyeHeight()), - new DoubleTag("", $this->z) - ]), - new ListTag("Motion", [ - new DoubleTag("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)), - new DoubleTag("", -sin($this->pitch / 180 * M_PI)), - new DoubleTag("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)) - ]), - new ListTag("Rotation", [ - //yaw/pitch for arrows taken crosswise, not along the arrow shaft. - new FloatTag("", ($this->yaw > 180 ? 360 : 0) - $this->yaw), //arrow yaw must range from -180 to +180 - new FloatTag("", -$this->pitch) - ]), - new ShortTag("Fire", $this->isOnFire() ? 45 * 60 : 0) - ]); - - $diff = ($this->server->getTick() - $this->startAction); - $p = $diff / 20; - $f = min((($p ** 2) + $p * 2) / 3, 1) * 2; - $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->getLevel(), $nbt, $this, $f == 2), $f); - - if($f < 0.1 or $diff < 5){ - $ev->setCancelled(); - } - - $this->server->getPluginManager()->callEvent($ev); - - if($ev->isCancelled()){ - $ev->getProjectile()->kill(); - $this->inventory->sendContents($this); - }else{ - $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); - if($this->isSurvival()){ - $this->inventory->removeItem(ItemFactory::get(Item::ARROW, 0, 1)); - $bow->setDamage($bow->getDamage() + 1); - if($bow->getDamage() >= 385){ - $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 0)); - }else{ - $this->inventory->setItemInHand($bow); - } - } - if($ev->getProjectile() instanceof Projectile){ - $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile())); - if($projectileEv->isCancelled()){ - $ev->getProjectile()->kill(); - }else{ - $ev->getProjectile()->spawnToAll(); - $this->level->addSound(new LaunchSound($this), $this->getViewers()); - } - }else{ - $ev->getProjectile()->spawnToAll(); - } - } + if($this->isUsingItem()){ + $item = $this->inventory->getItemInHand(); + if($item->onReleaseUsing($this)){ + $this->inventory->setItemInHand($item); } }else{ $this->inventory->sendContents($this); diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index dbb1007c6..c4f485d6a 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -482,7 +482,7 @@ namespace pocketmine { } $gitHash = str_repeat("00", 20); -#ifndef COMPILE + if(\Phar::running(true) === ""){ if(Utils::execute("git rev-parse HEAD", $out) === 0){ $gitHash = trim($out); @@ -490,8 +490,14 @@ namespace pocketmine { $gitHash .= "-dirty"; } } + }else{ + $phar = new \Phar(\Phar::running(false)); + $meta = $phar->getMetadata(); + if(isset($meta["git"])){ + $gitHash = $meta["git"]; + } } -#endif + define('pocketmine\GIT_COMMIT', $gitHash); diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index f0e4f3fff..5a3010804 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -75,16 +75,16 @@ class Anvil extends Fallable{ return true; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $direction = ($player !== null ? $player->getDirection() : 0) & 0x03; $this->meta = ($this->meta & 0x0c) | $direction; - return $this->getLevel()->setBlock($block, $this, true, true); + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1), + ItemFactory::get($this->getItemId(), $this->getDamage() & 0x0c, 1) ]; } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 3cbad3758..7465bc192 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -175,21 +175,21 @@ class Bed extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if(!$down->isTransparent()){ $meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03; $next = $this->getSide(self::getOtherHalfSide($meta)); if($next->canBeReplaced() === true and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){ - $this->getLevel()->setBlock($block, BlockFactory::get($this->id, $meta), true, true); + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->id, $meta), true, true); $this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::BED), new ByteTag("color", $item->getDamage() & 0x0f), - new IntTag("x", $block->x), - new IntTag("y", $block->y), - new IntTag("z", $block->z), + new IntTag("x", $blockReplace->x), + new IntTag("y", $blockReplace->y), + new IntTag("z", $blockReplace->z) ]); $nbt2 = clone $nbt; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 0dc4cd5a5..48facec70 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -117,7 +117,10 @@ class Block extends Position implements BlockIds, Metadatable{ * @param int $meta */ final public function setDamage(int $meta){ - $this->meta = $meta & 0x0f; + if($meta < 0 or $meta > 0xf){ + throw new \InvalidArgumentException("Block damage values must be 0-15, not $meta"); + } + $this->meta = $meta; } /** @@ -137,15 +140,15 @@ class Block extends Position implements BlockIds, Metadatable{ * Places the Block, using block space and block target, and side. Returns if the block has been placed. * * @param Item $item - * @param Block $block - * @param Block $target + * @param Block $blockReplace + * @param Block $blockClicked * @param int $face * @param Vector3 $facePos * @param Player|null $player * * @return bool */ - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, $this, true, true); } @@ -263,6 +266,15 @@ class Block extends Position implements BlockIds, Metadatable{ return false; } + /** + * Returns whether random block updates will be done on this block. + * + * @return bool + */ + public function ticksRandomly() : bool{ + return false; + } + /** * AKA: Block->isPlaceable * @return bool @@ -342,7 +354,7 @@ class Block extends Position implements BlockIds, Metadatable{ */ public function getDrops(Item $item) : array{ return [ - ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1), + ItemFactory::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1) ]; } diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index a6bf9472c..6f41575d6 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -277,7 +277,7 @@ class BlockFactory{ self::registerBlock(new Magma()); self::registerBlock(new NetherWartBlock()); self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks")); - //TODO: BONE_BLOCK + self::registerBlock(new BoneBlock()); //TODO: SHULKER_BOX self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta")); @@ -297,7 +297,7 @@ class BlockFactory{ self::registerBlock(new GlazedTerracotta(Block::GREEN_GLAZED_TERRACOTTA, 0, "Green Glazed Terracotta")); self::registerBlock(new GlazedTerracotta(Block::RED_GLAZED_TERRACOTTA, 0, "Red Glazed Terracotta")); self::registerBlock(new GlazedTerracotta(Block::BLACK_GLAZED_TERRACOTTA, 0, "Black Glazed Terracotta")); - //TODO: CONCRETE + self::registerBlock(new Concrete()); //TODO: CONCRETEPOWDER //TODO: CHORUS_PLANT @@ -370,16 +370,14 @@ class BlockFactory{ * @return Block */ public static function get(int $id, int $meta = 0, Position $pos = null) : Block{ + if($meta < 0 or $meta > 0xf){ + throw new \InvalidArgumentException("Block meta value $meta is out of bounds"); + } + try{ - $block = self::$fullList[($id << 4) | $meta]; - if($block !== null){ - $block = clone $block; - }else{ - $block = new UnknownBlock($id, $meta); - } + $block = clone self::$fullList[($id << 4) | $meta]; }catch(\RuntimeException $e){ - //TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour) - $block = new UnknownBlock($id, $meta); + throw new \InvalidArgumentException("Block ID $id is out of bounds"); } if($pos !== null){ diff --git a/src/pocketmine/block/BlockIds.php b/src/pocketmine/block/BlockIds.php index 983883ae7..e7d04b86c 100644 --- a/src/pocketmine/block/BlockIds.php +++ b/src/pocketmine/block/BlockIds.php @@ -137,7 +137,7 @@ interface BlockIds{ const STONE_BRICK_STAIRS = 109; const MYCELIUM = 110; const LILY_PAD = 111, WATERLILY = 111, WATER_LILY = 111; - const NETHER_BRICK = 112, NETHER_BRICK_BLOCK = 112; + const NETHER_BRICK_BLOCK = 112; const NETHER_BRICK_FENCE = 113; const NETHER_BRICK_STAIRS = 114; const NETHER_WART_PLANT = 115; diff --git a/src/pocketmine/block/BoneBlock.php b/src/pocketmine/block/BoneBlock.php new file mode 100644 index 000000000..58472e77e --- /dev/null +++ b/src/pocketmine/block/BoneBlock.php @@ -0,0 +1,69 @@ +meta = $meta; + } + + public function getName() : string{ + return "Bone Block"; + } + + public function getHardness() : float{ + return 2; + } + + public function getToolType() : int{ + return Tool::TYPE_PICKAXE; + } + + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + return $this->getLevel()->setBlock($blockReplace, $this, true, true); + } + + public function getVariantBitmask() : int{ + return 0x03; + } + + public function getDrops(Item $item) : array{ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return parent::getDrops($item); // TODO: Change the autogenerated stub + } + + return []; + } + +} \ No newline at end of file diff --git a/src/pocketmine/block/BrownMushroom.php b/src/pocketmine/block/BrownMushroom.php index 2ca5ce010..00a43b844 100644 --- a/src/pocketmine/block/BrownMushroom.php +++ b/src/pocketmine/block/BrownMushroom.php @@ -23,19 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\item\Item; -use pocketmine\level\Level; -use pocketmine\math\Vector3; -use pocketmine\Player; - -class BrownMushroom extends Flowable{ +class BrownMushroom extends RedMushroom{ protected $id = self::BROWN_MUSHROOM; - public function __construct(int $meta = 0){ - $this->meta = $meta; - } - public function getName() : string{ return "Brown Mushroom"; } @@ -43,28 +34,4 @@ class BrownMushroom extends Flowable{ public function getLightLevel() : int{ return 1; } - - public function onUpdate(int $type){ - if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ - $this->getLevel()->useBreakOn($this); - - return Level::BLOCK_UPDATE_NORMAL; - } - } - - return false; - } - - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - $down = $this->getSide(Vector3::SIDE_DOWN); - if($down->isTransparent() === false){ - $this->getLevel()->setBlock($block, $this, true, true); - - return true; - } - - return false; - } - } \ No newline at end of file diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 22b06f629..806ac3702 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -59,15 +59,15 @@ class BurningFurnace extends Solid{ return 13; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, 2 => 5, - 3 => 3, + 3 => 3 ]; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0]; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::FURNACE), diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 62da396d8..e9a04ada7 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -66,6 +66,10 @@ class Cactus extends Transparent{ ); } + public function ticksRandomly() : bool{ + return true; + } + public function onEntityCollide(Entity $entity){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); $entity->attack($ev); @@ -108,7 +112,7 @@ class Cactus extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::SAND or $down->getId() === self::CACTUS){ $block0 = $this->getSide(Vector3::SIDE_NORTH); diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index d85702d51..65ef59040 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -62,10 +62,10 @@ class Cake extends Transparent implements FoodSource{ ); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() !== self::AIR){ - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 1b58fbef0..40ab5b90c 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -62,10 +62,10 @@ class Carpet extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() !== self::AIR){ - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index a3a3376c1..31640b3ee 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -67,12 +67,12 @@ class Chest extends Transparent{ ); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, 2 => 5, - 3 => 3, + 3 => 3 ]; $chest = null; @@ -94,7 +94,7 @@ class Chest extends Transparent{ } } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), diff --git a/src/pocketmine/item/Feather.php b/src/pocketmine/block/Concrete.php similarity index 52% rename from src/pocketmine/item/Feather.php rename to src/pocketmine/block/Concrete.php index 5d3c0c1f2..e2775d849 100644 --- a/src/pocketmine/item/Feather.php +++ b/src/pocketmine/block/Concrete.php @@ -21,12 +21,38 @@ declare(strict_types=1); -namespace pocketmine\item; +namespace pocketmine\block; +use pocketmine\block\utils\ColorBlockMetaHelper; +use pocketmine\item\Item; +use pocketmine\item\Tool; -class Feather extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::FEATHER, $meta, $count, "Feather"); +class Concrete extends Solid{ + + protected $id = Block::CONCRETE; + + public function __construct(int $meta = 0){ + $this->meta = $meta; + } + + public function getName() : string{ + return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Concrete"; + } + + public function getHardness() : float{ + return 1.8; + } + + public function getToolType() : int{ + return Tool::TYPE_PICKAXE; + } + + public function getDrops(Item $item) : array{ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return parent::getDrops($item); + } + + return []; } } \ No newline at end of file diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index b91781d08..216b69ea9 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -32,9 +32,9 @@ use pocketmine\Server; abstract class Crops extends Flowable{ - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($block->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){ - $this->getLevel()->setBlock($block, $this, true, true); + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){ + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } @@ -65,6 +65,10 @@ abstract class Crops extends Flowable{ return false; } + public function ticksRandomly() : bool{ + return true; + } + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index 8ccbab968..640748a57 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -41,10 +41,10 @@ class Dandelion extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){ - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index bd6b2f899..3d291f08a 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -216,7 +216,7 @@ abstract class Door extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === Vector3::SIDE_UP){ $blockUp = $this->getSide(Vector3::SIDE_UP); $blockDown = $this->getSide(Vector3::SIDE_DOWN); @@ -228,7 +228,7 @@ abstract class Door extends Transparent{ 0 => 3, 1 => 4, 2 => 2, - 3 => 5, + 3 => 5 ]; $next = $this->getSide($faces[($direction + 2) % 4]); $next2 = $this->getSide($faces[$direction]); @@ -238,7 +238,7 @@ abstract class Door extends Transparent{ } $this->setDamage($player->getDirection() & 0x03); - $this->getLevel()->setBlock($block, $this, true, true); //Bottom + $this->getLevel()->setBlock($blockReplace, $this, true, true); //Bottom $this->getLevel()->setBlock($blockUp, $b = BlockFactory::get($this->getId(), $metaUp), true); //Top return true; } diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index 4050536c6..5637fda4c 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -54,11 +54,11 @@ class DoublePlant extends Flowable{ return $names[$this->meta & 0x07] ?? ""; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - $id = $block->getSide(Vector3::SIDE_DOWN)->getId(); - if(($id === Block::GRASS or $id === Block::DIRT) and $block->getSide(Vector3::SIDE_UP)->canBeReplaced()){ - $this->getLevel()->setBlock($block, $this, false, false); - $this->getLevel()->setBlock($block->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + $id = $blockReplace->getSide(Vector3::SIDE_DOWN)->getId(); + if(($id === Block::GRASS or $id === Block::DIRT) and $blockReplace->getSide(Vector3::SIDE_UP)->canBeReplaced()){ + $this->getLevel()->setBlock($blockReplace, $this, false, false); + $this->getLevel()->setBlock($blockReplace->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false); return true; } diff --git a/src/pocketmine/block/DoubleStoneSlab.php b/src/pocketmine/block/DoubleStoneSlab.php index 07850aba6..82128b355 100644 --- a/src/pocketmine/block/DoubleStoneSlab.php +++ b/src/pocketmine/block/DoubleStoneSlab.php @@ -52,7 +52,7 @@ class DoubleStoneSlab extends Solid{ 4 => "Brick", 5 => "Stone Brick", 6 => "Quartz", - 7 => "Nether Brick", + 7 => "Nether Brick" ]; return "Double " . $names[$this->meta & 0x07] . " Slab"; } @@ -60,7 +60,7 @@ class DoubleStoneSlab extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_WOODEN){ return [ - ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2), + ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2) ]; } diff --git a/src/pocketmine/block/EmeraldOre.php b/src/pocketmine/block/EmeraldOre.php index 24ba01db1..9e5549c8f 100644 --- a/src/pocketmine/block/EmeraldOre.php +++ b/src/pocketmine/block/EmeraldOre.php @@ -50,7 +50,7 @@ class EmeraldOre extends Solid{ public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_IRON){ return [ - ItemFactory::get(Item::EMERALD, 0, 1), + ItemFactory::get(Item::EMERALD, 0, 1) ]; } diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 3cbcbe36d..581e181e5 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -41,8 +41,8 @@ class EnchantingTable extends Transparent{ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - $this->getLevel()->setBlock($block, $this, true, true); + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + $this->getLevel()->setBlock($blockReplace, $this, true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::ENCHANT_TABLE), new IntTag("x", $this->x), diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index af4964635..38e4da8f6 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -40,17 +40,17 @@ class EndRod extends Flowable{ return "End Rod"; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ $this->meta = $face; }else{ $this->meta = $face ^ 0x01; } - if($target instanceof EndRod and $target->getDamage() === $this->meta){ + if($blockClicked instanceof EndRod and $blockClicked->getDamage() === $this->meta){ $this->meta ^= 0x01; } - return $this->level->setBlock($block, $this, true, true); + return $this->level->setBlock($blockReplace, $this, true, true); } public function isSolid() : bool{ diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index a8ded4089..748585d77 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -56,7 +56,7 @@ abstract class Fallable extends Solid{ new FloatTag("", 0) ]), new IntTag("TileID", $this->getId()), - new ByteTag("Data", $this->getDamage()), + new ByteTag("Data", $this->getDamage()) ])); $fall->spawnToAll(); diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 0c42b7937..cbe941fd2 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\Tool; +use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; class Farmland extends Transparent{ @@ -48,6 +49,10 @@ class Farmland extends Transparent{ return Tool::TYPE_SHOVEL; } + public function ticksRandomly() : bool{ + return true; + } + protected function recalculateBoundingBox(){ return new AxisAlignedBB( $this->x, @@ -59,6 +64,14 @@ class Farmland extends Transparent{ ); } + public function onUpdate(int $type){ + if($type === Level::BLOCK_UPDATE_RANDOM){ + //TODO: hydration + } + + return false; + } + public function getDrops(Item $item) : array{ return [ ItemFactory::get(Item::DIRT, 0, 1) diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index ba463c2d7..0cc922163 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -69,9 +69,9 @@ class FenceGate extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0); - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 51a872fec..0b44d54bc 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -61,6 +61,10 @@ class Fire extends Flowable{ return true; } + public function ticksRandomly() : bool{ + return true; + } + public function onEntityCollide(Entity $entity){ $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); $entity->attack($ev); @@ -103,6 +107,8 @@ class Fire extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } } + + //TODO: fire spread } return false; diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index 80a0b36fd..ae69eadea 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -60,10 +60,10 @@ class Flower extends Flowable{ return $names[$this->meta] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ - $this->getLevel()->setBlock($block, $this, true); + $this->getLevel()->setBlock($blockReplace, $this, true); return true; } diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 643bc2848..d7e6f771f 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -63,20 +63,20 @@ class FlowerPot extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ return false; } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::FLOWER_POT), - new IntTag("x", $block->x), - new IntTag("y", $block->y), - new IntTag("z", $block->z), + new IntTag("x", $blockReplace->x), + new IntTag("y", $blockReplace->y), + new IntTag("z", $blockReplace->z), new ShortTag("item", 0), - new IntTag("mData", 0), + new IntTag("mData", 0) ]); if($item->hasCustomBlockData()){ diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index 47199c496..36ab5aa46 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -39,7 +39,7 @@ class GlazedTerracotta extends Solid{ return Tool::TYPE_PICKAXE; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($player !== null){ $faces = [ 0 => 4, @@ -50,7 +50,7 @@ class GlazedTerracotta extends Solid{ $this->meta = $faces[(~($player->getDirection() - 1)) & 0x03]; } - return $this->getLevel()->setBlock($block, $this, true, true); + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/GlowingObsidian.php b/src/pocketmine/block/GlowingObsidian.php index c851563c1..f83f8fc5c 100644 --- a/src/pocketmine/block/GlowingObsidian.php +++ b/src/pocketmine/block/GlowingObsidian.php @@ -40,4 +40,11 @@ class GlowingObsidian extends Solid{ return 12; } + public function getHardness() : float{ + return 10; + } + + public function getBlastResistance() : float{ + return 50; + } } \ No newline at end of file diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 338b0864e..e60995fee 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -55,10 +55,14 @@ class Grass extends Solid{ public function getDrops(Item $item) : array{ return [ - ItemFactory::get(Item::DIRT, 0, 1), + ItemFactory::get(Item::DIRT, 0, 1) ]; } + public function ticksRandomly() : bool{ + return true; + } + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_RANDOM){ $lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z); diff --git a/src/pocketmine/block/HayBale.php b/src/pocketmine/block/HayBale.php index f9567056e..4299bff15 100644 --- a/src/pocketmine/block/HayBale.php +++ b/src/pocketmine/block/HayBale.php @@ -43,18 +43,18 @@ class HayBale extends Solid{ return 0.5; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 0, 2 => 0b1000, 3 => 0b1000, 4 => 0b0100, - 5 => 0b0100, + 5 => 0b0100 ]; $this->meta = ($this->meta & 0x03) | $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 85b7be266..3006153cd 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -57,8 +57,10 @@ class Ice extends Transparent{ } public function onBreak(Item $item, Player $player = null) : bool{ - $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); + return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); + } + public function ticksRandomly() : bool{ return true; } diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index d92e16a3a..23e8fc7f2 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -105,7 +105,7 @@ class ItemFrame extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP){ return false; } @@ -118,13 +118,13 @@ class ItemFrame extends Flowable{ ]; $this->meta = $faces[$face]; - $this->level->setBlock($block, $this, true, true); + $this->level->setBlock($blockReplace, $this, true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::ITEM_FRAME), - new IntTag("x", $block->x), - new IntTag("y", $block->y), - new IntTag("z", $block->z), + new IntTag("x", $blockReplace->x), + new IntTag("y", $blockReplace->y), + new IntTag("z", $blockReplace->z), new FloatTag("ItemDropChance", 1.0), new ByteTag("ItemRotation", 0) ]); diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index be3a9f119..0dd8221f2 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -110,17 +110,17 @@ class Ladder extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($target->isTransparent() === false){ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($blockClicked->isTransparent() === false){ $faces = [ 2 => 2, 3 => 3, 4 => 4, - 5 => 5, + 5 => 5 ]; if(isset($faces[$face])){ $this->meta = $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index d5001c9e6..e92fb7759 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -63,7 +63,7 @@ class Lava extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $ret = $this->getLevel()->setBlock($this, $this, true, false); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index 689deede9..5b0047330 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -59,7 +59,7 @@ class Leaves extends Transparent{ self::OAK => "Oak Leaves", self::SPRUCE => "Spruce Leaves", self::BIRCH => "Birch Leaves", - self::JUNGLE => "Jungle Leaves", + self::JUNGLE => "Jungle Leaves" ]; return $names[$this->meta & 0x03]; } @@ -68,6 +68,10 @@ class Leaves extends Transparent{ return true; } + public function ticksRandomly() : bool{ + return true; + } + protected function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){ ++$check; $index = $pos->x . "." . $pos->y . "." . $pos->z; @@ -160,7 +164,7 @@ class Leaves extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta |= 0x04; return $this->getLevel()->setBlock($this, $this, true); } diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index fb8c77920..553ab0c5c 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -34,7 +34,7 @@ class Leaves2 extends Leaves{ public function getName() : string{ static $names = [ self::ACACIA => "Acacia Leaves", - self::DARK_OAK => "Dark Oak Leaves", + self::DARK_OAK => "Dark Oak Leaves" ]; return $names[$this->meta & 0x03] ?? "Unknown"; } diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 5d143af04..e4e3dcd2e 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -57,6 +57,10 @@ class Mycelium extends Solid{ ]; } + public function ticksRandomly() : bool{ + return true; + } + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_RANDOM){ //TODO: light levels diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index f7c0d1185..ab2e88090 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -40,10 +40,14 @@ class NetherWartPlant extends Flowable{ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function ticksRandomly() : bool{ + return true; + } + + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === Block::SOUL_SAND){ - $this->getLevel()->setBlock($block, $this, false, true); + $this->getLevel()->setBlock($blockReplace, $this, false, true); return true; } diff --git a/src/pocketmine/block/Obsidian.php b/src/pocketmine/block/Obsidian.php index 7a8ff16fb..1b817f3c4 100644 --- a/src/pocketmine/block/Obsidian.php +++ b/src/pocketmine/block/Obsidian.php @@ -46,6 +46,10 @@ class Obsidian extends Solid{ return 35; //50 in PC } + public function getBlastResistance() : float{ + return 6000; + } + public function getDrops(Item $item) : array{ if($item->isPickaxe() >= Tool::TIER_DIAMOND){ return parent::getDrops($item); diff --git a/src/pocketmine/block/Prismarine.php b/src/pocketmine/block/Prismarine.php index d7b7f7aec..498417674 100644 --- a/src/pocketmine/block/Prismarine.php +++ b/src/pocketmine/block/Prismarine.php @@ -46,7 +46,7 @@ class Prismarine extends Solid{ static $names = [ self::NORMAL => "Prismarine", self::DARK => "Dark Prismarine", - self::BRICKS => "Prismarine Bricks", + self::BRICKS => "Prismarine Bricks" ]; return $names[$this->meta & 0x03] ?? "Unknown"; } diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index 9d5c4cf20..0bd5ae1aa 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -48,11 +48,11 @@ class Pumpkin extends Solid{ return "Pumpkin"; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($player instanceof Player){ $this->meta = ((int) $player->getDirection() + 1) % 4; } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Quartz.php b/src/pocketmine/block/Quartz.php index 5bd4a8733..a9f96a56b 100644 --- a/src/pocketmine/block/Quartz.php +++ b/src/pocketmine/block/Quartz.php @@ -23,15 +23,17 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\PillarRotationHelper; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; +use pocketmine\Player; class Quartz extends Solid{ const QUARTZ_NORMAL = 0; const QUARTZ_CHISELED = 1; const QUARTZ_PILLAR = 2; - const QUARTZ_PILLAR2 = 3; protected $id = self::QUARTZ_BLOCK; @@ -47,10 +49,16 @@ class Quartz extends Solid{ static $names = [ self::QUARTZ_NORMAL => "Quartz Block", self::QUARTZ_CHISELED => "Chiseled Quartz Block", - self::QUARTZ_PILLAR => "Quartz Pillar", - self::QUARTZ_PILLAR2 => "Quartz Pillar", + self::QUARTZ_PILLAR => "Quartz Pillar" ]; - return $names[$this->meta & 0x03]; + return $names[$this->meta & 0x03] ?? "Unknown"; + } + + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($this->meta !== self::QUARTZ_NORMAL){ + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + } + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } public function getToolType() : int{ diff --git a/src/pocketmine/block/Rail.php b/src/pocketmine/block/Rail.php index 61a21b5bd..723a9d20c 100644 --- a/src/pocketmine/block/Rail.php +++ b/src/pocketmine/block/Rail.php @@ -55,9 +55,9 @@ class Rail extends Flowable{ return 0.7; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if(!$block->getSide(Vector3::SIDE_DOWN)->isTransparent()){ - return $this->getLevel()->setBlock($block, $this, true, true); + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent()){ + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } return false; diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index de491b279..0af15d796 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -40,6 +40,9 @@ class RedMushroom extends Flowable{ return "Red Mushroom"; } + public function ticksRandomly() : bool{ + return true; + } public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ @@ -53,10 +56,10 @@ class RedMushroom extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->isTransparent() === false){ - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 7034ba4ce..719afa6a1 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -46,7 +46,7 @@ class RedstoneOre extends Solid{ return 3; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, $this, true, false); } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 910c1eb1d..9597a6d96 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -57,11 +57,14 @@ class Sapling extends Flowable{ return $names[$this->meta & 0x07] ?? "Unknown"; } + public function ticksRandomly() : bool{ + return true; + } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index a453ccbd2..2f08dfb94 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -60,13 +60,13 @@ class SignPost extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face !== Vector3::SIDE_DOWN){ $nbt = new CompoundTag("", [ new StringTag("id", Tile::SIGN), - new IntTag("x", $block->x), - new IntTag("y", $block->y), - new IntTag("z", $block->z), + new IntTag("x", $blockReplace->x), + new IntTag("y", $blockReplace->y), + new IntTag("z", $blockReplace->z), new StringTag("Text1", ""), new StringTag("Text2", ""), new StringTag("Text3", ""), @@ -85,10 +85,10 @@ class SignPost extends Transparent{ if($face === Vector3::SIDE_UP){ $this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0f; - $this->getLevel()->setBlock($block, $this, true); + $this->getLevel()->setBlock($blockReplace, $this, true); }else{ $this->meta = $face; - $this->getLevel()->setBlock($block, new WallSign($this->meta), true); + $this->getLevel()->setBlock($blockReplace, new WallSign($this->meta), true); } Tile::createTile(Tile::SIGN, $this->getLevel(), $nbt); diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 7f20eb678..2a75e3c45 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -64,7 +64,7 @@ class Skull extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face !== Vector3::SIDE_DOWN){ $this->meta = $face; if($face === Vector3::SIDE_UP){ @@ -72,7 +72,7 @@ class Skull extends Flowable{ }else{ $rot = $face; } - $this->getLevel()->setBlock($block, $this, true); + $this->getLevel()->setBlock($blockReplace, $this, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::SKULL), new ByteTag("SkullType", $item->getDamage()), diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index 565d746f5..8b602161d 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -54,11 +54,14 @@ class SnowLayer extends Flowable{ return Tool::TYPE_SHOVEL; } + public function ticksRandomly() : bool{ + return true; + } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($block->getSide(Vector3::SIDE_DOWN)->isSolid()){ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($blockReplace->getSide(Vector3::SIDE_DOWN)->isSolid()){ //TODO: fix placement - $this->getLevel()->setBlock($block, $this, true); + $this->getLevel()->setBlock($blockReplace, $this, true); return true; } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index a17b17eca..4b7bc6b8c 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -130,18 +130,18 @@ abstract class Stair extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 2, 2 => 1, - 3 => 3, + 3 => 3 ]; $this->meta = $faces[$player->getDirection()] & 0x03; if(($facePos->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){ $this->meta |= 0x04; //Upside-down stairs } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/StoneBricks.php b/src/pocketmine/block/StoneBricks.php index 0645c517b..50db48a68 100644 --- a/src/pocketmine/block/StoneBricks.php +++ b/src/pocketmine/block/StoneBricks.php @@ -51,7 +51,7 @@ class StoneBricks extends Solid{ self::NORMAL => "Stone Bricks", self::MOSSY => "Mossy Stone Bricks", self::CRACKED => "Cracked Stone Bricks", - self::CHISELED => "Chiseled Stone Bricks", + self::CHISELED => "Chiseled Stone Bricks" ]; return $names[$this->meta & 0x03]; } diff --git a/src/pocketmine/block/StoneSlab.php b/src/pocketmine/block/StoneSlab.php index 3758e87c4..e6d5077a6 100644 --- a/src/pocketmine/block/StoneSlab.php +++ b/src/pocketmine/block/StoneSlab.php @@ -53,7 +53,7 @@ class StoneSlab extends WoodenSlab{ self::BRICK => "Brick", self::STONE_BRICK => "Stone Brick", self::QUARTZ => "Quartz", - self::NETHER_BRICK => "Nether Brick", + self::NETHER_BRICK => "Nether Brick" ]; return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index dc5156203..6512fbd4a 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -44,6 +44,10 @@ class Sugarcane extends Flowable{ return "Sugarcane"; } + public function ticksRandomly() : bool{ + return true; + } + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ @@ -102,10 +106,10 @@ class Sugarcane extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::SUGARCANE_BLOCK){ - $this->getLevel()->setBlock($block, BlockFactory::get(Block::SUGARCANE_BLOCK), true); + $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); return true; }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ @@ -114,7 +118,7 @@ class Sugarcane extends Flowable{ $block2 = $down->getSide(Vector3::SIDE_WEST); $block3 = $down->getSide(Vector3::SIDE_EAST); if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ - $this->getLevel()->setBlock($block, BlockFactory::get(Block::SUGARCANE_BLOCK), true); + $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true); return true; } diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 9caeaee52..d9836d395 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -50,10 +50,10 @@ class TallGrass extends Flowable{ return $names[$this->meta & 0x03] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::GRASS){ - $this->getLevel()->setBlock($block, $this, true); + $this->getLevel()->setBlock($blockReplace, $this, true); return true; } diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 44ca18a02..02f1fc5fa 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -68,24 +68,24 @@ class Torch extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $below = $this->getSide(Vector3::SIDE_DOWN); - if($target->isTransparent() === false and $face !== Vector3::SIDE_DOWN){ + if($blockClicked->isTransparent() === false and $face !== Vector3::SIDE_DOWN){ $faces = [ Vector3::SIDE_UP => 5, Vector3::SIDE_NORTH => 4, Vector3::SIDE_SOUTH => 3, Vector3::SIDE_WEST => 2, - Vector3::SIDE_EAST => 1, + Vector3::SIDE_EAST => 1 ]; $this->meta = $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; }elseif($below->isTransparent() === false or $below->getId() === self::FENCE or $below->getId() === self::COBBLESTONE_WALL){ $this->meta = 0; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 34243452c..104b5c383 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -124,7 +124,7 @@ class Trapdoor extends Transparent{ return $bb; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $directions = [ 0 => 1, 1 => 3, @@ -137,7 +137,7 @@ class Trapdoor extends Transparent{ if(($facePos->y > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){ $this->meta |= self::MASK_UPPER; //top half of block } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 6e64984d6..e2c6531ef 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -67,6 +67,10 @@ class Vine extends Transparent{ return true; } + public function ticksRandomly() : bool{ + return true; + } + public function onEntityCollide(Entity $entity){ $entity->resetFallDistance(); } @@ -132,18 +136,18 @@ class Vine extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ //TODO: multiple sides - if($target->isSolid()){ + if($blockClicked->isSolid()){ $faces = [ 2 => self::FLAG_SOUTH, 3 => self::FLAG_NORTH, 4 => self::FLAG_EAST, - 5 => self::FLAG_WEST, + 5 => self::FLAG_WEST ]; if(isset($faces[$face])){ $this->meta = $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } @@ -169,6 +173,8 @@ class Vine extends Transparent{ $this->level->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ + //TODO: vine growth } return false; diff --git a/src/pocketmine/block/WallSign.php b/src/pocketmine/block/WallSign.php index 50863d824..62ce2507f 100644 --- a/src/pocketmine/block/WallSign.php +++ b/src/pocketmine/block/WallSign.php @@ -38,7 +38,7 @@ class WallSign extends SignPost{ 2 => 3, 3 => 2, 4 => 5, - 5 => 4, + 5 => 4 ]; if($type === Level::BLOCK_UPDATE_NORMAL){ if(isset($faces[$this->meta])){ diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 4f9ef3e76..df5c729f7 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -53,7 +53,7 @@ class Water extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $ret = $this->getLevel()->setBlock($this, $this, true, false); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index c2fb17515..a701d6226 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -57,9 +57,9 @@ class WaterLily extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - if($target instanceof Water){ - $up = $target->getSide(Vector3::SIDE_UP); + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + if($blockClicked instanceof Water){ + $up = $blockClicked->getSide(Vector3::SIDE_UP); if($up->getId() === Block::AIR){ $this->getLevel()->setBlock($up, $this, true, true); return true; diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index bf1933013..baaf09303 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\PillarRotationHelper; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\math\Vector3; @@ -49,25 +50,14 @@ class Wood extends Solid{ self::OAK => "Oak Wood", self::SPRUCE => "Spruce Wood", self::BIRCH => "Birch Wood", - self::JUNGLE => "Jungle Wood", + self::JUNGLE => "Jungle Wood" ]; return $names[$this->meta & 0x03]; } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ - $faces = [ - Vector3::SIDE_DOWN => 0, - Vector3::SIDE_UP => 0, - Vector3::SIDE_NORTH => 0b1000, - Vector3::SIDE_SOUTH => 0b1000, - Vector3::SIDE_WEST => 0b0100, - Vector3::SIDE_EAST => 0b0100, - ]; - - $this->meta = ($this->meta & 0x03) | $faces[$face]; - $this->getLevel()->setBlock($block, $this, true, true); - - return true; + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ + $this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face); + return $this->getLevel()->setBlock($blockReplace, $this, true, true); } public function getVariantBitmask() : int{ diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 3df1f3e2c..1fa697d6b 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -82,34 +82,34 @@ class WoodenSlab extends Transparent{ return $with !== null and $with->getId() === $this->getId() and ($with->getDamage() & 0x07) === ($this->getDamage() & 0x07); } - public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta &= 0x07; if($face === Vector3::SIDE_DOWN){ - if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($target, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and ($blockClicked->getDamage() & 0x07) === $this->meta){ + $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true); return true; - }elseif($block->getId() === $this->id and ($block->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true); + }elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); return true; }else{ $this->meta |= 0x08; } }elseif($face === Vector3::SIDE_UP){ - if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($target, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and ($blockClicked->getDamage() & 0x07) === $this->meta){ + $this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true); return true; - }elseif($block->getId() === $this->id and ($block->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true); + }elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); return true; } }else{ //TODO: collision - if($block->getId() === $this->id){ - if(($block->getDamage() & 0x07) === $this->meta){ - $this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true); + if($blockReplace->getId() === $this->id){ + if(($blockReplace->getDamage() & 0x07) === $this->meta){ + $this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true); return true; } @@ -122,10 +122,10 @@ class WoodenSlab extends Transparent{ } } - if($block->getId() === $this->id and ($target->getDamage() & 0x07) !== ($this->meta & 0x07)){ + if($blockReplace->getId() === $this->id and ($blockClicked->getDamage() & 0x07) !== ($this->meta & 0x07)){ return false; } - $this->getLevel()->setBlock($block, $this, true, true); + $this->getLevel()->setBlock($blockReplace, $this, true, true); return true; } diff --git a/src/pocketmine/block/utils/ColorBlockMetaHelper.php b/src/pocketmine/block/utils/ColorBlockMetaHelper.php index 01a6ab77f..246c2e7cd 100644 --- a/src/pocketmine/block/utils/ColorBlockMetaHelper.php +++ b/src/pocketmine/block/utils/ColorBlockMetaHelper.php @@ -42,7 +42,7 @@ class ColorBlockMetaHelper{ 12 => "Brown", 13 => "Green", 14 => "Red", - 15 => "Black", + 15 => "Black" ]; return $names[$meta] ?? "Unknown"; diff --git a/src/pocketmine/item/Diamond.php b/src/pocketmine/block/utils/PillarRotationHelper.php similarity index 69% rename from src/pocketmine/item/Diamond.php rename to src/pocketmine/block/utils/PillarRotationHelper.php index bef773f7c..3cb3a928a 100644 --- a/src/pocketmine/item/Diamond.php +++ b/src/pocketmine/block/utils/PillarRotationHelper.php @@ -21,12 +21,19 @@ declare(strict_types=1); -namespace pocketmine\item; +namespace pocketmine\block\utils; +use pocketmine\math\Vector3; -class Diamond extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND, $meta, $count, "Diamond"); +class PillarRotationHelper{ + + public static function getMetaFromFace(int $meta, int $face) : int{ + $faces = [ + Vector3::SIDE_DOWN => 0, + Vector3::SIDE_NORTH => 0x08, + Vector3::SIDE_WEST => 0x04, + ]; + + return ($meta & 0x03) | $faces[$face & ~0x01]; } - } \ No newline at end of file diff --git a/src/pocketmine/item/Apple.php b/src/pocketmine/item/Apple.php index 5b2a2947d..1184d60cd 100644 --- a/src/pocketmine/item/Apple.php +++ b/src/pocketmine/item/Apple.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class Apple extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::APPLE, $meta, $count, "Apple"); + public function __construct(int $meta = 0){ + parent::__construct(self::APPLE, $meta, "Apple"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/Arrow.php b/src/pocketmine/item/Arrow.php index ab5300ac3..e86076fc7 100644 --- a/src/pocketmine/item/Arrow.php +++ b/src/pocketmine/item/Arrow.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class Arrow extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::ARROW, $meta, $count, "Arrow"); + public function __construct(int $meta = 0){ + parent::__construct(self::ARROW, $meta, "Arrow"); } } diff --git a/src/pocketmine/item/BakedPotato.php b/src/pocketmine/item/BakedPotato.php index a3bf3b31a..932b0ce0d 100644 --- a/src/pocketmine/item/BakedPotato.php +++ b/src/pocketmine/item/BakedPotato.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class BakedPotato extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BAKED_POTATO, $meta, $count, "Baked Potato"); + public function __construct(int $meta = 0){ + parent::__construct(self::BAKED_POTATO, $meta, "Baked Potato"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/Bed.php b/src/pocketmine/item/Bed.php index e9e6d5505..fece690a3 100644 --- a/src/pocketmine/item/Bed.php +++ b/src/pocketmine/item/Bed.php @@ -27,9 +27,9 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class Bed extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::BED_BLOCK); - parent::__construct(self::BED, $meta, $count, "Bed"); + parent::__construct(self::BED, $meta, "Bed"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/Beetroot.php b/src/pocketmine/item/Beetroot.php index f84157717..3e36291ca 100644 --- a/src/pocketmine/item/Beetroot.php +++ b/src/pocketmine/item/Beetroot.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class Beetroot extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BEETROOT, $meta, $count, "Beetroot"); + public function __construct(int $meta = 0){ + parent::__construct(self::BEETROOT, $meta, "Beetroot"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/BeetrootSeeds.php b/src/pocketmine/item/BeetrootSeeds.php index a0bd39c14..5be598aa2 100644 --- a/src/pocketmine/item/BeetrootSeeds.php +++ b/src/pocketmine/item/BeetrootSeeds.php @@ -27,8 +27,8 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class BeetrootSeeds extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::BEETROOT_BLOCK); - parent::__construct(self::BEETROOT_SEEDS, $meta, $count, "Beetroot Seeds"); + parent::__construct(self::BEETROOT_SEEDS, $meta, "Beetroot Seeds"); } } \ No newline at end of file diff --git a/src/pocketmine/item/BeetrootSoup.php b/src/pocketmine/item/BeetrootSoup.php index 0b0f62856..011846038 100644 --- a/src/pocketmine/item/BeetrootSoup.php +++ b/src/pocketmine/item/BeetrootSoup.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class BeetrootSoup extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BEETROOT_SOUP, $meta, $count, "Beetroot Soup"); + public function __construct(int $meta = 0){ + parent::__construct(self::BEETROOT_SOUP, $meta, "Beetroot Soup"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/BlazePowder.php b/src/pocketmine/item/BlazePowder.php deleted file mode 100644 index cddf38a41..000000000 --- a/src/pocketmine/item/BlazePowder.php +++ /dev/null @@ -1,30 +0,0 @@ -isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){ + $player->getInventory()->sendContents($player); + } + + $nbt = new CompoundTag("", [ + new ListTag("Pos", [ + new DoubleTag("", $player->x), + new DoubleTag("", $player->y + $player->getEyeHeight()), + new DoubleTag("", $player->z) + ]), + new ListTag("Motion", [ + new DoubleTag("", -sin($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)), + new DoubleTag("", -sin($player->pitch / 180 * M_PI)), + new DoubleTag("", cos($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)) + ]), + new ListTag("Rotation", [ + //yaw/pitch for arrows taken crosswise, not along the arrow shaft. + new FloatTag("", ($player->yaw > 180 ? 360 : 0) - $player->yaw), //arrow yaw must range from -180 to +180 + new FloatTag("", -$player->pitch) + ]), + new ShortTag("Fire", $player->isOnFire() ? 45 * 60 : 0) + ]); + + $diff = $player->getItemUseDuration(); + $p = $diff / 20; + $force = min((($p ** 2) + $p * 2) / 3, 1) * 2; + + + $entity = Entity::createEntity("Arrow", $player->getLevel(), $nbt, $player, $force == 2); + if($entity instanceof Projectile){ + $ev = new EntityShootBowEvent($player, $this, $entity, $force); + + if($force < 0.1 or $diff < 5){ + $ev->setCancelled(); + } + + $player->getServer()->getPluginManager()->callEvent($ev); + + $entity = $ev->getProjectile(); //This might have been changed by plugins + + if($ev->isCancelled()){ + $entity->kill(); + $player->getInventory()->sendContents($player); + }else{ + $entity->setMotion($entity->getMotion()->multiply($ev->getForce())); + if($player->isSurvival()){ + $player->getInventory()->removeItem(ItemFactory::get(Item::ARROW, 0, 1)); + $this->setDamage($this->getDamage() + 1); + if($this->getDamage() >= $this->getMaxDurability()){ + $player->getInventory()->setItemInHand(ItemFactory::get(Item::AIR, 0, 0)); + }else{ + $player->getInventory()->setItemInHand($this); + } + } + + if($entity instanceof Projectile){ + $player->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($entity)); + if($projectileEv->isCancelled()){ + $ev->getProjectile()->kill(); + }else{ + $ev->getProjectile()->spawnToAll(); + $player->level->addSound(new LaunchSound($player), $player->getViewers()); + } + }else{ + $entity->spawnToAll(); + } + } + }else{ + $entity->spawnToAll(); + } + + return true; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Bowl.php b/src/pocketmine/item/Bowl.php index b7dc13b5a..6d8405f0c 100644 --- a/src/pocketmine/item/Bowl.php +++ b/src/pocketmine/item/Bowl.php @@ -25,8 +25,9 @@ namespace pocketmine\item; class Bowl extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BOWL, $meta, $count, "Bowl"); + public function __construct(int $meta = 0){ + parent::__construct(self::BOWL, $meta, "Bowl"); } + //TODO: check fuel } \ No newline at end of file diff --git a/src/pocketmine/item/Bread.php b/src/pocketmine/item/Bread.php index a4d74bcd6..6673a470b 100644 --- a/src/pocketmine/item/Bread.php +++ b/src/pocketmine/item/Bread.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class Bread extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BREAD, $meta, $count, "Bread"); + public function __construct(int $meta = 0){ + parent::__construct(self::BREAD, $meta, "Bread"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/BrewingStand.php b/src/pocketmine/item/BrewingStand.php index 25894a7cd..9597d4ba0 100644 --- a/src/pocketmine/item/BrewingStand.php +++ b/src/pocketmine/item/BrewingStand.php @@ -23,8 +23,11 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\block\Block; + class BrewingStand extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::BREWING_STAND, $meta, $count, "Brewing Stand"); + public function __construct(int $meta = 0){ + $this->block = Block::get(Block::BREWING_STAND_BLOCK); + parent::__construct(self::BREWING_STAND, $meta, "Brewing Stand"); } } diff --git a/src/pocketmine/item/Brick.php b/src/pocketmine/item/Brick.php deleted file mode 100644 index f9979708e..000000000 --- a/src/pocketmine/item/Brick.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::CAKE_BLOCK); - parent::__construct(self::CAKE, $meta, $count, "Cake"); + parent::__construct(self::CAKE, $meta, "Cake"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/Carrot.php b/src/pocketmine/item/Carrot.php index ee6ba7b40..d39588d26 100644 --- a/src/pocketmine/item/Carrot.php +++ b/src/pocketmine/item/Carrot.php @@ -27,9 +27,9 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class Carrot extends Food{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::CARROT_BLOCK); - parent::__construct(self::CARROT, $meta, $count, "Carrot"); + parent::__construct(self::CARROT, $meta, "Carrot"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/ChainBoots.php b/src/pocketmine/item/ChainBoots.php index 9786690b6..d75db7e1c 100644 --- a/src/pocketmine/item/ChainBoots.php +++ b/src/pocketmine/item/ChainBoots.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class ChainBoots extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::CHAIN_BOOTS, $meta, $count, "Chainmail Boots"); + public function __construct(int $meta = 0){ + parent::__construct(self::CHAIN_BOOTS, $meta, "Chainmail Boots"); + } + + public function getDefensePoints() : int{ + return 1; } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainChestplate.php b/src/pocketmine/item/ChainChestplate.php index e573e6a24..edc866f98 100644 --- a/src/pocketmine/item/ChainChestplate.php +++ b/src/pocketmine/item/ChainChestplate.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class ChainChestplate extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::CHAIN_CHESTPLATE, $meta, $count, "Chain Chestplate"); + public function __construct(int $meta = 0){ + parent::__construct(self::CHAIN_CHESTPLATE, $meta, "Chain Chestplate"); + } + + public function getDefensePoints() : int{ + return 5; } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainHelmet.php b/src/pocketmine/item/ChainHelmet.php index b6a31f8e9..9a217fb0d 100644 --- a/src/pocketmine/item/ChainHelmet.php +++ b/src/pocketmine/item/ChainHelmet.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class ChainHelmet extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::CHAIN_HELMET, $meta, $count, "Chainmail Helmet"); + public function __construct(int $meta = 0){ + parent::__construct(self::CHAIN_HELMET, $meta, "Chainmail Helmet"); + } + + public function getDefensePoints() : int{ + return 2; } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainLeggings.php b/src/pocketmine/item/ChainLeggings.php index 90a60bc79..c7245e054 100644 --- a/src/pocketmine/item/ChainLeggings.php +++ b/src/pocketmine/item/ChainLeggings.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class ChainLeggings extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::CHAIN_LEGGINGS, $meta, $count, "Chain Leggings"); + public function __construct(int $meta = 0){ + parent::__construct(self::CHAIN_LEGGINGS, $meta, "Chain Leggings"); + } + + public function getDefensePoints() : int{ + return 4; } } \ No newline at end of file diff --git a/src/pocketmine/item/Clay.php b/src/pocketmine/item/Clay.php deleted file mode 100644 index d8367885d..000000000 --- a/src/pocketmine/item/Clay.php +++ /dev/null @@ -1,32 +0,0 @@ -meta === 1){ $this->name = "Charcoal"; } diff --git a/src/pocketmine/item/Compass.php b/src/pocketmine/item/Compass.php index ace5fdcec..98e95ad2a 100644 --- a/src/pocketmine/item/Compass.php +++ b/src/pocketmine/item/Compass.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class Compass extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::COMPASS, $meta, $count, "Compass"); + public function __construct(int $meta = 0){ + parent::__construct(self::COMPASS, $meta, "Compass"); } } diff --git a/src/pocketmine/item/CookedChicken.php b/src/pocketmine/item/CookedChicken.php index 55369f19c..153183d37 100644 --- a/src/pocketmine/item/CookedChicken.php +++ b/src/pocketmine/item/CookedChicken.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class CookedChicken extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::COOKED_CHICKEN, $meta, $count, "Cooked Chicken"); + public function __construct(int $meta = 0){ + parent::__construct(self::COOKED_CHICKEN, $meta, "Cooked Chicken"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/CookedFish.php b/src/pocketmine/item/CookedFish.php index 168a61c62..27e77e64b 100644 --- a/src/pocketmine/item/CookedFish.php +++ b/src/pocketmine/item/CookedFish.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class CookedFish extends Fish{ - public function __construct($meta = 0, $count = 1){ - Food::__construct(self::COOKED_FISH, $meta, $count, $meta === self::FISH_SALMON ? "Cooked Salmon" : "Cooked Fish"); + public function __construct(int $meta = 0){ + Food::__construct(self::COOKED_FISH, $meta, $meta === self::FISH_SALMON ? "Cooked Salmon" : "Cooked Fish"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/CookedPorkchop.php b/src/pocketmine/item/CookedPorkchop.php index 9b13ebb3d..7d6d8e387 100644 --- a/src/pocketmine/item/CookedPorkchop.php +++ b/src/pocketmine/item/CookedPorkchop.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class CookedPorkchop extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::COOKED_PORKCHOP, $meta, $count, "Cooked Porkchop"); + public function __construct(int $meta = 0){ + parent::__construct(self::COOKED_PORKCHOP, $meta, "Cooked Porkchop"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/CookedRabbit.php b/src/pocketmine/item/CookedRabbit.php index 51bca14fa..c94543fc3 100644 --- a/src/pocketmine/item/CookedRabbit.php +++ b/src/pocketmine/item/CookedRabbit.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class CookedRabbit extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::COOKED_RABBIT, $meta, $count, "Cooked Rabbit"); + public function __construct(int $meta = 0){ + parent::__construct(self::COOKED_RABBIT, $meta, "Cooked Rabbit"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/Cookie.php b/src/pocketmine/item/Cookie.php index 488816c2e..ad1a1f5a3 100644 --- a/src/pocketmine/item/Cookie.php +++ b/src/pocketmine/item/Cookie.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class Cookie extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::COOKIE, $meta, $count, "Cookie"); + public function __construct(int $meta = 0){ + parent::__construct(self::COOKIE, $meta, "Cookie"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/DiamondAxe.php b/src/pocketmine/item/DiamondAxe.php index 0352a48c9..7904cd470 100644 --- a/src/pocketmine/item/DiamondAxe.php +++ b/src/pocketmine/item/DiamondAxe.php @@ -25,12 +25,15 @@ namespace pocketmine\item; class DiamondAxe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_AXE, $meta, $count, "Diamond Axe"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_AXE, $meta, "Diamond Axe"); } public function isAxe(){ return Tool::TIER_DIAMOND; } + public function getAttackPoints() : int{ + return 7; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondBoots.php b/src/pocketmine/item/DiamondBoots.php index 7666826b0..eef1e3056 100644 --- a/src/pocketmine/item/DiamondBoots.php +++ b/src/pocketmine/item/DiamondBoots.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class DiamondBoots extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_BOOTS, $meta, $count, "Diamond Boots"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_BOOTS, $meta, "Diamond Boots"); + } + + public function getDefensePoints() : int{ + return 3; } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondChestplate.php b/src/pocketmine/item/DiamondChestplate.php index 2aaf9d2ea..f7824e37b 100644 --- a/src/pocketmine/item/DiamondChestplate.php +++ b/src/pocketmine/item/DiamondChestplate.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class DiamondChestplate extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_CHESTPLATE, $meta, $count, "Diamond Chestplate"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_CHESTPLATE, $meta, "Diamond Chestplate"); + } + + public function getDefensePoints() : int{ + return 8; } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondHelmet.php b/src/pocketmine/item/DiamondHelmet.php index bb70f7a8f..6ebe38612 100644 --- a/src/pocketmine/item/DiamondHelmet.php +++ b/src/pocketmine/item/DiamondHelmet.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class DiamondHelmet extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_HELMET, $meta, $count, "Diamond Helmet"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_HELMET, $meta, "Diamond Helmet"); + } + + public function getDefensePoints() : int{ + return 3; } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondHoe.php b/src/pocketmine/item/DiamondHoe.php index 5b99f4047..f9414496c 100644 --- a/src/pocketmine/item/DiamondHoe.php +++ b/src/pocketmine/item/DiamondHoe.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class DiamondHoe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_HOE, $meta, $count, "Diamond Hoe"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_HOE, $meta, "Diamond Hoe"); } public function isHoe(){ diff --git a/src/pocketmine/item/DiamondLeggings.php b/src/pocketmine/item/DiamondLeggings.php index 997475abf..1beb2a8b0 100644 --- a/src/pocketmine/item/DiamondLeggings.php +++ b/src/pocketmine/item/DiamondLeggings.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class DiamondLeggings extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_LEGGINGS, $meta, $count, "Diamond Leggings"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_LEGGINGS, $meta, "Diamond Leggings"); + } + + public function getDefensePoints() : int{ + return 6; } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondPickaxe.php b/src/pocketmine/item/DiamondPickaxe.php index c9414a508..915409493 100644 --- a/src/pocketmine/item/DiamondPickaxe.php +++ b/src/pocketmine/item/DiamondPickaxe.php @@ -25,11 +25,15 @@ namespace pocketmine\item; class DiamondPickaxe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_PICKAXE, $meta, $count, "Diamond Pickaxe"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_PICKAXE, $meta, "Diamond Pickaxe"); } public function isPickaxe(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 6; + } } diff --git a/src/pocketmine/item/DiamondShovel.php b/src/pocketmine/item/DiamondShovel.php index 7edefb0aa..64c0ef459 100644 --- a/src/pocketmine/item/DiamondShovel.php +++ b/src/pocketmine/item/DiamondShovel.php @@ -25,11 +25,15 @@ namespace pocketmine\item; class DiamondShovel extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_SHOVEL, $meta, "Diamond Shovel"); } public function isShovel(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 5; + } } diff --git a/src/pocketmine/item/DiamondSword.php b/src/pocketmine/item/DiamondSword.php index 2ad11527f..0205ca4b3 100644 --- a/src/pocketmine/item/DiamondSword.php +++ b/src/pocketmine/item/DiamondSword.php @@ -25,11 +25,15 @@ namespace pocketmine\item; class DiamondSword extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DIAMOND_SWORD, $meta, $count, "Diamond Sword"); + public function __construct(int $meta = 0){ + parent::__construct(self::DIAMOND_SWORD, $meta, "Diamond Sword"); } public function isSword(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 8; + } } diff --git a/src/pocketmine/item/Dye.php b/src/pocketmine/item/Dye.php index 1bcb77f8a..54a9e137a 100644 --- a/src/pocketmine/item/Dye.php +++ b/src/pocketmine/item/Dye.php @@ -24,9 +24,10 @@ declare(strict_types=1); namespace pocketmine\item; class Dye extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::DYE, $meta, $count, "Dye"); + public function __construct(int $meta = 0){ + parent::__construct(self::DYE, $meta, "Dye"); } + //TODO: names } diff --git a/src/pocketmine/item/Egg.php b/src/pocketmine/item/Egg.php index 0b1235e0a..b13868f06 100644 --- a/src/pocketmine/item/Egg.php +++ b/src/pocketmine/item/Egg.php @@ -24,9 +24,11 @@ declare(strict_types=1); namespace pocketmine\item; class Egg extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::EGG, $meta, $count, "Egg"); + public function __construct(int $meta = 0){ + parent::__construct(self::EGG, $meta, "Egg"); } + //TODO + } diff --git a/src/pocketmine/item/Emerald.php b/src/pocketmine/item/Emerald.php deleted file mode 100644 index 50a4cd47f..000000000 --- a/src/pocketmine/item/Emerald.php +++ /dev/null @@ -1,32 +0,0 @@ -meta === self::FISH_SALMON){ $name = "Raw Salmon"; @@ -40,7 +40,7 @@ class Fish extends Food{ }elseif($this->meta === self::FISH_PUFFERFISH){ $name = "Pufferfish"; } - parent::__construct(self::RAW_FISH, $meta, $count, $name); + parent::__construct(self::RAW_FISH, $meta, $name); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/FishingRod.php b/src/pocketmine/item/FishingRod.php index 1d99c5c03..43ec05f43 100644 --- a/src/pocketmine/item/FishingRod.php +++ b/src/pocketmine/item/FishingRod.php @@ -24,7 +24,9 @@ declare(strict_types=1); namespace pocketmine\item; class FishingRod extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::FISHING_ROD, $meta, $count, "Fishing Rod"); + public function __construct(int $meta = 0){ + parent::__construct(self::FISHING_ROD, $meta, "Fishing Rod"); } + + //TODO } \ No newline at end of file diff --git a/src/pocketmine/item/Flint.php b/src/pocketmine/item/Flint.php deleted file mode 100644 index a9a5a86a1..000000000 --- a/src/pocketmine/item/Flint.php +++ /dev/null @@ -1,32 +0,0 @@ -setBlock($block, BlockFactory::get(Block::FIRE), true); if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){ if($this->getDamage() >= $this->getMaxDurability()){ - $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0)); + $player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 0)); }else{ $this->meta++; $player->getInventory()->setItemInHand($this); @@ -52,4 +52,8 @@ class FlintSteel extends Tool{ return false; } + + public function getMaxDurability(){ + return 65; + } } \ No newline at end of file diff --git a/src/pocketmine/item/FlowerPot.php b/src/pocketmine/item/FlowerPot.php index 9c880bbd3..b0ab35fd4 100644 --- a/src/pocketmine/item/FlowerPot.php +++ b/src/pocketmine/item/FlowerPot.php @@ -27,8 +27,8 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class FlowerPot extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::FLOWER_POT_BLOCK); - parent::__construct(self::FLOWER_POT, $meta, $count, "Flower Pot"); + parent::__construct(self::FLOWER_POT, $meta, "Flower Pot"); } } \ No newline at end of file diff --git a/src/pocketmine/item/GlassBottle.php b/src/pocketmine/item/GlassBottle.php index cfddc4d9f..682eecacf 100644 --- a/src/pocketmine/item/GlassBottle.php +++ b/src/pocketmine/item/GlassBottle.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\item; class GlassBottle extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::GLASS_BOTTLE, $meta, $count, "Glass Bottle"); + public function __construct(int $meta = 0){ + parent::__construct(self::GLASS_BOTTLE, $meta, "Glass Bottle"); } } diff --git a/src/pocketmine/item/GlisteringMelon.php b/src/pocketmine/item/GlisteringMelon.php deleted file mode 100644 index 1ef5836b1..000000000 --- a/src/pocketmine/item/GlisteringMelon.php +++ /dev/null @@ -1,30 +0,0 @@ -block = BlockFactory::get(Block::IRON_DOOR_BLOCK); - parent::__construct(self::IRON_DOOR, $meta, $count, "Iron Door"); + parent::__construct(self::IRON_DOOR, $meta, "Iron Door"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/IronHelmet.php b/src/pocketmine/item/IronHelmet.php index e2d3cb594..325563648 100644 --- a/src/pocketmine/item/IronHelmet.php +++ b/src/pocketmine/item/IronHelmet.php @@ -25,7 +25,11 @@ namespace pocketmine\item; class IronHelmet extends Armor{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::IRON_HELMET, $meta, $count, "Iron Helmet"); + public function __construct(int $meta = 0){ + parent::__construct(self::IRON_HELMET, $meta, "Iron Helmet"); + } + + public function getDefensePoints() : int{ + return 2; } } \ No newline at end of file diff --git a/src/pocketmine/item/IronHoe.php b/src/pocketmine/item/IronHoe.php index 8872a34ea..02205d607 100644 --- a/src/pocketmine/item/IronHoe.php +++ b/src/pocketmine/item/IronHoe.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class IronHoe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::IRON_HOE, $meta, $count, "Iron Hoe"); + public function __construct(int $meta = 0){ + parent::__construct(self::IRON_HOE, $meta, "Iron Hoe"); } public function isHoe(){ diff --git a/src/pocketmine/item/IronIngot.php b/src/pocketmine/item/IronIngot.php deleted file mode 100644 index 653afea9a..000000000 --- a/src/pocketmine/item/IronIngot.php +++ /dev/null @@ -1,32 +0,0 @@ -id = $id & 0xffff; $this->meta = $meta !== -1 ? $meta & 0xffff : -1; - $this->count = $count; $this->name = $name; if(!isset($this->block) and $this->id <= 0xff and isset(BlockFactory::$list[$this->id])){ $this->block = BlockFactory::get($this->id, $this->meta); @@ -631,9 +635,12 @@ class Item implements ItemIds, \JsonSerializable{ /** * @param int $count + * @return $this */ public function setCount(int $count){ $this->count = $count; + + return $this; } public function isNull() : bool{ @@ -709,9 +716,12 @@ class Item implements ItemIds, \JsonSerializable{ /** * @param int $meta + * @return $this */ public function setDamage(int $meta){ $this->meta = $meta !== -1 ? $meta & 0xFFFF : -1; + + return $this; } /** @@ -740,6 +750,22 @@ class Item implements ItemIds, \JsonSerializable{ return 0; } + /** + * Returns how many points of damage this item will deal to an entity when used as a weapon. + * @return int + */ + public function getAttackPoints() : int{ + return 1; + } + + /** + * Returns how many armor points can be gained by wearing this item. + * @return int + */ + public function getDefensePoints() : int{ + return 0; + } + /** * @param Entity|Block $object * @@ -807,6 +833,16 @@ class Item implements ItemIds, \JsonSerializable{ return false; } + /** + * Called when a player is using this item and releases it. Used to handle bow shoot actions. + * + * @param Player $player + * @return bool + */ + public function onReleaseUsing(Player $player) : bool{ + return false; + } + /** * Compares an Item to this Item and check if they match. * diff --git a/src/pocketmine/item/ItemBlock.php b/src/pocketmine/item/ItemBlock.php index c7ea32080..05a9c1334 100644 --- a/src/pocketmine/item/ItemBlock.php +++ b/src/pocketmine/item/ItemBlock.php @@ -29,14 +29,19 @@ use pocketmine\block\Block; * Class used for Items that can be Blocks */ class ItemBlock extends Item{ - public function __construct(Block $block, $meta = 0, int $count = 1){ + + /** + * @param Block $block + * @param int $meta Used in crafting recipes for any-damage ingredients (blocks must have meta values 0-15) + */ + public function __construct(Block $block, int $meta = 0){ $this->block = $block; - parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName()); + parent::__construct($block->getId(), $meta, $block->getName()); } public function setDamage(int $meta){ - $this->meta = $meta !== -1 ? $meta & 0xf : -1; - $this->block->setDamage($this->meta !== -1 ? $this->meta : 0); + $this->meta = $meta; + $this->block->setDamage($this->meta !== -1 ? $this->meta & 0xf : 0); } public function getBlock() : Block{ diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index 382d27cab..b3a729ebf 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -46,9 +46,9 @@ class ItemFactory{ self::registerItem(new Bow()); self::registerItem(new Arrow()); self::registerItem(new Coal()); - self::registerItem(new Diamond()); - self::registerItem(new IronIngot()); - self::registerItem(new GoldIngot()); + self::registerItem(new Item(Item::DIAMOND, 0, "Diamond")); + self::registerItem(new Item(Item::IRON_INGOT, 0, "Iron Ingot")); + self::registerItem(new Item(Item::GOLD_INGOT, 0, "Gold Ingot")); self::registerItem(new IronSword()); self::registerItem(new WoodenSword()); self::registerItem(new WoodenShovel()); @@ -70,15 +70,15 @@ class ItemFactory{ self::registerItem(new GoldPickaxe()); self::registerItem(new GoldAxe()); self::registerItem(new StringItem()); - self::registerItem(new Feather()); - self::registerItem(new Gunpowder()); + self::registerItem(new Item(Item::FEATHER, 0, "Feather")); + self::registerItem(new Item(Item::GUNPOWDER, 0, "Gunpowder")); self::registerItem(new WoodenHoe()); self::registerItem(new StoneHoe()); self::registerItem(new IronHoe()); self::registerItem(new DiamondHoe()); self::registerItem(new GoldHoe()); self::registerItem(new WheatSeeds()); - self::registerItem(new Wheat()); + self::registerItem(new Item(Item::WHEAT, 0, "Wheat")); self::registerItem(new Bread()); self::registerItem(new LeatherCap()); self::registerItem(new LeatherTunic()); @@ -100,7 +100,7 @@ class ItemFactory{ self::registerItem(new GoldChestplate()); self::registerItem(new GoldLeggings()); self::registerItem(new GoldBoots()); - self::registerItem(new Flint()); + self::registerItem(new Item(Item::FLINT, 0, "Flint")); self::registerItem(new RawPorkchop()); self::registerItem(new CookedPorkchop()); self::registerItem(new Painting()); @@ -110,35 +110,36 @@ class ItemFactory{ self::registerItem(new Bucket()); self::registerItem(new Minecart()); - + //TODO: SADDLE self::registerItem(new IronDoor()); self::registerItem(new Redstone()); self::registerItem(new Snowball()); self::registerItem(new Boat()); - self::registerItem(new Leather()); + self::registerItem(new Item(Item::LEATHER, 0, "Leather")); - self::registerItem(new Brick()); - self::registerItem(new Clay()); + self::registerItem(new Item(Item::BRICK, 0, "Brick")); + self::registerItem(new Item(Item::CLAY_BALL, 0, "Clay")); self::registerItem(new Sugarcane()); - self::registerItem(new Paper()); + self::registerItem(new Item(Item::PAPER, 0, "Paper")); self::registerItem(new Book()); - self::registerItem(new Slimeball()); + self::registerItem(new Item(Item::SLIME_BALL, 0, "Slimeball")); + //TODO: CHEST_MINECART self::registerItem(new Egg()); self::registerItem(new Compass()); self::registerItem(new FishingRod()); self::registerItem(new Clock()); - self::registerItem(new GlowstoneDust()); + self::registerItem(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust")); self::registerItem(new Fish()); self::registerItem(new CookedFish()); self::registerItem(new Dye()); - self::registerItem(new Bone()); - self::registerItem(new Sugar()); + self::registerItem(new Item(Item::BONE, 0, "Bone")); + self::registerItem(new Item(Item::SUGAR, 0, "Sugar")); self::registerItem(new Cake()); self::registerItem(new Bed()); - + //TODO: REPEATER self::registerItem(new Cookie()); - + //TODO: FILLED_MAP self::registerItem(new Shears()); self::registerItem(new Melon()); self::registerItem(new PumpkinSeeds()); @@ -147,45 +148,92 @@ class ItemFactory{ self::registerItem(new Steak()); self::registerItem(new RawChicken()); self::registerItem(new CookedChicken()); - - self::registerItem(new GoldNugget()); + //TODO: ROTTEN_FLESH + //TODO: ENDER_PEARL + //TODO: BLAZE_ROD + //TODO: GHAST_TEAR + self::registerItem(new Item(Item::GOLD_NUGGET, 0, "Gold Nugget")); self::registerItem(new NetherWart()); self::registerItem(new Potion()); self::registerItem(new GlassBottle()); self::registerItem(new SpiderEye()); - self::registerItem(new FermentedSpiderEye()); - self::registerItem(new BlazePowder()); - self::registerItem(new MagmaCream()); + self::registerItem(new Item(Item::FERMENTED_SPIDER_EYE, 0, "Fermented Spider Eye")); + self::registerItem(new Item(Item::BLAZE_POWDER, 0, "Blaze Powder")); + self::registerItem(new Item(Item::MAGMA_CREAM, 0, "Magma Cream")); self::registerItem(new BrewingStand()); - - self::registerItem(new GlisteringMelon()); + //TODO: CAULDRON + //TODO: ENDER_EYE + self::registerItem(new Item(Item::GLISTERING_MELON, 0, "Glistering Melon")); self::registerItem(new SpawnEgg()); + //TODO: BOTTLE_O_ENCHANTING + //TODO: FIREBALL - self::registerItem(new Emerald()); + self::registerItem(new Item(Item::EMERALD, 0, "Emerald")); self::registerItem(new ItemFrame()); self::registerItem(new FlowerPot()); self::registerItem(new Carrot()); self::registerItem(new Potato()); self::registerItem(new BakedPotato()); - + //TODO: POISONOUS_POTATO + //TODO: EMPTYMAP self::registerItem(new GoldenCarrot()); self::registerItem(new Skull()); - - self::registerItem(new NetherStar()); + //TODO: CARROTONASTICK + self::registerItem(new Item(Item::NETHER_STAR, 0, "Nether Star")); self::registerItem(new PumpkinPie()); - self::registerItem(new NetherBrick()); - self::registerItem(new NetherQuartz()); - - self::registerItem(new PrismarineShard()); - + //TODO: ENCHANTED_BOOK + //TODO: COMPARATOR + self::registerItem(new Item(Item::NETHER_BRICK, 0, "Nether Brick")); + self::registerItem(new Item(Item::NETHER_QUARTZ, 0, "Nether Quartz")); + //TODO: MINECART_WITH_TNT + //TODO: HOPPER_MINECART + self::registerItem(new Item(Item::PRISMARINE_SHARD, 0, "Prismarine Shard")); + //TODO: HOPPER + //TODO: RABBIT self::registerItem(new CookedRabbit()); + //TODO: RABBIT_STEW + //TODO: RABBIT_FOOT + //TODO: RABBIT_HIDE + //TODO: HORSEARMORLEATHER + //TODO: HORSEARMORIRON + //TODO: GOLD_HORSE_ARMOR + //TODO: DIAMOND_HORSE_ARMOR + //TODO: LEAD + //TODO: NAMETAG + self::registerItem(new Item(Item::PRISMARINE_CRYSTALS, 0, "Prismarine Crystals")); + //TODO: MUTTONRAW + //TODO: COOKED_MUTTON - self::registerItem(new PrismarineCrystals()); + //TODO: END_CRYSTAL + //TODO: SPRUCE_DOOR + //TODO: BIRCH_DOOR + //TODO: JUNGLE_DOOR + //TODO: ACACIA_DOOR + //TODO: DARK_OAK_DOOR + //TODO: CHORUS_FRUIT + //TODO: CHORUS_FRUIT_POPPED + + //TODO: DRAGON_BREATH + //TODO: SPLASH_POTION + + //TODO: LINGERING_POTION + + //TODO: COMMAND_BLOCK_MINECART + //TODO: ELYTRA + //TODO: SHULKER_SHELL + + //TODO: TOTEM + + //TODO: IRON_NUGGET self::registerItem(new Beetroot()); self::registerItem(new BeetrootSeeds()); self::registerItem(new BeetrootSoup()); + //TODO: RAW_SALMON + //TODO: CLOWNFISH + //TODO: PUFFERFISH + //TODO: COOKED_SALMON self::registerItem(new GoldenAppleEnchanted()); } @@ -224,28 +272,36 @@ class ItemFactory{ * @param CompoundTag|string $tags * * @return Item + * @throws \TypeError */ public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ + if(!is_string($tags) and !($tags instanceof CompoundTag)){ + throw new \TypeError("`tags` argument must be a string or CompoundTag instance, " . (is_object($tags) ? "instance of " . get_class($tags) : gettype($tags)) . " given"); + } + + $item = null; try{ if($id < 256){ - return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags); + /* Blocks must have a damage value 0-15, but items can have damage value -1 to indicate that they are + * crafting ingredients with any-damage. */ + $item = new ItemBlock(BlockFactory::get($id, $meta !== -1 ? $meta & 0xf : 0), $meta); }else{ - /** @var Item|null $item */ - $item = self::$list[$id]; - if($item === null){ - return (new Item($id, $meta, $count))->setCompoundTag($tags); - }else{ - $item = clone $item; - $item->setDamage($meta); - $item->setCount($count); - $item->setCompoundTag($tags); - - return $item; + /** @var Item|null $listed */ + $listed = self::$list[$id]; + if($listed !== null){ + $item = clone $listed; } } }catch(\RuntimeException $e){ - return (new Item($id, $meta, $count))->setCompoundTag($tags); + throw new \InvalidArgumentException("Item ID $id is invalid or out of bounds"); } + + $item = ($item ?? new Item($id, $meta)); + + $item->setDamage($meta); + $item->setCount($count); + $item->setCompoundTag($tags); + return $item; } /** diff --git a/src/pocketmine/item/ItemFrame.php b/src/pocketmine/item/ItemFrame.php index 59491f78d..9ee88ace0 100644 --- a/src/pocketmine/item/ItemFrame.php +++ b/src/pocketmine/item/ItemFrame.php @@ -27,8 +27,8 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class ItemFrame extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::ITEM_FRAME_BLOCK); - parent::__construct(self::ITEM_FRAME, $meta, $count, "Item Frame"); + parent::__construct(self::ITEM_FRAME, $meta, "Item Frame"); } } \ No newline at end of file diff --git a/src/pocketmine/item/ItemIds.php b/src/pocketmine/item/ItemIds.php index 2998a8c66..40f2bcd26 100644 --- a/src/pocketmine/item/ItemIds.php +++ b/src/pocketmine/item/ItemIds.php @@ -175,7 +175,7 @@ interface ItemIds extends BlockIds{ const FIREWORKSCHARGE = 402, FIREWORKS_CHARGE = 402; const ENCHANTED_BOOK = 403; const COMPARATOR = 404; - const NETHERBRICK = 405; + const NETHERBRICK = 405, NETHER_BRICK = 405; const NETHER_QUARTZ = 406, QUARTZ = 406; const MINECART_WITH_TNT = 407, TNT_MINECART = 407; const HOPPER_MINECART = 408, MINECART_WITH_HOPPER = 408; diff --git a/src/pocketmine/item/Leather.php b/src/pocketmine/item/Leather.php deleted file mode 100644 index 412966daa..000000000 --- a/src/pocketmine/item/Leather.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::MELON_STEM); - parent::__construct(self::MELON_SEEDS, $meta, $count, "Melon Seeds"); + parent::__construct(self::MELON_SEEDS, $meta, "Melon Seeds"); } } \ No newline at end of file diff --git a/src/pocketmine/item/Minecart.php b/src/pocketmine/item/Minecart.php index ce06e9c72..9454c57ee 100644 --- a/src/pocketmine/item/Minecart.php +++ b/src/pocketmine/item/Minecart.php @@ -24,9 +24,10 @@ declare(strict_types=1); namespace pocketmine\item; class Minecart extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::MINECART, $meta, $count, "Minecart"); + public function __construct(int $meta = 0){ + parent::__construct(self::MINECART, $meta, "Minecart"); } + //TODO } diff --git a/src/pocketmine/item/MushroomStew.php b/src/pocketmine/item/MushroomStew.php index 51929c5ec..8a2db5d08 100644 --- a/src/pocketmine/item/MushroomStew.php +++ b/src/pocketmine/item/MushroomStew.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class MushroomStew extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::MUSHROOM_STEW, $meta, $count, "Mushroom Stew"); + public function __construct(int $meta = 0){ + parent::__construct(self::MUSHROOM_STEW, $meta, "Mushroom Stew"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/NetherBrick.php b/src/pocketmine/item/NetherBrick.php deleted file mode 100644 index bffa9330c..000000000 --- a/src/pocketmine/item/NetherBrick.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::NETHER_WART_PLANT); - parent::__construct(self::NETHER_WART, $meta, $count, "Nether Wart"); + parent::__construct(self::NETHER_WART, $meta, "Nether Wart"); } } diff --git a/src/pocketmine/item/Painting.php b/src/pocketmine/item/Painting.php index badfaf701..c521675d6 100644 --- a/src/pocketmine/item/Painting.php +++ b/src/pocketmine/item/Painting.php @@ -29,8 +29,8 @@ use pocketmine\math\Vector3; use pocketmine\Player; class Painting extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::PAINTING, $meta, $count, "Painting"); + public function __construct(int $meta = 0){ + parent::__construct(self::PAINTING, $meta, "Painting"); } public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ diff --git a/src/pocketmine/item/Paper.php b/src/pocketmine/item/Paper.php deleted file mode 100644 index 99f185eca..000000000 --- a/src/pocketmine/item/Paper.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::POTATO_BLOCK); - parent::__construct(self::POTATO, $meta, $count, "Potato"); + parent::__construct(self::POTATO, $meta, "Potato"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/Potion.php b/src/pocketmine/item/Potion.php index a8d6f62e3..af52c249a 100644 --- a/src/pocketmine/item/Potion.php +++ b/src/pocketmine/item/Potion.php @@ -26,8 +26,8 @@ namespace pocketmine\item; use pocketmine\entity\Entity; class Potion extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::POTION, $meta, $count, "Potion"); + public function __construct(int $meta = 0){ + parent::__construct(self::POTION, $meta, "Potion"); } public function canBeConsumed() : bool{ diff --git a/src/pocketmine/item/PrismarineCrystals.php b/src/pocketmine/item/PrismarineCrystals.php deleted file mode 100644 index 0d50309f3..000000000 --- a/src/pocketmine/item/PrismarineCrystals.php +++ /dev/null @@ -1,31 +0,0 @@ -block = BlockFactory::get(Block::PUMPKIN_STEM); - parent::__construct(self::PUMPKIN_SEEDS, $meta, $count, "Pumpkin Seeds"); + parent::__construct(self::PUMPKIN_SEEDS, $meta, "Pumpkin Seeds"); } } \ No newline at end of file diff --git a/src/pocketmine/item/RawBeef.php b/src/pocketmine/item/RawBeef.php index bce963e60..88a46265b 100644 --- a/src/pocketmine/item/RawBeef.php +++ b/src/pocketmine/item/RawBeef.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class RawBeef extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::RAW_BEEF, $meta, $count, "Raw Beef"); + public function __construct(int $meta = 0){ + parent::__construct(self::RAW_BEEF, $meta, "Raw Beef"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/RawChicken.php b/src/pocketmine/item/RawChicken.php index a6f211d3b..fadcbde29 100644 --- a/src/pocketmine/item/RawChicken.php +++ b/src/pocketmine/item/RawChicken.php @@ -26,8 +26,8 @@ namespace pocketmine\item; use pocketmine\entity\Effect; class RawChicken extends Food{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::RAW_CHICKEN, $meta, $count, "Raw Chicken"); + public function __construct(int $meta = 0){ + parent::__construct(self::RAW_CHICKEN, $meta, "Raw Chicken"); } public function getFoodRestore() : int{ diff --git a/src/pocketmine/item/RawPorkchop.php b/src/pocketmine/item/RawPorkchop.php index 4c9f58e86..d5e56725d 100644 --- a/src/pocketmine/item/RawPorkchop.php +++ b/src/pocketmine/item/RawPorkchop.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\item; class RawPorkchop extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::RAW_PORKCHOP, $meta, $count, "Raw Porkchop"); + public function __construct(int $meta = 0){ + parent::__construct(self::RAW_PORKCHOP, $meta, "Raw Porkchop"); } } diff --git a/src/pocketmine/item/Redstone.php b/src/pocketmine/item/Redstone.php index 57ffdd899..9f1784f2e 100644 --- a/src/pocketmine/item/Redstone.php +++ b/src/pocketmine/item/Redstone.php @@ -23,9 +23,13 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\block\Block; +use pocketmine\block\BlockFactory; + class Redstone extends Item{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::REDSTONE, $meta, $count, "Redstone"); + public function __construct(int $meta = 0){ + $this->block = BlockFactory::get(Block::REDSTONE_WIRE); + parent::__construct(self::REDSTONE, $meta, "Redstone"); } } diff --git a/src/pocketmine/item/Shears.php b/src/pocketmine/item/Shears.php index 7c740484f..36d377185 100644 --- a/src/pocketmine/item/Shears.php +++ b/src/pocketmine/item/Shears.php @@ -25,7 +25,15 @@ namespace pocketmine\item; class Shears extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::SHEARS, $meta, $count, "Shears"); + public function __construct(int $meta = 0){ + parent::__construct(self::SHEARS, $meta, "Shears"); + } + + public function getMaxDurability(){ + return 239; + } + + public function isShears(){ + return true; } } \ No newline at end of file diff --git a/src/pocketmine/item/Sign.php b/src/pocketmine/item/Sign.php index 42e97f844..834be4e9a 100644 --- a/src/pocketmine/item/Sign.php +++ b/src/pocketmine/item/Sign.php @@ -27,9 +27,9 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class Sign extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::SIGN_POST); - parent::__construct(self::SIGN, $meta, $count, "Sign"); + parent::__construct(self::SIGN, $meta, "Sign"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/Skull.php b/src/pocketmine/item/Skull.php index b5608f181..403418797 100644 --- a/src/pocketmine/item/Skull.php +++ b/src/pocketmine/item/Skull.php @@ -27,8 +27,8 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class Skull extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::SKULL_BLOCK); - parent::__construct(self::SKULL, $meta, $count, "Mob Head"); + parent::__construct(self::SKULL, $meta, "Mob Head"); } } \ No newline at end of file diff --git a/src/pocketmine/item/Slimeball.php b/src/pocketmine/item/Slimeball.php deleted file mode 100644 index 21b07a799..000000000 --- a/src/pocketmine/item/Slimeball.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::TRIPWIRE); + parent::__construct(self::STRING, $meta, "String"); } } diff --git a/src/pocketmine/item/Sugar.php b/src/pocketmine/item/Sugar.php deleted file mode 100644 index 65ff2cc14..000000000 --- a/src/pocketmine/item/Sugar.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::SUGARCANE_BLOCK); - parent::__construct(self::SUGARCANE, $meta, $count, "Sugar Cane"); + parent::__construct(self::SUGARCANE, $meta, "Sugar Cane"); } } \ No newline at end of file diff --git a/src/pocketmine/item/Tool.php b/src/pocketmine/item/Tool.php index c1621bbb0..b2b612f30 100644 --- a/src/pocketmine/item/Tool.php +++ b/src/pocketmine/item/Tool.php @@ -40,10 +40,6 @@ abstract class Tool extends Item{ const TYPE_AXE = 4; const TYPE_SHEARS = 5; - public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ - parent::__construct($id, $meta, $count, $name); - } - public function getMaxStackSize(){ return 1; } @@ -97,10 +93,7 @@ abstract class Tool extends Item{ Tool::TIER_WOODEN => 60, Tool::TIER_STONE => 132, Tool::TIER_IRON => 251, - Tool::TIER_DIAMOND => 1562, - self::FLINT_STEEL => 65, - self::SHEARS => 239, - self::BOW => 385, + Tool::TIER_DIAMOND => 1562 ]; if(($type = $this->isPickaxe()) === false){ @@ -108,7 +101,7 @@ abstract class Tool extends Item{ if(($type = $this->isSword()) === false){ if(($type = $this->isShovel()) === false){ if(($type = $this->isHoe()) === false){ - $type = $this->id; + return false; } } } @@ -123,31 +116,7 @@ abstract class Tool extends Item{ return $tag !== null and $tag->getValue() > 0; } - public function isPickaxe(){ - return false; - } - - public function isAxe(){ - return false; - } - - public function isSword(){ - return false; - } - - public function isShovel(){ - return false; - } - - public function isHoe(){ - return false; - } - - public function isShears(){ - return ($this->id === self::SHEARS); - } - public function isTool(){ - return ($this->id === self::FLINT_STEEL or $this->id === self::SHEARS or $this->id === self::BOW or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false); + return true; } } \ No newline at end of file diff --git a/src/pocketmine/item/Wheat.php b/src/pocketmine/item/Wheat.php deleted file mode 100644 index ec12acefe..000000000 --- a/src/pocketmine/item/Wheat.php +++ /dev/null @@ -1,32 +0,0 @@ -block = BlockFactory::get(Block::WHEAT_BLOCK); - parent::__construct(self::WHEAT_SEEDS, $meta, $count, "Wheat Seeds"); + parent::__construct(self::WHEAT_SEEDS, $meta, "Wheat Seeds"); } } \ No newline at end of file diff --git a/src/pocketmine/item/WoodenAxe.php b/src/pocketmine/item/WoodenAxe.php index 5def14b7d..8cb28d2fb 100644 --- a/src/pocketmine/item/WoodenAxe.php +++ b/src/pocketmine/item/WoodenAxe.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class WoodenAxe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::WOODEN_AXE, $meta, $count, "Wooden Axe"); + public function __construct(int $meta = 0){ + parent::__construct(self::WOODEN_AXE, $meta, "Wooden Axe"); } public function isAxe(){ @@ -36,4 +36,8 @@ class WoodenAxe extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 4; + } } diff --git a/src/pocketmine/item/WoodenDoor.php b/src/pocketmine/item/WoodenDoor.php index d233cc1a3..3ea688ad3 100644 --- a/src/pocketmine/item/WoodenDoor.php +++ b/src/pocketmine/item/WoodenDoor.php @@ -27,9 +27,9 @@ use pocketmine\block\Block; use pocketmine\block\BlockFactory; class WoodenDoor extends Item{ - public function __construct($meta = 0, $count = 1){ + public function __construct(int $meta = 0){ $this->block = BlockFactory::get(Block::WOODEN_DOOR_BLOCK); - parent::__construct(self::WOODEN_DOOR, $meta, $count, "Wooden Door"); + parent::__construct(self::WOODEN_DOOR, $meta, "Wooden Door"); } public function getMaxStackSize(){ diff --git a/src/pocketmine/item/WoodenHoe.php b/src/pocketmine/item/WoodenHoe.php index b9926cc0e..ab2faa729 100644 --- a/src/pocketmine/item/WoodenHoe.php +++ b/src/pocketmine/item/WoodenHoe.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class WoodenHoe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::WOODEN_HOE, $meta, $count, "Wooden Hoe"); + public function __construct(int $meta = 0){ + parent::__construct(self::WOODEN_HOE, $meta, "Wooden Hoe"); } public function isHoe(){ diff --git a/src/pocketmine/item/WoodenPickaxe.php b/src/pocketmine/item/WoodenPickaxe.php index 66d28b537..a2df1dc71 100644 --- a/src/pocketmine/item/WoodenPickaxe.php +++ b/src/pocketmine/item/WoodenPickaxe.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class WoodenPickaxe extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::WOODEN_PICKAXE, $meta, $count, "Wooden Pickaxe"); + public function __construct(int $meta = 0){ + parent::__construct(self::WOODEN_PICKAXE, $meta, "Wooden Pickaxe"); } public function isPickaxe(){ @@ -36,4 +36,8 @@ class WoodenPickaxe extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 3; + } } diff --git a/src/pocketmine/item/WoodenShovel.php b/src/pocketmine/item/WoodenShovel.php index e12907a47..8582ba97f 100644 --- a/src/pocketmine/item/WoodenShovel.php +++ b/src/pocketmine/item/WoodenShovel.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class WoodenShovel extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::WOODEN_SHOVEL, $meta, $count, "Wooden Shovel"); + public function __construct(int $meta = 0){ + parent::__construct(self::WOODEN_SHOVEL, $meta, "Wooden Shovel"); } public function isShovel(){ @@ -36,4 +36,8 @@ class WoodenShovel extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 2; + } } diff --git a/src/pocketmine/item/WoodenSword.php b/src/pocketmine/item/WoodenSword.php index 5a1d52643..37d9ccfa7 100644 --- a/src/pocketmine/item/WoodenSword.php +++ b/src/pocketmine/item/WoodenSword.php @@ -25,8 +25,8 @@ namespace pocketmine\item; class WoodenSword extends Tool{ - public function __construct($meta = 0, $count = 1){ - parent::__construct(self::WOODEN_SWORD, $meta, $count, "Wooden Sword"); + public function __construct(int $meta = 0){ + parent::__construct(self::WOODEN_SWORD, $meta, "Wooden Sword"); } public function isSword(){ @@ -36,4 +36,8 @@ class WoodenSword extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 5; + } } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 55d1d6f16..fdac6aa92 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -26,28 +26,8 @@ declare(strict_types=1); */ namespace pocketmine\level; -use pocketmine\block\Beetroot; use pocketmine\block\Block; use pocketmine\block\BlockFactory; -use pocketmine\block\BrownMushroom; -use pocketmine\block\Cactus; -use pocketmine\block\Carrot; -use pocketmine\block\Farmland; -use pocketmine\block\Fire; -use pocketmine\block\Grass; -use pocketmine\block\Ice; -use pocketmine\block\Leaves; -use pocketmine\block\Leaves2; -use pocketmine\block\MelonStem; -use pocketmine\block\Mycelium; -use pocketmine\block\NetherWartPlant; -use pocketmine\block\Potato; -use pocketmine\block\PumpkinStem; -use pocketmine\block\RedMushroom; -use pocketmine\block\Sapling; -use pocketmine\block\SnowLayer; -use pocketmine\block\Sugarcane; -use pocketmine\block\Wheat; use pocketmine\entity\Arrow; use pocketmine\entity\Effect; use pocketmine\entity\Entity; @@ -227,30 +207,8 @@ class Level implements ChunkManager, Metadatable{ private $chunkTickList = []; private $chunksPerTick; private $clearChunksOnTick; - private $randomTickBlocks = [ - Block::GRASS => Grass::class, - Block::SAPLING => Sapling::class, - Block::LEAVES => Leaves::class, - Block::WHEAT_BLOCK => Wheat::class, - Block::FARMLAND => Farmland::class, - Block::SNOW_LAYER => SnowLayer::class, - Block::ICE => Ice::class, - Block::CACTUS => Cactus::class, - Block::SUGARCANE_BLOCK => Sugarcane::class, - Block::RED_MUSHROOM => RedMushroom::class, - Block::BROWN_MUSHROOM => BrownMushroom::class, - Block::PUMPKIN_STEM => PumpkinStem::class, - Block::MELON_STEM => MelonStem::class, - //Block::VINE => true, - Block::MYCELIUM => Mycelium::class, - //Block::COCOA_BLOCK => true, - Block::CARROT_BLOCK => Carrot::class, - Block::POTATO_BLOCK => Potato::class, - Block::LEAVES2 => Leaves2::class, - Block::FIRE => Fire::class, - Block::BEETROOT_BLOCK => Beetroot::class, - Block::NETHER_WART_PLANT => NetherWartPlant::class - ]; + /** @var \SplFixedArray */ + private $randomTickBlocks = null; /** @var LevelTimings */ public $timings; @@ -344,10 +302,19 @@ class Level implements ChunkManager, Metadatable{ $this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true); $this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false); + $this->randomTickBlocks = \SplFixedArray::fromArray(array_filter(BlockFactory::$list->toArray(), function(Block $block = null){ + return $block !== null and $block->ticksRandomly(); + })); + $this->randomTickBlocks->setSize(256); + $dontTickBlocks = $this->server->getProperty("chunk-ticking.disable-block-ticking", []); foreach($dontTickBlocks as $id){ - if(isset($this->randomTickBlocks[$id])){ - unset($this->randomTickBlocks[$id]); + try{ + if(isset($this->randomTickBlocks[$id])){ + $this->randomTickBlocks[$id] = null; + } + }catch(\RuntimeException $e){ + //index out of bounds } } @@ -912,11 +879,11 @@ class Level implements ChunkManager, Metadatable{ } public function addRandomTickedBlock(int $id){ - $this->randomTickBlocks[$id] = get_class(BlockFactory::$list[$id]); + $this->randomTickBlocks[$id] = BlockFactory::get($id); } public function removeRandomTickedBlock(int $id){ - unset($this->randomTickBlocks[$id]); + $this->randomTickBlocks[$id] = null; } private function tickChunks(){ @@ -964,17 +931,18 @@ class Level implements ChunkManager, Metadatable{ foreach($chunk->getSubChunks() as $Y => $subChunk){ if(!$subChunk->isEmpty()){ - $k = mt_rand(0, 0x7fffffff); - for($i = 0; $i < 3; ++$i, $k >>= 10){ + for($i = 0; $i < 3; ++$i){ + $k = mt_rand(0, 0xfff); $x = $k & 0x0f; - $y = ($k >> 8) & 0x0f; - $z = ($k >> 16) & 0x0f; + $y = ($k >> 4) & 0x0f; + $z = ($k >> 8) & 0x0f; $blockId = $subChunk->getBlockId($x, $y, $z); - if(isset($this->randomTickBlocks[$blockId])){ - $class = $this->randomTickBlocks[$blockId]; + if($this->randomTickBlocks[$blockId] !== null){ /** @var Block $block */ - $block = new $class($subChunk->getBlockData($x, $y, $z)); + $block = clone $this->randomTickBlocks[$blockId]; + $block->setDamage($subChunk->getBlockData($x, $y, $z)); + $block->x = $chunkX * 16 + $x; $block->y = ($Y << 4) + $y; $block->z = $chunkZ * 16 + $z; @@ -1567,6 +1535,27 @@ class Level implements ChunkManager, Metadatable{ return null; } + /** + * Checks if the level spawn protection radius will prevent the player from using items or building at the specified + * Vector3 position. + * + * @param Player $player + * @param Vector3 $vector + * + * @return bool false if spawn protection cancelled the action, true if not. + */ + protected function checkSpawnProtection(Player $player, Vector3 $vector) : bool{ + if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){ + $t = new Vector2($vector->x, $vector->z); + $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); + if(count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance){ + return true; + } + } + + return false; + } + /** * Tries to break a block using a item, including Player time checks if available * It'll try to lower the durability if Item is a tool, and set it to Air if broken. @@ -1590,12 +1579,8 @@ class Level implements ChunkManager, Metadatable{ if(($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) or $player->isSpectator()){ $ev->setCancelled(); - }elseif(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){ - $t = new Vector2($target->x, $target->z); - $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); - if(count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance){ //set it to cancelled so plugins can bypass this - $ev->setCancelled(); - } + }elseif($this->checkSpawnProtection($player, $target)){ + $ev->setCancelled(); //set it to cancelled so plugins can bypass this } if($player->isAdventure(true) and !$ev->isCancelled()){ @@ -1710,30 +1695,26 @@ class Level implements ChunkManager, Metadatable{ * @return bool */ public function useItemOn(Vector3 $vector, Item &$item, int $face, Vector3 $facePos = null, Player $player = null, bool $playSound = false) : bool{ - $target = $this->getBlock($vector); - $block = $target->getSide($face); + $blockClicked = $this->getBlock($vector); + $blockReplace = $blockClicked->getSide($face); if($facePos === null){ $facePos = new Vector3(0.0, 0.0, 0.0); } - if($block->y >= $this->provider->getWorldHeight() or $block->y < 0){ + if($blockReplace->y >= $this->provider->getWorldHeight() or $blockReplace->y < 0){ //TODO: build height limit messages for custom world heights and mcregion cap return false; } - if($target->getId() === Item::AIR){ + if($blockClicked->getId() === Item::AIR){ return false; } if($player !== null){ - $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); - if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){ - $t = new Vector2($target->x, $target->z); - $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); - if(count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance){ //set it to cancelled so plugins can bypass this - $ev->setCancelled(); - } + $ev = new PlayerInteractEvent($player, $item, $blockClicked, $face, $blockClicked->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); + if($this->checkSpawnProtection($player, $blockClicked)){ + $ev->setCancelled(); //set it to cancelled so plugins can bypass this } if($player->isAdventure(true) and !$ev->isCancelled()){ @@ -1743,7 +1724,7 @@ class Level implements ChunkManager, Metadatable{ foreach($tag as $v){ if($v instanceof StringTag){ $entry = ItemFactory::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ + if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $blockClicked->getId()){ $canPlace = true; break; } @@ -1756,12 +1737,12 @@ class Level implements ChunkManager, Metadatable{ $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ - $target->onUpdate(self::BLOCK_UPDATE_TOUCH); - if(!$player->isSneaking() and $target->onActivate($item, $player) === true){ + $blockClicked->onUpdate(self::BLOCK_UPDATE_TOUCH); + if(!$player->isSneaking() and $blockClicked->onActivate($item, $player) === true){ return true; } - if(!$player->isSneaking() and $item->onActivate($this, $player, $block, $target, $face, $facePos)){ + if(!$player->isSneaking() and $item->onActivate($this, $player, $blockReplace, $blockClicked, $face, $facePos)){ if($item->getCount() <= 0){ $item = ItemFactory::get(Item::AIR, 0, 0); @@ -1771,7 +1752,7 @@ class Level implements ChunkManager, Metadatable{ }else{ return false; } - }elseif($target->onActivate($item, $player) === true){ + }elseif($blockClicked->onActivate($item, $player) === true){ return true; } @@ -1781,13 +1762,13 @@ class Level implements ChunkManager, Metadatable{ $hand = $item->getBlock(); - if($target->canBeReplaced($hand)){ - $block = $target; - }elseif(!$block->canBeReplaced($hand)){ + if($blockClicked->canBeReplaced($hand)){ + $blockReplace = $blockClicked; + }elseif(!$blockReplace->canBeReplaced($hand)){ return false; } - $hand->position($block); + $hand->position($blockReplace); if($hand->isSolid() === true and $hand->getBoundingBox() !== null){ $entities = $this->getCollidingEntities($hand->getBoundingBox()); @@ -1815,21 +1796,18 @@ class Level implements ChunkManager, Metadatable{ if($player !== null){ - $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); - if(!$player->hasPermission("pocketmine.spawnprotect.bypass") and ($distance = $this->server->getSpawnRadius()) > -1){ - $t = new Vector2($target->x, $target->z); - $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); - if(count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance){ //set it to cancelled so plugins can bypass this - $ev->setCancelled(); - } + $ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item); + if($this->checkSpawnProtection($player, $blockClicked)){ + $ev->setCancelled(); } + $this->server->getPluginManager()->callEvent($ev); if($ev->isCancelled()){ return false; } } - if(!$hand->place($item, $block, $target, $face, $facePos, $player)){ + if(!$hand->place($item, $blockReplace, $blockClicked, $face, $facePos, $player)){ return false; } diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index 9a7e6ed65..49e44bcdf 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -47,7 +47,7 @@ class AsyncPool{ $this->server = $server; $this->size = $size; - $memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024)); + $memoryLimit = (int) max(-1, (int) $this->server->getProperty("memory.async-worker-hard-limit", 1024)); for($i = 0; $i < $this->size; ++$i){ $this->workerUsage[$i] = 0;