enchantment fix
This commit is contained in:
@@ -18,7 +18,7 @@ loader_version_range=[2,)
|
||||
mod_id=l2core
|
||||
mod_name=L2Core
|
||||
mod_license=LGPL-2.1
|
||||
mod_version=3.0.5-pre40
|
||||
mod_version=3.0.6-pre10
|
||||
mod_group_id=dev.xkmc
|
||||
mod_authors=lcy0x1
|
||||
mod_description=Core Library mod for all L2 mods
|
||||
|
||||
@@ -3,7 +3,9 @@ package dev.xkmc.l2core.compat.patchouli;
|
||||
import com.tterrag.registrate.providers.ProviderType;
|
||||
import com.tterrag.registrate.util.DataIngredient;
|
||||
import dev.xkmc.l2core.init.reg.registrate.L2Registrate;
|
||||
import dev.xkmc.l2core.serial.advancements.RewardBuilder;
|
||||
import dev.xkmc.l2core.serial.recipe.ConditionalRecipeWrapper;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.recipes.RecipeBuilder;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
@@ -34,13 +36,15 @@ public class PatchouliHelper {
|
||||
}
|
||||
|
||||
private final L2Registrate reg;
|
||||
private final ResourceLocation book;
|
||||
public final ResourceLocation book;
|
||||
public final RewardBuilder reward;
|
||||
|
||||
private ResourceLocation model;
|
||||
|
||||
public PatchouliHelper(L2Registrate reg, String name) {
|
||||
this.reg = reg;
|
||||
book = ResourceLocation.fromNamespaceAndPath(reg.getModid(), name);
|
||||
book = reg.loc(name);
|
||||
reward = new RewardBuilder(reg, 0, ResourceKey.create(Registries.LOOT_TABLE, book), () -> PatchouliHelper.getBookLoot(book));
|
||||
}
|
||||
|
||||
public PatchouliHelper buildModel() {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package dev.xkmc.l2core.init.reg.ench;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderOwner;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public record DataGenHolder<T>(ResourceKey<T> key, T val) implements Holder<T> {
|
||||
@Override
|
||||
public T value() {
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBound() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(ResourceLocation pLocation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(ResourceKey<T> pResourceKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Predicate<ResourceKey<T>> pPredicate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(TagKey<T> pTagKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Holder<T> pHolder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TagKey<T>> tags() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Either<ResourceKey<T>, T> unwrap() {
|
||||
return Either.left(key());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceKey<T>> unwrapKey() {
|
||||
return Optional.of(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind kind() {
|
||||
return Kind.REFERENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSerializeIn(HolderOwner<T> pOwner) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -62,6 +63,11 @@ public interface EECVal<T> extends Val<DataComponentType<List<ConditionalEffect<
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface Num extends EECVal<EnchantmentValueEffect> {
|
||||
@@ -83,6 +89,11 @@ public interface EECVal<T> extends Val<DataComponentType<List<ConditionalEffect<
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,6 +113,11 @@ public interface EECVal<T> extends Val<DataComponentType<List<ConditionalEffect<
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -117,6 +133,11 @@ public interface EECVal<T> extends Val<DataComponentType<List<ConditionalEffect<
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package dev.xkmc.l2core.init.reg.ench;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.tterrag.registrate.providers.ProviderType;
|
||||
import com.tterrag.registrate.providers.RegistrateTagsProvider;
|
||||
import cpw.mods.util.Lazy;
|
||||
import dev.xkmc.l2core.init.L2LibReg;
|
||||
import dev.xkmc.l2core.init.L2TagGen;
|
||||
import dev.xkmc.l2core.init.reg.registrate.L2Registrate;
|
||||
@@ -19,6 +18,7 @@ import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.effects.EnchantmentValueEffect;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
import net.neoforged.neoforge.common.util.Lazy;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class EnchReg {
|
||||
pvd.addDataGenerator(L2TagGen.ENCH_TAGS, this::doTagGen);
|
||||
var init = pvd.getDataGenInitializer();
|
||||
init.add(Registries.ENCHANTMENT, this::build);
|
||||
init.addDependency(ProviderType.DYNAMIC, L2TagGen.ENCH_TAGS);
|
||||
init.addDependency(L2TagGen.ENCH_TAGS, ProviderType.DYNAMIC);
|
||||
}
|
||||
|
||||
private <T> DeferredHolder<DataComponentType<?>, DataComponentType<T>> reg(String id, Codec<T> codec) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.xkmc.l2core.init.reg.ench;
|
||||
|
||||
import cpw.mods.util.Lazy;
|
||||
import com.tterrag.registrate.providers.RegistrateProvider;
|
||||
import dev.xkmc.l2core.util.DataGenOnly;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -15,6 +16,7 @@ import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.ItemEnchantments;
|
||||
import net.neoforged.neoforge.common.CommonHooks;
|
||||
import net.neoforged.neoforge.common.Tags;
|
||||
import net.neoforged.neoforge.common.util.Lazy;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -28,6 +30,9 @@ public interface EnchVal {
|
||||
|
||||
ResourceKey<Enchantment> id();
|
||||
|
||||
@DataGenOnly
|
||||
Holder<Enchantment> datagenDirect(RegistrateProvider pvd);
|
||||
|
||||
default Holder<Enchantment> holder() {
|
||||
return Optional.ofNullable(CommonHooks.resolveLookup(Registries.ENCHANTMENT)).orElseThrow().getOrThrow(id());
|
||||
}
|
||||
@@ -42,6 +47,14 @@ public interface EnchVal {
|
||||
|
||||
interface Impl extends EnchVal {
|
||||
Lazy<Builder> builder();
|
||||
|
||||
@Override
|
||||
default Holder<Enchantment> datagenDirect(RegistrateProvider pvd) {
|
||||
var val = builder().get().cache;
|
||||
if (val == null) throw new IllegalStateException("Enchantment is not built yet");
|
||||
return new DataGenHolder<>(id(), val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interface Flag extends EnchVal {
|
||||
@@ -71,6 +84,8 @@ public interface EnchVal {
|
||||
|
||||
final List<TagKey<Enchantment>> tags = new ArrayList<>();
|
||||
|
||||
private Enchantment cache;
|
||||
|
||||
Builder(ResourceLocation id) {
|
||||
this.id = id;
|
||||
supported = primary = new HolderSetBuilder.Simple<>(Tags.Items.ENCHANTABLES);
|
||||
@@ -156,14 +171,17 @@ public interface EnchVal {
|
||||
|
||||
Enchantment build(BootstrapContext<Enchantment> ctx, ResourceLocation id) {
|
||||
var items = ctx.registryLookup(Registries.ITEM).orElseThrow();
|
||||
var enchs = ctx.registryLookup(Registries.ENCHANTMENT).orElseThrow();
|
||||
var enchs = ctx.lookup(Registries.ENCHANTMENT);
|
||||
var fakeItem = new FakeRegistryLookup<>(Registries.ITEM);
|
||||
var fakeEnch = new FakeRegistryLookup<>(Registries.ENCHANTMENT);
|
||||
var ans = Enchantment.enchantment(new Enchantment.EnchantmentDefinition(
|
||||
supported.build(items), Optional.of(primary.build(items)),
|
||||
supported.build(fakeItem, items), Optional.of(primary.build(fakeItem, items)),
|
||||
weight, maxLevel, min, max, anvilCost,
|
||||
group == null ? List.of() : List.of(group)));
|
||||
if (exclude != null) ans.exclusiveWith(exclude.build(enchs));
|
||||
if (exclude != null) ans.exclusiveWith(exclude.build(fakeEnch, enchs));
|
||||
for (var e : effects) e.accept(ans);
|
||||
return ans.build(id);
|
||||
cache = ans.build(id);
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package dev.xkmc.l2core.init.reg.ench;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public record FakeRegistryLookup<T>(ResourceKey<? extends Registry<? extends T>> key)
|
||||
implements HolderLookup.RegistryLookup<T> {
|
||||
|
||||
@Override
|
||||
public Lifecycle registryLifecycle() {
|
||||
return Lifecycle.stable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Holder.Reference<T>> listElements() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<HolderSet.Named<T>> listTags() {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Holder.Reference<T>> get(ResourceKey<T> pResourceKey) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<HolderSet.Named<T>> get(TagKey<T> pTagKey) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSerializeIn(HolderOwner<T> pOwner) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.xkmc.l2core.init.reg.ench;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -37,12 +37,12 @@ public interface HolderSetBuilder<T> {
|
||||
return new Any<>();
|
||||
}
|
||||
|
||||
HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd);
|
||||
HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd);
|
||||
|
||||
record Simple<T>(TagKey<T> tag) implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return pvd.getOrThrow(tag);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface HolderSetBuilder<T> {
|
||||
record Direct<T>(ResourceKey<T> key) implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return HolderSet.direct(pvd.getOrThrow(key));
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public interface HolderSetBuilder<T> {
|
||||
record Or<T>(List<HolderSetBuilder<T>> list) implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
return new OrHolderSet<>(list.stream().map(e -> e.build(pvd)).toList());
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return new OrHolderSet<>(list.stream().map(e -> e.build(reg, pvd)).toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,8 +69,8 @@ public interface HolderSetBuilder<T> {
|
||||
record And<T>(List<HolderSetBuilder<T>> list) implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
return new AndHolderSet<>(list.stream().map(e -> e.build(pvd)).toList());
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return new AndHolderSet<>(list.stream().map(e -> e.build(reg, pvd)).toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -78,8 +78,8 @@ public interface HolderSetBuilder<T> {
|
||||
record Not<T>(HolderSetBuilder<T> val) implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
return new NotHolderSet<>(pvd, val.build(pvd));
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return new NotHolderSet<>(reg, val.build(reg, pvd));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,8 +87,8 @@ public interface HolderSetBuilder<T> {
|
||||
record Any<T>() implements HolderSetBuilder<T> {
|
||||
|
||||
@Override
|
||||
public HolderSet<T> build(HolderLookup.RegistryLookup<T> pvd) {
|
||||
return new AnyHolderSet<>(pvd);
|
||||
public HolderSet<T> build(FakeRegistryLookup<T> reg, HolderGetter<T> pvd) {
|
||||
return new AnyHolderSet<>(reg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,11 @@ public record AttReg(DeferredRegister<AttachmentType<?>> att) {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private record CapValImpl<E extends AttachmentHolder, T extends GeneralCapabilityTemplate<E, T>>(
|
||||
@@ -66,6 +71,11 @@ public record AttReg(DeferredRegister<AttachmentType<?>> att) {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private record PlayerValImpl<T extends PlayerCapabilityTemplate<T>>(
|
||||
@@ -77,6 +87,11 @@ public record AttReg(DeferredRegister<AttachmentType<?>> att) {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.xkmc.l2core.init.reg.simple;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import dev.xkmc.l2serial.serialization.codec.MapCodecAdaptor;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
@@ -27,6 +28,12 @@ public record CdcReg<T>(DeferredRegister<MapCodec<? extends T>> reg) {
|
||||
public MapCodec<R> get() {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.ComponentSerialization;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Unit;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
@@ -75,6 +76,12 @@ public record DCReg(DeferredRegister<DataComponentType<?>> reg) {
|
||||
public DataComponentType<T> get() {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.xkmc.l2core.init.reg.simple;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import dev.xkmc.l2serial.serialization.codec.MapCodecAdaptor;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.neoforge.common.crafting.ICustomIngredient;
|
||||
import net.neoforged.neoforge.common.crafting.IngredientType;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
@@ -30,6 +31,12 @@ public record IngReg(DeferredRegister<IngredientType<?>> reg) {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ public record SR<T>(DeferredRegister<T> reg) {
|
||||
return val.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return val.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.xkmc.l2core.init.reg.simple;
|
||||
|
||||
import com.tterrag.registrate.util.entry.RegistryEntry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -8,6 +9,8 @@ public interface Val<T> extends Supplier<T> {
|
||||
|
||||
T get();
|
||||
|
||||
ResourceLocation id();
|
||||
|
||||
record Registrate<H, T extends H>(RegistryEntry<H, T> entry) implements Val<T> {
|
||||
|
||||
@Override
|
||||
@@ -15,6 +18,11 @@ public interface Val<T> extends Supplier<T> {
|
||||
return entry.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation id() {
|
||||
return entry.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package dev.xkmc.l2core.mixin;
|
||||
|
||||
import net.neoforged.fml.config.ConfigTracker;
|
||||
import net.neoforged.fml.config.ModConfig;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Mixin(ConfigTracker.class)
|
||||
public interface ConfigTrackerAccessor {
|
||||
|
||||
@Accessor
|
||||
public ConcurrentHashMap<String, ModConfig> getFileMap();
|
||||
|
||||
}
|
||||
@@ -93,11 +93,11 @@ public class AdvancementGenerator {
|
||||
return sub;
|
||||
}
|
||||
|
||||
public Entry patchouli(L2Registrate reg, CriterionBuilder builder, ResourceLocation book, String title, String desc) {
|
||||
ItemStack stack = PatchouliHelper.getBook(book);
|
||||
public Entry patchouli(L2Registrate reg, CriterionBuilder builder, PatchouliHelper pat, String title, String desc) {
|
||||
ItemStack stack = PatchouliHelper.getBook(pat.book);
|
||||
return create("patchouli", stack, builder, title, desc)
|
||||
.add(new ModLoadedAdv("patchouli"))
|
||||
.add(new RewardBuilder(reg, 0, ResourceKey.create(Registries.LOOT_TABLE, book), () -> PatchouliHelper.getBookLoot(book)));
|
||||
.add(pat.reward);
|
||||
}
|
||||
|
||||
public Entry root() {
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
package dev.xkmc.l2core.serial.configval;
|
||||
|
||||
import dev.xkmc.l2core.mixin.ConfigTrackerAccessor;
|
||||
import dev.xkmc.l2core.init.L2Core;
|
||||
import dev.xkmc.l2serial.util.Wrappers;
|
||||
import net.neoforged.fml.config.ConfigTracker;
|
||||
import net.neoforged.fml.config.ModConfig;
|
||||
import net.neoforged.neoforge.common.ModConfigSpec;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AbstractConfigParser {
|
||||
|
||||
private static Map<String, ModConfig> getMap() {
|
||||
try {
|
||||
return Wrappers.cast(ConfigTracker.class.getDeclaredField("fileMap").get(ConfigTracker.INSTANCE));
|
||||
} catch (Exception e) {
|
||||
L2Core.LOGGER.throwing(e);
|
||||
return Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<Object> parse(String path, List<String> line) {
|
||||
var file = ((ConfigTrackerAccessor) ConfigTracker.INSTANCE).getFileMap().get(path);
|
||||
if (file == null) return Optional.empty();
|
||||
var map = getMap();
|
||||
var file = map.get(path);
|
||||
if (file == null) {
|
||||
L2Core.LOGGER.warn("File {} is not a config file", path);
|
||||
return Optional.empty();
|
||||
}
|
||||
var spec = file.getSpec();
|
||||
if (!(spec instanceof ModConfigSpec modSpec) || !modSpec.isLoaded()) return Optional.empty();
|
||||
if (!(spec instanceof ModConfigSpec modSpec) || !modSpec.isLoaded()){
|
||||
L2Core.LOGGER.warn("File {} is not a loaded config file", path);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.ofNullable(modSpec.getValues().get(line));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import dev.xkmc.l2serial.serialization.codec.MapCodecAdaptor;
|
||||
import dev.xkmc.l2serial.util.Wrappers;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeInput;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
@@ -35,8 +34,7 @@ public class RecSerializer<R extends Recipe<I>, I extends RecipeInput> implement
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public R blank() {
|
||||
return Wrappers.get(() -> cls.getConstructor(ResourceLocation.class)
|
||||
.newInstance(ResourceLocation.withDefaultNamespace("dummy")));
|
||||
return Wrappers.get(() -> cls.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,11 @@ public class ConfigInit {
|
||||
val.path = path;
|
||||
RegistrateDistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> initClient(mod));
|
||||
reg.initConfigTitle(mod);
|
||||
reg.addRawLang(reg.getModid() + ".configuration.section." + path.replaceAll("[-_/]", ".") + ".title",
|
||||
mod.getModInfo().getDisplayName() + " " + RegistrateLangProvider.toEnglishName(type.extension()) + " Configuration");
|
||||
String typeName = RegistrateLangProvider.toEnglishName(type.extension());
|
||||
String fileName = reg.getModid() + ".configuration.section." + path.replaceAll("[-_/]", ".");
|
||||
String title = mod.getModInfo().getDisplayName() + " " + typeName + " Configuration";
|
||||
reg.addRawLang(fileName, title);
|
||||
reg.addRawLang(fileName + ".title", title);
|
||||
}
|
||||
|
||||
private static void initClient(ModContainer mod) {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
"package": "dev.xkmc.l2core.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
"ConfigTrackerAccessor"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user