Skip to content

Commit

Permalink
Changed 1.16.5 System.out.println to normal logger
Browse files Browse the repository at this point in the history
Add PatLogger in PatPatClient
Geckolib fix in <= 1.19.3 (Tested on 1.16.5)
Add 1.21.4 support
Order of class initialization in PatPat has been changed
Added stonecutter geckolib var
Added MIN_SUPPORT_VERSION for custom resourcepacks
Updated stonecutter version
  • Loading branch information
nikita51bot committed Dec 4, 2024
1 parent 60005b7 commit 85d812d
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 133 deletions.
49 changes: 30 additions & 19 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 @@ -193,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 @@ -226,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 @@ -413,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 @@ -440,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 @@ -507,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 @@ -532,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 @@ -546,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 @@ -599,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
2 changes: 1 addition & 1 deletion 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.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
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 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.5-beta.5"
}

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");
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/lopymine/patpat/compat/LoadedMods.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void onInitialize() {

private static void sendDebugLog(boolean modLoaded, String modId) {
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("{} Loaded: {}", modId, modLoaded);
PatPatClient.LOGGER.info("{} Loaded: {}", modId, modLoaded);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ public class GeckoLibCompatPlugin extends CompatPlugin {

@Override
protected String getCompatModId() {
//? <= 1.19.3 {
/*return "geckolib3";
*///?} else {
return "geckolib";
//?}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ReplayModCompat {

public static void onPat(UUID pattedEntity, UUID whoPatted) {
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Sending dummy packet for Replay Mod. [Patted: {} and Who: {}]", pattedEntity, whoPatted);
PatPatClient.LOGGER.info("Sending dummy packet for Replay Mod. [Patted: {} and Who: {}]", pattedEntity, whoPatted);
}
if (LoadedMods.REPLAY_MOD_LOADED) {
PatEntityForReplayModS2CPacket packet = new PatEntityForReplayModS2CPacket(pattedEntity, whoPatted);
Expand All @@ -30,7 +30,7 @@ public static void onPat(UUID pattedEntity, UUID whoPatted) {
return;
}
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Replay Mod not Installed!");
PatPatClient.LOGGER.info("Replay Mod not Installed!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void sendDummyPacket(Packet<?> packet) {
//? !(=1.20.5) {
if (com.replaymod.recording.ReplayModRecording.instance.getConnectionEventHandler() != null) {
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Sent dummy packet for Replay Mod");
PatPatClient.LOGGER.info("Sent dummy packet for Replay Mod");
}
com.replaymod.recording.packet.PacketListener packetListener = com.replaymod.recording.ReplayModRecording.instance.getConnectionEventHandler().getPacketListener();
if (packetListener != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public static PatPatClientConfig getInstance() {
private static @NotNull PatPatClientConfig create() {
PatPatClientConfig config = new PatPatClientConfig();
try (FileWriter writer = new FileWriter(CONFIG_FILE, StandardCharsets.UTF_8)) {
String json = GSON.toJson(CODEC.encode(config, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPatClient::error));*/
String json = GSON.toJson(CODEC.encode(config, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPatClient.LOGGER::error));*/
writer.write(json);
} catch (Exception e) {
PatPatClient.error("Failed to create config", e);
PatPatClient.LOGGER.error("Failed to create config", e);
}
return config;
}
Expand All @@ -103,9 +103,9 @@ private static PatPatClientConfig read() {
}

try (FileReader reader = new FileReader(CONFIG_FILE, StandardCharsets.UTF_8)) {
return CODEC.decode(JsonOps.INSTANCE, /*? <=1.17.1 {*//*new JsonParser().parse(reader)*//*?} else {*/JsonParser.parseReader(reader)/*?}*/)/*? if >=1.20.5 {*/.getOrThrow()/*?} else {*//*.getOrThrow(false, PatPatClient::error)*//*?}*/.getFirst();
return CODEC.decode(JsonOps.INSTANCE, /*? <=1.17.1 {*//*new JsonParser().parse(reader)*//*?} else {*/JsonParser.parseReader(reader)/*?}*/)/*? if >=1.20.5 {*/.getOrThrow()/*?} else {*//*.getOrThrow(false, PatPatClient.LOGGER::error)*//*?}*/.getFirst();
} catch (Exception e) {
PatPatClient.error("Failed to read config", e);
PatPatClient.LOGGER.error("Failed to read config", e);
}
return PatPatClientConfig.create();
}
Expand All @@ -114,16 +114,16 @@ public void save() {
PatPatClient.setConfig(this);
CompletableFuture.runAsync(() -> {
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Saving PatPat Client Config...");
PatPatClient.LOGGER.info("Saving PatPat Client Config...");
}
try (FileWriter writer = new FileWriter(CONFIG_FILE, StandardCharsets.UTF_8)) {
String json = GSON.toJson(CODEC.encode(this, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPatClient::error));*/
String json = GSON.toJson(CODEC.encode(this, JsonOps.INSTANCE, JsonOps.INSTANCE.empty())/*? if >=1.20.5 {*/.getOrThrow());/*?} else*//*.getOrThrow(false, PatPatClient.LOGGER::error));*/
writer.write(json);
} catch (Exception e) {
PatPatClient.error("Failed to save config", e);
PatPatClient.LOGGER.error("Failed to save config", e);
}
if (PatPatClient.getConfig().isDebugLogEnabled()) {
PatPatClient.info("Saved PatPat Client Config");
PatPatClient.LOGGER.info("Saved PatPat Client Config");
}
});
}
Expand Down
Loading

0 comments on commit 85d812d

Please sign in to comment.