# NBTElementHelper.NBTCompoundHelper

`com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper`

**Since:** 1.5.1

Wraps a compound tag and provides access to its keys and values.  
 ```js
const player = Player.getPlayer();  
if (player !== null) {
  const nbt = player.getMainHand().getNBT();  
  if (nbt instanceof NBTHelpers.Compound) {
    Chat.log(nbt.getKeys());  
  }
}
 ```

Available in scripts as `NBTHelpers.Compound`.

Nested type declared in [NBTElementHelper](NBTElementHelper.md).

## Constructors

### new NBTElementHelper.NBTCompoundHelper {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_constructor-CompoundTag-}

```js
new NBTElementHelper.NBTCompoundHelper(CompoundTag base)
```

Wraps the supplied compound tag without copying it.

**Parameters:**
- `base`: the compound tag to wrap

## Methods

### asString {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_asString-String-}

```js
asString(String key): String
```

Returns the string value under `key`, or its textual representation for non-string tags.

**Parameters:**
- `key`: the key to retrieve

**Returns:** the value's string or textual representation, or `null` if absent

**Since:** 1.5.1

### asString {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_asString-}

```js
asString(): String
```

Returns the string value for string tags, or the tag's textual representation otherwise.

**Returns:** the string value or textual representation

**Since:** 1.5.1

### get {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_get-String-}

```js
get(String key): NBTElementHelper<?>
```

Returns the value under `key`, or `null` if absent.

**Parameters:**
- `key`: the key to retrieve

**Returns:** the value, or `null` if absent

**Since:** 1.5.1

### getKeys {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_getKeys-}

```js
getKeys(): Set<String>
```

Returns the compound's live key set.

**Returns:** the key set backed by the compound

**Since:** 1.6.0

### getType {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_getType-String-}

```js
getType(String key): int
```

Returns the tag type id for the value under `key`, or `-1` if absent.

**Parameters:**
- `key`: the key to check

**Returns:** the value's tag type id, or `-1` if absent

**Since:** 1.8.4

### getType {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_getType-}

```js
getType(): int
```

Returns this tag's Minecraft NBT type id; see the class documentation for the mapping.

**Returns:** this tag's NBT type id

**Since:** 1.5.1

### has {#com.jsmacrosce.jsmacros.client.api.helper.NBTElementHelper.NBTCompoundHelper_has-String-}

```js
has(String key): boolean
```

Returns whether this compound contains `key`.

**Parameters:**
- `key`: the key to check

**Returns:** `true` if the key is present

**Since:** 1.5.1
