Package cn.nukkit.blockstate
Class BlockState
java.lang.Object
cn.nukkit.blockstate.BlockState
- All Implemented Interfaces:
IBlockState
,Serializable
@PowerNukkitOnly
@Since("1.4.0.0-PN")
@ParametersAreNonnullByDefault
public final class BlockState
extends Object
implements Serializable, IBlockState
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionasItemBlock
(int count) boolean
forItem()
int
Deprecated.int
getBlock()
getBlock
(Level level, int x, int y, int z, int layer, boolean repair, Consumer<BlockStateRepair> callback) int
boolean
getBooleanValue
(String propertyName) int
int
getIntValue
(String propertyName) int
Deprecated.getPersistenceValue
(String propertyName) getPropertyValue
(String propertyName) int
Deprecated.int
hashCode()
boolean
boolean
static BlockState
of
(int blockId) static BlockState
of
(int blockId, byte blockData) static BlockState
of
(int blockId, int blockData) static BlockState
of
(int blockId, long blockData) static BlockState
static BlockState
of
(int blockId, BigInteger blockData) static BlockState
Returns theBlockState
object that represents the givenpersistedStateId
.static BlockState
Returns theBlockState
object that represents the givenpersistedStateId
.onlyWithProperties
(BlockProperty<?>... properties) onlyWithProperties
(String... propertyNames) onlyWithProperty
(BlockProperty<?> property) <T extends Serializable>
BlockStateonlyWithProperty
(BlockProperty<T> property, T value) onlyWithProperty
(String name) onlyWithProperty
(String name, Serializable value) toString()
void
validate()
withBlockId
(int blockId) withData
(int data) withData
(long data) withData
(BigInteger data) <E extends Serializable>
BlockStatewithProperty
(BlockProperty<E> property, E value) withProperty
(String propertyName, Serializable value) withProperty
(String propertyName, String persistenceValue) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface cn.nukkit.blockstate.IBlockState
asItemBlock, getBigId, getBlock, getBlock, getBlock, getBlock, getBlock, getBlock, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBlockRepairing, getBooleanValue, getCheckedProperty, getCheckedPropertyValue, getFullId, getIntValue, getLegacyStateId, getMinimalistStateId, getPersistenceName, getPersistenceValue, getProperty, getPropertyNames, getPropertyValue, getRuntimeId, getStateId, getUncheckedPropertyValue, getUncheckedPropertyValue
-
Field Details
-
AIR
-
-
Method Details
-
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId) -
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId, @Nonnegative byte blockData) -
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId, @Nonnegative int blockData) -
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId, @Nonnegative long blockData) -
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId, @Nonnegative BigInteger blockData) -
of
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public static BlockState of(@Nonnegative int blockId, @Nonnegative Number blockData) - Throws:
InvalidBlockStateDataTypeException
- If theblockData
param is notInteger
,Long
, orBigInteger
.
-
of
@PowerNukkitOnly @Since("1.5.2.0-PN") @Nonnull public static BlockState of(@Nonnull String persistedStateId) Returns the
BlockState
object that represents the givenpersistedStateId
.Same as
of(persistedStateid, true
.- Parameters:
persistedStateId
- Must follow the same syntax returned byIBlockState.getStateId()
orIBlockState.getLegacyStateId()
- Returns:
- The block state, never null
- Throws:
InvalidBlockPropertyValueException
- If any property value in the givenpersistedStateId
is not valid for the state.
-
of
@PowerNukkitOnly @Since("1.5.2.0-PN") @Nonnull public static BlockState of(@Nonnull String persistedStateId, boolean useDefaultPropertyValues) Returns theBlockState
object that represents the givenpersistedStateId
.- Parameters:
persistedStateId
- Must follow the same syntax returned byIBlockState.getStateId()
orIBlockState.getLegacyStateId()
useDefaultPropertyValues
- Whentrue
, the default value will be used for any missingBlockProperty
inpersistedStateId
.- Returns:
- The block state, never null
- Throws:
IllegalArgumentException
- IfuseDefaultPropertyValues
is false and there are missing propertiesInvalidBlockPropertyValueException
- If any property value in the givenpersistedStateId
is not valid for the state.NoSuchElementException
- If there are no block registered with the given id.
-
getBlockId
- Specified by:
getBlockId
in interfaceIBlockState
-
withData
-
withData
-
withData
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public BlockState withData(@Nonnegative BigInteger data) -
withData
-
withBlockId
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public BlockState withBlockId(@Nonnegative int blockId) -
withProperty
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public <E extends Serializable> BlockState withProperty(BlockProperty<E> property, @Nullable E value) -
withProperty
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public BlockState withProperty(String propertyName, @Nullable Serializable value) - Throws:
NoSuchElementException
- If the property is not registeredInvalidBlockPropertyValueException
- If the new value is not accepted by the property
-
withProperty
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public BlockState withProperty(String propertyName, String persistenceValue) -
onlyWithProperties
@PowerNukkitOnly @Since("1.4.0.0-PN") public BlockState onlyWithProperties(BlockProperty<?>... properties) - Throws:
NoSuchElementException
- If any of the property is not registered
-
onlyWithProperties
- Throws:
NoSuchElementException
- If any of the given property names is not found
-
onlyWithProperty
- Throws:
NoSuchElementException
- If the property was not found
-
onlyWithProperty
- Throws:
NoSuchElementException
- If the property was not found
-
onlyWithProperty
@PowerNukkitOnly @Since("1.4.0.0-PN") public BlockState onlyWithProperty(String name, Serializable value) - Throws:
NoSuchElementException
- If the property is not registeredInvalidBlockPropertyValueException
- If the new value is not accepted by the property
-
onlyWithProperty
@PowerNukkitOnly @Since("1.4.0.0-PN") public <T extends Serializable> BlockState onlyWithProperty(BlockProperty<T> property, T value) - Throws:
NoSuchElementException
- If the property is not registeredInvalidBlockPropertyValueException
- If the new value is not accepted by the property
-
forItem
-
asItemBlock
- Specified by:
asItemBlock
in interfaceIBlockState
-
getDataStorage
- Specified by:
getDataStorage
in interfaceIBlockState
-
getProperties
- Specified by:
getProperties
in interfaceIBlockState
-
getLegacyDamage
@Nonnegative @Deprecated @DeprecationDetails(reason="Can\'t store all data, exists for backward compatibility reasons", since="1.4.0.0-PN", replaceWith="getDataStorage()") @PowerNukkitOnly public int getLegacyDamage()Deprecated.- Specified by:
getLegacyDamage
in interfaceIBlockState
-
getBigDamage
@Unsigned @Deprecated @DeprecationDetails(reason="Can\'t store all data, exists for backward compatibility reasons", since="1.4.0.0-PN", replaceWith="getDataStorage()") @PowerNukkitOnly public int getBigDamage()Deprecated.- Specified by:
getBigDamage
in interfaceIBlockState
-
getSignedBigDamage
@Nonnegative @Since("1.4.0.0-PN") @PowerNukkitOnly @Deprecated @DeprecationDetails(reason="Can\'t store all data, exists for backward compatibility reasons", since="1.4.0.0-PN", replaceWith="getDataStorage()") public int getSignedBigDamage()Deprecated.- Specified by:
getSignedBigDamage
in interfaceIBlockState
-
getHugeDamage
- Specified by:
getHugeDamage
in interfaceIBlockState
-
getPropertyValue
- Specified by:
getPropertyValue
in interfaceIBlockState
-
getIntValue
- Specified by:
getIntValue
in interfaceIBlockState
-
getBooleanValue
- Specified by:
getBooleanValue
in interfaceIBlockState
-
getPersistenceValue
- Specified by:
getPersistenceValue
in interfaceIBlockState
-
getCurrentState
- Specified by:
getCurrentState
in interfaceIBlockState
-
getBitSize
- Specified by:
getBitSize
in interfaceIBlockState
-
getExactIntStorage
- Specified by:
getExactIntStorage
in interfaceIBlockState
- Throws:
ArithmeticException
- If the storage have more than 32 bits
-
isDefaultState
- Specified by:
isDefaultState
in interfaceIBlockState
-
equals
-
hashCode
public int hashCode() -
validate
- Throws:
InvalidBlockStateException
- If the stored state is invalid
-
isCachedValidationValid
-
getCachedValidation
-
getBlock
- Specified by:
getBlock
in interfaceIBlockState
-
getBlock
@Nonnull @PowerNukkitOnly public Block getBlock(@Nullable Level level, int x, int y, int z, int layer, boolean repair, @Nullable Consumer<BlockStateRepair> callback) - Specified by:
getBlock
in interfaceIBlockState
-
toString
-