config update

This commit is contained in:
lcy0x1
2024-07-22 20:46:56 +08:00
parent 8894999249
commit b247899e71
18 changed files with 225 additions and 21 deletions

View File

@@ -10,7 +10,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.06.02
minecraft_version=1.21 minecraft_version=1.21
minecraft_version_range=[1.21,1.22) minecraft_version_range=[1.21,1.22)
neo_version=21.0.93-beta neo_version=21.0.112-beta
neo_version_range=[21.0,) neo_version_range=[21.0,)
loader_version_range=[2,) loader_version_range=[2,)
@@ -18,15 +18,15 @@ loader_version_range=[2,)
mod_id=l2core mod_id=l2core
mod_name=L2Core mod_name=L2Core
mod_license=LGPL-2.1 mod_license=LGPL-2.1
mod_version=3.0.5-pre25 mod_version=3.0.5-pre40
mod_group_id=dev.xkmc mod_group_id=dev.xkmc
mod_authors=lcy0x1 mod_authors=lcy0x1
mod_description=Core Library mod for all L2 mods mod_description=Core Library mod for all L2 mods
jei_minecraft_version = 1.21-neoforge jei_minecraft_version = 1.21-neoforge
jei_version = 19.0.0.7 jei_version = 19.5.0.44
registrate_version = MC1.21-1.4.4+fcb9a93 registrate_version = MC1.21-1.4.7+5e718e9
lljij = false lljij = false
rootMod = false rootMod = false

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// 1.21 2024-07-22T16:24:34.828971 Registrate Provider for l2core [Data Maps, Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), generic_server_provider, Blockstates, Item models, Lang (en_us/en_ud), generic_client_provider, Tags (mob_effect), Tags (attribute), Tags (enchantment), Registries]
684b615cec06e91692b3ea45372b4a39ca4d36fc assets/l2core/lang/en_ud.json
9bed3d62e02ce678c56912f1cdfde3af63c74741 assets/l2core/lang/en_us.json
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/l2core/tags/mob_effect/tracked_effects.json

View File

@@ -1 +0,0 @@
// 1.20.1 2023-07-17T13:58:00.905748 Registrate Provider for l2library [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]

View File

@@ -0,0 +1,3 @@
{
"l2core.title": "ǝɹoƆᄅꞀ"
}

View File

@@ -0,0 +1,3 @@
{
"l2core.title": "L2Core"
}

View File

@@ -0,0 +1,3 @@
{
"values": []
}

View File

@@ -19,7 +19,7 @@ import java.util.function.Supplier;
public class PatchouliHelper { public class PatchouliHelper {
public static final ProviderType<PatchouliProvider> PATCHOULI = ProviderType.register("patchouli", PatchouliProvider::new); public static final ProviderType<PatchouliProvider> PATCHOULI = ProviderType.registerServerData("patchouli", PatchouliProvider::new);
public static ItemStack getBook(ResourceLocation book) { public static ItemStack getBook(ResourceLocation book) {
return ItemStack.EMPTY; // TODO ItemModBook.forBook(book); return ItemStack.EMPTY; // TODO ItemModBook.forBook(book);

View File

@@ -0,0 +1,44 @@
package dev.xkmc.l2core.events;
import dev.xkmc.l2core.init.L2Core;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BooleanSupplier;
@EventBusSubscriber(value = Dist.CLIENT, modid = L2Core.MODID, bus = EventBusSubscriber.Bus.GAME)
public class ClientScheduler {
private static List<BooleanSupplier> TASKS = new ArrayList<>();
@SubscribeEvent
public static void clientTick(ClientTickEvent.Post event) {
execute();
}
public static synchronized void schedule(Runnable runnable) {
TASKS.add(() -> {
runnable.run();
return true;
});
}
public static synchronized void schedulePersistent(BooleanSupplier runnable) {
TASKS.add(runnable);
}
private static synchronized void execute() {
if (!TASKS.isEmpty()) {
List<BooleanSupplier> temp = TASKS;
TASKS = new ArrayList<>();
temp.removeIf(BooleanSupplier::getAsBoolean);
temp.addAll(TASKS);
TASKS = temp;
}
}
}

View File

@@ -20,7 +20,6 @@ import static dev.xkmc.l2serial.network.PacketHandler.NetDir.PLAY_TO_CLIENT;
// The value here should match an entry in the META-INF/mods.toml file // The value here should match an entry in the META-INF/mods.toml file
@Mod(L2Core.MODID) @Mod(L2Core.MODID)
@EventBusSubscriber(modid = L2Core.MODID, bus = EventBusSubscriber.Bus.MOD)
public class L2Core { public class L2Core {
public static final String MODID = "l2core"; public static final String MODID = "l2core";
@@ -41,10 +40,6 @@ public class L2Core {
REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen); REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen);
} }
@SubscribeEvent
public static void gatherData(GatherDataEvent event) {
}
public static ResourceLocation loc(String id) { public static ResourceLocation loc(String id) {
return ResourceLocation.fromNamespaceAndPath(MODID, id); return ResourceLocation.fromNamespaceAndPath(MODID, id);
} }

View File

@@ -12,6 +12,7 @@ import com.tterrag.registrate.util.nullness.NonNullSupplier;
import com.tterrag.registrate.util.nullness.NonnullType; import com.tterrag.registrate.util.nullness.NonnullType;
import dev.xkmc.l2core.init.L2Core; import dev.xkmc.l2core.init.L2Core;
import dev.xkmc.l2core.init.reg.simple.Val; import dev.xkmc.l2core.init.reg.simple.Val;
import dev.xkmc.l2core.util.ConfigInit;
import dev.xkmc.l2serial.serialization.custom_handler.CodecHandler; import dev.xkmc.l2serial.serialization.custom_handler.CodecHandler;
import dev.xkmc.l2serial.util.Wrappers; import dev.xkmc.l2serial.util.Wrappers;
import net.minecraft.client.particle.ParticleEngine; import net.minecraft.client.particle.ParticleEngine;
@@ -32,7 +33,9 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.Potion;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import net.neoforged.neoforge.data.loading.DatagenModLoader; import net.neoforged.neoforge.data.loading.DatagenModLoader;
import net.neoforged.neoforge.registries.NewRegistryEvent; import net.neoforged.neoforge.registries.NewRegistryEvent;
@@ -44,6 +47,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@@ -53,15 +57,34 @@ public class L2Registrate extends AbstractRegistrate<L2Registrate> {
public L2Registrate(String modid) { public L2Registrate(String modid) {
super(modid); super(modid);
var bus = ModLoadingContext.get().getActiveContainer().getEventBus(); var mod = ModLoadingContext.get().getActiveContainer();
var bus = mod.getEventBus();
if (bus != null) registerEventListeners(bus); if (bus != null) registerEventListeners(bus);
else L2Core.LOGGER.error("Failed to register mod {}", modid); else L2Core.LOGGER.error("Failed to register mod {}", modid);
addRawLang(modid + ".title", mod.getModInfo().getDisplayName());
} }
public ResourceLocation loc(String id) { public ResourceLocation loc(String id) {
return ResourceLocation.fromNamespaceAndPath(getModid(), id); return ResourceLocation.fromNamespaceAndPath(getModid(), id);
} }
private boolean initConfig = false;
public <T extends ConfigInit> T registerClient(Function<ConfigInit.Builder, T> factory) {
return ConfigInit.register(this, ModConfig.Type.CLIENT, factory);
}
public <T extends ConfigInit> T registerSynced(Function<ConfigInit.Builder, T> factory) {
return ConfigInit.register(this, ModConfig.Type.SERVER, factory);
}
public void initConfigTitle(ModContainer mod) {
if (initConfig) return;
initConfig = true;
addRawLang(getModid() + ".configuration.title", mod.getModInfo().getDisplayName() + " Configuration");
}
public <T, P extends T> GenericBuilder<T, P> generic(RegistryInstance<T> cls, String id, NonNullSupplier<P> sup) { public <T, P extends T> GenericBuilder<T, P> generic(RegistryInstance<T> cls, String id, NonNullSupplier<P> sup) {
return entry(id, cb -> new GenericBuilder<>(this, id, cb, cls.key(), sup)); return entry(id, cb -> new GenericBuilder<>(this, id, cb, cls.key(), sup));
} }
@@ -99,9 +122,17 @@ public class L2Registrate extends AbstractRegistrate<L2Registrate> {
return new Val.Registrate<>(ans); return new Val.Registrate<>(ans);
} }
public <E> RegistryInstance<E> newRegistry(String id) {
ResourceKey<Registry<E>> key = ResourceKey.createRegistryKey(loc(id));
RegistryBuilder<E> ans = new RegistryBuilder<>(key);
Registry<E> reg = ans.create();
OneTimeEventReceiver.addModListener(this, NewRegistryEvent.class, (e) -> e.register(reg));
return new RegistryInstance<>(reg, key);
}
@SuppressWarnings({"unsafe"}) @SuppressWarnings({"unsafe"})
public <E> RegistryInstance<E> newRegistry(String id, Class<?> cls, Consumer<RegistryBuilder<E>> cons) { public <E> RegistryInstance<E> newRegistry(String id, Class<?> cls, Consumer<RegistryBuilder<E>> cons) {
ResourceKey<Registry<E>> key = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(getModid(), id)); ResourceKey<Registry<E>> key = ResourceKey.createRegistryKey(loc(id));
var ans = new RegistryBuilder<>(key); var ans = new RegistryBuilder<>(key);
cons.accept(ans); cons.accept(ans);
var reg = ans.create(); var reg = ans.create();

View File

@@ -15,11 +15,19 @@ import java.util.function.Supplier;
public record RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot, public record RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
Supplier<LootTable.Builder> sup) implements IAdvBuilder { Supplier<LootTable.Builder> sup) implements IAdvBuilder {
@Override public RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) { Supplier<LootTable.Builder> sup){
builder.rewards(AdvancementRewards.Builder.loot(loot).addExperience(exp).build()); this.reg = reg;
this.exp = exp;
this.loot = loot;
this.sup = sup;
reg.addDataGenerator(ProviderType.LOOT, e -> e.addLootAction(LootContextParamSets.EMPTY, reg.addDataGenerator(ProviderType.LOOT, e -> e.addLootAction(LootContextParamSets.EMPTY,
x -> x.accept(loot, sup.get()))); x -> x.accept(loot, sup.get())));
} }
@Override
public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
builder.rewards(AdvancementRewards.Builder.loot(loot).addExperience(exp).build());
}
} }

View File

@@ -0,0 +1,108 @@
package dev.xkmc.l2core.util;
import com.tterrag.registrate.providers.RegistrateLangProvider;
import com.tterrag.registrate.util.RegistrateDistExecutor;
import dev.xkmc.l2core.init.reg.registrate.L2Registrate;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.common.ModConfigSpec;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
public class ConfigInit {
private String folder = null;
private String path = "";
public String getPath() {
return path;
}
protected void folder(String str) {
if (folder != null) throw new IllegalStateException("folder already set to " + folder);
this.folder = str;
}
protected void markL2() {
folder("l2configs/");
}
protected void markPlain() {
folder("");
}
public static <T extends ConfigInit> T register(L2Registrate reg, ModConfig.Type type, Function<Builder, T> factory) {
var builder = new Builder(reg);
var ans = factory.apply(builder);
var spec = builder.build();
register(reg, type, spec, ans);
return ans;
}
private static void register(L2Registrate reg, ModConfig.Type type, IConfigSpec spec, ConfigInit val) {
if (val.folder == null) throw new IllegalStateException("Config must specify folder");
var mod = ModLoadingContext.get().getActiveContainer();
String path = val.folder + mod.getModId() + "-" + type.extension() + ".toml";
mod.registerConfig(type, spec, path);
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");
}
private static void initClient(ModContainer mod) {
mod.<IConfigScreenFactory>registerExtensionPoint(IConfigScreenFactory.class, () -> ConfigurationScreen::new);
}
public static class Builder extends ModConfigSpec.Builder {
private final L2Registrate reg;
private String text = null;
Builder(L2Registrate reg) {
this.reg = reg;
}
@Deprecated
@Override
public Builder push(String path) {
super.push(path);
return this;
}
public Builder push(String path, String name) {
reg.addRawLang(reg.getModid() + ".configuration." + path, name);
super.push(path);
return this;
}
public Builder text(String text) {
this.text = text;
return this;
}
@Override
public <T> ModConfigSpec.ConfigValue<T> define(List<String> path, ModConfigSpec.ValueSpec value, Supplier<T> defaultSupplier) {
if (text == null) throw new IllegalStateException("text not specified");
reg.addRawLang(reg.getModid() + ".configuration." + path.getLast(), text);
String comment = value.getComment();
reg.addRawLang(reg.getModid() + ".configuration." + path.getLast() + ".tooltip", comment == null ? "" : comment);
return super.define(path, value, defaultSupplier);
}
@Override
public ModConfigSpec.Builder comment(String comment) {
return super.comment(comment);
}
}
}

View File

@@ -0,0 +1,8 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package dev.xkmc.l2core.util;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -0,0 +1,3 @@
{
"l2core.title": "莱特兰·核心"
}

View File

@@ -1,5 +0,0 @@
{
"generic.attack_range": "攻击距离",
"generic.reachDistance": "触及距离",
"forge.swimSpeed": "游泳速度"
}