Skip to content

Commit

Permalink
Move lang datagen to common
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Sep 10, 2023
1 parent 441ce36 commit d458771
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gripe._90.megacells.datagen;

import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;

import com.google.gson.JsonObject;

import org.jetbrains.annotations.NotNull;

import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;

import appeng.core.definitions.BlockDefinition;
import appeng.core.definitions.ItemDefinition;

import gripe._90.megacells.MEGACells;
import gripe._90.megacells.definition.MEGABlocks;
import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGATranslations;

public class CommonLanguageProvider implements DataProvider {
private final Map<String, String> translationEntries = new TreeMap<>();
private final PackOutput output;

public CommonLanguageProvider(PackOutput output) {
this.output = output;
}

private void addTranslations() {
MEGAItems.getItems().forEach(this::add);
MEGABlocks.getBlocks().forEach(this::add);
Arrays.stream(MEGATranslations.values()).forEach(this::add);
add("text.autoconfig.%s.title".formatted(MEGACells.MODID), MEGATranslations.ModName.getEnglishText());
}

private void add(ItemDefinition<?> item) {
add(item.asItem().getDescriptionId(), item.getEnglishName());
}

private void add(BlockDefinition<?> block) {
add(block.block().getDescriptionId(), block.getEnglishName());
}

private void add(MEGATranslations translation) {
add(translation.getTranslationKey(), translation.getEnglishText());
}

private void add(String translationKey, String englishText) {
if (translationEntries.containsKey(translationKey)) {
throw new RuntimeException("Duplicate translation key: " + translationKey);
}

translationEntries.put(translationKey, englishText);
}

@NotNull
@Override
public CompletableFuture<?> run(CachedOutput writer) {
var translationJson = new JsonObject();
var translationFile = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "lang")
.json(MEGACells.makeId("en_us"));

addTranslations();
translationEntries.forEach(translationJson::addProperty);
return DataProvider.saveStable(writer, translationJson, translationFile);
}

@NotNull
@Override
public String getName() {
return "Language";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public InteractionResult onActivated(
return InteractionResult.PASS;
}

var be = this.getBlockEntity(level, pos);
var be = getBlockEntity(level, pos);

if (be != null) {
if (!level.isClientSide()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public void onInitializeDataGenerator(FabricDataGenerator generator) {
pack.addProvider((FabricDataOutput output) ->
new CommonTagProvider.ItemTags(output, registries, blocks.contentsGetter()));

pack.addProvider((FabricDataOutput output) -> new CommonLanguageProvider(output));
pack.addProvider(ModelProvider::new);
pack.addProvider(RecipeProvider::new);
pack.addProvider(LootTableProvider::new);
pack.addProvider(LocalisationProvider::new);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public static void onGatherData(GatherDataEvent event) {

pack.addProvider(RecipeProvider::new);
pack.addProvider(LootTableProvider::new);
pack.addProvider(LocalisationProvider::new);
pack.addProvider(CommonLanguageProvider::new);
}
}

0 comments on commit d458771

Please sign in to comment.