forked from KubeJS-Mods/KubeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ logs | |
eclipse | ||
run | ||
run_server | ||
/log | ||
.vscode |
49 changes: 49 additions & 0 deletions
49
common/src/main/java/dev/latvian/kubejs/registry/types/FakeModBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dev.latvian.kubejs.registry.types; | ||
|
||
import org.jetbrains.annotations.Contract; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import dev.latvian.mods.rhino.util.HideFromJS; | ||
|
||
/** | ||
* @author G_cat101 | ||
*/ | ||
public class FakeModBuilder { | ||
public String modId; | ||
public String displayName; | ||
public String namespace; | ||
public String description = ""; | ||
public String version = "1.0"; | ||
|
||
public FakeModBuilder(String modId) { | ||
this.modId = modId; | ||
this.namespace = modId; | ||
this.displayName = modId; | ||
|
||
addFakeMod(this); | ||
} | ||
|
||
@ExpectPlatform | ||
@HideFromJS | ||
@Contract(value = "_ -> null") | ||
static void addFakeMod(FakeModBuilder builder) { | ||
throw new AssertionError("Not Implemented"); | ||
} | ||
|
||
public FakeModBuilder displayName(String displayName) { | ||
this.displayName = displayName; | ||
return this; | ||
} | ||
public FakeModBuilder namespace(String namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
public FakeModBuilder description(String description) { | ||
this.description = description; | ||
return this; | ||
} | ||
public FakeModBuilder version(String version) { | ||
this.version = version; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
fabric/src/main/java/dev/latvian/kubejs/fabric/fakemods/FakeModContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dev.latvian.kubejs.fabric.fakemods; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import dev.latvian.kubejs.registry.types.FakeModBuilder; | ||
import net.fabricmc.loader.api.ModContainer; | ||
import net.fabricmc.loader.api.metadata.ModMetadata; | ||
import net.fabricmc.loader.api.metadata.ModOrigin; | ||
import net.fabricmc.loader.impl.metadata.ModOriginImpl; | ||
|
||
public class FakeModContainer implements ModContainer { | ||
private FakeModMetadata metadata; | ||
|
||
public FakeModContainer(FakeModBuilder builder) { | ||
this.metadata = new FakeModMetadata(builder); | ||
} | ||
|
||
@Override | ||
public ModMetadata getMetadata() { | ||
return metadata; | ||
} | ||
|
||
@Override | ||
public List<Path> getRootPaths() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public ModOrigin getOrigin() { | ||
return new ModOriginImpl(); | ||
} | ||
@Override | ||
public Optional<ModContainer> getContainingMod() { | ||
return Optional.empty(); | ||
} | ||
@Override | ||
public Collection<ModContainer> getContainedMods() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public Path getRootPath() { | ||
return null; | ||
} | ||
@Override | ||
public Path getPath(String file) { | ||
return null; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
fabric/src/main/java/dev/latvian/kubejs/fabric/fakemods/FakeModMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package dev.latvian.kubejs.fabric.fakemods; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
|
||
import dev.latvian.kubejs.registry.types.FakeModBuilder; | ||
import net.fabricmc.loader.api.Version; | ||
import net.fabricmc.loader.api.metadata.ContactInformation; | ||
import net.fabricmc.loader.api.metadata.CustomValue; | ||
import net.fabricmc.loader.api.metadata.ModDependency; | ||
import net.fabricmc.loader.api.metadata.ModEnvironment; | ||
import net.fabricmc.loader.api.metadata.ModMetadata; | ||
import net.fabricmc.loader.api.metadata.Person; | ||
import net.fabricmc.loader.impl.metadata.ContactInformationImpl; | ||
import net.fabricmc.loader.impl.util.version.StringVersion; | ||
|
||
public class FakeModMetadata implements ModMetadata { | ||
private FakeModBuilder builder; | ||
|
||
public FakeModMetadata(FakeModBuilder builder) { | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return builder.modId; | ||
} | ||
@Override | ||
public Version getVersion() { | ||
return new StringVersion(builder.version); | ||
} | ||
@Override | ||
public String getName() { | ||
return builder.displayName; | ||
} | ||
@Override | ||
public String getDescription() { | ||
return builder.description; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "fabric"; | ||
} | ||
@Override | ||
public Collection<String> getProvides() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public ModEnvironment getEnvironment() { | ||
return ModEnvironment.UNIVERSAL; | ||
} | ||
@Override | ||
public Collection<ModDependency> getDependencies() { | ||
return Lists.newArrayList(); | ||
} | ||
|
||
@Override | ||
public Collection<Person> getAuthors() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public Collection<Person> getContributors() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public ContactInformation getContact() { | ||
return new ContactInformationImpl(Maps.newHashMap()); | ||
} | ||
@Override | ||
public Collection<String> getLicense() { | ||
return Lists.newArrayList(); | ||
} | ||
@Override | ||
public Optional<String> getIconPath(int size) { | ||
return Optional.empty(); | ||
} | ||
@Override | ||
public boolean containsCustomValue(String key) { | ||
return false; | ||
} | ||
@Override | ||
public CustomValue getCustomValue(String key) { | ||
return null; | ||
} | ||
@Override | ||
public Map<String, CustomValue> getCustomValues() { | ||
return Maps.newHashMap(); | ||
} | ||
@Override | ||
public boolean containsCustomElement(String key) { | ||
return false; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
fabric/src/main/java/dev/latvian/kubejs/mixin/fabric/FabricLoaderImplMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.latvian.kubejs.mixin.fabric; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import net.fabricmc.loader.api.ModContainer; | ||
import net.fabricmc.loader.impl.FabricLoaderImpl; | ||
import net.fabricmc.loader.impl.ModContainerImpl; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import dev.latvian.kubejs.registry.types.fabric.FakeModBuilderImpl; | ||
|
||
@Mixin(FabricLoaderImpl.class) | ||
public class FabricLoaderImplMixin { | ||
@Shadow(remap = false) protected List<ModContainerImpl> mods; | ||
|
||
@Inject(method = "getAllMods", at = @At(value = "HEAD"), remap = false) | ||
private void getCategory(CallbackInfoReturnable<Collection<ModContainer>> cir) { | ||
ArrayList<ModContainer> modsWithFake = new ArrayList<>(); | ||
|
||
modsWithFake.addAll(mods); | ||
modsWithFake.addAll(FakeModBuilderImpl.fakeMods); | ||
|
||
cir.setReturnValue(modsWithFake); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
fabric/src/main/java/dev/latvian/kubejs/registry/types/fabric/FakeModBuilderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.latvian.kubejs.registry.types.fabric; | ||
|
||
import java.util.ArrayList; | ||
import dev.latvian.kubejs.fabric.fakemods.FakeModContainer; | ||
import dev.latvian.kubejs.registry.types.FakeModBuilder; | ||
import net.fabricmc.loader.api.ModContainer; | ||
import net.fabricmc.loader.impl.FabricLoaderImpl; | ||
|
||
/** | ||
* @author G_cat101 | ||
*/ | ||
public class FakeModBuilderImpl { | ||
public static ArrayList<ModContainer> fakeMods = new ArrayList<>(); | ||
|
||
private static ArrayList<String> getModIds() { | ||
ArrayList<String> modIds = new ArrayList<>(); | ||
FabricLoaderImpl.INSTANCE.getAllMods().forEach(m -> { | ||
modIds.add(m.getMetadata().getId()); | ||
}); | ||
return modIds; | ||
} | ||
|
||
public static void addFakeMod(FakeModBuilder builder) throws Exception { | ||
if (getModIds().contains(builder.modId)) { | ||
throw new IllegalArgumentException("Tried to create a fake mod with id '" + builder.modId + "', but a mod with that id already exists."); | ||
} | ||
|
||
fakeMods.add(new FakeModContainer(builder)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
forge/src/main/java/dev/latvian/kubejs/forge/FakeModInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.latvian.kubejs.forge; | ||
|
||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.maven.artifact.versioning.ArtifactVersion; | ||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
|
||
import dev.latvian.kubejs.registry.types.FakeModBuilder; | ||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo; | ||
import net.minecraftforge.forgespi.language.IModFileInfo; | ||
import net.minecraftforge.forgespi.language.IModInfo; | ||
|
||
public class FakeModInfo implements IModInfo { | ||
private FakeModBuilder builder; | ||
|
||
public FakeModInfo(FakeModBuilder builder) { | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public String getModId() {return builder.modId;} | ||
@Override | ||
public String getDisplayName() {return builder.displayName;} | ||
@Override | ||
public String getNamespace() {return builder.namespace;} | ||
@Override | ||
public String getDescription() {return builder.description;} | ||
@Override | ||
public ArtifactVersion getVersion() {return new DefaultArtifactVersion(builder.version);} | ||
|
||
@Override | ||
public IModFileInfo getOwningFile() {return null;} | ||
@Override | ||
public List<? extends ModVersion> getDependencies() {return Lists.newArrayList();} | ||
@Override | ||
public Map<String, Object> getModProperties() {return Maps.newHashMap();} | ||
@Override | ||
public URL getUpdateURL() {return null;} | ||
} |
Oops, something went wrong.