mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 05:02:30 +00:00
Merge upstream
This commit is contained in:
commit
e12163f70c
26 files changed
+763
-370
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package vazkii.botania.api.state;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
|
||||
// Generic base class for unlisted properties
|
||||
public class PropertyObject<T> implements IUnlistedProperty<T> {
|
||||
|
||||
private final String name;
|
||||
private final Class<T> clazz;
|
||||
private final Predicate<T> validator;
|
||||
private final Function<T, String> stringFunction;
|
||||
|
||||
public PropertyObject(String name, Class<T> clazz, Predicate<T> validator, Function<T, String> stringFunction) {
|
||||
this.name = name;
|
||||
this.clazz = clazz;
|
||||
this.validator = validator;
|
||||
this.stringFunction = stringFunction;
|
||||
}
|
||||
|
||||
public PropertyObject(String name, Class<T> clazz) {
|
||||
this(name, clazz, Predicates.alwaysTrue(), Object::toString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(T value) {
|
||||
return validator.apply(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<T> getType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(T value) {
|
||||
return stringFunction.apply(value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user