blob: 61d4d40891341d201b9620cb43c29a656384d3b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package shcm.shsupercm.fabric.citresewn.cit.builtin.conditions;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;
import shcm.shsupercm.fabric.citresewn.cit.CITCondition;
import shcm.shsupercm.fabric.citresewn.cit.CITContext;
import shcm.shsupercm.fabric.citresewn.cit.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue;
/**
* Common condition parser for identifiers.
*/
public abstract class IdentifierCondition extends CITCondition {
/**
* Parsed identifier.
*/
protected Identifier value;
/**
* Converts the given context to an identifier to compare the parsed value to.
* @param context context to retrieve the compared value from
* @return the identifier value associated with the given context
*/
protected Identifier getValue(CITContext context) {
throw new AssertionError("Not implemented by this condition");
}
@Override
public void load(PropertyValue value, PropertyGroup properties) throws CITParsingException {
try {
this.value = new Identifier(value.value());
} catch (InvalidIdentifierException e) {
throw new CITParsingException(e.getMessage(), properties, value.position());
}
}
@Override
public boolean test(CITContext context) {
return this.value.equals(getValue(context));
}
}
|