mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if($resultBlock instanceof Air){
|
||||
if($target instanceof Liquid and $target->getDamage() === 0){
|
||||
if($blockClicked instanceof Liquid and $blockClicked->getDamage() === 0){
|
||||
$resultItem = clone $this;
|
||||
$resultItem->setDamage($target->getId());
|
||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $resultItem));
|
||||
$resultItem->setDamage($blockClicked->getId());
|
||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem));
|
||||
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()){
|
||||
$player->getInventory()->setItemInHand($ev->getItem());
|
||||
}
|
||||
@ -71,9 +71,9 @@ class Bucket extends Item{
|
||||
}elseif($resultBlock instanceof Liquid){
|
||||
$resultItem = clone $this;
|
||||
$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()){
|
||||
$player->getLevel()->setBlock($block, $resultBlock, true, true);
|
||||
$player->getLevel()->setBlock($blockReplace, $resultBlock, true, true);
|
||||
if($player->isSurvival()){
|
||||
$player->getInventory()->setItemInHand($ev->getItem());
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ class FlintSteel extends Tool{
|
||||
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{
|
||||
if($block->getId() === self::AIR and ($target instanceof Solid)){
|
||||
$level->setBlock($block, BlockFactory::get(Block::FIRE), true);
|
||||
$level->broadcastLevelSoundEvent($block->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_IGNITE);
|
||||
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||
if($blockReplace->getId() === self::AIR and ($blockClicked instanceof Solid)){
|
||||
$level->setBlock($blockReplace, BlockFactory::get(Block::FIRE), true);
|
||||
$level->broadcastLevelSoundEvent($blockReplace->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_IGNITE);
|
||||
|
||||
$this->applyDamage(1);
|
||||
|
||||
|
@ -785,14 +785,14 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
*
|
||||
* @param Level $level
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param Block $blockReplace
|
||||
* @param Block $blockClicked
|
||||
* @param int $face
|
||||
* @param Vector3 $facePos
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ class Painting extends Item{
|
||||
parent::__construct(self::PAINTING, $meta, "Painting");
|
||||
}
|
||||
|
||||
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){
|
||||
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
|
||||
if($blockClicked->isTransparent() === false and $face > 1 and $blockReplace->isSolid() === false){
|
||||
$faces = [
|
||||
2 => 1,
|
||||
3 => 3,
|
||||
@ -73,9 +73,9 @@ class Painting extends Item{
|
||||
];
|
||||
$motive = $motives[mt_rand(0, count($motives) - 1)];
|
||||
$data = [
|
||||
"x" => $target->x,
|
||||
"y" => $target->y,
|
||||
"z" => $target->z,
|
||||
"x" => $blockClicked->x,
|
||||
"y" => $blockClicked->y,
|
||||
"z" => $blockClicked->z,
|
||||
"yaw" => $faces[$face] * 90,
|
||||
"Motive" => $motive[0],
|
||||
];
|
||||
|
@ -39,12 +39,12 @@ class SpawnEgg extends Item{
|
||||
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("", [
|
||||
new ListTag("Pos", [
|
||||
new DoubleTag("", $block->getX() + 0.5),
|
||||
new DoubleTag("", $block->getY()),
|
||||
new DoubleTag("", $block->getZ() + 0.5)
|
||||
new DoubleTag("", $blockReplace->getX() + 0.5),
|
||||
new DoubleTag("", $blockReplace->getY()),
|
||||
new DoubleTag("", $blockReplace->getZ() + 0.5)
|
||||
]),
|
||||
new ListTag("Motion", [
|
||||
new DoubleTag("", 0),
|
||||
|
Loading…
x
Reference in New Issue
Block a user