Add jei and rei config option

This commit is contained in:
LLytho 2022-08-21 11:13:38 +02:00
parent 22d33a870d
commit ddeb359781
5 changed files with 32 additions and 8 deletions

View file

@ -3,6 +3,8 @@ package com.almostreliable.unified.compat;
import com.almostreliable.unified.AlmostUnifiedPlatform;
import com.almostreliable.unified.BuildConfig;
import com.almostreliable.unified.config.Config;
import com.almostreliable.unified.config.UnifyConfig;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaTypes;
@ -26,7 +28,12 @@ public class AlmostJEI implements IModPlugin {
return;
}
Collection<ItemStack> items = HideHelper.createHidingList();
UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer());
if(config.reiOrJeiDisabled()) {
return;
}
Collection<ItemStack> items = HideHelper.createHidingList(config);
if (!items.isEmpty()) {
jei.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, items);
}

View file

@ -19,8 +19,7 @@ import java.util.stream.Collectors;
public class HideHelper {
public static Collection<ItemStack> createHidingList() {
UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer());
public static Collection<ItemStack> createHidingList(UnifyConfig config) {
List<UnifyTag<Item>> unifyTags = config.bakeTags();
TagMap tagMap = TagMap.create(unifyTags);
ReplacementMap repMap = new ReplacementMap(tagMap, config);

View file

@ -1,10 +1,10 @@
package com.almostreliable.unified.config;
import com.almostreliable.unified.AlmostUnified;
import com.almostreliable.unified.BuildConfig;
import com.almostreliable.unified.utils.JsonUtils;
import com.almostreliable.unified.utils.UnifyTag;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
@ -20,8 +20,9 @@ public class UnifyConfig extends Config {
private final Set<UnifyTag<Item>> ignoredTags;
private final Set<ResourceLocation> ignoredRecipeTypes;
private final Set<ResourceLocation> ignoredRecipes;
private final boolean hideJeiRei;
public UnifyConfig(List<String> stoneStrata, List<String> materials, List<String> unbakedTags, List<String> modPriorities, Set<UnifyTag<Item>> ignoredTags, Set<ResourceLocation> ignoredRecipeTypes, Set<ResourceLocation> ignoredRecipes) {
public UnifyConfig(List<String> stoneStrata, List<String> materials, List<String> unbakedTags, List<String> modPriorities, Set<UnifyTag<Item>> ignoredTags, Set<ResourceLocation> ignoredRecipeTypes, Set<ResourceLocation> ignoredRecipes, boolean hideJeiRei) {
this.stoneStrata = stoneStrata;
this.materials = materials;
this.unbakedTags = unbakedTags;
@ -29,6 +30,7 @@ public class UnifyConfig extends Config {
this.ignoredTags = ignoredTags;
this.ignoredRecipeTypes = ignoredRecipeTypes;
this.ignoredRecipes = ignoredRecipes;
this.hideJeiRei = hideJeiRei;
}
public List<String> getStoneStrata() {
@ -68,6 +70,10 @@ public class UnifyConfig extends Config {
return result;
}
public boolean reiOrJeiDisabled() {
return !hideJeiRei;
}
public static class Serializer extends Config.Serializer<UnifyConfig> {
public static final String STONE_STRATA = "stoneStrata";
@ -78,6 +84,8 @@ public class UnifyConfig extends Config {
public static final String IGNORED_RECIPE_TYPES = "ignoredRecipeTypes";
public static final String IGNORED_RECIPES = "ignoredRecipes";
public static final String HIDE_JEI_REI = "itemsHidingJeiRei";
@Override
public UnifyConfig deserialize(JsonObject json) {
List<String> stoneStrata = safeGet(() -> JsonUtils.toList(json.getAsJsonArray(STONE_STRATA)),
@ -102,8 +110,9 @@ public class UnifyConfig extends Config {
.stream()
.map(ResourceLocation::new)
.collect(Collectors.toSet()), new HashSet<>());
boolean hideJeiRei = safeGet(() -> json.getAsJsonPrimitive(HIDE_JEI_REI).getAsBoolean(), true);
return new UnifyConfig(stoneStrata, materials, tags, mods, ignoredTags, ignoredRecipeTypes, ignoredRecipes);
return new UnifyConfig(stoneStrata, materials, tags, mods, ignoredTags, ignoredRecipeTypes, ignoredRecipes, hideJeiRei);
}
@Override
@ -129,6 +138,7 @@ public class UnifyConfig extends Config {
.stream()
.map(ResourceLocation::toString)
.collect(Collectors.toList())));
json.add(HIDE_JEI_REI, new JsonPrimitive(config.hideJeiRei));
return json;
}
}

View file

@ -35,7 +35,8 @@ public class TestUtils {
TestUtils.TEST_MOD_PRIORITIES,
new HashSet<>(),
new HashSet<>(),
new HashSet<>());
new HashSet<>(),
true);
public static final ResourceKey<Registry<Item>> FAKE_ITEM_REGISTRY = FakeResourceKeyRegistry.create("item");
public static final UnifyTag<Item> BRONZE_ORES_TAG = tag("forge:ores/bronze");
public static final UnifyTag<Item> INVAR_ORES_TAG = tag("forge:ores/invar");

View file

@ -1,6 +1,8 @@
package com.almostreliable.unified.compat;
import com.almostreliable.unified.AlmostUnifiedPlatform;
import com.almostreliable.unified.config.Config;
import com.almostreliable.unified.config.UnifyConfig;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.util.EntryStacks;
@ -12,6 +14,11 @@ public class AlmostREI implements REIClientPlugin {
return;
}
HideHelper.createHidingList().stream().map(EntryStacks::of).forEach(registry::removeEntry);
UnifyConfig config = Config.load(UnifyConfig.NAME, new UnifyConfig.Serializer());
if(config.reiOrJeiDisabled()) {
return;
}
HideHelper.createHidingList(config).stream().map(EntryStacks::of).forEach(registry::removeEntry);
}
}