All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spongepowered.api.state.StateProperty Maven / Gradle / Ivy

There is a newer version: 9.0.0
Show newest version
/*
 * This file is part of SpongeAPI, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered 
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.api.state;

import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.util.Nameable;

import java.util.Collection;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * Represents a possible state property in a {@link StateContainer}s {@link State}.
 * 
 * 

A {@link State} can include zero or more {@link StateProperty}s. Each * {@link StateProperty} within a {@link State} is mapped to a value which * represents the current value at the time the {@link State} was taken. *

* *

For example, a {@link BlockTypes#RED_BED} contains three possible * {@link StateProperty}s :

* *
    *
  • {@link EnumStateProperties#RED_BED_FACING}
  • *
  • {@link BooleanStateProperties#RED_BED_OCCUPIED}
  • *
  • {@link EnumStateProperties#RED_BED_PART}
  • *
* *

If you query a {@link BlockTypes#RED_BED}'s {@link StateProperty} you have two * possible outcomes for each {@link StateProperty}. The * {@link BooleanStateProperties#RED_BED_OCCUPIED} has the following possible values:

* *
    *
  • true
  • *
  • false
  • *
* *

As 'OCCUPIED' is a {@link BooleanStateProperty}, it can only be true * or false. * The {@link EnumStateProperties#RED_BED_PART} has the following possible values:

* *
    *
  • HEAD
  • *
  • FOOT
  • *
* *

To determine the current value of a {@link StateProperty}, you would call * {@link State#stateProperty(StateProperty)}. To determine all possible * values of a {@link StateProperty}, you would call * {@link State#stateProperties()}.

* *

As stated above, a {@link StateContainer} may not always have one or more * {@link StateProperty}s. An example of such a block is {@link BlockTypes#BOOKSHELF}.

*/ public interface StateProperty> extends Nameable { /** * Gets all possible values for a specific {@link StateProperty}. The * included values may not be in any particular order. The returned * {@link Collection} should be considered immutable. * * @return All possible values */ Collection possibleValues(); /** * Gets the class type of the {@link StateProperty}'s values. * * @return The value class */ Class valueClass(); /** * Gets the {@link Predicate} used to determine valid values for this. * {@link StateProperty}. Any "value" that returns true when * {@link Predicate#test(Object)} is called is valid. The * {@link Predicate} is specific to this property. * * @return The predicate */ Predicate predicate(); /** * Attempts to parse the provided value as a value dictated possible by * this state property or {@link Optional#empty()} otherwise. * * @param value The value to parse * @return The actual value */ Optional parseValue(String value); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy