2022-08-08 17:40:12 +08:00
|
|
|
package com.gtnewhorizon.structurelib.structure;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
2025-10-28 00:52:40 -04:00
|
|
|
/**
|
|
|
|
|
* A functional interface that is used to iterate over an arbitrary structure.
|
|
|
|
|
*/
|
|
|
|
|
@FunctionalInterface
|
|
|
|
|
public interface IStructureWalker<T> {
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2025-10-28 00:52:40 -04:00
|
|
|
/**
|
|
|
|
|
* Called once per structure element.
|
|
|
|
|
*
|
|
|
|
|
* @param element The current element
|
|
|
|
|
* @param world The current world
|
|
|
|
|
* @param x The absolute X position of the element in world coordinates
|
|
|
|
|
* @param y The absolute Y position of the element in world coordinates
|
|
|
|
|
* @param z The absolute Z position of the element in world coordinates
|
|
|
|
|
* @param a The relative A position of the element in structure-local coordinates (pre transform)
|
|
|
|
|
* @param b The relative B position of the element in structure-local coordinates (pre transform)
|
|
|
|
|
* @param c The relative C position of the element in structure-local coordinates (pre transform)
|
|
|
|
|
* @return False to stop iterating, true to continue.
|
|
|
|
|
*/
|
2022-09-11 02:54:11 +08:00
|
|
|
boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c);
|
2022-08-12 12:25:03 +08:00
|
|
|
|
2022-09-11 02:54:11 +08:00
|
|
|
default boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
|
|
|
|
int c) {
|
2022-08-12 12:25:03 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static <T> IStructureWalker<T> ignoreBlockUnloaded(IStructureWalker<T> walker) {
|
|
|
|
|
return new IStructureWalker<T>() {
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2022-08-12 12:25:03 +08:00
|
|
|
@Override
|
2022-09-11 02:54:11 +08:00
|
|
|
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c) {
|
|
|
|
|
return walker.visit(element, world, x, y, z, a, b, c);
|
2022-08-12 12:25:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-09-11 02:54:11 +08:00
|
|
|
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
|
|
|
|
int c) {
|
|
|
|
|
return walker.visit(element, world, x, y, z, a, b, c);
|
2022-08-12 12:25:03 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static <T> IStructureWalker<T> skipBlockUnloaded(IStructureWalker<T> walker) {
|
|
|
|
|
return new IStructureWalker<T>() {
|
2023-01-30 12:52:27 +00:00
|
|
|
|
2022-08-12 12:25:03 +08:00
|
|
|
@Override
|
2022-09-11 02:54:11 +08:00
|
|
|
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z, int a, int b, int c) {
|
|
|
|
|
return walker.visit(element, world, x, y, z, a, b, c);
|
2022-08-12 12:25:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-09-11 02:54:11 +08:00
|
|
|
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z, int a, int b,
|
|
|
|
|
int c) {
|
2022-08-12 12:25:03 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-08-08 17:40:12 +08:00
|
|
|
}
|