Skip to content

Instantly share code, notes, and snippets.

@TheGlitch76
Last active April 20, 2020 03:03
Show Gist options
  • Save TheGlitch76/79621c529ccbd54a0b60a4e37966789f to your computer and use it in GitHub Desktop.
Save TheGlitch76/79621c529ccbd54a0b60a4e37966789f to your computer and use it in GitHub Desktop.
interfaces
import java.nio.file.Path;
import net.fabricmc.loader.api.ModContainer;
public interface ModProvider {
/**
* This stage is for scanning a jar and optionally choosing to provide this jar as a /todo link/ ProvidedModContainer.
* No transformations should occur during this stage. This allows Loader to fail hard if two {@link ModProvider}s
* attempt to provide the same modid for a jar.
* Please note that more than one ModProvider can grant a jar a modid, as long as the ids do not conflict.
*/
void acceptCandidate(ProvidedModCandidateRepresentation representation);
/**
* Do any needed transformations/additional parsing here. You may either provide a valid ModContainer for this jar, or
* redirect the Path to a jar that contains a valid fabric.mod.json.
*
* <p>Please note that if Loader is unable to associate the proper IDs with the ones
* the {@link ModProvider#acceptCandidate(ProvidedModCandidateRepresentation)} stage assigned, either
* through adding {@link ModContainer}s or redirecting the jar via {@link ProvidedModRepresentation#setPath(Path)},
* the game will crash.</p>
*/
void processMod(ProvidedModRepresentation representation);
}
import java.nio.file.Path;
import java.util.Collection;
/**
* A candidate for a {@link ProvidedModRepresentation}.
*/
// TODO: this name is a little wordy. Maybe move to be subclass of ProvidedModRepresentation?
public interface ProvidedModCandidateRepresentation {
/**
* Get the path of the jar associated with this candidate.
*/
Path getPath();
/**
* Associate a modid with this canidate.
*
* <p>Candidates can have more than one modid associated with them, but they must not conflict.</p>
* @param id modid the modid of the mod that will be associated with the jar (i.e. 'bulkieshukies-sponge')
*/
ProvidedModCandidateRepresentation provideId(String id);
/**
* Associate multiple modids with this canidate.
* @see ProvidedModCandidateRepresentation#provideId(String)
*/
ProvidedModCandidateRepresentation provideIds(Collection<String> ids);
}
import java.nio.file.Path;
import java.util.Collection;
import net.fabricmc.loader.api.ModContainer;
/**
* A representation of a provided mod.
* <p>This is passed in the {@link ModProvider#processMod(ProvidedModRepresentation)} stage to allow changes
* to its state.</p>
*/
public interface ProvidedModRepresentation {
/**
* Get the path of the jar associated with this candidate
* @return
*/
Path getPath();
/**
* Get the ID the {@link ModProvider#acceptCandidate(ProvidedModCandidateRepresentation)} stage associated with this representation.
*/
String getId();
/**
* Set the path of this mod's jar.
* This is the preferred method of applying transformations to a jar: instead of changing the jar directly,
* make a copy and redirect this to the copy. Note that jar-in-jar mods will not be loaded.
* <p>This step is optional.</p>
*/
// TODO: should we make the mods folder read-only for this?
// Pros: it means that users can share mods from the mod folder without WeirdThings:tm: happening
// Cons: mod size is mulitplied by the number of providers that redirect the path because of caching.
// Personally I (glitch) think we should do that.
ProvidedModRepresentation setPath(Path path);
/**
* Give this representation a {@link ModContainer}. Unlike normal fabric mods, provided jars can have more than one
* ModContainer associated with them.
*
* <p>This step is optional if you have added a fabric.mod.json using the {@link ProvidedModRepresentation#setPath(Path)}
* method.</p>
*/
ProvidedModRepresentation addModContainer(ModContainer container);
/**
* Give this representation multiple {@link ModContainer}s.
* @see ProvidedModRepresentation#addModContainer(ModContainer)
*/
ProvidedModRepresentation addModContainers(Collection<ModContainer> containers);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment