Skip to content

Commit

Permalink
Merge pull request #4 from LopyMine/GeckoLib-Support
Browse files Browse the repository at this point in the history
GeckoLib Support
  • Loading branch information
LopyMine authored Dec 4, 2024
2 parents 5a3701f + 98ac096 commit 5738674
Show file tree
Hide file tree
Showing 54 changed files with 333 additions and 134 deletions.
77 changes: 57 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import groovy.json.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.marhali:json5-java:2.0.0'
}
}

// TODO Move methods with j5tj in buildSrc and use kotlin lang
import de.marhali.json5.Json5
import de.marhali.json5.Json5Element

plugins {
id("fabric-loom") version "1.8-SNAPSHOT"
Expand Down Expand Up @@ -55,6 +66,16 @@ repositories {
name "Modrinth"
url "https://api.modrinth.com/maven"
} // Replay Mod

maven {
name = 'GeckoLib'
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
content {
includeGroupByRegex("software\\.bernie.*")
includeGroup("com.eliotlash.mclib")
includeGroup("com.eliotlash.molang")
}
}
}

dependencies {
Expand Down Expand Up @@ -89,6 +110,22 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

// GeckoLib
def geckoLibVersion = prop("dep.geckolib")
if (geckoLibVersion != "unknown") {
if (mcVersion == "1.17.1") {
modImplementation("software.bernie.geckolib:geckolib-fabric-1.17:${geckoLibVersion}")
} else if (mcVersion == "1.18.2") {
modImplementation("software.bernie.geckolib:geckolib-fabric-1.18:${geckoLibVersion}")
} else if (mcVersion == "1.19.1" || mcVersion == "1.19.2") {
modImplementation("software.bernie.geckolib:geckolib-fabric-1.19:${geckoLibVersion}")
} else if (mcVersion == "1.20") {
modImplementation("software.bernie.geckolib:geckolib-fabric-1.20.1:${geckoLibVersion}")
} else {
modImplementation("software.bernie.geckolib:geckolib-fabric-${mcVersion}:${geckoLibVersion}")
}
}

if (!(stonecutter.compare("1.20.5", mcVersion) == 0)) {
// Replay Mod
modImplementation("maven.modrinth:replaymod:${findProperty("dep.replaymod")}")
Expand Down Expand Up @@ -152,7 +189,7 @@ processResources {
inputs.property key, value
}

filesMatching(["fabric.mod.json", "${modId}.mixins.json5".toString(), "assets/${modId}/lang/*.json".toString(), "assets/${modId}/textures/easter/egg.json".toString()]) {
filesMatching(["fabric.mod.json", "${modId}.mixins.json5".toString(), "${modId}-geckolib.mixins.json5".toString(), "assets/${modId}/lang/*.json".toString(), "assets/${modId}/textures/easter/egg.json".toString()]) {
expand(props)
}

Expand All @@ -167,6 +204,7 @@ stonecutter {
swap("mod_version", "\"${prop("mod_version")}\";")
swap("mod_id", "\"${prop("mod_id")}\";")
swap("mod_name", "\"${prop("mod_name")}\";")
stonecutter.const("geckolib", prop("dep.geckolib") != "unknown")
}

tasks.withType(JavaCompile).configureEach {
Expand Down Expand Up @@ -200,13 +238,12 @@ tasks.named("processResources") {
return
}

def parser = new JsonSlurper()
parser.type = JsonParserType.LAX
def obj = parser.parseText(json5Text)
def json = JsonOutput.toJson(obj)
Json5 json5 = Json5.builder(options -> options.allowInvalidSurrogate().build());
Json5Element obj = json5.parse(json5Text)
String json = json5.serialize(obj)

def jsonPath = parent.resolve(substringBeforeLast(name, ".") + ".json").toString()
def jsonFile = new File(jsonPath)
String jsonPath = parent.resolve(substringBeforeLast(name, ".") + ".json").toString()
File jsonFile = new File(jsonPath)

jsonFile.parentFile.mkdirs()
jsonFile.write(json)
Expand Down Expand Up @@ -387,16 +424,16 @@ publishMods {
}

if (requiresDepends.first() != "none") {
requires(requiresDepends)
requires = requiresDepends
}
if (optionalDepends.first() != "none") {
optional(optionalDepends)
optional = optionalDepends
}
if (incompatibleDepends.first() != "none") {
incompatible(incompatibleDepends)
incompatible = incompatibleDepends
}
if (embedsDepends.first() != "none") {
embeds(embedsDepends)
embeds = embedsDepends
}
}

Expand All @@ -414,16 +451,16 @@ publishMods {
}

if (requiresDepends.first() != "none") {
requires(requiresDepends)
requires = requiresDepends
}
if (optionalDepends.first() != "none") {
optional(optionalDepends)
optional = optionalDepends
}
if (incompatibleDepends.first() != "none") {
incompatible(incompatibleDepends)
incompatible = incompatibleDepends
}
if (embedsDepends.first() != "none") {
embeds(embedsDepends)
embeds = embedsDepends
}
}
}
Expand Down Expand Up @@ -481,7 +518,7 @@ UUID getUUID(Object uuid) {
return null
}

// Cannot be static!
@SuppressWarnings('GrMethodMayBeStatic') // Method cannot be static
int getJavaVersionAsInteger(String minecraftVersion) {
return stonecutter.compare("1.20.5", minecraftVersion) == 1 ?
stonecutter.compare("1.18", minecraftVersion) == 1 ?
Expand All @@ -506,7 +543,7 @@ Properties getPersonalProperties() {
for (line in personalPropertiesFile.readLines()) {
def key = "absolute_path_to_sponge_mixin"
if (line.startsWith(key)) {
def substring = line.substring(key.length()+1)
def substring = line.substring(key.length() + 1)
if (!substring.isEmpty()) {
personalProperties.setProperty(key, substring)
}
Expand All @@ -520,7 +557,7 @@ Properties getPersonalProperties() {
MultiVersion getCurrentMultiVersion(String minecraftVersion) {
def versions = prop("publication_versions").toString().split(" ")
for (version in versions) {
def split = version.substring(0, version.length()-1).split("\\[")
def split = version.substring(0, version.length() - 1).split("\\[")
def project = split[0]
if (project == minecraftVersion) {
def supportedVersionsString = split[1]
Expand Down Expand Up @@ -573,7 +610,7 @@ class MultiVersion {
bMax = maxVersion.length()
}
def maxMain = maxVersion.substring(0, bMax)
def maxMinor = maxVersion.substring(bMax+1, maxVersion.length())
def maxMinor = maxVersion.substring(bMax + 1, maxVersion.length())
if (minMain == maxMain) {
return "${minVersion}-${maxMinor}"
}
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ lombok_version = 1.18.32

# Multi-Versions Properties
# Verified version: 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21
multi_versions = 1.21.3
multi_versions = 1.16.5 1.17 1.17.1 1.18 1.18.1 1.18.2 1.19 1.19.1 1.19.2 1.19.3 1.19.4 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21 1.21.1 1.21.2 1.21.3 1.21.4

# Build Dependencies
build.yarn = [VERSIONED]
Expand All @@ -35,6 +35,7 @@ dep.yacl = [VERSIONED]
dep.modmenu = [VERSIONED]
dep.cloth-config = [VERSIONED]
dep.replaymod = [VERSIONED]
dep.geckolib = [VERSIONED]

# # # # # # # # # # # # # #
# Publication Properties #
Expand All @@ -43,7 +44,7 @@ dep.replaymod = [VERSIONED]
# Mod Loaders
loaders = fabric
# Publication Versions from `ROOT/build/libs/mod-version-here.jar` or from `ROOT/versions/MULTI_VERSION/build/libs/...` if not present in root
publication_versions = 1.16.5 1.17 1.17.1 1.18 1.18.2 1.19 1.19.1 1.19.2 1.19.3 1.19.4 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21
publication_versions = 1.16.5 1.17 1.17.1 1.18 1.18.1 1.18.2 1.19 1.19.1 1.19.2 1.19.3 1.19.4 1.20 1.20.1 1.20.2 1.20.3 1.20.4 1.20.5 1.20.6 1.21 1.21.1 1.21.2 1.21.3
# Version Type [RELEASE, BETA, ALPHA]
version_type = RELEASE

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pluginManagement {
}

plugins {
id "dev.kikugie.stonecutter" version "0.4.4"
id "dev.kikugie.stonecutter" version "0.4.6"
}

def multiVersions = getMultiVersions()
Expand Down
28 changes: 5 additions & 23 deletions src/main/java/net/lopymine/patpat/PatLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,27 @@

//? >=1.17 {
import org.slf4j.*;
//?}
//?} else {
/*import org.apache.logging.log4j.*;
*///?}

public class PatLogger {

//? >=1.17 {
private final Logger logger;
//?} else {
/*private final String name;
*///?}

public PatLogger(String name){
//? >=1.17 {
logger = LoggerFactory.getLogger(name);
//?} else {
/*this.name = name;
*///?}
public PatLogger(String name) {
logger = /*? if >=1.17 {*/LoggerFactory/*?} else {*//*LogManager*//*?}*/.getLogger(name);
}

public void info(String text, Object... args) {
//? >=1.17 {
logger.info(text, args);
//?} else {
/*System.out.println("[%s/INFO] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}

public void warn(String text, Object... args) {
//? >=1.17 {
logger.warn(text, args);
//?} else {
/*System.out.println("[%s/WARN] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}

public void error(String text, Object... args) {
//? >=1.17 {
logger.error(text, args);
//?} else {
/*System.out.println("[%s/ERROR] ".formatted(name) + text.replace("{}", "%s").formatted(args));
*///?}
}
}
4 changes: 2 additions & 2 deletions src/main/java/net/lopymine/patpat/PatPat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public class PatPat implements ModInitializer {

public static final PatLogger LOGGER = new PatLogger(MOD_NAME);
@Getter
private static PatPatServerConfig config = PatPatServerConfig.getInstance();
private static PatPatServerConfig config;

@Override
public void onInitialize() {
PatPat.config = PatPatServerConfig.getInstance();
PatPatConfigManager.onInitialize();
PatPat.config = PatPatServerConfig.getInstance();
PatPatServerCommandManager.register();
PatPatServerPacketManager.register();
PatPat.LOGGER.info("PatPat Initialized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static <S> ListMode getListMode(CommandContext<S> context, String id) {
public ListMode parse(StringReader reader) throws CommandSyntaxException {
String modeId = reader.readUnquotedString();
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Parsed modeId from ListModeArgumentType: {}", modeId);
PatPatClient.LOGGER.info("Parsed modeId from ListModeArgumentType: {}", modeId);
}
ListMode listMode = ListMode.getById(modeId);
if (listMode == null) {
Expand All @@ -46,11 +46,11 @@ public ListMode parse(StringReader reader) throws CommandSyntaxException {

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestMatching(Arrays.stream(ListMode.values()).flatMap((listMode) -> Stream.of(listMode.name())).toList(), builder);
return CommandSource.suggestMatching(Arrays.stream(ListMode.values()).flatMap(listMode -> Stream.of(listMode.name())).toList(), builder);
}

@Override
public Collection<String> getExamples() {
return Arrays.stream(ListMode.values()).flatMap((listMode) -> Stream.of(listMode.name())).toList();
return Arrays.stream(ListMode.values()).flatMap(listMode -> Stream.of(listMode.name())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PlayerInfo parse(@NotNull StringReader reader) throws CommandSyntaxExcept
String s = reader.readUnquotedString();

if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Parsed PlayerInfo from PlayerInfoArgumentType: {}",s);
PatPatClient.LOGGER.info("Parsed PlayerInfo from PlayerInfoArgumentType: {}",s);
}

ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
Expand Down
33 changes: 3 additions & 30 deletions src/main/java/net/lopymine/patpat/client/PatPatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,20 @@

import lombok.*;

//? >=1.17
import org.slf4j.*;

import net.fabricmc.api.ClientModInitializer;

import net.lopymine.patpat.PatLogger;
import net.lopymine.patpat.compat.LoadedMods;
import net.lopymine.patpat.config.client.PatPatClientConfig;
import net.lopymine.patpat.manager.client.*;

public class PatPatClient implements ClientModInitializer {

//? >=1.17
public static final Logger LOGGER = LoggerFactory.getLogger("PatPat/Client");
public static final PatLogger LOGGER = new PatLogger("PatPat/Client");
@Getter
@Setter
private static PatPatClientConfig config;

public static void info(String text, Object... args) {
//? >=1.17 {
LOGGER.info(text, args);
//?} else {
/*System.out.println("[PatPat/Client/INFO] " + text.replace("{}", "%s").formatted(args));
*///?}
}

public static void warn(String text, Object... args) {
//? >=1.17 {
LOGGER.warn(text, args);
//?} else {
/*System.out.println("[PatPat/Client/WARN] " + text.replace("{}", "%s").formatted(args));
*///?}
}

public static void error(String text, Object... args) {
//? >=1.17 {
LOGGER.error(text, args);
//?} else {
/*System.out.println("[PatPat/Client/ERROR] " + text.replace("{}", "%s").formatted(args));
*///?}
}

@Override
public void onInitializeClient() {
PatPatClient.config = PatPatClientConfig.getInstance();
Expand All @@ -52,6 +25,6 @@ public void onInitializeClient() {
PatPatClientReloadListener.register();
LoadedMods.onInitialize();

info("PatPat Client Initialized");
LOGGER.info("PatPat Client Initialized");
}
}
Loading

0 comments on commit 5738674

Please sign in to comment.