# BlockDataHelper

`com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper`

A block state, its position, and its optional block entity, returned by world block lookups.  
 [getNBT()](#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getNBT-) returns `null` when no block entity was captured.  
 ```js
const block = World.getBlock(Player.getPlayer().getBlockPos().down());  
if (block !== null) {
  Chat.log(`${block.getId()} at ${block.getBlockPos()}`);  
  Chat.log(`it is ${block.getName()} and solid is ${block.getBlockStateHelper().isSolid()}`);  

  // the extra data, for the blocks that keep some
  const nbt = block.getNBT();  
  if (nbt === null) {
    Chat.log("no block entity here");  
  } else {
    Chat.log(nbt.asString());  
  }
}
 ```

## Constructors

### new BlockDataHelper {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_constructor-BlockState-BlockEntity-BlockPos-}

```js
new BlockDataHelper(BlockState b, BlockEntity e, BlockPos bp)
```

Stores the supplied block state, its block type, optional block entity, and position.  
 The state must be non-null; the position is retained as supplied.

**Parameters:**
- `b`: block state to wrap; must be non-null
- `e`: block entity, or `null` when absent
- `bp`: block position to store

## Methods

### getBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlock-}

```js
getBlock(): BlockHelper
```

Returns a helper for the block kind, without its state properties.

**Returns:** the block

**Since:** 1.6.5

### getBlockPos {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockPos-}

```js
getBlockPos(): BlockPosHelper
```

Returns the position stored when this block helper was created.

**Returns:** the block pos.

**Since:** 1.2.7

### getBlockState {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockState-}

```js
getBlockState(): Map<String, String>
```

Returns every state property keyed by its name, with the current game-defined value name.  
 This matches [StateHelper.toMap()](StateHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.StateHelper_toMap-) on [getBlockStateHelper()](#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockStateHelper-).

**Returns:** the property names and their current values.

**Since:** 1.1.7

### getBlockStateHelper {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockStateHelper-}

```js
getBlockStateHelper(): BlockStateHelper
```

Returns a helper for this block's state and its properties.

**Returns:** a helper over the state this block is in.

**Since:** 1.6.5

### getId {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getId-}

```js
getId(): String
```

The block's registry id, independent of its state properties.

**Returns:** the block's registry id.

### getName {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getName-}

```js
getName(): TextHelper
```

The block's translated name, independent of its state.

**Returns:** the translated name of the block. (was string before 1.6.5)

### getNBT {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getNBT-}

```js
getNBT(): NBTElementHelper.NBTCompoundHelper
```

Serializes the captured block entity to a compound on each call, excluding its position and id.

**Returns:** the block entity's data, or `null` if this block has no block entity.

**Since:** 1.5.1

**Note:** used to be a [Map](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.html) of [String](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/String.html) to [String](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/String.html)

### getRawBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getRawBlock-}

```js
getRawBlock(): Block
```

Returns the underlying Minecraft block type, without its state properties.

**Returns:** the raw block object this helper wraps.

### getRawBlockEntity {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getRawBlockEntity-}

```js
getRawBlockEntity(): BlockEntity
```

Returns the captured block entity, or `null` if none was captured. [getNBT()](#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getNBT-)
 serializes this same entity when present.

**Returns:** the raw block entity, or `null` if this block has none.

### getRawBlockState {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getRawBlockState-}

```js
getRawBlockState(): BlockState
```

Returns the underlying Minecraft block state wrapped by this helper.

**Returns:** the raw block state this helper wraps.

### getX {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getX-}

```js
getX(): int
```

The block's `x` coordinate.

**Returns:** the `x` value of the block.

**Since:** 1.1.7

### getY {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getY-}

```js
getY(): int
```

The block's `y` coordinate.

**Returns:** the `y` value of the block.

**Since:** 1.1.7

### getZ {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getZ-}

```js
getZ(): int
```

The block's `z` coordinate.

**Returns:** the `z` value of the block.

**Since:** 1.1.7

### toString {#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_toString-}

```js
toString(): String
```

Returns a diagnostic representation containing the stored position coordinates and block registry id.

**Returns:** diagnostic representation of this block data
