Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into dev/1.21
  • Loading branch information
RawDiamondMC committed Aug 4, 2024
2 parents 49ffcef + f2385ba commit bd14b6d
Show file tree
Hide file tree
Showing 35 changed files with 913 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ServiceLoader;

public class ModUtils {
public static <T> T load(Class<T> clazz) {
public static <T> T loadService(Class<T> clazz) {
return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getName()));
}
}
16 changes: 16 additions & 0 deletions command-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
group = "band.kessoku.lib.command"
version = libs.versions.mod.get() + "+common." + libs.versions.minecraft.get()

base {
archivesName = rootProject.name + "-command_api"
}

architectury {
common(["fabric", "neoforge"])
}

dependencies {
modImplementation libs.fabric.loader
implementation(project(":base-common"))
implementation(project(":event-base-common"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package band.kessoku.lib.command;

public class KessokuCommand {
public static final String MOD_ID = "kessoku_command";
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package band.kessoku.lib.event.events.command;
package band.kessoku.lib.command.api.events;

import band.kessoku.lib.event.api.Event;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;

public interface CommandRegister {
public interface CommandRegistryEvent {

Event<CommandRegister> EVENT = Event.of(commandRegisters -> (dispatcher, registryAccess, environment) -> commandRegisters.forEach(commandRegister -> commandRegister.register(dispatcher, registryAccess, environment)));
Event<CommandRegistryEvent> EVENT = Event.of(commandRegistryEvents -> (dispatcher, registryAccess, environment) -> {
for (CommandRegistryEvent commandRegistryEvent : commandRegistryEvents) {
commandRegistryEvent.register(dispatcher, registryAccess, environment);
}
});

/**
* Called when the server is registering commands.
Expand Down
56 changes: 56 additions & 0 deletions command-fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
plugins {
id 'com.github.johnrengelman.shadow'
}

group = "band.kessoku.lib.command"
version = libs.versions.mod.get() + "+fabric." + libs.versions.minecraft.get()

base {
archivesName = rootProject.name + "-command_api"
}

architectury {
platformSetupLoomIde()
fabric()
}

configurations {
common {
canBeResolved = true
canBeConsumed = false
}
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
shadowBundle {
canBeResolved = true
canBeConsumed = false
}
}

dependencies {
modImplementation libs.fabric.loader
modImplementation libs.fabric.api

implementation(project(":event-base-common"))

common(project(path: ':command-common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':command-common', configuration: 'transformProductionFabric')
}

processResources {
inputs.property 'version', project.version

filesMatching('fabric.mod.json') {
expand version: project.version
}
}

shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
}

remapJar {
input.set shadowJar.archiveFile
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package band.kessoku.lib.command;

import band.kessoku.lib.command.impl.KessokuCommandImpl;
import net.fabricmc.api.ModInitializer;

public class KessokuCommandEntrypoint implements ModInitializer {
@Override
public void onInitialize() {
KessokuCommandImpl.registerCommonEvents();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package band.kessoku.lib.command.impl;

import band.kessoku.lib.command.api.events.CommandRegistryEvent;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;

public class KessokuCommandImpl {
public static void registerCommonEvents() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
CommandRegistryEvent.EVENT.invoker().register(dispatcher, registryAccess, environment);
});
}
}
31 changes: 31 additions & 0 deletions command-fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"schemaVersion": 1,
"id": "kessoku_command",
"version": "${version}",
"name": "Kessoku Command API",
"description": "About command registries.",
"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",
"environment": "*",
"depends": {
"fabricloader": ">=0.16.0",
"minecraft": "1.21",
"java": ">=21",
"fabric-api": "*"
},
"custom": {
"modmenu": {
"badges": [
"library"
]
}
}
}
Empty file.
60 changes: 60 additions & 0 deletions command-neo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
plugins {
id 'com.github.johnrengelman.shadow'
}

group = "band.kessoku.lib.command"
version = libs.versions.mod.get() + "+neoforge." + libs.versions.minecraft.get()

base {
archivesName = rootProject.name + "-command_api"
}

architectury {
platformSetupLoomIde()
neoForge()
}

repositories {
maven { url "https://maven.neoforged.net/releases/" }
}

configurations {
common {
canBeResolved = true
canBeConsumed = false
}
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentNeoForge.extendsFrom common
shadowBundle {
canBeResolved = true
canBeConsumed = false
}
}

dependencies {
neoForge libs.neo

implementation(project(":event-base-common"))
implementation(project(":event-base-neo"))

common(project(path: ':command-common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':command-common', configuration: 'transformProductionNeoForge')
}

processResources {
inputs.property 'version', project.version

filesMatching('META-INF/neoforge.mods.toml') {
expand version: project.version
}
}

shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
}

remapJar {
input.set shadowJar.archiveFile
}
1 change: 1 addition & 0 deletions command-neo/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loom.platform=neoforge
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package band.kessoku.lib.command;

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) {
var forgeEventBus = NeoForge.EVENT_BUS;

KessokuCommandImpl.registerCommonEvents(forgeEventBus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package band.kessoku.lib.command.impl;

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 static void registerCommonEvents(IEventBus forgeEventBus) {
NeoEventUtils.registerEvent(forgeEventBus, RegisterCommandsEvent.class, event -> {
CommandRegistryEvent.EVENT.invoker().register(event.getDispatcher(), event.getBuildContext(), event.getCommandSelection());
});
}
}
29 changes: 29 additions & 0 deletions command-neo/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
modLoader = "javafml"
loaderVersion = "[4,)"
license = "LGPL-3.0-only"
issueTrackerURL = "https://github.com/KessokuTeaTime/KessokuLib/issues"

[[mods]]
modId = "kessoku_command"
version = "${version}"
displayName = "Kessoku Command API"
description = '''
About command registries.
'''
logoFile = "icon.png"
authors = "Kessoku Tea Time"
displayURL = "https://modrinth.com/mod/kessoku-lib"

[[dependencies.kessoku-event-base]]
modId = "neoforge"
type = "required"
versionRange = "[21.0,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.kessoku-event-base]]
modId = "minecraft"
type = "required"
versionRange = "[1.21,)"
ordering = "NONE"
side = "BOTH"

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package band.kessoku.lib.event;

public class KessokuEventBaseEntrypoint {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package band.kessoku.lib.event.util;

import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;

import java.util.function.Consumer;

public class NeoEventUtils {
public static <T extends Event> void registerEvent(IEventBus eventBus, Class<T> eventClass, Consumer<T> consumer) {
eventBus.addListener(EventPriority.HIGHEST, eventClass, consumer);
}
}
2 changes: 2 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ architectury {
}

dependencies {
modImplementation libs.fabric.loader

include(project(":base-fabric"))
include(project(":event-base-fabric"))
include(project(":platform-fabric"))
Expand Down
16 changes: 16 additions & 0 deletions lifecycle-events-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
group = "band.kessoku.lib.event"
version = libs.versions.mod.get() + "+common." + libs.versions.minecraft.get()

base {
archivesName = rootProject.name + "-lifecycle-events"
}

architectury {
common(["fabric", "neoforge"])
}

dependencies {
modImplementation libs.fabric.loader
implementation(project(":base-common"))
implementation(project(":event-base-common"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package band.kessoku.lib.events.lifecycle;

public class KessokuLifecycleEvents {
public static final String MOD_ID = "kessoku_lifecycle_events";
}
Loading

0 comments on commit bd14b6d

Please sign in to comment.