Fix lang generator escaping newlines, add lang generator test
This commit is contained in:
parent
69ba974960
commit
ebd463e92f
4 changed files with 39 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
25f832a55d9d61fe27871ce866ef712b625032cc assets\data_gen_test\lang\en_us.json
|
||||
dc2deb0c2da07695855bbb88882455a80787ccac assets\data_gen_test\models\block\acacia_door_bottom.json
|
||||
e987df4921fc71322984556e9617915d4df2bdff assets\data_gen_test\models\block\acacia_door_bottom_hinge.json
|
||||
5103910559b21ce74f315358935a3e582b0c45cd assets\data_gen_test\models\block\acacia_door_top.json
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"biome.minecraft.beach": "Beach",
|
||||
"block.minecraft.stone": "Stone",
|
||||
"data_gen_test.test.unicode": "\u0287s\u01DD\u2534 \u01DDpo\u0254\u1D09u\u2229",
|
||||
"effect.minecraft.poison": "Poison",
|
||||
"enchantment.minecraft.sharpness": "Sharpness",
|
||||
"entity.minecraft.cat": "Cat",
|
||||
"item.minecraft.diamond": "Diamond"
|
||||
}
|
|
@ -27,7 +27,7 @@ import java.util.Objects;
|
|||
import java.util.TreeMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.text.translate.JavaUnicodeEscaper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
@ -73,7 +73,7 @@ public abstract class LanguageProvider implements IDataProvider {
|
|||
|
||||
private void save(DirectoryCache cache, Object object, Path target) throws IOException {
|
||||
String data = GSON.toJson(object);
|
||||
data = StringEscapeUtils.escapeJava(data); // Escape control chars and unicode
|
||||
data = JavaUnicodeEscaper.outsideOf(0, 0x7f).translate(data); // Escape unicode after the fact so that it's not double escaped by GSON
|
||||
String hash = IDataProvider.HASH_FUNCTION.hashUnencodedChars(data).toString();
|
||||
if (!Objects.equals(cache.getPreviousHash(target), hash) || !Files.exists(target)) {
|
||||
Files.createDirectories(target.getParent());
|
||||
|
|
|
@ -70,11 +70,16 @@ import net.minecraft.data.DirectoryCache;
|
|||
import net.minecraft.data.IFinishedRecipe;
|
||||
import net.minecraft.data.RecipeProvider;
|
||||
import net.minecraft.data.ShapedRecipeBuilder;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.resources.IResource;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.biome.Biomes;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
import net.minecraftforge.client.model.generators.ExistingFileHelper;
|
||||
|
@ -88,6 +93,7 @@ import net.minecraftforge.client.model.generators.VariantBlockStateBuilder;
|
|||
import net.minecraftforge.common.crafting.ConditionalAdvancement;
|
||||
import net.minecraftforge.common.crafting.ConditionalRecipe;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
|
||||
import net.minecraftforge.common.data.LanguageProvider;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
|
@ -113,6 +119,7 @@ public class DataGeneratorTest
|
|||
|
||||
if (event.includeClient())
|
||||
{
|
||||
gen.addProvider(new Lang(gen));
|
||||
gen.addProvider(new ItemModels(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(new BlockStates(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
|
@ -176,6 +183,26 @@ public class DataGeneratorTest
|
|||
}
|
||||
}
|
||||
|
||||
public static class Lang extends LanguageProvider
|
||||
{
|
||||
public Lang(DataGenerator gen)
|
||||
{
|
||||
super(gen, MODID, "en_us");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTranslations()
|
||||
{
|
||||
add(Blocks.STONE, "Stone");
|
||||
add(Items.DIAMOND, "Diamond");
|
||||
add(Biomes.BEACH, "Beach");
|
||||
add(Effects.POISON, "Poison");
|
||||
add(Enchantments.SHARPNESS, "Sharpness");
|
||||
add(EntityType.CAT, "Cat");
|
||||
add(MODID + ".test.unicode", "\u0287s\u01DD\u2534 \u01DDpo\u0254\u1D09u\u2229");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ItemModels extends ItemModelProvider
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
|
Loading…
Reference in a new issue