diff --git a/base/common/build.gradle b/base/common/build.gradle index 4ecd4c79..8f45564d 100644 --- a/base/common/build.gradle +++ b/base/common/build.gradle @@ -1,8 +1,6 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.base" base.archivesName = rootProject.name + "-base" dependencies { - } \ No newline at end of file diff --git a/base/common/src/main/java/band/kessoku/lib/api/KessokuLib.java b/base/common/src/main/java/band/kessoku/lib/api/KessokuLib.java new file mode 100644 index 00000000..7eeabc58 --- /dev/null +++ b/base/common/src/main/java/band/kessoku/lib/api/KessokuLib.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.*; + +import org.jetbrains.annotations.UnmodifiableView; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class KessokuLib { + private static final List> initializedModules = new ArrayList<>(); + + private KessokuLib() { + } + + public static void loadModule(Class moduleCommonClass) { + // Try to get module name + String moduleName; + try { + Field field = moduleCommonClass.getField("NAME"); + if (!Modifier.isStatic(field.getModifiers())) + throw new IllegalArgumentException("NAME in " + moduleCommonClass.getPackageName() + " is not static!"); + field.setAccessible(true); + moduleName = (String) field.get(null); + } catch (NoSuchFieldException e) { + getLogger().warn("no NAME found for {}! Using package name", moduleCommonClass.getPackageName()); + moduleName = moduleCommonClass.getPackageName(); + } catch (IllegalAccessException e) { + // Already set accessible, shouldn't be called + moduleName = moduleCommonClass.getPackageName(); + } + initializedModules.add(moduleCommonClass); + getLogger().info("{} loaded!", moduleName); + } + + public static boolean isModuleLoaded(Class moduleCommonClass) { + return initializedModules.contains(moduleCommonClass); + } + + @UnmodifiableView + public static List> getActiveModules() { + return Collections.unmodifiableList(initializedModules); + } + + public static T loadService(final Class clazz) { + return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getPackageName())); + } + + public static Logger getLogger() { + return LoggerFactory.getLogger("[Kessoku Lib]"); + } +} diff --git a/base/common/src/main/java/band/kessoku/lib/base/KessokuBase.java b/base/common/src/main/java/band/kessoku/lib/api/base/KessokuBase.java similarity index 84% rename from base/common/src/main/java/band/kessoku/lib/base/KessokuBase.java rename to base/common/src/main/java/band/kessoku/lib/api/base/KessokuBase.java index 6bda4ea3..31dbfa9b 100644 --- a/base/common/src/main/java/band/kessoku/lib/base/KessokuBase.java +++ b/base/common/src/main/java/band/kessoku/lib/api/base/KessokuBase.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.base; +package band.kessoku.lib.api.base; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuBase { +public final class KessokuBase { public static final String MOD_ID = "kessoku_base"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuBase]"); + public static final String NAME = "Kessoku Base API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); } diff --git a/base/common/src/main/java/band/kessoku/lib/base/ModUtils.java b/base/common/src/main/java/band/kessoku/lib/api/base/KessokuUtils.java similarity index 59% rename from base/common/src/main/java/band/kessoku/lib/base/ModUtils.java rename to base/common/src/main/java/band/kessoku/lib/api/base/KessokuUtils.java index 1fc1cac6..d05cbb5e 100644 --- a/base/common/src/main/java/band/kessoku/lib/base/ModUtils.java +++ b/base/common/src/main/java/band/kessoku/lib/api/base/KessokuUtils.java @@ -13,39 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.base; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package band.kessoku.lib.api.base; import java.lang.reflect.Constructor; -import java.util.List; -import java.util.ServiceLoader; +import java.util.*; -public class ModUtils { - public static T loadService(Class clazz) { - return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getName())); - } +import org.jetbrains.annotations.NotNull; - public static Logger getLogger() { - return LoggerFactory.getLogger("[KessokuLib]"); +public final class KessokuUtils { + private KessokuUtils() { } - public static boolean isType(List list, Class type) { - for (Object element : list) { + public static boolean isType(final List list, final Class type) { + for (final Object element : list) { if (!(type.isInstance(element))) { return false; } } return true; } - public static V constructUnsafely(Class cls) { + + public static V constructUnsafely(final Class cls) { try { - Constructor constructor = cls.getDeclaredConstructor(); + final Constructor constructor = cls.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } + + public static @NotNull Set getKeysByValue(final Map map, final V value) { + final Set result = new HashSet<>(); + map.forEach((k, v) -> { + if (v.equals(value)) result.add(k); + }); + return result; + } } diff --git a/base/common/src/main/java/band/kessoku/lib/impl/package-info.java b/base/common/src/main/java/band/kessoku/lib/impl/package-info.java new file mode 100644 index 00000000..85595c92 --- /dev/null +++ b/base/common/src/main/java/band/kessoku/lib/impl/package-info.java @@ -0,0 +1,4 @@ +@ApiStatus.Internal +package band.kessoku.lib.impl; + +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file diff --git a/base/fabric/build.gradle b/base/fabric/build.gradle index ea593d9d..11183406 100644 --- a/base/fabric/build.gradle +++ b/base/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.base" base.archivesName = rootProject.name + "-base" kessoku { diff --git a/config/fabric/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java b/base/fabric/src/main/java/band/kessoku/lib/impl/base/fabric/KessokuBaseFabric.java similarity index 74% rename from config/fabric/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java rename to base/fabric/src/main/java/band/kessoku/lib/impl/base/fabric/KessokuBaseFabric.java index 9ca29101..4b940120 100644 --- a/config/fabric/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java +++ b/base/fabric/src/main/java/band/kessoku/lib/impl/base/fabric/KessokuBaseFabric.java @@ -13,12 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config; +package band.kessoku.lib.impl.base.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.base.KessokuBase; import net.fabricmc.api.ModInitializer; -public class KessokuConfigEntrypoint implements ModInitializer { +public final class KessokuBaseFabric implements ModInitializer { @Override public void onInitialize() { + KessokuLib.loadModule(KessokuBase.class); } } diff --git a/base/fabric/src/main/resources/fabric.mod.json b/base/fabric/src/main/resources/fabric.mod.json index e9c59795..317f5099 100644 --- a/base/fabric/src/main/resources/fabric.mod.json +++ b/base/fabric/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "kessoku_base", "version": "${version}", "name": "Kessoku Base", - "description": "Provide some basic API.", + "description": "Kessoku base API.", "authors": [ "Kessoku Tea Time" ], @@ -16,7 +16,7 @@ "icon": "icon.png", "entrypoints": { "main": [ - "band.kessoku.lib.base.KessokuBaseEntrypoint" + "band.kessoku.lib.impl.base.fabric.KessokuBaseFabric" ] }, "environment": "*", diff --git a/base/neo/build.gradle b/base/neo/build.gradle index 1d37188e..76f07d02 100644 --- a/base/neo/build.gradle +++ b/base/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.base" base.archivesName = rootProject.name + "-base" kessoku { diff --git a/event-base/neo/src/main/java/band/kessoku/lib/event/util/NeoEventUtils.java b/base/neo/src/main/java/band/kessoku/lib/api/base/neoforge/NeoEventUtils.java similarity index 89% rename from event-base/neo/src/main/java/band/kessoku/lib/event/util/NeoEventUtils.java rename to base/neo/src/main/java/band/kessoku/lib/api/base/neoforge/NeoEventUtils.java index 7684094d..067012a0 100644 --- a/event-base/neo/src/main/java/band/kessoku/lib/event/util/NeoEventUtils.java +++ b/base/neo/src/main/java/band/kessoku/lib/api/base/neoforge/NeoEventUtils.java @@ -13,15 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.event.util; +package band.kessoku.lib.api.base.neoforge; + +import java.util.function.Consumer; import net.neoforged.bus.api.Event; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.IEventBus; -import java.util.function.Consumer; +public final class NeoEventUtils { + private NeoEventUtils() { + } -public class NeoEventUtils { public static void registerEvent(IEventBus eventBus, Class eventClass, Consumer consumer) { eventBus.addListener(EventPriority.HIGHEST, eventClass, consumer); } diff --git a/base/neo/src/main/java/band/kessoku/lib/impl/base/neoforge/KessokuBaseNeoforge.java b/base/neo/src/main/java/band/kessoku/lib/impl/base/neoforge/KessokuBaseNeoforge.java new file mode 100644 index 00000000..19d9f773 --- /dev/null +++ b/base/neo/src/main/java/band/kessoku/lib/impl/base/neoforge/KessokuBaseNeoforge.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.base.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.base.KessokuBase; + +import net.neoforged.fml.common.Mod; + +@Mod(KessokuBase.MOD_ID) +public final class KessokuBaseNeoforge { + public KessokuBaseNeoforge() { + KessokuLib.loadModule(KessokuBase.class); + } +} diff --git a/base/neo/src/main/resources/META-INF/neoforge.mods.toml b/base/neo/src/main/resources/META-INF/neoforge.mods.toml index da242cb8..8b5569e8 100644 --- a/base/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/base/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -8,7 +8,7 @@ modId = "kessoku_base" version = "${version}" displayName = "Kessoku Base" description = ''' -Provide some basic API. +Kessoku base API. ''' logoFile = "icon.png" authors = "Kessoku Tea Time" diff --git a/build.gradle b/build.gradle index 062e25ff..13db0016 100644 --- a/build.gradle +++ b/build.gradle @@ -99,4 +99,5 @@ subprojects { allprojects { apply plugin: "com.diffplug.spotless" + group = "band.kessoku.lib" } \ No newline at end of file diff --git a/buildSrc/src/main/java/band/kessoku/gradle/plugin/KesssokuExtension.java b/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuExtension.java similarity index 88% rename from buildSrc/src/main/java/band/kessoku/gradle/plugin/KesssokuExtension.java rename to buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuExtension.java index c0bf0ae5..0d44683e 100644 --- a/buildSrc/src/main/java/band/kessoku/gradle/plugin/KesssokuExtension.java +++ b/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuExtension.java @@ -12,10 +12,28 @@ import java.util.List; import java.util.Map; -public abstract class KesssokuExtension { +public abstract class KessokuExtension { @Inject protected abstract Project getProject(); + protected static final List MODULES = List.of( + "base", + "command", + "config", + "data", + "entity-events", + "entrypoint", + "event-base", + "keybinding", + "lifecycle-events", + "platform", + "registry" + ); + + public List getModuleList() { + return MODULES; + } + public void library(String lib) { Project project = this.getProject(); DependencyHandler dependencies = project.getDependencies(); @@ -77,13 +95,6 @@ public void moduleInclude(String name, String plat) { "configuration", "namedElements" )); dependencies.add("include", dependency); - - LoomGradleExtensionAPI loom = project.getExtensions().getByType(LoomGradleExtensionAPI.class); - loom.mods(mods -> mods.register("kessoku-" + name + "-" + plat, settings -> { - Project depProject = project.project(":" + name + "-" + plat); - SourceSetContainer sourceSets = depProject.getExtensions().getByType(SourceSetContainer.class); - settings.sourceSet(sourceSets.getByName("main"), depProject); - })); } public void common(String name, ModPlatform platform) { diff --git a/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuGradlePlugin.java b/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuGradlePlugin.java index c2a9f33f..787a95ad 100644 --- a/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuGradlePlugin.java +++ b/buildSrc/src/main/java/band/kessoku/gradle/plugin/KessokuGradlePlugin.java @@ -10,7 +10,8 @@ import java.util.List; -public class KessokuGradlePlugin implements Plugin { +public final class KessokuGradlePlugin implements Plugin { + private static final List NEO_GROUPS = List.of( "net.neoforged", "cpw.mods", @@ -28,14 +29,15 @@ public void apply(@NotNull PluginAware target) { settings.getGradle().getPluginManager().apply(KessokuGradlePlugin.class); } case Project project -> { - project.getExtensions().create("kessoku", KesssokuExtension.class); + project.getExtensions().create("kessoku", KessokuExtension.class); additionalRepositories(project.getRepositories()); } case Gradle gradle -> { return; } - default -> throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass()); + default -> + throw new IllegalArgumentException("Expected target to be a Project or Settings, but was a " + target.getClass()); } } diff --git a/buildSrc/src/main/java/band/kessoku/gradle/plugin/PlatformIdentifier.java b/buildSrc/src/main/java/band/kessoku/gradle/plugin/PlatformIdentifier.java new file mode 100644 index 00000000..5fabce45 --- /dev/null +++ b/buildSrc/src/main/java/band/kessoku/gradle/plugin/PlatformIdentifier.java @@ -0,0 +1,30 @@ +package band.kessoku.gradle.plugin; + +import net.fabricmc.loom.util.ModPlatform; + +import java.util.Locale; + +public enum PlatformIdentifier { + FABRIC("Fabric", ModPlatform.FABRIC), + NEO("Neo", ModPlatform.NEOFORGE) + ; + + private final String displayName; + private final ModPlatform modPlatform; + + PlatformIdentifier(String displayName, ModPlatform modPlatform) { + this.displayName = displayName; + this.modPlatform = modPlatform; + } + + /** + * Returns the lowercase ID of this mod platform. + */ + public String id() { + return name().toLowerCase(Locale.ROOT); + } + + public String displayName() { + return displayName; + } +} diff --git a/command/common/build.gradle b/command/common/build.gradle index f10e31df..36470dc7 100644 --- a/command/common/build.gradle +++ b/command/common/build.gradle @@ -1,10 +1,8 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.command" base.archivesName = rootProject.name + "-command" kessoku { modules(["base", "event-base"], "common") - testModules(["base", "event-base"], "common") } \ No newline at end of file diff --git a/command/common/src/main/java/band/kessoku/lib/command/KessokuCommand.java b/command/common/src/main/java/band/kessoku/lib/api/command/KessokuCommand.java similarity index 83% rename from command/common/src/main/java/band/kessoku/lib/command/KessokuCommand.java rename to command/common/src/main/java/band/kessoku/lib/api/command/KessokuCommand.java index 736475e2..a012cae3 100644 --- a/command/common/src/main/java/band/kessoku/lib/command/KessokuCommand.java +++ b/command/common/src/main/java/band/kessoku/lib/api/command/KessokuCommand.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command; +package band.kessoku.lib.api.command; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuCommand { +public final class KessokuCommand { public static final String MOD_ID = "kessoku_command"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuCommand]"); + public static final String NAME = "Kessoku Command API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); } diff --git a/command/common/src/main/java/band/kessoku/lib/command/api/events/CommandRegistryEvent.java b/command/common/src/main/java/band/kessoku/lib/api/event/command/CommandRegistryEvent.java similarity index 82% rename from command/common/src/main/java/band/kessoku/lib/command/api/events/CommandRegistryEvent.java rename to command/common/src/main/java/band/kessoku/lib/api/event/command/CommandRegistryEvent.java index e6f1780f..ca36d488 100644 --- a/command/common/src/main/java/band/kessoku/lib/command/api/events/CommandRegistryEvent.java +++ b/command/common/src/main/java/band/kessoku/lib/api/event/command/CommandRegistryEvent.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command.api.events; +package band.kessoku.lib.api.event.command; import band.kessoku.lib.event.api.Event; import com.mojang.brigadier.CommandDispatcher; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.command.CommandRegistryAccess; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +@ApiStatus.NonExtendable public interface CommandRegistryEvent { - Event EVENT = Event.of(commandRegistryEvents -> (dispatcher, registryAccess, environment) -> { for (CommandRegistryEvent commandRegistryEvent : commandRegistryEvents) { commandRegistryEvent.register(dispatcher, registryAccess, environment); @@ -32,10 +34,9 @@ public interface CommandRegistryEvent { /** * Called when the server is registering commands. * - * @param dispatcher the command dispatcher to register commands to + * @param dispatcher the command dispatcher to register commands to * @param registryAccess object exposing access to the game's registries - * @param environment environment the registrations should be done for, used for commands that are dedicated or integrated server only + * @param environment environment the registrations should be done for, used for commands that are dedicated or integrated server only */ void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment); - } diff --git a/command/common/src/test/java/kessoku/testmod/command/KessokuTestCommand.java b/command/common/src/test/java/kessoku/testmod/command/KessokuTestCommand.java index c01b1a6a..62189cce 100644 --- a/command/common/src/test/java/kessoku/testmod/command/KessokuTestCommand.java +++ b/command/common/src/test/java/kessoku/testmod/command/KessokuTestCommand.java @@ -15,8 +15,9 @@ */ package kessoku.testmod.command; -import band.kessoku.lib.command.api.events.CommandRegistryEvent; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.command.CommandRegistryEvent; + import net.minecraft.server.command.CommandManager; import net.minecraft.text.Text; diff --git a/command/fabric/build.gradle b/command/fabric/build.gradle index 46fe7b84..822a6428 100644 --- a/command/fabric/build.gradle +++ b/command/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.command" base.archivesName = rootProject.name + "-command" kessoku { diff --git a/command/fabric/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java b/command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandFabric.java similarity index 72% rename from command/fabric/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java rename to command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandFabric.java index e37cd1f3..bc8d056c 100644 --- a/command/fabric/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java +++ b/command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandFabric.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command; +package band.kessoku.lib.impl.command.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.command.KessokuCommand; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.command.impl.KessokuCommandImpl; import net.fabricmc.api.ModInitializer; -public class KessokuCommandEntrypoint implements ModInitializer { +public final class KessokuCommandFabric implements ModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuCommand.MARKER, "KessokuLib-Command is Loaded!"); + KessokuLib.loadModule(KessokuCommand.class); KessokuCommandImpl.registerCommonEvents(); } } diff --git a/command/fabric/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java b/command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandImpl.java similarity index 86% rename from command/fabric/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java rename to command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandImpl.java index 565b0902..e4509235 100644 --- a/command/fabric/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java +++ b/command/fabric/src/main/java/band/kessoku/lib/impl/command/fabric/KessokuCommandImpl.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command.impl; +package band.kessoku.lib.impl.command.fabric; + +import band.kessoku.lib.api.event.command.CommandRegistryEvent; -import band.kessoku.lib.command.api.events.CommandRegistryEvent; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -public class KessokuCommandImpl { +public final class KessokuCommandImpl { public static void registerCommonEvents() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { CommandRegistryEvent.EVENT.invoker().register(dispatcher, registryAccess, environment); diff --git a/command/fabric/src/main/resources/fabric.mod.json b/command/fabric/src/main/resources/fabric.mod.json index 04fadd51..38f39f62 100644 --- a/command/fabric/src/main/resources/fabric.mod.json +++ b/command/fabric/src/main/resources/fabric.mod.json @@ -14,6 +14,11 @@ }, "license": "LGPL-3.0-only", "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.command.fabric.KessokuCommandFabric" + ] + }, "environment": "*", "depends": { "fabricloader": ">=0.16.0", diff --git a/command/fabric/src/main/resources/kessoku_command.mixins.json b/command/fabric/src/main/resources/kessoku_command.mixins.json deleted file mode 100644 index e69de29b..00000000 diff --git a/command/neo/build.gradle b/command/neo/build.gradle index 9b8cb21b..2df96647 100644 --- a/command/neo/build.gradle +++ b/command/neo/build.gradle @@ -2,12 +2,11 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.command" base.archivesName = rootProject.name + "-command" kessoku { modules(["base", "event-base"], "common") - module("event-base", "neo") + module("base", "neo") common("command", ModPlatform.NEOFORGE) shadowBundle("command", ModPlatform.NEOFORGE) diff --git a/command/neo/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java b/command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandImpl.java similarity index 83% rename from command/neo/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java rename to command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandImpl.java index b265eaae..a6373e58 100644 --- a/command/neo/src/main/java/band/kessoku/lib/command/impl/KessokuCommandImpl.java +++ b/command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandImpl.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command.impl; +package band.kessoku.lib.impl.command.neoforge; + +import band.kessoku.lib.api.base.neoforge.NeoEventUtils; +import band.kessoku.lib.api.event.command.CommandRegistryEvent; -import band.kessoku.lib.command.api.events.CommandRegistryEvent; -import band.kessoku.lib.event.util.NeoEventUtils; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.event.RegisterCommandsEvent; -public class KessokuCommandImpl { +public final class KessokuCommandImpl { public static void registerCommonEvents(IEventBus forgeEventBus) { NeoEventUtils.registerEvent(forgeEventBus, RegisterCommandsEvent.class, event -> { CommandRegistryEvent.EVENT.invoker().register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection()); diff --git a/command/neo/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java b/command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandNeoforge.java similarity index 70% rename from command/neo/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java rename to command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandNeoforge.java index 581e8ad9..29543947 100644 --- a/command/neo/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java +++ b/command/neo/src/main/java/band/kessoku/lib/impl/command/neoforge/KessokuCommandNeoforge.java @@ -13,19 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.command; +package band.kessoku.lib.impl.command.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.command.KessokuCommand; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.command.impl.KessokuCommandImpl; -import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.common.NeoForge; @Mod(KessokuCommand.MOD_ID) -public class KessokuCommandEntrypoint { - public KessokuCommandEntrypoint(IEventBus modEventBus) { +public final class KessokuCommandNeoforge { + public KessokuCommandNeoforge() { var forgeEventBus = NeoForge.EVENT_BUS; - ModUtils.getLogger().info(KessokuCommand.MARKER, "KessokuLib-Command is Loaded!"); + KessokuLib.loadModule(KessokuCommand.class); KessokuCommandImpl.registerCommonEvents(forgeEventBus); } } diff --git a/config/common/build.gradle b/config/common/build.gradle index 69d57f62..9aa790ce 100644 --- a/config/common/build.gradle +++ b/config/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.config" base.archivesName = rootProject.name + "-config" kessoku { diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java b/config/common/src/main/java/band/kessoku/lib/api/config/AbstractConfig.java similarity index 92% rename from config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java rename to config/common/src/main/java/band/kessoku/lib/api/config/AbstractConfig.java index 416d6827..dee3d9be 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/AbstractConfig.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/AbstractConfig.java @@ -13,18 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api; - -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.config.KessokuConfig; -import band.kessoku.lib.config.api.annotations.Comment; -import band.kessoku.lib.config.api.annotations.Comments; -import band.kessoku.lib.config.api.annotations.Name; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.logging.log4j.core.util.ReflectionUtil; +package band.kessoku.lib.api.config; import java.io.File; import java.io.FileWriter; @@ -37,6 +26,16 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.config.annotations.Comment; +import band.kessoku.lib.api.config.annotations.Comments; +import band.kessoku.lib.api.config.annotations.Name; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.logging.log4j.core.util.ReflectionUtil; + @SuppressWarnings({"rawtypes", "unused"}) public abstract class AbstractConfig { private final List> preSave = new ArrayList<>(); @@ -93,13 +92,13 @@ public boolean load() { ConfigValue.Type type = ConfigValue.Type.asType(cValue); // Check if the type is valid to deserialize if (type == ConfigValue.Type.NULL) { - ModUtils.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file!", cValue.getClass().getName()); + KessokuLib.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file!", cValue.getClass().getName()); continue; } // Check if the type matches the value's type if (value.getType() != type) { - ModUtils.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file! Expect {}.", type.toString().toLowerCase(), value.getType().toString().toLowerCase()); + KessokuLib.getLogger().error(KessokuConfig.MARKER, "Illegal type`{}` found in the file! Expect {}.", type.toString().toLowerCase(), value.getType().toString().toLowerCase()); continue; } @@ -137,7 +136,7 @@ public void reset() { public ImmutableList> getValidValues() { if (this.values != null) { - return ImmutableList.>builder().addAll(this.values.stream().map(field -> + return ImmutableList.>builder().addAll(this.values.parallelStream().map(field -> (ConfigValue) ReflectionUtil.getFieldValue(field, this)).toList()).build(); } @@ -216,7 +215,7 @@ private Map serialize() { AbstractConfig category = (AbstractConfig) fieldValue; if (this.split) { if (!category.save()) { - ModUtils.getLogger().error(KessokuConfig.MARKER, "Failed to save category `{}!`", category.getSimpleName()); + KessokuLib.getLogger().error(KessokuConfig.MARKER, "Failed to save category `{}!`", category.getSimpleName()); } continue; } diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/ConfigSerializer.java b/config/common/src/main/java/band/kessoku/lib/api/config/ConfigSerializer.java similarity index 95% rename from config/common/src/main/java/band/kessoku/lib/config/api/ConfigSerializer.java rename to config/common/src/main/java/band/kessoku/lib/api/config/ConfigSerializer.java index 86d492aa..fe36bfe5 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/ConfigSerializer.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/ConfigSerializer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api; +package band.kessoku.lib.api.config; import java.util.Map; diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/ConfigValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/ConfigValue.java similarity index 98% rename from config/common/src/main/java/band/kessoku/lib/config/api/ConfigValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/ConfigValue.java index 7868674a..0a7f28fb 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/ConfigValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/ConfigValue.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api; +package band.kessoku.lib.api.config; import java.util.List; import java.util.Map; diff --git a/config/common/src/main/java/band/kessoku/lib/config/KessokuConfig.java b/config/common/src/main/java/band/kessoku/lib/api/config/KessokuConfig.java similarity index 94% rename from config/common/src/main/java/band/kessoku/lib/config/KessokuConfig.java rename to config/common/src/main/java/band/kessoku/lib/api/config/KessokuConfig.java index e9a021b1..33b167d2 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/KessokuConfig.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/KessokuConfig.java @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config; +package band.kessoku.lib.api.config; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; -import band.kessoku.lib.config.api.AbstractConfig; -import band.kessoku.lib.config.api.ConfigSerializer; import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -24,17 +27,13 @@ import org.slf4j.Marker; import org.slf4j.MarkerFactory; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - public final class KessokuConfig { private static final Map> configs = new HashMap<>(); private static final Map, ConfigSerializer> serializerCache = new HashMap<>(); public static final String MOD_ID = "kessoku_config"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuConfig]"); + public static final String NAME = "Kessoku Config API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); @SuppressWarnings({"unchecked", "unused"}) public static T register(T config, Class serializer) { diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comment.java b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comment.java similarity index 94% rename from config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comment.java rename to config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comment.java index fe2e8d1a..808ed7f3 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comment.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comment.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.annotations; +package band.kessoku.lib.api.config.annotations; import java.lang.annotation.*; diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comments.java b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comments.java similarity index 94% rename from config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comments.java rename to config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comments.java index 90c2ae8f..8433c23f 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Comments.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Comments.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.annotations; +package band.kessoku.lib.api.config.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Name.java b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Name.java similarity index 94% rename from config/common/src/main/java/band/kessoku/lib/config/api/annotations/Name.java rename to config/common/src/main/java/band/kessoku/lib/api/config/annotations/Name.java index cbc4a8d4..b4d05627 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/annotations/Name.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/annotations/Name.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.annotations; +package band.kessoku.lib.api.config.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/Json5Serializer.java b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/Json5Serializer.java similarity index 92% rename from config/common/src/main/java/band/kessoku/lib/config/api/serializers/Json5Serializer.java rename to config/common/src/main/java/band/kessoku/lib/api/config/serializers/Json5Serializer.java index 3e5c3f40..e27b59df 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/Json5Serializer.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/Json5Serializer.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.serializers; +package band.kessoku.lib.api.config.serializers; -import band.kessoku.lib.config.api.AbstractConfig; -import band.kessoku.lib.config.api.ConfigSerializer; +import java.util.Map; + +import band.kessoku.lib.api.config.AbstractConfig; +import band.kessoku.lib.api.config.ConfigSerializer; import club.someoneice.json.JSON; import club.someoneice.json.node.JsonNode; import club.someoneice.json.processor.Json5Builder; -import java.util.Map; - // TODO public class Json5Serializer implements ConfigSerializer { @Override diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/JsonSerializer.java b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/JsonSerializer.java similarity index 91% rename from config/common/src/main/java/band/kessoku/lib/config/api/serializers/JsonSerializer.java rename to config/common/src/main/java/band/kessoku/lib/api/config/serializers/JsonSerializer.java index 38d331a4..0d8be82e 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/JsonSerializer.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/JsonSerializer.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.serializers; +package band.kessoku.lib.api.config.serializers; -import band.kessoku.lib.config.api.AbstractConfig; -import band.kessoku.lib.config.api.ConfigSerializer; +import java.util.Map; + +import band.kessoku.lib.api.config.AbstractConfig; +import band.kessoku.lib.api.config.ConfigSerializer; import club.someoneice.json.JSON; import club.someoneice.json.Pair; import club.someoneice.json.node.JsonNode; import club.someoneice.json.node.MapNode; import club.someoneice.json.processor.JsonBuilder; -import java.util.Map; - public class JsonSerializer implements ConfigSerializer { @Override public String serialize(Map value) { diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/TomlSerializer.java b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/TomlSerializer.java similarity index 88% rename from config/common/src/main/java/band/kessoku/lib/config/api/serializers/TomlSerializer.java rename to config/common/src/main/java/band/kessoku/lib/api/config/serializers/TomlSerializer.java index 5b5afe5b..f4ad88b8 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/serializers/TomlSerializer.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/serializers/TomlSerializer.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.serializers; - -import band.kessoku.lib.config.api.AbstractConfig; -import band.kessoku.lib.config.api.ConfigSerializer; -import com.electronwill.nightconfig.core.CommentedConfig; +package band.kessoku.lib.api.config.serializers; import java.util.Map; +import band.kessoku.lib.api.config.AbstractConfig; +import band.kessoku.lib.api.config.ConfigSerializer; +import com.electronwill.nightconfig.core.CommentedConfig; + //todo public class TomlSerializer implements ConfigSerializer { @Override diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/BooleanValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/BooleanValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/BooleanValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/BooleanValue.java index b9120543..2e0b35cf 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/BooleanValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/BooleanValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class BooleanValue extends DefaultConfigValue { private BooleanValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/DefaultConfigValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/DefaultConfigValue.java similarity index 94% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/DefaultConfigValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/DefaultConfigValue.java index 460c8623..cc3f8f76 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/DefaultConfigValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/DefaultConfigValue.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; - -import band.kessoku.lib.config.api.ConfigValue; +package band.kessoku.lib.api.config.values; import java.util.function.Supplier; +import band.kessoku.lib.api.config.ConfigValue; + sealed abstract class DefaultConfigValue implements ConfigValue permits BooleanValue, DoubleValue, FloatValue, IntegerValue, ListValue, LongValue, MapValue, StringValue { public final Supplier defaultValue; public T value; diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/DoubleValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/DoubleValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/DoubleValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/DoubleValue.java index 3c05a1b7..84714e41 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/DoubleValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/DoubleValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class DoubleValue extends DefaultConfigValue { private DoubleValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/FloatValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/FloatValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/FloatValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/FloatValue.java index 1d66d0ff..07c5909b 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/FloatValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/FloatValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class FloatValue extends DefaultConfigValue { private FloatValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/IntegerValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/IntegerValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/IntegerValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/IntegerValue.java index ce7539cb..b2f81974 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/IntegerValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/IntegerValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class IntegerValue extends DefaultConfigValue { private IntegerValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/ListValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/ListValue.java similarity index 99% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/ListValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/ListValue.java index ecf17e84..43ed0d08 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/ListValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/ListValue.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.*; +import java.util.function.Supplier; import com.google.common.collect.ImmutableList; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Unmodifiable; -import java.util.*; -import java.util.function.Supplier; - @SuppressWarnings({"rawtypes"}) public final class ListValue extends DefaultConfigValue> implements List { private ListValue(Supplier> defaultValue) { diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/LongValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/LongValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/LongValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/LongValue.java index 2de89dc5..4418a959 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/LongValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/LongValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class LongValue extends DefaultConfigValue { private LongValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/MapValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/MapValue.java similarity index 98% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/MapValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/MapValue.java index 39858f37..c937ccae 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/MapValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/MapValue.java @@ -13,13 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; - -import com.google.common.collect.ImmutableMap; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Unmodifiable; +package band.kessoku.lib.api.config.values; import java.util.Collection; import java.util.HashMap; @@ -27,6 +21,12 @@ import java.util.Set; import java.util.function.Supplier; +import com.google.common.collect.ImmutableMap; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + public final class MapValue extends DefaultConfigValue> implements Map { private MapValue(Supplier> defaultValue) { super(defaultValue); diff --git a/config/common/src/main/java/band/kessoku/lib/config/api/values/StringValue.java b/config/common/src/main/java/band/kessoku/lib/api/config/values/StringValue.java similarity index 96% rename from config/common/src/main/java/band/kessoku/lib/config/api/values/StringValue.java rename to config/common/src/main/java/band/kessoku/lib/api/config/values/StringValue.java index 6d75a28e..8d0ff915 100644 --- a/config/common/src/main/java/band/kessoku/lib/config/api/values/StringValue.java +++ b/config/common/src/main/java/band/kessoku/lib/api/config/values/StringValue.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config.api.values; +package band.kessoku.lib.api.config.values; + +import java.util.function.Supplier; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - public final class StringValue extends DefaultConfigValue { private StringValue(Supplier defaultValue) { super(defaultValue); diff --git a/config/fabric/build.gradle b/config/fabric/build.gradle index 1f6176d7..fa5324cb 100644 --- a/config/fabric/build.gradle +++ b/config/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.config" base.archivesName = rootProject.name + "-config" kessoku { diff --git a/registry/fabric/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java b/config/fabric/src/main/java/band/kessoku/lib/impl/config/fabric/KessokuConfigFabric.java similarity index 74% rename from registry/fabric/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java rename to config/fabric/src/main/java/band/kessoku/lib/impl/config/fabric/KessokuConfigFabric.java index dc03364d..0212b577 100644 --- a/registry/fabric/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java +++ b/config/fabric/src/main/java/band/kessoku/lib/impl/config/fabric/KessokuConfigFabric.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry; +package band.kessoku.lib.impl.config.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.config.KessokuConfig; -import band.kessoku.lib.base.ModUtils; import net.fabricmc.api.ModInitializer; -public class KessokuRegistryEntrypoint implements ModInitializer { +public final class KessokuConfigFabric implements ModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuRegistry.MARKER, "KessokuLib-Registry is loaded!"); + KessokuLib.loadModule(KessokuConfig.class); } } diff --git a/config/fabric/src/main/resources/fabric.mod.json b/config/fabric/src/main/resources/fabric.mod.json index ff234944..0e3d0dc1 100644 --- a/config/fabric/src/main/resources/fabric.mod.json +++ b/config/fabric/src/main/resources/fabric.mod.json @@ -14,6 +14,11 @@ }, "license": "LGPL-3.0-only", "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.config.fabric.KessokuConfigFabric" + ] + }, "environment": "*", "depends": { "fabricloader": ">=0.16.0", diff --git a/config/neo/build.gradle b/config/neo/build.gradle index 9d20d28d..43b731f9 100644 --- a/config/neo/build.gradle +++ b/config/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.config" base.archivesName = rootProject.name + "-config" kessoku { diff --git a/config/neo/src/main/java/band/kessoku/lib/impl/config/neoforge/KessokuConfigNeoforge.java b/config/neo/src/main/java/band/kessoku/lib/impl/config/neoforge/KessokuConfigNeoforge.java new file mode 100644 index 00000000..7c5043d1 --- /dev/null +++ b/config/neo/src/main/java/band/kessoku/lib/impl/config/neoforge/KessokuConfigNeoforge.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.config.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.config.KessokuConfig; + +import net.neoforged.fml.common.Mod; + +@Mod(KessokuConfig.MOD_ID) +public final class KessokuConfigNeoforge { + public KessokuConfigNeoforge() { + KessokuLib.loadModule(KessokuConfig.class); + } +} diff --git a/data/common/build.gradle b/data/common/build.gradle index 195048bd..0a242833 100644 --- a/data/common/build.gradle +++ b/data/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.data" base.archivesName = rootProject.name + "-data" kessoku { diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/Data.java b/data/common/src/main/java/band/kessoku/lib/api/data/Data.java new file mode 100644 index 00000000..adbd1ab2 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/api/data/Data.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.data; + +import org.jetbrains.annotations.NotNull; + +/** + * A fundamental part for Kessoku Lib to hold data. + *

+ * This data is only readable in most cases, and it can be considered immutable. + *

+ * @param The type of data. + */ +public interface Data { + /** + * @return The value. + */ + T get(); + + /** + * @return The id using to distinguish data. + */ + @NotNull + String id(); +} diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java b/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java new file mode 100644 index 00000000..24922dad --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/api/data/DataStructure.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.data; + +/** + * This is an interface used to abstract a structure holding some data and implement processing logic. + *

+ * When building structure, data must be member variable and {@link DataStructure#integrate(Data) "integrate()"} + * can be used to hold data for other usages. + *

+ */ +public interface DataStructure { + > K integrate(K data); + K integrate(K dataStructure); +} diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEvents.java b/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java similarity index 78% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEvents.java rename to data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java index da912290..23357e84 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEvents.java +++ b/data/common/src/main/java/band/kessoku/lib/api/data/KessokuData.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity; +package band.kessoku.lib.api.data; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuEntityEvents { - public static final String MOD_ID = "kessoku_entity_events"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuEntityEvents]"); +public final class KessokuData { + public static final String MOD_ID = "kessoku_data"; + public static final String NAME = "Kessoku Data API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME +"]"); } diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java b/data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java new file mode 100644 index 00000000..81972ec8 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/api/data/MutableData.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.data; + +/** + * A fundamental part for Kessoku Lib to hold data. + *

+ * This data is mutable. + *

+ * @param The type of data. + */ +public interface MutableData extends Data { + void set(T newValue); +} diff --git a/data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java b/data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java new file mode 100644 index 00000000..70f188ca --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/api/data/NBTSerializable.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.data; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +/** + * An interface used to normalize serialization of {@link NbtCompound NBT}. + */ +public interface NBTSerializable { + void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); + void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); +} diff --git a/data/common/src/main/java/band/kessoku/lib/data/KessokuData.java b/data/common/src/main/java/band/kessoku/lib/data/KessokuData.java deleted file mode 100644 index 2560f1be..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/KessokuData.java +++ /dev/null @@ -1,9 +0,0 @@ -package band.kessoku.lib.data; - -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -public final class KessokuData { - public static final String MOD_ID = "kessoku_data"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuData]"); -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/api/Data.java b/data/common/src/main/java/band/kessoku/lib/data/api/Data.java deleted file mode 100644 index 4ee5abd3..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/api/Data.java +++ /dev/null @@ -1,23 +0,0 @@ -package band.kessoku.lib.data.api; - -import org.jetbrains.annotations.NotNull; - -/** - * A fundamental part for Kessoku Lib to hold data. - *

- * This data is only readable in most cases, and it can be considered immutable. - *

- * @param The type of data. - */ -public interface Data { - /** - * @return The value. - */ - T get(); - - /** - * @return The id using to distinguish data. - */ - @NotNull - String id(); -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/api/DataStructure.java b/data/common/src/main/java/band/kessoku/lib/data/api/DataStructure.java deleted file mode 100644 index 0778f2ba..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/api/DataStructure.java +++ /dev/null @@ -1,13 +0,0 @@ -package band.kessoku.lib.data.api; - -/** - * This is an interface used to abstract a structure holding some data and implement processing logic. - *

- * When building structure, data must be member variable and {@link DataStructure#integrate(Data) "integrate()"} - * can be used to hold data for other usages. - *

- */ -public interface DataStructure { - > K integrate(K data); - K integrate(K dataStructure); -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/api/MutableData.java b/data/common/src/main/java/band/kessoku/lib/data/api/MutableData.java deleted file mode 100644 index 403e1239..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/api/MutableData.java +++ /dev/null @@ -1,12 +0,0 @@ -package band.kessoku.lib.data.api; - -/** - * A fundamental part for Kessoku Lib to hold data. - *

- * This data is mutable. - *

- * @param The type of data. - */ -public interface MutableData extends Data { - void set(T newValue); -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/api/NBTSerializable.java b/data/common/src/main/java/band/kessoku/lib/data/api/NBTSerializable.java deleted file mode 100644 index 1fd4a088..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/api/NBTSerializable.java +++ /dev/null @@ -1,12 +0,0 @@ -package band.kessoku.lib.data.api; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -/** - * An interface used to normalize serialization of {@link NbtCompound NBT}. - */ -public interface NBTSerializable { - void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); - void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries); -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ByteData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/ByteData.java deleted file mode 100644 index 35b9c1ae..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ByteData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class ByteData extends BaseData implements NBTSerializable { - private ByteData(String id, byte defaultValue) { - super(id, defaultValue); - } - - public static ByteData create(String id, byte defaultValue) { - return new ByteData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putByte(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getByte(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/DoubleData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/DoubleData.java deleted file mode 100644 index 67e5182f..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/DoubleData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class DoubleData extends BaseData implements NBTSerializable { - private DoubleData(String id, double defaultValue) { - super(id, defaultValue); - } - - public static DoubleData create(String id, double defaultValue) { - return new DoubleData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putDouble(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getDouble(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/FloatData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/FloatData.java deleted file mode 100644 index f9ec9abd..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/FloatData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class FloatData extends BaseData implements NBTSerializable { - private FloatData(String id, float defaultValue) { - super(id, defaultValue); - } - - public static FloatData create(String id, float defaultValue) { - return new FloatData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putFloat(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getFloat(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/IntData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/IntData.java deleted file mode 100644 index 0abe3863..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/IntData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class IntData extends BaseData implements NBTSerializable { - private IntData(String id, int defaultValue) { - super(id, defaultValue); - } - - public static IntData create(String id, int defaultValue) { - return new IntData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putInt(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getInt(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/LongData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/LongData.java deleted file mode 100644 index be3d6026..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/LongData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class LongData extends BaseData implements NBTSerializable { - private LongData(String id, long defaultValue) { - super(id, defaultValue); - } - - public static LongData create(String id, long defaultValue) { - return new LongData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putLong(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getLong(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ShortData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/ShortData.java deleted file mode 100644 index 66df58a3..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ShortData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class ShortData extends BaseData implements NBTSerializable { - private ShortData(String id, short defaultValue) { - super(id, defaultValue); - } - - public static ShortData create(String id, short defaultValue) { - return new ShortData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putShort(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getShort(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/StringData.java b/data/common/src/main/java/band/kessoku/lib/data/impl/base/StringData.java deleted file mode 100644 index 2c5ba6a8..00000000 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/StringData.java +++ /dev/null @@ -1,26 +0,0 @@ -package band.kessoku.lib.data.impl.base; - -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.RegistryWrapper; - -public final class StringData extends BaseData implements NBTSerializable { - private StringData(String id, String defaultValue) { - super(id, defaultValue); - } - - public static StringData create(String id, String defaultValue) { - return new StringData(id, defaultValue); - } - - @Override - public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - nbt.putString(id(), get()); - } - - @Override - public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { - set(nbt.getString(id())); - } -} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/BaseData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java similarity index 55% rename from data/common/src/main/java/band/kessoku/lib/data/impl/BaseData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java index 2b1b3bd1..9db0f77a 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/BaseData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/BaseData.java @@ -1,10 +1,25 @@ -package band.kessoku.lib.data.impl; - -import band.kessoku.lib.data.api.MutableData; -import org.jetbrains.annotations.NotNull; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data; import java.util.Objects; +import band.kessoku.lib.api.data.MutableData; +import org.jetbrains.annotations.NotNull; + public class BaseData implements MutableData { private final String id; private T value; diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java new file mode 100644 index 00000000..830390d9 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ByteData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class ByteData extends BaseData implements NBTSerializable { + private ByteData(String id, byte defaultValue) { + super(id, defaultValue); + } + + public static ByteData create(String id, byte defaultValue) { + return new ByteData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putByte(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getByte(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java new file mode 100644 index 00000000..d8091a44 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/DoubleData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class DoubleData extends BaseData implements NBTSerializable { + private DoubleData(String id, double defaultValue) { + super(id, defaultValue); + } + + public static DoubleData create(String id, double defaultValue) { + return new DoubleData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putDouble(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getDouble(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java new file mode 100644 index 00000000..ca2d4afb --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/FloatData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class FloatData extends BaseData implements NBTSerializable { + private FloatData(String id, float defaultValue) { + super(id, defaultValue); + } + + public static FloatData create(String id, float defaultValue) { + return new FloatData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putFloat(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getFloat(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/IdentifierData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java similarity index 50% rename from data/common/src/main/java/band/kessoku/lib/data/impl/base/IdentifierData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java index c2d8eb62..25b3fe22 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/IdentifierData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IdentifierData.java @@ -1,7 +1,23 @@ -package band.kessoku.lib.data.impl.base; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.RegistryWrapper; import net.minecraft.util.Identifier; diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java new file mode 100644 index 00000000..1866e19f --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/IntData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class IntData extends BaseData implements NBTSerializable { + private IntData(String id, int defaultValue) { + super(id, defaultValue); + } + + public static IntData create(String id, int defaultValue) { + return new IntData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putInt(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getInt(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ItemStackData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java similarity index 55% rename from data/common/src/main/java/band/kessoku/lib/data/impl/base/ItemStackData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java index 12853e5f..b0063f13 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/ItemStackData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ItemStackData.java @@ -1,7 +1,23 @@ -package band.kessoku.lib.data.impl.base; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.RegistryWrapper; diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java new file mode 100644 index 00000000..b812f75e --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/LongData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class LongData extends BaseData implements NBTSerializable { + private LongData(String id, long defaultValue) { + super(id, defaultValue); + } + + public static LongData create(String id, long defaultValue) { + return new LongData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putLong(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getLong(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java new file mode 100644 index 00000000..f294eb87 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/ShortData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class ShortData extends BaseData implements NBTSerializable { + private ShortData(String id, short defaultValue) { + super(id, defaultValue); + } + + public static ShortData create(String id, short defaultValue) { + return new ShortData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putShort(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getShort(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java new file mode 100644 index 00000000..31ea8d75 --- /dev/null +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/StringData.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; + +import net.minecraft.nbt.NbtCompound; +import net.minecraft.registry.RegistryWrapper; + +public final class StringData extends BaseData implements NBTSerializable { + private StringData(String id, String defaultValue) { + super(id, defaultValue); + } + + public static StringData create(String id, String defaultValue) { + return new StringData(id, defaultValue); + } + + @Override + public void write(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + nbt.putString(id(), get()); + } + + @Override + public void read(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { + set(nbt.getString(id())); + } +} diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/base/TextData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java similarity index 55% rename from data/common/src/main/java/band/kessoku/lib/data/impl/base/TextData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java index 33c17d1c..39bcd0b4 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/base/TextData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/base/TextData.java @@ -1,13 +1,29 @@ -package band.kessoku.lib.data.impl.base; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.base; + +import static net.minecraft.block.entity.BlockEntity.tryParseCustomName; + +import band.kessoku.lib.api.data.NBTSerializable; +import band.kessoku.lib.impl.data.BaseData; -import band.kessoku.lib.data.api.NBTSerializable; -import band.kessoku.lib.data.impl.BaseData; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.RegistryWrapper; import net.minecraft.text.Text; -import static net.minecraft.block.entity.BlockEntity.tryParseCustomName; - public final class TextData extends BaseData implements NBTSerializable { private TextData(String id, Text defaultValue) { super(id, defaultValue); diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/collection/DefaultedListData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java similarity index 67% rename from data/common/src/main/java/band/kessoku/lib/data/impl/collection/DefaultedListData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java index 52a92ecc..8bdd3086 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/collection/DefaultedListData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/DefaultedListData.java @@ -1,10 +1,25 @@ -package band.kessoku.lib.data.impl.collection; - -import org.jetbrains.annotations.NotNull; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.collection; import java.util.Collections; import java.util.ListIterator; +import org.jetbrains.annotations.NotNull; + public final class DefaultedListData extends ListData { private final @NotNull T defaultValue; diff --git a/data/common/src/main/java/band/kessoku/lib/data/impl/collection/ListData.java b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java similarity index 57% rename from data/common/src/main/java/band/kessoku/lib/data/impl/collection/ListData.java rename to data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java index ace76738..5481cf9b 100644 --- a/data/common/src/main/java/band/kessoku/lib/data/impl/collection/ListData.java +++ b/data/common/src/main/java/band/kessoku/lib/impl/data/collection/ListData.java @@ -1,12 +1,27 @@ -package band.kessoku.lib.data.impl.collection; - -import band.kessoku.lib.data.api.Data; -import org.jetbrains.annotations.NotNull; +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.collection; import java.util.AbstractList; import java.util.ArrayList; import java.util.List; +import band.kessoku.lib.api.data.Data; +import org.jetbrains.annotations.NotNull; + public class ListData extends AbstractList implements Data> { private final List list = new ArrayList<>(); private final String id; diff --git a/data/common/src/main/resources/kessoku-data-common.mixins.json b/data/common/src/main/resources/kessoku_data.mixins.json similarity index 70% rename from data/common/src/main/resources/kessoku-data-common.mixins.json rename to data/common/src/main/resources/kessoku_data.mixins.json index 42a84e7e..77d01231 100644 --- a/data/common/src/main/resources/kessoku-data-common.mixins.json +++ b/data/common/src/main/resources/kessoku_data.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.data.mixin", + "package": "band.kessoku.lib.mixin.data", "compatibilityLevel": "JAVA_21", "injectors": { "defaultRequire": 1 diff --git a/data/fabric/build.gradle b/data/fabric/build.gradle index 8346122d..fa7b41f8 100644 --- a/data/fabric/build.gradle +++ b/data/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.data" base.archivesName = rootProject.name + "-data" kessoku { diff --git a/data/fabric/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java b/data/fabric/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java deleted file mode 100644 index b0eb48f2..00000000 --- a/data/fabric/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java +++ /dev/null @@ -1,11 +0,0 @@ -package band.kessoku.lib.data; - -import band.kessoku.lib.base.ModUtils; -import net.fabricmc.api.ModInitializer; - -public class KessokuDataEntrypoint implements ModInitializer { - @Override - public void onInitialize() { - ModUtils.getLogger().info(KessokuData.MARKER, "KessokuLib-BlockEntity is Loaded!"); - } -} diff --git a/base/fabric/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java b/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java similarity index 74% rename from base/fabric/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java rename to data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java index dffce6a0..443bd49a 100644 --- a/base/fabric/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java +++ b/data/fabric/src/main/java/band/kessoku/lib/impl/data/fabric/KessokuDataFabric.java @@ -13,13 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.base; +package band.kessoku.lib.impl.data.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.data.KessokuData; import net.fabricmc.api.ModInitializer; -public class KessokuBaseEntrypoint implements ModInitializer { +public final class KessokuDataFabric implements ModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuBase.MARKER, "KessokuLib-Base is loaded!"); + KessokuLib.loadModule(KessokuData.class); } } diff --git a/data/fabric/src/main/resources/fabric.mod.json b/data/fabric/src/main/resources/fabric.mod.json index 4202d5b4..cfd842bd 100644 --- a/data/fabric/src/main/resources/fabric.mod.json +++ b/data/fabric/src/main/resources/fabric.mod.json @@ -14,6 +14,11 @@ }, "license": "LGPL-3.0-only", "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.data.fabric.KessokuDataFabric" + ] + }, "environment": "*", "depends": { "fabricloader": ">=0.16.0", @@ -22,7 +27,7 @@ "fabric-api": "*" }, "mixins": [ - "kessoku-data-fabric.mixins.json" + "kessoku_data.mixins.json" ], "custom": { "modmenu": { diff --git a/data/neo/build.gradle b/data/neo/build.gradle index 285e9016..ac472948 100644 --- a/data/neo/build.gradle +++ b/data/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.data" base.archivesName = rootProject.name + "-data" kessoku { diff --git a/data/neo/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java b/data/neo/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java deleted file mode 100644 index d6558b67..00000000 --- a/data/neo/src/main/java/band/kessoku/lib/data/KessokuDataEntrypoint.java +++ /dev/null @@ -1,12 +0,0 @@ -package band.kessoku.lib.data; - -import band.kessoku.lib.base.ModUtils; -import net.neoforged.bus.api.IEventBus; -import net.neoforged.fml.common.Mod; - -@Mod(KessokuData.MOD_ID) -public class KessokuDataEntrypoint { - public KessokuDataEntrypoint(IEventBus modEventBus) { - ModUtils.getLogger().info(KessokuData.MARKER, "KessokuLib-BlockEntity is Loaded!"); - } -} diff --git a/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java b/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java new file mode 100644 index 00000000..c37265be --- /dev/null +++ b/data/neo/src/main/java/band/kessoku/lib/impl/data/neoforge/KessokuDataNeoforge.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.data.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.data.KessokuData; + +import net.neoforged.fml.common.Mod; + +@Mod(KessokuData.MOD_ID) +public final class KessokuDataNeoforge { + public KessokuDataNeoforge() { + KessokuLib.loadModule(KessokuData.class); + } +} diff --git a/data/neo/src/main/resources/META-INF/neoforge.mods.toml b/data/neo/src/main/resources/META-INF/neoforge.mods.toml index 51fd411f..e8ae709b 100644 --- a/data/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/data/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -26,4 +26,7 @@ modId = "minecraft" type = "required" versionRange = "[1.21,)" ordering = "NONE" -side = "BOTH" \ No newline at end of file +side = "BOTH" + +[[mixins]] +config="kessoku_data.mixins.json" \ No newline at end of file diff --git a/entity-events/common/build.gradle b/entity-events/common/build.gradle index 44e97fa1..f9299802 100644 --- a/entity-events/common/build.gradle +++ b/entity-events/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.events.entity" base.archivesName = rootProject.name + "-entity-events" kessoku { diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntityElytraEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntityElytraEvent.java similarity index 80% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntityElytraEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntityElytraEvent.java index b0e8eecc..86473085 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntityElytraEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntityElytraEvent.java @@ -13,25 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package band.kessoku.lib.api.event.entity; -package band.kessoku.lib.events.entity.api; - +import band.kessoku.lib.api.event.entity.item.KessokuElytraItem; import band.kessoku.lib.event.api.Event; -import band.kessoku.lib.events.entity.api.item.KessokuElytraItem; -import net.minecraft.entity.EquipmentSlot; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; /** * Events related to elytra flight for living entities. Elytra flight is also known as "fall flying". */ -public class EntityElytraEvent { +@ApiStatus.NonExtendable +public interface EntityElytraEvent { /** * An event to check if elytra flight (both through normal and custom elytras) is allowed. * All listeners need to return true to allow the entity to fly, otherwise elytra flight will be blocked/stopped. */ - public static final Event ALLOW = Event.of(listeners -> entity -> { + Event ALLOW = Event.of(listeners -> entity -> { for (Allow listener : listeners) { if (!listener.allowElytraFlight(entity)) { return false; @@ -47,7 +47,7 @@ public class EntityElytraEvent { * *

Items that wish to enable custom elytra flight when worn in the chest equipment slot can simply implement {@link KessokuElytraItem} instead of registering a listener. */ - public static final Event CUSTOM = Event.of(listeners -> (entity, tickElytra) -> { + Event CUSTOM = Event.of(listeners -> (entity, tickElytra) -> { for (Custom listener : listeners) { if (listener.useCustomElytra(entity, tickElytra)) { return true; @@ -57,20 +57,8 @@ public class EntityElytraEvent { return false; }); - static { - CUSTOM.register((entity, tickElytra) -> { - ItemStack chestStack = entity.getEquippedStack(EquipmentSlot.CHEST); - - if (chestStack.getItem() instanceof KessokuElytraItem fabricElytraItem) { - return fabricElytraItem.useCustomElytra(entity, chestStack, tickElytra); - } - - return false; - }); - } - @FunctionalInterface - public interface Allow { + interface Allow { /** * @return false to block elytra flight, true to allow it (unless another listener returns false) */ @@ -78,7 +66,7 @@ public interface Allow { } @FunctionalInterface - public interface Custom { + interface Custom { /** * Try to use a custom elytra for an entity. * A custom elytra is anything that allows an entity to enter and continue elytra flight when some condition is met. @@ -104,8 +92,4 @@ public interface Custom { */ boolean useCustomElytra(LivingEntity entity, boolean tickElytra); } - - private EntityElytraEvent() { - } - } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntitySleepEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntitySleepEvent.java similarity index 86% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntitySleepEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntitySleepEvent.java index 0c361fc8..b6456327 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/EntitySleepEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/EntitySleepEvent.java @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.api; +package band.kessoku.lib.api.event.entity; import band.kessoku.lib.event.api.Event; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + import net.minecraft.block.BlockState; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -23,7 +26,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; -import org.jetbrains.annotations.Nullable; /** @@ -44,7 +46,8 @@ * Custom beds generally only need a custom {@link #ALLOW_BED} checker and a {@link #MODIFY_SLEEPING_DIRECTION} callback, * but the other events might be useful as well. */ -public class EntitySleepEvent { +@ApiStatus.NonExtendable +public interface EntitySleepEvent { /** * An event that checks whether a player can start to sleep in a bed-like block. * This event only applies to sleeping using {@link PlayerEntity#trySleep(BlockPos)}. @@ -60,7 +63,7 @@ public class EntitySleepEvent { * is used in addition to vanilla checks. The more detailed events {@link #ALLOW_SLEEP_TIME} and {@link #ALLOW_NEARBY_MONSTERS} * are also checked before this event. */ - public static final Event ALLOW_SLEEPING = Event.of(callbacks -> (player, sleepingPos) -> { + Event ALLOW_SLEEPING = Event.of(callbacks -> (player, sleepingPos) -> { for (AllowSleeping callback : callbacks) { PlayerEntity.SleepFailureReason reason = callback.allowSleep(player, sleepingPos); @@ -75,7 +78,7 @@ public class EntitySleepEvent { /** * An event that is called when an entity starts to sleep. */ - public static final Event START_SLEEPING = Event.of(callbacks -> (entity, sleepingPos) -> { + Event START_SLEEPING = Event.of(callbacks -> (entity, sleepingPos) -> { for (StartSleeping callback : callbacks) { callback.onStartSleeping(entity, sleepingPos); } @@ -84,7 +87,7 @@ public class EntitySleepEvent { /** * An event that is called when an entity stops sleeping and wakes up. */ - public static final Event STOP_SLEEPING = Event.of(callbacks -> (entity, sleepingPos) -> { + Event STOP_SLEEPING = Event.of(callbacks -> (entity, sleepingPos) -> { for (StopSleeping callback : callbacks) { callback.onStopSleeping(entity, sleepingPos); } @@ -102,7 +105,7 @@ public class EntitySleepEvent { * * @see LivingEntity#isSleepingInBed() */ - public static final Event ALLOW_BED = Event.of(callbacks -> (entity, sleepingPos, state, vanillaResult) -> { + Event ALLOW_BED = Event.of(callbacks -> (entity, sleepingPos, state, vanillaResult) -> { for (AllowBed callback : callbacks) { ActionResult result = callback.allowBed(entity, sleepingPos, state, vanillaResult); @@ -120,7 +123,7 @@ public class EntitySleepEvent { *

Note that if sleeping during day time is allowed, the game will still reset the time to 0 if the usual * conditions are met, unless forbidden with {@link #ALLOW_RESETTING_TIME}. */ - public static final Event ALLOW_SLEEP_TIME = Event.of(callbacks -> (player, sleepingPos, vanillaResult) -> { + Event ALLOW_SLEEP_TIME = Event.of(callbacks -> (player, sleepingPos, vanillaResult) -> { for (AllowSleepTime callback : callbacks) { ActionResult result = callback.allowSleepTime(player, sleepingPos, vanillaResult); @@ -137,7 +140,7 @@ public class EntitySleepEvent { * *

This event can also be used to force a failing result, meaning it can do custom monster checks. */ - public static final Event ALLOW_NEARBY_MONSTERS = Event.of(callbacks -> (player, sleepingPos, vanillaResult) -> { + Event ALLOW_NEARBY_MONSTERS = Event.of(callbacks -> (player, sleepingPos, vanillaResult) -> { for (AllowNearbyMonsters callback : callbacks) { ActionResult result = callback.allowNearbyMonsters(player, sleepingPos, vanillaResult); @@ -155,7 +158,7 @@ public class EntitySleepEvent { *

When this event is called, all vanilla time resetting checks have already succeeded, i.e. this event * is used in addition to vanilla checks. */ - public static final Event ALLOW_RESETTING_TIME = Event.of(callbacks -> player -> { + Event ALLOW_RESETTING_TIME = Event.of(callbacks -> player -> { for (AllowResettingTime callback : callbacks) { if (!callback.allowResettingTime(player)) { return false; @@ -172,7 +175,7 @@ public class EntitySleepEvent { * If the block is not a {@link net.minecraft.block.BedBlock}, you need to provide the sleeping direction manually * with this event. */ - public static final Event MODIFY_SLEEPING_DIRECTION = Event.of(callbacks -> (entity, sleepingPos, sleepingDirection) -> { + Event MODIFY_SLEEPING_DIRECTION = Event.of(callbacks -> (entity, sleepingPos, sleepingDirection) -> { for (ModifySleepingDirection callback : callbacks) { sleepingDirection = callback.modifySleepDirection(entity, sleepingPos, sleepingDirection); } @@ -185,7 +188,7 @@ public class EntitySleepEvent { * *

Vanilla always allows this operation. */ - public static final Event ALLOW_SETTING_SPAWN = Event.of(callbacks -> (player, sleepingPos) -> { + Event ALLOW_SETTING_SPAWN = Event.of(callbacks -> (player, sleepingPos) -> { for (AllowSettingSpawn callback : callbacks) { if (!callback.allowSettingSpawn(player, sleepingPos)) { return false; @@ -201,7 +204,7 @@ public class EntitySleepEvent { *

Note that this is not needed for blocks using {@link net.minecraft.block.BedBlock}, * which are handled automatically. */ - public static final Event SET_BED_OCCUPATION_STATE = Event.of(callbacks -> (entity, sleepingPos, bedState, occupied) -> { + Event SET_BED_OCCUPATION_STATE = Event.of(callbacks -> (entity, sleepingPos, bedState, occupied) -> { for (SetBedOccupationState callback : callbacks) { if (callback.setBedOccupationState(entity, sleepingPos, bedState, occupied)) { return true; @@ -218,7 +221,7 @@ public class EntitySleepEvent { * If the block is not a {@link net.minecraft.block.BedBlock}, you need to provide the wake-up position manually * with this event. */ - public static final Event MODIFY_WAKE_UP_POSITION = Event.of(callbacks -> (entity, sleepingPos, bedState, wakeUpPos) -> { + Event MODIFY_WAKE_UP_POSITION = Event.of(callbacks -> (entity, sleepingPos, bedState, wakeUpPos) -> { for (ModifyWakeUpPosition callback : callbacks) { wakeUpPos = callback.modifyWakeUpPosition(entity, sleepingPos, bedState, wakeUpPos); } @@ -227,7 +230,7 @@ public class EntitySleepEvent { }); @FunctionalInterface - public interface AllowSleeping { + interface AllowSleeping { /** * Checks whether a player can start sleeping in a bed-like block. * @@ -241,7 +244,7 @@ public interface AllowSleeping { } @FunctionalInterface - public interface StartSleeping { + interface StartSleeping { /** * Called when an entity starts to sleep. * @@ -252,7 +255,7 @@ public interface StartSleeping { } @FunctionalInterface - public interface StopSleeping { + interface StopSleeping { /** * Called when an entity stops sleeping and wakes up. * @@ -263,7 +266,7 @@ public interface StopSleeping { } @FunctionalInterface - public interface AllowBed { + interface AllowBed { /** * Checks whether a block is a valid bed for the entity. * @@ -274,13 +277,13 @@ public interface AllowBed { * @param state the block state to check * @param vanillaResult {@code true} if vanilla allows the block, {@code false} otherwise * @return {@link ActionResult#SUCCESS} if the bed is valid, {@link ActionResult#FAIL} if it's not, - * {@link ActionResult#PASS} to fall back to other callbacks + * {@link ActionResult#PASS} to fall back to other callbacks */ ActionResult allowBed(LivingEntity entity, BlockPos sleepingPos, BlockState state, boolean vanillaResult); } @FunctionalInterface - public interface AllowSleepTime { + interface AllowSleepTime { /** * Checks whether the current time of day is valid for sleeping. * @@ -290,13 +293,13 @@ public interface AllowSleepTime { * @param sleepingPos the (possibly still unset) {@linkplain LivingEntity#getSleepingPosition() sleeping position} of the player * @param vanillaResult {@code true} if vanilla allows the time, {@code false} otherwise * @return {@link ActionResult#SUCCESS} if the time is valid, {@link ActionResult#FAIL} if it's not, - * {@link ActionResult#PASS} to fall back to other callbacks + * {@link ActionResult#PASS} to fall back to other callbacks */ ActionResult allowSleepTime(PlayerEntity player, BlockPos sleepingPos, boolean vanillaResult); } @FunctionalInterface - public interface AllowNearbyMonsters { + interface AllowNearbyMonsters { /** * Checks whether a player can sleep when monsters are nearby. * @@ -306,24 +309,24 @@ public interface AllowNearbyMonsters { * @param sleepingPos the (possibly still unset) {@linkplain LivingEntity#getSleepingPosition() sleeping position} of the player * @param vanillaResult {@code true} if vanilla's monster check succeeded (there were no monsters), {@code false} otherwise * @return {@link ActionResult#SUCCESS} to allow sleeping, {@link ActionResult#FAIL} to prevent sleeping, - * {@link ActionResult#PASS} to fall back to other callbacks + * {@link ActionResult#PASS} to fall back to other callbacks */ ActionResult allowNearbyMonsters(PlayerEntity player, BlockPos sleepingPos, boolean vanillaResult); } @FunctionalInterface - public interface AllowResettingTime { + interface AllowResettingTime { /** * Checks whether a sleeping player counts into skipping the current day and resetting the time to 0. * - * @param player the sleeping player + * @param player the sleeping player * @return {@code true} if allowed, {@code false} otherwise */ boolean allowResettingTime(PlayerEntity player); } @FunctionalInterface - public interface ModifySleepingDirection { + interface ModifySleepingDirection { /** * Modifies or provides a sleeping direction for a block. * The sleeping direction is where a player's head is pointing when they're sleeping. @@ -338,7 +341,7 @@ public interface ModifySleepingDirection { } @FunctionalInterface - public interface AllowSettingSpawn { + interface AllowSettingSpawn { /** * Checks whether a player's spawn can be set when sleeping. * @@ -350,7 +353,7 @@ public interface AllowSettingSpawn { } @FunctionalInterface - public interface SetBedOccupationState { + interface SetBedOccupationState { /** * Sets the occupation state of a bed block. * @@ -364,7 +367,7 @@ public interface SetBedOccupationState { } @FunctionalInterface - public interface ModifyWakeUpPosition { + interface ModifyWakeUpPosition { /** * Modifies or provides a wake-up position for an entity waking up. * @@ -377,6 +380,4 @@ public interface ModifyWakeUpPosition { @Nullable Vec3d modifyWakeUpPosition(LivingEntity entity, BlockPos sleepingPos, BlockState bedState, @Nullable Vec3d wakeUpPos); } - - private EntitySleepEvent() {} } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/KessokuEntityEvents.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/KessokuEntityEvents.java new file mode 100644 index 00000000..1c80bc4d --- /dev/null +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/KessokuEntityEvents.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.event.entity; + +import band.kessoku.lib.api.event.entity.item.KessokuElytraItem; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.item.ItemStack; + +public final class KessokuEntityEvents { + public static final String MOD_ID = "kessoku_entity_events"; + public static final String NAME = "Kessoku Entity Events API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); + + static { + EntityElytraEvent.CUSTOM.register((entity, tickElytra) -> { + ItemStack chestStack = entity.getEquippedStack(EquipmentSlot.CHEST); + + if (chestStack.getItem() instanceof KessokuElytraItem fabricElytraItem) { + return fabricElytraItem.useCustomElytra(entity, chestStack, tickElytra); + } + + return false; + }); + } +} diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityCombatEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityCombatEvent.java similarity index 83% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityCombatEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityCombatEvent.java index 136a5016..7dbd04a1 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityCombatEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityCombatEvent.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.api; +package band.kessoku.lib.api.event.entity; import band.kessoku.lib.event.api.Event; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.server.world.ServerWorld; @@ -23,20 +25,21 @@ /** * Events related to entities in combat. */ -public class ServerEntityCombatEvent { +@ApiStatus.NonExtendable +public interface ServerEntityCombatEvent { /** * An event that is called after an entity is directly responsible for killing another entity. * * @see Entity#onKilledOther(ServerWorld, LivingEntity) */ - public static final Event AFTER_KILLED_OTHER_ENTITY = Event.of(callbacks -> (world, entity, killedEntity) -> { + Event AFTER_KILLED_OTHER_ENTITY = Event.of(callbacks -> (world, entity, killedEntity) -> { for (AfterKilledOtherEntity callback : callbacks) { callback.afterKilledOtherEntity(world, entity, killedEntity); } }); @FunctionalInterface - public interface AfterKilledOtherEntity { + interface AfterKilledOtherEntity { /** * Called after an entity has killed another entity. * @@ -46,7 +49,4 @@ public interface AfterKilledOtherEntity { */ void afterKilledOtherEntity(ServerWorld world, Entity entity, LivingEntity killedEntity); } - - private ServerEntityCombatEvent() { - } } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityWorldChangeEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityWorldChangeEvent.java similarity index 79% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityWorldChangeEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityWorldChangeEvent.java index 1208e598..a4bcba97 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerEntityWorldChangeEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerEntityWorldChangeEvent.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.api; +package band.kessoku.lib.api.event.entity; import band.kessoku.lib.event.api.Event; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.entity.Entity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -25,7 +27,8 @@ * * @apiNote For a {@link ServerPlayerEntity}, please use {@link ServerEntityWorldChangeEvent#AFTER_PLAYER_CHANGE_WORLD}. */ -public class ServerEntityWorldChangeEvent { +@ApiStatus.NonExtendable +public interface ServerEntityWorldChangeEvent { /** * An event which is called after an entity has been moved to a different world. * @@ -36,7 +39,7 @@ public class ServerEntityWorldChangeEvent { * * @see ServerEntityWorldChangeEvent#AFTER_PLAYER_CHANGE_WORLD */ - public static final Event AFTER_ENTITY_CHANGE_WORLD = Event.of(callbacks -> (originalEntity, newEntity, origin, destination) -> { + Event AFTER_ENTITY_CHANGE_WORLD = Event.of(callbacks -> (originalEntity, newEntity, origin, destination) -> { for (AfterEntityChange callback : callbacks) { callback.afterChangeWorld(originalEntity, newEntity, origin, destination); } @@ -50,14 +53,14 @@ public class ServerEntityWorldChangeEvent { * * @see ServerEntityWorldChangeEvent#AFTER_ENTITY_CHANGE_WORLD */ - public static final Event AFTER_PLAYER_CHANGE_WORLD = Event.of(callbacks -> (player, origin, destination) -> { + Event AFTER_PLAYER_CHANGE_WORLD = Event.of(callbacks -> (player, origin, destination) -> { for (AfterPlayerChange callback : callbacks) { callback.afterChangeWorld(player, origin, destination); } }); @FunctionalInterface - public interface AfterEntityChange { + interface AfterEntityChange { /** * Called after an entity has been recreated at the destination when being moved to a different world. * @@ -65,25 +68,22 @@ public interface AfterEntityChange { * {@link AfterPlayerChange} should be used to track when a player has changed worlds. * * @param originalEntity the original entity - * @param newEntity the new entity at the destination - * @param origin the world the original entity is in - * @param destination the destination world the new entity is in + * @param newEntity the new entity at the destination + * @param origin the world the original entity is in + * @param destination the destination world the new entity is in */ void afterChangeWorld(Entity originalEntity, Entity newEntity, ServerWorld origin, ServerWorld destination); } @FunctionalInterface - public interface AfterPlayerChange { + interface AfterPlayerChange { /** * Called after a player has been moved to different world. * - * @param player the player - * @param origin the original world the player was in + * @param player the player + * @param origin the original world the player was in * @param destination the new world the player was moved to */ void afterChangeWorld(ServerPlayerEntity player, ServerWorld origin, ServerWorld destination); } - - private ServerEntityWorldChangeEvent() { - } } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerLivingEntityEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerLivingEntityEvent.java similarity index 81% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerLivingEntityEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerLivingEntityEvent.java index 55a8602f..c7696ab2 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerLivingEntityEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerLivingEntityEvent.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.api; +package band.kessoku.lib.api.event.entity; import band.kessoku.lib.event.api.Event; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.mob.MobEntity; @@ -23,13 +25,14 @@ /** * Various server-side only events related to living entities. */ -public class ServerLivingEntityEvent { +@ApiStatus.NonExtendable +public interface ServerLivingEntityEvent { /** * An event that is called when a living entity is going to take damage. * This is fired from {@link LivingEntity#damage}, before armor or any other mitigation are applied. * Mods can cancel this to prevent the damage entirely. */ - public static final Event ALLOW_DAMAGE = Event.of(callbacks -> (entity, source, amount) -> { + Event ALLOW_DAMAGE = Event.of(callbacks -> (entity, source, amount) -> { for (AllowDamage callback : callbacks) { if (!callback.allowDamage(entity, source, amount)) { return false; @@ -49,7 +52,7 @@ public class ServerLivingEntityEvent { * *

This event is not fired if the entity was killed by the damage. */ - public static final Event AFTER_DAMAGE = Event.of(callbacks -> (entity, source, baseDamageTaken, damageTaken, blocked) -> { + Event AFTER_DAMAGE = Event.of(callbacks -> (entity, source, baseDamageTaken, damageTaken, blocked) -> { for (AfterDamage callback : callbacks) { callback.afterDamage(entity, source, baseDamageTaken, damageTaken, blocked); } @@ -68,7 +71,7 @@ public class ServerLivingEntityEvent { *

  • a mod that changes death mechanics switching the player over to the mod's play-mode, where death doesn't apply
  • * */ - public static final Event ALLOW_DEATH = Event.of(callbacks -> (entity, damageSource, damageAmount) -> { + Event ALLOW_DEATH = Event.of(callbacks -> (entity, damageSource, damageAmount) -> { for (AllowDeath callback : callbacks) { if (!callback.allowDeath(entity, damageSource, damageAmount)) { return false; @@ -81,7 +84,7 @@ public class ServerLivingEntityEvent { /** * An event that is called when a living entity dies. */ - public static final Event AFTER_DEATH = Event.of(callbacks -> (entity, damageSource) -> { + Event AFTER_DEATH = Event.of(callbacks -> (entity, damageSource) -> { for (AfterDeath callback : callbacks) { callback.afterDeath(entity, damageSource); } @@ -96,14 +99,14 @@ public class ServerLivingEntityEvent { *

    This event only handles cases where the entity type changes, requiring a new instance. Notably it does not * cover mooshrooms changing color from lightning, creepers getting charged, or wolves being tamed.

    */ - public static final Event MOB_CONVERSION = Event.of(callbacks -> (previous, converted, keepEquipment) -> { + Event MOB_CONVERSION = Event.of(callbacks -> (previous, converted, keepEquipment) -> { for (MobConversion callback : callbacks) { callback.onConversion(previous, converted, keepEquipment); } }); @FunctionalInterface - public interface AllowDamage { + interface AllowDamage { /** * Called when a living entity is going to take damage. Can be used to cancel the damage entirely. * @@ -118,26 +121,26 @@ public interface AllowDamage { } @FunctionalInterface - public interface AfterDamage { + interface AfterDamage { /** * Called after a living entity took damage, unless they were killed. The base damage taken is given as damage * taken before armor or enchantments are applied, but after other effects like shields are applied. * - * @param entity the entity that was damaged - * @param source the source of the damage + * @param entity the entity that was damaged + * @param source the source of the damage * @param baseDamageTaken the amount of damage initially dealt - * @param damageTaken the amount of damage actually taken by the entity, before armor and enchantment effects - * @param blocked whether the damage was blocked by a shield + * @param damageTaken the amount of damage actually taken by the entity, before armor and enchantment effects + * @param blocked whether the damage was blocked by a shield */ void afterDamage(LivingEntity entity, DamageSource source, float baseDamageTaken, float damageTaken, boolean blocked); } @FunctionalInterface - public interface AllowDeath { + interface AllowDeath { /** * Called when a living entity takes fatal damage (before totems of undying can take effect). * - * @param entity the entity + * @param entity the entity * @param damageSource the source of the fatal damage * @param damageAmount the amount of damage that has killed the entity * @return true if the death should go ahead, false to cancel the death. @@ -146,28 +149,25 @@ public interface AllowDeath { } @FunctionalInterface - public interface AfterDeath { + interface AfterDeath { /** * Called when a living entity dies. The death cannot be canceled at this point. * - * @param entity the entity + * @param entity the entity * @param damageSource the source of the fatal damage */ void afterDeath(LivingEntity entity, DamageSource damageSource); } @FunctionalInterface - public interface MobConversion { + interface MobConversion { /** * Called when a mob is converted to another type. * - * @param previous the previous entity instance - * @param converted the new instance for the converted entity + * @param previous the previous entity instance + * @param converted the new instance for the converted entity * @param keepEquipment whether the converted entity should keep the previous one's equipment, like armor */ void onConversion(MobEntity previous, MobEntity converted, boolean keepEquipment); } - - private ServerLivingEntityEvent() { - } } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerPlayerEvent.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerPlayerEvent.java similarity index 78% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerPlayerEvent.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerPlayerEvent.java index 6a00958f..002db24e 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/ServerPlayerEvent.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/ServerPlayerEvent.java @@ -13,19 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.api; +package band.kessoku.lib.api.event.entity; import band.kessoku.lib.event.api.Event; +import org.jetbrains.annotations.ApiStatus; + import net.minecraft.server.network.ServerPlayerEntity; -public class ServerPlayerEvent { +@ApiStatus.NonExtendable +public interface ServerPlayerEvent { /** * An event that is called when the data from an old player is copied to a new player. * *

    This event is typically called before a player is completely respawned. * Mods may use this event to copy old player data to a new player. */ - public static final Event COPY_FROM = Event.of(callbacks -> (oldPlayer, newPlayer, alive) -> { + Event COPY_FROM = Event.of(callbacks -> (oldPlayer, newPlayer, alive) -> { for (CopyFrom callback : callbacks) { callback.copyFromPlayer(oldPlayer, newPlayer, alive); } @@ -36,36 +39,33 @@ public class ServerPlayerEvent { * *

    Mods may use this event for reference clean up on the old player. */ - public static final Event AFTER_RESPAWN = Event.of(callbacks -> (oldPlayer, newPlayer, alive) -> { + Event AFTER_RESPAWN = Event.of(callbacks -> (oldPlayer, newPlayer, alive) -> { for (AfterRespawn callback : callbacks) { callback.afterRespawn(oldPlayer, newPlayer, alive); } }); @FunctionalInterface - public interface CopyFrom { + interface CopyFrom { /** * Called when player data is copied to a new player. * * @param oldPlayer the old player * @param newPlayer the new player - * @param alive whether the old player is still alive + * @param alive whether the old player is still alive */ void copyFromPlayer(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive); } @FunctionalInterface - public interface AfterRespawn { + interface AfterRespawn { /** * Called after player a has been respawned. * * @param oldPlayer the old player * @param newPlayer the new player - * @param alive whether the old player is still alive + * @param alive whether the old player is still alive */ void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive); } - - private ServerPlayerEvent() { - } } diff --git a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/item/KessokuElytraItem.java b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/item/KessokuElytraItem.java similarity index 97% rename from entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/item/KessokuElytraItem.java rename to entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/item/KessokuElytraItem.java index 70124c43..2f1af087 100644 --- a/entity-events/common/src/main/java/band/kessoku/lib/events/entity/api/item/KessokuElytraItem.java +++ b/entity-events/common/src/main/java/band/kessoku/lib/api/event/entity/item/KessokuElytraItem.java @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package band.kessoku.lib.events.entity.api.item; +package band.kessoku.lib.api.event.entity.item; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; diff --git a/entity-events/fabric/build.gradle b/entity-events/fabric/build.gradle index 67aef1bd..79e11072 100644 --- a/entity-events/fabric/build.gradle +++ b/entity-events/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.events.entity" base.archivesName = rootProject.name + "-entity-events" kessoku { diff --git a/entity-events/fabric/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java b/entity-events/fabric/src/main/java/band/kessoku/lib/impl/events/entity/fabric/KessokuEntityEventsFabric.java similarity index 78% rename from entity-events/fabric/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java rename to entity-events/fabric/src/main/java/band/kessoku/lib/impl/events/entity/fabric/KessokuEntityEventsFabric.java index 9ae2dcc4..d7913413 100644 --- a/entity-events/fabric/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java +++ b/entity-events/fabric/src/main/java/band/kessoku/lib/impl/events/entity/fabric/KessokuEntityEventsFabric.java @@ -13,17 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity; +package band.kessoku.lib.impl.events.entity.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.event.entity.EntityElytraEvent; +import band.kessoku.lib.api.event.entity.EntitySleepEvent; +import band.kessoku.lib.api.event.entity.KessokuEntityEvents; -import band.kessoku.lib.events.entity.api.EntityElytraEvent; -import band.kessoku.lib.events.entity.api.EntitySleepEvent; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.entity.event.v1.EntityElytraEvents; import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; -public class KessokuEntityEventEntrypoint implements ModInitializer { +public final class KessokuEntityEventsFabric implements ModInitializer { @Override public void onInitialize() { + KessokuLib.loadModule(KessokuEntityEvents.class); EntityElytraEvents.ALLOW.register(entity -> EntityElytraEvent.ALLOW.invoker().allowElytraFlight(entity)); EntityElytraEvents.CUSTOM.register((entity, tickElytra) -> EntityElytraEvent.CUSTOM.invoker().useCustomElytra(entity, tickElytra)); diff --git a/entity-events/fabric/src/main/resources/fabric.mod.json b/entity-events/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..e6fab368 --- /dev/null +++ b/entity-events/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "kessoku_entity_events", + "version": "${version}", + "name": "Kessoku Entity Events API", + "description": "Provide some events about entity.", + "authors": [ + "Kessoku Tea Time" + ], + "contact": { + "homepage": "https://modrinth.com/mod/kessoku-lib", + "sources": "https://github.com/KessokuTeaTime/KessokuLib", + "issues": "https://github.com/KessokuTeaTime/KessokuLib/issues" + }, + "license": "LGPL-3.0-only", + "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.events.entity.fabric.KessokuEntityEventsFabric" + ] + }, + "environment": "*", + "depends": { + "fabricloader": ">=0.16.0", + "minecraft": "1.21", + "java": ">=21", + "fabric-api": "*" + }, + "custom": { + "modmenu": { + "badges": [ + "library" + ] + } + } +} \ No newline at end of file diff --git a/entity-events/neo/build.gradle b/entity-events/neo/build.gradle index 4a764e0e..60191b46 100644 --- a/entity-events/neo/build.gradle +++ b/entity-events/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.events.entity" base.archivesName = rootProject.name + "-entity-events" loom { @@ -11,7 +10,7 @@ loom { kessoku { modules(["base", "event-base"], "common") - module("event-base", "neo") + module("base", "neo") common("entity-events", ModPlatform.NEOFORGE) shadowBundle("entity-events", ModPlatform.NEOFORGE) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java b/entity-events/neo/src/main/java/band/kessoku/lib/impl/event/entity/KessokuEntityEventsNeoforge.java similarity index 85% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java rename to entity-events/neo/src/main/java/band/kessoku/lib/impl/event/entity/KessokuEntityEventsNeoforge.java index 1355e9a2..d2edcb68 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/KessokuEntityEventEntrypoint.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/impl/event/entity/KessokuEntityEventsNeoforge.java @@ -13,16 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity; +package band.kessoku.lib.impl.event.entity; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.base.neoforge.NeoEventUtils; +import band.kessoku.lib.api.event.entity.EntitySleepEvent; +import band.kessoku.lib.api.event.entity.KessokuEntityEvents; +import band.kessoku.lib.api.event.entity.ServerLivingEntityEvent; +import band.kessoku.lib.api.event.entity.ServerPlayerEvent; -import band.kessoku.lib.event.util.NeoEventUtils; -import band.kessoku.lib.events.entity.api.EntitySleepEvent; -import band.kessoku.lib.events.entity.api.ServerLivingEntityEvent; -import band.kessoku.lib.events.entity.api.ServerPlayerEvent; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; + import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.entity.living.LivingConversionEvent; @@ -32,8 +36,9 @@ import net.neoforged.neoforge.event.entity.player.PlayerEvent; @Mod(KessokuEntityEvents.MOD_ID) -public class KessokuEntityEventEntrypoint { - public KessokuEntityEventEntrypoint() { +public final class KessokuEntityEventsNeoforge { + public KessokuEntityEventsNeoforge() { + KessokuLib.loadModule(KessokuEntityEvents.class); NeoEventUtils.registerEvent(NeoForge.EVENT_BUS, LivingIncomingDamageEvent.class, event -> { var entity = event.getEntity(); if (!entity.getWorld().isClient() && ServerLivingEntityEvent.ALLOW_DAMAGE.invoker().allowDamage(entity, event.getSource(), event.getAmount())) { diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/EntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/EntityMixin.java similarity index 95% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/EntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/EntityMixin.java index bbc7b00b..d95c13c3 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/EntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/EntityMixin.java @@ -13,22 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.ServerEntityWorldChangeEvent; +import java.util.Set; + +import band.kessoku.lib.api.event.entity.ServerEntityWorldChangeEvent; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.entity.Entity; -import net.minecraft.network.packet.s2c.play.PositionFlag; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.world.TeleportTarget; -import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Set; +import net.minecraft.entity.Entity; +import net.minecraft.network.packet.s2c.play.PositionFlag; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.TeleportTarget; +import net.minecraft.world.World; @Mixin(Entity.class) abstract class EntityMixin { diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/IItemExtensionMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/IItemExtensionMixin.java similarity index 92% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/IItemExtensionMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/IItemExtensionMixin.java index 7156960e..93dca60b 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/IItemExtensionMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/IItemExtensionMixin.java @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.item.KessokuElytraItem; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.neoforged.neoforge.common.extensions.IItemExtension; +import band.kessoku.lib.api.event.entity.item.KessokuElytraItem; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; + +import net.neoforged.neoforge.common.extensions.IItemExtension; + @Mixin(IItemExtension.class) public interface IItemExtensionMixin { @Inject(method = "canElytraFly", at = @At("HEAD"), cancellable = true) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/LivingEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/LivingEntityMixin.java similarity index 97% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/LivingEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/LivingEntityMixin.java index 8f7a3141..2d5e1495 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/LivingEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/LivingEntityMixin.java @@ -13,14 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.EntitySleepEvent; -import band.kessoku.lib.events.entity.api.ServerEntityCombatEvent; -import band.kessoku.lib.events.entity.api.ServerLivingEntityEvent; +import java.util.Optional; + +import band.kessoku.lib.api.event.entity.EntitySleepEvent; +import band.kessoku.lib.api.event.entity.ServerEntityCombatEvent; +import band.kessoku.lib.api.event.entity.ServerLivingEntityEvent; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BedBlock; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -36,18 +49,6 @@ import net.minecraft.world.CollisionView; import net.minecraft.world.World; import net.minecraft.world.WorldView; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Optional; @Mixin(LivingEntity.class) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/MobEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/MobEntityMixin.java similarity index 92% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/MobEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/MobEntityMixin.java index ee612144..66435c6a 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/MobEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/MobEntityMixin.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.ServerLivingEntityEvent; +import band.kessoku.lib.api.event.entity.ServerLivingEntityEvent; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.entity.Entity; -import net.minecraft.entity.mob.MobEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; +import net.minecraft.entity.Entity; +import net.minecraft.entity.mob.MobEntity; + @Mixin(MobEntity.class) public class MobEntityMixin { @ModifyArg(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerEntityMixin.java similarity index 92% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerEntityMixin.java index 3a4e042d..c6625b49 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerEntityMixin.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.EntitySleepEvent; -import net.minecraft.entity.player.PlayerEntity; +import band.kessoku.lib.api.event.entity.EntitySleepEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.entity.player.PlayerEntity; + @Mixin(PlayerEntity.class) abstract class PlayerEntityMixin { @Inject(method = "canResetTimeBySleeping", at = @At("RETURN"), cancellable = true) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerManagerMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerManagerMixin.java similarity index 92% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerManagerMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerManagerMixin.java index e9e255a3..df146c29 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/PlayerManagerMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/PlayerManagerMixin.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.ServerPlayerEvent; -import net.minecraft.entity.Entity; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; +import band.kessoku.lib.api.event.entity.ServerPlayerEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.entity.Entity; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; + @Mixin(PlayerManager.class) abstract class PlayerManagerMixin { @Inject(method = "respawnPlayer", at = @At("TAIL")) diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/ServerPlayerEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/ServerPlayerEntityMixin.java similarity index 98% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/ServerPlayerEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/ServerPlayerEntityMixin.java index 78e9dc39..78c2c25d 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/ServerPlayerEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/ServerPlayerEntityMixin.java @@ -13,11 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin; +package band.kessoku.lib.mixin.event.entity; -import band.kessoku.lib.events.entity.api.*; +import java.util.List; + +import band.kessoku.lib.api.event.entity.*; import com.llamalad7.mixinextras.sugar.Local; import com.mojang.datafixers.util.Either; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -33,16 +44,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; @Mixin(ServerPlayerEntity.class) abstract class ServerPlayerEntityMixin extends LivingEntityMixin { diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/LivingEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/LivingEntityMixin.java similarity index 95% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/LivingEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/LivingEntityMixin.java index 6d1bc813..56688e93 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/LivingEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/LivingEntityMixin.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin.elytra; +package band.kessoku.lib.mixin.event.entity.elytra; -import band.kessoku.lib.events.entity.api.EntityElytraEvent; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.world.World; +import band.kessoku.lib.api.event.entity.EntityElytraEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.world.World; + @SuppressWarnings("unused") @Mixin(LivingEntity.class) abstract class LivingEntityMixin extends Entity { diff --git a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/PlayerEntityMixin.java b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/PlayerEntityMixin.java similarity index 95% rename from entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/PlayerEntityMixin.java rename to entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/PlayerEntityMixin.java index 4f976263..9b3d1ac8 100644 --- a/entity-events/neo/src/main/java/band/kessoku/lib/events/entity/mixin/elytra/PlayerEntityMixin.java +++ b/entity-events/neo/src/main/java/band/kessoku/lib/mixin/event/entity/elytra/PlayerEntityMixin.java @@ -13,19 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.entity.mixin.elytra; +package band.kessoku.lib.mixin.event.entity.elytra; -import band.kessoku.lib.events.entity.api.EntityElytraEvent; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.World; +import band.kessoku.lib.api.event.entity.EntityElytraEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.World; + @SuppressWarnings("unused") @Mixin(PlayerEntity.class) abstract class PlayerEntityMixin extends LivingEntity { diff --git a/entity-events/neo/src/main/resources/META-INF/neoforge.mods.toml b/entity-events/neo/src/main/resources/META-INF/neoforge.mods.toml index 2d1edc7b..59495499 100644 --- a/entity-events/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/entity-events/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -15,7 +15,7 @@ authors = "Kessoku Tea Time" displayURL = "https://modrinth.com/mod/kessoku-lib" [[mixins]] -config = "kessoku-entity-events.mixins.json" +config = "kessoku_entity_events.neoforge.mixins.json" [[dependencies.kessoku_entity_events]] modId = "neoforge" diff --git a/entity-events/neo/src/main/resources/kessoku-entity-events.mixins.json b/entity-events/neo/src/main/resources/kessoku_entity_events.neoforge.mixins.json similarity index 86% rename from entity-events/neo/src/main/resources/kessoku-entity-events.mixins.json rename to entity-events/neo/src/main/resources/kessoku_entity_events.neoforge.mixins.json index 99284fbd..e0ac9813 100644 --- a/entity-events/neo/src/main/resources/kessoku-entity-events.mixins.json +++ b/entity-events/neo/src/main/resources/kessoku_entity_events.neoforge.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.events.entity.mixin", + "package": "band.kessoku.lib.mixin.event.entity", "compatibilityLevel": "JAVA_21", "mixins": [ "EntityMixin", diff --git a/entrypoint/common/build.gradle b/entrypoint/common/build.gradle index 5fb240c5..eecf9a22 100644 --- a/entrypoint/common/build.gradle +++ b/entrypoint/common/build.gradle @@ -1,10 +1,10 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.entrypoint" base.archivesName = rootProject.name + "-entrypoint" kessoku { module("base", "common") + module("platform", "common") } dependencies { diff --git a/config/neo/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/EntrypointMetadata.java similarity index 77% rename from config/neo/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java rename to entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/EntrypointMetadata.java index a90fee90..0cd57cd8 100644 --- a/config/neo/src/main/java/band/kessoku/lib/config/KessokuConfigEntrypoint.java +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/EntrypointMetadata.java @@ -13,12 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.config; +package band.kessoku.lib.api.entrypoint; -import net.neoforged.fml.common.Mod; - -@Mod(KessokuConfig.MOD_ID) -public class KessokuConfigEntrypoint { - public KessokuConfigEntrypoint() { - } +public interface EntrypointMetadata { + String getAdapter(); + String getValue(); } diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuEntrypoint.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuEntrypoint.java new file mode 100644 index 00000000..a1413052 --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuEntrypoint.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.entrypoint; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.api.platform.ModLoader; +import band.kessoku.lib.impl.entrypoint.JavaLanguageAdapter; +import band.kessoku.lib.impl.entrypoint.exceptions.LanguageAdapterException; +import club.someoneice.json.JSON; +import club.someoneice.json.node.JsonNode; +import club.someoneice.json.node.MapNode; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +public final class KessokuEntrypoint { + private KessokuEntrypoint() { + } + + public static final String MOD_ID = "kessoku_entrypoint"; + public static final String NAME = "Kessoku Entrypoint API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); + public static final int LATEST_SCHEMA_VERSION = 1; + private static Map modInfoMap; + private static final Map adapters = new HashMap<>(); + private static final Map> entryMap = new HashMap<>(); + + static { + KessokuLib.getLogger().info(MARKER, "Start loading Kessoku Entrypoint API."); + Map modInfoMap = new HashMap<>(); + for (ModData modData : ModLoader.getMods()) { + final String modid = modData.getModId(); + final Path kessokuJsonPath = modData.findPath("kessoku.json").orElse(null); + // Not found + if (kessokuJsonPath == null) continue; + try { + final MapNode json = (MapNode) JSON.json.parse(Files.readString(kessokuJsonPath)).asTypeNodeOrThrow(JsonNode.NodeType.Map, "Expect kessoku.json to be an object!"); + if (!json.has("schemaVersion")) throw new NullPointerException("schemaVersion is required!"); + final int schemaVersion = (int) json.get("schemaVersion").asTypeNodeOrThrow(JsonNode.NodeType.Int, "schemaVersion should be an integer!").getObj(); + @SuppressWarnings("SwitchStatementWithTooFewBranches") final KessokuMetadata metadata = switch (schemaVersion) { + case 1 -> KessokuMetadata.parse(json, modid); + default -> + throw new UnsupportedOperationException("Unsupported schemaVersion " + schemaVersion + " found! Consider updating Kessoku Lib to a newer version."); + }; + modInfoMap.put(modid, metadata); + } catch (Exception e) { + throw new RuntimeException("Failed to read kessoku info file from mod " + modData.getModId(), e); + } + } + KessokuEntrypoint.modInfoMap = Collections.unmodifiableMap(modInfoMap); + adapters.put("java", JavaLanguageAdapter.INSTANCE); + modInfoMap.forEach((modid, metadata) -> + metadata.entrypoints().forEach((key, entrypointMetadataList) -> { + List entries = new ArrayList<>(); + entrypointMetadataList.forEach(entrypointMetadata -> { + try { + Object instance = getAdapter(entrypointMetadata.getAdapter()).parse(ModLoader.getModData(modid), entrypointMetadata.getValue()); + entries.add(new Entry(modid, instance)); + } catch (LanguageAdapterException e) { + throw new RuntimeException(e); + } + } + ); + Objects.requireNonNull(entryMap.putIfAbsent(key, new ArrayList<>())).addAll(entries); + }) + ); + } + + public static void registerLanguageAdapter(String language, T adapter) { + if (adapters.containsKey(language)) throw new IllegalStateException(language + " has already been registered!"); + adapters.putIfAbsent(language, adapter); + } + + public static LanguageAdapter getAdapter(String language) { + return adapters.get(language); + } + + public static Optional getKessokuMetadata(String modid) { + return Optional.ofNullable(modInfoMap.get(modid)); + } + + @SuppressWarnings("unchecked") + private static final class Entry { + public final ModData modData; + private final Object instance; + + public Entry(String modid, Object instance) { + this.modData = ModLoader.getModData(modid); + this.instance = instance; + } + + public T get(Class type) { + return (T) this.instance; + } + } +} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuMetadata.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuMetadata.java new file mode 100644 index 00000000..1b4afd5d --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/KessokuMetadata.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.entrypoint; + +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +import band.kessoku.lib.impl.entrypoint.exceptions.KessokuParseException; +import club.someoneice.json.Pair; +import club.someoneice.json.api.exception.NodeCastException; +import club.someoneice.json.node.ArrayNode; +import club.someoneice.json.node.JsonNode; +import club.someoneice.json.node.MapNode; + +public record KessokuMetadata(Map> entrypoints, + Map languageAdapters, String modid) { + public KessokuMetadata(Map> entrypoints, Map languageAdapters, String modid) { + this.entrypoints = Collections.unmodifiableMap(entrypoints); + this.languageAdapters = Collections.unmodifiableMap(languageAdapters); + this.modid = modid; + } + + public static KessokuMetadata parse(final MapNode json, final String modid) { + final Map> entrypoints = new HashMap<>(); + final Map languageAdapters = new HashMap<>(); + try { + for (Pair> pair : json) { + switch (pair.getKey()) { + case "entrypoint" -> parseEntrypoint(entrypoints, pair.getValue(), modid); + case "languageAdapters" -> parseLanguageAdapters(languageAdapters, pair.getValue(), modid); + default -> throw new IllegalArgumentException(); + } + } + return new KessokuMetadata(entrypoints, languageAdapters,modid); + } catch (Exception e) { + throw new KessokuParseException(e, "Failed to parse kessoku.json provided by " + modid); + } + } + + private static void parseEntrypoint(final Map> entrypoints, final JsonNode node, final String modid) { + // Check if it's an object + node.asTypeNodeOrThrow(JsonNode.NodeType.Map, "entrypoint should be an object!"); + ((MapNode) node).forEach(pair -> { + // normalize value + final JsonNode rawValue = pair.getValue(); + // TODO + final List entrypointMetadataList = switch (rawValue.getType()) { + case Map -> parseObjectEntrypoint((MapNode) rawValue); + case String -> List.of(new EntrypointMetadata() { + @Override + public String getAdapter() { + return "java"; + } + + @Override + public String getValue() { + return (String) rawValue.getObj(); + } + }); + case Array -> { + ArrayNode arrayNode = (ArrayNode) rawValue; + if (arrayNode.isEmpty()) { + yield List.of(); + } else { + yield switch (arrayNode.get(0).getType()) { + case String -> { + List result = new ArrayList<>(); + arrayNode.forEach(jsonNode -> result.add(new EntrypointMetadata() { + @Override + public String getAdapter() { + return "java"; + } + + @Override + public String getValue() { + return (String) jsonNode.getObj(); + } + })); + yield result; + } + case Map -> { + List list = new ArrayList<>(); + arrayNode.forEach(jsonNode -> list.addAll(parseObjectEntrypoint((MapNode) jsonNode))); + yield list; + } + case null, default -> throw new NodeCastException(""); + }; + } + } + case null, default -> throw new NodeCastException(""); + }; + entrypoints.put(pair.getKey(), entrypointMetadataList); + }); + } + + private static List parseObjectEntrypoint(MapNode node) { + Map> map = node.getObj(); + String adapter = "java"; + String value = null; + for (Map.Entry> entry : map.entrySet()) { + String s = entry.getKey(); + JsonNode jsonNode = entry.getValue(); + switch (s) { + case "adapter": + adapter = (String) jsonNode.asTypeNodeOrThrow(JsonNode.NodeType.String, "adapter should be a string").getObj(); + break; + case "value": + value = (String) jsonNode.asTypeNodeOrThrow(JsonNode.NodeType.String, "value should be a string").getObj(); + break; + default: + throw new UnsupportedOperationException("Unknown key " + s + " found in kessoku.json!"); + } + } + if (value == null) throw new NullPointerException(); + final String finalAdapter = adapter; + final String finalClassName = value; + return List.of(new EntrypointMetadata() { + @Override + public String getAdapter() { + return finalAdapter; + } + + @Override + public String getValue() { + return finalClassName; + } + }); + } + + private static void parseLanguageAdapters(final Map languageAdapters, final JsonNode node, final String modid) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ClassCastException { + node.asTypeNodeOrThrow(JsonNode.NodeType.Map, "languageAdapters should be an object!"); + for (Pair> pair : ((MapNode) node)) { + String language = pair.getKey(); + String adapterClassName = (String) pair.getValue().asTypeNodeOrThrow(JsonNode.NodeType.String, "adapters should be a string!").getObj(); + Class adapterClass = Class.forName(adapterClassName); + LanguageAdapter adapter = (LanguageAdapter) adapterClass.getConstructor().newInstance(); + KessokuEntrypoint.registerLanguageAdapter(language, adapter); + languageAdapters.put(language, adapter); + } + } +} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/LanguageAdapter.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/LanguageAdapter.java new file mode 100644 index 00000000..de547d90 --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/LanguageAdapter.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.entrypoint; + +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.impl.entrypoint.JavaLanguageAdapter; +import band.kessoku.lib.impl.entrypoint.exceptions.LanguageAdapterException; + +public interface LanguageAdapter { + /** + * Get an instance of the default language adapter. + */ + static LanguageAdapter getDefault() { + return JavaLanguageAdapter.INSTANCE; + } + + /** + * Creates an object of {@code type} from an arbitrary string declaration. + * + * @param mod the mod which the object is from + * @param value the string declaration of the object + * @return the created object + * @throws LanguageAdapterException if a problem arises during creation, such as an invalid declaration + */ + Object parse(ModData mod, String value) throws LanguageAdapterException; +} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuClientModInitializer.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuClientModInitializer.java similarity index 93% rename from entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuClientModInitializer.java rename to entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuClientModInitializer.java index cf523709..e9bec627 100644 --- a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuClientModInitializer.java +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuClientModInitializer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.entrypoint.api; +package band.kessoku.lib.api.entrypoint.entrypoints; @FunctionalInterface public interface KessokuClientModInitializer { diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuDedicatedServerModInitializer.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuDedicatedServerModInitializer.java similarity index 93% rename from entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuDedicatedServerModInitializer.java rename to entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuDedicatedServerModInitializer.java index cfc7a254..9b89f1c5 100644 --- a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuDedicatedServerModInitializer.java +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuDedicatedServerModInitializer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.entrypoint.api; +package band.kessoku.lib.api.entrypoint.entrypoints; @FunctionalInterface public interface KessokuDedicatedServerModInitializer { diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuModInitializer.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuModInitializer.java similarity index 93% rename from entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuModInitializer.java rename to entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuModInitializer.java index 33aa17ca..305e4a53 100644 --- a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/api/KessokuModInitializer.java +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuModInitializer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.entrypoint.api; +package band.kessoku.lib.api.entrypoint.entrypoints; @FunctionalInterface public interface KessokuModInitializer { diff --git a/event-base/neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuPreLaunchEntrypoint.java similarity index 76% rename from event-base/neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java rename to entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuPreLaunchEntrypoint.java index c06cbc22..d89c3db4 100644 --- a/event-base/neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java +++ b/entrypoint/common/src/main/java/band/kessoku/lib/api/entrypoint/entrypoints/KessokuPreLaunchEntrypoint.java @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.event; +package band.kessoku.lib.api.entrypoint.entrypoints; -import net.neoforged.fml.common.Mod; - -@Mod(KessokuEventBase.MOD_ID) -public class KessokuEventBaseEntrypoint { - public KessokuEventBaseEntrypoint() { - - } +@FunctionalInterface +public interface KessokuPreLaunchEntrypoint { + void onPreLaunch(); } diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypoint.java b/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypoint.java deleted file mode 100644 index 6f3129fa..00000000 --- a/entrypoint/common/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypoint.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.entrypoint; - -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -public class KessokuEntrypoint { - public static final String MOD_ID = "kessoku_entrypoint"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuEntrypoint]"); -} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/JavaLanguageAdapter.java b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/JavaLanguageAdapter.java new file mode 100644 index 00000000..d603650c --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/JavaLanguageAdapter.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.entrypoint; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import band.kessoku.lib.api.entrypoint.LanguageAdapter; +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.impl.entrypoint.exceptions.LanguageAdapterException; + +public final class JavaLanguageAdapter implements LanguageAdapter { + public static final LanguageAdapter INSTANCE = new JavaLanguageAdapter(); + + private JavaLanguageAdapter() { + } + + @Override + public Object parse(final ModData mod, final String value) throws LanguageAdapterException { + final String[] methodSplit = value.split("::"); + if (methodSplit.length >= 3) { + throw new LanguageAdapterException("Invalid handle format: " + value); + } + // Try to get the class + final Class c; + try { + c = Class.forName(methodSplit[0]); + } catch (ClassNotFoundException e) { + throw new LanguageAdapterException(e); + } + // The class may be an inner class + if (!Modifier.isStatic(c.getModifiers())) + throw new LanguageAdapterException("Class is not static: " + methodSplit[0]); + // try to get the Object + if (methodSplit.length == 1) { + try { + return c.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw new LanguageAdapterException(e); + } + } else /* methodSplit.length == 2 */ { + Getter getter = null; + // Try to find method + try { + final Method method = c.getMethod(methodSplit[1], ModData.class); + if (!Modifier.isStatic(method.getModifiers())) throw new LanguageAdapterException("Method " + value + " must be static!"); + getter = () -> { + method.setAccessible(true); + try { + return method.invoke(null, mod); + } catch (InvocationTargetException | IllegalAccessException e) { + throw new LanguageAdapterException(e); + } + }; + } catch (NoSuchMethodException e) { + try { + final Method method = c.getMethod(methodSplit[1]); + if (!Modifier.isStatic(method.getModifiers())) throw new LanguageAdapterException("Method " + value + " must be static!"); + getter = () -> { + method.setAccessible(true); + try { + return method.invoke(null); + } catch (InvocationTargetException | IllegalAccessException e2) { + throw new LanguageAdapterException(e2); + } + }; + } catch (NoSuchMethodException e3) { + // not method + } + } + + // Try to find field + try { + Field field = c.getDeclaredField(methodSplit[1]); + + if (!Modifier.isStatic(field.getModifiers())) { + throw new LanguageAdapterException("Field " + value + " must be static!"); + } + + if (getter != null) { + throw new LanguageAdapterException("Ambiguous " + value + " - refers to both field and method!"); + } + return field.get(null); + } catch (NoSuchFieldException e) { + if (getter == null) throw new LanguageAdapterException("Could not find " + value + "!"); + } catch (IllegalAccessException e) { + throw new LanguageAdapterException("Field " + value + " cannot be accessed!", e); + } + return getter.get(); + } + } + + interface Getter { + Object get() throws LanguageAdapterException; + } +} \ No newline at end of file diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuEntrypointException.java b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuEntrypointException.java new file mode 100644 index 00000000..227e06f5 --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuEntrypointException.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.entrypoint.exceptions; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@ApiStatus.Internal +public final class KessokuEntrypointException extends RuntimeException { + @Nullable + public final String modid; + public final String key; + + public KessokuEntrypointException(String key, Throwable cause) { + super("Exception while loading entries for entrypoint '" + key + "'!", cause); + this.modid = null; + this.key = key; + } + + public KessokuEntrypointException(String key, @NotNull String modid, Throwable cause) { + super("Exception while loading entries for entrypoint '" + key + "' provided by '" + modid + "'", cause); + this.modid = modid; + this.key = key; + } +} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuParseException.java b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuParseException.java new file mode 100644 index 00000000..14d99a50 --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/KessokuParseException.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.entrypoint.exceptions; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class KessokuParseException extends RuntimeException { + @Nullable + public final String modid; + + public KessokuParseException(@NotNull String message, @Nullable String modid) { + super("Failed to parse kessoku.json for " + modid + " : " + message); + this.modid = modid; + } + + public KessokuParseException(@NotNull String message, @Nullable String modid, @NotNull Throwable cause) { + super("Failed to parse kessoku.json for " + modid + " : " + message, cause); + this.modid = modid; + } + + public KessokuParseException(@NotNull Throwable cause, @Nullable String modid) { + super(cause); + this.modid = modid; + } +} diff --git a/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/LanguageAdapterException.java b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/LanguageAdapterException.java new file mode 100644 index 00000000..e30b1627 --- /dev/null +++ b/entrypoint/common/src/main/java/band/kessoku/lib/impl/entrypoint/exceptions/LanguageAdapterException.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.entrypoint.exceptions; + +public final class LanguageAdapterException extends Exception { + /** + * Creates a new language adapter exception. + * + * @param s the message + */ + public LanguageAdapterException(String s) { + super(s); + } + + /** + * Creates a new language adapter exception. + * + * @param t the cause + */ + public LanguageAdapterException(Throwable t) { + super(t); + } + + /** + * Creates a new language adapter exception. + * + * @param s the message + * @param t the cause + */ + public LanguageAdapterException(String s, Throwable t) { + super(s, t); + } +} diff --git a/entrypoint/fabric/build.gradle b/entrypoint/fabric/build.gradle index 15bfb594..c4aa372b 100644 --- a/entrypoint/fabric/build.gradle +++ b/entrypoint/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.entrypoint" base.archivesName = rootProject.name + "-entrypoint" kessoku { @@ -13,5 +12,4 @@ kessoku { } dependencies { - implementation libs.aj4j } diff --git a/entrypoint/fabric/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java b/entrypoint/fabric/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java deleted file mode 100644 index d26a67db..00000000 --- a/entrypoint/fabric/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.entrypoint; - -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; -import band.kessoku.lib.entrypoint.api.KessokuDedicatedServerModInitializer; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import com.google.common.collect.ImmutableMap; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - -import java.lang.reflect.InvocationTargetException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; - -public class KessokuEntrypointEntrypoint implements ModInitializer, ClientModInitializer, DedicatedServerModInitializer, PreLaunchEntrypoint { - private static ImmutableMap modInfoList; - - @Override - public void onInitialize() { - ModUtils.getLogger().info(KessokuEntrypoint.MARKER, "KessokuLib-Entrypoint is loaded!"); - FabricLoader.getInstance().invokeEntrypoints("kMain", KessokuModInitializer.class, KessokuModInitializer::onInitialize); - } - - @Override - public void onInitializeClient() { - FabricLoader.getInstance().invokeEntrypoints("kClient", KessokuClientModInitializer.class, KessokuClientModInitializer::onInitializeClient); - } - - @Override - public void onInitializeServer() { - FabricLoader.getInstance().invokeEntrypoints("kServer", KessokuDedicatedServerModInitializer.class, KessokuDedicatedServerModInitializer::onInitializeServer); - } - - @Override - public void onPreLaunch() { - for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { - Path path = modContainer.findPath("kessoku.json").orElse(null); - if (path == null) continue; - - try { - String json = Files.readString(path); - } catch (Exception e) { - throw new RuntimeException("Failed to read accessWidener file from mod " + modContainer.getMetadata().getId(), e); - } - } - } - - public record KessokuInfo(Map> entrypointMap) { - } - - public record EntrypointInfo(Class entrypoint, T instance) { - public static EntrypointInfo create(Class entrypoint) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - return new EntrypointInfo<>(entrypoint, entrypoint.getDeclaredConstructor().newInstance()); - } - } -} diff --git a/entrypoint/fabric/src/main/java/band/kessoku/lib/impl/entrypoint/fabric/KessokuEntrypointFabric.java b/entrypoint/fabric/src/main/java/band/kessoku/lib/impl/entrypoint/fabric/KessokuEntrypointFabric.java new file mode 100644 index 00000000..c7556437 --- /dev/null +++ b/entrypoint/fabric/src/main/java/band/kessoku/lib/impl/entrypoint/fabric/KessokuEntrypointFabric.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.entrypoint.fabric; + + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.entrypoint.KessokuEntrypoint; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.DedicatedServerModInitializer; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +public final class KessokuEntrypointFabric implements ModInitializer, ClientModInitializer, DedicatedServerModInitializer, PreLaunchEntrypoint { + @Override + public void onInitialize() { + } + + @Override + public void onInitializeClient() { + } + + @Override + public void onInitializeServer() { + } + + @Override + public void onPreLaunch() { + KessokuLib.loadModule(KessokuEntrypoint.class); + } +} diff --git a/entrypoint/fabric/src/main/resources/fabric.mod.json b/entrypoint/fabric/src/main/resources/fabric.mod.json index deaac6b4..68df0a05 100644 --- a/entrypoint/fabric/src/main/resources/fabric.mod.json +++ b/entrypoint/fabric/src/main/resources/fabric.mod.json @@ -16,16 +16,16 @@ "icon": "icon.png", "entrypoints": { "main": [ - "band.kessoku.lib.entrypoint.KessokuEntrypointEntrypoint" + "band.kessoku.lib.impl.entrypoint.fabric.KessokuEntrypointFabric" ], "client": [ - "band.kessoku.lib.entrypoint.KessokuEntrypointEntrypoint" + "band.kessoku.lib.impl.entrypoint.fabric.KessokuEntrypointFabric" ], "server": [ - "band.kessoku.lib.entrypoint.KessokuEntrypointEntrypoint" + "band.kessoku.lib.impl.entrypoint.fabric.KessokuEntrypointFabric" ], "preLaunch": [ - "band.kessoku.lib.entrypoint.KessokuEntrypointEntrypoint" + "band.kessoku.lib.impl.entrypoint.fabric.KessokuEntrypointFabric" ] }, "environment": "*", diff --git a/entrypoint/neo/build.gradle b/entrypoint/neo/build.gradle index 1a603332..ea6c1d73 100644 --- a/entrypoint/neo/build.gradle +++ b/entrypoint/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.entrypoint" base.archivesName = rootProject.name + "-entrypoint" kessoku { diff --git a/entrypoint/neo/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java b/entrypoint/neo/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java deleted file mode 100644 index df592af0..00000000 --- a/entrypoint/neo/src/main/java/band/kessoku/lib/entrypoint/KessokuEntrypointEntrypoint.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.entrypoint; - -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; -import band.kessoku.lib.entrypoint.api.KessokuDedicatedServerModInitializer; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import com.google.common.collect.ImmutableList; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.fml.ModList; -import net.neoforged.fml.common.Mod; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Mod(KessokuEntrypoint.MOD_ID) -public final class KessokuEntrypointEntrypoint { - private static final Map> entrypointMap = new HashMap<>(); - - public KessokuEntrypointEntrypoint(Dist dist) { - ModUtils.getLogger().info(KessokuEntrypoint.MARKER, "KessokuLib-Entrypoint is loaded!"); - registerEntrypoint("kMain", KessokuModInitializer.class); - registerEntrypoint("kClient", KessokuClientModInitializer.class); - registerEntrypoint("kServer", KessokuDedicatedServerModInitializer.class); - } - - @SuppressWarnings("unchecked") - public static void registerEntrypoint(String entrypointName, Class initializer) { - if (entrypointMap.containsKey(entrypointName)) throw new UnsupportedOperationException(); - final ImmutableList.Builder builder = ImmutableList.builder(); - ModList.get().getMods().forEach(info -> { - try { - Map properties = info.getModProperties(); - if (properties.containsKey(entrypointName)) { - Object entrypointList = properties.get(entrypointName); - if (!(entrypointList instanceof List)) { - throw new IllegalArgumentException(); - } - - if (!ModUtils.isType((List) entrypointList, String.class)) { - for (Object entrypoint : ((List) entrypointList)) { - Class clazz = Class.forName((String) entrypoint); - if (!clazz.isAssignableFrom(initializer)) throw new IllegalArgumentException(); - builder.add((T) clazz.getConstructor().newInstance()); - } - } - } - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - entrypointMap.put(entrypointName, builder.build()); - } -} diff --git a/base/neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java b/entrypoint/neo/src/main/java/band/kessoku/lib/impl/entrypoint/neoforge/KessokuEntrypointNeoforge.java similarity index 74% rename from base/neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java rename to entrypoint/neo/src/main/java/band/kessoku/lib/impl/entrypoint/neoforge/KessokuEntrypointNeoforge.java index 3077d878..480fc9d1 100644 --- a/base/neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java +++ b/entrypoint/neo/src/main/java/band/kessoku/lib/impl/entrypoint/neoforge/KessokuEntrypointNeoforge.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.base; +package band.kessoku.lib.impl.entrypoint.neoforge; + +import band.kessoku.lib.api.entrypoint.KessokuEntrypoint; import net.neoforged.fml.common.Mod; -@Mod(KessokuBase.MOD_ID) -public class KessokuBaseEntrypoint { - public KessokuBaseEntrypoint() { - ModUtils.getLogger().info(KessokuBase.MARKER, "KessokuLib-Base is loaded!"); +@Mod(KessokuEntrypoint.MOD_ID) +public final class KessokuEntrypointNeoforge { + public KessokuEntrypointNeoforge() { } } diff --git a/entrypoint/neo/src/main/java/band/kessoku/lib/mixin/entrypoint/neoforge/FMLLoaderMixin.java b/entrypoint/neo/src/main/java/band/kessoku/lib/mixin/entrypoint/neoforge/FMLLoaderMixin.java new file mode 100644 index 00000000..3c63e600 --- /dev/null +++ b/entrypoint/neo/src/main/java/band/kessoku/lib/mixin/entrypoint/neoforge/FMLLoaderMixin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.mixin.entrypoint.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.entrypoint.KessokuEntrypoint; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.neoforged.fml.loading.FMLLoader; + +@Mixin(FMLLoader.class) +public class FMLLoaderMixin { + @Inject(method = "beforeStart", at = @At("HEAD")) + private static void preLaunch(ModuleLayer gameLayer, CallbackInfo ci) { + KessokuLib.loadModule(KessokuEntrypoint.class); + } +} diff --git a/entrypoint/neo/src/main/resources/META-INF/neoforge.mods.toml b/entrypoint/neo/src/main/resources/META-INF/neoforge.mods.toml index f1f9e9fe..b5d6916a 100644 --- a/entrypoint/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/entrypoint/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -26,4 +26,7 @@ modId = "minecraft" type = "required" versionRange = "[1.21,)" ordering = "NONE" -side = "BOTH" \ No newline at end of file +side = "BOTH" + +[[mixins]] +config = "kessoku_entrypoint.neoforge.mixins.json" \ No newline at end of file diff --git a/entrypoint/neo/src/main/resources/kessoku_entrypoint.neoforge.mixins.json b/entrypoint/neo/src/main/resources/kessoku_entrypoint.neoforge.mixins.json new file mode 100644 index 00000000..975d2dff --- /dev/null +++ b/entrypoint/neo/src/main/resources/kessoku_entrypoint.neoforge.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "band.kessoku.lib.mixin.entrypoint.neoforge", + "compatibilityLevel": "JAVA_21", + "mixins": [ + "FMLLoaderMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/event-base/common/build.gradle b/event-base/common/build.gradle index 5b70f622..1e6fa0e2 100644 --- a/event-base/common/build.gradle +++ b/event-base/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.event" base.archivesName = rootProject.name + "-event-base" kessoku { diff --git a/event-base/common/src/main/java/band/kessoku/lib/event/api/Event.java b/event-base/common/src/main/java/band/kessoku/lib/event/api/Event.java index c2d742fb..123d59cd 100644 --- a/event-base/common/src/main/java/band/kessoku/lib/event/api/Event.java +++ b/event-base/common/src/main/java/band/kessoku/lib/event/api/Event.java @@ -15,13 +15,12 @@ */ package band.kessoku.lib.event.api; -import band.kessoku.lib.event.impl.EventImpl; - import java.util.List; import java.util.function.Function; -public interface Event { +import band.kessoku.lib.event.impl.EventImpl; +public interface Event { T invoker(); void register(T listener, EventPhase phase); diff --git a/event-base/common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java b/event-base/common/src/main/java/band/kessoku/lib/event/api/KessokuEventBase.java similarity index 84% rename from event-base/common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java rename to event-base/common/src/main/java/band/kessoku/lib/event/api/KessokuEventBase.java index 4f4fc692..8a1b187b 100644 --- a/event-base/common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java +++ b/event-base/common/src/main/java/band/kessoku/lib/event/api/KessokuEventBase.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.event; +package band.kessoku.lib.event.api; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuEventBase { +public final class KessokuEventBase { public static final String MOD_ID = "kessoku_event_base"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuEventBase]"); + public static final String NAME = "Kessoku Event Base"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); } diff --git a/event-base/common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java b/event-base/common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java index 9336c11f..ff1f1681 100644 --- a/event-base/common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java +++ b/event-base/common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java @@ -15,19 +15,18 @@ */ package band.kessoku.lib.event.impl; -import band.kessoku.lib.event.api.Event; -import band.kessoku.lib.event.api.EventPhase; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; -public class EventImpl implements Event { +import band.kessoku.lib.event.api.Event; +import band.kessoku.lib.event.api.EventPhase; - private Map> listeners = new HashMap<>(); - private Function, T> invokerFunc; +public final class EventImpl implements Event { + private final Map> listeners = new HashMap<>(); + private final Function, T> invokerFunc; public EventImpl(Function, T> invokerFunc) { this.invokerFunc = invokerFunc; diff --git a/event-base/common/src/test/java/kessoku/testmod/event/KessokuTestEvent.java b/event-base/common/src/test/java/kessoku/testmod/event/KessokuTestEvent.java index 11c9ebbb..e942f52a 100644 --- a/event-base/common/src/test/java/kessoku/testmod/event/KessokuTestEvent.java +++ b/event-base/common/src/test/java/kessoku/testmod/event/KessokuTestEvent.java @@ -15,7 +15,7 @@ */ package kessoku.testmod.event; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; import band.kessoku.lib.event.api.Event; public class KessokuTestEvent implements KessokuModInitializer { diff --git a/event-base/fabric/build.gradle b/event-base/fabric/build.gradle index 90382324..870ae025 100644 --- a/event-base/fabric/build.gradle +++ b/event-base/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.event" base.archivesName = rootProject.name + "-event-base" kessoku { diff --git a/event-base/fabric/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java b/event-base/fabric/src/main/java/band/kessoku/lib/impl/event/fabric/KessokuEventBaseFabric.java similarity index 73% rename from event-base/fabric/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java rename to event-base/fabric/src/main/java/band/kessoku/lib/impl/event/fabric/KessokuEventBaseFabric.java index a41b9cec..18881f19 100644 --- a/event-base/fabric/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java +++ b/event-base/fabric/src/main/java/band/kessoku/lib/impl/event/fabric/KessokuEventBaseFabric.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.event; +package band.kessoku.lib.impl.event.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.event.api.KessokuEventBase; -import band.kessoku.lib.base.ModUtils; import net.fabricmc.api.ModInitializer; -public class KessokuEventBaseEntrypoint implements ModInitializer { +public final class KessokuEventBaseFabric implements ModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuEventBase.MARKER, "KessokuLib-EventBase is Loaded!"); + KessokuLib.loadModule(KessokuEventBase.class); } } diff --git a/event-base/fabric/src/main/resources/fabric.mod.json b/event-base/fabric/src/main/resources/fabric.mod.json index 15a32574..200b47db 100644 --- a/event-base/fabric/src/main/resources/fabric.mod.json +++ b/event-base/fabric/src/main/resources/fabric.mod.json @@ -14,6 +14,11 @@ }, "license": "LGPL-3.0-only", "icon": "icon.png", + "entrypoints": { + "main": [ + "band.kessoku.lib.impl.event.fabric.KessokuEventBaseFabric" + ] + }, "environment": "*", "depends": { "fabricloader": ">=0.16.0", diff --git a/event-base/neo/build.gradle b/event-base/neo/build.gradle index 747c5de3..0579927f 100644 --- a/event-base/neo/build.gradle +++ b/event-base/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.event" base.archivesName = rootProject.name + "-event-base" kessoku { diff --git a/event-base/neo/src/main/java/band/kessoku/lib/impl/event/neoforge/KessokuEventBaseNeoforge.java b/event-base/neo/src/main/java/band/kessoku/lib/impl/event/neoforge/KessokuEventBaseNeoforge.java new file mode 100644 index 00000000..d889595f --- /dev/null +++ b/event-base/neo/src/main/java/band/kessoku/lib/impl/event/neoforge/KessokuEventBaseNeoforge.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.event.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.event.api.KessokuEventBase; + +import net.neoforged.fml.common.Mod; + +@Mod(KessokuEventBase.MOD_ID) +public class KessokuEventBaseNeoforge { + public KessokuEventBaseNeoforge() { + KessokuLib.loadModule(KessokuEventBase.class); + } +} diff --git a/gradle/example/fabric/build.gradle b/gradle/example/fabric/build.gradle index 7dde7094..80af3fc1 100644 --- a/gradle/example/fabric/build.gradle +++ b/gradle/example/fabric/build.gradle @@ -1,11 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.package" base.archivesName = rootProject.name + "-package" -dependencies { - //kessoku.moduleImpl("base", "common") +kessoku { + modules("base", "common") - common(project(path: ':package-common', configuration: 'namedElements')) { transitive false } - shadowBundle(project(path: ':package-common', configuration: 'transformProductionFabric')) + common("package-common", ModPlatform.FABRIC) + shadowBundle("package-common", ModPlatform.FABRIC) } diff --git a/gradle/example/neo/build.gradle b/gradle/example/neo/build.gradle index b79e798f..726226fa 100644 --- a/gradle/example/neo/build.gradle +++ b/gradle/example/neo/build.gradle @@ -1,11 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.package" base.archivesName = rootProject.name + "-package" -dependencies { - //kessoku.moduleImpl("base", "common") +kessoku { + modules("base", "common") - common(project(path: ':package-common', configuration: 'namedElements')) { transitive false } - shadowBundle(project(path: ':package-common', configuration: 'transformProductionNeoForge')) + common("package-common", ModPlatform.FABRIC) + shadowBundle("package-common", ModPlatform.FABRIC) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2a4d3662..38f5278f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ fabric-api = "0.102.0+1.21" # Plugin version loom = "1.7-SNAPSHOT" architectury = "3.4-SNAPSHOT" -shadow = "8.3.1" +shadow = "8.3.2" spotless = "7.0.0.BETA2" idea-ext = "1.1.8" diff --git a/keybind/fabric/build.gradle b/keybind/fabric/build.gradle deleted file mode 100644 index d0826ed0..00000000 --- a/keybind/fabric/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -import net.fabricmc.loom.util.ModPlatform - -apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") - -group = "band.kessoku.lib.keybind" -base.archivesName = rootProject.name + "-keybind" - -kessoku { - module("base", "common") - - common("keybind", ModPlatform.FABRIC) - shadowBundle("keybind", ModPlatform.FABRIC) -} diff --git a/keybind/neo/build.gradle b/keybind/neo/build.gradle deleted file mode 100644 index 35a3f798..00000000 --- a/keybind/neo/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -import net.fabricmc.loom.util.ModPlatform - -apply from: rootProject.file("gradle/scripts/klib-neo.gradle") - -group = "band.kessoku.lib.keybind" -base.archivesName = rootProject.name + "-keybind" - -kessoku { - module("base", "common") - module("event-base", "neo") - - common("keybind", ModPlatform.NEOFORGE) - shadowBundle("keybind", ModPlatform.NEOFORGE) -} diff --git a/keybind/common/build.gradle b/keybinding/common/build.gradle similarity index 56% rename from keybind/common/build.gradle rename to keybinding/common/build.gradle index b06b6a4d..920a1f44 100644 --- a/keybind/common/build.gradle +++ b/keybinding/common/build.gradle @@ -1,7 +1,6 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.keybind" -base.archivesName = rootProject.name + "-keybind" +base.archivesName = rootProject.name + "-keybinding" kessoku { module("base", "common") diff --git a/keybinding/common/src/main/java/band/kessoku/lib/api/keybinding/client/KeyBindingRegister.java b/keybinding/common/src/main/java/band/kessoku/lib/api/keybinding/client/KeyBindingRegister.java new file mode 100644 index 00000000..3681b5d9 --- /dev/null +++ b/keybinding/common/src/main/java/band/kessoku/lib/api/keybinding/client/KeyBindingRegister.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.keybinding.client; + +import java.util.Map; +import java.util.Set; + +import band.kessoku.lib.api.base.KessokuUtils; +import band.kessoku.lib.impl.keybinding.client.CategoryOrderMap; +import band.kessoku.lib.service.keybinding.client.KeyBindingRegisterService; +import org.jetbrains.annotations.Nullable; + +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; + +public final class KeyBindingRegister { + private KeyBindingRegister() { + } + + public static boolean addCategory(String categoryTranslationKey) { + Map map = CategoryOrderMap.getInstance(); + + if (map.containsKey(categoryTranslationKey)) { + return false; + } + + final int largest = map.values().stream().max(Integer::compareTo).orElse(0); + map.put(categoryTranslationKey, largest + 1); + return true; + } + + public boolean hasCategory(String categoryTranslationKey) { + return CategoryOrderMap.getInstance().containsKey(categoryTranslationKey); + } + + public boolean hasCategory(int index) { + return !this.getCategorySet(index).isEmpty(); + } + + public Set getCategorySet(int index) { + return KessokuUtils.getKeysByValue(CategoryOrderMap.getInstance(), index); + } + + public @Nullable Integer indexOf(String categoryTranslationKey) { + return CategoryOrderMap.getInstance().get(categoryTranslationKey); + } + + public boolean addCategory(int index, String categoryTranslationKey) { + if (this.hasCategory(categoryTranslationKey)) return false; + CategoryOrderMap.getInstance().putIfAbsent(categoryTranslationKey, index); + return true; + } + + public static KeyBinding register(KeyBinding keyBinding) { + return KeyBindingRegisterService.INSTANCE.register(keyBinding); + } + + public static InputUtil.Key getBoundKey(KeyBinding keyBinding) { + return KeyBindingRegisterService.INSTANCE.getBoundKey(keyBinding); + } +} diff --git a/keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/CategoryOrderMap.java b/keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/CategoryOrderMap.java new file mode 100644 index 00000000..c5ca4646 --- /dev/null +++ b/keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/CategoryOrderMap.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.keybinding.client; + +import java.util.HashMap; +import java.util.Map; + +import band.kessoku.lib.api.KessokuLib; +import org.jetbrains.annotations.ApiStatus; + +import net.minecraft.text.Text; + +// RawDiamondMC Note: +// Maybe some hacky changes to implement insertAfter and insertBefore? +public final class CategoryOrderMap extends HashMap { + private static CategoryOrderMap INSTANCE; + + private CategoryOrderMap(Map map) { + super(map); + INSTANCE = this; + } + + @ApiStatus.Internal + public static CategoryOrderMap of(Map map) { + if (INSTANCE != null) + throw new UnsupportedOperationException("CATEGORY_ORDER_MAP has already been initialized!"); + return new CategoryOrderMap(map); + } + + @Override + public Integer put(String key, Integer value) { + if (this.containsValue(value) && value != Integer.MAX_VALUE && value != Integer.MIN_VALUE) + KessokuLib.getLogger().warn(KessokuKeybinding.MARKER, "Duplicate category index found! Category: {} Index: {}", Text.translatable(key), value); + return super.put(key, value); + } + + public static CategoryOrderMap getInstance() { + if (INSTANCE == null) + throw new IllegalStateException("CATEGORY_ORDER_MAP has not been initialized yet!"); + return INSTANCE; + } +} diff --git a/keybind/common/src/main/java/band/kessoku/lib/keybind/KessokuKeybind.java b/keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/KessokuKeybinding.java similarity index 90% rename from keybind/common/src/main/java/band/kessoku/lib/keybind/KessokuKeybind.java rename to keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/KessokuKeybinding.java index 3a390c53..20ecc741 100644 --- a/keybind/common/src/main/java/band/kessoku/lib/keybind/KessokuKeybind.java +++ b/keybinding/common/src/main/java/band/kessoku/lib/impl/keybinding/client/KessokuKeybinding.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind; +package band.kessoku.lib.impl.keybinding.client; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuKeybind { +public final class KessokuKeybinding { public static final String MOD_ID = "kessoku_keybind"; public static final Marker MARKER = MarkerFactory.getMarker("[KessokuKeybind]"); } diff --git a/keybinding/common/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingMixin.java b/keybinding/common/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingMixin.java new file mode 100644 index 00000000..52961710 --- /dev/null +++ b/keybinding/common/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingMixin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.mixin.keybinding.client; + +import java.util.Collections; +import java.util.Map; +import java.util.function.Consumer; + +import band.kessoku.lib.impl.keybinding.client.CategoryOrderMap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.client.option.KeyBinding; +import net.minecraft.util.Util; + +@Mixin(KeyBinding.class) +public class KeyBindingMixin { + @SuppressWarnings("unchecked") + @Redirect(method = "", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/Util;make(Ljava/lang/Object;Ljava/util/function/Consumer;)Ljava/lang/Object;")) + private static T replaceCategoryOrderMap(T object, Consumer initializer) { + Map map = (Map) Util.make(object, initializer); + return (T) Collections.synchronizedMap(CategoryOrderMap.of(map)); + } +} diff --git a/keybind/common/src/main/java/band/kessoku/lib/keybind/api/KeyBindRegister.java b/keybinding/common/src/main/java/band/kessoku/lib/service/keybinding/client/KeyBindingRegisterService.java similarity index 73% rename from keybind/common/src/main/java/band/kessoku/lib/keybind/api/KeyBindRegister.java rename to keybinding/common/src/main/java/band/kessoku/lib/service/keybinding/client/KeyBindingRegisterService.java index 2cbf21a0..9a237883 100644 --- a/keybind/common/src/main/java/band/kessoku/lib/keybind/api/KeyBindRegister.java +++ b/keybinding/common/src/main/java/band/kessoku/lib/service/keybinding/client/KeyBindingRegisterService.java @@ -13,18 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind.api; +package band.kessoku.lib.service.keybinding.client; + +import band.kessoku.lib.api.KessokuLib; -import band.kessoku.lib.keybind.impl.KessokuKeyBindService; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; -public interface KeyBindRegister { - static KeyBindRegister getInstance() { - return KessokuKeyBindService.getRegister(); - } +public interface KeyBindingRegisterService { + KeyBindingRegisterService INSTANCE = KessokuLib.loadService(KeyBindingRegisterService.class); - boolean addCategory(String categoryTranslationKey); KeyBinding register(KeyBinding keyBinding); + InputUtil.Key getBoundKey(KeyBinding keyBinding); } diff --git a/keybind/common/src/main/resources/icon.png b/keybinding/common/src/main/resources/icon.png similarity index 100% rename from keybind/common/src/main/resources/icon.png rename to keybinding/common/src/main/resources/icon.png diff --git a/keybinding/common/src/main/resources/kessoku_key_binding.mixins.json b/keybinding/common/src/main/resources/kessoku_key_binding.mixins.json new file mode 100644 index 00000000..ac16eea2 --- /dev/null +++ b/keybinding/common/src/main/resources/kessoku_key_binding.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "band.kessoku.lib.mixin.keybinding.client", + "compatibilityLevel": "JAVA_21", + "client": [ + "KeyBindingMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/keybind/common/src/test/java/kessoku/testmod/keybind/KessokuTestKeybind.java b/keybinding/common/src/test/java/kessoku/testmod/keybinding/KessokuTestKeybinding.java similarity index 73% rename from keybind/common/src/test/java/kessoku/testmod/keybind/KessokuTestKeybind.java rename to keybinding/common/src/test/java/kessoku/testmod/keybinding/KessokuTestKeybinding.java index f0b7f9ca..890c47c9 100644 --- a/keybind/common/src/test/java/kessoku/testmod/keybind/KessokuTestKeybind.java +++ b/keybinding/common/src/test/java/kessoku/testmod/keybinding/KessokuTestKeybinding.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package kessoku.testmod.keybind; +package kessoku.testmod.keybinding; + +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.service.keybinding.client.KeyBindingRegisterService; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.keybind.api.KeyBindRegister; import net.minecraft.client.option.KeyBinding; -public class KessokuTestKeybind implements KessokuModInitializer { +public class KessokuTestKeybinding implements KessokuModInitializer { @Override public void onInitialize() { - KeyBindRegister.getInstance().register( + KeyBindingRegisterService.INSTANCE.register( new KeyBinding( "Test Name", 0, diff --git a/keybinding/fabric/build.gradle b/keybinding/fabric/build.gradle new file mode 100644 index 00000000..2a39f57d --- /dev/null +++ b/keybinding/fabric/build.gradle @@ -0,0 +1,12 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") + +base.archivesName = rootProject.name + "-keybinding" + +kessoku { + module("base", "common") + + common("keybinding", ModPlatform.FABRIC) + shadowBundle("keybinding", ModPlatform.FABRIC) +} diff --git a/keybind/fabric/src/main/java/band/kessoku/lib/keybind/KessokuKeybindEntrypoint.java b/keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KessokuKeyBindingFabric.java similarity index 71% rename from keybind/fabric/src/main/java/band/kessoku/lib/keybind/KessokuKeybindEntrypoint.java rename to keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KessokuKeyBindingFabric.java index dd08fd87..97a329b2 100644 --- a/keybind/fabric/src/main/java/band/kessoku/lib/keybind/KessokuKeybindEntrypoint.java +++ b/keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KessokuKeyBindingFabric.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind; +package band.kessoku.lib.impl.keybinding.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.impl.keybinding.client.KessokuKeybinding; -import band.kessoku.lib.base.ModUtils; import net.fabricmc.api.ClientModInitializer; -public class KessokuKeybindEntrypoint implements ClientModInitializer { +public final class KessokuKeyBindingFabric implements ClientModInitializer { @Override public void onInitializeClient() { - ModUtils.getLogger().info(KessokuKeybind.MARKER, "KessokuKeybind is loaded!"); + KessokuLib.loadModule(KessokuKeybinding.class); } } diff --git a/keybind/fabric/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java b/keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KeyBindingRegisterImpl.java similarity index 72% rename from keybind/fabric/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java rename to keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KeyBindingRegisterImpl.java index d5764291..6e5565f2 100644 --- a/keybind/fabric/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java +++ b/keybinding/fabric/src/main/java/band/kessoku/lib/impl/keybinding/fabric/KeyBindingRegisterImpl.java @@ -13,22 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind.impl; +package band.kessoku.lib.impl.keybinding.fabric; -import band.kessoku.lib.keybind.api.KeyBindRegister; +import band.kessoku.lib.service.keybinding.client.KeyBindingRegisterService; import com.google.auto.service.AutoService; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.fabricmc.fabric.impl.client.keybinding.KeyBindingRegistryImpl; + import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; -@AutoService(KeyBindRegister.class) -public class KeyBindRegisterImpl implements KeyBindRegister { - @Override - public boolean addCategory(String categoryTranslationKey) { - return KeyBindingRegistryImpl.addCategory(categoryTranslationKey); - } +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +@AutoService(KeyBindingRegisterService.class) +public final class KeyBindingRegisterImpl implements KeyBindingRegisterService { @Override public KeyBinding register(KeyBinding keyBinding) { return KeyBindingHelper.registerKeyBinding(keyBinding); diff --git a/keybind/fabric/src/main/resources/fabric.mod.json b/keybinding/fabric/src/main/resources/fabric.mod.json similarity index 76% rename from keybind/fabric/src/main/resources/fabric.mod.json rename to keybinding/fabric/src/main/resources/fabric.mod.json index 6af6cfbb..7834baa1 100644 --- a/keybind/fabric/src/main/resources/fabric.mod.json +++ b/keybinding/fabric/src/main/resources/fabric.mod.json @@ -14,7 +14,15 @@ }, "license": "LGPL-3.0-only", "icon": "icon.png", - "environment": "*", + "entrypoints": { + "client": [ + "band.kessoku.lib.impl.keybinding.fabric.KessokuKeyBindingFabric" + ] + }, + "environment": "client", + "mixins": [ + "kessoku_key_binding.mixins.json" + ], "depends": { "fabricloader": ">=0.16.0", "minecraft": "1.21", diff --git a/keybinding/neo/build.gradle b/keybinding/neo/build.gradle new file mode 100644 index 00000000..23e36f3e --- /dev/null +++ b/keybinding/neo/build.gradle @@ -0,0 +1,13 @@ +import net.fabricmc.loom.util.ModPlatform + +apply from: rootProject.file("gradle/scripts/klib-neo.gradle") + +base.archivesName = rootProject.name + "-keybinding" + +kessoku { + module("base", "common") + module("base", "neo") + + common("keybinding", ModPlatform.NEOFORGE) + shadowBundle("keybinding", ModPlatform.NEOFORGE) +} diff --git a/keybind/neo/gradle.properties b/keybinding/neo/gradle.properties similarity index 100% rename from keybind/neo/gradle.properties rename to keybinding/neo/gradle.properties diff --git a/keybind/neo/src/main/java/band/kessoku/lib/keybind/KessokuKeyBindEntrypoint.java b/keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KessokuKeyBindingNeoforge.java similarity index 65% rename from keybind/neo/src/main/java/band/kessoku/lib/keybind/KessokuKeyBindEntrypoint.java rename to keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KessokuKeyBindingNeoforge.java index 08b76ae1..f5e20f5e 100644 --- a/keybind/neo/src/main/java/band/kessoku/lib/keybind/KessokuKeyBindEntrypoint.java +++ b/keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KessokuKeyBindingNeoforge.java @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind; +package band.kessoku.lib.impl.keybinding.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.impl.keybinding.client.KessokuKeybinding; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.keybind.impl.KeyBindRegisterImpl; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.fml.loading.FMLLoader; -@Mod(value = KessokuKeybind.MOD_ID, dist = Dist.CLIENT) -public class KessokuKeyBindEntrypoint { - public KessokuKeyBindEntrypoint(IEventBus modEventBus) { +@Mod(value = KessokuKeybinding.MOD_ID, dist = Dist.CLIENT) +public final class KessokuKeyBindingNeoforge { + public KessokuKeyBindingNeoforge(IEventBus modEventBus) { if (FMLLoader.getDist().isClient()) { - ModUtils.getLogger().info(KessokuKeybind.MARKER, "KessokuKeybind is loaded!"); - KeyBindRegisterImpl.registerEvent(modEventBus); + KessokuLib.loadModule(KessokuKeybinding.class); + KeyBindingRegisterImpl.registerEvent(modEventBus); } } } diff --git a/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java b/keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KeyBindingRegisterImpl.java similarity index 71% rename from keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java rename to keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KeyBindingRegisterImpl.java index 6e34c8ce..669351bc 100644 --- a/keybind/neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java +++ b/keybinding/neo/src/main/java/band/kessoku/lib/impl/keybinding/neoforge/KeyBindingRegisterImpl.java @@ -13,46 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind.impl; +package band.kessoku.lib.impl.keybinding.neoforge; -import band.kessoku.lib.event.util.NeoEventUtils; -import band.kessoku.lib.keybind.api.KeyBindRegister; -import band.kessoku.lib.keybind.mixin.KeyBindingAccessor; +import java.util.List; + +import band.kessoku.lib.api.base.neoforge.NeoEventUtils; +import band.kessoku.lib.api.keybinding.client.KeyBindingRegister; +import band.kessoku.lib.mixin.keybinding.client.KeyBindingAccessor; +import band.kessoku.lib.service.keybinding.client.KeyBindingRegisterService; import com.google.auto.service.AutoService; import it.unimi.dsi.fastutil.objects.ReferenceArrayList; + import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; + import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; -import java.util.List; -import java.util.Map; - -@AutoService(KeyBindRegister.class) -public class KeyBindRegisterImpl implements KeyBindRegister { +@AutoService(KeyBindingRegisterService.class) +public final class KeyBindingRegisterImpl implements KeyBindingRegisterService { private static final List KEY_BINDINGS = new ReferenceArrayList<>(); private static boolean processed; - /* Amarok Note: - Maybe Object2IntMap ...? - */ - private static Map getCategoryMap() { - return KeyBindingAccessor.kessoku$getCategoryMap(); - } - - @Override - public boolean addCategory(String categoryTranslationKey) { - Map map = getCategoryMap(); - - if (map.containsKey(categoryTranslationKey)) { - return false; - } - - final int largest = map.values().stream().max(Integer::compareTo).orElse(0); - map.put(categoryTranslationKey, largest + 1); - return true; - } - @Override public KeyBinding register(KeyBinding keyBinding) { if (processed) { @@ -68,7 +50,7 @@ public KeyBinding register(KeyBinding keyBinding) { } // This will do nothing if the category already exists. - addCategory(keyBinding.getCategory()); + KeyBindingRegister.addCategory(keyBinding.getCategory()); KEY_BINDINGS.add(keyBinding); return keyBinding; } diff --git a/keybind/neo/src/main/java/band/kessoku/lib/keybind/mixin/KeyBindingAccessor.java b/keybinding/neo/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingAccessor.java similarity index 82% rename from keybind/neo/src/main/java/band/kessoku/lib/keybind/mixin/KeyBindingAccessor.java rename to keybinding/neo/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingAccessor.java index 761b190d..3c47fcb8 100644 --- a/keybind/neo/src/main/java/band/kessoku/lib/keybind/mixin/KeyBindingAccessor.java +++ b/keybinding/neo/src/main/java/band/kessoku/lib/mixin/keybinding/client/KeyBindingAccessor.java @@ -13,22 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind.mixin; +package band.kessoku.lib.mixin.keybinding.client; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import java.util.Map; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; @Mixin(KeyBinding.class) public interface KeyBindingAccessor { - @Accessor("CATEGORY_ORDER_MAP") - static Map kessoku$getCategoryMap() { - throw new AssertionError(); - } - @Accessor("boundKey") InputUtil.Key kessoku$getBoundKey(); } diff --git a/keybind/neo/src/main/resources/META-INF/neoforge.mods.toml b/keybinding/neo/src/main/resources/META-INF/neoforge.mods.toml similarity index 72% rename from keybind/neo/src/main/resources/META-INF/neoforge.mods.toml rename to keybinding/neo/src/main/resources/META-INF/neoforge.mods.toml index 246deded..fe7fa585 100644 --- a/keybind/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/keybinding/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -4,7 +4,7 @@ license = "LGPL-3.0-only" issueTrackerURL = "https://github.com/KessokuTeaTime/KessokuLib/issues" [[mods]] -modId = "kessoku_keybind" +modId = "kessoku_key_binding" version = "${version}" displayName = "Kessoku Keybind" description = ''' @@ -15,16 +15,19 @@ authors = "Kessoku Tea Time" displayURL = "https://modrinth.com/mod/kessoku-lib" [[mixins]] -config = "kessoku-keybind.mixins.json" +config = "kessoku_key_binding.neoforge.mixins.json" -[[dependencies.kessoku_keybind]] +[[mixins]] +config = "kessoku_key_binding.mixins.json" + +[[dependencies.kessoku_key_binding]] modId = "neoforge" type = "required" versionRange = "[21.0,)" ordering = "NONE" side = "BOTH" -[[dependencies.kessoku_keybind]] +[[dependencies.kessoku_key_binding]] modId = "minecraft" type = "required" versionRange = "[1.21,)" diff --git a/keybind/neo/src/main/resources/kessoku-keybind.mixins.json b/keybinding/neo/src/main/resources/kessoku_key_binding.neoforge.mixins.json similarity index 72% rename from keybind/neo/src/main/resources/kessoku-keybind.mixins.json rename to keybinding/neo/src/main/resources/kessoku_key_binding.neoforge.mixins.json index ed56cb35..06bf55f4 100644 --- a/keybind/neo/src/main/resources/kessoku-keybind.mixins.json +++ b/keybinding/neo/src/main/resources/kessoku_key_binding.neoforge.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.keybind.mixin", + "package": "band.kessoku.lib.mixin.keybinding.client", "compatibilityLevel": "JAVA_17", "mixins": [ "KeyBindingAccessor" diff --git a/lifecycle-events/common/build.gradle b/lifecycle-events/common/build.gradle index ab52a22e..c1b73952 100644 --- a/lifecycle-events/common/build.gradle +++ b/lifecycle-events/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.events.lifecycle" base.archivesName = rootProject.name + "-lifecycle-events" kessoku { diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/LifecycleEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/LifecycleEvent.java similarity index 96% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/LifecycleEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/LifecycleEvent.java index 8da71c44..41d896c9 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/LifecycleEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/LifecycleEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.registry.DynamicRegistryManager; public class LifecycleEvent { diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerBlockEntityEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerBlockEntityEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerBlockEntityEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerBlockEntityEvent.java index be8f5023..7203cd1f 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerBlockEntityEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerBlockEntityEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.block.entity.BlockEntity; import net.minecraft.server.world.ServerWorld; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerChunkEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerChunkEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerChunkEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerChunkEvent.java index 56281165..c9313f14 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerChunkEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerChunkEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.server.world.ServerWorld; import net.minecraft.world.chunk.WorldChunk; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerEntityEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerEntityEvent.java similarity index 98% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerEntityEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerEntityEvent.java index 541e7f99..3c71839a 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerEntityEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerEntityEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerLifecycleEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerLifecycleEvent.java similarity index 99% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerLifecycleEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerLifecycleEvent.java index 83855139..ddef5e86 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerLifecycleEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerLifecycleEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.resource.LifecycledResourceManager; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerTickEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerTickEvent.java similarity index 98% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerTickEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerTickEvent.java index ff4ff747..83ab8c34 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerTickEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerTickEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerWorldEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerWorldEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerWorldEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerWorldEvent.java index ab56c956..786fd40c 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/ServerWorldEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/ServerWorldEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api; +package band.kessoku.lib.api.event.lifecycle; import band.kessoku.lib.event.api.Event; + import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientBlockEntityEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientBlockEntityEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientBlockEntityEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientBlockEntityEvent.java index 8236ef45..0ef4a1c8 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientBlockEntityEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientBlockEntityEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api.client; +package band.kessoku.lib.api.event.lifecycle.client; import band.kessoku.lib.event.api.Event; + import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.world.ClientWorld; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientChunkEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientChunkEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientChunkEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientChunkEvent.java index 902aa49e..37011043 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientChunkEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientChunkEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api.client; +package band.kessoku.lib.api.event.lifecycle.client; import band.kessoku.lib.event.api.Event; + import net.minecraft.client.world.ClientWorld; import net.minecraft.world.chunk.WorldChunk; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientEntityEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientEntityEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientEntityEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientEntityEvent.java index f7723e72..5fd99be4 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientEntityEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientEntityEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api.client; +package band.kessoku.lib.api.event.lifecycle.client; import band.kessoku.lib.event.api.Event; + import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientLifecycleEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientLifecycleEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientLifecycleEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientLifecycleEvent.java index c86a245b..b47508cc 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientLifecycleEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientLifecycleEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api.client; +package band.kessoku.lib.api.event.lifecycle.client; import band.kessoku.lib.event.api.Event; + import net.minecraft.client.MinecraftClient; public class ClientLifecycleEvent { diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientTickEvent.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientTickEvent.java similarity index 97% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientTickEvent.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientTickEvent.java index 16afe29a..d304cbd9 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/api/client/ClientTickEvent.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/api/event/lifecycle/client/ClientTickEvent.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.api.client; +package band.kessoku.lib.api.event.lifecycle.client; import band.kessoku.lib.event.api.Event; + import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEvents.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEvents.java deleted file mode 100644 index 0f761cb5..00000000 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEvents.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.events.lifecycle; - -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -public class KessokuLifecycleEvents { - public static final String MOD_ID = "kessoku_lifecycle_events"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuLifecycleEvents]"); -} diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImpl.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/KessokuLifecycleEvents.java similarity index 78% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImpl.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/KessokuLifecycleEvents.java index 9e6a35ea..2196de13 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImpl.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/KessokuLifecycleEvents.java @@ -13,19 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.impl; +package band.kessoku.lib.impl.event.lifecycle; + +import band.kessoku.lib.api.event.lifecycle.ServerBlockEntityEvent; +import band.kessoku.lib.api.event.lifecycle.ServerChunkEvent; +import band.kessoku.lib.api.event.lifecycle.ServerEntityEvent; +import band.kessoku.lib.api.event.lifecycle.ServerWorldEvent; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; -import band.kessoku.lib.events.lifecycle.api.ServerBlockEntityEvent; -import band.kessoku.lib.events.lifecycle.api.ServerChunkEvent; -import band.kessoku.lib.events.lifecycle.api.ServerEntityEvent; -import band.kessoku.lib.events.lifecycle.api.ServerWorldEvent; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.Entity; import net.minecraft.world.chunk.WorldChunk; -public class KessokuLifecycleEventsImpl { - public static void clientInit() { +public class KessokuLifecycleEvents { + public static final String MOD_ID = "kessoku_lifecycle_events"; + public static final String NAME = "Kessoku Lifecycle Events API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); + public static void clientInit() { } public static void init() { diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/LoadedChunksCache.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/LoadedChunksCache.java similarity index 95% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/LoadedChunksCache.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/LoadedChunksCache.java index 8a0140ef..bbeeb8c8 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/impl/LoadedChunksCache.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/impl/event/lifecycle/LoadedChunksCache.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.impl; - -import net.minecraft.world.chunk.WorldChunk; +package band.kessoku.lib.impl.event.lifecycle; import java.util.Set; +import net.minecraft.world.chunk.WorldChunk; + /** * A simple marker interface which holds references to chunks which block entities may be loaded or unloaded from. */ diff --git a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/mixin/WorldMixin.java b/lifecycle-events/common/src/main/java/band/kessoku/lib/mixin/lifecycle/WorldMixin.java similarity index 92% rename from lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/mixin/WorldMixin.java rename to lifecycle-events/common/src/main/java/band/kessoku/lib/mixin/lifecycle/WorldMixin.java index 68a19b0c..8adcacb6 100644 --- a/lifecycle-events/common/src/main/java/band/kessoku/lib/events/lifecycle/mixin/WorldMixin.java +++ b/lifecycle-events/common/src/main/java/band/kessoku/lib/mixin/lifecycle/WorldMixin.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin; +package band.kessoku.lib.mixin.lifecycle; -import band.kessoku.lib.events.lifecycle.impl.LoadedChunksCache; -import net.minecraft.world.World; -import net.minecraft.world.chunk.WorldChunk; +import java.util.HashSet; +import java.util.Set; + +import band.kessoku.lib.impl.event.lifecycle.LoadedChunksCache; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; -import java.util.HashSet; -import java.util.Set; +import net.minecraft.world.World; +import net.minecraft.world.chunk.WorldChunk; @Mixin(World.class) public abstract class WorldMixin implements LoadedChunksCache { diff --git a/lifecycle-events/common/src/main/resources/kessoku-lifecycle-events.mixins.json b/lifecycle-events/common/src/main/resources/kessoku_lifecycle_events.mixins.json similarity index 74% rename from lifecycle-events/common/src/main/resources/kessoku-lifecycle-events.mixins.json rename to lifecycle-events/common/src/main/resources/kessoku_lifecycle_events.mixins.json index 7c1fc2a6..45be2a58 100644 --- a/lifecycle-events/common/src/main/resources/kessoku-lifecycle-events.mixins.json +++ b/lifecycle-events/common/src/main/resources/kessoku_lifecycle_events.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.events.lifecycle.mixin", + "package": "band.kessoku.lib.mixin.lifecycle", "compatibilityLevel": "JAVA_17", "mixins": [ "WorldMixin" diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/CommonLifecycleTest.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/CommonLifecycleTest.java index beddeeb2..2dab231f 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/CommonLifecycleTest.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/CommonLifecycleTest.java @@ -15,8 +15,8 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.LifecycleEvent; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.LifecycleEvent; public class CommonLifecycleTest implements KessokuModInitializer { @Override diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/KessokuTestLifecycle.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/KessokuTestLifecycle.java index 7378a833..1cf93910 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/KessokuTestLifecycle.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/KessokuTestLifecycle.java @@ -15,9 +15,9 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.ServerChunkEvent; -import band.kessoku.lib.events.lifecycle.api.ServerLifecycleEvent; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.ServerChunkEvent; +import band.kessoku.lib.api.event.lifecycle.ServerLifecycleEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ResourceReloadTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ResourceReloadTests.java index 3aa84352..32e193e3 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ResourceReloadTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ResourceReloadTests.java @@ -15,8 +15,8 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.ServerLifecycleEvent; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.ServerLifecycleEvent; public class ResourceReloadTests implements KessokuModInitializer { @Override diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerBlockEntityTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerBlockEntityTests.java index 83d6ef65..b0f6fb15 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerBlockEntityTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerBlockEntityTests.java @@ -15,14 +15,15 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.ServerBlockEntityEvent; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.registry.Registries; - import java.util.ArrayList; import java.util.List; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.ServerBlockEntityEvent; + +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.registry.Registries; + public class ServerBlockEntityTests implements KessokuModInitializer { private final List serverBlockEntities = new ArrayList<>(); diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerEntityTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerEntityTests.java index 9267e48f..8caa2af8 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerEntityTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerEntityTests.java @@ -15,13 +15,14 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.ServerEntityEvent; -import net.minecraft.entity.Entity; - import java.util.ArrayList; import java.util.List; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.ServerEntityEvent; + +import net.minecraft.entity.Entity; + public class ServerEntityTests implements KessokuModInitializer { private final List serverEntities = new ArrayList<>(); diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerTickTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerTickTests.java index 3d7dfa89..90ba360d 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerTickTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/ServerTickTests.java @@ -15,14 +15,15 @@ */ package kessoku.testmod.lifecycle; -import band.kessoku.lib.entrypoint.api.KessokuModInitializer; -import band.kessoku.lib.events.lifecycle.api.ServerTickEvent; -import net.minecraft.registry.RegistryKey; -import net.minecraft.world.World; - import java.util.HashMap; import java.util.Map; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuModInitializer; +import band.kessoku.lib.api.event.lifecycle.ServerTickEvent; + +import net.minecraft.registry.RegistryKey; +import net.minecraft.world.World; + public class ServerTickTests implements KessokuModInitializer { private final Map, Integer> tickTracker = new HashMap<>(); diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientBlockEntityTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientBlockEntityTests.java index 1af76bc6..4b5b183c 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientBlockEntityTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientBlockEntityTests.java @@ -15,8 +15,8 @@ */ package kessoku.testmod.lifecycle.client; -import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; -import band.kessoku.lib.events.lifecycle.api.client.ClientBlockEntityEvent; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuClientModInitializer; +import band.kessoku.lib.api.event.lifecycle.client.ClientBlockEntityEvent; public class ClientBlockEntityTests implements KessokuClientModInitializer { @Override diff --git a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientChunkTests.java b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientChunkTests.java index 01437042..575d892d 100644 --- a/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientChunkTests.java +++ b/lifecycle-events/common/src/test/java/kessoku/testmod/lifecycle/client/ClientChunkTests.java @@ -15,8 +15,8 @@ */ package kessoku.testmod.lifecycle.client; -import band.kessoku.lib.entrypoint.api.KessokuClientModInitializer; -import band.kessoku.lib.events.lifecycle.api.client.ClientChunkEvent; +import band.kessoku.lib.api.entrypoint.entrypoints.KessokuClientModInitializer; +import band.kessoku.lib.api.event.lifecycle.client.ClientChunkEvent; public class ClientChunkTests implements KessokuClientModInitializer { @Override diff --git a/lifecycle-events/fabric/build.gradle b/lifecycle-events/fabric/build.gradle index b9a3b794..06afb824 100644 --- a/lifecycle-events/fabric/build.gradle +++ b/lifecycle-events/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.events.lifecycle" base.archivesName = rootProject.name + "-lifecycle-events" kessoku { diff --git a/lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java b/lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsFabric.java similarity index 66% rename from lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java rename to lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsFabric.java index 2dccd782..dd872426 100644 --- a/lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java +++ b/lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsFabric.java @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle; +package band.kessoku.lib.impl.event.lifecycle.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.impl.event.lifecycle.KessokuLifecycleEvents; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.events.lifecycle.impl.KessokuLifecycleEventsImplFabric; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; -public class KessokuLifecycleEventsEntrypoint implements ModInitializer, ClientModInitializer { +public class KessokuLifecycleEventsFabric implements ModInitializer, ClientModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded!"); + KessokuLib.loadModule(KessokuLifecycleEvents.class); KessokuLifecycleEventsImplFabric.registerCommonEvents(); } @Override public void onInitializeClient() { - ModUtils.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded on client!"); + KessokuLib.loadModule(KessokuLifecycleEvents.class); KessokuLifecycleEventsImplFabric.registerClientEvents(); } } diff --git a/lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplFabric.java b/lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsImplFabric.java similarity index 95% rename from lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplFabric.java rename to lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsImplFabric.java index f08462a7..0e939fa9 100644 --- a/lifecycle-events/fabric/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplFabric.java +++ b/lifecycle-events/fabric/src/main/java/band/kessoku/lib/impl/event/lifecycle/fabric/KessokuLifecycleEventsImplFabric.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.impl; +package band.kessoku.lib.impl.event.lifecycle.fabric; + +import band.kessoku.lib.api.event.lifecycle.*; +import band.kessoku.lib.api.event.lifecycle.client.*; +import band.kessoku.lib.impl.event.lifecycle.KessokuLifecycleEvents; -import band.kessoku.lib.events.lifecycle.api.*; -import band.kessoku.lib.events.lifecycle.api.client.*; import net.fabricmc.fabric.api.client.event.lifecycle.v1.*; import net.fabricmc.fabric.api.event.lifecycle.v1.*; public class KessokuLifecycleEventsImplFabric { public static void registerClientEvents() { - KessokuLifecycleEventsImpl.clientInit(); + KessokuLifecycleEvents.clientInit(); ClientLifecycleEvents.CLIENT_STARTED.register(client -> ClientLifecycleEvent.STARTED.invoker().onClientStarted(client)); ClientLifecycleEvents.CLIENT_STOPPING.register(client -> ClientLifecycleEvent.STOPPING.invoker().onClientStopping(client)); @@ -43,7 +45,7 @@ public static void registerClientEvents() { } public static void registerCommonEvents() { - KessokuLifecycleEventsImpl.init(); + KessokuLifecycleEvents.init(); CommonLifecycleEvents.TAGS_LOADED.register((registries, client) -> LifecycleEvent.TAG_LOADED.invoker().onTagsLoaded(registries, client)); diff --git a/lifecycle-events/fabric/src/main/resources/fabric.mod.json b/lifecycle-events/fabric/src/main/resources/fabric.mod.json index babb0eef..98afa6e7 100644 --- a/lifecycle-events/fabric/src/main/resources/fabric.mod.json +++ b/lifecycle-events/fabric/src/main/resources/fabric.mod.json @@ -17,10 +17,10 @@ "environment": "*", "entrypoints": { "main": [ - "band.kessoku.lib.events.lifecycle.KessokuLifecycleEventsEntrypoint::onInitialize" + "band.kessoku.lib.impl.event.lifecycle.fabric.KessokuLifecycleEventsFabric::onInitialize" ], "client": [ - "band.kessoku.lib.events.lifecycle.KessokuLifecycleEventsEntrypoint::onInitializeClient" + "band.kessoku.lib.impl.event.lifecycle.fabric.KessokuLifecycleEventsFabric::onInitializeClient" ] }, "depends": { @@ -30,7 +30,7 @@ "fabric-api": "*" }, "mixins": [ - "kessoku-lifecycle-events.mixins.json" + "kessoku_lifecycle_events.mixins.json" ], "custom": { "modmenu": { diff --git a/lifecycle-events/neo/build.gradle b/lifecycle-events/neo/build.gradle index dae86a10..266e8fee 100644 --- a/lifecycle-events/neo/build.gradle +++ b/lifecycle-events/neo/build.gradle @@ -2,21 +2,20 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.events.lifecycle" base.archivesName = rootProject.name + "-lifecycle-events" loom { - accessWidenerPath = file("src/main/resources/kessoku-lifecycle-events.accesswidener") + accessWidenerPath = file("src/main/resources/kessoku_lifecycle_events.accesswidener") } kessoku { modules(["base", "event-base"], "common") - module("event-base", "neo") + module("base", "neo") common("lifecycle-events", ModPlatform.NEOFORGE) shadowBundle("lifecycle-events", ModPlatform.NEOFORGE) } remapJar { - atAccessWideners.add("kessoku-lifecycle-events.accesswidener") + atAccessWideners.add("kessoku_lifecycle_events.accesswidener") } diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplNeo.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsImplNeo.java similarity index 88% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplNeo.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsImplNeo.java index 29facebc..c504c26d 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/impl/KessokuLifecycleEventsImplNeo.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsImplNeo.java @@ -13,16 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.impl; +package band.kessoku.lib.impl.event.lifecycle.neoforge; + +import band.kessoku.lib.api.base.neoforge.NeoEventUtils; +import band.kessoku.lib.api.event.lifecycle.*; +import band.kessoku.lib.api.event.lifecycle.client.ClientChunkEvent; +import band.kessoku.lib.impl.event.lifecycle.KessokuLifecycleEvents; -import band.kessoku.lib.event.util.NeoEventUtils; -import band.kessoku.lib.events.lifecycle.api.*; -import band.kessoku.lib.events.lifecycle.api.client.ClientChunkEvent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.world.chunk.WorldChunk; + import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.event.OnDatapackSyncEvent; @@ -38,7 +41,7 @@ public class KessokuLifecycleEventsImplNeo { public static void registerClientEvents(IEventBus forgeEventBus) { - KessokuLifecycleEventsImpl.clientInit(); + KessokuLifecycleEvents.clientInit(); NeoEventUtils.registerEvent(forgeEventBus, ChunkEvent.Load.class, event -> { if (event.getLevel() instanceof ClientWorld world && event.getChunk() instanceof WorldChunk chunk) { @@ -52,26 +55,26 @@ public static void registerClientEvents(IEventBus forgeEventBus) { }); NeoEventUtils.registerEvent(forgeEventBus, ClientTickEvent.Pre.class, event -> { - band.kessoku.lib.events.lifecycle.api.client.ClientTickEvent.START_CLIENT_TICK.invoker().onStartTick(MinecraftClient.getInstance()); + band.kessoku.lib.api.event.lifecycle.client.ClientTickEvent.START_CLIENT_TICK.invoker().onStartTick(MinecraftClient.getInstance()); }); NeoEventUtils.registerEvent(forgeEventBus, ClientTickEvent.Post.class, event -> { - band.kessoku.lib.events.lifecycle.api.client.ClientTickEvent.END_CLIENT_TICK.invoker().onEndTick(MinecraftClient.getInstance()); + band.kessoku.lib.api.event.lifecycle.client.ClientTickEvent.END_CLIENT_TICK.invoker().onEndTick(MinecraftClient.getInstance()); }); NeoEventUtils.registerEvent(forgeEventBus, LevelTickEvent.Pre.class, event -> { if (event.getLevel() instanceof ClientWorld world) { - band.kessoku.lib.events.lifecycle.api.client.ClientTickEvent.START_WORLD_TICK.invoker().onStartTick(world); + band.kessoku.lib.api.event.lifecycle.client.ClientTickEvent.START_WORLD_TICK.invoker().onStartTick(world); } }); NeoEventUtils.registerEvent(forgeEventBus, LevelTickEvent.Post.class, event -> { if (event.getLevel() instanceof ClientWorld world) { - band.kessoku.lib.events.lifecycle.api.client.ClientTickEvent.END_WORLD_TICK.invoker().onEndTick(world); + band.kessoku.lib.api.event.lifecycle.client.ClientTickEvent.END_WORLD_TICK.invoker().onEndTick(world); } }); } public static void registerCommonEvents(IEventBus forgeEventBus) { - KessokuLifecycleEventsImpl.init(); + KessokuLifecycleEvents.init(); NeoEventUtils.registerEvent(forgeEventBus, TagsUpdatedEvent.class, event -> { LifecycleEvent.TAG_LOADED.invoker().onTagsLoaded(event.getRegistryAccess(), event.getUpdateCause() == TagsUpdatedEvent.UpdateCause.CLIENT_PACKET_RECEIVED); diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsNeoforge.java similarity index 67% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsNeoforge.java index 16f01db3..762cf958 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/KessokuLifecycleEventsEntrypoint.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/impl/event/lifecycle/neoforge/KessokuLifecycleEventsNeoforge.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle; +package band.kessoku.lib.impl.event.lifecycle.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.impl.event.lifecycle.KessokuLifecycleEvents; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.events.lifecycle.impl.KessokuLifecycleEventsImplNeo; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; @@ -24,13 +25,13 @@ import net.neoforged.neoforge.common.NeoForge; @Mod(KessokuLifecycleEvents.MOD_ID) -public class KessokuLifecycleEventsEntrypoint { - public KessokuLifecycleEventsEntrypoint(IEventBus modEventBus, ModContainer modContainer) { +public class KessokuLifecycleEventsNeoforge { + public KessokuLifecycleEventsNeoforge(IEventBus modEventBus, ModContainer modContainer) { var forgeEventBus = NeoForge.EVENT_BUS; - ModUtils.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded!"); + KessokuLib.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded!"); KessokuLifecycleEventsImplNeo.registerCommonEvents(forgeEventBus); if (FMLLoader.getDist().isClient()) { - ModUtils.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded on client!"); + KessokuLib.getLogger().info(KessokuLifecycleEvents.MARKER, "KessokuLib-LifecycleEvents is loaded on client!"); KessokuLifecycleEventsImplNeo.registerClientEvents(forgeEventBus); } } diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/MinecraftServerMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/MinecraftServerMixin.java similarity index 95% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/MinecraftServerMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/MinecraftServerMixin.java index 4d736c41..3fd95812 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/MinecraftServerMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/MinecraftServerMixin.java @@ -13,18 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo; +package band.kessoku.lib.mixin.event.lifecycle.neoforge; -import band.kessoku.lib.events.lifecycle.api.ServerLifecycleEvent; -import net.minecraft.server.MinecraftServer; +import java.util.Collection; +import java.util.concurrent.CompletableFuture; + +import band.kessoku.lib.api.event.lifecycle.ServerLifecycleEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.Collection; -import java.util.concurrent.CompletableFuture; +import net.minecraft.server.MinecraftServer; @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerEntityHandlerMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerEntityHandlerMixin.java similarity index 93% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerEntityHandlerMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerEntityHandlerMixin.java index c7de6c17..ef6e8adf 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerEntityHandlerMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerEntityHandlerMixin.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo; +package band.kessoku.lib.mixin.event.lifecycle.neoforge; -import band.kessoku.lib.events.lifecycle.api.ServerEntityEvent; -import net.minecraft.entity.Entity; -import net.minecraft.server.world.ServerWorld; +import band.kessoku.lib.api.event.lifecycle.ServerEntityEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,6 +23,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; + @Mixin(targets = "net/minecraft/server/world/ServerWorld$ServerEntityHandler") public class ServerEntityHandlerMixin { // final synthetic Lnet/minecraft/server/world/ServerWorld; field_26936 diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerWorldMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerWorldMixin.java similarity index 93% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerWorldMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerWorldMixin.java index 2689b8ce..3c94a5c2 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/ServerWorldMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/ServerWorldMixin.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo; +package band.kessoku.lib.mixin.event.lifecycle.neoforge; -import band.kessoku.lib.events.lifecycle.api.ServerTickEvent; -import net.minecraft.server.world.ServerWorld; +import java.util.function.BooleanSupplier; + +import band.kessoku.lib.api.event.lifecycle.ServerTickEvent; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.function.BooleanSupplier; +import net.minecraft.server.world.ServerWorld; @Mixin(ServerWorld.class) public abstract class ServerWorldMixin { diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientChunkManagerMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientChunkManagerMixin.java similarity index 95% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientChunkManagerMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientChunkManagerMixin.java index bc38d367..57870571 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientChunkManagerMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientChunkManagerMixin.java @@ -13,16 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.client; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.client; -import band.kessoku.lib.events.lifecycle.api.client.ClientChunkEvent; -import net.minecraft.client.world.ClientChunkManager; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.ChunkData; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.chunk.WorldChunk; +import java.util.function.Consumer; + +import band.kessoku.lib.api.event.lifecycle.client.ClientChunkEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -32,7 +27,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.util.function.Consumer; +import net.minecraft.client.world.ClientChunkManager; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.play.ChunkData; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.chunk.WorldChunk; @Mixin(ClientChunkManager.class) public abstract class ClientChunkManagerMixin { diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientEntityHandlerMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientEntityHandlerMixin.java similarity index 93% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientEntityHandlerMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientEntityHandlerMixin.java index 86012919..d09dca24 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientEntityHandlerMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientEntityHandlerMixin.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.client; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.client; -import band.kessoku.lib.events.lifecycle.api.client.ClientEntityEvent; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.Entity; +import band.kessoku.lib.api.event.lifecycle.client.ClientEntityEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,6 +23,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; + @Mixin(targets = "net/minecraft/client/world/ClientWorld$ClientEntityHandler") public class ClientEntityHandlerMixin { // final synthetic Lnet/minecraft/client/world/ClientWorld; field_27735 diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientPlayNetworkHandlerMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientPlayNetworkHandlerMixin.java similarity index 93% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientPlayNetworkHandlerMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientPlayNetworkHandlerMixin.java index f3007179..43454762 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/ClientPlayNetworkHandlerMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/ClientPlayNetworkHandlerMixin.java @@ -13,11 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.client; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.client; + +import band.kessoku.lib.api.event.lifecycle.client.ClientBlockEntityEvent; +import band.kessoku.lib.api.event.lifecycle.client.ClientEntityEvent; +import band.kessoku.lib.impl.event.lifecycle.LoadedChunksCache; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import band.kessoku.lib.events.lifecycle.api.client.ClientBlockEntityEvent; -import band.kessoku.lib.events.lifecycle.api.client.ClientEntityEvent; -import band.kessoku.lib.events.lifecycle.impl.LoadedChunksCache; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.world.ClientWorld; @@ -25,11 +31,6 @@ import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; import net.minecraft.world.chunk.WorldChunk; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPlayNetworkHandler.class) abstract class ClientPlayNetworkHandlerMixin { diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/MinecraftClientMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/MinecraftClientMixin.java similarity index 92% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/MinecraftClientMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/MinecraftClientMixin.java index 5a726575..357fec64 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/MinecraftClientMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/MinecraftClientMixin.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.client; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.client; -import band.kessoku.lib.events.lifecycle.api.client.ClientLifecycleEvent; -import net.minecraft.client.MinecraftClient; +import band.kessoku.lib.api.event.lifecycle.client.ClientLifecycleEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.MinecraftClient; + @Mixin(MinecraftClient.class) public abstract class MinecraftClientMixin { @Inject(at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;)V", shift = At.Shift.AFTER, remap = false), method = "stop") diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/WorldChunkMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/WorldChunkMixin.java similarity index 96% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/WorldChunkMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/WorldChunkMixin.java index f259450f..8f6d4fd7 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/client/WorldChunkMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/client/WorldChunkMixin.java @@ -13,17 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.client; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.client; -import band.kessoku.lib.events.lifecycle.api.ServerBlockEntityEvent; -import band.kessoku.lib.events.lifecycle.api.client.ClientBlockEntityEvent; +import java.util.Map; + +import band.kessoku.lib.api.event.lifecycle.ServerBlockEntityEvent; +import band.kessoku.lib.api.event.lifecycle.client.ClientBlockEntityEvent; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.WorldChunk; import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; @@ -35,7 +31,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.util.Map; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.WorldChunk; @Mixin(WorldChunk.class) abstract class WorldChunkMixin { diff --git a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/server/WorldChunkMixin.java b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/server/WorldChunkMixin.java similarity index 97% rename from lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/server/WorldChunkMixin.java rename to lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/server/WorldChunkMixin.java index 89e7101e..1a245c75 100644 --- a/lifecycle-events/neo/src/main/java/band/kessoku/lib/events/lifecycle/mixin/neo/server/WorldChunkMixin.java +++ b/lifecycle-events/neo/src/main/java/band/kessoku/lib/mixin/event/lifecycle/neoforge/server/WorldChunkMixin.java @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.events.lifecycle.mixin.neo.server; +package band.kessoku.lib.mixin.event.lifecycle.neoforge.server; -import band.kessoku.lib.events.lifecycle.api.ServerBlockEntityEvent; +import java.util.Map; + +import band.kessoku.lib.api.event.lifecycle.ServerBlockEntityEvent; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.WorldChunk; import org.jetbrains.annotations.Nullable; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; @@ -33,7 +30,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.util.Map; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.WorldChunk; /** * This is a server only mixin for good reason: diff --git a/lifecycle-events/neo/src/main/resources/META-INF/neoforge.mods.toml b/lifecycle-events/neo/src/main/resources/META-INF/neoforge.mods.toml index 7267445e..41778550 100644 --- a/lifecycle-events/neo/src/main/resources/META-INF/neoforge.mods.toml +++ b/lifecycle-events/neo/src/main/resources/META-INF/neoforge.mods.toml @@ -15,10 +15,10 @@ authors = "Kessoku Tea Time" displayURL = "https://modrinth.com/mod/kessoku-lib" [[mixins]] -config = "kessoku-lifecycle-events.mixins.json" +config = "kessoku_lifecycle-events.mixins.json" [[mixins]] -config = "kessoku-lifecycle-events.neo.mixins.json" +config = "kessoku_lifecycle_events.neoforge.mixins.json" [[accessTransformers]] file = "META-INF/accesstransformer.cfg" diff --git a/lifecycle-events/neo/src/main/resources/kessoku-lifecycle-events.accesswidener b/lifecycle-events/neo/src/main/resources/kessoku_lifecycle_events.accesswidener similarity index 100% rename from lifecycle-events/neo/src/main/resources/kessoku-lifecycle-events.accesswidener rename to lifecycle-events/neo/src/main/resources/kessoku_lifecycle_events.accesswidener diff --git a/lifecycle-events/neo/src/main/resources/kessoku-lifecycle-events.neo.mixins.json b/lifecycle-events/neo/src/main/resources/kessoku_lifecycle_events.neoforge.mixins.json similarity index 88% rename from lifecycle-events/neo/src/main/resources/kessoku-lifecycle-events.neo.mixins.json rename to lifecycle-events/neo/src/main/resources/kessoku_lifecycle_events.neoforge.mixins.json index 8c4c7bb7..8bbf62a3 100644 --- a/lifecycle-events/neo/src/main/resources/kessoku-lifecycle-events.neo.mixins.json +++ b/lifecycle-events/neo/src/main/resources/kessoku_lifecycle_events.neoforge.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.events.lifecycle.mixin.neo", + "package": "band.kessoku.lib.mixin.event.lifecycle.neoforge", "compatibilityLevel": "JAVA_17", "mixins": [ "MinecraftServerMixin", diff --git a/platform/common/build.gradle b/platform/common/build.gradle index 186e6f2f..dfef799c 100644 --- a/platform/common/build.gradle +++ b/platform/common/build.gradle @@ -1,6 +1,5 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.platform" base.archivesName = rootProject.name + "-platform" kessoku { diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/api/Env.java b/platform/common/src/main/java/band/kessoku/lib/api/platform/Env.java similarity index 94% rename from platform/common/src/main/java/band/kessoku/lib/platform/api/Env.java rename to platform/common/src/main/java/band/kessoku/lib/api/platform/Env.java index 4f5b6d2e..b8b774d4 100644 --- a/platform/common/src/main/java/band/kessoku/lib/platform/api/Env.java +++ b/platform/common/src/main/java/band/kessoku/lib/api/platform/Env.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.api; +package band.kessoku.lib.api.platform; public enum Env { CLIENT, diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/KessokuPlatform.java b/platform/common/src/main/java/band/kessoku/lib/api/platform/KessokuPlatform.java similarity index 80% rename from platform/common/src/main/java/band/kessoku/lib/platform/KessokuPlatform.java rename to platform/common/src/main/java/band/kessoku/lib/api/platform/KessokuPlatform.java index c4d0958f..bb116487 100644 --- a/platform/common/src/main/java/band/kessoku/lib/platform/KessokuPlatform.java +++ b/platform/common/src/main/java/band/kessoku/lib/api/platform/KessokuPlatform.java @@ -13,12 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform; +package band.kessoku.lib.api.platform; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuPlatform { +public final class KessokuPlatform { + private KessokuPlatform() { + } + public static final String MOD_ID = "kessoku_platform"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuPlatform]"); + public static final String NAME = "Kessoku Platform API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); } diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModData.java b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModData.java similarity index 98% rename from platform/common/src/main/java/band/kessoku/lib/platform/api/ModData.java rename to platform/common/src/main/java/band/kessoku/lib/api/platform/ModData.java index 3f78b239..321f2218 100644 --- a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModData.java +++ b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModData.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.api; +package band.kessoku.lib.api.platform; import java.nio.file.Path; import java.util.Collection; @@ -25,10 +25,12 @@ public interface ModData { * Returns the mod's ID. */ String getModId(); + /** * Returns the mod's version. */ String getVersion(); + /** * Returns all of the mod's dependencies. */ @@ -43,6 +45,7 @@ public interface ModData { * Get the description of the mod. */ String getDescription(); + /** * Returns the mod's authors. */ diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModDependencyInfo.java b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModDependencyInfo.java similarity index 94% rename from platform/common/src/main/java/band/kessoku/lib/platform/api/ModDependencyInfo.java rename to platform/common/src/main/java/band/kessoku/lib/api/platform/ModDependencyInfo.java index d0f212f2..e98d16e2 100644 --- a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModDependencyInfo.java +++ b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModDependencyInfo.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.api; +package band.kessoku.lib.api.platform; +import band.kessoku.lib.service.platform.ModLoaderService; import org.jetbrains.annotations.Nullable; public interface ModDependencyInfo { @@ -22,6 +23,7 @@ public interface ModDependencyInfo { * Get the kind of dependency. */ DependencyKind getKind(); + /** * Returns the ID of the mod to check. */ @@ -88,7 +90,7 @@ public boolean isSoft() { */ @Nullable public String getKey() { - return ModLoader.getInstance().isFabric() ? fabricKey : neoKey; + return ModLoaderService.getInstance().isFabric() ? fabricKey : neoKey; } } } diff --git a/platform/common/src/main/java/band/kessoku/lib/api/platform/ModLoader.java b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModLoader.java new file mode 100644 index 00000000..7dec0e5c --- /dev/null +++ b/platform/common/src/main/java/band/kessoku/lib/api/platform/ModLoader.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.api.platform; + +import java.nio.file.Path; +import java.util.Collection; + +import band.kessoku.lib.service.platform.ModLoaderService; + +public final class ModLoader { + private ModLoader() { + } + + public static ModData getModData(String modid) { + return ModLoaderService.getInstance().getModData(modid); + } + + public static boolean isFabric() { + return ModLoaderService.getInstance().isFabric(); + } + + public static boolean isNeoForge() { + return ModLoaderService.getInstance().isNeoForge(); + } + + public static Env getEnv() { + return ModLoaderService.getInstance().getEnv(); + } + + public static Path getGameFolder() { + return ModLoaderService.getInstance().getGameFolder(); + } + + public static Path getConfigFolder() { + return ModLoaderService.getInstance().getConfigFolder(); + } + + public static Path getModsFolder() { + return ModLoaderService.getInstance().getModsFolder(); + } + + public static boolean isModLoaded(String id) { + return ModLoaderService.getInstance().isModLoaded(id); + } + + public static Collection getModIds() { + return ModLoaderService.getInstance().getModIds(); + } + + public static Collection getMods() { + return ModLoaderService.getInstance().getMods(); + } + + public static boolean isDevEnv() { + return ModLoaderService.getInstance().isDevEnv(); + } +} diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/impl/KessokuPlatformServices.java b/platform/common/src/main/java/band/kessoku/lib/platform/impl/KessokuPlatformServices.java deleted file mode 100644 index 20dff52a..00000000 --- a/platform/common/src/main/java/band/kessoku/lib/platform/impl/KessokuPlatformServices.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.platform.impl; - -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.platform.api.ModLoader; - -public class KessokuPlatformServices { - private static final ModLoader modLoader = ModUtils.loadService(ModLoader.class); - - public static ModLoader getModLoader() { - return modLoader; - } -} diff --git a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java b/platform/common/src/main/java/band/kessoku/lib/service/platform/ModLoaderService.java similarity index 75% rename from platform/common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java rename to platform/common/src/main/java/band/kessoku/lib/service/platform/ModLoaderService.java index b7fef091..6b71ec32 100644 --- a/platform/common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java +++ b/platform/common/src/main/java/band/kessoku/lib/service/platform/ModLoaderService.java @@ -13,27 +13,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.api; - -import band.kessoku.lib.platform.impl.KessokuPlatformServices; +package band.kessoku.lib.service.platform; import java.nio.file.Path; import java.util.Collection; -public interface ModLoader { - static ModLoader getInstance() { - return KessokuPlatformServices.getModLoader(); +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.platform.Env; +import band.kessoku.lib.api.platform.ModData; + +public interface ModLoaderService { + static ModLoaderService getInstance() { + return KessokuLib.loadService(ModLoaderService.class); } ModData getModData(String modid); + boolean isFabric(); + boolean isNeoForge(); + Env getEnv(); + Path getGameFolder(); + Path getConfigFolder(); + Path getModsFolder(); + boolean isModLoaded(String id); + Collection getModIds(); + Collection getMods(); + boolean isDevEnv(); } diff --git a/platform/fabric/build.gradle b/platform/fabric/build.gradle index 45298d91..ca35cd19 100644 --- a/platform/fabric/build.gradle +++ b/platform/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.platform" base.archivesName = rootProject.name + "-platform" kessoku { diff --git a/platform/fabric/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/KessokuPlatformFabric.java similarity index 72% rename from platform/fabric/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java rename to platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/KessokuPlatformFabric.java index 1ba1bcf0..2ff617f2 100644 --- a/platform/fabric/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java +++ b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/KessokuPlatformFabric.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform; +package band.kessoku.lib.impl.platform.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.platform.KessokuPlatform; -import band.kessoku.lib.base.ModUtils; import net.fabricmc.api.ModInitializer; -public class KessokuPlatformEntrypoint implements ModInitializer { +public final class KessokuPlatformFabric implements ModInitializer { @Override public void onInitialize() { - ModUtils.getLogger().info(KessokuPlatform.MARKER, "KessokuLib-Platform is loaded!"); + KessokuLib.loadModule(KessokuPlatform.class); } } diff --git a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDataImpl.java similarity index 93% rename from platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java rename to platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDataImpl.java index d0bf3a56..0d855670 100644 --- a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java +++ b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDataImpl.java @@ -13,14 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; - -import band.kessoku.lib.platform.api.ModData; -import band.kessoku.lib.platform.api.ModDependencyInfo; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; -import net.fabricmc.loader.api.metadata.ModMetadata; -import net.fabricmc.loader.api.metadata.Person; +package band.kessoku.lib.impl.platform.fabric; import java.nio.file.Path; import java.util.Collection; @@ -28,7 +21,15 @@ import java.util.Optional; import java.util.stream.Collectors; -public class ModDataImpl implements ModData { +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.api.platform.ModDependencyInfo; + +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.metadata.ModMetadata; +import net.fabricmc.loader.api.metadata.Person; + +public final class ModDataImpl implements ModData { private final ModContainer modContainer; private final ModMetadata modMetadata; @@ -36,6 +37,7 @@ public ModDataImpl(String modid) { this.modContainer = FabricLoader.getInstance().getModContainer(modid).orElseThrow(); this.modMetadata = modContainer.getMetadata(); } + public ModDataImpl(ModContainer container) { this.modContainer = container; this.modMetadata = modContainer.getMetadata(); diff --git a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDependencyInfoImpl.java similarity index 59% rename from platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java rename to platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDependencyInfoImpl.java index 0d9767a4..8590b719 100644 --- a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java +++ b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModDependencyInfoImpl.java @@ -13,36 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; +package band.kessoku.lib.impl.platform.fabric; + +import band.kessoku.lib.api.platform.ModDependencyInfo; -import band.kessoku.lib.platform.api.ModDependencyInfo; import net.fabricmc.loader.api.metadata.ModDependency; -public class ModDependencyInfoImpl implements ModDependencyInfo { +public final class ModDependencyInfoImpl implements ModDependencyInfo { private final ModDependency value; + public ModDependencyInfoImpl(ModDependency dependency) { this.value = dependency; } + @Override public DependencyKind getKind() { - switch (value.getKind()) { - case DEPENDS -> { - return DependencyKind.DEPENDS; - } - case RECOMMENDS -> { - return DependencyKind.RECOMMENDS; - } - case SUGGESTS -> { - return DependencyKind.SUGGESTS; - } - case CONFLICTS -> { - return DependencyKind.CONFLICTS; - } - case BREAKS -> { - return DependencyKind.BREAKS; - } - } - return null; + return switch (value.getKind()) { + case DEPENDS -> DependencyKind.DEPENDS; + case RECOMMENDS -> DependencyKind.RECOMMENDS; + case SUGGESTS -> DependencyKind.SUGGESTS; + case CONFLICTS -> DependencyKind.CONFLICTS; + case BREAKS -> DependencyKind.BREAKS; + }; } @Override diff --git a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModLoaderImpl.java similarity index 80% rename from platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java rename to platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModLoaderImpl.java index f5e27ff6..323f774d 100644 --- a/platform/fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java +++ b/platform/fabric/src/main/java/band/kessoku/lib/impl/platform/fabric/ModLoaderImpl.java @@ -13,24 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; +package band.kessoku.lib.impl.platform.fabric; -import band.kessoku.lib.platform.api.Env; -import band.kessoku.lib.platform.api.ModData; -import band.kessoku.lib.platform.api.ModLoader; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import band.kessoku.lib.api.platform.Env; +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.service.platform.ModLoaderService; import com.google.auto.service.AutoService; + import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.ModMetadata; -import java.nio.file.Path; -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@AutoService(ModLoader.class) -public class ModLoaderImpl implements ModLoader { +@AutoService(ModLoaderService.class) +public final class ModLoaderImpl implements ModLoaderService { private final Map modDataMap = new ConcurrentHashMap<>(); @Override @@ -75,12 +76,12 @@ public boolean isModLoaded(String id) { @Override public Collection getModIds() { - return FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).map(ModMetadata::getId).toList(); + return FabricLoader.getInstance().getAllMods().parallelStream().map(ModContainer::getMetadata).map(ModMetadata::getId).toList(); } @Override public Collection getMods() { - return FabricLoader.getInstance().getAllMods().stream().map(ModDataImpl::new).toList(); + return FabricLoader.getInstance().getAllMods().parallelStream().map(ModDataImpl::new).toList(); } @Override diff --git a/platform/fabric/src/main/resources/fabric.mod.json b/platform/fabric/src/main/resources/fabric.mod.json index 800a7029..0c8cd38c 100644 --- a/platform/fabric/src/main/resources/fabric.mod.json +++ b/platform/fabric/src/main/resources/fabric.mod.json @@ -17,7 +17,7 @@ "environment": "*", "entrypoints": { "main": [ - "band.kessoku.lib.platform.KessokuPlatformEntrypoint" + "band.kessoku.lib.impl.platform.fabric.KessokuPlatformFabric" ] }, "depends": { diff --git a/platform/neo/build.gradle b/platform/neo/build.gradle index 6bb585aa..11e6b374 100644 --- a/platform/neo/build.gradle +++ b/platform/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.platform" base.archivesName = rootProject.name + "-platform" kessoku { diff --git a/platform/neo/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/KessokuPlatformNeoforge.java similarity index 71% rename from platform/neo/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java rename to platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/KessokuPlatformNeoforge.java index c34ea948..581477c8 100644 --- a/platform/neo/src/main/java/band/kessoku/lib/platform/KessokuPlatformEntrypoint.java +++ b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/KessokuPlatformNeoforge.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform; +package band.kessoku.lib.impl.platform.neoforge; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.platform.KessokuPlatform; -import band.kessoku.lib.base.ModUtils; import net.neoforged.fml.common.Mod; @Mod(KessokuPlatform.MOD_ID) -public class KessokuPlatformEntrypoint { - public KessokuPlatformEntrypoint() { - ModUtils.getLogger().info(KessokuPlatform.MARKER, "KessokuLib-Platform is loaded!"); +public final class KessokuPlatformNeoforge { + public KessokuPlatformNeoforge() { + KessokuLib.loadModule(KessokuPlatform.class); } } diff --git a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDataImpl.java similarity index 94% rename from platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java rename to platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDataImpl.java index 50f71a4a..3b8038c8 100644 --- a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDataImpl.java +++ b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDataImpl.java @@ -13,15 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; - -import band.kessoku.lib.platform.api.ModData; -import band.kessoku.lib.platform.api.ModDependencyInfo; -import net.neoforged.fml.ModContainer; -import net.neoforged.fml.ModList; -import net.neoforged.fml.loading.moddiscovery.ModFileInfo; -import net.neoforged.neoforgespi.language.IModFileInfo; -import net.neoforged.neoforgespi.language.IModInfo; +package band.kessoku.lib.impl.platform.neoforge; import java.nio.file.Files; import java.nio.file.Path; @@ -30,7 +22,16 @@ import java.util.List; import java.util.Optional; -public class ModDataImpl implements ModData { +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.api.platform.ModDependencyInfo; + +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.moddiscovery.ModFileInfo; +import net.neoforged.neoforgespi.language.IModFileInfo; +import net.neoforged.neoforgespi.language.IModInfo; + +public final class ModDataImpl implements ModData { private final ModContainer modContainer; private final IModInfo modInfo; diff --git a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDependencyInfoImpl.java similarity index 88% rename from platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java rename to platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDependencyInfoImpl.java index 2b202b06..c7913199 100644 --- a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModDependencyInfoImpl.java +++ b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModDependencyInfoImpl.java @@ -13,16 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; +package band.kessoku.lib.impl.platform.neoforge; + +import band.kessoku.lib.api.platform.ModDependencyInfo; -import band.kessoku.lib.platform.api.ModDependencyInfo; import net.neoforged.neoforgespi.language.IModInfo; -public class ModDependencyInfoImpl implements ModDependencyInfo { +public final class ModDependencyInfoImpl implements ModDependencyInfo { private final IModInfo.ModVersion value; + public ModDependencyInfoImpl(IModInfo.ModVersion modVersion) { this.value = modVersion; } + @Override public DependencyKind getKind() { return switch (value.getType()) { diff --git a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModLoaderImpl.java similarity index 81% rename from platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java rename to platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModLoaderImpl.java index 525796cf..cad8b2df 100644 --- a/platform/neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java +++ b/platform/neo/src/main/java/band/kessoku/lib/impl/platform/neoforge/ModLoaderImpl.java @@ -13,24 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.platform.impl; +package band.kessoku.lib.impl.platform.neoforge; -import band.kessoku.lib.platform.api.Env; -import band.kessoku.lib.platform.api.ModData; -import band.kessoku.lib.platform.api.ModLoader; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import band.kessoku.lib.api.platform.Env; +import band.kessoku.lib.api.platform.ModData; +import band.kessoku.lib.service.platform.ModLoaderService; import com.google.auto.service.AutoService; + import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLLoader; import net.neoforged.fml.loading.FMLPaths; import net.neoforged.neoforgespi.language.IModInfo; -import java.nio.file.Path; -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@AutoService(ModLoader.class) -public class ModLoaderImpl implements ModLoader { +@AutoService(ModLoaderService.class) +public final class ModLoaderImpl implements ModLoaderService { private final Map modDataMap = new ConcurrentHashMap<>(); @Override @@ -75,12 +76,12 @@ public boolean isModLoaded(String id) { @Override public Collection getModIds() { - return ModList.get().getMods().stream().map(IModInfo::getModId).toList(); + return ModList.get().getMods().parallelStream().map(IModInfo::getModId).toList(); } @Override public Collection getMods() { - return ModList.get().getMods().stream().map(ModDataImpl::new).toList(); + return ModList.get().getMods().parallelStream().map(ModDataImpl::new).toList(); } @Override diff --git a/registry/common/build.gradle b/registry/common/build.gradle index c0183cf8..096e500d 100644 --- a/registry/common/build.gradle +++ b/registry/common/build.gradle @@ -1,10 +1,9 @@ apply from: rootProject.file("gradle/scripts/klib-common.gradle") -group = "band.kessoku.lib.registry" base.archivesName = rootProject.name + "-registry" loom { - accessWidenerPath = file("src/main/resources/kessoku-registry.accesswidener") + accessWidenerPath = file("src/main/resources/kessoku_registry.accesswidener") } kessoku { @@ -12,5 +11,4 @@ kessoku { } dependencies { - } diff --git a/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java b/registry/common/src/main/java/band/kessoku/lib/api/registry/FuelRegistry.java similarity index 87% rename from registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java rename to registry/common/src/main/java/band/kessoku/lib/api/registry/FuelRegistry.java index 9531d4eb..af9b2354 100644 --- a/registry/common/src/main/java/band/kessoku/lib/registry/api/FuelRegistry.java +++ b/registry/common/src/main/java/band/kessoku/lib/api/registry/FuelRegistry.java @@ -13,11 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry.api; +package band.kessoku.lib.api.registry; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import net.minecraft.block.AbstractFurnaceBlock; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.block.entity.BlockEntity; import net.minecraft.component.ComponentMap; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; @@ -26,21 +35,16 @@ import net.minecraft.recipe.RecipeType; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.TagKey; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import net.minecraft.util.math.BlockPos; /** * Poor compatibility in Fabric * * @param */ -@SuppressWarnings("unused, deprecation, rawtypes") +@SuppressWarnings({"unused", "deprecation", "rawtypes"}) @ApiStatus.Experimental -public class FuelRegistry> { +public final class FuelRegistry> { private final Object2IntMap itemRegistries = new Object2IntLinkedOpenHashMap<>(); private final Object2IntMap dataRegistries = new Object2IntLinkedOpenHashMap<>(); private final Object2IntMap> tagRegistries = new Object2IntLinkedOpenHashMap<>(); @@ -181,11 +185,16 @@ public static void setFuelTime(ItemConvertible item, int cookTime) { } /** + * @param block the block which acts like a furnace * @return The fuel time. + * @implNote to ensure compatibility, this method creates a temporal entity to get fuel time */ - public static int getFuelTime(ItemStack stack) { - final var fuelMap = AbstractFurnaceBlockEntity.createFuelTimeMap(); - return fuelMap.getOrDefault(stack.getItem(), 0); + public static int getFuelTime(T block, ItemStack stack) { + BlockEntity entity = block.createBlockEntity((BlockPos) BlockPos.ZERO, block.getDefaultState()); + if (!(entity instanceof AbstractFurnaceBlockEntity)) return 0; + int fuelTime = ((AbstractFurnaceBlockEntity) entity).getFuelTime(stack); + entity.markRemoved(); + return fuelTime; } public record ItemWithData(ComponentMap componentMap, ItemConvertible item) { diff --git a/registry/common/src/main/java/band/kessoku/lib/registry/KessokuRegistry.java b/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java similarity index 80% rename from registry/common/src/main/java/band/kessoku/lib/registry/KessokuRegistry.java rename to registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java index 8abc3f68..1c7e7024 100644 --- a/registry/common/src/main/java/band/kessoku/lib/registry/KessokuRegistry.java +++ b/registry/common/src/main/java/band/kessoku/lib/api/registry/KessokuRegistry.java @@ -13,12 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry; +package band.kessoku.lib.api.registry; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public class KessokuRegistry { +public final class KessokuRegistry { + private KessokuRegistry() { + } + public static final String MOD_ID = "kessoku_registry"; - public static final Marker MARKER = MarkerFactory.getMarker("[KessokuRegistry]"); + public static final String NAME = "Kessoku Registry API"; + public static final Marker MARKER = MarkerFactory.getMarker("[" + NAME + "]"); } diff --git a/registry/common/src/main/java/band/kessoku/lib/registry/api/Registry.java b/registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java similarity index 79% rename from registry/common/src/main/java/band/kessoku/lib/registry/api/Registry.java rename to registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java index e8cc527d..52545a47 100644 --- a/registry/common/src/main/java/band/kessoku/lib/registry/api/Registry.java +++ b/registry/common/src/main/java/band/kessoku/lib/api/registry/Registry.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry.api; +package band.kessoku.lib.api.registry; + +import band.kessoku.lib.service.registry.RegistryService; -import band.kessoku.lib.registry.impl.KessokuRegistryServices; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; @@ -23,24 +24,17 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; -import org.jetbrains.annotations.ApiStatus; -@SuppressWarnings("unused") -public interface Registry { - @ApiStatus.Internal - static Registry getInstance() { - return KessokuRegistryServices.getRegistry(); +public final class Registry { + private Registry() { } - static T register(net.minecraft.registry.Registry registry, String id, T entry) { + public static T register(net.minecraft.registry.Registry registry, String id, T entry) { return register(registry, Identifier.of(id), entry); } - @ApiStatus.Internal - T registerInternal(net.minecraft.registry.Registry registry, Identifier id, T entry); - static T register(net.minecraft.registry.Registry registry, Identifier id, T entry) { - return Registry.getInstance().registerInternal(registry, id, entry); + return RegistryService.getInstance().register(registry, id, entry); } static Item registerItem(Identifier id, Item.Settings settings) { @@ -74,4 +68,4 @@ static Item registerSimpleBlockItem(RegistryEntry block, Item.Settings se static Item registerSimpleBlockItem(RegistryEntry block) { return registerSimpleBlockItem(block.getKey().orElseThrow().getValue(), block.value(), new Item.Settings()); } -} \ No newline at end of file +} diff --git a/registry/common/src/main/java/band/kessoku/lib/registry/impl/KessokuRegistryServices.java b/registry/common/src/main/java/band/kessoku/lib/registry/impl/KessokuRegistryServices.java deleted file mode 100644 index 138c1ff2..00000000 --- a/registry/common/src/main/java/band/kessoku/lib/registry/impl/KessokuRegistryServices.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 KessokuTeaTime - * - * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.gnu.org/licenses/lgpl-3.0.html - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package band.kessoku.lib.registry.impl; - -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.registry.api.Registry; - -public class KessokuRegistryServices { - private static final Registry registry = ModUtils.loadService(Registry.class); - - public static Registry getRegistry() { - return registry; - } -} diff --git a/keybind/common/src/main/java/band/kessoku/lib/keybind/impl/KessokuKeyBindService.java b/registry/common/src/main/java/band/kessoku/lib/service/registry/RegistryService.java similarity index 62% rename from keybind/common/src/main/java/band/kessoku/lib/keybind/impl/KessokuKeyBindService.java rename to registry/common/src/main/java/band/kessoku/lib/service/registry/RegistryService.java index f6fb22aa..6fe48832 100644 --- a/keybind/common/src/main/java/band/kessoku/lib/keybind/impl/KessokuKeyBindService.java +++ b/registry/common/src/main/java/band/kessoku/lib/service/registry/RegistryService.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.keybind.impl; +package band.kessoku.lib.service.registry; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.keybind.api.KeyBindRegister; +import band.kessoku.lib.api.KessokuLib; -public class KessokuKeyBindService { - private static final KeyBindRegister register = ModUtils.loadService(KeyBindRegister.class); +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; - public static KeyBindRegister getRegister() { - return register; +public interface RegistryService { + static RegistryService getInstance() { + return KessokuLib.loadService(RegistryService.class); } -} + T register(Registry registry, Identifier id, T entry); +} \ No newline at end of file diff --git a/registry/common/src/main/resources/kessoku-registry.accesswidener b/registry/common/src/main/resources/kessoku_registry.accesswidener similarity index 100% rename from registry/common/src/main/resources/kessoku-registry.accesswidener rename to registry/common/src/main/resources/kessoku_registry.accesswidener diff --git a/registry/fabric/build.gradle b/registry/fabric/build.gradle index 9f234bb6..57161cc4 100644 --- a/registry/fabric/build.gradle +++ b/registry/fabric/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib.registry" base.archivesName = rootProject.name + "-registry" loom { diff --git a/registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/KessokuRegistryFabric.java b/registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/KessokuRegistryFabric.java new file mode 100644 index 00000000..f0fbd2e8 --- /dev/null +++ b/registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/KessokuRegistryFabric.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 KessokuTeaTime + * + * Licensed under the GNU Lesser General Pubic License, Version 3 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/lgpl-3.0.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package band.kessoku.lib.impl.registry.fabric; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.registry.KessokuRegistry; + +import net.fabricmc.api.ModInitializer; + +public final class KessokuRegistryFabric implements ModInitializer { + @Override + public void onInitialize() { + KessokuLib.loadModule(KessokuRegistry.class); + } +} diff --git a/registry/fabric/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java b/registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/RegistryImpl.java similarity index 65% rename from registry/fabric/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java rename to registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/RegistryImpl.java index a48c47cb..dc25c516 100644 --- a/registry/fabric/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java +++ b/registry/fabric/src/main/java/band/kessoku/lib/impl/registry/fabric/RegistryImpl.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry.impl; +package band.kessoku.lib.impl.registry.fabric; -import band.kessoku.lib.registry.api.Registry; +import band.kessoku.lib.service.registry.RegistryService; import com.google.auto.service.AutoService; + +import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; -@AutoService(Registry.class) -public class RegistryImpl implements Registry { +@AutoService(RegistryService.class) +public final class RegistryImpl implements RegistryService { @Override - public T registerInternal(net.minecraft.registry.Registry registry, Identifier id, T entry) { - return net.minecraft.registry.Registry.register(registry, id, entry); + public T register(Registry registry, Identifier id, T entry) { + return Registry.register(registry, id, entry); } } diff --git a/registry/fabric/src/main/java/band/kessoku/lib/registry/mixin/AbstractFurnaceBlockEntityMixin.java b/registry/fabric/src/main/java/band/kessoku/lib/mixin/registry/fabric/AbstractFurnaceBlockEntityMixin.java similarity index 93% rename from registry/fabric/src/main/java/band/kessoku/lib/registry/mixin/AbstractFurnaceBlockEntityMixin.java rename to registry/fabric/src/main/java/band/kessoku/lib/mixin/registry/fabric/AbstractFurnaceBlockEntityMixin.java index 425d4c06..65491dd5 100644 --- a/registry/fabric/src/main/java/band/kessoku/lib/registry/mixin/AbstractFurnaceBlockEntityMixin.java +++ b/registry/fabric/src/main/java/band/kessoku/lib/mixin/registry/fabric/AbstractFurnaceBlockEntityMixin.java @@ -13,11 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry.mixin; +package band.kessoku.lib.mixin.registry.fabric; -import band.kessoku.lib.registry.api.FuelRegistry; +import band.kessoku.lib.api.registry.FuelRegistry; import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + import net.minecraft.block.BlockState; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.block.entity.BlockEntityType; @@ -25,14 +31,9 @@ import net.minecraft.recipe.AbstractCookingRecipe; import net.minecraft.recipe.RecipeType; import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(AbstractFurnaceBlockEntity.class) -public class AbstractFurnaceBlockEntityMixin { +public final class AbstractFurnaceBlockEntityMixin { @Unique private RecipeType recipeType; diff --git a/registry/fabric/src/main/resources/fabric.mod.json b/registry/fabric/src/main/resources/fabric.mod.json index 6af496ed..e6dd34e8 100644 --- a/registry/fabric/src/main/resources/fabric.mod.json +++ b/registry/fabric/src/main/resources/fabric.mod.json @@ -16,14 +16,14 @@ "icon": "icon.png", "entrypoints": { "main": [ - "band.kessoku.lib.registry.KessokuRegistryEntrypoint" + "band.kessoku.lib.impl.registry.fabric.KessokuRegistryFabric" ] }, "environment": "*", "mixins": [ - "kessoku-registry-fabric.mixins.json" + "kessoku_registry.fabric.mixins.json" ], - "accessWidener": "kessoku-registry.accesswidener", + "accessWidener": "kessoku_registry.accesswidener", "depends": { "fabricloader": ">=0.16.0", "minecraft": "1.21", diff --git a/registry/fabric/src/main/resources/kessoku-registry-fabric.mixins.json b/registry/fabric/src/main/resources/kessoku_registry.fabric.mixins.json similarity index 74% rename from registry/fabric/src/main/resources/kessoku-registry-fabric.mixins.json rename to registry/fabric/src/main/resources/kessoku_registry.fabric.mixins.json index 647c83c5..3da4a0d0 100644 --- a/registry/fabric/src/main/resources/kessoku-registry-fabric.mixins.json +++ b/registry/fabric/src/main/resources/kessoku_registry.fabric.mixins.json @@ -1,6 +1,6 @@ { "required": true, - "package": "band.kessoku.lib.registry.mixin", + "package": "band.kessoku.lib.mixin.registry.fabric", "compatibilityLevel": "JAVA_21", "mixins": [ "AbstractFurnaceBlockEntityMixin" diff --git a/registry/neo/build.gradle b/registry/neo/build.gradle index dbc27d79..092c9ee8 100644 --- a/registry/neo/build.gradle +++ b/registry/neo/build.gradle @@ -2,7 +2,6 @@ import net.fabricmc.loom.util.ModPlatform apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib.registry" base.archivesName = rootProject.name + "-registry" loom { @@ -11,12 +10,12 @@ loom { kessoku { module("base", "common") - module("event-base", "neo") + module("base", "neo") common("registry", ModPlatform.NEOFORGE) shadowBundle("registry", ModPlatform.NEOFORGE) } remapJar { - atAccessWideners.add("kessoku-registry.accesswidener") + atAccessWideners.add("kessoku_registry.accesswidener") } diff --git a/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java b/registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/KessokuRegistryNeoforge.java similarity index 78% rename from registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java rename to registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/KessokuRegistryNeoforge.java index 1b16a420..bd95f9b8 100644 --- a/registry/neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java +++ b/registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/KessokuRegistryNeoforge.java @@ -13,26 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry; +package band.kessoku.lib.impl.registry.neoforge; + +import java.util.Objects; + +import band.kessoku.lib.api.KessokuLib; +import band.kessoku.lib.api.base.neoforge.NeoEventUtils; +import band.kessoku.lib.api.registry.FuelRegistry; +import band.kessoku.lib.api.registry.KessokuRegistry; -import band.kessoku.lib.base.ModUtils; -import band.kessoku.lib.event.util.NeoEventUtils; -import band.kessoku.lib.registry.api.FuelRegistry; -import band.kessoku.lib.registry.impl.RegistryImpl; import net.minecraft.item.ItemStack; import net.minecraft.recipe.RecipeType; + import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent; import net.neoforged.neoforge.registries.RegisterEvent; -import java.util.Objects; - @Mod(KessokuRegistry.MOD_ID) -public class KessokuRegistryEntrypoint { - public KessokuRegistryEntrypoint(IEventBus modEventBus) { - ModUtils.getLogger().info(KessokuRegistry.MARKER, "KessokuLib-Registry is loaded!"); +public final class KessokuRegistryNeoforge { + public KessokuRegistryNeoforge(IEventBus modEventBus) { + KessokuLib.loadModule(KessokuRegistry.class); NeoEventUtils.registerEvent(modEventBus, RegisterEvent.class, RegistryImpl::onRegister); NeoEventUtils.registerEvent(NeoForge.EVENT_BUS, FurnaceFuelBurnTimeEvent.class, event -> { final ItemStack stack = event.getItemStack(); diff --git a/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java b/registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/RegistryImpl.java similarity index 80% rename from registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java rename to registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/RegistryImpl.java index d9f5b9bc..3ae00930 100644 --- a/registry/neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java +++ b/registry/neo/src/main/java/band/kessoku/lib/impl/registry/neoforge/RegistryImpl.java @@ -13,23 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package band.kessoku.lib.registry.impl; +package band.kessoku.lib.impl.registry.neoforge; -import band.kessoku.lib.registry.api.Registry; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +import band.kessoku.lib.service.registry.RegistryService; import com.google.auto.service.AutoService; import com.google.common.collect.Maps; -import net.minecraft.util.Identifier; -import net.neoforged.neoforge.registries.RegisterEvent; import org.jetbrains.annotations.ApiStatus; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +import net.neoforged.neoforge.registries.RegisterEvent; -@AutoService(Registry.class) +@AutoService(RegistryService.class) @SuppressWarnings({"unchecked", "rawtypes"}) -public class RegistryImpl implements Registry { - private static final Map> registries = new ConcurrentHashMap<>(); +public final class RegistryImpl implements RegistryService { + private static final Map> registries = new ConcurrentHashMap<>(); private static boolean registered = false; @ApiStatus.Internal @@ -39,7 +42,7 @@ public static void onRegister(RegisterEvent event) { } @Override - public T registerInternal(net.minecraft.registry.Registry registry, Identifier id, T entry) { + public T register(Registry registry, Identifier id, T entry) { if (registered) { throw new IllegalStateException("Cannot register new entries after net.neoforged.neoforge.registries.RegisterEvent has been fired."); } diff --git a/settings.gradle b/settings.gradle index 42868e3a..e8dd999b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,7 +19,7 @@ includeModule("platform") // Platform includeModule("registry") // Registry includeModule("lifecycle-events") // Lifecycle Events includeModule("command") // Command API -includeModule("keybind") // Keybind API +includeModule("keybinding") // Keybinding API includeModule("config") // Config API includeModule("entrypoint") // Entrypoint API includeModule("entity-events") // Entity Events diff --git a/wrapper/fabric/build.gradle b/wrapper/fabric/build.gradle index fba7110e..48bad971 100644 --- a/wrapper/fabric/build.gradle +++ b/wrapper/fabric/build.gradle @@ -1,12 +1,9 @@ -import net.fabricmc.loom.util.ModPlatform +import band.kessoku.gradle.plugin.PlatformIdentifier apply from: rootProject.file("gradle/scripts/klib-fabric.gradle") -group = "band.kessoku.lib" base.archivesName = rootProject.name -var modules = ["base", "event-base", "lifecycle-events", "platform", "registry"] - kessoku { - moduleIncludes(modules, ModPlatform.FABRIC.id()) + moduleIncludes(getModuleList(), PlatformIdentifier.FABRIC.id()) } diff --git a/wrapper/neo/build.gradle b/wrapper/neo/build.gradle index 698f7850..fa8354f7 100644 --- a/wrapper/neo/build.gradle +++ b/wrapper/neo/build.gradle @@ -1,10 +1,9 @@ +import band.kessoku.gradle.plugin.PlatformIdentifier + apply from: rootProject.file("gradle/scripts/klib-neo.gradle") -group = "band.kessoku.lib" base.archivesName = rootProject.name -var modules = ["base", "event-base", "lifecycle-events", "platform", "registry"] - kessoku { - moduleIncludes(modules, "neo") + moduleIncludes(getModuleList(), PlatformIdentifier.NEO.id()) }