-
Notifications
You must be signed in to change notification settings - Fork 69
New mod list from Catalogue #422
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
base: main
Are you sure you want to change the base?
Changes from all commits
6ee3fea
7d90fab
b72cf62
228df8f
2f54366
4bb77d9
fc61b53
a0504da
b56b4fa
1648a0b
fe30282
5d64fe0
595b361
965d082
4c5057d
fbc15c1
9c27fb9
d9592b2
b8aa362
0ae99b9
e28f8d8
b989b98
31142d9
4d74274
a4a9c1d
9e95deb
74e38dc
d938889
e14e608
0b50e24
19780b8
c91e378
b964282
d8fd7c9
0683241
1a330b0
a57373b
3b55025
ad6ba81
4939ee0
fea4d69
6098091
1995e09
563c7de
88ba37d
3b2b735
f486cb9
61f96d2
6d7f3a6
05b4a10
b516706
2452473
2dc3890
e3893a6
909b13c
89a5c54
66c1d3b
431e418
38a57fe
a6175c5
9107c70
51efc2b
cce5c91
f5ffc1c
1421313
8c1eca9
d098ffb
9a2727e
20df0d0
ec3880e
72a0632
38a86d7
1f64491
8eab721
2c7ced2
cfbca69
2cdfdfe
dbc0b05
6e37d03
84f599f
bc8b537
45cde05
1188f27
f88b394
dac3d26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.cleanroommc.catalogue; | ||
|
|
||
| import net.minecraftforge.common.config.Config; | ||
| import net.minecraftforge.common.config.ConfigManager; | ||
| import net.minecraftforge.fml.client.event.ConfigChangedEvent; | ||
| import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Config(modid = CatalogueConstants.MOD_ID) | ||
| public class CatalogueConfig { | ||
|
|
||
| @Config.Comment({ | ||
| "Whether enable Catalogue.", | ||
| "Setting it false will stop Catalogue redirecting Forge's mod list calls." | ||
| }) | ||
| @Config.LangKey("catalogue.config.enable") | ||
| public static boolean enable = true; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "The list of library mods' mod ids.", | ||
| "They will have grey names in the mod list." | ||
| }) | ||
| @Config.LangKey("catalogue.config.library_list") | ||
| public static String[] libraryList = new String[]{ | ||
| "forge", | ||
| "FML", | ||
| "mcp", | ||
| "cleanroom", | ||
| "configanytime", | ||
| "mixinbooter", | ||
| "fugue", | ||
| "scalar", | ||
| "kirino_ecs", | ||
| "kirino_engine", | ||
| "kirino_gl" | ||
| }; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "The list of ignored dependencies' mod ids.", | ||
| "They will not be displayed when searching for dependencies/dependants." | ||
| }) | ||
| @Config.LangKey("catalogue.config.ignored_dependencies_list") | ||
| public static String[] ignoredDependenciesList = new String[]{ | ||
| "minecraft", | ||
| "forge", | ||
| "FML", | ||
| "mcp", | ||
| "cleanroom" | ||
| }; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "Whether limit the size of mods' banners." | ||
| }) | ||
| @Config.LangKey("catalogue.config.enable_banner_limit") | ||
| public static boolean enableBannerLimit = false; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "The maximum of banner's width. Will not work if Enable Banner Limit is set false." | ||
| }) | ||
| @Config.LangKey("catalogue.config.banner_max_width") | ||
| @Config.RangeInt(min = 0) | ||
| public static int bannerMaxWidth = 1280; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "The maximum of banner's height. Will not work if Enable Banner Limit is set false." | ||
| }) | ||
| @Config.LangKey("catalogue.config.banner_max_height") | ||
| @Config.RangeInt(min = 0) | ||
| public static int bannerMaxHeight = 256; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "Whether limit the size of mods' icons." | ||
| }) | ||
| @Config.LangKey("catalogue.config.enable_icon_limit") | ||
| public static boolean enableIconLimit = false; | ||
|
|
||
| @Config.RequiresMcRestart | ||
| @Config.Comment({ | ||
| "The maximum of icon's width and height. Will not work if Enable Icon Limit is set false." | ||
| }) | ||
| @Config.LangKey("catalogue.config.icon_max_width_height") | ||
| @Config.RangeInt(min = 0) | ||
| public static int iconMaxWidthHeight = 256; | ||
|
|
||
| @SubscribeEvent | ||
| public static void onConfigChanged(@NotNull ConfigChangedEvent.OnConfigChangedEvent event) { | ||
| if (event.getModID().equals(CatalogueConstants.MOD_ID)) { | ||
| ConfigManager.sync(CatalogueConstants.MOD_ID, Config.Type.INSTANCE); | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will be no need for this to be another mod, it'll be part of Cleanroom.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't find a final LOGGER named Cleanroom or String "cleanroom". Where should I put them? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.cleanroommc.catalogue; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class CatalogueConstants { | ||
| public static final String MOD_ID = "catalogue"; | ||
| public static final String MOD_NAME = "Catalogue"; | ||
| public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.cleanroommc.catalogue; | ||
|
|
||
| import net.minecraft.util.ResourceLocation; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Author: MrCrayfish | ||
| */ | ||
| public class Utils { | ||
| public static ResourceLocation resource(String name) { | ||
| return new ResourceLocation(CatalogueConstants.MOD_ID, name); | ||
| } | ||
|
|
||
| public static ResourceLocation withDefaultNamespace(String name) { | ||
| return resource("textures/gui/sprites/" + name + ".png"); | ||
| } | ||
|
Comment on lines
+11
to
+17
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
|
|
||
| public static float lerp(float delta, float start, float end) { | ||
| return start + delta * (end - start); | ||
| } | ||
|
|
||
| public static double lerp(double delta, double start, double end) { | ||
| return start + delta * (end - start); | ||
| } | ||
|
|
||
| public static int roundToward(int value, int factor) { | ||
| return positiveCeilDiv(value, factor) * factor; | ||
| } | ||
|
|
||
| public static int positiveCeilDiv(int x, int y) { | ||
| return -Math.floorDiv(-x, y); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.cleanroommc.catalogue.client; | ||
|
|
||
| import com.cleanroommc.catalogue.CatalogueConstants; | ||
| import com.cleanroommc.catalogue.Utils; | ||
| import com.cleanroommc.catalogue.exception.InvalidBrandingImageException; | ||
| import com.cleanroommc.catalogue.exception.ModResourceNotFoundException; | ||
| import com.cleanroommc.catalogue.platform.ClientServices; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.renderer.texture.DynamicTexture; | ||
| import net.minecraft.client.resources.IResourcePack; | ||
| import net.minecraft.util.ResourceLocation; | ||
|
|
||
| import java.awt.image.BufferedImage; | ||
| import java.io.IOException; | ||
| import java.util.Optional; | ||
| import java.util.function.BiPredicate; | ||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * Author: MrCrayfish | ||
| */ | ||
| public record Branding(String prefix, int imageWidth, int imageHeight, | ||
| BiPredicate<BufferedImage, Branding> predicate, | ||
| Function<IModData, String> locator, boolean override) { | ||
| public static final Branding ICON = new Branding("icon", ClientServices.PLATFORM.getIconLimit(), ClientServices.PLATFORM.getIconLimit(), ImagePredicate.SQUARE.and(ClientServices.PLATFORM.getEnableIconLimit() ? ImagePredicate.LESS_THAN_OR_EQUAL : ImagePredicate.ANY), IModData::getImageIcon, false); | ||
| public static final Branding BANNER = new Branding("banner", ClientServices.PLATFORM.getBannerLimit().maxWidth(), ClientServices.PLATFORM.getBannerLimit().maxHeight(), ClientServices.PLATFORM.getEnableBannerLimit() ? ImagePredicate.LESS_THAN_OR_EQUAL : ImagePredicate.ANY, IModData::getBanner, false); | ||
| public static final Branding BACKGROUND = new Branding("background", 512, 256, ImagePredicate.EQUAL, IModData::getBackground, true); | ||
|
|
||
| public Optional<ImageInfo> loadResource(IModData data) { | ||
| String resource = this.locator.apply(data); | ||
| if (resource == null || resource.isBlank()) return Optional.empty(); | ||
|
|
||
| String modId = data.getModId(); | ||
| BufferedImage image; | ||
| try { | ||
| IResourcePack resourcePack = data.getResourcePack(); | ||
| if (this.equals(Branding.BANNER) && resourcePack != null && !resource.startsWith("/")) { | ||
| image = resourcePack.getPackImage(); | ||
| } else { | ||
| resource = resource.startsWith("/") ? resource : "/" + resource; | ||
| image = ClientServices.PLATFORM.loadImageFromModResource(modId, resource); | ||
| } | ||
| this.predicate.test(image, this); // An InvalidBrandingImageException will be thrown if anything is wrong | ||
| DynamicTexture texture = new DynamicTexture(image); | ||
| ResourceLocation id = this.override ? Utils.resource(this.prefix) : | ||
| Utils.resource("%s/%s".formatted(this.prefix, data.getModId())); | ||
| Minecraft.getMinecraft().getTextureManager().loadTexture(id, texture); | ||
| return Optional.of(new ImageInfo(id, image.getWidth(), image.getHeight(), () -> { | ||
| Minecraft.getMinecraft().getTextureManager().deleteTexture(id); | ||
| })); | ||
| } catch (InvalidBrandingImageException e) { | ||
| CatalogueConstants.LOG.error("Invalid {} branding resource '{}' for mod '{}'", this.prefix, resource, modId, e); | ||
| } catch (ModResourceNotFoundException e) { | ||
| CatalogueConstants.LOG.error("Unable to locate the {} branding resource '{}' for mod '{}'", this.prefix, resource, modId, e); | ||
| } catch (IOException e) { | ||
| CatalogueConstants.LOG.error("An error occurred when loading the {} branding resource '{}' for mod '{}'", this.prefix, resource, modId, e); | ||
| } | ||
|
|
||
| return Optional.empty(); | ||
| } | ||
|
|
||
| public record BannerLimit(int maxWidth, int maxHeight) { | ||
| } | ||
| } |
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.
Allow this to be part of Cleanroom's configurations, we'll need a cleanroom directory in configs, and this could be
modlist.cfg, name can be change in the@Configannotation.