com.yungnickyoung.minecraft.yungsapi.world.structure.condition.ModLoadedCondition 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.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.yungnickyoung.minecraft.yungsapi.services.Services;
import com.yungnickyoung.minecraft.yungsapi.world.structure.context.StructureContext;
/**
* Passes if the mod with the provided mod ID is loaded.
*/
public class ModLoadedCondition extends StructureCondition {
public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((builder) -> builder
.group(
Codec.STRING.fieldOf("modid").forGetter(conditon -> conditon.modId))
.apply(builder, ModLoadedCondition::new));
private final String modId;
public ModLoadedCondition(String modId) {
this.modId = modId;
}
@Override
public StructureConditionType> type() {
return StructureConditionType.MOD_LOADED;
}
@Override
public boolean passes(StructureContext ctx) {
return Services.PLATFORM.isModLoaded(this.modId);
}
}