From e1d894057c3d89406b9aca3750d217c3c3205019 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 20 Aug 2017 10:23:34 +0100 Subject: [PATCH] Changed face position floating-point params to Vector3s --- src/pocketmine/Player.php | 5 +++-- src/pocketmine/block/Anvil.php | 3 ++- src/pocketmine/block/Bed.php | 2 +- src/pocketmine/block/Block.php | 6 ++---- src/pocketmine/block/BrownMushroom.php | 2 +- src/pocketmine/block/BurningFurnace.php | 3 ++- src/pocketmine/block/Cactus.php | 2 +- src/pocketmine/block/Cake.php | 2 +- src/pocketmine/block/Carpet.php | 2 +- src/pocketmine/block/Chest.php | 2 +- src/pocketmine/block/Crops.php | 2 +- src/pocketmine/block/Dandelion.php | 2 +- src/pocketmine/block/Door.php | 2 +- src/pocketmine/block/DoublePlant.php | 2 +- src/pocketmine/block/EnchantingTable.php | 3 ++- src/pocketmine/block/EndRod.php | 2 +- src/pocketmine/block/FenceGate.php | 3 ++- src/pocketmine/block/Flower.php | 2 +- src/pocketmine/block/FlowerPot.php | 2 +- src/pocketmine/block/GlazedTerracotta.php | 3 ++- src/pocketmine/block/HayBale.php | 3 ++- src/pocketmine/block/ItemFrame.php | 3 ++- src/pocketmine/block/Ladder.php | 3 ++- src/pocketmine/block/Lava.php | 3 ++- src/pocketmine/block/Leaves.php | 2 +- src/pocketmine/block/NetherWartPlant.php | 2 +- src/pocketmine/block/Pumpkin.php | 3 ++- src/pocketmine/block/Rail.php | 2 +- src/pocketmine/block/RedMushroom.php | 2 +- src/pocketmine/block/RedstoneOre.php | 3 ++- src/pocketmine/block/Sapling.php | 2 +- src/pocketmine/block/SignPost.php | 2 +- src/pocketmine/block/Skull.php | 3 ++- src/pocketmine/block/SnowLayer.php | 2 +- src/pocketmine/block/Stair.php | 5 +++-- src/pocketmine/block/Sugarcane.php | 2 +- src/pocketmine/block/TallGrass.php | 2 +- src/pocketmine/block/Torch.php | 2 +- src/pocketmine/block/Trapdoor.php | 5 +++-- src/pocketmine/block/Vine.php | 2 +- src/pocketmine/block/Water.php | 3 ++- src/pocketmine/block/WaterLily.php | 2 +- src/pocketmine/block/Wood.php | 3 ++- src/pocketmine/block/WoodenSlab.php | 5 +++-- src/pocketmine/item/Bucket.php | 3 ++- src/pocketmine/item/FlintSteel.php | 3 ++- src/pocketmine/item/Item.php | 17 ++++++++-------- src/pocketmine/item/Painting.php | 3 ++- src/pocketmine/item/SpawnEgg.php | 3 ++- src/pocketmine/level/Level.php | 24 ++++++++++++----------- 50 files changed, 96 insertions(+), 75 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index e7312f272..f2821d830 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2364,6 +2364,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + $facePos = new Vector3($packet->fx, $packet->fy, $packet->fz); $this->craftingType = 0; @@ -2373,7 +2374,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){ }elseif($this->isCreative()){ $item = $this->inventory->getItemInHand(); - if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this, true) === true){ + if($this->level->useItemOn($blockVector, $item, $packet->face, $facePos, $this, true) === true){ return true; } }elseif(!$this->inventory->getItemInHand()->equals($packet->item)){ @@ -2381,7 +2382,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ }else{ $item = $this->inventory->getItemInHand(); $oldItem = clone $item; - if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this, true)){ + if($this->level->useItemOn($blockVector, $item, $packet->face, $facePos, $this, true)){ if(!$item->equals($oldItem) or $item->getCount() !== $oldItem->getCount()){ $this->inventory->setItemInHand($item); $this->inventory->sendHeldItem($this->hasSpawned); diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 3a8faca91..65243d59d 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\inventory\AnvilInventory; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\Player; class Anvil extends Fallable{ @@ -73,7 +74,7 @@ class Anvil extends Fallable{ return true; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, 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); diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 8016b22ae..990b3aa07 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -174,7 +174,7 @@ class Bed extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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()){ $meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 5cd2cfd03..5970a865e 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -476,14 +476,12 @@ class Block extends Position implements BlockIds, Metadatable{ * @param Block $block * @param Block $target * @param int $face - * @param float $fx - * @param float $fy - * @param float $fz + * @param Vector3 $facePos * @param Player|null $player * * @return bool */ - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, $this, true, true); } diff --git a/src/pocketmine/block/BrownMushroom.php b/src/pocketmine/block/BrownMushroom.php index 9a548843d..d5002344e 100644 --- a/src/pocketmine/block/BrownMushroom.php +++ b/src/pocketmine/block/BrownMushroom.php @@ -56,7 +56,7 @@ class BrownMushroom extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index 0afd9924a..22b06f629 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -58,7 +59,7 @@ class BurningFurnace extends Solid{ return 13; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 957376b3a..88608e4db 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -108,7 +108,7 @@ class Cactus extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->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 46149050d..85f0846c5 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -62,7 +62,7 @@ class Cake extends Transparent implements FoodSource{ ); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() !== self::AIR){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index edd54ae79..1b58fbef0 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -62,7 +62,7 @@ class Carpet extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() !== self::AIR){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index fb0d2412b..2d44e7b01 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -67,7 +67,7 @@ class Chest extends Transparent{ ); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index da387e9e7..b91781d08 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -32,7 +32,7 @@ use pocketmine\Server; abstract class Crops extends Flowable{ - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index ba8e43e11..8ccbab968 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -41,7 +41,7 @@ class Dandelion extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 7b13292b0..d070c3a3a 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, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === 1){ $blockUp = $this->getSide(Vector3::SIDE_UP); $blockDown = $this->getSide(Vector3::SIDE_DOWN); diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index 730ede9cb..386dcf4c0 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -53,7 +53,7 @@ class DoublePlant extends Flowable{ return $names[$this->meta & 0x07] ?? ""; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index 5566ca113..bf69dcb62 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\inventory\EnchantInventory; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; @@ -40,7 +41,7 @@ class EnchantingTable extends Transparent{ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::ENCHANT_TABLE), diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index ded66fe88..af4964635 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -40,7 +40,7 @@ class EndRod extends Flowable{ return "End Rod"; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){ $this->meta = $face; }else{ diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 1c1d23e9a..ba463c2d7 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -27,6 +27,7 @@ use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\Player; class FenceGate extends Transparent{ @@ -68,7 +69,7 @@ class FenceGate extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, 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); diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index c227e8a8f..80a0b36fd 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -60,7 +60,7 @@ class Flower extends Flowable{ return $names[$this->meta] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($block, $this, true); diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 623b0d8d0..206c7c089 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -62,7 +62,7 @@ class FlowerPot extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ return false; } diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index 4d6638865..47199c496 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\Player; class GlazedTerracotta extends Solid{ @@ -38,7 +39,7 @@ class GlazedTerracotta extends Solid{ return Tool::TYPE_PICKAXE; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($player !== null){ $faces = [ 0 => 4, diff --git a/src/pocketmine/block/HayBale.php b/src/pocketmine/block/HayBale.php index 7acf1afd9..f9567056e 100644 --- a/src/pocketmine/block/HayBale.php +++ b/src/pocketmine/block/HayBale.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; +use pocketmine\math\Vector3; use pocketmine\Player; class HayBale extends Solid{ @@ -42,7 +43,7 @@ class HayBale extends Solid{ return 0.5; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 0, diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 95a65855f..e6fcaa8bc 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\{ ByteTag, CompoundTag, FloatTag, IntTag, StringTag }; @@ -103,7 +104,7 @@ class ItemFrame extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face === 0 or $face === 1){ return false; } diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 471ca6fb9..be3a9f119 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -28,6 +28,7 @@ use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\Player; class Ladder extends Transparent{ @@ -109,7 +110,7 @@ class Ladder extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($target->isTransparent() === false){ $faces = [ 2 => 2, diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 67601274e..2b557fa2c 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; +use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; @@ -62,7 +63,7 @@ class Lava extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, 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 4bf918572..a83f04a51 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -159,7 +159,7 @@ class Leaves extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta |= 0x04; return $this->getLevel()->setBlock($this, $this, true); } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 743086f93..47f549d11 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -39,7 +39,7 @@ class NetherWartPlant extends Flowable{ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === Block::SOUL_SAND){ $this->getLevel()->setBlock($block, $this, false, true); diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index b2501c312..9d5c4cf20 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\Player; class Pumpkin extends Solid{ @@ -47,7 +48,7 @@ class Pumpkin extends Solid{ return "Pumpkin"; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($player instanceof Player){ $this->meta = ((int) $player->getDirection() + 1) % 4; } diff --git a/src/pocketmine/block/Rail.php b/src/pocketmine/block/Rail.php index 7cbf77326..61a21b5bd 100644 --- a/src/pocketmine/block/Rail.php +++ b/src/pocketmine/block/Rail.php @@ -55,7 +55,7 @@ class Rail extends Flowable{ return 0.7; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); } diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index 7b49bb5a7..de491b279 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -53,7 +53,7 @@ class RedMushroom extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index dbafbf15f..ba8c35214 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; class RedstoneOre extends Solid{ @@ -44,7 +45,7 @@ class RedstoneOre extends Solid{ return 3; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, 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 5c6bd9d62..d4d7f7640 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -57,7 +57,7 @@ class Sapling extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index e8db4799f..757750c58 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -60,7 +60,7 @@ class SignPost extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face !== 0){ $nbt = new CompoundTag("", [ new StringTag("id", Tile::SIGN), diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 85bdbf1fb..5d2c79750 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -62,7 +63,7 @@ class Skull extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($face !== 0){ $this->meta = $face; if($face === 1){ diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index 06f7ea3dd..12d617eb4 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -54,7 +54,7 @@ class SnowLayer extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ if($block->getSide(Vector3::SIDE_DOWN)->isSolid()){ //TODO: fix placement $this->getLevel()->setBlock($block, $this, true); diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index e7991909c..ef5277582 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\Player; abstract class Stair extends Transparent{ @@ -129,7 +130,7 @@ abstract class Stair extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 2, @@ -137,7 +138,7 @@ abstract class Stair extends Transparent{ 3 => 3, ]; $this->meta = $faces[$player->getDirection()] & 0x03; - if(($fy > 0.5 and $face !== 1) or $face === 0){ + if(($facePos->y > 0.5 and $face !== 1) or $face === 0){ $this->meta |= 0x04; //Upside-down stairs } $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index c18c6e74b..1be88f7fe 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -102,7 +102,7 @@ class Sugarcane extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === self::SUGARCANE_BLOCK){ $this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true); diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 8c5a09219..73723aa25 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -49,7 +49,7 @@ class TallGrass extends Flowable{ return $names[$this->meta & 0x03] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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->getId() === self::GRASS){ $this->getLevel()->setBlock($block, $this, true); diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 33b47d082..9b545cff4 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -68,7 +68,7 @@ class Torch extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $below = $this->getSide(Vector3::SIDE_DOWN); if($target->isTransparent() === false and $face !== 0){ diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 613193ffa..34243452c 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -27,6 +27,7 @@ use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\Player; class Trapdoor extends Transparent{ @@ -123,7 +124,7 @@ class Trapdoor extends Transparent{ return $bb; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $directions = [ 0 => 1, 1 => 3, @@ -133,7 +134,7 @@ class Trapdoor extends Transparent{ if($player !== null){ $this->meta = $directions[$player->getDirection() & 0x03]; } - if(($fy > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){ + 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); diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 893bf8073..6e64984d6 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -132,7 +132,7 @@ class Vine extends Transparent{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ //TODO: multiple sides if($target->isSolid()){ $faces = [ diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 7027b4d85..4f9ef3e76 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\entity\Entity; use pocketmine\item\Item; +use pocketmine\math\Vector3; use pocketmine\Player; class Water extends Liquid{ @@ -52,7 +53,7 @@ class Water extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, 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 05cfa1b2b..c2fb17515 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -57,7 +57,7 @@ class WaterLily extends Flowable{ } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + 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); if($up->getId() === Block::AIR){ diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 2aa208bc9..7236317fc 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\Vector3; use pocketmine\Player; class Wood extends Solid{ @@ -53,7 +54,7 @@ class Wood extends Solid{ return $names[$this->meta & 0x03]; } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 0, diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 862cdd60f..b01812376 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; use pocketmine\Player; class WoodenSlab extends Transparent{ @@ -77,7 +78,7 @@ class WoodenSlab extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ + public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{ $this->meta &= 0x07; if($face === 0){ if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta)){ @@ -111,7 +112,7 @@ class WoodenSlab extends Transparent{ return false; }else{ - if($fy > 0.5){ + if($facePos->y > 0.5){ $this->meta |= 0x08; } } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 070fc4992..50370a937 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -28,6 +28,7 @@ use pocketmine\block\Block; use pocketmine\block\Liquid; use pocketmine\event\player\PlayerBucketFillEvent; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; class Bucket extends Item{ @@ -47,7 +48,7 @@ class Bucket extends Item{ return 0; } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ $targetBlock = Block::get($this->meta); if($targetBlock instanceof Air){ diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index 6cd5d4782..a431b35e8 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\block\Fire; use pocketmine\block\Solid; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; class FlintSteel extends Tool{ @@ -34,7 +35,7 @@ class FlintSteel extends Tool{ parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel"); } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ if($block->getId() === self::AIR and ($target instanceof Solid)){ $level->setBlock($block, Block::get(Block::FIRE), true); if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){ diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index d79bccfc4..5a8171305 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -30,6 +30,7 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; use pocketmine\item\enchantment\Enchantment; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; @@ -978,18 +979,16 @@ class Item implements ItemIds, \JsonSerializable{ /** * Called when a player uses this item on a block. * - * @param Level $level - * @param Player $player - * @param Block $block - * @param Block $target - * @param int $face - * @param float $fx - * @param float $fy - * @param float $fz + * @param Level $level + * @param Player $player + * @param Block $block + * @param Block $target + * @param int $face + * @param Vector3 $facePos * * @return bool */ - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ return false; } diff --git a/src/pocketmine/item/Painting.php b/src/pocketmine/item/Painting.php index db459ce85..badfaf701 100644 --- a/src/pocketmine/item/Painting.php +++ b/src/pocketmine/item/Painting.php @@ -25,6 +25,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\Player; class Painting extends Item{ @@ -32,7 +33,7 @@ class Painting extends Item{ parent::__construct(self::PAINTING, $meta, $count, "Painting"); } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ if($target->isTransparent() === false and $face > 1 and $block->isSolid() === false){ $faces = [ 2 => 1, diff --git a/src/pocketmine/item/SpawnEgg.php b/src/pocketmine/item/SpawnEgg.php index 2ba0c7554..99c2d1692 100644 --- a/src/pocketmine/item/SpawnEgg.php +++ b/src/pocketmine/item/SpawnEgg.php @@ -26,6 +26,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\entity\Entity; use pocketmine\level\Level; +use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\FloatTag; @@ -38,7 +39,7 @@ class SpawnEgg extends Item{ parent::__construct(self::SPAWN_EGG, $meta, $count, "Spawn Egg"); } - public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{ $nbt = new CompoundTag("", [ new ListTag("Pos", [ new DoubleTag("", $block->getX() + 0.5), diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 1b2088c75..60f4dee34 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1702,21 +1702,23 @@ class Level implements ChunkManager, Metadatable{ /** * Uses a item on a position and face, placing it or activating the block * - * @param Vector3 $vector - * @param Item $item - * @param int $face - * @param float $fx default 0.0 - * @param float $fy default 0.0 - * @param float $fz default 0.0 - * @param Player $player default null - * @param bool $playSound Whether to play a block-place sound if the block was placed successfully. + * @param Vector3 $vector + * @param Item $item + * @param int $face + * @param Vector3|null $facePos + * @param Player|null $player default null + * @param bool $playSound Whether to play a block-place sound if the block was placed successfully. * * @return bool */ - public function useItemOn(Vector3 $vector, Item &$item, int $face, float $fx = 0.0, float $fy = 0.0, float $fz = 0.0, Player $player = null, bool $playSound = false) : 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); + if($facePos === null){ + $facePos = new Vector3(0.0, 0.0, 0.0); + } + if($block->y >= $this->provider->getWorldHeight() or $block->y < 0){ //TODO: build height limit messages for custom world heights and mcregion cap return false; @@ -1761,7 +1763,7 @@ class Level implements ChunkManager, Metadatable{ return true; } - if(!$player->isSneaking() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ + if(!$player->isSneaking() and $item->onActivate($this, $player, $block, $target, $face, $facePos)){ if($item->getCount() <= 0){ $item = Item::get(Item::AIR, 0, 0); @@ -1832,7 +1834,7 @@ class Level implements ChunkManager, Metadatable{ } } - if($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false){ + if($hand->place($item, $block, $target, $face, $facePos, $player) === false){ return false; }