Skip to content

Commit

Permalink
Dependency Info
Browse files Browse the repository at this point in the history
  • Loading branch information
RawDiamondMC committed Aug 3, 2024
1 parent 2ffcf38 commit 2485c22
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface ModData {
/**
* Returns all of the mod's dependencies.
*/
Collection<ModDependency> getDependencies();
Collection<? extends ModDependencyInfo> getDependencies();

/**
* Get the name of the mod.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import org.jetbrains.annotations.Nullable;

public interface ModDependency {
public interface ModDependencyInfo {
/**
* Get the kind of dependency.
*/
Kind getKind();
DependencyKind getKind();
/**
* Returns the ID of the mod to check.
*/
String getModId();

enum Kind {
enum DependencyKind {
/**
* It prevents the mod from loading if this dependency is missing.
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ enum Kind {
private final boolean positive;
private final boolean soft;

Kind(@Nullable String fabricKey, @Nullable String neoKey, boolean positive, boolean soft) {
DependencyKind(@Nullable String fabricKey, @Nullable String neoKey, boolean positive, boolean soft) {
this.fabricKey = fabricKey;
this.neoKey = neoKey;
this.positive = positive;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package band.kessoku.lib.platform.impl;

import band.kessoku.lib.platform.api.ModData;
import band.kessoku.lib.platform.api.ModDependency;
import band.kessoku.lib.platform.api.ModDependencyInfo;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
Expand Down Expand Up @@ -33,8 +33,8 @@ public String getVersion() {
}

@Override
public Collection<ModDependency> getDependencies() {
return List.of();
public Collection<? extends ModDependencyInfo> getDependencies() {
return modMetadata.getDependencies().stream().map(ModDependencyInfoImpl::new).collect(Collectors.toSet());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package band.kessoku.lib.platform.impl;

import band.kessoku.lib.platform.api.ModDependencyInfo;
import net.fabricmc.loader.api.metadata.ModDependency;

public class ModDependencyInfoImpl implements ModDependencyInfo {
private final ModDependency value;
public ModDependencyInfoImpl(ModDependency dependency) {
value = dependency;
}
@Override
public DependencyKind getKind() {
switch (value.getKind()) {
case DEPENDS -> {
return DependencyKind.DEPENDS;
}
case RECOMMENDS -> {
return DependencyKind.RECOMMENDS;
}
case SUGGESTS -> {
return DependencyKind.SUGGESTS;
}
case CONFLICTS -> {
return DependencyKind.CONFLICTS;
}
case BREAKS -> {
return DependencyKind.BREAKS;
}
}
return null;
}

@Override
public String getModId() {
return value.getModId();
}

public ModDependency getModDependency() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package band.kessoku.lib.platform.impl;

import band.kessoku.lib.platform.api.ModData;
import band.kessoku.lib.platform.api.ModDependency;
import band.kessoku.lib.platform.api.ModDependencyInfo;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.moddiscovery.ModFileInfo;
Expand All @@ -11,6 +11,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;

public class ModDataImpl implements ModData {
private final ModContainer modContainer;
Expand All @@ -32,8 +33,8 @@ public String getVersion() {
}

@Override
public Collection<ModDependency> getDependencies() {
return List.of();
public Collection<? extends ModDependencyInfo> getDependencies() {
return modInfo.getDependencies().stream().map(ModDependencyInfoImpl::new).collect(Collectors.toSet());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package band.kessoku.lib.platform.impl;

import band.kessoku.lib.platform.api.ModDependencyInfo;
import net.neoforged.neoforgespi.language.IModInfo;

public class ModDependencyInfoImpl implements ModDependencyInfo {
private final IModInfo.ModVersion value;
public ModDependencyInfoImpl(IModInfo.ModVersion modVersion) {
value = modVersion;
}
@Override
public DependencyKind getKind() {
switch (value.getType()) {
case OPTIONAL -> {
return DependencyKind.OPTIONAL;
}
case REQUIRED -> {
return DependencyKind.DEPENDS;
}
case DISCOURAGED -> {
return DependencyKind.CONFLICTS;
}
case INCOMPATIBLE -> {
return DependencyKind.BREAKS;
}
}
return null;
}

@Override
public String getModId() {
return value.getModId();
}

public IModInfo.ModVersion getModVersion() {
return value;
}
}

0 comments on commit 2485c22

Please sign in to comment.