com.yungnickyoung.minecraft.yungsapi.world.structure.condition.RotationCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of YungsApi-1.21-Fabric Show documentation
Show all versions of YungsApi-1.21-Fabric Show documentation
A common API for YUNG's Minecraft mods
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);
}
}