Files
Minions/src/main/java/io/github/skippyall/minions/module/MinionModule.java
T
2026-01-18 00:52:13 +01:00

43 lines
1.9 KiB
Java

package io.github.skippyall.minions.module;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import eu.pb4.polymer.core.api.other.PolymerComponent;
import io.github.skippyall.minions.MinionRegistries;
import io.github.skippyall.minions.Minions;
import io.github.skippyall.minions.minion.MinionRuntime;
import io.github.skippyall.minions.program.instruction.InstructionType;
import net.minecraft.component.ComponentType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import java.util.List;
public record MinionModule(List<InstructionType<MinionRuntime>> instructions, List<SpecialAbility> specialAbilities) {
public static final Codec<MinionModule> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
MinionRegistries.INSTRUCTION_TYPES.getCodec().listOf().fieldOf("instructions").forGetter(MinionModule::instructions),
MinionRegistries.SPECIAL_ABILITIES.getCodec().listOf().fieldOf("specialAbilities").forGetter(MinionModule::specialAbilities)
).apply(instance, MinionModule::new)
);
public static final ComponentType<MinionModule> COMPONENT_TYPE = ComponentType.<MinionModule>builder().codec(CODEC).build();
public static final MinionModule EMPTY = new MinionModule(List.of());
public MinionModule(List<InstructionType<MinionRuntime>> instructions) {
this(instructions, List.of());
}
public MinionModule(List<InstructionType<MinionRuntime>> instructions, List<SpecialAbility> specialAbilities) {
this.instructions = List.copyOf(instructions);
this.specialAbilities = List.copyOf(specialAbilities);
}
public static void register() {
Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Minions.MOD_ID, "minion_module"), COMPONENT_TYPE);
PolymerComponent.registerDataComponent(COMPONENT_TYPE);
}
}