Last active
July 11, 2021 21:43
-
-
Save BEcraft/6b949b2c4d868fcd00f8fd6505d6bc37 to your computer and use it in GitHub Desktop.
Maps with custom images PocketMine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Picture; | |
use pocketmine\item\Item; | |
use pocketmine\event\Listener; | |
use pocketmine\{Server, Player}; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\event\player\PlayerJoinEvent; | |
use pocketmine\utils\{Color, TextFormat as T}; | |
use pocketmine\nbt\tag\{CompoundTag, StringTag}; | |
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket; | |
class Main extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
$this->getServer()->getLogger()->info("enabled"); | |
@mkdir($this->getDataFolder()); | |
@mkdir($this->getDataFolder()."Image/"); | |
} | |
public function onJoin(PlayerJoinEvent $event){ | |
$player = $event->getPlayer(); | |
$folder = $this->getDataFolder()."Image/"; | |
$colores = []; | |
$imagen = @imagecreatefrompng($folder."BEcraft.png"); | |
if($imagen === false){ | |
$player->sendMessage(T::RED."Error with image!"); | |
return; | |
} | |
$r = 0; | |
$g = 0; | |
$b = 0; | |
$ancho = 128; | |
$altura = 128; | |
$imagen = imagescale($imagen, $ancho, $altura, IMG_NEAREST_NEIGHBOUR); | |
imagepng($imagen, $folder."BEcraft-new.png"); | |
for($y = 0; $y < $altura; ++$y){ | |
for($x = 0; $x < $ancho; ++$x){ | |
$rgb = imagecolorat($imagen, $x, $y); | |
$color = imagecolorsforindex($imagen, $rgb); | |
$r = $color["red"]; | |
$g = $color["green"]; | |
$b = $color["blue"]; | |
$colores[$y][$x] = new Color($r, $g, $b, 0xff); | |
} | |
} | |
$map = Item::get(Item::FILLED_MAP); | |
$map->setCount(1); | |
$key = 18293883; | |
$tag = new CompoundTag("", []); | |
$tag->map_uuid = new StringTag("map_uuid", $key); | |
$map->setCompoundTag($tag); | |
$player->getInventory()->setItem(6, $map); | |
$pk = new ClientboundMapItemDataPacket(); | |
$pk->mapId = $key; | |
$pk->type = ClientboundMapItemDataPacket::BITFLAG_TEXTURE_UPDATE; | |
$pk->height = 128; | |
$pk->width = 128; | |
$pk->scale = 1; | |
$pk->colors = $colores; | |
$player->dataPacket($pk); | |
$player->sendMessage(T::GREEN."Image completed!"); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment