Solved Map not rendering correctly

Discussion in 'Spigot Plugin Development' started by bys1, Mar 12, 2020.

  1. I have three MapRenderers.
    Renderer 1 is called every tick and sets some pixels to light blue.
    Renderer 2 is called every 5 seconds and renders the map.
    Renderer 3 is called every tick but does not edit the map; it only handles Cursors.
    Now I know from debug logs that renderer 1 is constantly setting certain pixels to 126 (light blue), but the light blue pixels don't show up at all. Only when the map renders for the first time, but after modifying the scale it doesn't work at all while the renderer is still setting the pixels according to the debug logs.
    On MapInitializeEvent I'm setting the scale to Scale.FARTHEST, but after any other scale changes performed later it won't work anymore. I know for sure that any other renderers are removed, so I have no idea why it does not show the pixels that are clearly being set...

    From debugging I know that the pixels are set correctly serverside, even 2,5 seconds later. However, the client simply doesn't show them...

    Any ideas?

    Solution:
    This is probably a bug in Spigot. If you have multiple MapRenderers modifying the map canvas, only the canvas of the last renderer is actually being sent to the player. Any other renderer will be ignored!
     
    #1 bys1, Mar 12, 2020
    Last edited: Mar 18, 2020
  2. Have you tried rejoining the server and checking if something changed?
     
  3. Doesn't matter at all, the map should be updating normally.
     
  4. Okay I will experiment a bit and I'll tell you if I find a solution
     
  5. Can you post your code? Changing map scale works fine for me.
    Code (Java):
        @EventHandler
        public void onMapInit(MapInitializeEvent mie){
            MapView mv = mie.getMap();
            Bukkit.broadcastMessage("scale:"+mv.getScale());
            mv.getRenderers().clear();
            mv.addRenderer(new TestMapRenderer());
        }
     
     
        class TestMapRenderer extends MapRenderer{
            int currX=0,currY=0,timesCalled=0;
         
            @SuppressWarnings("deprecation")
            @Override
            public void render(MapView mv, MapCanvas mc, Player p) {
                int c = timesCalled%208;//loop all colors
                //mc.drawText(0, 0, MinecraftFont.Font, timesCalled+"-"+p.getDisplayName());
                //p.resetTitle();
                p.sendTitle("", "timesCalled:"+timesCalled, 0, 1, 0);
                byte cB = (byte) (c<128?c:-129+(c-127));
                for(int y = 0; y < 8; y++){
                    for(int x = 0; x < 8; x++){
                        mc.setPixel(currX+x, currY+y, cB);
                    }
                }
                currX+=8;
                if(currX >= 128){
                    currY+=8;
                    currX=0;
                    if(currY >= 128){
                        currY=0;
                        for(int y = 0; y < 128; y++){
                            for(int x = 0; x < 128; x++){
                                mc.setPixel(x, y, (byte)119); //fill black
                            }
                        }
                        int sc = mv.getScale().getValue()+1;
                        if(sc > 4) sc = 0;
                        mv.setScale(MapView.Scale.valueOf((byte)sc));
                        Bukkit.broadcastMessage("newScale:"+mv.getScale());
                    }
                }
                timesCalled++;
            }
        }
     
  6. see if the map still holds the reference to the renderer when it begins to fail
     
  7. You mean check if the renderer is still there?
    It is, because it is spamming the debug logs in the console. And those logs are telling me it is setting certain pixels to light blue (with coords between 0 and 128), however I don't see those light blue pixels on the actual map.