All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yungnickyoung.minecraft.yungsapi.world.structure.condition.AllOfCondition Maven / Gradle / Ivy

The newest version!
package com.yungnickyoung.minecraft.yungsapi.world.structure.condition;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.yungnickyoung.minecraft.yungsapi.world.structure.context.StructureContext;

import java.util.List;

/**
 * Compound condition that only passes if all member conditions pass.
 */
public class AllOfCondition extends StructureCondition {
    public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((builder) -> builder
            .group(
                    StructureConditionType.CONDITION_CODEC.listOf().fieldOf("conditions").forGetter(condition -> condition.conditions)
            ).apply(builder, AllOfCondition::new));

    /**
     * List of member conditions.
     */
    private final List conditions;

    public AllOfCondition(List conditions) {
        this.conditions = conditions;
    }

    @Override
    public StructureConditionType type() {
        return StructureConditionType.ALL_OF;
    }

    @Override
    public boolean passes(StructureContext ctx) {
        return conditions.stream().allMatch(condition -> condition.passes(ctx));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy