Skip to content

Commit

Permalink
add config to un-pollute jei
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jan 6, 2025
1 parent 277b13e commit 6259eae
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.");
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/main/generated/assets/bibliocraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BibliocraftWoodType> 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<List<WoodTypeDeferredHolder<Item, ?>>> 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<List<ColoredDeferredHolder<Item, ?>>> 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<List<ColoredWoodTypeDeferredHolder<Item, ?>>> 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;
Expand All @@ -38,19 +55,56 @@ public void registerItemSubtypes(ISubtypeRegistration registration) {

@Override
public void registerRecipes(IRecipeRegistration registration) {
List<BibliocraftWoodType> woodTypes = BibliocraftApi.getWoodTypeRegistry()
.getAll()
.stream()
.filter(e -> ModList.get().isLoaded(e.getNamespace()))
.toList();
if (!Config.JEI_SHOW_WOOD_TYPES.get()) {
for (WoodTypeDeferredHolder<Item, ?> 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<Item, ?> holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) {
registration.addIngredientInfo(holder.get(OAK.get(), WHITE), ALL_COLORS_AND_WOOD_TYPES);
}
} else {
for (ColoredWoodTypeDeferredHolder<Item, ?> holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) {
for (BibliocraftWoodType woodType : BibliocraftApi.getWoodTypeRegistry().getAll()) {
registration.addIngredientInfo(holder.get(woodType, WHITE), ALL_COLORS);
}
}
}
for (ColoredDeferredHolder<Item, ?> 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<Item, ?> 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<Item, ?> holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) {
removeAllExcept(jeiRuntime, holder, holder.get(OAK.get(), WHITE));
}
} else {
for (ColoredWoodTypeDeferredHolder<Item, ?> holder : COLORED_WOOD_TYPE_DEFERRED_HOLDERS.get()) {
for (BibliocraftWoodType woodType : BibliocraftApi.getWoodTypeRegistry().getAll()) {
removeAllExcept(jeiRuntime, holder, holder.get(woodType, WHITE));
}
}
}
for (ColoredDeferredHolder<Item, ?> holder : COLORED_DEFERRED_HOLDERS.get()) {
removeAllExcept(jeiRuntime, holder, holder.get(WHITE));
}
}
}

private void remove(IRecipeRegistration registration, WoodTypeDeferredHolder<Item, ?> holder, List<BibliocraftWoodType> woodTypesToRemove) {
registration.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, woodTypesToRemove
.stream()
.map(holder::get)
.map(ItemStack::new)
.collect(Collectors.toSet()));
private void removeAllExcept(IJeiRuntime jeiRuntime, GroupingDeferredHolder<Item, ?> holder, Item except) {
jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, holder.values().stream().filter(e -> e != except).map(ItemStack::new).toList());
}

@SuppressWarnings("DataFlowIssue")
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @param <T> The second type of the {@link DeferredHolder} to use. For example, for wrapping a {@code DeferredHolder<Block, DoorBlock>}, this would be {@code DoorBlock}.
*/
@SuppressWarnings("unused")
public class ColoredDeferredHolder<R, T extends R> {
public class ColoredDeferredHolder<R, T extends R> implements GroupingDeferredHolder<R, T> {
private final Map<DyeColor, DeferredHolder<R, T>> map = new LinkedHashMap<>();

/**
Expand Down Expand Up @@ -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<DyeColor, DeferredHolder<R, T>> map() {
return Collections.unmodifiableMap(map);
}

@Override
public Collection<DeferredHolder<R, T>> holders() {
return map.values();
}

/**
* @return An immutable collection of values of all {@link DeferredHolder}s in this object.
*/
@Override
public Collection<T> 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<ResourceLocation> 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<DyeColor, DeferredHolder<R, T>> map() {
return Collections.unmodifiableMap(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @param <T> The second type of the {@link DeferredHolder} to use. For example, for wrapping a {@code DeferredHolder<Block, DoorBlock>}, this would be {@code DoorBlock}.
*/
@SuppressWarnings("unused")
public class ColoredWoodTypeDeferredHolder<R, T extends R> {
public class ColoredWoodTypeDeferredHolder<R, T extends R> implements GroupingDeferredHolder<R, T> {
private final Map<BibliocraftWoodType, ColoredDeferredHolder<R, T>> map = new LinkedHashMap<>();

/**
Expand Down Expand Up @@ -80,30 +80,24 @@ public Collection<ColoredDeferredHolder<R, T>> 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<BibliocraftWoodType, ColoredDeferredHolder<R, T>> map() {
return Collections.unmodifiableMap(map);
}

@Override
public Collection<DeferredHolder<R, T>> 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<T> 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<ResourceLocation> 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<BibliocraftWoodType, ColoredDeferredHolder<R, T>> map() {
return Collections.unmodifiableMap(map);
}
}
Original file line number Diff line number Diff line change
@@ -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<R, T extends R> {
/**
* @return An immutable collection of all {@link DeferredHolder}s in this object.
*/
Collection<DeferredHolder<R, T>> holders();

/**
* @return An immutable collection of values of all {@link DeferredHolder}s in this object.
*/
Collection<T> values();

/**
* @return An immutable collection of ids of all {@link DeferredHolder}s in this object.
*/
Collection<ResourceLocation> ids();
}
Loading

0 comments on commit 6259eae

Please sign in to comment.