Skip to content

Commit

Permalink
Merge branch '1.21-Unified' into update-to-1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Aizistral authored Oct 28, 2024
2 parents 58b2128 + cb05b3c commit 85c2993
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 183 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.+"
Expand Down Expand Up @@ -158,6 +158,7 @@ curseforge {
mainArtifact(remapJar)

addGameVersion project.minecraft_version
addGameVersion '1.21'
addGameVersion 'Quilt'
addGameVersion 'Fabric'
addGameVersion 'Java 21'
Expand Down Expand Up @@ -190,7 +191,7 @@ modrinth {
versionType = "${version_type}"
changelog = rootProject.file("docs/CHANGELOG.md").text
uploadFile = remapJar
gameVersions = [ project.minecraft_version ]
gameVersions = [ project.minecraft_version, '1.21' ]
loaders = ['fabric', 'quilt']

dependencies {
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#### **\[Build 1.21.1-v2.9.0\]:**

- Initial 1.21.1 port;
- Fixed a bug where client would disconnect from Realms if encryption is enabled, and a player's death from a named item is announced in chat ([thanks forkiesassds, #480](https://github.com/Aizistral-Studios/No-Chat-Reports/pull/480));
- Fixed server ping hanging up in multiplayer menu in some cases ([thanks pietro-lopes, #487](https://github.com/Aizistral-Studios/No-Chat-Reports/pull/487)).

#### **\[Build 1.21-v2.8.0\]:**

- Initial 1.21 port.
Expand Down
3 changes: 2 additions & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ curseforge {
changelog = rootProject.file('docs/CHANGELOG.md')

addGameVersion project.minecraft_version
addGameVersion '1.21'
addGameVersion "Java 21"
addGameVersion "Forge"

Expand All @@ -211,7 +212,7 @@ modrinth {
versionType = "${version_type}"
changelog = rootProject.file("docs/CHANGELOG.md").text
uploadFile = jar
gameVersions = [ project.minecraft_version ]
gameVersions = [ project.minecraft_version, '1.21' ]

syncBodyFrom = rootProject.file("docs/README.md").text
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"required": true,
"minVersion": "0.8",
"package": "com.aizistral.nochatreports.forge.mixins",
"compatibilityLevel": "JAVA_18",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"client.MixinClientConnection",
"client.MixinClientHandshakePacketListenerImpl",
"client.MixinClientPacketListener",
"client.MixinServerStatusPinger$1"
"client.MixinClientPacketListener"
],
"server": [],
"injectors": {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ forge_version=1.21.3-53.0.4
neoforge_version=21.3.4-beta

# Mod Properties
mod_version=1.21.3-v2.9.0
mod_version=1.21.3-v2.10.0
maven_group=com.aizistral.nochatreports
archives_base_name=NoChatReports-FABRIC
mod_id=nochatreports
Expand Down
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.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 3 additions & 2 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
id 'eclipse'
id 'idea'
id "com.modrinth.minotaur" version "2.+"
id 'net.neoforged.gradle.userdev' version '7.0.142'
id 'net.neoforged.gradle.userdev' version '7.0.145'
}

println("Applying plugins...")
Expand Down Expand Up @@ -170,6 +170,7 @@ curseforge {
changelog = rootProject.file('docs/CHANGELOG.md')

addGameVersion project.minecraft_version
addGameVersion '1.21'
addGameVersion "Java 21"
addGameVersion "NeoForge"

Expand All @@ -186,7 +187,7 @@ modrinth {
versionType = "${version_type}"
changelog = rootProject.file("docs/CHANGELOG.md").text
uploadFile = jar
gameVersions = [ project.minecraft_version ]
gameVersions = [ project.minecraft_version, '1.21' ]

syncBodyFrom = rootProject.file("docs/README.md").text
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"required": true,
"minVersion": "0.8",
"package": "com.aizistral.nochatreports.neoforge.mixins",
"compatibilityLevel": "JAVA_18",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"client.MixinClientConnection",
"client.MixinClientHandshakePacketListenerImpl",
"client.MixinClientPacketListener",
"client.MixinServerStatusPinger$1"
"client.MixinClientPacketListener"
],
"server": [],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.aizistral.nochatreports.common.config.NCRConfig;
import com.aizistral.nochatreports.common.encryption.Encryptor;

import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
Expand All @@ -15,13 +16,13 @@

public class EncryptionUtil {

public static Optional<Component> tryDecrypt(Component component) {
public static Optional<Component> tryDecrypt(HolderLookup.Provider provider, Component component) {
var optional = NCRConfig.getEncryption().getEncryptor();
if (optional.isEmpty())
return Optional.empty();

Encryptor<?> encryption = optional.get();
Component copy = recreate(component);
Component copy = recreate(provider, component);
ComponentContents contents = copy.getContents();

return Optional.ofNullable(tryDecrypt(copy, encryption) ? copy : null);
Expand Down Expand Up @@ -81,8 +82,8 @@ public static Optional<String> tryDecrypt(String message, Encryptor<?> encryptor
}
}

public static Component recreate(Component component) {
return Component.Serializer.fromJson(Component.Serializer.toJson(component, RegistryAccess.EMPTY), RegistryAccess.EMPTY);
public static Component recreate(HolderLookup.Provider provider, Component component) {
return Component.Serializer.fromJson(Component.Serializer.toJson(component, provider), provider);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.aizistral.nochatreports.common.mixins.client;

import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;

Expand All @@ -22,6 +25,7 @@

@Mixin(ChatComponent.class)
public class MixinChatComponent {
@Shadow @Final private Minecraft minecraft;
private static final GuiMessageTag.Icon ENCRYPTED_ICON = GuiMessageTag.Icon.valueOf("CHAT_NCR_ENCRYPTED");
private boolean lastMessageEncrypted;
private Component lastMessageOriginal;
Expand All @@ -44,10 +48,11 @@ private GuiMessage modifyGUIMessage(GuiMessage msg) {
Component.Serializer.toJson(msg.content(), RegistryAccess.EMPTY));
}

var decrypted = EncryptionUtil.tryDecrypt(msg.content());
assert minecraft.level != null;
var decrypted = EncryptionUtil.tryDecrypt(minecraft.level.registryAccess(), msg.content());

decrypted.ifPresentOrElse(component -> {
this.lastMessageOriginal = EncryptionUtil.recreate(msg.content());
this.lastMessageOriginal = EncryptionUtil.recreate(minecraft.level.registryAccess(), msg.content());
this.lastMessageEncrypted = true;
}, () -> this.lastMessageEncrypted = false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Base64;
import java.util.UUID;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -40,6 +41,8 @@ private boolean isSenderLocalPlayer(UUID uuid) {
throw new IllegalStateException("@Shadow transformation failed. Should never happen.");
}

@Shadow @Final private Minecraft minecraft;

@Inject(method = "handleSystemMessage", at = @At("HEAD"), cancellable = true)
private void onHandleSystemMessage(Component message, boolean overlay, CallbackInfo info) {
if (message instanceof MutableComponent mutable && message.getContents() instanceof TranslatableContents translatable) {
Expand Down Expand Up @@ -115,7 +118,8 @@ private void onEvaluateTrustLevel(PlayerChatMessage playerChatMessage, Component
@ModifyVariable(method = "narrateChatMessage(Lnet/minecraft/network/chat/ChatType$Bound;"
+ "Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"), argsOnly = true)
private Component decryptNarratedMessage(Component msg) {
return EncryptionUtil.tryDecrypt(msg).orElse(msg);
assert minecraft.level != null;
return EncryptionUtil.tryDecrypt(minecraft.level.registryAccess(), msg).orElse(msg);
}

}
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
package com.aizistral.nochatreports.common.mixins.client;

import java.lang.reflect.Field;
import java.net.InetSocketAddress;

import net.minecraft.client.multiplayer.ServerStatusPinger;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.network.Connection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.aizistral.nochatreports.common.NCRCore;
import com.aizistral.nochatreports.common.config.NCRConfig;
import com.aizistral.nochatreports.common.core.ServerDataExtension;
import com.aizistral.nochatreports.common.platform.extensions.ServerPingerExtension;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
import net.minecraft.network.protocol.status.ServerStatus;


/**
* This one ensures "preventsChatReports" property is transferred from {@link ServerStatus} to
* {@link ServerData} when handling status response.
* @author fxmorin (original implementation)
* @author Aizistral (current version)
* @author pietro-lopes (fixed https://github.com/Aizistral-Studios/No-Chat-Reports/issues/481)
*/

@Mixin(targets = "net/minecraft/client/multiplayer/ServerStatusPinger$1")
public abstract class MixinServerStatusPinger$1 implements ServerPingerExtension {
public abstract class MixinServerStatusPinger$1 {

/**
* @reason Ensure "preventsChatReports" property is transferred from {@link ServerStatus} to
* {@link ServerData} when handling status response.
* @author fxmorin (original implementation)
* @author Aizistral (current version)
*/
@Unique
private ServerDataExtension nochatreports$serverData;

@Inject(method = "<init>", at = @At("RETURN"))
private void captureServerData(ServerStatusPinger serverStatusPinger, Connection connection, ServerData serverData, Runnable runnable, Runnable runnable2, InetSocketAddress inetSocketAddress, ServerAddress serverAddress, CallbackInfo ci){
this.nochatreports$serverData = (ServerDataExtension) serverData;
}

@Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;"
+ "description()Lnet/minecraft/network/chat/Component;",
ordinal = 0, shift = At.Shift.BEFORE))
+ "description()Lnet/minecraft/network/chat/Component;"))
private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) {
boolean preventsReports = ((ServerDataExtension) (Object) packet.status()).preventsChatReports();
((ServerDataExtension) this.getServerData()).setPreventsChatReports(preventsReports);

if (this.nochatreports$serverData == null) {
NCRCore.LOGGER.error("Failed to capture ServerData instance in MixinServerStatusPinger$1!");
NCRCore.LOGGER.catching(new IllegalStateException());
return;
}

this.nochatreports$serverData.setPreventsChatReports(preventsReports);

if (NCRConfig.getCommon().enableDebugLog()) {
NCRCore.LOGGER.info("Received status response packet from server, preventsChatReports: {}",
Expand Down
Loading

0 comments on commit 85c2993

Please sign in to comment.