mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-15 21:31:05 +00:00
implement blockstate cache in Column
This commit is contained in:
+6
-1
@@ -13,6 +13,8 @@ import com.dfsek.terra.api.structure.feature.Locator;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
|
||||
public class PatternLocator implements Locator {
|
||||
private final Pattern pattern;
|
||||
@@ -25,6 +27,9 @@ public class PatternLocator implements Locator {
|
||||
|
||||
@Override
|
||||
public BinaryColumn getSuitableCoordinates(Column<?> column) {
|
||||
return new BinaryColumn(search, y -> pattern.matches(y, column));
|
||||
int min = FastMath.max(column.getMinY(), search.getMin());
|
||||
int max = FastMath.min(column.getMaxY(), search.getMax());
|
||||
if(min >= max) return BinaryColumn.getNull();
|
||||
return new BinaryColumn(min, max, y -> pattern.matches(y, column));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -13,6 +13,8 @@ import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
|
||||
public class MatchPattern implements Pattern {
|
||||
private final Range range;
|
||||
@@ -25,8 +27,10 @@ public class MatchPattern implements Pattern {
|
||||
|
||||
@Override
|
||||
public boolean matches(int y, Column<?> column) {
|
||||
for(int i = range.getMin(); i < range.getMax(); i++) {
|
||||
if(!matches.test(column.getBlock(y + i))) return false;
|
||||
int min = FastMath.max(column.getMinY(), range.getMin() + y);
|
||||
int max = FastMath.min(column.getMaxY(), range.getMax() + y);
|
||||
for(int i = min; i < max; i++) {
|
||||
if(!matches.test(column.getBlock(i))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user