1.8.8 How can I scan an area for certain formations of blocks?

Discussion in 'Spigot Plugin Development' started by _CheeseGrater_, Jul 1, 2020 at 1:08 AM.

  1. ugh so this is gonna be hard to explain.
    So basically I'm trying to make a mini-game, and I want it to be easy to make maps for me and my friends to play on, and to mark where I want players to spawn I'm gonna put down two beacon blocks on top of each other to signify where I need the plugin to send players(once players actually join it turns those to air and puts a cage around them but yea). So is there any way that I can find the location of all beacon blocks in a certain area, then check if there is another beacon block on top of that, then add that location to a list?7
  2. It's not going to be easy, and it would probably be a little laggy.

    What you can do, is create like a special custom schematic class, which details what a specific build looks like. For example, it could store a hashmap of blocks to relative locations:

    { [0,0,0]:Material.RED_WOOL,

    This example structure would just be a mini L shape made out of 3 different wool blocks. Another thing you'll need in this class is a method to check if a block is part of this structure. So just loop through the relative locations, then do block.getRelative(x,y,z) to check if the material is the same.

    This is where it gets a bit tricky. If I rotate the structure, the green wool wouldn't be at 0,0,1 anymore, it could be at 0,0,-1 or 1,0,0 or -1,0,0 as well. So you also need to make a loop to accommodate for this, and similar cases.

    Now that you have this custom schematic class, simply loop through every block in the area, and run the check method.

    You can also just use BlockPlaceEvent to try and track it and this would be more optimised, but it will break when tools like worldedit are used to place the beacons.