Solved Cannot add custom image on the filled map

Discussion in 'Development' started by EnderVlad, May 23, 2020 at 6:57 PM.

  1. EnderVlad

    EnderVlad Creeper

    Messages:
    5
    GitHub:
    EnderVlad96
    I am trying to add custom image, but it does not work.. I tried to do that by catching the MapInfoRequestPacket, but it did not work when I held the map in my hand(
    PHP:
    public function onHold(PlayerItemHeldEvent $event): void
        
    {
            
    $player $event->getPlayer();
            if (
    $event->getItem()->getId() === ItemIds::FILLED_MAP) {
    //            var_dump(1);
                
    $folder $this->loader->getDataFolder();
                
    $colors = [];
                
    $imaged = @imagecreatefrompng($folder "map.png");
                
    $anchor 128;
                
    $altars 128;
                
    $imaged imagescale($imaged$anchor$altarsIMG_NEAREST_NEIGHBOUR);
                
    imagepng($imaged$folder "map.png");
                for (
    $y 0$y $altars; ++$y) {
                    for (
    $x 0$x $anchor; ++$x) {
                        
    $rgb imagecolorat($imaged$x$y);
                        
    $color imagecolorsforindex($imaged$rgb);
                        
    $r $color["red"];
                        
    $g $color["green"];
                        
    $b $color["blue"];
                        
    $colors[$y][$x] = new Color($r$g$b0xff);
                    }
                }

    //            var_dump($event->getItem()->getNamedTag()->getInt("map_uuid"));
                
    $pk = new ClientboundMapItemDataPacket();
                
    $pk->mapId $event->getItem()->getNamedTag()->getInt("map_uuid");
                
    $pk->type ClientboundMapItemDataPacket::BITFLAG_TEXTURE_UPDATE;
                
    $pk->height 128;
                
    $pk->width 128;
                
    $pk->scale 1;
                
    $pk->colors $colors;
                
    $player->getNetworkSession()->sendDataPacket($pk);
            }
        }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    435
    The tag map_uuid is a LongTag
     
    EnderVlad likes this.
  3. EnderVlad

    EnderVlad Creeper

    Messages:
    5
    GitHub:
    EnderVlad96
    Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.