add more APIs, update gradle, add branding
This commit is contained in:
parent
2bf62501c9
commit
6a7bddc2b4
|
@ -14,4 +14,23 @@ repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraft(project.libs.versions.minecraft).loader(project.libs.versions.frogloader)
|
dependencies {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
phytotelma {
|
||||||
|
loader(project.libs.versions.frogloader)
|
||||||
|
minecraft(project.libs.versions.minecraft)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.processResources {
|
||||||
|
inputs.property("version", version)
|
||||||
|
|
||||||
|
filesMatching("frog.mod.toml") {
|
||||||
|
expand("version" to version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.runClient {
|
||||||
|
classpath(sourceSets.test.get().runtimeClasspath)
|
||||||
|
}
|
||||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
||||||
#Mon May 13 10:13:59 CEST 2024
|
#Mon May 13 10:13:59 CEST 2024
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package dev.frogmc.froglib.branding.impl.mixin.client;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||||
|
import net.minecraft.client.ClientBrandRetriever;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
||||||
|
@Mixin(ClientBrandRetriever.class)
|
||||||
|
public class ClientBrandRetrieverMixin {
|
||||||
|
|
||||||
|
@ModifyReturnValue(method = "getClientModName", at = @At("RETURN"))
|
||||||
|
private static String setClientBrand(String original){
|
||||||
|
return original+"/FrogLoader";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,18 @@
|
||||||
package dev.frogmc.froglib.entrypoints.mixin.client;
|
package dev.frogmc.froglib.entrypoints.mixin.client;
|
||||||
|
|
||||||
import dev.frogmc.froglib.entrypoints.ExtensionLauncher;
|
import dev.frogmc.froglib.entrypoints.ExtensionLauncher;
|
||||||
import net.minecraft.client.main.Main;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.main.GameConfig;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(Main.class)
|
@Mixin(Minecraft.class)
|
||||||
public class MainMixin {
|
public abstract class MinecraftMixin {
|
||||||
|
|
||||||
@Inject(method = "main", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;setName(Ljava/lang/String;)V"))
|
@Inject(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;running:Z"))
|
||||||
private static void initializeClient(String[] args, CallbackInfo ci) {
|
private void initializeClient(GameConfig gameConfig, CallbackInfo ci) {
|
||||||
ExtensionLauncher.invokeClient();
|
ExtensionLauncher.invokeClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(Main.class)
|
@Mixin(Main.class)
|
||||||
public class MinecraftServerMixin {
|
public abstract class MinecraftServerMainMixin {
|
||||||
|
|
||||||
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;spin(Ljava/util/function/Function;)Lnet/minecraft/server/MinecraftServer;"))
|
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;spin(Ljava/util/function/Function;)Lnet/minecraft/server/MinecraftServer;"))
|
||||||
private static void initializeServer(String[] args, CallbackInfo ci) {
|
private static void initializeServer(String[] args, CallbackInfo ci) {
|
|
@ -1,9 +1,17 @@
|
||||||
package dev.frogmc.froglib.events.api;
|
package dev.frogmc.froglib.events.api;
|
||||||
|
|
||||||
import dev.frogmc.froglib.events.api.types.ClientStartupEvent;
|
import dev.frogmc.froglib.events.api.types.ClientStartupEvent;
|
||||||
|
import dev.frogmc.froglib.events.api.types.ClientTickEvent;
|
||||||
import dev.frogmc.froglib.events.api.types.ServerStartupEvent;
|
import dev.frogmc.froglib.events.api.types.ServerStartupEvent;
|
||||||
|
import dev.frogmc.froglib.events.api.types.ServerTickEvent;
|
||||||
|
|
||||||
public class Events {
|
public class Events {
|
||||||
public static final Event<ClientStartupEvent> CLIENT_STARTUP = Event.of(ClientStartupEvent.class);
|
public static final Event<ClientStartupEvent> CLIENT_STARTUP = Event.of(ClientStartupEvent.class);
|
||||||
public static final Event<ServerStartupEvent> SERVER_STARTUP = Event.of(ServerStartupEvent.class);
|
public static final Event<ServerStartupEvent> SERVER_STARTUP = Event.of(ServerStartupEvent.class);
|
||||||
|
|
||||||
|
public static final Event<ClientTickEvent> PRE_CLIENT_TICK = Event.of(ClientTickEvent.class);
|
||||||
|
public static final Event<ClientTickEvent> POST_CLIENT_TICK = Event.of(ClientTickEvent.class);
|
||||||
|
|
||||||
|
public static final Event<ServerTickEvent> PRE_SERVER_TICK = Event.of(ServerTickEvent.class);
|
||||||
|
public static final Event<ServerTickEvent> POST_SERVER_TICK = Event.of(ServerTickEvent.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package dev.frogmc.froglib.events.api.types;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
|
public interface ClientTickEvent {
|
||||||
|
|
||||||
|
void onTick(Minecraft minecraft);
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package dev.frogmc.froglib.events.api.types;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
|
public interface ServerTickEvent {
|
||||||
|
void onTick(MinecraftServer server);
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package dev.frogmc.froglib.events.impl.mixin;
|
||||||
|
|
||||||
|
import dev.frogmc.froglib.events.api.Events;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mixin(MinecraftServer.class)
|
||||||
|
public abstract class MinecraftServerMixin {
|
||||||
|
|
||||||
|
@Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tickServer(Ljava/util/function/BooleanSupplier;)V"))
|
||||||
|
private void preServerTick(CallbackInfo ci) {
|
||||||
|
Events.PRE_SERVER_TICK.invoker().onTick((MinecraftServer) (Object) this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tickServer(Ljava/util/function/BooleanSupplier;)V", shift = At.Shift.AFTER))
|
||||||
|
private void postServerTick(CallbackInfo ci) {
|
||||||
|
Events.POST_SERVER_TICK.invoker().onTick((MinecraftServer) (Object) this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,10 +9,20 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(Minecraft.class)
|
@Mixin(Minecraft.class)
|
||||||
public class MinecraftMixin {
|
public abstract class MinecraftMixin {
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void postClientInit(GameConfig gameConfig, CallbackInfo ci) {
|
private void postClientInit(GameConfig gameConfig, CallbackInfo ci) {
|
||||||
Events.CLIENT_STARTUP.invoker().onClientInit((Minecraft) (Object) this, gameConfig);
|
Events.CLIENT_STARTUP.invoker().onClientInit((Minecraft) (Object) this, gameConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "tick", at = @At("HEAD"))
|
||||||
|
private void preClientTick(CallbackInfo ci) {
|
||||||
|
Events.PRE_CLIENT_TICK.invoker().onTick((Minecraft) (Object) this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "tick", at = @At("TAIL"))
|
||||||
|
private void postClientTick(CallbackInfo ci) {
|
||||||
|
Events.POST_CLIENT_TICK.invoker().onTick((Minecraft) (Object) this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(DedicatedServer.class)
|
@Mixin(DedicatedServer.class)
|
||||||
public class DedicatedServerMixin {
|
public abstract class DedicatedServerMixin {
|
||||||
|
|
||||||
@Inject(method = "initServer", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;)V", ordinal = 0))
|
@Inject(method = "initServer", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;)V", ordinal = 0))
|
||||||
private void initializeServer(CallbackInfoReturnable<Boolean> cir) {
|
private void initializeServer(CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package dev.frogmc.froglib.keybinds.api;
|
||||||
|
|
||||||
|
import dev.frogmc.froglib.keybinds.impl.KeyMappingsImpl;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
|
||||||
|
public interface KeyMappings {
|
||||||
|
|
||||||
|
private static KeyMappings getInstance(){
|
||||||
|
return KeyMappingsImpl.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register(KeyMapping mapping){
|
||||||
|
getInstance().registerKey(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerKey(KeyMapping mapping);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package dev.frogmc.froglib.keybinds.impl;
|
||||||
|
|
||||||
|
import dev.frogmc.froglib.keybinds.api.KeyMappings;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
|
public class KeyMappingsImpl implements KeyMappings {
|
||||||
|
|
||||||
|
private static final KeyMappingsImpl INSTANCE = new KeyMappingsImpl();
|
||||||
|
public static KeyMappings getInstance(){
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerKey(KeyMapping mapping){
|
||||||
|
Minecraft.getInstance().options.keyMappings = ArrayUtils.add(Minecraft.getInstance().options.keyMappings, mapping);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package dev.frogmc.froglib.keybinds.impl.mixin.client;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
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(KeyMapping.class)
|
||||||
|
public abstract class KeyMappingMixin {
|
||||||
|
|
||||||
|
@Shadow @Final @Mutable private static Map<String, Integer> CATEGORY_SORT_ORDER;
|
||||||
|
|
||||||
|
@Inject(method = "<init>(Ljava/lang/String;Lcom/mojang/blaze3d/platform/InputConstants$Type;ILjava/lang/String;)V", at = @At("TAIL"))
|
||||||
|
private void addModCategoriesToOrdering(String name, InputConstants.Type type, int keyCode, String category, CallbackInfo ci){
|
||||||
|
if (!CATEGORY_SORT_ORDER.containsKey(category)) {
|
||||||
|
CATEGORY_SORT_ORDER.put(category, CATEGORY_SORT_ORDER.size()+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ format_version = "1.0.0"
|
||||||
[frog.mod]
|
[frog.mod]
|
||||||
id = "froglib"
|
id = "froglib"
|
||||||
name = "FrogLib"
|
name = "FrogLib"
|
||||||
version = "0.0.1"
|
version = "$version"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
credits = [
|
credits = [
|
||||||
{ name = "FrogMC Team", roles = ["author"] }
|
{ name = "FrogMC Team", roles = ["author"] }
|
||||||
|
@ -23,8 +23,10 @@ server = [
|
||||||
"dev.frogmc.froglib.resources.impl.ResourceLoaderServer"
|
"dev.frogmc.froglib.resources.impl.ResourceLoaderServer"
|
||||||
]
|
]
|
||||||
mixin_config = [
|
mixin_config = [
|
||||||
|
"froglib.branding.mixins.json",
|
||||||
"froglib.entrypoints.mixins.json",
|
"froglib.entrypoints.mixins.json",
|
||||||
"froglib.events.mixins.json",
|
"froglib.events.mixins.json",
|
||||||
"froglib.resources.mixins.json"
|
"froglib.resources.mixins.json",
|
||||||
|
"froglib.keybinds.mixins.json"
|
||||||
]
|
]
|
||||||
|
frog_aw = "froglib.accesswidener"
|
||||||
|
|
3
src/main/resources/froglib.accesswidener
Normal file
3
src/main/resources/froglib.accesswidener
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
accessWidener v2 named
|
||||||
|
|
||||||
|
mutable field net/minecraft/client/Options keyMappings [Lnet/minecraft/client/KeyMapping;
|
17
src/main/resources/froglib.branding.mixins.json
Normal file
17
src/main/resources/froglib.branding.mixins.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "dev.frogmc.froglib.branding.impl.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_21",
|
||||||
|
"mixins": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"server": [
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"client.ClientBrandRetrieverMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,10 @@
|
||||||
"package": "dev.frogmc.froglib.entrypoints.mixin",
|
"package": "dev.frogmc.froglib.entrypoints.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"server": [
|
"server": [
|
||||||
"server.MinecraftServerMixin"
|
"server.MinecraftServerMainMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"client.MainMixin"
|
"client.MinecraftMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"package": "dev.frogmc.froglib.events.impl.mixin",
|
"package": "dev.frogmc.froglib.events.impl.mixin",
|
||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"MinecraftServerMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"server.DedicatedServerMixin"
|
"server.DedicatedServerMixin"
|
||||||
|
|
17
src/main/resources/froglib.keybinds.mixins.json
Normal file
17
src/main/resources/froglib.keybinds.mixins.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "dev.frogmc.froglib.keybinds.impl.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_21",
|
||||||
|
"mixins": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"server": [
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"client.KeyMappingMixin"
|
||||||
|
],
|
||||||
|
"injectors": {
|
||||||
|
"defaultRequire": 1
|
||||||
|
}
|
||||||
|
}
|
14
src/test/java/dev/frogmc/froglib/test/KeybindsTest.java
Normal file
14
src/test/java/dev/frogmc/froglib/test/KeybindsTest.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package dev.frogmc.froglib.test;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
|
import dev.frogmc.froglib.entrypoints.ClientExtension;
|
||||||
|
import dev.frogmc.froglib.keybinds.api.KeyMappings;
|
||||||
|
import dev.frogmc.frogloader.api.mod.ModProperties;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
|
|
||||||
|
public class KeybindsTest implements ClientExtension {
|
||||||
|
@Override
|
||||||
|
public void onClientInit(ModProperties mod) {
|
||||||
|
KeyMappings.register(new KeyMapping("key.froglib.test", InputConstants.KEY_O, "category.froglib"));
|
||||||
|
}
|
||||||
|
}
|
19
src/test/resources/frog.mod.toml
Normal file
19
src/test/resources/frog.mod.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[frog]
|
||||||
|
format_version = "1.0.0"
|
||||||
|
|
||||||
|
[frog.mod]
|
||||||
|
id = "frog_lib_test"
|
||||||
|
name = "Frog Lib Test Mod"
|
||||||
|
version = "1.0.0"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
credits = [
|
||||||
|
{ name = "FrogMC Team", roles = ["author"] }
|
||||||
|
]
|
||||||
|
|
||||||
|
[frog.dependencies]
|
||||||
|
depends = [
|
||||||
|
{ id = "minecraft", versions = "~1.20.6", name = "Minecraft" }
|
||||||
|
]
|
||||||
|
|
||||||
|
[frog.extensions]
|
||||||
|
client = "dev.frogmc.froglib.test.KeybindsTest"
|
Loading…
Reference in a new issue