Package net.commoble.exmachina.api.content

# Record Class VariantsMechanicalComponent

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

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()`.
  `variants` - Map of blockstate selector string (e.g. "side=down,waterlogged=false") to any number of node definitions. NodeShapes within a variant must be unique, and each state must be matched by exactly one selector. The "" selector may be used to match all states.

All Implemented Interfaces:
  `MechanicalComponent`

public record VariantsMechanicalComponent(boolean save, Map<String,List<RawNode>> variants) extends Record implements MechanicalComponent
General-purpose MechanicalComponent which defines static mechanical nodes per-blockstate similar to how a blockstate file assigns model variants.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`VariantsMechanicalComponent.VariantBuilder`
Datagen helper for building a variant matching multiple properties' values

## Field Summary

Fields
Modifier and Type
Field
Description
`static final com.mojang.serialization.MapCodec<VariantsMechanicalComponent>`
`CODEC`
{ "type": "exmachina:variants", "save": true, // automatically persists updates in data attached to blockentity, defaults to false "variants": [ "side=down,waterlogged=false": [ // same format as blockstate json variant selectors // list of RawNode objects, see that class for additional docs ], "side=up": { // singular RawNode object is fine too } ] }
`static final net.minecraft.resources.ResourceKey<com.mojang.serialization.MapCodec<? extends MechanicalComponent>>`
`KEY`
exmachina:mechanical_component / exmachina:variants

## Constructor Summary

Constructors
Constructor
Description
`VariantsMechanicalComponent(boolean save, Map<String,List<RawNode>> variants)`
Creates an instance of a `VariantsMechanicalComponent` record class.

## Method Summary

Modifier and Type
Method
Description
`VariantsMechanicalComponent`
`addMultiPropertyVariant(Consumer<VariantsMechanicalComponent.VariantBuilder> builderConsumer, RawNode... rawNodes)`
Datagen helper to add a variant matching multiple properties' values
`<T extends Comparable<T>>
VariantsMechanicalComponent`
`addVariant(net.minecraft.world.level.block.state.properties.Property<T> property, T value, RawNode... rawNodes)`
Datagen helper to add a variant matching a single property's value
`static VariantsMechanicalComponent`
`always(boolean save, RawNode... rawNodes)`
Datagen helper which assigns the given nodes to all states
`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 VariantsMechanicalComponent`
`builder(boolean save)`
Datagen helper returning a mutable builder-like VariantsMechanicalComponent
`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.
`boolean`
`save()`
Returns the value of the `save` record component.
`final String`
`toString()`
Returns a string representation of this record class.
`Map<String,List<RawNode>>`
`variants()`
Returns the value of the `variants` record component.

### 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:variants

### CODEC

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

     {
       "type": "exmachina:variants",
       "save": true, // automatically persists updates in data attached to blockentity, defaults to false
       "variants": [
         "side=down,waterlogged=false": [ // same format as blockstate json variant selectors
           // list of RawNode objects, see that class for additional docs
         ],
         "side=up": {
            // singular RawNode object is fine too
         }
       ]
     }

## Constructor Details

### VariantsMechanicalComponent

public VariantsMechanicalComponent(boolean save, Map<String,List<RawNode>> variants)
Creates an instance of a `VariantsMechanicalComponent` record class.

Parameters:
  `save` - the value for the `save` record component
  `variants` - the value for the `variants` 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

### always

public static VariantsMechanicalComponent always(boolean save, RawNode... rawNodes)
Datagen helper which assigns the given nodes to all states

Parameters:
  `save` - If true, mechanical updates will be stored in a `MechanicalNodeStates` data attachment.
  `rawNodes` - RawNodes to assign to all blockstates
Returns:
  VariantsMechanicalComponent where all blockstates use the provided nodes

### builder

public static VariantsMechanicalComponent builder(boolean save)
Datagen helper returning a mutable builder-like VariantsMechanicalComponent

Parameters:
  `save` - If true, mechanical updates will be stored in a `MechanicalNodeStates` data attachment.
Returns:
  VariantsMechanicalComponent with a mutable internal map to add nodes to

### addVariant

public <T extends Comparable<T>> VariantsMechanicalComponent addVariant(net.minecraft.world.level.block.state.properties.Property<T> property, T value, RawNode... rawNodes)
Datagen helper to add a variant matching a single property's value

Type Parameters:
  `T` - Type of the blockstate property's values, e.g. Direction
Parameters:
  `property` - Property of this block's blockstates, e.g. BlockStateProperties.FACING
  `value` - A value of that property, e.g. Direction.NORTH
  `rawNodes` - RawNodes to assign to blockstates having that property value (can be none to assign no nodes)
Returns:
  this

### addMultiPropertyVariant

public VariantsMechanicalComponent addMultiPropertyVariant(Consumer<VariantsMechanicalComponent.VariantBuilder> builderConsumer, RawNode... rawNodes)
Datagen helper to add a variant matching multiple properties' values

Parameters:
  `builderConsumer` - Consumer of the form

       builder -> builder
              .add(BlockStateProperties.DIRECTION, Direction.NORTH)
              .add(BlockStateProperties.LIT, true)

  `rawNodes` - zero or more RawNodes to assign to states having all property values specified by the variant
Returns:
  this

### 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

### 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

### variants

public Map<String,List<RawNode>> variants()
Returns the value of the `variants` record component.

Returns:
  the value of the `variants` record component