Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'altay/stable' into altay3
Browse files Browse the repository at this point in the history
  • Loading branch information
haniokasai committed Mar 21, 2019
2 parents 862f4ed + 7187c65 commit 67bf9e9
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 129 deletions.
24 changes: 12 additions & 12 deletions src/pocketmine/item/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

use pocketmine\maps\MapData;
use pocketmine\maps\MapManager;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\Player;

class Map extends Item{
Expand All @@ -35,22 +38,19 @@ class Map extends Item{

public function __construct(int $meta = 0){
parent::__construct(self::FILLED_MAP, $meta, "Map");

if($this->isMapInit()){
MapManager::loadMapData($this->getMapId());
}
}

public function getMapData() : ?MapData{
return MapManager::getMapDataById($this->getMapId());
}

public function onUpdate(Player $player) : void{
if($data = $this->getMapData()){
$data->renderMap($player);
$player->sendTip("messaaage");
if($this->isMapInit()){
if($data = $this->getMapData()){
$data->renderMap($player);

$data->updateVisiblePlayers($player, $this);
$data->updateVisiblePlayers($player, $this);
}
}
}

Expand All @@ -75,31 +75,31 @@ public function getMaxStackSize() : int{
}

public function setMapId(int $mapId) : void{
$this->getNamedTag()->setLong(self::TAG_MAP_UUID, $mapId);
$this->setNamedTagEntry(new LongTag(self::TAG_MAP_UUID, $mapId));
}

public function getMapId() : int{
return $this->getNamedTag()->getLong(self::TAG_MAP_UUID, 0, true);
}

public function setMapNameIndex(int $nameIndex) : void{
$this->getNamedTag()->setInt(self::TAG_MAP_NAME_INDEX, $nameIndex);
$this->setNamedTagEntry(new IntTag(self::TAG_MAP_NAME_INDEX, $nameIndex));
}

public function getMapNameIndex() : int{
return $this->getNamedTag()->getInt(self::TAG_MAP_NAME_INDEX, 0, true);
}

public function setMapDisplayPlayers(bool $value) : void{
$this->getNamedTag()->setByte(self::TAG_MAP_DISPLAY_PLAYERS, intval($value));
$this->setNamedTagEntry(new ByteTag(self::TAG_MAP_DISPLAY_PLAYERS, intval($value)));
}

public function isMapDisplayPlayers() : bool{
return boolval($this->getNamedTag()->getByte(self::TAG_MAP_DISPLAY_PLAYERS, 0, true));
}

public function setMapInit(bool $value) : void{
$this->getNamedTag()->setByte(self::TAG_MAP_IS_INIT, intval($value));
$this->setNamedTagEntry(new ByteTag(self::TAG_MAP_IS_INIT, intval($value)));
}

public function isMapInit() : bool{
Expand Down
59 changes: 39 additions & 20 deletions src/pocketmine/maps/MapData.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
<?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/
* @author TuranicTeam
* @link https://github.com/TuranicTeam/Altay
*
*
*/
*/

declare(strict_types=1);

namespace pocketmine\maps;

use pocketmine\item\Map;
use pocketmine\level\Level;
use pocketmine\maps\renderer\MapRenderer;
use pocketmine\maps\renderer\VanillaMapRenderer;
use pocketmine\math\Vector2;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
Expand Down Expand Up @@ -56,7 +61,7 @@ class MapData{
protected $cachedDataPacket = null;

/** @var bool */
protected $fullyExplored = true;
protected $fullyExplored = false;
/** @var bool */
protected $unlimitedTracking = true;
/** @var bool */
Expand All @@ -67,12 +72,29 @@ class MapData{
/** @var MapRenderer[] */
protected $renderers = [];

/**
* MapData constructor.
*
* @param int $mapId
* @param MapRenderer[] $renderers
*/
public function __construct(int $mapId, array $renderers = []){
$this->id = $mapId;
if(empty($renderers)){
$renderers[] = new VanillaMapRenderer();
}
$this->renderers = $renderers;

foreach($renderers as $renderer){
$renderer->initialize($this);
}

$transColor = new Color(0, 0, 0, 0);
for($y = 0; $y < 128; $y++){
for($x = 0; $x < 128; $x++){
$this->setColorAt($x, $y, clone $transColor);
}
}
}

/**
Expand Down Expand Up @@ -176,8 +198,7 @@ public function updateMap(int $flags) : void{
$pk = $this->createDataPacket($flags);
if($info->forceUpdate and !empty($pk->colors)){
$info->forceUpdate = false;
$player->sendPopup("xxxxx");
$pk->cropTexture($info->minX, $info->minY, $info->maxX + 1 - $info->minX, $info->maxY + 1 - $info->minY);
//$pk->cropTexture($info->minX, $info->minY, $info->maxX + 1 - $info->minX, $info->maxY + 1 - $info->minY);
}
$player->sendDataPacket($pk);
}
Expand Down Expand Up @@ -283,6 +304,7 @@ public function setFullyExplored(bool $fullyExplored) : void{
public function getMapInfo(Player $player) : MapInfo{
if(!isset($this->playersMap[spl_object_hash($player)])){
$this->playersMap[spl_object_hash($player)] = new MapInfo($player);

$mo = new MapTrackedObject();
$mo->entityUniqueId = $player->getId();
$mo->type = MapTrackedObject::TYPE_PLAYER;
Expand Down Expand Up @@ -327,15 +349,11 @@ public function updateVisiblePlayers(Player $player, Map $mapStack){
$this->trackedObjects[$player->getName()] = $mo;
}

if(!$player->getInventory()->contains($mapStack)){
unset($this->decorations[$player->getName()]);
}

if($mapStack->isMapDisplayPlayers()){
foreach($this->playersMap as $info){
$pi = $info->player;
if($pi->isOnline() and $pi->isAlive() and $pi->level->getDimension() === $this->dimension and $info->packetSendTimer++ % 5 === 0){
if(!$mapStack->isOnItemFrame() and $pi->getInventory()->contains($mapStack)){
if($pi->isOnline() and $pi->isAlive() and $pi->level->getDimension() === $this->dimension){
if(!$mapStack->isOnItemFrame() and $info->packetSendTimer++ % 5 === 0){
$this->updateDecorations(MapDecoration::TYPE_PLAYER, $pi->level, $pi->getName(), $pi->getFloorX(), $pi->getFloorZ(), $pi->getYaw());
}
}else{
Expand Down Expand Up @@ -416,7 +434,7 @@ public function updateDecorations(int $type, Level $worldIn, String $entityIdent
$deco->rot = $b2;
$deco->xOffset = $b0;
$deco->yOffset = $b1;
$deco->color = $color ?? new Color(0, 0, 0);
$deco->color = $color ?? new Color(255, 255, 255);
$deco->label = $entityIdentifier;

$this->decorations[$entityIdentifier] = $deco;
Expand All @@ -429,6 +447,7 @@ public function updateDecorations(int $type, Level $worldIn, String $entityIdent
*/
public function addRenderer(MapRenderer $renderer) : void{
$this->renderers[spl_object_id($renderer)] = $renderer;
$renderer->initialize($this);
}

/**
Expand Down
23 changes: 13 additions & 10 deletions src/pocketmine/maps/MapInfo.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?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/
* @author TuranicTeam
* @link https://github.com/TuranicTeam/Altay
*
*
*/
*/

declare(strict_types=1);

namespace pocketmine\maps;
Expand Down
2 changes: 2 additions & 0 deletions src/pocketmine/maps/MapManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* _ _
* /\ | | |
Expand All @@ -18,6 +19,7 @@
* @link https://github.com/TuranicTeam/Altay
*
*/

declare(strict_types=1);

namespace pocketmine\maps;
Expand Down
24 changes: 0 additions & 24 deletions src/pocketmine/maps/MapRenderer.php

This file was deleted.

39 changes: 39 additions & 0 deletions src/pocketmine/maps/renderer/MapRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 TuranicTeam
* @link https://github.com/TuranicTeam/Altay
*
*/

namespace pocketmine\maps\renderer;

use pocketmine\maps\MapData;
use pocketmine\Player;

interface MapRenderer{

public function initialize(MapData $mapData) : void;

/**
* Renders a map
*
* @param MapData $mapData
* @param Player $player
*/
public function render(MapData $mapData, Player $player) : void;
}
Loading

0 comments on commit 67bf9e9

Please sign in to comment.