# 1.15.2 How do i check if an area is sealed.

Discussion in 'Spigot Plugin Development' started by hidden1nin, Feb 14, 2020.

1. ### hidden1nin

I'm developing a plugin that will use oxygen and i need to know how to see if a 3*3*3 cube is sealed, and once i learn that, how to see if a more ridged shape is sealed like a L shape box, i know i should only check whenever a block is updated, but i am still confused entirely.

2. ### MightyOne

Create two sets, one for processed air blocks and one for “unprocessed” air blocks - those which have the possibility to be connected to new air blocks. Add your source block to the latter one.
Create a while loop under the condition that there are unprocessed blocks left in that set and that the size of the set with processed blocks is smaller than 3x3x3 or whatever.
In the loop pick one block from the unprocessed block set and detect all neighbor blocks with e.g Block#getRelative() in all (axis aligned) directions. Add all neighbor blocks with Material air to the unprocessed block set (but only if they don’t exist already in one of the sets).
Finish the loop with moving the picked block from the unprocessed set to processed one.

The algorithm should not stop listing connected air blocks unless the whole closed space is detected or if the limit of blocks is exceed.

4. ### ForbiddenSoul

Well this is not a good solution, but it is a start... Maybe.

If you have a way to distinguish the inside of the cube, vs the outside, excellent, if not, things will probably get expensive.

Sample an air block from within the cube / shape.
Get a set of all other connect air blocks.
If this operation completes, and there are only 1, 14, or like 100 other connected air blocks the container is sealed.
What if you sample something that is not sealed though? It would just keep checking and checking.
Set a limit of some kind, I don't know, maybe 1024, and check if the set count exceeds that limit while adding connected air. If it exceeds the limit the it is either not sealed or too large.

If you can't distinguish inside from outside, you might have to run this check 6 times (faces if a block) to see if there is an inside.

Either of those is not so bad, if you can just check once and save the result. If you have to check multiple "boxes" for multiple people in real time, it is going to get real heavy real quick.

More brain storming is needed for a good answer. Some saving of which air blocks are considered sealed, should be the way to go, when to check or recheck if they are sealed is the tricky bit...

5. ### hidden1nin

How do modpacks like galactic craft do their checks? Maybe I should copy what they use

6. ### robertlit

Can't you check that yourself?

7. ### Stellrow

Hes is pretty much on the point,you could go deeper and checking a a block sides and slowly building a cube walls

Also
Code (Text):
public void checkCrops(Location center,Integer Ydiff,Integer radius) {
Location min = new Location(center.getWorld(), center.getX() - radius, center.getY() + Ydiff, center.getZ() - radius);
Location max = new Location(center.getWorld(), center.getX() + radius, center.getY() + Ydiff, center.getZ() + radius);
for (int x = (int) min.getX(); x <= (int) max.getX(); x++) {
for (int z = (int) min.getZ(); z <= (int) max.getZ(); z++) {
Location cord= new Location(center.getWorld(), x, min.getY(), z);
Block block = cord.getBlock();

A thing i used way back years ago,tweak it for ur needs

Meaning you could just check size by size,check if all are air and stuff...
How would this work? You get all the cube walls(sides/top floor/bottom floor) check if any are air and solved..

#7
Last edited: Feb 14, 2020
• Like x 1