Temporarily Saving Specific Block Locations Then Using Them..

Discussion in 'Spigot Plugin Development' started by digdiggydigger, May 17, 2017.

  1. Hello Spigot,

    So today i'm looking for some help regarding searching through a world and temporarily saving (Saving until a server reload/restart) all the diamond block locations so I can finally put a floating item on top of them. Now I know there are things on Google, but they just didn't make sense to my brain I guess so i was hoping for maybe a more helpful response from the community?

    I've not don't anything like this before so its new to me :p I do know that it probably makes more sense to use a HashMap or an ArrayList to store the locations but apart from that I'm clueless :oops:

    Thanks, Ethan:D

    EDIT: Is it worth me using maybe world guard to check through the blocks in a region?
     
    #1 digdiggydigger, May 17, 2017
    Last edited: May 17, 2017
  2. Well, if you want to save every diamond block on the world that's going to use a lot of space, since world can be quite big, i would save the locations when the chunck is generated in a database, then you kinda can listen for some events to know when the diamond block is removed, if you want to get the diamond blocks from an area you can simply scan the area and then add every diamond block location to a list.
     
    • Like Like x 1
  3. It's a void world and I've only placed about 30 diamond blocks so I don't think it will take that much space, and thats what I'm struggling with because I know what todo just not how to do it..
     
  4. Well, how did you place those diamond blocks ? If you placed them with code then just save the locations, if not it depends of how affar they are from each other, you could just scan and area for them. If you manually placed those blocks you could also make a system that when you manually place the block it will be added to a list.
     
  5. They were placed around the map where it was created and they are spaced out but the map is no larger than about 200x200
     
  6. Then you can scan a 200 x 200 area and look for the diamonds.
     
  7. I know but..
     
  8. Found this code with a google search. Maybe it can help with what you need

    Code (Text):
    public List<Block> getRegionBlocks(World world, Location loc1, Location loc2) {
            List<Block> blocks = new ArrayList<Block>();
            for(double x = loc1.getX(); x <= loc2.getX(); x++) {
                for(double y = loc1.getY(); y <= loc2.getY(); y++) {
                    for(double z = loc1.getZ(); z <= loc2.getZ(); z++) {
                        Location loc = new Location(world, x, y, z);
                        blocks.add(loc.getBlock());
                    }
                }
            }
            return blocks;
        }
     
  9. Hmm okay thank you, so then i would just use a for and check all the blocks in that list and any diamonds block it finds - add them to another list then i can use it?
     
  10. That's the theory :)
     
    • Agree Agree x 1