1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Add translation strings for text components, and more small things

This commit is contained in:
Eclipse
2025-07-18 08:37:26 +00:00
parent 5188ec097b
commit a9ca727aab
8 changed files with 55 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ package org.geysermc.rainbow;
import org.geysermc.rainbow.pack.BedrockPack;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -27,6 +28,10 @@ public final class PackManager {
currentPack.ifPresentOrElse(consumer, runnable);
}
public Optional<Path> getExportPath() {
return currentPack.map(BedrockPack::getExportPath);
}
public Optional<Boolean> finish() {
Optional<Boolean> success = currentPack.map(BedrockPack::save);
currentPack = Optional.empty();

View File

@@ -5,6 +5,8 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
@@ -13,10 +15,16 @@ import org.geysermc.rainbow.mapper.InventoryMapper;
import org.geysermc.rainbow.mapper.PackMapper;
import org.geysermc.rainbow.pack.BedrockPack;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.BiConsumer;
public class PackGeneratorCommand {
private static final Component NO_PACK_CREATED = Component.translatable("commands.rainbow.no_pack", Component.literal("/rainbow create <name>")
.withStyle(style -> style.withColor(ChatFormatting.BLUE).withUnderlined(true)
.withClickEvent(new ClickEvent.SuggestCommand("/rainbow create "))));
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, PackManager packManager, PackMapper packMapper) {
dispatcher.register(ClientCommandManager.literal("rainbow")
.then(ClientCommandManager.literal("create")
@@ -26,10 +34,10 @@ public class PackGeneratorCommand {
try {
packManager.startPack(name);
} catch (Exception exception) {
context.getSource().sendError(Component.literal("Failed to create new pack!"));
context.getSource().sendError(Component.translatable("commands.rainbow.create_pack_failed"));
throw new RuntimeException(exception);
}
context.getSource().sendFeedback(Component.literal("Created pack with name " + name));
context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_created", name));
return 0;
})
)
@@ -38,9 +46,9 @@ public class PackGeneratorCommand {
.executes(runWithPack(packManager, (source, pack) -> {
ItemStack heldItem = source.getPlayer().getMainHandItem();
switch (pack.map(heldItem)) {
case NONE_MAPPED -> source.sendError(Component.literal("No item was mapped. Either no custom item was found, or it was already included in the pack"));
case PROBLEMS_OCCURRED -> source.sendFeedback(Component.literal("The held item was mapped, however problems occurred whilst doing so. Read the pack report after finishing the pack for more information"));
case MAPPED_SUCCESSFULLY -> source.sendFeedback(Component.literal("The held item was mapped"));
case NONE_MAPPED -> source.sendError(Component.translatable("commands.rainbow.no_item_mapped"));
case PROBLEMS_OCCURRED -> source.sendFeedback(Component.translatable("commands.rainbow.mapped_held_item_problems"));
case MAPPED_SUCCESSFULLY -> source.sendFeedback(Component.translatable("commands.rainbow.mapped_held_item"));
}
}))
)
@@ -61,12 +69,12 @@ public class PackGeneratorCommand {
}
if (mapped > 0) {
source.sendFeedback(Component.literal("Mapped " + mapped + " items from your inventory"));
source.sendFeedback(Component.translatable("commands.rainbow.mapped_items_from_inventory", mapped));
if (errors) {
source.sendFeedback(Component.literal("Problems occurred whilst mapping items. Read the pack report after finishing the pack for more information"));
source.sendFeedback(Component.translatable("commands.rainbow.mapped_items_problems"));
}
} else {
source.sendError(Component.literal("No items were mapped. Either no custom items were found, or they were already included in the pack"));
source.sendError(Component.translatable("commands.rainbow.no_items_mapped"));
}
}))
)
@@ -92,25 +100,27 @@ public class PackGeneratorCommand {
.then(ClientCommandManager.literal("inventory")
.executes(runWithPack(packManager, (source, pack) -> {
packMapper.setItemProvider(InventoryMapper.INSTANCE);
source.sendFeedback(Component.literal("Now watching inventories for custom items to map"));
source.sendFeedback(Component.translatable("commands.rainbow.automatic_inventory_mapping"));
}))
)
.then(ClientCommandManager.literal("stop")
.executes(runWithPack(packManager, (source, pack) -> {
packMapper.setItemProvider(null);
source.sendFeedback(Component.literal("Stopped automatic mapping of custom items"));
source.sendFeedback(Component.translatable("commands.rainbow.stopped_automatic_mapping"));
}))
)
)
.then(ClientCommandManager.literal("finish")
.executes(context -> {
Optional<Path> exportPath = packManager.getExportPath();
packManager.finish().ifPresentOrElse(success -> {
if (!success) {
context.getSource().sendError(Component.literal("Errors occurred whilst writing the pack to disk!"));
context.getSource().sendError(Component.translatable("commands.rainbow.pack_finished_error"));
} else {
context.getSource().sendFeedback(Component.literal("Wrote pack to disk"));
context.getSource().sendFeedback(Component.translatable("commands.rainbow.pack_finished_successfully")
.withStyle(style -> style.withUnderlined(true).withClickEvent(new ClickEvent.OpenFile(exportPath.orElseThrow()))));
}
}, () -> context.getSource().sendError(Component.literal("Create a pack first!")));
}, () -> context.getSource().sendError(NO_PACK_CREATED));
return 0;
})
)
@@ -120,7 +130,7 @@ public class PackGeneratorCommand {
private static Command<FabricClientCommandSource> runWithPack(PackManager manager, BiConsumer<FabricClientCommandSource, BedrockPack> executor) {
return context -> {
manager.runOrElse(pack -> executor.accept(context.getSource(), pack),
() -> context.getSource().sendError(Component.literal("Create a pack first!")));
() -> context.getSource().sendError(NO_PACK_CREATED));
return 0;
};
}

View File

@@ -34,10 +34,10 @@ public class PackMapper {
.filter(result -> result != BedrockPack.MappingResult.NONE_MAPPED)
.count();
if (mapped != 0) {
player.displayClientMessage(Component.literal("Mapped " + mapped + " items"), false);
player.displayClientMessage(Component.translatable("chat.rainbow.mapped_items", mapped), false);
}
if (itemProvider.isDone()) {
player.displayClientMessage(Component.literal("Finished mapping items from provider"), false);
player.displayClientMessage(Component.translatable("chat.rainbow.automatic_mapping_finished"), false);
itemProvider = null;
}
}, () -> itemProvider = null);

View File

@@ -39,7 +39,7 @@ public class GeometryRenderer {
try (OversizedItemRenderer itemRenderer = new OversizedItemRenderer(Minecraft.getInstance().renderBuffers().bufferSource())) {
//noinspection DataFlowIssue
((PictureInPictureCopyRenderer) itemRenderer).geyser_mappings_generator$allowTextureCopy();
((PictureInPictureCopyRenderer) itemRenderer).rainbow$allowTextureCopy();
itemRenderer.prepare(oversizedRenderState, new GuiRenderState(), 4);
writeAsPNG(path, ((PictureInPictureRendererAccessor) itemRenderer).getTexture());
}

View File

@@ -20,7 +20,7 @@ public abstract class PictureInPictureRendererMixin implements AutoCloseable, Pi
private boolean allowTextureCopy = false;
@Override
public void geyser_mappings_generator$allowTextureCopy() {
public void rainbow$allowTextureCopy() {
if (texture != null) {
throw new IllegalStateException("texture already created");
}

View File

@@ -154,6 +154,10 @@ public class BedrockPack {
return success;
}
public Path getExportPath() {
return exportPath;
}
private String createPackSummary() {
return """
-- PACK GENERATION REPORT --

View File

@@ -2,5 +2,5 @@ package org.geysermc.rainbow.render;
public interface PictureInPictureCopyRenderer {
void geyser_mappings_generator$allowTextureCopy();
void rainbow$allowTextureCopy();
}

View File

@@ -0,0 +1,17 @@
{
"chat.rainbow.automatic_mapping_finished": "Finished mapping items from provider",
"chat.rainbow.mapped_items": "Mapped %d items",
"commands.rainbow.automatic_inventory_mapping": "Now watching inventories for custom items to map",
"commands.rainbow.create_pack_failed": "Failed to create new pack!",
"commands.rainbow.mapped_held_item": "The held item was mapped",
"commands.rainbow.mapped_held_item_problems": "The held item was mapped, however problems occurred whilst doing so. Read the pack report after finishing the pack for more information",
"commands.rainbow.mapped_items_from_inventory": "Mapped %d items from your inventory",
"commands.rainbow.mapped_items_problems": "Problems occurred whilst mapping items. Read the pack report after finishing the pack for more information",
"commands.rainbow.no_item_mapped": "No item was mapped. Either no custom item was found, or it was already included in the pack",
"commands.rainbow.no_items_mapped": "No items were mapped. Either no custom items were found, or they were already included in the pack",
"commands.rainbow.no_pack": "Create a pack first: %s",
"commands.rainbow.pack_created": "Created pack with name %s",
"commands.rainbow.pack_finished_error": "Errors occurred whilst writing the pack to disk!",
"commands.rainbow.pack_finished_successfully": "Wrote pack to disk",
"commands.rainbow.stopped_automatic_mapping": "Stopped automatic mapping of custom items"
}