-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to 23w41a * Fix not all components being translated * Improve codec mixin
- Loading branch information
Showing
7 changed files
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
api/src/main/java/xyz/nucleoid/server/translations/mixin/packet/TextSerializerMixin.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
...main/java/xyz/nucleoid/server/translations/mixin/packet/TranslatableTextContentMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters