mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
Refactor confusing parameter names for Item->onActivate()
next: refactor the function itself
This commit is contained in:
parent
af85659c63
commit
769a50faa5
@ -50,16 +50,16 @@ class Bucket extends Item{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||||
$resultBlock = BlockFactory::get($this->meta);
|
$resultBlock = BlockFactory::get($this->meta);
|
||||||
|
|
||||||
if($resultBlock instanceof Air){
|
if($resultBlock instanceof Air){
|
||||||
if($target instanceof Liquid and $target->getDamage() === 0){
|
if($blockClicked instanceof Liquid and $blockClicked->getDamage() === 0){
|
||||||
$resultItem = clone $this;
|
$resultItem = clone $this;
|
||||||
$resultItem->setDamage($target->getId());
|
$resultItem->setDamage($blockClicked->getId());
|
||||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $resultItem));
|
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem));
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$player->getLevel()->setBlock($target, BlockFactory::get(Block::AIR), true, true);
|
$player->getLevel()->setBlock($blockClicked, BlockFactory::get(Block::AIR), true, true);
|
||||||
if($player->isSurvival()){
|
if($player->isSurvival()){
|
||||||
$player->getInventory()->setItemInHand($ev->getItem());
|
$player->getInventory()->setItemInHand($ev->getItem());
|
||||||
}
|
}
|
||||||
@ -71,9 +71,9 @@ class Bucket extends Item{
|
|||||||
}elseif($resultBlock instanceof Liquid){
|
}elseif($resultBlock instanceof Liquid){
|
||||||
$resultItem = clone $this;
|
$resultItem = clone $this;
|
||||||
$resultItem->setDamage(0);
|
$resultItem->setDamage(0);
|
||||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $resultItem));
|
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $blockReplace, $face, $this, $resultItem));
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$player->getLevel()->setBlock($block, $resultBlock, true, true);
|
$player->getLevel()->setBlock($blockReplace, $resultBlock, true, true);
|
||||||
if($player->isSurvival()){
|
if($player->isSurvival()){
|
||||||
$player->getInventory()->setItemInHand($ev->getItem());
|
$player->getInventory()->setItemInHand($ev->getItem());
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ class FlintSteel extends Tool{
|
|||||||
parent::__construct(self::FLINT_STEEL, $meta, "Flint and Steel");
|
parent::__construct(self::FLINT_STEEL, $meta, "Flint and Steel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||||
if($block->getId() === self::AIR and ($target instanceof Solid)){
|
if($blockReplace->getId() === self::AIR and ($blockClicked instanceof Solid)){
|
||||||
$level->setBlock($block, BlockFactory::get(Block::FIRE), true);
|
$level->setBlock($blockReplace, BlockFactory::get(Block::FIRE), true);
|
||||||
$level->broadcastLevelSoundEvent($block->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_IGNITE);
|
$level->broadcastLevelSoundEvent($blockReplace->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_IGNITE);
|
||||||
|
|
||||||
$this->applyDamage(1);
|
$this->applyDamage(1);
|
||||||
|
|
||||||
|
@ -785,14 +785,14 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
*
|
*
|
||||||
* @param Level $level
|
* @param Level $level
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @param Block $block
|
* @param Block $blockReplace
|
||||||
* @param Block $target
|
* @param Block $blockClicked
|
||||||
* @param int $face
|
* @param int $face
|
||||||
* @param Vector3 $facePos
|
* @param Vector3 $facePos
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ class Painting extends Item{
|
|||||||
parent::__construct(self::PAINTING, $meta, "Painting");
|
parent::__construct(self::PAINTING, $meta, "Painting");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||||
if($target->isTransparent() === false and $face > 1 and $block->isSolid() === false){
|
if($blockClicked->isTransparent() === false and $face > 1 and $blockReplace->isSolid() === false){
|
||||||
$faces = [
|
$faces = [
|
||||||
2 => 1,
|
2 => 1,
|
||||||
3 => 3,
|
3 => 3,
|
||||||
@ -73,9 +73,9 @@ class Painting extends Item{
|
|||||||
];
|
];
|
||||||
$motive = $motives[mt_rand(0, count($motives) - 1)];
|
$motive = $motives[mt_rand(0, count($motives) - 1)];
|
||||||
$data = [
|
$data = [
|
||||||
"x" => $target->x,
|
"x" => $blockClicked->x,
|
||||||
"y" => $target->y,
|
"y" => $blockClicked->y,
|
||||||
"z" => $target->z,
|
"z" => $blockClicked->z,
|
||||||
"yaw" => $faces[$face] * 90,
|
"yaw" => $faces[$face] * 90,
|
||||||
"Motive" => $motive[0],
|
"Motive" => $motive[0],
|
||||||
];
|
];
|
||||||
|
@ -39,12 +39,12 @@ class SpawnEgg extends Item{
|
|||||||
parent::__construct(self::SPAWN_EGG, $meta, "Spawn Egg");
|
parent::__construct(self::SPAWN_EGG, $meta, "Spawn Egg");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||||
$nbt = new CompoundTag("", [
|
$nbt = new CompoundTag("", [
|
||||||
new ListTag("Pos", [
|
new ListTag("Pos", [
|
||||||
new DoubleTag("", $block->getX() + 0.5),
|
new DoubleTag("", $blockReplace->getX() + 0.5),
|
||||||
new DoubleTag("", $block->getY()),
|
new DoubleTag("", $blockReplace->getY()),
|
||||||
new DoubleTag("", $block->getZ() + 0.5)
|
new DoubleTag("", $blockReplace->getZ() + 0.5)
|
||||||
]),
|
]),
|
||||||
new ListTag("Motion", [
|
new ListTag("Motion", [
|
||||||
new DoubleTag("", 0),
|
new DoubleTag("", 0),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user