generated from CleanroomMC/ForgeDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 30
Fallback property container for all installed mods #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
457ad26
fallback mod container
brachy84 555dfb4
for item iterator
brachy84 e88628e
make ingredient instead of iterable
brachy84 6dea48f
reviews
brachy84 8c38834
[i] operator for item stacks, make OreDictIngredient extend ItemsIngr…
brachy84 5f936c6
fixes & allow range in [] op
brachy84 90dc689
Merge branch 'master' into modmapper
brachy84 4947231
spotless
brachy84 27a0f5e
more
brachy84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
64 changes: 64 additions & 0 deletions
64
src/main/java/com/cleanroommc/groovyscript/compat/mods/ForgeModWrapper.java
This file contains hidden or 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,64 @@ | ||
| package com.cleanroommc.groovyscript.compat.mods; | ||
|
|
||
| import com.cleanroommc.groovyscript.helper.ingredient.ItemsIngredient; | ||
| import net.minecraft.creativetab.CreativeTabs; | ||
| import net.minecraft.item.Item; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.util.NonNullList; | ||
| import net.minecraftforge.fml.common.Loader; | ||
| import net.minecraftforge.fml.common.ModContainer; | ||
| import net.minecraftforge.fml.common.registry.ForgeRegistries; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ForgeModWrapper { | ||
|
|
||
| private ModContainer container; | ||
| private ItemsIngredient items; | ||
|
|
||
| public ForgeModWrapper(ModContainer container) { | ||
| this.container = container; | ||
| } | ||
|
|
||
| public ForgeModWrapper() {} | ||
|
|
||
| void initialize(String owner) { | ||
| this.container = Loader.instance().getIndexedModList().get(owner); | ||
| if (this.container == null) { | ||
| throw new IllegalStateException("Can't create property container for unloaded mod!"); | ||
| } | ||
| } | ||
|
|
||
| public ItemsIngredient getAllItems() { | ||
| if (this.items == null) { | ||
| List<ItemStack> items = new ArrayList<>(); | ||
| NonNullList<ItemStack> stacks = NonNullList.create(); | ||
| for (Item item : ForgeRegistries.ITEMS) { | ||
| if (item.getRegistryName().getNamespace().equals(container.getModId())) { | ||
| item.getSubItems(CreativeTabs.SEARCH, stacks); | ||
| items.addAll(stacks); | ||
| stacks.clear(); | ||
| } | ||
| } | ||
| this.items = new ItemsIngredient(items); | ||
| } | ||
| return this.items; | ||
| } | ||
|
|
||
| public ModContainer getContainer() { | ||
| return container; | ||
| } | ||
|
|
||
| public String getId() { | ||
| return this.container.getModId(); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return this.container.getName(); | ||
| } | ||
|
|
||
| public String getVersion() { | ||
| return this.container.getVersion(); | ||
| } | ||
| } |
This file contains hidden or 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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/cleanroommc/groovyscript/compat/mods/MinecraftModContainer.java
This file contains hidden or 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,60 @@ | ||
| package com.cleanroommc.groovyscript.compat.mods; | ||
|
|
||
| import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule; | ||
| import com.google.common.base.Supplier; | ||
| import com.google.common.base.Suppliers; | ||
| import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.Set; | ||
|
|
||
| public final class MinecraftModContainer extends GroovyContainer<VanillaModule> { | ||
|
|
||
| private static final String modId = "minecraft"; | ||
| private static final String containerName = "Minecraft"; | ||
| private final Supplier<VanillaModule> modProperty; | ||
| private final Collection<String> aliases; | ||
|
|
||
| MinecraftModContainer() { | ||
| this.modProperty = Suppliers.memoize(() -> { | ||
| VanillaModule t = VanillaModule.INSTANCE; | ||
| t.addPropertyFieldsOf(t, false); | ||
| return t; | ||
| }); | ||
| Set<String> aliasSet = new ObjectOpenHashSet<>(); | ||
| aliasSet.add("mc"); | ||
| aliasSet.add(modId); | ||
| this.aliases = Collections.unmodifiableSet(aliasSet); | ||
| ModSupport.INSTANCE.registerContainer(this); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLoaded() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull Collection<String> getAliases() { | ||
| return aliases; | ||
| } | ||
|
|
||
| @Override | ||
| public VanillaModule get() { | ||
| return modProperty.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull String getModId() { | ||
| return modId; | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull String getContainerName() { | ||
| return containerName; | ||
| } | ||
|
|
||
| @Override | ||
| public void onCompatLoaded(GroovyContainer<?> container) {} | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would
vanillabe a good alias? would allowmods.vanilla, which i find rather amusing.i believe using
aliasSet.addAll(Alias.generateOf("Vanilla", containerName).and("MC", "mc"));should work.