Skip to content

Commit

Permalink
Allow all messages to be translated
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Gegy committed Jan 29, 2023
1 parent b932eaa commit c0ae6d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
20 changes: 9 additions & 11 deletions src/main/java/xyz/nucleoid/slime_mould/game/SlimeMouldActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public final class SlimeMouldActive {
private static final Item GROWTH_ITEM = Items.WOODEN_HOE;

private static final ItemStackBuilder GROWTH_STACK = ItemStackBuilder.of(GROWTH_ITEM)
.setName(Text.literal("Grow your mould!").formatted(Formatting.GREEN, Formatting.BOLD))
.addLore(Text.literal("Right click on blocks adjacent to your own to grow"));
.setName(Text.translatable("text.slime_mould.growth_stack.name").formatted(Formatting.GREEN, Formatting.BOLD))
.addLore(Text.translatable("text.slime_mould.growth_stack.description"));

private static final EntityAttributeModifier STRETCHED_THIN_MODIFIER = new EntityAttributeModifier(
"slime_mould_stretched_thin",
Expand Down Expand Up @@ -90,7 +90,7 @@ private SlimeMouldActive(GameActivity activity, ServerWorld world, SlimeMouldMap

this.food = new SlimeMouldFood(activity, world);

this.sidebar = widgets.addSidebar(Text.literal("Slime Mould!").formatted(Formatting.RED, Formatting.BOLD));
this.sidebar = widgets.addSidebar(Text.translatable("text.slime_mould.sidebar.title").formatted(Formatting.RED, Formatting.BOLD));
}

public static void open(GameSpace gameSpace, ServerWorld world, SlimeMouldMap map, SlimeMouldConfig config) {
Expand Down Expand Up @@ -352,18 +352,17 @@ private void updateFoodBar(ServerPlayerEntity player, Mould mould) {

private void updateSidebar() {
this.sidebar.set(content -> {
content.add(Text.literal("Expand your slime mould!").formatted(Formatting.GREEN));
content.add(Text.translatable("text.slime_mould.sidebar.description").formatted(Formatting.GREEN));
content.add(ScreenTexts.EMPTY);

this.playerToMould.values().stream()
.sorted(Comparator.comparingInt(mould -> -mould.score))
.limit(8)
.forEach(mould -> {
content.add(
mould.team.config().name().copy()
.append(": ")
.append(Text.literal(mould.score + "").formatted(Formatting.GOLD))
);
Text name = mould.team.config().name();
Text score = Text.literal(mould.score + "").formatted(Formatting.GOLD);

content.add(Text.translatable("text.slime_mould.sidebar.line", name, score));
});
});
}
Expand All @@ -381,8 +380,7 @@ private boolean takeFoodFrom(Mould mould) {
private void eliminate(Mould mould) {
if (this.playerToMould.remove(mould.player, mould)) {
this.gameSpace.getPlayers().sendMessage(
Text.literal(mould.player.getName())
.append(" has been eliminated!")
Text.translatable("text.slime_mould.eliminated", mould.player.getName())
.formatted(Formatting.RED)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SlimeMouldMap build(MinecraftServer server) {
try {
template = MapTemplateSerializer.loadFromResource(server, this.config.template);
} catch (IOException e) {
throw new GameOpenException(Text.literal("Failed to load map template"), e);
throw new GameOpenException(Text.translatable("text.slime_mould.template_load_failed"), e);
}

MapTemplateMetadata metadata = template.getMetadata();
Expand All @@ -38,7 +38,7 @@ public SlimeMouldMap build(MinecraftServer server) {
private SlimeMouldPlate buildPlate(MapTemplate template, MapTemplateMetadata metadata) {
TemplateRegion plate = metadata.getFirstRegion("plate");
if (plate == null) {
throw new GameOpenException(Text.literal("Missing plate region!"));
throw new GameOpenException(Text.translatable("text.slime_mould.no_plate_region"));
}

int radius = this.computePlateRadius(template, plate.getBounds());
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/data/slime_mould/games/standard.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"type": "slime_mould:slime_mould",
"name": "Slime Mould",
"map": {
"template": "slime_mould:slime_mould"
},
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/data/slime_mould/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"gameType.slime_mould.slime_mould": "Slime Mould",
"gameType.slime_mould.standard": "Slime Mould",
"text.slime_mould.eliminated": "%s has been eliminated!",
"text.slime_mould.growth_stack.description": "Right click on blocks adjacent to your own to grow",
"text.slime_mould.growth_stack.name": "Grow your mould!",
"text.slime_mould.no_plate_region": "Missing plate region!",
"text.slime_mould.sidebar.description": "Expand your slime mould!",
"text.slime_mould.sidebar.line": "%s: %s",
"text.slime_mould.sidebar.title": "Slime Mould!",
"text.slime_mould.template_load_failed": "Failed to load map template"
}

0 comments on commit c0ae6d9

Please sign in to comment.