diff --git a/src/data/java/com/github/minecraftschurlimods/bibliocraft/datagen/assets/BCEnglishLanguageProvider.java b/src/data/java/com/github/minecraftschurlimods/bibliocraft/datagen/assets/BCEnglishLanguageProvider.java index 19990fd1..aa0605d5 100644 --- a/src/data/java/com/github/minecraftschurlimods/bibliocraft/datagen/assets/BCEnglishLanguageProvider.java +++ b/src/data/java/com/github/minecraftschurlimods/bibliocraft/datagen/assets/BCEnglishLanguageProvider.java @@ -67,6 +67,14 @@ protected void addTranslations() { add(StockroomCatalogSorting.Item.ALPHABETICAL_DESC.getTranslationKey(), "Z-A"); add(StockroomCatalogSorting.Item.COUNT_ASC.getTranslationKey(), "1-99"); add(StockroomCatalogSorting.Item.COUNT_DESC.getTranslationKey(), "99-1"); + add("config." + BibliocraftApi.MOD_ID + ".compatibility", "Compatibility"); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.tooltip", "Contains compatibility options."); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei", "JEI"); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.tooltip", "Contains compatibility options for the JEI mod."); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_wood_types", "Show Wood Types"); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_wood_types.tooltip", "Whether to show blocks for all wood types in JEI, or just the default oak."); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_color_types", "Show Color Types"); + add("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_color_types.tooltip", "Whether to show blocks for all color types in JEI, or just the default white."); add(Translations.CLOCK_ADD_TRIGGER, "Add Trigger"); add(Translations.CLOCK_DELETE_TRIGGER, "Delete Trigger"); add(Translations.CLOCK_EDIT_TRIGGER, "Edit Trigger"); @@ -102,6 +110,9 @@ protected void addTranslations() { add(Translations.STOCKROOM_CATALOG_ADD_CONTAINER, "Started listing contents of %s in the Stockroom Catalog!"); add(Translations.STOCKROOM_CATALOG_REMOVE_CONTAINER, "Stopped listing contents of %s in the Stockroom Catalog!"); add(Translations.TAPE_MEASURE_DISTANCE, "Distance: %s blocks (x: %s, y: %s, z: %s)"); + add(Translations.ALL_COLORS, "This block can be crafted in all colors."); + add(Translations.ALL_COLORS_AND_WOOD_TYPES, "This block can be crafted in all colors and wood types."); + add(Translations.ALL_WOOD_TYPES, "This block can be crafted in all wood types."); } /** diff --git a/src/main/generated/assets/bibliocraft/lang/en_us.json b/src/main/generated/assets/bibliocraft/lang/en_us.json index 0e6f8849..0f5489b2 100644 --- a/src/main/generated/assets/bibliocraft/lang/en_us.json +++ b/src/main/generated/assets/bibliocraft/lang/en_us.json @@ -903,6 +903,14 @@ "block.bibliocraft.yellow_warped_seat": "Yellow Warped Seat", "block.bibliocraft.yellow_warped_seat_back": "Yellow Warped Seat Back", "block.bibliocraft.yellow_warped_wall_display_case": "Yellow Warped Display Case", + "config.bibliocraft.compatibility": "Compatibility", + "config.bibliocraft.compatibility.jei": "JEI", + "config.bibliocraft.compatibility.jei.show_color_types": "Show Color Types", + "config.bibliocraft.compatibility.jei.show_color_types.tooltip": "Whether to show blocks for all color types in JEI, or just the default white.", + "config.bibliocraft.compatibility.jei.show_wood_types": "Show Wood Types", + "config.bibliocraft.compatibility.jei.show_wood_types.tooltip": "Whether to show blocks for all wood types in JEI, or just the default oak.", + "config.bibliocraft.compatibility.jei.tooltip": "Contains compatibility options for the JEI mod.", + "config.bibliocraft.compatibility.tooltip": "Contains compatibility options.", "container.bibliocraft.bookcase": "Bookcase", "container.bibliocraft.cookie_jar": "Cookie Jar", "container.bibliocraft.disc_rack": "Disc Rack", @@ -1842,5 +1850,8 @@ "item.bibliocraft.yellow_warped_raised_seat_back": "Yellow Warped Raised Seat Back", "item.bibliocraft.yellow_warped_small_seat_back": "Yellow Warped Small Seat Back", "item.bibliocraft.yellow_warped_tall_seat_back": "Yellow Warped Tall Seat Back", - "itemGroup.bibliocraft": "Bibliocraft" + "itemGroup.bibliocraft": "Bibliocraft", + "jei.bibliocraft.all_colors": "This block can be crafted in all colors.", + "jei.bibliocraft.all_colors_and_wood_types": "This block can be crafted in all colors and wood types.", + "jei.bibliocraft.all_wood_types": "This block can be crafted in all wood types." } \ No newline at end of file diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/Bibliocraft.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/Bibliocraft.java index 8c8a237e..75c86dc5 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/Bibliocraft.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/Bibliocraft.java @@ -1,9 +1,16 @@ package com.github.minecraftschurlimods.bibliocraft; import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi; +import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.neoforge.client.gui.ConfigurationScreen; +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; @Mod(BibliocraftApi.MOD_ID) public final class Bibliocraft { - public Bibliocraft() {} + public Bibliocraft(ModContainer container) { + container.registerConfig(ModConfig.Type.CLIENT, Config.SPEC); + container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new); + } } diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/BibliocraftJeiPlugin.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/BibliocraftJeiPlugin.java index b1326cc0..93265b60 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/BibliocraftJeiPlugin.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/BibliocraftJeiPlugin.java @@ -4,6 +4,10 @@ import com.github.minecraftschurlimods.bibliocraft.api.woodtype.BibliocraftWoodType; import com.github.minecraftschurlimods.bibliocraft.init.BCItems; import com.github.minecraftschurlimods.bibliocraft.util.BCUtil; +import com.github.minecraftschurlimods.bibliocraft.util.Translations; +import com.github.minecraftschurlimods.bibliocraft.util.init.ColoredDeferredHolder; +import com.github.minecraftschurlimods.bibliocraft.util.init.ColoredWoodTypeDeferredHolder; +import com.github.minecraftschurlimods.bibliocraft.util.init.GroupingDeferredHolder; import com.github.minecraftschurlimods.bibliocraft.util.init.WoodTypeDeferredHolder; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; @@ -12,20 +16,33 @@ import mezz.jei.api.ingredients.subtypes.UidContext; import mezz.jei.api.registration.IRecipeRegistration; import mezz.jei.api.registration.ISubtypeRegistration; +import mezz.jei.api.runtime.IJeiRuntime; import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.neoforged.fml.ModList; +import net.neoforged.neoforge.common.util.Lazy; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.stream.Collectors; @JeiPlugin public final class BibliocraftJeiPlugin implements IModPlugin { private static final ResourceLocation UID = BCUtil.modLoc("jei_plugin"); - + private static final Lazy OAK = Lazy.of(() -> BibliocraftApi.getWoodTypeRegistry().get(BCUtil.mcLoc("oak"))); + private static final DyeColor WHITE = DyeColor.WHITE; + private static final Component ALL_COLORS = Component.translatable(Translations.ALL_COLORS); + private static final Component ALL_COLORS_AND_WOOD_TYPES = Component.translatable(Translations.ALL_COLORS_AND_WOOD_TYPES); + private static final Component ALL_WOOD_TYPES = Component.translatable(Translations.ALL_WOOD_TYPES); + private static final Lazy>> WOOD_TYPE_DEFERRED_HOLDERS = + Lazy.of(() -> List.of(BCItems.BOOKCASE, BCItems.FANCY_ARMOR_STAND, BCItems.FANCY_CLOCK, BCItems.FANCY_CRAFTER, BCItems.GRANDFATHER_CLOCK, BCItems.LABEL, BCItems.POTION_SHELF, BCItems.SHELF, BCItems.TABLE, BCItems.TOOL_RACK)); + private static final Lazy>> COLORED_DEFERRED_HOLDERS = + Lazy.of(() -> List.of(BCItems.FANCY_GOLD_LAMP, BCItems.FANCY_IRON_LAMP, BCItems.FANCY_GOLD_LANTERN, BCItems.FANCY_IRON_LANTERN)); + private static final Lazy>> COLORED_WOOD_TYPE_DEFERRED_HOLDERS = + Lazy.of(() -> List.of(BCItems.DISPLAY_CASE, BCItems.SEAT, BCItems.SMALL_SEAT_BACK, BCItems.RAISED_SEAT_BACK, BCItems.FLAT_SEAT_BACK, BCItems.TALL_SEAT_BACK, BCItems.FANCY_SEAT_BACK)); + @Override public ResourceLocation getPluginUid() { return UID; @@ -38,19 +55,56 @@ public void registerItemSubtypes(ISubtypeRegistration registration) { @Override public void registerRecipes(IRecipeRegistration registration) { - List woodTypes = BibliocraftApi.getWoodTypeRegistry() - .getAll() - .stream() - .filter(e -> ModList.get().isLoaded(e.getNamespace())) - .toList(); + if (!Config.JEI_SHOW_WOOD_TYPES.get()) { + for (WoodTypeDeferredHolder holder : WOOD_TYPE_DEFERRED_HOLDERS.get()) { + registration.addIngredientInfo(holder.get(OAK.get()), ALL_WOOD_TYPES); + } + } + if (!Config.JEI_SHOW_COLOR_TYPES.get()) { + if (!Config.JEI_SHOW_WOOD_TYPES.get()) { + for (ColoredWoodTypeDeferredHolder holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) { + registration.addIngredientInfo(holder.get(OAK.get(), WHITE), ALL_COLORS_AND_WOOD_TYPES); + } + } else { + for (ColoredWoodTypeDeferredHolder holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) { + for (BibliocraftWoodType woodType : BibliocraftApi.getWoodTypeRegistry().getAll()) { + registration.addIngredientInfo(holder.get(woodType, WHITE), ALL_COLORS); + } + } + } + for (ColoredDeferredHolder holder : COLORED_DEFERRED_HOLDERS.get()) { + registration.addIngredientInfo(holder.get(WHITE), ALL_COLORS); + } + } + } + + @Override + public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { + if (!Config.JEI_SHOW_WOOD_TYPES.get()) { + for (WoodTypeDeferredHolder holder : WOOD_TYPE_DEFERRED_HOLDERS.get()) { + removeAllExcept(jeiRuntime, holder, holder.get(OAK.get())); + } + } + if (!Config.JEI_SHOW_COLOR_TYPES.get()) { + if (!Config.JEI_SHOW_WOOD_TYPES.get()) { + for (ColoredWoodTypeDeferredHolder holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) { + removeAllExcept(jeiRuntime, holder, holder.get(OAK.get(), WHITE)); + } + } else { + for (ColoredWoodTypeDeferredHolder holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) { + for (BibliocraftWoodType woodType : BibliocraftApi.getWoodTypeRegistry().getAll()) { + removeAllExcept(jeiRuntime, holder, holder.get(woodType, WHITE)); + } + } + } + for (ColoredDeferredHolder holder : COLORED_DEFERRED_HOLDERS.get()) { + removeAllExcept(jeiRuntime, holder, holder.get(WHITE)); + } + } } - private void remove(IRecipeRegistration registration, WoodTypeDeferredHolder holder, List woodTypesToRemove) { - registration.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, woodTypesToRemove - .stream() - .map(holder::get) - .map(ItemStack::new) - .collect(Collectors.toSet())); + private void removeAllExcept(IJeiRuntime jeiRuntime, GroupingDeferredHolder holder, Item except) { + jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, holder.values().stream().filter(e -> e != except).map(ItemStack::new).toList()); } @SuppressWarnings("DataFlowIssue") diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/Config.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/Config.java new file mode 100644 index 00000000..28e6b960 --- /dev/null +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/Config.java @@ -0,0 +1,33 @@ +package com.github.minecraftschurlimods.bibliocraft; + +import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi; +import net.neoforged.neoforge.common.ModConfigSpec; + +public final class Config { + public static final ModConfigSpec SPEC; + public static final ModConfigSpec.BooleanValue JEI_SHOW_WOOD_TYPES; + public static final ModConfigSpec.BooleanValue JEI_SHOW_COLOR_TYPES; + + static { + ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); + builder + .comment("Contains compatibility options.") + .translation("config." + BibliocraftApi.MOD_ID + ".compatibility") + .push("compatibility"); + builder + .comment("Contains compatibility options for the JEI mod.") + .translation("config." + BibliocraftApi.MOD_ID + ".compatibility.jei") + .push("compatibility"); + JEI_SHOW_WOOD_TYPES = builder + .comment("Whether to show blocks for all wood types in JEI, or just the default oak.") + .translation("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_wood_types") + .define("show_wood_types", true); + JEI_SHOW_COLOR_TYPES = builder + .comment("Whether to show blocks for all color types in JEI, or just the default white.") + .translation("config." + BibliocraftApi.MOD_ID + ".compatibility.jei.show_color_types") + .define("show_color_types", true); + builder.pop(); + builder.pop(); + SPEC = builder.build(); + } +} diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/Translations.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/Translations.java index 49d6e9c2..6e581463 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/Translations.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/Translations.java @@ -42,4 +42,8 @@ public interface Translations { String STOCKROOM_CATALOG_ADD_CONTAINER = "item." + BibliocraftApi.MOD_ID + ".stockroom_catalog.add_container"; String STOCKROOM_CATALOG_REMOVE_CONTAINER = "item." + BibliocraftApi.MOD_ID + ".stockroom_catalog.remove_container"; String TAPE_MEASURE_DISTANCE = "item." + BibliocraftApi.MOD_ID + ".tape_measure.distance"; + + String ALL_COLORS = "jei." + BibliocraftApi.MOD_ID + ".all_colors"; + String ALL_COLORS_AND_WOOD_TYPES = "jei." + BibliocraftApi.MOD_ID + ".all_colors_and_wood_types"; + String ALL_WOOD_TYPES = "jei." + BibliocraftApi.MOD_ID + ".all_wood_types"; } diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredDeferredHolder.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredDeferredHolder.java index d06272d1..3e52aaf0 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredDeferredHolder.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredDeferredHolder.java @@ -18,7 +18,7 @@ * @param The second type of the {@link DeferredHolder} to use. For example, for wrapping a {@code DeferredHolder}, this would be {@code DoorBlock}. */ @SuppressWarnings("unused") -public class ColoredDeferredHolder { +public class ColoredDeferredHolder implements GroupingDeferredHolder { private final Map> map = new LinkedHashMap<>(); /** @@ -59,30 +59,24 @@ public ResourceLocation id(DyeColor color) { } /** - * @return An immutable collection of all {@link DeferredHolder}s in this object. + * @return An immutable map of all {@link DyeColor} to {@link DeferredHolder} associations in this object. */ + public Map> map() { + return Collections.unmodifiableMap(map); + } + + @Override public Collection> holders() { return map.values(); } - /** - * @return An immutable collection of values of all {@link DeferredHolder}s in this object. - */ + @Override public Collection values() { return map.values().stream().map(DeferredHolder::get).toList(); } - /** - * @return An immutable collection of ids of all {@link DeferredHolder}s in this object. - */ + @Override public Collection ids() { return map.values().stream().map(DeferredHolder::getId).toList(); } - - /** - * @return An immutable map of all {@link DyeColor} to {@link DeferredHolder} associations in this object. - */ - public Map> map() { - return Collections.unmodifiableMap(map); - } } diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredWoodTypeDeferredHolder.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredWoodTypeDeferredHolder.java index 68288eed..3e3cd9c8 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredWoodTypeDeferredHolder.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/ColoredWoodTypeDeferredHolder.java @@ -21,7 +21,7 @@ * @param The second type of the {@link DeferredHolder} to use. For example, for wrapping a {@code DeferredHolder}, this would be {@code DoorBlock}. */ @SuppressWarnings("unused") -public class ColoredWoodTypeDeferredHolder { +public class ColoredWoodTypeDeferredHolder implements GroupingDeferredHolder { private final Map> map = new LinkedHashMap<>(); /** @@ -80,30 +80,24 @@ public Collection> elements() { } /** - * @return An immutable collection of all {@link DeferredHolder}s in this object. + * @return An immutable map of all {@link BibliocraftWoodType} to {@link DeferredHolder} associations in this object. */ + public Map> map() { + return Collections.unmodifiableMap(map); + } + + @Override public Collection> holders() { return elements().stream().flatMap(holder -> holder.holders().stream()).toList(); } - /** - * @return An immutable collection of values of all {@link DeferredHolder}s in this object. - */ + @Override public Collection values() { return elements().stream().flatMap(holder -> holder.values().stream()).toList(); } - /** - * @return An immutable collection of ids of all {@link DeferredHolder}s in this object. - */ + @Override public Collection ids() { return elements().stream().flatMap(holder -> holder.ids().stream()).toList(); } - - /** - * @return An immutable map of all {@link BibliocraftWoodType} to {@link DeferredHolder} associations in this object. - */ - public Map> map() { - return Collections.unmodifiableMap(map); - } } diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/GroupingDeferredHolder.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/GroupingDeferredHolder.java new file mode 100644 index 00000000..29cbbf71 --- /dev/null +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/GroupingDeferredHolder.java @@ -0,0 +1,26 @@ +package com.github.minecraftschurlimods.bibliocraft.util.init; + +import net.minecraft.resources.ResourceLocation; +import net.neoforged.neoforge.registries.DeferredHolder; + +import java.util.Collection; + +/** + * Represents a group of {@link DeferredHolder}s. + */ +public interface GroupingDeferredHolder { + /** + * @return An immutable collection of all {@link DeferredHolder}s in this object. + */ + Collection> holders(); + + /** + * @return An immutable collection of values of all {@link DeferredHolder}s in this object. + */ + Collection values(); + + /** + * @return An immutable collection of ids of all {@link DeferredHolder}s in this object. + */ + Collection ids(); +} diff --git a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/WoodTypeDeferredHolder.java b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/WoodTypeDeferredHolder.java index dc897c1a..4d7df382 100644 --- a/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/WoodTypeDeferredHolder.java +++ b/src/main/java/com/github/minecraftschurlimods/bibliocraft/util/init/WoodTypeDeferredHolder.java @@ -19,7 +19,7 @@ * @param The second type of the {@link DeferredHolder} to use. For example, for wrapping a {@code DeferredHolder}, this would be {@code DoorBlock}. */ @SuppressWarnings("unused") -public class WoodTypeDeferredHolder { +public class WoodTypeDeferredHolder implements GroupingDeferredHolder { private final Map> map = new LinkedHashMap<>(); /** @@ -64,38 +64,24 @@ public ResourceLocation id(BibliocraftWoodType type) { } /** - * @return An immutable collection of all {@link DeferredHolder}s in this object. + * @return An immutable map of all {@link BibliocraftWoodType} to {@link DeferredHolder} associations in this object. */ + public Map> map() { + return Collections.unmodifiableMap(map); + } + + @Override public Collection> holders() { return map.values(); } - /** - * @return An immutable collection of values of all {@link DeferredHolder}s in this object. - */ + @Override public Collection values() { return map.values().stream().map(DeferredHolder::get).toList(); } - /** - * @return An array of values of all {@link DeferredHolder}s in this object. - */ - @SuppressWarnings("unchecked") - public T[] valuesAsArray() { - return map.values().stream().map(DeferredHolder::get).toList().toArray((T[]) new Object[0]); - } - - /** - * @return An immutable collection of ids of all {@link DeferredHolder}s in this object. - */ + @Override public Collection ids() { return map.values().stream().map(DeferredHolder::getId).toList(); } - - /** - * @return An immutable map of all {@link BibliocraftWoodType} to {@link DeferredHolder} associations in this object. - */ - public Map> map() { - return Collections.unmodifiableMap(map); - } }