Skip to content

Commit

Permalink
Update to 1.20.3 (#55)
Browse files Browse the repository at this point in the history
* Update to 23w41a

* Fix not all components being translated

* Improve codec mixin
  • Loading branch information
DrexHD authored Dec 1, 2023
1 parent 6d4783f commit 90420ae
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ static Text asLocalizedFor(final Text text, final ServerLanguage language, final
style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackContent(stack)));
} else if (translateDeeply && style.getHoverEvent().getAction() == HoverEvent.Action.SHOW_ENTITY) {
var value = style.getHoverEvent().getValue(HoverEvent.Action.SHOW_ENTITY);
if (value.name != null) {
style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ENTITY, new HoverEvent.EntityContent(value.entityType, value.uuid, asLocalizedFor(value.name, language, true))));
if (value.name.isPresent()) {
style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ENTITY, new HoverEvent.EntityContent(value.entityType, value.uuid, asLocalizedFor(value.name.get(), language, true))));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static void updateSide(NbtCompound nbt, LocalizationTarget target) {

private static void updateLines(NbtList messages, LocalizationTarget target) {
for (int i = 0; i < messages.size(); i++) {
messages.set(i, NbtString.of(Text.Serializer.toJson(Localization.text(Text.Serializer.fromLenientJson(messages.getString(i)), target))));
messages.set(i, NbtString.of(Text.Serialization.toJsonString(Localization.text(Text.Serialization.fromLenientJson(messages.getString(i)), target))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static void translateLore(NbtCompound display, ServerLanguage target) {
private static String localizeTextJson(String json, ServerLanguage target) {
Text text;
try {
text = Text.Serializer.fromLenientJson(json);
text = Text.Serialization.fromLenientJson(json);
} catch (Exception e) {
text = null;
}
Expand All @@ -102,7 +102,7 @@ private static String localizeTextJson(String json, ServerLanguage target) {

Text localized = LocalizableText.asLocalizedFor(text, target, true);
if (!localized.equals(text)) {
return Text.Serializer.toJson(localized);
return Text.Serialization.toJsonString(localized);
} else {
return json;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package xyz.nucleoid.server.translations.mixin.packet;

import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.text.TranslatableTextContent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.nucleoid.server.translations.api.LocalizationTarget;

import java.util.function.Function;

@Mixin(TranslatableTextContent.class)
public abstract class TranslatableTextContentMixin {

@Redirect(
method = "<clinit>",
at = @At(value = "INVOKE",
target = "Lcom/mojang/serialization/codecs/RecordCodecBuilder;mapCodec(Ljava/util/function/Function;)Lcom/mojang/serialization/MapCodec;"
)
)
private static MapCodec<TranslatableTextContent> stapi$addTranslationFallback(Function<RecordCodecBuilder.Instance<TranslatableTextContent>, ? extends App<RecordCodecBuilder.Mu<TranslatableTextContent>, TranslatableTextContent>> builder) {
return RecordCodecBuilder.mapCodec(builder).xmap(Function.identity(), (content) -> {
if (content.getFallback() == null) {
var target = LocalizationTarget.forPacket();
if (target != null) {
return new TranslatableTextContent(content.getKey(), target.getLanguage().serverTranslations().get(content.getKey()), content.getArgs());
}
}
return content;
});
}

}
2 changes: 1 addition & 1 deletion api/src/main/resources/server_translations_api.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"packet.BlockEntityDataMixin",
"packet.BlockEntityUpdateS2CPacketMixin",
"packet.PacketByteBufMixin",
"packet.TextSerializerMixin",
"packet.TranslatableTextContentMixin",
"text.MutableTextMixin"
],
"client": [
Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ plugins {
}

class Globals {
static def baseVersion = "2.1.0"
static def mcVersion = "1.20.2-rc2"
static def yarnVersion = "+build.1"
static def baseVersion = "2.1.1"
static def mcVersion = "1.20.3-pre4"
static def yarnVersion = "+build.2"
}

archivesBaseName = "Server-Translations"
Expand Down Expand Up @@ -49,11 +49,11 @@ allprojects {
dependencies {
minecraft "com.mojang:minecraft:$Globals.mcVersion"
mappings "net.fabricmc:yarn:${Globals.mcVersion}${Globals.yarnVersion}:v2"
modImplementation "net.fabricmc:fabric-loader:0.14.22"
modImplementation "net.fabricmc:fabric-loader:0.14.23"

modImplementation include("xyz.nucleoid:packet-tweaker:0.5.0+1.20.2-rc1")

modImplementation "net.fabricmc.fabric-api:fabric-api:0.88.5+1.20.2"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.90.1+1.20.3"
}

processResources {
Expand Down

0 comments on commit 90420ae

Please sign in to comment.