Skip to content

Commit

Permalink
🎨 neoforge update
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Oct 9, 2024
1 parent 243d1fb commit 1ba90a8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .idea/ModAliasState.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion neoforge/origin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ mod_authors=kitUIN
mod_description=Show Image In Chat Line
mod_version=1.2.4
code_version=0.10.0
action_version=1.9.2-neoforge

# IF neoforge-1.20.2
#action_version=1.6.1-neoforge
# ELSE IF neoforge-1.20.3 || neoforge-1.20.4
#action_version=1.9.2-neoforge
# ELSE
#action_version=1.10.1-neoforge
# END IF
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.chat.contents.TranslatableContents;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -43,14 +42,14 @@ public Component addMessage(Component p_241484_) {
return chatimage$replaceMessage(p_241484_);
}


@Unique
private Component chatimage$replaceCode(Component text) {
String checkedText = "";
String key = "";
MutableComponent player = null;
boolean isSelf = false;
if (text.getContents() instanceof LiteralContents lc) {
if (text.getContents() instanceof #LiteralContents# lc) {
checkedText = lc.text();
} else if (text.getContents() instanceof TranslatableContents ttc) {
key = ttc.getKey();
Expand All @@ -59,7 +58,7 @@ public Component addMessage(Component p_241484_) {
player = (MutableComponent) args[0];
isSelf = player.getContents().toString().equals(this.minecraft.player.getName().getContents().toString());
MutableComponent contents = (MutableComponent) args[1];
if (contents.getContents() instanceof LiteralContents lc) {
if (contents.getContents() instanceof #LiteralContents# lc) {
checkedText = lc.text();
} else {
checkedText = contents.getContents().toString();
Expand Down Expand Up @@ -115,5 +114,4 @@ public Component addMessage(Component p_241484_) {
return message;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.kituin.chatimage.tool;


import io.github.kituin.ChatImageCode.ChatImageCode;
import io.github.kituin.ChatImageCode.ChatImageCodeInstance;
import io.github.kituin.ChatImageCode.exception.InvalidChatImageCodeException;
Expand All @@ -9,16 +10,43 @@
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;


// IF neoforge-1.20.2
// ELSE IF >= neoforge-1.20.3
// import com.mojang.serialization.Codec;
// import com.mojang.serialization.DataResult;
// import com.mojang.serialization.MapCodec;
// import com.mojang.serialization.codecs.RecordCodecBuilder;
// END IF
/**
* @author kitUIN
*/
public class ChatImageStyle {
public static final HoverEvent.Action<ChatImageCode> SHOW_IMAGE =
new HoverEvent.Action<>("show_chatimage", true,
ChatImageCode::fromJson,
ChatImageCode::toJson,
ChatImageStyle::fromJson);
// IF neoforge-1.20.2
// public static final HoverEvent.Action<ChatImageCode> SHOW_IMAGE =
// new HoverEvent.Action<>("show_chatimage", true,
// ChatImageCode::fromJson,
// ChatImageCode::toJson,
// ChatImageStyle::fromJson);
// ELSE IF >= neoforge-1.20.3
// public static final MapCodec<ChatImageCode> MAP_CODEC = RecordCodecBuilder.mapCodec(obj -> obj.group(
// Codec.STRING.fieldOf("url").forGetter(ChatImageCode::getUrl),
// Codec.BOOL.optionalFieldOf("nsfw",false).forGetter(ChatImageCode::isNsfw)
//).apply(obj, (url, nsfw) -> new ChatImageCode.Builder().setNsfw(nsfw).setUrlForce(url).build()));
// public static final Codec<ChatImageCode> CODEC = MAP_CODEC.codec();
// public static final HoverEvent.Action<ChatImageCode> SHOW_IMAGE = new HoverEvent.Action<>(
// "show_chatimage",
// true,
// CODEC,
// ChatImageStyle::legacySerializer);
//
// private static DataResult<ChatImageCode> legacySerializer(Component text) {
// try {
// return DataResult.success( new ChatImageCode.Builder().fromCode(text.toString()).build());
// } catch (InvalidChatImageCodeException e) {
// return DataResult.error(() -> "Failed to parse ChatImageCode: " + e.getMessage());
// }
// }
// END IF
/**
* 文本 悬浮图片样式
*
Expand Down Expand Up @@ -64,4 +92,4 @@ public static ChatImageCode fromJson(Component text) {
return ChatImageCodeInstance.createBuilder().build();
}
}
}
}

0 comments on commit 1ba90a8

Please sign in to comment.