#Portals
1 messages · Page 1 of 1 (latest)
many portals in one chunk
ah ok, but seperate portals, you just want to find all connected blocks in a portal?
yeah
ok thats not hard
when I have tried I've got an infinite loop
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
^ i was kinda saying that in general chat basically troop through x and y coordinets in a sense
I've done this algorithm for claimed plots
slightly more complex but the same idea
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
so a tree with 4 nodes?
Okay just wanted to drop by and put that info in here, gnight you 2
@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
thank you
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