config update
This commit is contained in:
		@@ -19,7 +19,7 @@ import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
		return ItemStack.EMPTY; // TODO ItemModBook.forBook(book);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								src/main/java/dev/xkmc/l2core/events/ClientScheduler.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/main/java/dev/xkmc/l2core/events/ClientScheduler.java
									
									
									
									
									
										Normal 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;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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
 | 
			
		||||
@Mod(L2Core.MODID)
 | 
			
		||||
@EventBusSubscriber(modid = L2Core.MODID, bus = EventBusSubscriber.Bus.MOD)
 | 
			
		||||
public class L2Core {
 | 
			
		||||
 | 
			
		||||
	public static final String MODID = "l2core";
 | 
			
		||||
@@ -41,10 +40,6 @@ public class L2Core {
 | 
			
		||||
		REGISTRATE.addDataGenerator(L2TagGen.EFF_TAGS, L2TagGen::onEffectTagGen);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@SubscribeEvent
 | 
			
		||||
	public static void gatherData(GatherDataEvent event) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static ResourceLocation loc(String id) {
 | 
			
		||||
		return ResourceLocation.fromNamespaceAndPath(MODID, id);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ import com.tterrag.registrate.util.nullness.NonNullSupplier;
 | 
			
		||||
import com.tterrag.registrate.util.nullness.NonnullType;
 | 
			
		||||
import dev.xkmc.l2core.init.L2Core;
 | 
			
		||||
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.util.Wrappers;
 | 
			
		||||
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.alchemy.Potion;
 | 
			
		||||
import net.neoforged.api.distmarker.Dist;
 | 
			
		||||
import net.neoforged.fml.ModContainer;
 | 
			
		||||
import net.neoforged.fml.ModLoadingContext;
 | 
			
		||||
import net.neoforged.fml.config.ModConfig;
 | 
			
		||||
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
 | 
			
		||||
import net.neoforged.neoforge.data.loading.DatagenModLoader;
 | 
			
		||||
import net.neoforged.neoforge.registries.NewRegistryEvent;
 | 
			
		||||
@@ -44,6 +47,7 @@ import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.TreeMap;
 | 
			
		||||
import java.util.function.Consumer;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("unused")
 | 
			
		||||
@@ -53,15 +57,34 @@ public class L2Registrate extends AbstractRegistrate<L2Registrate> {
 | 
			
		||||
 | 
			
		||||
	public L2Registrate(String modid) {
 | 
			
		||||
		super(modid);
 | 
			
		||||
		var bus = ModLoadingContext.get().getActiveContainer().getEventBus();
 | 
			
		||||
		var mod = ModLoadingContext.get().getActiveContainer();
 | 
			
		||||
		var bus = mod.getEventBus();
 | 
			
		||||
		if (bus != null) registerEventListeners(bus);
 | 
			
		||||
		else L2Core.LOGGER.error("Failed to register mod {}", modid);
 | 
			
		||||
		addRawLang(modid + ".title", mod.getModInfo().getDisplayName());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ResourceLocation loc(String 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) {
 | 
			
		||||
		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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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"})
 | 
			
		||||
	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);
 | 
			
		||||
		cons.accept(ans);
 | 
			
		||||
		var reg = ans.create();
 | 
			
		||||
 
 | 
			
		||||
@@ -15,11 +15,19 @@ import java.util.function.Supplier;
 | 
			
		||||
public record RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
 | 
			
		||||
							Supplier<LootTable.Builder> sup) implements IAdvBuilder {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onBuild(String id, Advancement.Builder builder, List<ICondition> conditions) {
 | 
			
		||||
		builder.rewards(AdvancementRewards.Builder.loot(loot).addExperience(exp).build());
 | 
			
		||||
	public RewardBuilder(L2Registrate reg, int exp, ResourceKey<LootTable> loot,
 | 
			
		||||
						 Supplier<LootTable.Builder> sup){
 | 
			
		||||
		this.reg = reg;
 | 
			
		||||
		this.exp = exp;
 | 
			
		||||
		this.loot = loot;
 | 
			
		||||
		this.sup = sup;
 | 
			
		||||
		reg.addDataGenerator(ProviderType.LOOT, e -> e.addLootAction(LootContextParamSets.EMPTY,
 | 
			
		||||
				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());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										108
									
								
								src/main/java/dev/xkmc/l2core/util/ConfigInit.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								src/main/java/dev/xkmc/l2core/util/ConfigInit.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								src/main/java/dev/xkmc/l2core/util/package-info.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/main/java/dev/xkmc/l2core/util/package-info.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
@MethodsReturnNonnullByDefault
 | 
			
		||||
@ParametersAreNonnullByDefault
 | 
			
		||||
 | 
			
		||||
package dev.xkmc.l2core.util;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.MethodsReturnNonnullByDefault;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.ParametersAreNonnullByDefault;
 | 
			
		||||
							
								
								
									
										3
									
								
								src/main/resources/assets/l2core/lang/zh_cn.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/main/resources/assets/l2core/lang/zh_cn.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
{
 | 
			
		||||
  "l2core.title": "莱特兰·核心"
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
    "generic.attack_range": "攻击距离",
 | 
			
		||||
    "generic.reachDistance": "触及距离",
 | 
			
		||||
    "forge.swimSpeed": "游泳速度"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user