Options
All
  • Public
  • Public/Protected
  • All
Menu

Class to operate additional properties of a certain block in the world. Full rewrite not connected with InnerCoreBlockState, adding bunch of useful methods similar to those from Forge.

The main thing you need to know about block states is that the object is in fact immutable. Each object has a runtime ID. Each runtime ID refers to a block state object with a specific combination of property values. If you change the value of a property, for example using BlockState.setValue method, it is not changed in the object, but another object with another runtime ID and needed property values combination is returned.

This also means that if you want to change the value of a block property on specific coordinates in the world, you have to call BlockSource.setBlockState with an object obtained after changing the value of a property.

Example:

// suppose that the block we are getting is an anvil,
// not checking not to distract you
const anvil = world.getBlockState(x, y, z);

// as ANVIL_DAMAGE is a property of Java enum type,
// convert it to integer type to work with it in JS/TS
const ANVIL_DAMAGE_INT = KEX.VanillaStates.ANVIL_DAMAGE.toIntegerProperty();

// getting anvil damage value
const damageValue = anvil.getValue(ANVIL_DAMAGE_INT);
// if anvil is damaged
if(damageValue != KEX.BlockStates.AnvilDamage.UNDAMAGED) {
// resetting anvil damage and storing
// the returned object in the same variable
anvil = anvil.setValue(ANVIL_DAMAGE_INT, KEX.BlockStates.AnvilDamage.UNDAMAGED);
// setting the modified block state in the world (mandatory if changes made)
world.setBlockState(x, y, z, anvil, 0);
}

One more important thing to note is that a certain block with specific ID cannot store any block property by default. If you are initializing a block which you want to hold some properties, you have to specify them all using BlocksModule.registerStateForBlock method, providing block's numeric ID and property object.

Since this class released in KEX 5.0, InnerCoreBlockState was replaced with KEX's BlockState everywhere it was used.

since

5.0

Hierarchy

Index

Constructors

  • new BlockState(id: number, data: number): BlockState
  • Constructs new BlockState instance from given block numeric ID and data

    since

    5.0

    Parameters

    • id: number
    • data: number

    Returns BlockState

Properties

class: Class<Object>

Methods

  • clone(): any
  • since

    5.0

    Type Parameters

    • T

    Parameters

    Returns BlockState

    BlockState with the given property set to the value, which goes right next to the current value in the set of possible values of given property

  • equals(param0: any): boolean
  • Parameters

    • param0: any

    Returns boolean

  • finalize(): void
  • getDestroySpeed(): number
  • getFriction(): number
  • getLightBlock(): number
  • getLightEmission(): number
  • since

    5.0

    Type Parameters

    • T

    Parameters

    Returns Optional<T>

    the value of given block property in the following BlockState, wrapped in a java.util.Optional object, which holds null if the following block cannot hold the given property or it was not found for some reason

  • getRuntimeID(): number
  • since

    5.0

    Returns number

    runtime ID of the following BlockState, read more about it in the class description

  • since

    5.0

    Type Parameters

    • T

    Parameters

    Returns T

    the value of given block property in the following BlockState. Use only if you are sure the following block can hold the given property.

  • hasBlockEntity(): boolean
  • since

    5.0

    Returns boolean

    whether the following BlockState owns a vanilla or Java-registered custom block entity

  • hasProperty<T>(property: Property<T>): boolean
  • since

    5.0

    Type Parameters

    • T

    Parameters

    Returns boolean

    whether the block type in the following BlockState can hold the given block property

  • hashCode(): number
  • notify(): void
  • notifyAll(): void
  • since

    5.0

    Type Parameters

    • T

    • V

    Parameters

    Returns BlockState

    another BlockState with the given property value matching to the value given. Read more about how it works in the class description.

  • toString(): string
  • wait(): void
  • wait(param0: number): void
  • wait(param0: number, param1: number): void
  • Returns void

  • Parameters

    • param0: number

    Returns void

  • Parameters

    • param0: number
    • param1: number

    Returns void

Generated using TypeDoc