Showing with 899 additions and 329 deletions.
  1. +10 −14 CHANGELOG.md
  2. +1 −1 CHANGELOG_TEMPLATE.md
  3. +14 −2 build.gradle.kts
  4. +4 −3 gradle.properties
  5. +2 −1 settings.gradle.kts
  6. +4 −3 src/main/java/io/github/jamalam360/jamlib/Ducks.java
  7. +13 −14 src/main/java/io/github/jamalam360/jamlib/JamLib.java
  8. +3 −5 src/main/java/io/github/jamalam360/jamlib/JamLibClient.java
  9. +56 −8 src/main/java/io/github/jamalam360/jamlib/Util.java
  10. +116 −0 src/main/java/io/github/jamalam360/jamlib/compatibility/JamLibCompatibilityModuleHandler.java
  11. +87 −34 src/main/java/io/github/jamalam360/jamlib/config/JamLibConfig.java
  12. +9 −5 src/main/java/io/github/jamalam360/jamlib/event/client/MouseScrollCallback.java
  13. +50 −19 src/main/java/io/github/jamalam360/jamlib/keybind/JamLibKeybinds.java
  14. +66 −15 src/main/java/io/github/jamalam360/jamlib/log/JamLibLogger.java
  15. +3 −3 src/main/java/io/github/jamalam360/jamlib/mixin/JamLibMixinPlugin.java
  16. +4 −3 src/main/java/io/github/jamalam360/jamlib/mixin/dev/EulaReaderMixin.java
  17. +4 −3 src/main/java/io/github/jamalam360/jamlib/mixin/dev/MinecraftServerMixin.java
  18. +13 −12 src/main/java/io/github/jamalam360/jamlib/mixin/dev/session/MinecraftClientMixin.java
  19. +3 −1 src/main/java/io/github/jamalam360/jamlib/mixin/dev/session/RunArgsNetworkMixin.java
  20. +9 −8 src/main/java/io/github/jamalam360/jamlib/mixin/event/client/MouseMixin.java
  21. +23 −5 src/main/java/io/github/jamalam360/jamlib/network/JamLibC2SNetworkChannel.java
  22. +11 −3 src/main/java/io/github/jamalam360/jamlib/network/JamLibClientNetworking.java
  23. +9 −7 src/main/java/io/github/jamalam360/jamlib/network/JamLibNetworkChannel.java
  24. +27 −5 src/main/java/io/github/jamalam360/jamlib/network/JamLibS2CNetworkChannel.java
  25. +10 −2 src/main/java/io/github/jamalam360/jamlib/network/JamLibServerNetworking.java
  26. +190 −24 src/main/java/io/github/jamalam360/jamlib/registry/JamLibRegistry.java
  27. +4 −1 src/main/java/io/github/jamalam360/jamlib/registry/annotation/BlockItemFactory.java
  28. +5 −1 src/main/java/io/github/jamalam360/jamlib/registry/annotation/ContentRegistry.java
  29. +6 −1 src/main/java/io/github/jamalam360/jamlib/registry/annotation/WithIdentifier.java
  30. +2 −1 src/main/java/io/github/jamalam360/jamlib/registry/annotation/WithoutBlockItem.java
  31. +0 −96 src/main/java/io/github/jamalam360/jamlib/tick/TickScheduling.java
  32. +4 −3 src/main/resources/fabric.mod.json
  33. +8 −3 src/testmod/java/io/github/jamalam360/jamlib/test/JamLibTest.java
  34. +11 −11 src/testmod/java/io/github/jamalam360/jamlib/test/JamLibTestClient.java
  35. +1 −0 src/testmod/java/io/github/jamalam360/jamlib/test/JamLibTestNetwork.java
  36. +8 −7 ...amlib/Callback.java → testmod/java/io/github/jamalam360/jamlib/test/TestCompatibilityModule.java}
  37. +1 −1 src/testmod/java/io/github/jamalam360/jamlib/test/registry/TestBlocks.java
  38. +36 −0 src/testmod/java/io/github/jamalam360/jamlib/test/registry/TestEntities.java
  39. +64 −0 src/testmod/java/io/github/jamalam360/jamlib/test/registry/TestEntity.java
  40. +1 −0 src/testmod/java/io/github/jamalam360/jamlib/test/registry/TestItems.java
  41. +5 −2 src/testmod/resources/fabric.mod.json
  42. +2 −2 versions.toml
24 changes: 10 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
## Changelog

### Features

- Add `MouseScrollCallback`.

### Fixes
Support for 1.19-1.19.2 is back, along with 1.19.3 of course!

- Prefix mod ID to initialize messages.
- Add logging for dev features.
- Switch to QM on intermediary.

### Removals

- Removed JamLib config reload command.
### Features

Closed issues: None.
- Add a logger that is only active in development environments.
- Automatically register entity attributes for entity types registered through JamLib.
- Add `JamLibCompatibilityModuleHandler`.
- `JamLibLogger` now takes varargs to it's logging methods.
- Use SL4J rather than Log4J.
- Add JavaDoc.
- More overhauls.

[Full Changelog](https://github.com/JamCoreModding/JamLib/compare/0.4.4...0.5.0)
[Full Changelog](https://github.com/JamCoreModding/jam-lib/compare/0.5.0...0.6.0+1.19)
2 changes: 1 addition & 1 deletion CHANGELOG_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

Closed issues: None.

[Full Changelog](https://github.com/JamCoreModding/JamLib/compare/...)
[Full Changelog](https://github.com/JamCoreModding/jam-lib/compare/...)
16 changes: 14 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("fabric-loom") version "1.0-SNAPSHOT"
id("io.github.juuxel.loom-quiltflower") version "1.7.+"
id("io.github.juuxel.loom-quiltflower") version "1.+"
id("io.github.p03w.machete") version "1.+"
id("org.cadixdev.licenser") version "0.6.1"
}
Expand All @@ -16,7 +16,8 @@ version = mod_version
repositories {
val mavenUrls = mapOf(
Pair("https://maven.terraformersmc.com/releases", listOf("com.terraformersmc")),
Pair("https://maven.quiltmc.org/repository/release/", listOf("org.quiltmc")),
Pair("https://maven.quiltmc.org/repository/release/", listOf("org.quiltmc", "org.quiltmc.unpick")),
Pair("https://maven.quiltmc.org/repository/snapshot/", listOf("org.quiltmc", "org.quiltmc.unpick")),
Pair("https://api.modrinth.com/maven", listOf("maven.modrinth")),
)

Expand Down Expand Up @@ -44,6 +45,15 @@ dependencies {
modLocalRuntime(libs.bundles.runtime)
}

java {
withSourcesJar()
withJavadocJar()
}

tasks.withType(Javadoc::class.java) {
exclude("**/mixin/**")
}

sourceSets {
val main = this.getByName("main")

Expand All @@ -56,6 +66,8 @@ sourceSets {
}

loom {
runtimeOnlyLog4j.set(true)

runs {
create("testClient") {
client()
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

archive_base_name=jamlib
mod_version=0.5.0
release_name=V0.5.0 [1.19.x]
mod_version=0.6.0+1.19
release_name=V0.6.0 [1.19-1.19.2]
supported_versions=1.19,1.19.1,1.19.2
github_user=JamCoreModding
github_repo=JamLib
github_repo=jam-lib
release_branch=main
curseforge_project_id=623764
modrinth_project_id=jamlib
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ pluginManagement {
repositories {
val mavenUrls = listOf(
"https://maven.fabricmc.net/",
"https://maven.quiltmc.org/repository/release/"
"https://maven.quiltmc.org/repository/release/",
"https://maven.quiltmc.org/repository/snapshot/"
)

for (url in mavenUrls) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/github/jamalam360/jamlib/Ducks.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
package io.github.jamalam360.jamlib;

import net.minecraft.client.util.Session;
import org.jetbrains.annotations.ApiStatus.Internal;

/**
* @author Jamalam
*/
@Internal
public class Ducks {

public interface RunArgs$Network {

void setSession(Session session);
}
}
27 changes: 13 additions & 14 deletions src/main/java/io/github/jamalam360/jamlib/JamLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,33 @@

package io.github.jamalam360.jamlib;

import io.github.jamalam360.jamlib.config.JamLibConfig;
import static net.minecraft.server.command.CommandManager.literal;

import io.github.jamalam360.jamlib.log.JamLibLogger;
import io.github.jamalam360.jamlib.tick.TickScheduling;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus.Internal;

import static net.minecraft.server.command.CommandManager.literal;

@Internal
public class JamLib implements ModInitializer {

public static final JamLibLogger LOGGER = JamLibLogger.getLogger("jamlib");
public static final JamLibLogger DEV_LOGGER = JamLibLogger.getDevelopmentOnlyLogger("jamlib");

@Override
public void onInitialize() {
ServerTickEvents.END_WORLD_TICK.register(TickScheduling::onEndTickServer);

//noinspection CodeBlock2Expr
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, env) -> {
dispatcher.register(
literal("jamlib").then(
literal("version").executes(context -> {
//noinspection OptionalGetWithoutIsPresent
context.getSource().sendFeedback(Text.literal("JamLib " + FabricLoader.getInstance().getModContainer("jamlib").get().getMetadata().getVersion()), false);
return 1;
})
)
literal("jamlib").then(
literal("version").executes(context -> {
//noinspection OptionalGetWithoutIsPresent
context.getSource().sendFeedback(Text.literal("JamLib " + FabricLoader.getInstance().getModContainer("jamlib").get().getMetadata().getVersion()), false);
return 1;
})
)
);
});

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/io/github/jamalam360/jamlib/JamLibClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
package io.github.jamalam360.jamlib;

import io.github.jamalam360.jamlib.keybind.JamLibKeybinds;
import io.github.jamalam360.jamlib.tick.TickScheduling;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import org.jetbrains.annotations.ApiStatus.Internal;

/**
* @author Jamalam360
*/
@Internal
public class JamLibClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ClientTickEvents.END_WORLD_TICK.register(TickScheduling::onEndTickClient);
ClientTickEvents.END_CLIENT_TICK.register(JamLibKeybinds::onEndTick);
}
}
64 changes: 56 additions & 8 deletions src/main/java/io/github/jamalam360/jamlib/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,70 @@

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;

/**
* @author Jamalam
* General utilities that aren't related to Minecraft.
*/
public class Util {
public static <T> void ifNotNull(T value, Consumer<T> consumer) {
if (value != null) consumer.accept(value);

/**
* @param value The nullable value.
* @param consumer The consumer to run if {@code value} is not null.
* @param <T> The return type.
*/
public static <T> void ifNotNull(@Nullable T value, Consumer<T> consumer) {
if (value != null) {
consumer.accept(value);
}
}

public static <T> void ifNotNull(T value, Consumer<T> consumer, Callback elseConsumer) {
if (value != null) consumer.accept(value);
else elseConsumer.accept();
/**
* @param value The nullable value.
* @param consumer The consumer to run if {@code value} is not null.
* @param elseCallback The callback to run if {@code value} is null.
* @param <T> The return type.
*/
public static <T> void ifNotNull(@Nullable T value, Consumer<T> consumer, Runnable elseCallback) {
if (value != null) {
consumer.accept(value);
} else {
elseCallback.run();
}
}

public static <T, R> R ifNotNull(T value, Function<T, R> function, R elseValue) {
if (value != null) return function.apply(value);
/**
* @param value The nullable value.
* @param function The function to run to calculate the return value if {@code value} is not null.
* @param elseValue The value to return if {@code value} is null.
* @param <T> The value type.
* @param <R> The return type.
*
* @return The value computed by the {@code function} if {@code value} is not null, or else the {@code elseValue}.
*/
public static <T, R> R ifNotNull(@Nullable T value, Function<T, R> function, R elseValue) {
if (value != null) {
return function.apply(value);
}

return elseValue;
}

/**
* @param value The nullable value.
* @param function The function to run to calculate the return value if {@code value} is not null.
* @param elseFunction The function to run to calculate the return value if {@code value} is null.
* @param <T> The value type.
* @param <R> The return type.
*
* @return The value computed by the {@code function} if {@code value} is not null, or else the value computed by the {@code elseFunction}.
*/
public static <T, R> R ifNotNull(@Nullable T value, Function<T, R> function, Supplier<R> elseFunction) {
if (value != null) {
return function.apply(value);
}

return elseFunction.get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022 Jamalam
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package io.github.jamalam360.jamlib.compatibility;

import io.github.jamalam360.jamlib.JamLib;
import java.util.Optional;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.VersionParsingException;
import net.fabricmc.loader.api.metadata.version.VersionPredicate;

/**
* <p>Helper class to initialize 'compatibility modules' for a mod. A compatibility module is
* an entrypoint (that implements {@link ModInitializer}) that is only loaded when another specific mod is loaded.</p>
*
* <p>To define compatibility modules, create a {@code jamlib:compatibility_modules} map
* in your {@code fabric.mod.json}'s {@code custom} field (or the equivalent for the Quilt toolchain). The keys of this map should be mod ID's, and the values should be
* the fully qualified name of your compatibility module</p>
*
* <p>For example, to create an entrypoint that is only loaded if EMI is installed:</p>
* <pre>
* {@code
* "custom": {
* "jamlib:compatibility_modules": {
* "emi": "io.github.jamalam360.test.EmiCompatibility"
* }
* }
* }
* </pre>
* <p>JamLib only loads these classes if the other mod is present, so as long as you are
* careful, you shouldn't run into classloading issues.</p>
*
* <p>You can also optionally define a version(-range), which is parsed using {@link VersionPredicate#parse(String)}:</p>
* <pre>
* {@code
* "custom": {
* "jamlib:compatibility_modules": {
* "emi[>=0.3.0]": "io.github.jamalam360.test.EmiCompatibility",
* "emi[<0.3.0]": "io.github.jamalam360.test.OldEmiCompatibility",
* }
* }
* }
* </pre>
*/
public class JamLibCompatibilityModuleHandler {

/**
* Search for, and initialize if required, all compatibility modules under the specified {@code modId}.
*
* @param modId <b>Your mod's</b> ID. Used to lookup the {@code jamlib:compatibility_modules}
* map from the {@code fabric.mod.json} or {@code quilt.mod.json}.
*/
public static void initialize(String modId) {
Optional<ModContainer> mod = FabricLoader.getInstance().getModContainer(modId);

if (mod.isEmpty()) {
JamLib.LOGGER.warn("Attempted to initialize compatibility modules for non-existent mod " + modId);
return;
}

if (!mod.get().getMetadata().containsCustomValue("jamlib:compatibility_modules")) {
JamLib.LOGGER.warn("Attempted to initialize compatibility modules for mod with incorrect metadata", modId);
}

mod.get().getMetadata().getCustomValue("jamlib:compatibility_modules").getAsObject().forEach(((e -> {
String compatId = e.getKey();
VersionPredicate versionPredicate = null;

if (compatId.contains("[") && compatId.endsWith("]")) {
String version = compatId.substring(compatId.indexOf("[") + 1, compatId.length() - 1);
compatId = compatId.substring(0, compatId.indexOf("["));

try {
versionPredicate = VersionPredicate.parse(version);
} catch (VersionParsingException ex) {
JamLib.LOGGER.warn("Encountered invalid version range", version, "from compatibility modules of mod", modId);
}
}

if (FabricLoader.getInstance().isModLoaded(compatId) && (versionPredicate == null || versionPredicate.test(FabricLoader.getInstance().getModContainer(compatId).get().getMetadata().getVersion()))) {
JamLib.LOGGER.info("Initializing", modId, "compatibility module for", compatId);

try {
Class<?> clazz = Class.forName(e.getValue().getAsString());
ModInitializer init = (ModInitializer) clazz.getConstructor().newInstance();
init.onInitialize();
} catch (Exception exception) {
JamLib.LOGGER.warn("Failed to initialize compatibility module:", exception.toString());
}
}
})));
}
}
Loading