Merge branch 'master' into mcpe-1.2.5

This commit is contained in:
Dylan K. Taylor 2017-10-27 21:24:30 +01:00
commit dd085b35cc
58 changed files with 124 additions and 103 deletions

View File

@ -1378,8 +1378,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){
if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox;
$bb->minY = $this->y - 0.1;
$bb->maxY = $this->y + 0.1;
$bb->minY = $this->y - 0.2;
$bb->maxY = $this->y + 0.2;
if(count($this->level->getCollisionBlocks($bb, true)) > 0){
$this->onGround = true;
@ -2361,7 +2361,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$item = $this->inventory->getItemInHand();
}
$ev = new PlayerInteractEvent($this, $item, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
$ev = new PlayerInteractEvent($this, $item, null, $directionVector, $face, PlayerInteractEvent::RIGHT_CLICK_AIR);
$this->server->getPluginManager()->callEvent($ev);
@ -2624,7 +2624,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
break;
}
$target = $this->level->getBlock($pos);
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK);
$this->getServer()->getPluginManager()->callEvent($ev);
if($ev->isCancelled()){
$this->inventory->sendHeldItem($this);
@ -2913,7 +2913,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z));
if($tile instanceof ItemFrame){
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK);
$this->server->getPluginManager()->callEvent($ev);
if($this->isSpectator()){

View File

@ -100,7 +100,7 @@ class Anvil extends Fallable{
return true;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$direction = ($player !== null ? $player->getDirection() : 0) & 0x03;
$this->meta = ($this->meta & 0x0c) | $direction;
return $this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -171,7 +171,7 @@ class Bed extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if(!$down->isTransparent()){
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03;

View File

@ -175,12 +175,12 @@ class Block extends Position implements BlockIds, Metadatable{
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $facePos
* @param Vector3 $clickVector
* @param Player|null $player
*
* @return bool
*/
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, $this, true, true);
}

View File

@ -49,7 +49,7 @@ class BoneBlock extends Solid{
return Tool::TYPE_PICKAXE;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}

View File

@ -55,7 +55,7 @@ class BurningFurnace extends Solid{
return 13;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,

View File

@ -37,7 +37,7 @@ abstract class Button extends Flowable{
return 0;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
//TODO: check valid target block
$this->meta = $face;

View File

@ -112,7 +112,7 @@ class Cactus extends Transparent{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, 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);

View File

@ -62,7 +62,7 @@ class Cake extends Transparent implements FoodSource{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -62,7 +62,7 @@ class Carpet extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() !== self::AIR){
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -53,17 +53,18 @@ class Chest extends Transparent{
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
//these are slightly bigger than in PC
return new AxisAlignedBB(
$this->x + 0.0625,
$this->x + 0.025,
$this->y,
$this->z + 0.0625,
$this->x + 0.9375,
$this->y + 0.9475,
$this->z + 0.9375
$this->z + 0.025,
$this->x + 0.975,
$this->y + 0.95,
$this->z + 0.975
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 4,
1 => 2,

View File

@ -32,7 +32,7 @@ use pocketmine\Server;
abstract class Crops extends Flowable{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -41,7 +41,7 @@ class Dandelion extends Flowable{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, 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($blockReplace, $this, true, true);

View File

@ -216,7 +216,7 @@ abstract class Door extends Transparent{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP){
$blockUp = $this->getSide(Vector3::SIDE_UP);
$blockDown = $this->getSide(Vector3::SIDE_DOWN);

View File

@ -54,7 +54,7 @@ class DoublePlant extends Flowable{
return $names[$this->getVariant()] ?? "";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, 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);

View File

@ -39,7 +39,7 @@ class EnchantingTable extends Transparent{
$this->meta = $meta;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->getLevel()->setBlock($blockReplace, $this, true, true);
Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel(), TileEnchantTable::createNBT($this, $face, $item, $player));

View File

@ -40,7 +40,7 @@ class EndRod extends Flowable{
return "End Rod";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){
$this->meta = $face;
}else{

View File

@ -69,7 +69,7 @@ class FenceGate extends Transparent{
}
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0);
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -60,7 +60,7 @@ class Flower extends Flowable{
return $names[$this->meta] ?? "Unknown";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, 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($blockReplace, $this, true);

View File

@ -58,7 +58,7 @@ class FlowerPot extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){
return false;
}

View File

@ -39,7 +39,7 @@ class GlazedTerracotta extends Solid{
return Tool::TYPE_PICKAXE;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($player !== null){
$faces = [
0 => 4,

View File

@ -44,7 +44,7 @@ class HayBale extends Solid{
return 0.5;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -85,7 +85,7 @@ class ItemFrame extends Flowable{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_DOWN or $face === Vector3::SIDE_UP){
return false;
}

View File

@ -91,7 +91,7 @@ class Ladder extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockClicked->isTransparent() === false){
$faces = [
2 => 2,

View File

@ -63,7 +63,7 @@ class Lava extends Liquid{
$entity->resetFallDistance();
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$ret = $this->getLevel()->setBlock($this, $this, true, false);
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());

View File

@ -164,7 +164,7 @@ class Leaves extends Transparent{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta |= 0x04;
return $this->getLevel()->setBlock($this, $this, true);
}

View File

@ -48,7 +48,7 @@ class NetherWartPlant extends Flowable{
return true;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === Block::SOUL_SAND){
$this->getLevel()->setBlock($blockReplace, $this, false, true);

View File

@ -48,7 +48,7 @@ class Pumpkin extends Solid{
return "Pumpkin";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($player instanceof Player){
$this->meta = ((int) $player->getDirection() + 1) % 4;
}

View File

@ -54,7 +54,7 @@ class Quartz extends Solid{
return $names[$this->getVariant()] ?? "Unknown";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($this->meta !== self::NORMAL){
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
}

View File

@ -55,7 +55,7 @@ class Rail extends Flowable{
return 0.7;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockReplace->getSide(Vector3::SIDE_DOWN)->isTransparent()){
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}

View File

@ -56,7 +56,7 @@ class RedMushroom extends Flowable{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->isTransparent() === false){
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -46,7 +46,7 @@ class RedstoneOre extends Solid{
return 3;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
return $this->getLevel()->setBlock($this, $this, true, false);
}

View File

@ -60,7 +60,7 @@ class Sapling extends Flowable{
return true;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, 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($blockReplace, $this, true, true);

View File

@ -59,7 +59,7 @@ class SignPost extends Transparent{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face !== Vector3::SIDE_DOWN){
if($face === Vector3::SIDE_UP){

View File

@ -59,7 +59,7 @@ class Skull extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($face === Vector3::SIDE_DOWN){
return false;
}

View File

@ -52,7 +52,7 @@ abstract class Slab extends Transparent{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta &= 0x07;
if($face === Vector3::SIDE_DOWN){
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){
@ -86,7 +86,7 @@ abstract class Slab extends Transparent{
return false;
}else{
if($facePos->y > 0.5){
if($clickVector->y > 0.5){
$this->meta |= 0x08;
}
}

View File

@ -58,7 +58,7 @@ class SnowLayer extends Flowable{
return true;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockReplace->getSide(Vector3::SIDE_DOWN)->isSolid()){
//TODO: fix placement
$this->getLevel()->setBlock($blockReplace, $this, true);

View File

@ -83,7 +83,7 @@ abstract class Stair extends Transparent{
return $bbs;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$faces = [
0 => 0,
1 => 2,
@ -91,7 +91,7 @@ abstract class Stair extends Transparent{
3 => 3
];
$this->meta = $faces[$player->getDirection()] & 0x03;
if(($facePos->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){
if(($clickVector->y > 0.5 and $face !== Vector3::SIDE_UP) or $face === Vector3::SIDE_DOWN){
$this->meta |= 0x04; //Upside-down stairs
}
$this->getLevel()->setBlock($blockReplace, $this, true, true);

View File

@ -105,7 +105,7 @@ class Sugarcane extends Flowable{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::SUGARCANE_BLOCK){
$this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::SUGARCANE_BLOCK), true);

View File

@ -50,7 +50,7 @@ class TallGrass extends Flowable{
return $names[$this->getVariant()] ?? "Unknown";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::GRASS){
$this->getLevel()->setBlock($blockReplace, $this, true);

View File

@ -68,7 +68,7 @@ class Torch extends Flowable{
return false;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$below = $this->getSide(Vector3::SIDE_DOWN);
if($blockClicked->isTransparent() === false and $face !== Vector3::SIDE_DOWN){

View File

@ -124,7 +124,7 @@ class Trapdoor extends Transparent{
return $bb;
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$directions = [
0 => 1,
1 => 3,
@ -134,7 +134,7 @@ class Trapdoor extends Transparent{
if($player !== null){
$this->meta = $directions[$player->getDirection() & 0x03];
}
if(($facePos->y > 0.5 and $face !== self::SIDE_UP) or $face === self::SIDE_DOWN){
if(($clickVector->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($blockReplace, $this, true, true);

View File

@ -137,7 +137,7 @@ class Vine extends Flowable{
);
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockClicked->isSolid() or $face === Vector3::SIDE_UP or $face === Vector3::SIDE_DOWN){
return false;
}

View File

@ -53,7 +53,7 @@ class Water extends Liquid{
$entity->resetFallDistance();
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$ret = $this->getLevel()->setBlock($this, $this, true, false);
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());

View File

@ -57,7 +57,7 @@ class WaterLily extends Flowable{
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if($blockClicked instanceof Water){
$up = $blockClicked->getSide(Vector3::SIDE_UP);
if($up->getId() === Block::AIR){

View File

@ -55,7 +55,7 @@ class Wood extends Solid{
return $names[$this->getVariant()] ?? "Unknown";
}
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
$this->meta = PillarRotationHelper::getMetaFromFace($this->meta, $face);
return $this->getLevel()->setBlock($blockReplace, $this, true, true);
}

View File

@ -321,7 +321,7 @@ abstract class Living extends Entity implements Damageable{
}
public function fall(float $fallDistance){
$damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
$damage = ceil($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 0));
if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev);

View File

@ -58,16 +58,20 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
/** @var int */
protected $action;
public function __construct(Player $player, Item $item, Vector3 $block, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
if($block instanceof Block){
$this->blockTouched = $block;
$this->touchVector = new Vector3(0, 0, 0);
}else{
$this->touchVector = $block;
$this->blockTouched = BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
}
/**
* @param Player $player
* @param Item $item
* @param Block|null $block
* @param Vector3|null $touchVector
* @param int $face
* @param int $action
*/
public function __construct(Player $player, Item $item, ?Block $block, ?Vector3 $touchVector, int $face, int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK){
assert($block !== null or $touchVector !== null);
$this->player = $player;
$this->item = $item;
$this->blockTouched = $block ?? BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
$this->touchVector = $touchVector ?? new Vector3(0, 0, 0);
$this->blockFace = $face;
$this->action = $action;
}

View File

@ -50,7 +50,7 @@ class Bucket extends Item{
return 0;
}
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
$resultBlock = BlockFactory::get($this->meta);
if($resultBlock instanceof Air){

View File

@ -36,7 +36,7 @@ class FlintSteel extends Tool{
parent::__construct(self::FLINT_STEEL, $meta, "Flint and Steel");
}
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : 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);

View File

@ -788,11 +788,11 @@ class Item implements ItemIds, \JsonSerializable{
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $facePos
* @param Vector3 $clickVector
*
* @return bool
*/
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
return false;
}

View File

@ -33,7 +33,7 @@ class Painting extends Item{
parent::__construct(self::PAINTING, $meta, "Painting");
}
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
if($blockClicked->isTransparent() === false and $face > 1 and $blockReplace->isSolid() === false){
$faces = [
2 => 1,

View File

@ -34,7 +34,7 @@ class SpawnEgg extends Item{
parent::__construct(self::SPAWN_EGG, $meta, "Spawn Egg");
}
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos) : bool{
public function onActivate(Level $level, Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
$nbt = Entity::createBaseNBT($blockReplace->add(0.5, 0, 0.5), null, lcg_value() * 360, 0);
if($this->hasCustomName()){

View File

@ -1722,18 +1722,18 @@ class Level implements ChunkManager, Metadatable{
* @param Vector3 $vector
* @param Item $item
* @param int $face
* @param Vector3|null $facePos
* @param Vector3|null $clickVector
* @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, Vector3 $facePos = null, Player $player = null, bool $playSound = false) : bool{
public function useItemOn(Vector3 $vector, Item &$item, int $face, Vector3 $clickVector = null, Player $player = null, bool $playSound = false) : bool{
$blockClicked = $this->getBlock($vector);
$blockReplace = $blockClicked->getSide($face);
if($facePos === null){
$facePos = new Vector3(0.0, 0.0, 0.0);
if($clickVector === null){
$clickVector = new Vector3(0.0, 0.0, 0.0);
}
if($blockReplace->y >= $this->provider->getWorldHeight() or $blockReplace->y < 0){
@ -1746,7 +1746,7 @@ class Level implements ChunkManager, Metadatable{
}
if($player !== null){
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $face, $blockClicked->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK);
$ev = new PlayerInteractEvent($player, $item, $blockClicked, $clickVector, $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
}
@ -1776,7 +1776,7 @@ class Level implements ChunkManager, Metadatable{
return true;
}
if(!$player->isSneaking() and $item->onActivate($this, $player, $blockReplace, $blockClicked, $face, $facePos)){
if(!$player->isSneaking() and $item->onActivate($this, $player, $blockReplace, $blockClicked, $face, $clickVector)){
return true;
}
}else{
@ -1793,10 +1793,10 @@ class Level implements ChunkManager, Metadatable{
return false;
}
if($hand->canBePlacedAt($blockClicked, $facePos, $face, true)){
if($hand->canBePlacedAt($blockClicked, $clickVector, $face, true)){
$blockReplace = $blockClicked;
$hand->position($blockReplace);
}elseif(!$hand->canBePlacedAt($blockReplace, $facePos, $face, false)){
}elseif(!$hand->canBePlacedAt($blockReplace, $clickVector, $face, false)){
return false;
}
@ -1835,7 +1835,7 @@ class Level implements ChunkManager, Metadatable{
}
}
if(!$hand->place($item, $blockReplace, $blockClicked, $face, $facePos, $player)){
if(!$hand->place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
return false;
}

View File

@ -29,7 +29,6 @@ namespace pocketmine\level\format;
use pocketmine\block\BlockFactory;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
use pocketmine\tile\Spawnable;
@ -939,16 +938,10 @@ class Chunk{
}
$result .= $extraData->getBuffer();
if(count($this->tiles) > 0){
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$list = [];
foreach($this->tiles as $tile){
if($tile instanceof Spawnable){
$list[] = $tile->getSpawnCompound();
}
foreach($this->tiles as $tile){
if($tile instanceof Spawnable){
$result .= $tile->getSerializedSpawnCompound();
}
$nbt->setData($list);
$result .= $nbt->write(true);
}
return $result;

View File

@ -25,7 +25,6 @@ namespace pocketmine\level\format\io;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\network\mcpe\protocol\BatchPacket;
use pocketmine\network\mcpe\protocol\FullChunkDataPacket;
use pocketmine\scheduler\AsyncTask;
@ -54,11 +53,9 @@ class ChunkRequestTask extends AsyncTask{
//TODO: serialize tiles with chunks
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach($chunk->getTiles() as $tile){
if($tile instanceof Spawnable){
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write(true);
$tiles .= $tile->getSerializedSpawnCompound();
}
}

View File

@ -154,13 +154,13 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* tag is not of type $expectedType, an exception will be thrown.
*
* @param string $name
* @param string $expectedType
* @param string $expectedClass
* @param mixed $default
*
* @return mixed
*/
public function getTagValue(string $name, string $expectedType, $default = null){
$tag = $this->getTag($name, $expectedType);
public function getTagValue(string $name, string $expectedClass, $default = null){
$tag = $this->getTag($name, $expectedClass);
if($tag !== null){
return $tag->getValue();
}

View File

@ -30,15 +30,17 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\Player;
abstract class Spawnable extends Tile{
/** @var string|null */
private $spawnCompoundCache = null;
/** @var NBT|null */
private static $nbtWriter = null;
public function createSpawnPacket() : BlockEntityDataPacket{
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($this->getSpawnCompound());
$pk = new BlockEntityDataPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->namedtag = $nbt->write(true);
$pk->namedtag = $this->getSerializedSpawnCompound();
return $pk;
}
@ -67,7 +69,12 @@ abstract class Spawnable extends Tile{
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk);
}
/**
* Performs actions needed when the tile is modified, such as clearing caches and respawning the tile to players.
* WARNING: This MUST be called to clear spawn-compound and chunk caches when the tile's spawn compound has changed!
*/
protected function onChanged() : void{
$this->spawnCompoundCache = null;
$this->spawnToAll();
if($this->chunk !== null){
@ -76,6 +83,25 @@ abstract class Spawnable extends Tile{
}
}
/**
* Returns encoded NBT (varint, little-endian) used to spawn this tile to clients. Uses cache where possible,
* populates cache if it is null.
*
* @return string encoded NBT
*/
final public function getSerializedSpawnCompound() : string{
if($this->spawnCompoundCache === null){
if(self::$nbtWriter === null){
self::$nbtWriter = new NBT(NBT::LITTLE_ENDIAN);
}
self::$nbtWriter->setData($this->getSpawnCompound());
$this->spawnCompoundCache = self::$nbtWriter->write(true);
}
return $this->spawnCompoundCache;
}
/**
* @return CompoundTag
*/