Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockPattern
- {
- public interface PatternElement
- {
- boolean match(World world, BlockPos position);
- }
- public static class Layer
- {
- public static class Row
- {
- private final List<PatternElement> elements;
- public Row(List<PatternElement> elements)
- {
- this.elements = elements;
- }
- public boolean match(World world, BlockPos position)
- {
- for (int z = 0; z < elements.size(); z++)
- if (!elements.get(z).match(world, position.add(0, 0, z)))
- return false;
- return true;
- }
- }
- private final List<Row> rows;
- private final int minOccurrence;
- private final int maxOccurrence;
- public Layer(List<Row> rows, int minOccurrence, int maxOccurrence)
- {
- this.rows = rows;
- this.minOccurrence = minOccurrence;
- this.maxOccurrence = maxOccurrence;
- }
- public int match(World world, BlockPos position)
- {
- int y = 0;
- occurrences:
- for (; y < maxOccurrence; y++)
- {
- for (int x = 0; x < rows.size(); x++)
- {
- Row row = rows.get(x);
- boolean rowMatch = row.match(world, position.add(x, y, 0));
- if (!rowMatch)
- {
- y -= 1;
- break occurrences;
- }
- }
- }
- if (y < minOccurrence)
- return -1;
- return y + 1;
- }
- }
- private final List<Layer> layers;
- public BlockPattern(List<Layer> layers)
- {
- this.layers = layers;
- }
- public boolean match(World world, BlockPos position)
- {
- int y = 0;
- for (Layer layer : layers)
- {
- int match = layer.match(world, position.add(0, y, 0));
- if (match == -1)
- return false;
- else
- y += match;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement