Skip to content

Commit 62edabd

Browse files
committed
feat: added overrides config for per-mod substitution
also added recipe/loot/worldgen subpackages to unification package
1 parent 89aeb10 commit 62edabd

18 files changed

Lines changed: 402 additions & 311 deletions

src/main/java/dev/ftb/mods/ftbmaterials/FTBMaterials.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import dev.ftb.mods.ftbmaterials.registry.ModGlobalLootModifiers;
1515
import dev.ftb.mods.ftbmaterials.registry.ModItems;
1616
import dev.ftb.mods.ftbmaterials.resources.ResourceRegistries;
17-
import dev.ftb.mods.ftbmaterials.unification.UnifierManager;
17+
import dev.ftb.mods.ftbmaterials.unification.recipe.UnifierManager;
1818
import net.minecraft.commands.Commands;
1919
import net.minecraft.resources.ResourceLocation;
2020
import net.neoforged.api.distmarker.Dist;

src/main/java/dev/ftb/mods/ftbmaterials/commands/BuildUnifierDB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.mojang.brigadier.Command;
44
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
55
import com.mojang.brigadier.context.CommandContext;
6-
import dev.ftb.mods.ftbmaterials.unification.UnifierManager;
6+
import dev.ftb.mods.ftbmaterials.unification.recipe.UnifierManager;
77
import net.minecraft.commands.CommandSourceStack;
88
import net.minecraft.commands.Commands;
99
import net.minecraft.network.chat.Component;

src/main/java/dev/ftb/mods/ftbmaterials/commands/Reload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.mojang.brigadier.Command;
44
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
55
import com.mojang.brigadier.context.CommandContext;
6-
import dev.ftb.mods.ftbmaterials.unification.UnifierManager;
6+
import dev.ftb.mods.ftbmaterials.unification.recipe.UnifierManager;
77
import net.minecraft.commands.CommandSourceStack;
88
import net.minecraft.commands.Commands;
99
import net.minecraft.network.chat.Component;

src/main/java/dev/ftb/mods/ftbmaterials/config/StartupConfig.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.ftb.mods.ftbmaterials.FTBMaterials;
77

88
import java.util.ArrayList;
9+
import java.util.HashMap;
910

1011
public interface StartupConfig {
1112
String KEY = FTBMaterials.MOD_ID + "-startup";
@@ -30,4 +31,22 @@ public interface StartupConfig {
3031
StringListValue UNIFICATION_BLACKLIST_BLOCKS = BLACKLISTS.addStringList("unification_blacklist_blocks", new ArrayList<>())
3132
.comment("List of block IDs which should never be automatically added to the unification DB",
3233
"These can be wildcarded, e.g. 'somemod:*' blacklists all id's in the 'somemod' namespace");
34+
35+
SNBTConfig OVERRIDES = CONFIG.addGroup("overrides");
36+
StringStringMapValue ITEM_OVERRIDES = OVERRIDES.add(new StringStringMapValue(OVERRIDES, "item_overrides", new HashMap<>()))
37+
.comment("Map of <mod-id> -> map of <tag> -> <replacement_tag>",
38+
"Overrides applied to recipe types of the given mod when doing item lookup in the unification DB");
39+
StringStringMapValue TAG_OVERRIDES = OVERRIDES.add(new StringStringMapValue(OVERRIDES, "tag_overrides", new HashMap<>()))
40+
.comment("Map of <mod-id> -> map of <item> -> <replacement_item>",
41+
"Overrides applied to recipe types of the given mod when doing item tag lookup in the unification DB");
42+
43+
static String itemOverride(String in, String modId) {
44+
var map = ITEM_OVERRIDES.get().get(modId);
45+
return map != null ? map.getOrDefault(in, in) : in;
46+
}
47+
48+
static String itemTagOverride(String in, String modId) {
49+
var map = TAG_OVERRIDES.get().get(modId);
50+
return map != null ? map.getOrDefault(in, in) : in;
51+
}
3352
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.ftb.mods.ftbmaterials.config;
2+
3+
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
4+
import dev.ftb.mods.ftblibrary.snbt.config.BaseValue;
5+
import dev.ftb.mods.ftblibrary.snbt.config.SNBTConfig;
6+
import net.minecraft.Util;
7+
import net.minecraft.nbt.CompoundTag;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
public class StringStringMapValue extends BaseValue<Map<String, Map<String,String>>> {
14+
protected StringStringMapValue(@Nullable SNBTConfig c, String n, Map<String, Map<String, String>> def) {
15+
super(c, n, def);
16+
17+
super.set(new HashMap<>(def));
18+
}
19+
20+
@Override
21+
public void write(SNBTCompoundTag tag) {
22+
SNBTCompoundTag mapTag = new SNBTCompoundTag();
23+
get().forEach((k, subMap) -> {
24+
mapTag.put(k, Util.make(new CompoundTag(), t -> subMap.forEach(t::putString)));
25+
});
26+
27+
tag.put(this.key, mapTag);
28+
comment.forEach(c -> tag.comment(key, c));
29+
}
30+
31+
@Override
32+
public void read(SNBTCompoundTag tag) {
33+
Map<String, Map<String, String>> map = new HashMap<>();
34+
35+
SNBTCompoundTag mapTag = tag.getCompound(key);
36+
for (String key : mapTag.getAllKeys()) {
37+
Map<String, String> subMap = new HashMap<>();
38+
map.put(key, subMap);
39+
CompoundTag subTag = mapTag.getCompound(key);
40+
subTag.getAllKeys().forEach(k1 -> subMap.put(k1, subTag.getString(k1)));
41+
}
42+
43+
set(map);
44+
}
45+
}

src/main/java/dev/ftb/mods/ftbmaterials/data/LootModifiersGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.ftb.mods.ftbmaterials.data;
22

33
import dev.ftb.mods.ftbmaterials.FTBMaterials;
4-
import dev.ftb.mods.ftbmaterials.unification.LootTableUnifier;
4+
import dev.ftb.mods.ftbmaterials.unification.loot.LootTableUnifier;
55
import net.minecraft.core.HolderLookup;
66
import net.minecraft.data.PackOutput;
77
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;

src/main/java/dev/ftb/mods/ftbmaterials/mixin/BulkSectionAccessMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.ftb.mods.ftbmaterials.mixin;
22

33
import dev.ftb.mods.ftbmaterials.config.StartupConfig;
4-
import dev.ftb.mods.ftbmaterials.unification.UnifyingLevelChunkSection;
4+
import dev.ftb.mods.ftbmaterials.unification.worldgen.UnifyingLevelChunkSection;
55
import net.minecraft.core.BlockPos;
66
import net.minecraft.world.level.chunk.BulkSectionAccess;
77
import net.minecraft.world.level.chunk.LevelChunkSection;

src/main/java/dev/ftb/mods/ftbmaterials/mixin/RecipeManagerMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.google.gson.JsonElement;
44
import dev.ftb.mods.ftbmaterials.config.StartupConfig;
5-
import dev.ftb.mods.ftbmaterials.unification.UnifierManager;
5+
import dev.ftb.mods.ftbmaterials.unification.recipe.UnifierManager;
66
import net.minecraft.world.item.crafting.RecipeManager;
77
import org.spongepowered.asm.mixin.Mixin;
88
import org.spongepowered.asm.mixin.injection.At;

src/main/java/dev/ftb/mods/ftbmaterials/registry/ModGlobalLootModifiers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.mojang.serialization.MapCodec;
44
import dev.ftb.mods.ftbmaterials.FTBMaterials;
5-
import dev.ftb.mods.ftbmaterials.unification.LootTableUnifier;
5+
import dev.ftb.mods.ftbmaterials.unification.loot.LootTableUnifier;
66
import net.neoforged.neoforge.common.loot.IGlobalLootModifier;
77
import net.neoforged.neoforge.registries.DeferredRegister;
88
import net.neoforged.neoforge.registries.NeoForgeRegistries;

0 commit comments

Comments
 (0)