Skip to content

Commit

Permalink
Incomplete ContextMenu overhaul +stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuilder1961 committed Nov 13, 2024
1 parent 8cab87a commit 7f5b3e3
Show file tree
Hide file tree
Showing 32 changed files with 1,286 additions and 1,030 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ repositories {
mavenCentral()
maven { url "https://maven.terraformersmc.com/releases/" } // Mod Menu
maven { url "https://maven.isxander.dev/releases" } // YACL
//todo NEW MAVEN FOR ARCH... later
}

dependencies {
minecraft "com.mojang:minecraft:$project.minecraft"
mappings "net.fabricmc:yarn:$project.minecraft$project.yarn:v2"
modImplementation "net.fabricmc:fabric-loader:$project.loader"
modImplementation "net.fabricmc.fabric-api:fabric-api:$project.api"
modImplementation "net.fabricmc.fabric-api:fabric-api:$project.api"//comment out
//modApi "dev.architectury:architectury-fabric:${project.arch_api}"

modImplementation "com.terraformersmc:modmenu:$project.modmenu"
modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:$project.yacl"
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
- Java 21 is now required for all future versions of Chat Patches, even for older Minecraft versions. 1.20.5+ also has this requirement, so it
likely is already installed
- Fatal chat log saving errors will now try and dump all the data to the debug log, as a last-ditch effort to save it
- Overhauled the copy menu, which is now known as the Context Menu! It now has more features, including a toggle, main buttons copying their first
sub-button, and even more message parts to copy! ([#128](https://www.github.com/mrbuilder1961/ChatPatches/issues/128), [#129](https://www.github.com/mrbuilder1961/ChatPatches/issues/129), (maybe #166?), [#168](https://www.github.com/mrbuilder1961/ChatPatches/issues/168), [#185](https://www.github.com/mrbuilder1961/ChatPatches/issues/185))
- Random misc changes, dependency updates, rewordings, etc.
- **Dev notes:**
- Removed some constant values in the `fabric.mod.json` file that can now be automatically generated by gradle with Loom! (this causes what looks like
illegal JSON, but is ultimately fixed when built)
- Replaced usages of Google's GSON library with Mojang's Codec system, which works better long-term and is slightly less error-prone
- TODO: FILL THIS OUT LATERRRR PRE-PUB COMMIT

## Chat Patches `202.6.5` for Minecraft 1.20.2 on Fabric, Quilt
- Added the `searchPrefix` config option, which controls whether to filter previously sent messages based on the text behind the cursor, to speed up
Expand Down
19 changes: 12 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ mrId=MOqt4Z5n
# Required dependencies - https://fabricmc.net/develop
minecraft=1.20.2
yarn=+build.4
loader=0.15.11
loader=0.16.9
api=0.91.6+1.20.2
loom=1.6-SNAPSHOT
publish_plugin=0.5.1
stonecutter_plugin=1.3.1
arch_api=10.1.20
loom=1.8-SNAPSHOT
# mpp: https://github.com/modmuss50/mod-publish-plugin?tab=readme-ov-file#basic-usage and stonecutter: -
publish_plugin=0.7.4
#stonecutter_plugin=1.3.1

# Dependencies - modmenu: https://modrinth.com/mod/modmenu/versions?l=fabric and yacl: https://modrinth.com/mod/yacl/versions?l=fabric
modmenu=8.0.1
yacl=3.3.0-beta.1+1.20.2

# Publishing metadata - phase can be ALPHA, BETA, or STABLE
targets=1.20.2
# Publishing metadata
# /- Typically the latest version, but can be 1.21.x for example
branch=1.20.2
targets=1.20.1,1.20.2
loaders=Fabric,Quilt
phase=STABLE
# /- ALPHA, BETA, or STABLE
phase=ALPHA
# relations
required=fabric-api,yacl
optionals=modmenu,no-chat-reports
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
24 changes: 14 additions & 10 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,7 +85,9 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +148,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +205,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down Expand Up @@ -245,4 +249,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
91 changes: 50 additions & 41 deletions src/main/java/obro1961/chatpatches/ChatPatches.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package obro1961.chatpatches;

import com.google.gson.JsonElement;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand All @@ -15,25 +18,36 @@
import obro1961.chatpatches.util.ChatUtils;
import obro1961.chatpatches.util.Flags;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.function.Supplier;

public class ChatPatches implements ClientModInitializer {
public static final Supplier<String> TIME_FORMATTER = () -> new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
public static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger("Chat Patches");
public static final String MOD_ID = "chatpatches";
public static final Logger LOGGER = LoggerFactory.getLogger("Chat Patches");
//public static final RegistryWrapper.WrapperLookup LOOKUP = BuiltinRegistries.createWrapperLookup();

public static Config config = Config.create();
/** Contains the sender and timestamp data of the last received chat message. */
public static ChatUtils.MessageData msgData = ChatUtils.NIL_MSG_DATA;

private static String lastWorld = "";

/**
* Returns a {@code chatpatches:${path}}
* {@link Identifier}.
*/
public static Identifier id(String path) {
// unfortunately this method in 1.20.6 is method_43902
// but in 1.21 it's method_60655, making it incompatible
// this is grinding my gears bc the code is identical ToT
return Identifier.of(MOD_ID, path);
}

@Override
public void onInitializeClient() {
//todo: put all these callbacks somewhere else so i can split them by loader w arch api later
/*
* ChatLog saving events, run if config.chatlog is true:
* CLIENT_STOPPING - Always saves
Expand All @@ -56,10 +70,10 @@ public void onInitializeClient() {
ChatLog.restore(client);
}

ChatHudAccessor chatHud = ChatHudAccessor.from(client);
ChatHudAccessor chat = (ChatHudAccessor) client.inGameHud.getChatHud();
String current = currentWorldName(client);
// continues if the boundary line is enabled, >0 messages sent, and if the last and current worlds were servers, that they aren't the same
if( config.boundary && !chatHud.getMessages().isEmpty() && (!current.startsWith("S_") || !lastWorld.startsWith("S_") || !current.equals(lastWorld)) ) {
if( config.boundary && !chat.chatpatches$getMessages().isEmpty() && (!current.startsWith("S_") || !lastWorld.startsWith("S_") || !current.equals(lastWorld)) ) {
try {
String levelName = (lastWorld = current).substring(2); // makes a variable to update lastWorld in a cleaner way

Expand All @@ -72,16 +86,37 @@ public void onInitializeClient() {
}
}

// sets all messages (restored and boundary line) to a addedTime of 0 to prevent instant rendering (#42)
if(ChatLog.loaded && Flags.INIT.isRaised()) {
chatHud.getVisibleMessages().replaceAll(ln -> new ChatHudLine.Visible(0, ln.content(), ln.indicator(), ln.endOfEntry()));
Flags.INIT.lower();
}
// sets all messages (restored and boundary line) to a addedTime of -200 to prevent instant rendering (#42)
// only replaces messages that would render instantly to save performance on large chat logs
// no longer ran once per game, but once per join (#151)
int t = client.inGameHud.getTicks();
chat.chatpatches$getVisibleMessages().replaceAll(ln -> (t - ln.addedTime() < 200) ? new ChatHudLine.Visible(-200, ln.content(), ln.indicator(), ln.endOfEntry()) : ln);
});

LOGGER.info("[ChatPatches()] Finished setup!");
}

/**
* Returns the current ClientWorld's name. For singleplayer,
* returns the level name. For multiplayer, returns the
* server entry name. Falls back on the IP if it was
* direct-connect. Leads with "C_" or "S_" depending
* on the source of the ClientWorld.
* @param client A non-null MinecraftClient that must be in-game.
* @return (C or S) + "_" + (current world name)
*/
@SuppressWarnings("DataFlowIssue") // getServer and getCurrentServerEntry are not null if isIntegratedServerRunning is true
public static String currentWorldName(@NotNull MinecraftClient client) {
Objects.requireNonNull(client, "MinecraftClient must exist to access client data:");
String entryName;

return client.isIntegratedServerRunning()
? "C_" + client.getServer().getSaveProperties().getLevelName()
: (entryName = client.getCurrentServerEntry().name) == null || entryName.isBlank() // check if null/empty then use IP
? "S_" + client.getCurrentServerEntry().address
: "S_" + client.getCurrentServerEntry().name;
}


/**
* Logs an error-level message telling the user to report
Expand All @@ -102,34 +137,8 @@ public static void logInfoReportMessage(Throwable error) {
LOGGER.error("[%s.%s] /!\\ Please report this error on GitHub or Discord with the full log file attached! /!\\".formatted(clazz, method), error);
}

/**
* Creates a new Identifier using the ChatPatches mod ID.
* {@link Identifier#of(String, String)} is future-proof
* compared to {@link Identifier#Identifier(String, String)}
* (as of 06/16/2024).
*/
public static Identifier id(String path) {
return Identifier.of(MOD_ID, path);
}

/**
* Returns the current ClientWorld's name. For singleplayer,
* returns the level name. For multiplayer, returns the
* server entry name. Falls back on the IP if it was
* direct-connect. Leads with "C_" or "S_" depending
* on the source of the ClientWorld.
* @param client A non-null MinecraftClient that must be in-game.
* @return (C or S) + "_" + (current world name)
*/
@SuppressWarnings("DataFlowIssue") // getServer and getCurrentServerEntry are not null if isIntegratedServerRunning is true
public static String currentWorldName(@NotNull MinecraftClient client) {
Objects.requireNonNull(client, "MinecraftClient must exist to access client data:");
String entryName;

return client.isIntegratedServerRunning()
? "C_" + client.getServer().getSaveProperties().getLevelName()
: (entryName = client.getCurrentServerEntry().name) == null || entryName.isBlank() // check if null/empty then use IP
? "S_" + client.getCurrentServerEntry().address
: "S_" + client.getCurrentServerEntry().name;
// 1.20.5+ needs the RegistryOps instance
public static DynamicOps<JsonElement> jsonOps() {
return JsonOps.INSTANCE;
}
}
21 changes: 4 additions & 17 deletions src/main/java/obro1961/chatpatches/accessor/ChatHudAccessor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package obro1961.chatpatches.accessor;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.ChatHudLine;
import obro1961.chatpatches.mixin.gui.ChatHudMixin;
Expand All @@ -10,29 +9,17 @@
/**
* An access-widening interface used with {@link ChatHudMixin}
* to access necessary fields and methods w/o an extra
* accessor mixin. To get an instance, use
* {@link ChatHudAccessor#from(ChatHud)} or
* {@link ChatHudAccessor#from(MinecraftClient)}.
* accessor mixin.
*/
public interface ChatHudAccessor {
// these two methods avoid needing to cast everywhere because it looks ugly
static ChatHudAccessor from(ChatHud chatHud) {
return ((ChatHudAccessor) chatHud);
}
static ChatHudAccessor from(MinecraftClient client) {
return from(client.inGameHud.getChatHud());
}

//todo: decide in the future if i should add the prefix back, and also re-eval what access is still needed here
// unique methods, not present in ChatHud
/** {@link ChatHud#messages} */
List<ChatHudLine> getMessages();
List<ChatHudLine> chatpatches$getMessages();
/** {@link ChatHud#visibleMessages} */
List<ChatHudLine.Visible> getVisibleMessages();
/** {@link ChatHud#removalQueue} */
List<?> getRemovalQueue();
List<ChatHudLine.Visible> chatpatches$getVisibleMessages();
/** {@link ChatHud#scrolledLines} */
int getScrolledLines();
int chatpatches$getScrolledLines();

// renamed methods to access-widen them from ChatHud
/** {@link ChatHud#getMessageLineIndex(double, double)} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import net.minecraft.client.gui.screen.ChatScreen;

public interface ChatScreenAccessor {
static ChatScreenAccessor from(ChatScreen chatScreen) {
return ((ChatScreenAccessor) chatScreen);
}

void chatpatches$clearMessageDraft();
}
//todo here get rid of chatpatches$ orrr whattt
/** {@link ChatScreen#chatField}{@code .setText(str)} */
void chatpatches$overrideChatText(String str);
}
Loading

0 comments on commit 7f5b3e3

Please sign in to comment.