Search code examples
javaminecraftbukkit

Display Images on Multiple Maps in Item Frames


I am trying to create a slideshow like creation using a Spigot/Bukkit java plugin. I have struggled to find an answer to this online. What I want is a 5x5 grid of maps on item frames that I can put a image on. I would like to switch between different images on command. How would I go about doing this?


Solution

  • I once tried to implement a video player with maps. Let's start a little smaller, display one image on one map. To accomplish that, you need to implement your own MapRenderer. Just create a class which inherit from the MapRenderer class an override the render​ method. You need to resize and load the Image before drawing with drawImage(). The render method is called every tick, that's why you shouldn't do this inside the render method, it takes too much time and would block your main thread.

    To apply the renderer just create a map view with the createMap() method, clear the renderers list with mapview.getRenderers().clear(); and add your own renderer mapview.getRenderers().add(ownRenderer);.

    As last step you need to apply the MapView to a MapItem. Just create an ItemStack of the map material and cast the Metadata to MapMeta to apply the MapView with setMapView().

    To span the image upon multiple maps, just create multiple renderer and mapview instances which all display another part of the image (you can split the image with: getSubimage()). Again, split the Image asynchronously and definitely not inside the render method.

    Hope this helps, it isn't a complete tutorial but you should be able to create a small prototype with these hints.