Cuberite Forum
Custom images on maps - Printable Version

+- Cuberite Forum (
+-- Forum: Plugins (
+--- Forum: Plugin Discussion (
+--- Thread: Custom images on maps (/thread-2952.html)

Custom images on maps - Mathias - 05-18-2017

I noticed that you can change individual pixels on maps using SetPixel in cMap. I had an idea of creating a plugin (similar to Bukkit plugins) that downloads an image from the internet, resizes it to the size of a map, fetches the colors from the pixels in the image and places them on the map with SetPixel. However, I have no idea how to manipulate the image easily with Lua. Does anyone have any ideas?

(Map in this case is the map item that you can hold in your hand and place)

The code I have written so far. It currently only downloads the image:

Connect = {}

function Initialize(Plugin)

    dofile(cPluginManager:GetPluginsPath() .. "/InfoReg.lua")

    LOG("Initialised " .. Plugin:GetName())
    return true

function HandleMapImageCommand(Split, Player)
    if Split[2] == nil then
        Player:SendMessageInfo("Usage: " .. Split[1] .. " <imageurl>")
        local URL = Split[2]
        local FileName = URL:match("([^/]+)$")
            function(Body, Data)
                local Image =, "wb")
                local Image = nil
    return true

function OnDisable()
    LOG("Disabled " .. cPluginManager:GetCurrentPlugin():GetName() .. "!")

RE: Custom images on maps - NiLSPACE - 05-18-2017

You'll have to decode the image so you can read the individual image. There is a pure-Lua one for PNG's:

RE: Custom images on maps - Seadragon91 - 05-18-2017

The code does this:
  • Add map to player inventory with damage value 1, if not existent
  • Call callback on the map
  • For loop with x,y = 1-  100, the size is by default 128 x 128
  • Set the pixel to cMap.E_BASE_COLOR_TRANSPARENT
Don't see any change, maybe a missing packet update to the player.

Add the code in a plugin and register the command:
cPluginManager:BindCommand("/testmap", "testmap", CommandTestMap, "testmap")

function CommandTestMap(a_Split, a_Player)
	if not(a_Player:GetInventory():HasItems(cItem(E_ITEM_MAP,1, 1))) then
	-- Add map
		a_Player:GetInventory():AddItem(cItem(E_ITEM_MAP, 1, 1))

	a_Player:GetWorld():GetMapManager():DoWithMap(1, -- damage value = item id of map
		a_Player:SendMessage("Callback called")
		for x = 1, 100 do
			for y = 1, 100 do
				a_Map:SetPixel(x, y, cMap.E_BASE_COLOR_TRANSPARENT)
	return true

RE: Custom images on maps - Seadragon91 - 05-18-2017

@Mathias Does it work for you setting the pixel and you see it then?

RE: Custom images on maps - Mathias - 05-19-2017

(05-18-2017, 11:32 PM)Seadragon91 Wrote: @Mathias Does it work for you setting the pixel and you see it then?

It seems like maps are not generated unless right-clicking an empty map. I can then modify the pixels, but the custom pixels are overwritten if you don't change the map scale.

This code works after the map has been generated by right-clicking an empty map:
        Map:SetPosition(99999999, 99999999)
        for x = 0, 128 do
            for y = 0, 128 do
                Map:SetPixel(x, y, cMap.E_BASE_COLOR_BLUE)
    return true

RE: Custom images on maps - BillBodkin - 11-21-2019

It also seems to only work if a player is currently holding a map, im guessing map updates ore only sent to players who are holding a map.