Package net.commoble.exmachina.api.content

# Record Class MultipartMechanicalComponent

java.lang.Object
java.lang.Record
net.commoble.exmachina.api.content.MultipartMechanicalComponent

Record Components:
  `save` - If true, mechanical updates will be stored in a `MechanicalNodeStates` data attachment. Defaults false. Automatic syncing is currently not supported, but blockentities which wish to manually sync this can invoke `Level.sendBlockUpdated(net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.block.state.BlockState, int)` from `BlockEntity.setChanged()`.
  `multipart` - List of ApplyWhen cases

All Implemented Interfaces:
  `MechanicalComponent`

public record MultipartMechanicalComponent(boolean save, List<MultipartMechanicalComponent.ApplyWhen> multipart) extends Record implements MechanicalComponent
General-purpose MechanicalComponent which has a format similar to multipart blockstate defintions, assigning nodes to blockstates by comparing states to property-value predicate Cases. Multiple sets of nodes can be applied to individual blockstates.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final record`
`MultipartMechanicalComponent.ApplyWhen`
Component of MultipartMechanicalComponent definitions, analogous to the "when" and "apply" blocks in a blockstate json.
`static final record`
`MultipartMechanicalComponent.Case`
Component of Multipart definitions representing a blockstate predicate.
`static final record`
`MultipartMechanicalComponent.OrCase`
Component of Multipart definitions' 'when' blocks.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final com.mojang.serialization.MapCodec<MultipartMechanicalComponent>`
`CODEC`
{ "type": "exmachina:multipart", "save": true, // automatically persists updates in data attached to blockentity, defaults to false "multipart": [ { // apply one or more nodes in all cases "apply": { // see RawNode class for object definition } }, { // apply one or more nodes in specific case "apply": [ { // see RawNode class for object definition } ], "when": { // list of blockstate predicates, same format as multipart blockstate model jsons "up": "true", "face": "nortH|south" } } ] }
`static final net.minecraft.resources.ResourceKey<com.mojang.serialization.MapCodec<? extends MechanicalComponent>>`
`KEY`
exmachina:mechanical_component / exmachina:multipart

## Constructor Summary

Constructors
Constructor
Description
`MultipartMechanicalComponent(boolean save, List<MultipartMechanicalComponent.ApplyWhen> multipart)`
Creates an instance of a `MultipartMechanicalComponent` record class.

## Method Summary

Modifier and Type
Method
Description
`MultipartMechanicalComponent`
`addApplyWhen(MultipartMechanicalComponent.ApplyWhen applyWhen)`
Adds an apply-when case to this multipart definition
`com.mojang.serialization.DataResult<MechanicalBlockComponent>`
`bake(net.minecraft.world.level.block.Block block, net.minecraft.core.RegistryAccess registries)`
Validates and bakes a MechanicalBlockComponent for this component's associated block.
`static MultipartMechanicalComponent`
`builder(boolean save)`
Datagen helper; Creates and returns a MultipartMechanicalComponent for whom cases can be defined.
`com.mojang.serialization.MapCodec<? extends MechanicalComponent>`
`codec()`
Returns registerd MapCodec for this subclass.
`final boolean`
`equals(Object o)`
Indicates whether some other object is "equal to" this one.
`final int`
`hashCode()`
Returns a hash code value for this object.
`List<MultipartMechanicalComponent.ApplyWhen>`
`multipart()`
Returns the value of the `multipart` record component.
`boolean`
`save()`
Returns the value of the `save` record component.
`final String`
`toString()`
Returns a string representation of this record class.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### KEY

public static final net.minecraft.resources.ResourceKey<com.mojang.serialization.MapCodec<? extends MechanicalComponent>> KEY
exmachina:mechanical_component / exmachina:multipart

### CODEC

public static final com.mojang.serialization.MapCodec<MultipartMechanicalComponent> CODEC

     {
       "type": "exmachina:multipart",
       "save": true, // automatically persists updates in data attached to blockentity, defaults to false
       "multipart": [
            {
                    // apply one or more nodes in all cases
                    "apply": {
                            // see RawNode class for object definition
                    }
            },
            {
                    // apply one or more nodes in specific case
                    "apply": [
                            {
                                    // see RawNode class for object definition
                            }
                    ],
                    "when": { // list of blockstate predicates, same format as multipart blockstate model jsons
                            "up": "true",
                            "face": "nortH|south"
                    }
         }
       ]
     }

## Constructor Details

### MultipartMechanicalComponent

public MultipartMechanicalComponent(boolean save, List<MultipartMechanicalComponent.ApplyWhen> multipart)
Creates an instance of a `MultipartMechanicalComponent` record class.

Parameters:
  `save` - the value for the `save` record component
  `multipart` - the value for the `multipart` record component

## Method Details

### codec

public com.mojang.serialization.MapCodec<? extends MechanicalComponent> codec()
Description copied from interface: `MechanicalComponent`
Returns registerd MapCodec for this subclass.

Specified by:
  `codec` in interface `MechanicalComponent`
Returns:
  registerd MapCodec for this subclass

### bake

public com.mojang.serialization.DataResult<MechanicalBlockComponent> bake(net.minecraft.world.level.block.Block block, net.minecraft.core.RegistryAccess registries)
Description copied from interface: `MechanicalComponent`
Validates and bakes a MechanicalBlockComponent for this component's associated block. Invoked on server start.

Specified by:
  `bake` in interface `MechanicalComponent`
Parameters:
  `block` - Block which this MechanicalComponent shares an id with
  `registries` - RegistryAccess containing the datapack registries, if needed
Returns:
  DataResult containing the baked and validated block component, or an error result if validation failed

### builder

public static MultipartMechanicalComponent builder(boolean save)
Datagen helper; Creates and returns a MultipartMechanicalComponent for whom cases can be defined.

Parameters:
  `save` - If true, mechanical updates will be stored in a `MechanicalNodeStates` data attachment. Defaults false.
Returns:
  a mutable MultipartMechanicalComponent

### addApplyWhen

public MultipartMechanicalComponent addApplyWhen(MultipartMechanicalComponent.ApplyWhen applyWhen)
Adds an apply-when case to this multipart definition

Parameters:
  `applyWhen` - ApplyWhen to add
Returns:
  this

### toString

public final String toString()
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.

Specified by:
  `toString` in class `Record`
Returns:
  a string representation of this object

### hashCode

public final int hashCode()
Returns a hash code value for this object. The value is derived from the hash code of each of the record components.

Specified by:
  `hashCode` in class `Record`
Returns:
  a hash code value for this object

### equals

public final boolean equals(Object o)
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with `Objects::equals(Object,Object)`; primitive components are compared with '=='.

Specified by:
  `equals` in class `Record`
Parameters:
  `o` - the object with which to compare
Returns:
  `true` if this object is the same as the `o` argument; `false` otherwise.

### save

public boolean save()
Returns the value of the `save` record component.

Returns:
  the value of the `save` record component

### multipart

public List<MultipartMechanicalComponent.ApplyWhen> multipart()
Returns the value of the `multipart` record component.

Returns:
  the value of the `multipart` record component