Search in sources :

Example 1 with StateProperty

use of org.spongepowered.api.state.StateProperty in project SpongeCommon by SpongePowered.

the class AbstractSpongeStateMatcher method isValid.

protected final boolean isValid(final StateHolder<?, ?> stateHolder) {
    for (final Map.Entry<StateProperty<@NonNull ?>, Object> entry : this.properties.entrySet()) {
        final Property<?> property = (Property<?>) entry.getKey();
        final Object value = stateHolder.getValues().get(property);
        if (value == null || !value.equals(entry.getValue())) {
            return false;
        }
    }
    for (final StateProperty<@NonNull ?> entry : this.requiredProperties) {
        final Property<?> property = (Property<?>) entry;
        if (stateHolder.getValues().get(property) == null) {
            return false;
        }
    }
    final DataHolder dataHolder = (DataHolder) stateHolder;
    for (final KeyValueMatcher<?> valueMatcher : this.keyValueMatchers) {
        if (!this.matches(dataHolder, valueMatcher)) {
            return false;
        }
    }
    return true;
}
Also used : DataHolder(org.spongepowered.api.data.DataHolder) StateProperty(org.spongepowered.api.state.StateProperty) NonNull(org.checkerframework.checker.nullness.qual.NonNull) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) HashMap(java.util.HashMap) Map(java.util.Map) Property(net.minecraft.world.level.block.state.properties.Property) StateProperty(org.spongepowered.api.state.StateProperty)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Property (net.minecraft.world.level.block.state.properties.Property)1 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 DataHolder (org.spongepowered.api.data.DataHolder)1 StateProperty (org.spongepowered.api.state.StateProperty)1