Skip to content

Commit

Permalink
Update to 1.20.5, made "click to copy" hint to be translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
SyberiaK committed Jun 19, 2024
1 parent 450ef41 commit 7571b72
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
Expand All @@ -52,8 +52,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.10
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.11

# Mod Properties
mod_version=1.1.0
mod_version=1.2.0
maven_group=me.syberiak
archives_base_name=colorful-hex

# Dependencies
fabric_api_version=0.91.1+1.20.3
modmenu_version=9.0.0
fabric_api_version=0.97.8+1.20.5
modmenu_version=10.0.0
8 changes: 6 additions & 2 deletions src/main/java/me/syberiak/colorful_hex/ColorfulHEX.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void onInitializeClient() {
LOGGER.info("Initialized successfully.");
}

public static Text formatHexColors(Text text) {
public static MutableText formatHexColors(MutableText text) {
if (!text.getString().contains("#")) return text;

List<Text> textParts = text.withoutStyle();
Expand All @@ -32,6 +32,10 @@ public static Text formatHexColors(Text text) {
return formattedText;
}

public static Text formatHexColors(Text text) {
return formatHexColors(text.copy());
}

public static Text formatHexColorsPart(Text text) {
Style style = text.getStyle();
String part = text.getString();
Expand Down Expand Up @@ -79,7 +83,7 @@ public static Text toStyledHexColor(String code, Style style) {

TextColor color = TextColor.parse(code).result().orElseThrow();
ClickEvent copyByClick = new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text);
HoverEvent hintByHover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to copy!"));
HoverEvent hintByHover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("colorful_hex.click_to_copy"));

return Text.literal(text).setStyle(style.withColor(color)
.withUnderline(true).withClickEvent(copyByClick).withHoverEvent(hintByHover));
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/me/syberiak/colorful_hex/TooltipManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.item.TooltipType;
import net.minecraft.item.Item;
import net.minecraft.text.Text;
import net.minecraft.item.ItemStack;
import net.minecraft.client.item.TooltipContext;

public class TooltipManager {
public static void onItemTooltip(ItemStack _stack, TooltipContext _context, List<Text> lines) {
public static void onItemTooltip(ItemStack ignored, Item.TooltipContext ignored1, TooltipType ignored2, List<Text> texts) {
List<Text> formattedTooltip = new ArrayList<>();
for (Text line : lines) {
for (Text line : texts) {
formattedTooltip.add(ColorfulHEX.formatHexColors(line));
}

lines.clear();
lines.addAll(formattedTooltip);
texts.clear();
texts.addAll(formattedTooltip);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package me.syberiak.colorful_hex.mixin;

import net.minecraft.text.Text;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.MutableText;
import net.minecraft.client.gui.screen.ingame.BookScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Inject;

import me.syberiak.colorful_hex.ColorfulHEX;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BookScreen.WrittenBookContents.class)
@Mixin(BookScreen.Contents.class)
public class WrittenBookScreenMixin {
@SuppressWarnings("InvalidInjectorMethodSignature")
@ModifyVariable(method = "getPageUnchecked(I)Lnet/minecraft/text/StringVisitable;", at = @At("STORE"), ordinal = 0)
private StringVisitable injected(StringVisitable stringVisitable) {
if (!(stringVisitable instanceof Text text)) return stringVisitable;

return ColorfulHEX.formatHexColors(text);
@Inject(method = "getPage(I)Lnet/minecraft/text/StringVisitable;", at = @At("RETURN"), cancellable = true)
private void modifyPageContent(CallbackInfoReturnable<MutableText> cir) {
cir.setReturnValue(ColorfulHEX.formatHexColors(cir.getReturnValue()));
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/colorful_hex/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"modmenu.summaryTranslation.colorful_hex": "Makes HEX color tags in chat useful.",
"modmenu.descriptionTranslation.colorful_hex": "Makes HEX color tags in chat useful.\nYou can see what color is represented by HEX code and copy it to clipboard in one click.\n[WORKS ON CLIENT-SIDE ONLY]"
"modmenu.descriptionTranslation.colorful_hex": "Makes HEX color tags in chat useful.\nYou can see what color is represented by HEX code and copy it to clipboard in one click.\n[WORKS ON CLIENT-SIDE ONLY]",
"colorful_hex.click_to_copy": "Click to copy this color code!"
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/colorful_hex/lang/ru_ru.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"modmenu.summaryTranslation.colorful_hex": "Делает полезными цветовые коды формата HEX в чате.",
"modmenu.descriptionTranslation.colorful_hex": "Делает полезными цветовые коды формата HEX в чате.\nВы можете увидеть, какой цвет обозначается данным кодом HEX, и скопировать его в буфер обмена в один клик.\n[РАБОТАЕТ ТОЛЬКО НА СТОРОНЕ КЛИЕНТА]"
"modmenu.descriptionTranslation.colorful_hex": "Делает полезными цветовые коды формата HEX в чате.\nВы можете увидеть, какой цвет обозначается данным кодом HEX, и скопировать его в буфер обмена в один клик.\n[РАБОТАЕТ ТОЛЬКО НА СТОРОНЕ КЛИЕНТА]",
"colorful_hex.click_to_copy": "Нажмите, чтобы скопировать цветовой код!"

}
5 changes: 2 additions & 3 deletions src/main/resources/colorful_hex.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"required": true,
"minVersion": "0.8",
"package": "me.syberiak.colorful_hex.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
],
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"WrittenBookScreenMixin",
"ChatHudMixin"
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

"depends": {
"fabricloader": ">=0.14.11",
"minecraft": ">=1.20.3 <1.20.5",
"java": ">=17",
"minecraft": ">=1.20.5 <1.21",
"java": ">=21",
"fabric-api": ">=0.72.0"
},

Expand Down

0 comments on commit 7571b72

Please sign in to comment.