-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
320 additions
and
25 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
base-common/src/main/java/band/kessoku/lib/base/KessokuBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package band.kessoku.lib.base; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class KessokuBase { | ||
public static final String MOD_ID = "kessoku_base"; | ||
public static final Marker MARKER = MarkerFactory.getMarker("[KessokuBase]"); | ||
} |
7 changes: 7 additions & 0 deletions
7
base-common/src/main/java/band/kessoku/lib/base/ModUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
package band.kessoku.lib.base; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
public class ModUtils { | ||
public static <T> T loadService(Class<T> clazz) { | ||
return ServiceLoader.load(clazz).findFirst().orElseThrow(() -> new AssertionError("No impl found for " + clazz.getName())); | ||
} | ||
|
||
public static Logger getLogger() { | ||
return LoggerFactory.getLogger("[KessokuLib]"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
command-common/src/main/java/band/kessoku/lib/command/KessokuCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package band.kessoku.lib.command; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class KessokuCommand { | ||
public static final String MOD_ID = "kessoku_command"; | ||
public static final Marker MARKER = MarkerFactory.getMarker("[KessokuCommand]"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
command-fabric/src/main/java/band/kessoku/lib/command/KessokuCommandEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package band.kessoku.lib.command; | ||
|
||
import band.kessoku.lib.base.ModUtils; | ||
import band.kessoku.lib.command.impl.KessokuCommandImpl; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
public class KessokuCommandEntrypoint implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
ModUtils.getLogger().info(KessokuCommand.MARKER, "KessokuLib-Command is Loaded!"); | ||
KessokuCommandImpl.registerCommonEvents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
event-base-common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package band.kessoku.lib.event; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class KessokuEventBase { | ||
public static final String MOD_ID = "kessoku_event_base"; | ||
public static final Marker MARKER = MarkerFactory.getMarker("[KessokuEventBase]"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
event-base-fabric/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package band.kessoku.lib.event; | ||
|
||
import band.kessoku.lib.base.ModUtils; | ||
import net.fabricmc.api.ModInitializer; | ||
|
||
public class KessokuEventBaseEntrypoint implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
ModUtils.getLogger().info(KessokuEventBase.MARKER, "KessokuLib-EventBase is Loaded!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
org.gradle.jvmargs=-Xmx3G | ||
org.gradle.parallel=true | ||
org.gradle.parallel=true | ||
fabric.loom.multiProjectOptimisation=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apply from: rootProject.file("gradle/scripts/kessokulib-common.gradle") | ||
|
||
group = "band.kessoku.lib.keybind" | ||
base.archivesName = rootProject.name + "-keybind" | ||
|
||
dependencies { | ||
moduleImplementation(project(":base-common")) | ||
} |
9 changes: 9 additions & 0 deletions
9
keybind-common/src/main/java/band/kessoku/lib/keybind/KessokuKeybind.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package band.kessoku.lib.keybind; | ||
|
||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class KessokuKeybind { | ||
public static final String MOD_ID = "kessoku_keybind"; | ||
public static final Marker MARKER = MarkerFactory.getMarker("[KessokuKeybind]"); | ||
} |
15 changes: 15 additions & 0 deletions
15
keybind-common/src/main/java/band/kessoku/lib/keybind/api/KeyBindRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package band.kessoku.lib.keybind.api; | ||
|
||
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(); | ||
} | ||
|
||
boolean addCategory(String categoryTranslationKey); | ||
KeyBinding register(KeyBinding keyBinding); | ||
InputUtil.Key getBoundKey(KeyBinding keyBinding); | ||
} |
12 changes: 12 additions & 0 deletions
12
keybind-common/src/main/java/band/kessoku/lib/keybind/impl/KessokuKeyBindService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package band.kessoku.lib.keybind.impl; | ||
|
||
import band.kessoku.lib.base.ModUtils; | ||
import band.kessoku.lib.keybind.api.KeyBindRegister; | ||
|
||
public class KessokuKeyBindService { | ||
private static final KeyBindRegister register = ModUtils.loadService(KeyBindRegister.class); | ||
|
||
public static KeyBindRegister getRegister() { | ||
return register; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apply from: rootProject.file("gradle/scripts/kessokulib-fabric.gradle") | ||
|
||
group = "band.kessoku.lib.keybind" | ||
base.archivesName = rootProject.name + "-keybind" | ||
|
||
dependencies { | ||
moduleImplementation(project(":base-common")) | ||
|
||
common(project(path: ':keybind-common', configuration: 'namedElements')) { transitive false } | ||
shadowBundle(project(path: ':keybind-common', configuration: 'transformProductionFabric')) | ||
} |
11 changes: 11 additions & 0 deletions
11
keybind-fabric/src/main/java/band/kessoku/lib/keybind/KessokuKeybindEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package band.kessoku.lib.keybind; | ||
|
||
import band.kessoku.lib.base.ModUtils; | ||
import net.fabricmc.api.ClientModInitializer; | ||
|
||
public class KessokuKeybindEntrypoint implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
ModUtils.getLogger().info(KessokuKeybind.MARKER, "KessokuKeybind is loaded!"); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
keybind-fabric/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package band.kessoku.lib.keybind.impl; | ||
|
||
import band.kessoku.lib.keybind.api.KeyBindRegister; | ||
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); | ||
} | ||
|
||
@Override | ||
public KeyBinding register(KeyBinding keyBinding) { | ||
return KeyBindingHelper.registerKeyBinding(keyBinding); | ||
} | ||
|
||
@Override | ||
public InputUtil.Key getBoundKey(KeyBinding keyBinding) { | ||
return KeyBindingHelper.getBoundKeyOf(keyBinding); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apply from: rootProject.file("gradle/scripts/kessokulib-neo.gradle") | ||
|
||
group = "band.kessoku.lib.keybind" | ||
base.archivesName = rootProject.name + "-keybind" | ||
|
||
dependencies { | ||
moduleImplementation(project(":base-common")) | ||
moduleImplementation(project(":event-base-neo")) | ||
|
||
common(project(path: ':keybind-common', configuration: 'namedElements')) { transitive false } | ||
shadowBundle(project(path: ':keybind-common', configuration: 'transformProductionNeoForge')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
loom.platform=neoforge |
18 changes: 18 additions & 0 deletions
18
keybind-neo/src/main/java/band/kessoku/lib/keybind/KessokuKeyBindEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package band.kessoku.lib.keybind; | ||
|
||
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) { | ||
if (FMLLoader.getDist().isClient()) { | ||
ModUtils.getLogger().info(KessokuKeybind.MARKER, "KessokuKeybind is loaded!"); | ||
KeyBindRegisterImpl.registerEvent(modEventBus); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
keybind-neo/src/main/java/band/kessoku/lib/keybind/impl/KeyBindRegisterImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package band.kessoku.lib.keybind.impl; | ||
|
||
import band.kessoku.lib.event.util.NeoEventUtils; | ||
import band.kessoku.lib.keybind.api.KeyBindRegister; | ||
import band.kessoku.lib.keybind.mixin.KeyBindingAccessor; | ||
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; | ||
import java.util.Optional; | ||
|
||
@AutoService(KeyBindRegister.class) | ||
public class KeyBindRegisterImpl implements KeyBindRegister { | ||
private static final List<KeyBinding> KEY_BINDINGS = new ReferenceArrayList<>(); | ||
private static boolean processed; | ||
|
||
private static Map<String, Integer> getCategoryMap() { | ||
return KeyBindingAccessor.kessoku$getCategoryMap(); | ||
} | ||
|
||
@Override | ||
public boolean addCategory(String categoryTranslationKey) { | ||
Map<String, Integer> map = getCategoryMap(); | ||
|
||
if (map.containsKey(categoryTranslationKey)) { | ||
return false; | ||
} | ||
|
||
Optional<Integer> largest = map.values().stream().max(Integer::compareTo); | ||
int largestInt = largest.orElse(0); | ||
map.put(categoryTranslationKey, largestInt + 1); | ||
return true; | ||
} | ||
|
||
@Override | ||
public KeyBinding register(KeyBinding keyBinding) { | ||
if (processed) { | ||
throw new IllegalStateException("Key bindings have already been processed"); | ||
} | ||
|
||
for (KeyBinding existingKeyBindings : KEY_BINDINGS) { | ||
if (existingKeyBindings == keyBinding) { | ||
throw new IllegalArgumentException("Attempted to register a key binding twice: " + keyBinding.getTranslationKey()); | ||
} else if (existingKeyBindings.getTranslationKey().equals(keyBinding.getTranslationKey())) { | ||
throw new IllegalArgumentException("Attempted to register two key bindings with equal ID: " + keyBinding.getTranslationKey() + "!"); | ||
} | ||
} | ||
|
||
// This will do nothing if the category already exists. | ||
addCategory(keyBinding.getCategory()); | ||
KEY_BINDINGS.add(keyBinding); | ||
return keyBinding; | ||
} | ||
|
||
@Override | ||
public InputUtil.Key getBoundKey(KeyBinding keyBinding) { | ||
return ((KeyBindingAccessor) keyBinding).kessoku$getBoundKey(); | ||
} | ||
|
||
public static void registerEvent(IEventBus eventBus) { | ||
NeoEventUtils.registerEvent(eventBus, RegisterKeyMappingsEvent.class, event -> { | ||
KEY_BINDINGS.forEach(event::register); | ||
processed = true; | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
keybind-neo/src/main/java/band/kessoku/lib/keybind/mixin/KeyBindingAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package band.kessoku.lib.keybind.mixin; | ||
|
||
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; | ||
|
||
@Mixin(KeyBinding.class) | ||
public interface KeyBindingAccessor { | ||
@Accessor("CATEGORY_ORDER_MAP") | ||
static Map<String, Integer> kessoku$getCategoryMap() { | ||
throw new AssertionError(); | ||
} | ||
|
||
@Accessor("boundKey") | ||
InputUtil.Key kessoku$getBoundKey(); | ||
} |
Oops, something went wrong.