mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Start working on actually integrating PackConverter in Rainbow
This commit is contained in:
@@ -2,39 +2,16 @@ package org.geysermc.rainbow;
|
|||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
|
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import org.geysermc.pack.bedrock.resource.BedrockResourcePack;
|
|
||||||
import org.geysermc.pack.converter.PackConversionContext;
|
|
||||||
import org.geysermc.pack.converter.PackConverter;
|
|
||||||
import org.geysermc.pack.converter.converter.ActionListener;
|
|
||||||
import org.geysermc.pack.converter.converter.Converter;
|
|
||||||
import org.geysermc.pack.converter.converter.base.PackManifestConverter;
|
|
||||||
import org.geysermc.pack.converter.converter.lang.LangConverter;
|
|
||||||
import org.geysermc.pack.converter.converter.misc.SplashTextConverter;
|
|
||||||
import org.geysermc.pack.converter.converter.model.ModelConverter;
|
|
||||||
import org.geysermc.pack.converter.data.ConversionData;
|
|
||||||
import org.geysermc.pack.converter.util.DefaultLogListener;
|
|
||||||
import org.geysermc.pack.converter.util.LogListener;
|
|
||||||
import org.geysermc.rainbow.command.CommandSuggestionsArgumentType;
|
import org.geysermc.rainbow.command.CommandSuggestionsArgumentType;
|
||||||
import org.geysermc.rainbow.command.PackGeneratorCommand;
|
import org.geysermc.rainbow.command.PackGeneratorCommand;
|
||||||
import org.geysermc.rainbow.creative.MinecraftCreativeResourcePack;
|
|
||||||
import org.geysermc.rainbow.mapper.PackMapper;
|
import org.geysermc.rainbow.mapper.PackMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Rainbow implements ClientModInitializer {
|
public class Rainbow implements ClientModInitializer {
|
||||||
|
|
||||||
public static final String MOD_ID = "rainbow";
|
public static final String MOD_ID = "rainbow";
|
||||||
@@ -52,58 +29,6 @@ public class Rainbow implements ClientModInitializer {
|
|||||||
|
|
||||||
ArgumentTypeRegistry.registerArgumentType(getModdedLocation("command_suggestions"),
|
ArgumentTypeRegistry.registerArgumentType(getModdedLocation("command_suggestions"),
|
||||||
CommandSuggestionsArgumentType.class, SingletonArgumentInfo.contextFree(CommandSuggestionsArgumentType::new));
|
CommandSuggestionsArgumentType.class, SingletonArgumentInfo.contextFree(CommandSuggestionsArgumentType::new));
|
||||||
|
|
||||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, buildContext) -> {
|
|
||||||
dispatcher.register(ClientCommandManager.literal("debugtest")
|
|
||||||
.executes(context -> {
|
|
||||||
|
|
||||||
PackConverter packConverter = new PackConverter()
|
|
||||||
.packName("RAINBOW-TEST")
|
|
||||||
.output(FabricLoader.getInstance().getGameDir().resolve("pack-convert-out"));
|
|
||||||
Path tmpDir = FabricLoader.getInstance().getGameDir().resolve("pack-convert-temp");
|
|
||||||
|
|
||||||
ImageIO.scanForPlugins();
|
|
||||||
MinecraftCreativeResourcePack resourcePack = new MinecraftCreativeResourcePack(Minecraft.getInstance().getResourceManager());
|
|
||||||
BedrockResourcePack bedrockResourcePack = new BedrockResourcePack(tmpDir);
|
|
||||||
|
|
||||||
LogListener logListener = new DefaultLogListener();
|
|
||||||
final Converter.ConversionDataCreationContext conversionDataCreationContext = new Converter.ConversionDataCreationContext(
|
|
||||||
packConverter, logListener, null, tmpDir, resourcePack, resourcePack
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
List<Converter<?>> converters = new ArrayList<>();
|
|
||||||
converters.add(new PackManifestConverter());
|
|
||||||
converters.add(new LangConverter());
|
|
||||||
converters.add(new ModelConverter());
|
|
||||||
|
|
||||||
int errors = 0;
|
|
||||||
for (Converter converter : converters) {
|
|
||||||
ConversionData data = converter.createConversionData(conversionDataCreationContext);
|
|
||||||
PackConversionContext<?> conversionContext = new PackConversionContext<>(data, packConverter, resourcePack, bedrockResourcePack, logListener);
|
|
||||||
|
|
||||||
List<ActionListener<?>> actionListeners = List.of();
|
|
||||||
try {
|
|
||||||
actionListeners.forEach(actionListener -> actionListener.preConvert((PackConversionContext) conversionContext));
|
|
||||||
converter.convert(conversionContext);
|
|
||||||
actionListeners.forEach(actionListener -> actionListener.postConvert((PackConversionContext) conversionContext));
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logListener.error("Error converting pack!", t);
|
|
||||||
errors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
bedrockResourcePack.export();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
context.getSource().sendFeedback(Component.literal("exporting, " + errors + " errors"));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceLocation getModdedLocation(String path) {
|
public static ResourceLocation getModdedLocation(String path) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.geysermc.rainbow.mapping.BedrockItemMapper;
|
|||||||
import org.geysermc.rainbow.mapping.PackContext;
|
import org.geysermc.rainbow.mapping.PackContext;
|
||||||
import org.geysermc.rainbow.mapping.geyser.GeyserMappings;
|
import org.geysermc.rainbow.mapping.geyser.GeyserMappings;
|
||||||
import org.geysermc.rainbow.mixin.SplashRendererAccessor;
|
import org.geysermc.rainbow.mixin.SplashRendererAccessor;
|
||||||
|
import org.geysermc.rainbow.packconverter.PackConverterContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -72,6 +73,8 @@ public class BedrockPack {
|
|||||||
private final Set<ResourceLocation> modelsMapped = new HashSet<>();
|
private final Set<ResourceLocation> modelsMapped = new HashSet<>();
|
||||||
private final IntSet customModelDataMapped = new IntOpenHashSet();
|
private final IntSet customModelDataMapped = new IntOpenHashSet();
|
||||||
|
|
||||||
|
private final PackConverterContext packConverterContext = PackConverterContext.create(this);
|
||||||
|
|
||||||
private final ProblemReporter.Collector reporter;
|
private final ProblemReporter.Collector reporter;
|
||||||
|
|
||||||
public BedrockPack(String name) throws IOException {
|
public BedrockPack(String name) throws IOException {
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.geysermc.rainbow.packconverter;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.geysermc.pack.converter.pipeline.ConversionContext;
|
||||||
|
import org.geysermc.pack.converter.util.LogListener;
|
||||||
|
import org.geysermc.rainbow.Rainbow;
|
||||||
|
import org.geysermc.rainbow.creative.MinecraftCreativeResourcePack;
|
||||||
|
import org.geysermc.rainbow.pack.BedrockPack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record PackConverterContext(String packName, LogListener logListener, MinecraftCreativeResourcePack pack) {
|
||||||
|
|
||||||
|
public ConversionContext createConversionContext() {
|
||||||
|
return new ConversionContext(packName, logListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PackConverterContext create(BedrockPack pack) {
|
||||||
|
return new PackConverterContext(pack.name(), RainbowLogListener.INSTANCE, new MinecraftCreativeResourcePack(Minecraft.getInstance().getResourceManager()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RainbowLogListener implements LogListener {
|
||||||
|
private static final LogListener INSTANCE = new RainbowLogListener();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(@NotNull String message) {
|
||||||
|
Rainbow.LOGGER.debug(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(@NotNull String message) {
|
||||||
|
Rainbow.LOGGER.info(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void warn(@NotNull String message) {
|
||||||
|
Rainbow.LOGGER.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(@NotNull String message) {
|
||||||
|
Rainbow.LOGGER.error(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(@NotNull String message, @Nullable Throwable exception) {
|
||||||
|
Rainbow.LOGGER.error(message, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user