mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
add XOR pattern
This commit is contained in:
parent
48c7e4ab40
commit
5881e4465f
@ -28,6 +28,7 @@ import com.dfsek.terra.addons.feature.locator.config.pattern.NotPatternTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.pattern.OrPatternTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.pattern.SingleBlockMatchPatternTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.pattern.SolidMatchPatternTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.pattern.XorPatternTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
@ -83,6 +84,7 @@ public class LocatorAddon implements AddonInitializer {
|
||||
|
||||
patternRegistry.register(addon.key("AND"), AndPatternTemplate::new);
|
||||
patternRegistry.register(addon.key("OR"), OrPatternTemplate::new);
|
||||
patternRegistry.register(addon.key("XOR"), XorPatternTemplate::new);
|
||||
patternRegistry.register(addon.key("NOT"), NotPatternTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.feature.locator.config.pattern;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import com.dfsek.tectonic.api.exception.ValidationException;
|
||||
|
||||
import com.dfsek.terra.addons.feature.locator.patterns.Pattern;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class XorPatternTemplate implements ObjectTemplate<Pattern>, ValidatedConfigTemplate {
|
||||
@Value("patterns")
|
||||
private @Meta List<@Meta Pattern> patterns;
|
||||
|
||||
@Override
|
||||
public Pattern get() {
|
||||
Pattern current = patterns.remove(0);
|
||||
while(!patterns.isEmpty()) {
|
||||
current = current.xor(patterns.remove(0));
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(patterns.isEmpty()) throw new ValidationException("AND Pattern must specify at least 1 pattern.");
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user