Skip to content

Commit

Permalink
Do partial datagen for language files
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSunrize committed Jun 19, 2024
1 parent 109a216 commit 0ae40d6
Show file tree
Hide file tree
Showing 7 changed files with 1,652 additions and 129 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
##### Version 1.20.4-11.4.2-pre
- Do partial datagen for language files (BluSunrize)
- This way we don't forget about localizing the countless banner variations anymore

##### Version 1.20.4-11.4.1-176
- Add a netherite nugget (BluSunrize)
- This is to allow recycling outputs of nuggets
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version_neoforge=20.4.234
# "random" times. Updating this should usually be done in sync with updating the NeoForge version as there sometimes are
# cross-dependencies in e.g. argument generation.
version_neogradle=7.0.96
version_ie=11.4.1
version_ie=11.4.2
version_jei=17.0.0.30
version_cctweaked=1.110.2
version_buildnumber=176
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static void gatherData(GatherDataEvent event)
gen.addProvider(true, new StructureUpdater("structures/village", Lib.MODID, exHelper, output));
gen.addProvider(true, new DynamicModels(multiblocks, output, exHelper));
gen.addProvider(true, new LootModifierProvider(output));
gen.addProvider(true, new Language(output, exHelper, "en_us"));
for(final DataProvider provider : WorldGenerationProvider.makeProviders(output, lookup, exHelper))
gen.addProvider(true, provider);
ManualDataGenerator.addProviders(gen, exHelper);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* BluSunrize
* Copyright (c) 2020
*
* This code is licensed under "Blu's License of Common Sense"
* Details can be found in the license file in the root folder of this project
*/

package blusunrize.immersiveengineering.data;

import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.multiblocks.TemplateMultiblock;
import blusunrize.immersiveengineering.common.register.*;
import blusunrize.immersiveengineering.common.register.IEBannerPatterns.BannerEntry;
import blusunrize.immersiveengineering.common.util.Utils;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonReader;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.entity.BannerPattern;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.common.data.LanguageProvider;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;

public class Language extends LanguageProvider
{
final ExistingFileHelper existingFileHelper;
private final ResourceLocation baseLangFile;

public Language(PackOutput output, ExistingFileHelper existingFileHelper, String locale)
{
super(output, Lib.MODID, locale);
this.existingFileHelper = existingFileHelper;
this.baseLangFile = new ResourceLocation(Lib.MODID, locale);
}

@Override
protected void addTranslations()
{
// Load our existing resource file
try
{
final Gson gson = new Gson();
final Resource resource = existingFileHelper.getResource(baseLangFile, PackType.CLIENT_RESOURCES, ".json", "lang_base");
final BufferedReader reader = resource.openAsReader();
JsonObject object = GsonHelper.fromJson(gson, reader, JsonObject.class);
for(String key : object.keySet())
add(key, object.get(key).getAsString());
} catch(IOException e)
{
throw new RuntimeException("Failure to read base language file", e);
}

// Add banners with their coloration
for(BannerEntry banner : IEBannerPatterns.ALL_BANNERS)
for(Holder<BannerPattern> pattern : banner.patterns())
{
final String key = pattern.unwrapKey().get().location().getPath();
final String[] keyParts = key.split("_");
String bannerName = Utils.toCamelCase(keyParts[0]);
if(keyParts.length > 1)
bannerName += " ("+Utils.toCamelCase(keyParts[1])+")";
for(DyeColor dye : DyeColor.values())
{
String color = dye.getSerializedName();
add("block.minecraft.banner.immersiveengineering."+key+"."+color, I18n.get("color.minecraft."+color)+" "+bannerName);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ae40d6

Please sign in to comment.