Объект IBlockState представляет текущее состояние блока.

Импорт пакета

Link to импорт-пакета

It might be required for you to import the package if you encounter any issues, so better be safe than sorry and add the import.
import crafttweaker.block.IBlockState;

Вызов IBlockState

Link to вызов-iblockstate

Есть несколько методов, которые возвращают объекты IBlockState:

  • используя обработчик скобок<blockstate:minecraft:log:variant=spruce>,
  • используя статический метод IBlockState.getBlockState() (см. ниже для получения дополнительной информации),
  • используя метод getMatchingBlockStates() от объекта IBlockStateMatcher, чтобы получить массив IBlockState,
  • используя метод withProperty() от другого объекта IBlockState.

Разрешение IBlockState во время исполнения

Link to разрешение-iblockstate-во-время-исполнения

There may be times at which your script may rely on interaction with a block from a mod that has not been loaded yet, such as inside block events in ContentTweaker or another pre-init script loader. If you attempt to use a Bracket Handler for a block that has not yet been registered, the handler will fail to resolve and your script will not work.

To avoid this, you can use the static IBlockState.getBlockState() method to resolve an IBlockState at runtime.

static getBlockState

Link to static-getblockstate

static IBlockState getBlockState(String blockname, String... properties) Parameters:

  • String blockname → A string in the format "modid:blockname" as it would appear in the BlockState Bracket Handler
  • String... properties → Zero or more strings of "name=value" pairs of properties to apply to this blockstate. Any unspecified properties will use the same value as in the default blockstate for the specified block name.

Returns an IBlockState of the specified blockname with the specified properties, or the default blockstate if no properties are specified.

Наследование от IBlockProperties

Link to наследование-от-iblockproperties

IBlockState extends IBlockProperties. That means that all methods that are available to IBlockProperties objects are also available to IBlockState objects.

Extending IBlockStateMatcher

Link to extending-iblockstatematcher

IBlockState extends IBlockStateMatcher. That means that all methods that are available to IBlockStateMatcher objects are also available to IBlockState objects.

ZenMethods and ZenGetters

Link to zenmethods-and-zengetters

ZenGetterВозвращаемый типОписание
ZenGetter
block
Возвращаемый тип
IBlock
Описание
Returns the refered block
ZenGetter
meta
Возвращаемый тип
int
Описание
Returns the refered block's metadata
ZenGetter
commandString
Возвращаемый тип
string
Описание
Возвращает возможный обработчик скобок для этого состояния

boolean isReplaceable(IWorld world, IBlockPos pos);
Parameters:

  • IWorld world → The world to be checked in
  • IBlockPos pos → The Block's position

Returns a boolean that sais whether the block can be replaced or not.

Getting or changing Properties

Link to getting-or-changing-properties

You can get a list of all registered properties, either as list with all property names or as map that maps the properties to their value.
You can also check which values are possible for a given property name.
You can also use withProperty to create a new IBlockState object with that property changed.

ZenScript
Copy
List<String> getPropertyNames();
String getPropertyValue(String name);
List<String> getAllowedValuesForProperty(String name);

IBlockState withProperty(String name, String value);

Comparing two IBlockState objects

Link to comparing-two-iblockstate-objects

You can either use int compare(IBlockState other); or the ZenCompare Tokens == !=.
The return different types though:

  • state.compare(other) returns an int that is 0 if they are equal
  • state == other returns a bool that is true of they are equal

Getting an explicit Blockstate Matcher

Link to getting-an-explicit-blockstate-matcher

Returns an IBlockStateMatcher that matches the given block.

ZenScript
Copy
IBlockStateMatcher matchBlock();