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

com.yungnickyoung.minecraft.yungsapi.world.structure.condition.DepthCondition 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.Optional;
import net.minecraft.class_5699;

/**
 * Condition for constraining placement based on jigsaw piece depth.
 */
public class DepthCondition extends StructureCondition {
    public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((builder) -> builder
            .group(
                    class_5699.field_33441.optionalFieldOf("min_required_depth").forGetter(condition -> condition.minRequiredDepth),
                    class_5699.field_33441.optionalFieldOf("max_possible_depth").forGetter(condition -> condition.maxPossibleDepth))
            .apply(builder, DepthCondition::new));

    /**
     * The minimum required depth (in jigsaw pieces) from the structure start
     * at which this piece is allowed to spawn (inclusive).
     */
    public final Optional minRequiredDepth;

    /**
     * The maximum allowed depth (in jigsaw pieces) from the structure start
     * at which this piece is allowed to spawn (inclusive).
     */
    public final Optional maxPossibleDepth;

    public DepthCondition(Optional minRequiredDepth, Optional maxPossibleDepth) {
        this.minRequiredDepth = minRequiredDepth;
        this.maxPossibleDepth = maxPossibleDepth;
    }

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

    @Override
    public boolean passes(StructureContext ctx) {
        int depth = ctx.depth();
        boolean isAtMinRequiredDepth = minRequiredDepth.isEmpty() || minRequiredDepth.get() <= depth;
        boolean isAtMaxAllowableDepth = maxPossibleDepth.isEmpty() || maxPossibleDepth.get() >= depth;
        return isAtMinRequiredDepth && isAtMaxAllowableDepth;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy