mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
add optimization for AdjacentPatternLocator
This commit is contained in:
+13
-8
@@ -11,6 +11,8 @@ import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
|||||||
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
import com.dfsek.terra.api.structure.feature.BinaryColumn;
|
||||||
import com.dfsek.terra.api.structure.feature.Locator;
|
import com.dfsek.terra.api.structure.feature.Locator;
|
||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
import com.dfsek.terra.api.world.WritableWorld;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
|
|
||||||
@@ -31,16 +33,19 @@ public class AdjacentPatternLocator implements Locator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValid(int y, Column<?> column) {
|
private boolean isValid(int y, Column<?> column) {
|
||||||
|
WritableWorld world = column.getWorld();
|
||||||
|
int x = column.getX();
|
||||||
|
int z = column.getZ();
|
||||||
if(matchAll) {
|
if(matchAll) {
|
||||||
return pattern.matches(y, column.adjacent(0, -1)) &&
|
return pattern.matches(world, x, y, z - 1) &&
|
||||||
pattern.matches(y, column.adjacent(0, 1)) &&
|
pattern.matches(world, x, y, z + 1) &&
|
||||||
pattern.matches(y, column.adjacent(-1, 0)) &&
|
pattern.matches(world, x - 1, y, z) &&
|
||||||
pattern.matches(y, column.adjacent(1, 0));
|
pattern.matches(world, x + 1, y, z);
|
||||||
} else {
|
} else {
|
||||||
return pattern.matches(y, column.adjacent(0, -1)) ||
|
return pattern.matches(world, x, y, z - 1) ||
|
||||||
pattern.matches(y, column.adjacent(0, 1)) ||
|
pattern.matches(world, x, y, z + 1) ||
|
||||||
pattern.matches(y, column.adjacent(-1, 0)) ||
|
pattern.matches(world, x - 1, y, z) ||
|
||||||
pattern.matches(y, column.adjacent(1, 0));
|
pattern.matches(world, x + 1, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-2
@@ -7,14 +7,18 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.feature.locator.patterns;
|
package com.dfsek.terra.addons.feature.locator.patterns;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.world.ServerWorld;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.world.WritableWorld;
|
||||||
|
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
import net.jafama.FastMath;
|
|
||||||
|
|
||||||
|
|
||||||
public class MatchPattern implements Pattern {
|
public class MatchPattern implements Pattern {
|
||||||
private final Range range;
|
private final Range range;
|
||||||
@@ -35,4 +39,15 @@ public class MatchPattern implements Pattern {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(WritableWorld world, int x, int y, int z) {
|
||||||
|
int min = FastMath.max(world.getMinHeight(), range.getMin() + y);
|
||||||
|
int max = FastMath.min(world.getMinHeight(), range.getMax() + y);
|
||||||
|
if(max <= min) return false;
|
||||||
|
for(int i = min; i < max; i++) {
|
||||||
|
if(!matches.test(world.getBlockState(x, y, z))) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -7,12 +7,21 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.feature.locator.patterns;
|
package com.dfsek.terra.addons.feature.locator.patterns;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.world.ReadableWorld;
|
||||||
|
import com.dfsek.terra.api.world.ServerWorld;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
import com.dfsek.terra.api.world.WritableWorld;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||||
|
|
||||||
|
|
||||||
public interface Pattern {
|
public interface Pattern {
|
||||||
boolean matches(int y, Column<?> column);
|
boolean matches(int y, Column<?> column);
|
||||||
|
|
||||||
|
default boolean matches(WritableWorld world, int x, int y, int z) {
|
||||||
|
return matches(y, world.column(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default Pattern and(Pattern that) {
|
default Pattern and(Pattern that) {
|
||||||
return (y, column) -> this.matches(y, column) && that.matches(y, column);
|
return (y, column) -> this.matches(y, column) && that.matches(y, column);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user