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

com.yungnickyoung.minecraft.yungsapi.world.structure.condition.RotationCondition 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.YungsApiCommon;
import com.yungnickyoung.minecraft.yungsapi.world.structure.context.StructureContext;
import java.util.List;
import net.minecraft.class_2470;

/**
 * Passes if the provided StructureContext has a specified rotation.
 */
public class RotationCondition extends StructureCondition {
    public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((builder) -> builder
            .group(
                    class_2470.field_39313.listOf().fieldOf("rotations").forGetter(conditon -> conditon.validRotations))
            .apply(builder, RotationCondition::new));
    private final List validRotations;

    public RotationCondition(List validRotations) {
        this.validRotations = validRotations;
    }

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

    @Override
    public boolean passes(StructureContext ctx) {
        // Extract args from context
        class_2470 rotation = ctx.rotation();

        // Abort if missing any args
        if (rotation == null) YungsApiCommon.LOGGER.error("Missing required field 'rotation' for rotation condition!");
        if (rotation == null) return false;

        return this.validRotations.contains(rotation);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy