[Class] Render Custom Images in Minecraft! V1.2

Discussion in 'Resources' started by bigteddy98, Mar 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bigteddy98

    This resource is no longer available.
     
  2. Offline

    DevRosemberg

    Well, thats nice
     
    bigteddy98 likes this.
  3. Offline

    DarkBladee12

    bigteddy98 it's kinda inefficient when you let your renderer extend as listener if you decide to add many pictures. For example when you have 100 pictures there are 100 listeners registered for the PlayerQuitEvent. You should rather put the PlayerQuitEvent listener into your ArtRenderer class and store all renderers there and make a onQuit(Player p) method in the renderer class and call that from every renderer in the list when the event gets called. Besides that you should also call the method that reads an image from an url in a new thread, because that can sometimes take much time which will make the server lag meanwhile.
     
    bigteddy98 likes this.
  4. Offline

    bigteddy98

    EDIT: Fixed the PlayerQuitEvent, thanks for giving me advise.
    Reading the URL from another thread, would be better, but a little bit hard to work with. That's also why I advise you to get all pictures in onEnable, because getting your image only has to happend once.
     
  5. Offline

    DarkBladee12

    bigteddy98 yes that's probably more efficient!
     
    bigteddy98 likes this.
  6. Offline

    Howaner

    bigteddy98 likes this.
  7. Offline

    ItsLeoFTW

    Sounds neat. I'm going to try it right now.
     
    bigteddy98 likes this.
  8. Offline

    DarkBladee12

    bigteddy98 likes this.
  9. Offline

    bigteddy98

    Thanks bro :)
     
  10. Offline

    bigteddy98

    That plugin indeed uses the same way to do it, but this resource is probably a lot easier to use in your own plugins then using that plugin as a dependency.
     
  11. Offline

    ccrama

    bigteddy98 Created this massive thing with 203 images, takes FOREVER to login though, any way to fix/ease that?
    [​IMG]

    //EDIT
    I did this by looping through every x/y axis of the image area (29x7 blocks), and cropping the image with .getSubimage!

    Also, I fixed the extreme lag on joins. All I had to do was add a runnable in the Join handler in the class, and as a bonus the images load almost instantly with very little impact on preformance/join time (i.e. they join instantly, and after about a second, the images are fully loaded with no little lines). Here is the updated method
    Code:java
    1. @EventHandler
    2. private void onJoin(PlayerJoinEvent event) {
    3. final Player p = event.getPlayer();
    4. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("UnityHub"), new Runnable() {
    5. public void run() {
    6. for (ItemFrame frame : ArtRenderer.this.frames) {
    7. MapView map = Bukkit.getServer().getMap(frame.getItem().getDurability());
    8. p.sendMap(map);
    9. }
    10. }
    11. }, 30L);
    12.  
    13.  
    14. }


    //EDIT
    only issue with this method is it reloads on every join, but me with 400+ maps loads in about 5 seconds after join

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    DoctorDark and bigteddy98 like this.
  12. Offline

    bigteddy98

    ccrama looks really nice, but does that also fix the problems you were expecting with logging in? If so, I will directly add it to the class.

    //EDIT: I tested it and I must say I really like the eay you fixed it, I will add it.
     
  13. Offline

    ccrama

    bigteddy98 I found an issue where if you are loading more than 300 images, it will get SUPER slow and not work very well. For smaller applications though, my fix should work! Thanks!
     
    bigteddy98 likes this.
  14. Offline

    bigteddy98

    Thanks alot, will add it now.

    Could you send me the code you are using to loop and crop your image? Might wanna add it if you are fine with that.

    Updated some code, thanks to ccrama, tested it with an image of 138 paintings, laggs a little, but works fine:
    [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    ccrama likes this.
  15. Offline

    ccrama

    bigteddy98 Possibly! Depends on whether I end up using it for part of the server's hub who I'm working for. Ill send you a PM if I can let you use it!
     
  16. Offline

    MiniDigger

  17. Offline

    ccrama

    bigteddy98 check your inbox. I was able to make it almost exclusively lag free (lag from the MAPS is gone, only slight lag from item frames remains). It has to do with the joinevent causing massive amounts of packets being sent, in my case 13,000+ packets were being sent on join. You can test out the fix I sent you in your mail and see if it works for you too!
     
  18. Offline

    Syd

    Btw. there are several public plugin on BukkitDev, that allow you to create custom images.
     
  19. Offline

    HeavyMine13

    I need to make a massive picture! And it needs like 50x50 frames! How can I do it?
     
  20. Offline

    ccrama

    HeavyMine13 that will create 2500 images, which is like spawning 2500 cows in a single 50x50 area. Imagine the lag that will cause! Itemframes are entities just like animals/monsters, and should be treated as such.
     
  21. Offline

    HeavyMine13

    XD I meant 5x5 lol like yours how can I do that u said u looped through x n y n z and use cropping can u show me how pls?
     
  22. Offline

    ccrama

    HeavyMine13 well it's private code for a server I'm working for, but I can give you some of the examples of how I did it. Note that the code is very crude, but it works...

    First, create a bukkit runnable for each of your rows, nested within each other. Then find a location of where they are to spawn. Next, create an integer for each with a value of 0. In each of the runnables, put an if statement like so:

    if(yournumber > 0){
    yournumber += 1;
    //spawn image here. You can use image.getSubImage(x value * 128, y value * what row it is, 128, 128) to get one chunk of the image. Get the x and y value from a variable that changes every runnable too.

    When if(yournumber == 0){, nest the next runnable under that, and at the very end put this.cancel().

    Sorry I cant give out the full code, but hope this helps regardless!
     
  23. Offline

    MrAwellstein

    Do you think there is any possibility to get moving pictures with something like this?
     
  24. Offline

    HeavyMine13

    What do u mean by bukkit runnable for each row, nested within each other. And what do I do with the integer if it (as u said) equals 0?
     
  25. Offline

    DarkBladee12

    HeavyMine13 I've wrote something to split an image into smaller parts yesterday. Here's the code:

    Code:java
    1. public List<BufferedImage> split(BufferedImage image, int width, int height) {
    2. int type = image.getType();
    3. int imageWidth = image.getWidth();
    4. int imageHeight = image.getHeight();
    5. int rows = imageWidth / width;
    6. if (imageWidth % width != 0)
    7. rows++;
    8. int columns = imageHeight / height;
    9. if (imageHeight % height != 0)
    10. columns++;
    11. List<BufferedImage> images = new ArrayList<BufferedImage>();
    12. for (int x = 0; x < rows; x++) {
    13. for (int y = 0; y < columns; y++) {
    14. int positionX = width * x;
    15. int positionY = width * y;
    16. int splitWidth = positionX + width > imageWidth ? imageWidth - positionX : width;
    17. int splitHeight = positionY + height > imageHeight ? imageHeight - positionY : height;
    18. BufferedImage split = new BufferedImage(splitWidth, splitHeight, type);
    19. Graphics2D graphics = split.createGraphics();
    20. graphics.drawImage(image, 0, 0, splitWidth, splitHeight, positionX, positionY, positionX + splitWidth, positionY + splitHeight, null);
    21. graphics.dispose();
    22. images.add(split);
    23. }
    24. }
    25. return images;
    26. }
     
    HeavyMine13 and bigteddy98 like this.
  26. Offline

    bigteddy98

    Moving images would be possible, but this would need a lot CPU and almost unlimited bandwith. I tried this once and my CPU was continuously at 100% (2 fps), my server send almost 10.000 packets per second, for only one player.

    So, it will be possible, but not in a real server I guess.
     
    DarkBladee12 likes this.
  27. Offline

    MrAwellstein

    What about making it invisible? Having multiple stacked in the same place and try alternating through them?

    BTW
    Thanks for the awesome tutorials. I really enjoy them. :D
     
  28. Offline

    bigteddy98

    The Minecraft client won't keep maps in memory when you hide them from the client. If you want to switch between multiple images, you will need to resend the whole picture, which might cause extreme high bandwith/cpu usage.

    Thanks, I enjoy doing it :D.

    Not realistic I think, this will need tons of bandwith usage and this will cause the clients to lagg.

    Thanks alot, I think many people will thank you for this (including me, thanks :D).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  29. Offline

    SoThatsIt

    this would mean you would need multiple item frames for each frame of the video. That could be a lot of item frames which would cause lag. Maybe you could send despawn and spawn packets to the players though?
     
    bigteddy98 likes this.
  30. Offline

    HeavyMine13

    Thanks :D 1 thing, how can I use it ._.
     
Thread Status:
Not open for further replies.

Share This Page