mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Added BlockUpdateEvent
This commit is contained in:
parent
69d132401e
commit
bda6f03e15
@ -34,7 +34,7 @@ abstract class BlockEvent extends Event{
|
|||||||
/**
|
/**
|
||||||
* @param Block $block
|
* @param Block $block
|
||||||
*/
|
*/
|
||||||
protected function __construct(Block $block){
|
public function __construct(Block $block){
|
||||||
$this->block = $block;
|
$this->block = $block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
src/pocketmine/event/block/BlockUpdateEvent.php
Normal file
34
src/pocketmine/event/block/BlockUpdateEvent.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\event\block;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\event\Cancellable;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a block tries to be updated due to a neighbor change
|
||||||
|
*/
|
||||||
|
class BlockUpdateEvent extends BlockEvent implements Cancellable{
|
||||||
|
public static $handlerList = null;
|
||||||
|
|
||||||
|
}
|
@ -49,6 +49,7 @@ use pocketmine\entity\DroppedItem;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\block\BlockBreakEvent;
|
use pocketmine\event\block\BlockBreakEvent;
|
||||||
use pocketmine\event\block\BlockPlaceEvent;
|
use pocketmine\event\block\BlockPlaceEvent;
|
||||||
|
use pocketmine\event\block\BlockUpdateEvent;
|
||||||
use pocketmine\event\level\ChunkLoadEvent;
|
use pocketmine\event\level\ChunkLoadEvent;
|
||||||
use pocketmine\event\level\ChunkPopulateEvent;
|
use pocketmine\event\level\ChunkPopulateEvent;
|
||||||
use pocketmine\event\level\ChunkUnloadEvent;
|
use pocketmine\event\level\ChunkUnloadEvent;
|
||||||
@ -689,21 +690,20 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Vector3 $pos
|
* @param Vector3 $pos
|
||||||
* @param int $type
|
|
||||||
*/
|
*/
|
||||||
public function updateAround(Vector3 $pos, $type = self::BLOCK_UPDATE_NORMAL){
|
public function updateAround(Vector3 $pos){
|
||||||
if($pos instanceof Block){
|
if($pos instanceof Block){
|
||||||
$block = $pos;
|
$block = $pos;
|
||||||
}else{
|
}else{
|
||||||
$block = $this->getBlock($pos);
|
$block = $this->getBlock($pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
$block->getSide(0)->onUpdate($type);
|
for($side = 0; $side <= 5; ++$side){
|
||||||
$block->getSide(1)->onUpdate($type);
|
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block->getSide($side)));
|
||||||
$block->getSide(2)->onUpdate($type);
|
if(!$ev->isCancelled()){
|
||||||
$block->getSide(3)->onUpdate($type);
|
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
||||||
$block->getSide(4)->onUpdate($type);
|
}
|
||||||
$block->getSide(5)->onUpdate($type);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -937,7 +937,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
Cache::remove("world:" . $this->getID() . ":" . $index);
|
Cache::remove("world:" . $this->getID() . ":" . $index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($direct === true){
|
//if($direct === true){
|
||||||
$pk = new UpdateBlockPacket;
|
$pk = new UpdateBlockPacket;
|
||||||
$pk->x = $pos->x;
|
$pk->x = $pos->x;
|
||||||
$pk->y = $pos->y;
|
$pk->y = $pos->y;
|
||||||
@ -949,7 +949,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
/** @var Player $player */
|
/** @var Player $player */
|
||||||
$player->dataPacket($pk);
|
$player->dataPacket($pk);
|
||||||
}
|
}
|
||||||
}else{
|
/*}else{
|
||||||
if(!($pos instanceof Position)){
|
if(!($pos instanceof Position)){
|
||||||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||||
}
|
}
|
||||||
@ -964,17 +964,20 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->changedCount[$index] |= 1 << $Y;
|
$this->changedCount[$index] |= 1 << $Y;
|
||||||
}
|
}
|
||||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if($update === true){
|
if($update === true){
|
||||||
$this->updateAround($pos, self::BLOCK_UPDATE_NORMAL);
|
$this->updateAround($pos);
|
||||||
$block->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block));
|
||||||
|
if(!$ev->isCancelled()){
|
||||||
|
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
||||||
foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){
|
foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){
|
||||||
$entity->scheduleUpdate();
|
$entity->scheduleUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Vector3 $source
|
* @param Vector3 $source
|
||||||
|
Loading…
x
Reference in New Issue
Block a user