#Portals

1 messages · Page 1 of 1 (latest)

proper phoenix
#

What do you mean by many portals?

fallow dawn
#

many portals in one chunk

proper phoenix
#

ah ok, but seperate portals, you just want to find all connected blocks in a portal?

fallow dawn
#

yeah

proper phoenix
#

ok thats not hard

fallow dawn
#

when I have tried I've got an infinite loop

proper phoenix
#

if you have one block, you simply do a N/S/E/W search for a block next to teh start block

#

expanding out

#

you shoudl also include up and down to cover upright portals

haughty maple
#

^ i was kinda saying that in general chat basically troop through x and y coordinets in a sense

proper phoenix
#

I've done this algorithm for claimed plots

#

slightly more complex but the same idea

haughty maple
#

Yeah thats just a very basic way to do it, im not the best at algorithms, but something like that wouldn't be too hard on the CPU

fallow dawn
#

so a tree with 4 nodes?

haughty maple
#

Okay just wanted to drop by and put that info in here, gnight you 2

fallow dawn
#

@proper phoenix

proper phoenix
#

no

#

you have 6 directions you have to search

#

you will need to create some helper methods...

#
List<BlockFace> cardinal = Arrays.asList( BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.Down );

public static List<Block> getNeighbourPortals(Block block) {
  List<Block> portals = new ArrayList<Block>();
  for (BlockFace direction : cardinal) {
    Block test = block.getFacing(direction);
    if (test.getType() == Material.PORTAL)
      portals.add(test);
  }
  return portals;
}```
#

basically search around a block for any portal blocks

#

you will have to fix the Material check to look for any portal block types

#

Then the algorithm part

fallow dawn
#

thank you

proper phoenix
#

Untested but somethgin like ```java
public static List<Block> getAllConnected(Block block) {

    Set<Block> tested = new HashSet<Block>();
    List<Block> toTest = new ArrayList<Block>();
    
    toTest.add(block);
    
    /*
     * Loop until we have tested all connected blocks.
     */
    while (!toTest.isEmpty()) {
        
        Block test = toTest.get(0);
        toTest.remove(0);
        tested.add(test);
        
        for (Block portal : getNeighbourPortals(test)) {
            if (!toTest.contains(portal) && !tested.contains(portal)) {
                toTest.add(portal);
            }
        }
    }
    return Collections.unmodifiableList(new ArrayList<Block>(tested));
}```
#

if you call getAllConnected passing it a portal block it should return a list of all connected portal blocks

#

let me know if it works

#

as it was just thrown together

fallow dawn
#

Will do, thanks a lot

#

Thank you very much

#

It's working