Removed Tag Helper
This commit is contained in:
parent
df890a0167
commit
cd6b385ae2
13 changed files with 10 additions and 229 deletions
|
@ -1,73 +0,0 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class TagHelper {
|
||||
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_BLOCK = Maps.newConcurrentMap();
|
||||
private static final Map<ResourceLocation, Set<ResourceLocation>> TAGS_ITEM = Maps.newConcurrentMap();
|
||||
|
||||
public static void addTag(Tag.Named<Block> tag, Block... blocks) {
|
||||
ResourceLocation tagID = tag.getName();
|
||||
Set<ResourceLocation> set = TAGS_BLOCK.computeIfAbsent(tagID, k -> Sets.newHashSet());
|
||||
for (Block block: blocks) {
|
||||
ResourceLocation id = Registry.BLOCK.getKey(block);
|
||||
if (id != Registry.BLOCK.getDefaultKey()) {
|
||||
set.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTag(Tag.Named<Item> tag, ItemLike... items) {
|
||||
ResourceLocation tagID = tag.getName();
|
||||
Set<ResourceLocation> set = TAGS_ITEM.computeIfAbsent(tagID, k -> Sets.newHashSet());
|
||||
for (ItemLike item: items) {
|
||||
ResourceLocation id = Registry.ITEM.getKey(item.asItem());
|
||||
if (id != Registry.ITEM.getDefaultKey()) {
|
||||
set.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static void addTags(ItemLike item, Tag.Named<Item>... tags) {
|
||||
for (Tag.Named<Item> tag: tags) {
|
||||
addTag(tag, item);
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static void addTags(Block block, Tag.Named<Block>... tags) {
|
||||
for (Tag.Named<Block> tag: tags) {
|
||||
addTag(tag, block);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tag.Builder apply(Tag.Builder builder, Set<ResourceLocation> ids) {
|
||||
ids.forEach(value -> builder.addElement(value, "Better End Code"));
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static Map<ResourceLocation, Tag.Builder> apply(String entry, Map<ResourceLocation, Tag.Builder> tagsMap) {
|
||||
Map<ResourceLocation, Set<ResourceLocation>> endTags = null;
|
||||
if (entry.equals("block")) {
|
||||
endTags = TAGS_BLOCK;
|
||||
} else if (entry.equals("item")) {
|
||||
endTags = TAGS_ITEM;
|
||||
}
|
||||
if (endTags != null) {
|
||||
endTags.forEach((id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Tag.Builder.tag()), ids));
|
||||
}
|
||||
return tagsMap;
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class TranslationHelper {
|
||||
public static void printMissingNames() {
|
||||
List<String> missingNamesEn = Lists.newArrayList();
|
||||
List<String> missingNamesRu = Lists.newArrayList();
|
||||
|
||||
Gson gson = new Gson();
|
||||
InputStream streamEn = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/en_us.json");
|
||||
InputStream streamRu = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/ru_ru.json");
|
||||
JsonObject translationEn = gson.fromJson(new InputStreamReader(streamEn), JsonObject.class);
|
||||
JsonObject translationRu = gson.fromJson(new InputStreamReader(streamRu), JsonObject.class);
|
||||
|
||||
Registry.BLOCK.forEach((block) -> {
|
||||
if (Registry.BLOCK.getKey(block).getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||
String name = block.getName().getString();
|
||||
if (!translationEn.has(name)) {
|
||||
missingNamesEn.add(name);
|
||||
}
|
||||
if (!translationRu.has(name)) {
|
||||
missingNamesRu.add(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
EndItems.getModItems().forEach((item) -> {
|
||||
String name = item.getDescription().getString();
|
||||
if (!translationEn.has(name)) {
|
||||
missingNamesEn.add(name);
|
||||
}
|
||||
if (!translationRu.has(name)) {
|
||||
missingNamesRu.add(name);
|
||||
}
|
||||
});
|
||||
|
||||
EndBiomes.getModBiomes().forEach((endBiome) -> {
|
||||
if (endBiome.getID().getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||
String name = "biome." + BetterEnd.MOD_ID + "." + endBiome.getID().getPath();
|
||||
if (!translationEn.has(name)) {
|
||||
missingNamesEn.add(name);
|
||||
}
|
||||
if (!translationRu.has(name)) {
|
||||
missingNamesRu.add(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Registry.ENTITY_TYPE.forEach((entity) -> {
|
||||
ResourceLocation id = Registry.ENTITY_TYPE.getKey(entity);
|
||||
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||
String name = "entity." + BetterEnd.MOD_ID + "." + id.getPath();
|
||||
if (!translationEn.has(name)) {
|
||||
missingNamesEn.add(name);
|
||||
}
|
||||
if (!translationRu.has(name)) {
|
||||
missingNamesRu.add(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!missingNamesEn.isEmpty() || !missingNamesRu.isEmpty()) {
|
||||
|
||||
System.out.println("========================================");
|
||||
System.out.println(" MISSING NAMES LIST");
|
||||
|
||||
if (!missingNamesEn.isEmpty()) {
|
||||
Collections.sort(missingNamesEn);
|
||||
System.out.println("========================================");
|
||||
System.out.println(" ENGLISH");
|
||||
System.out.println("========================================");
|
||||
missingNamesEn.forEach((name) -> {
|
||||
System.out.println(" \"" + name + "\": \"" + fastTranslateEn(name) + "\",");
|
||||
});
|
||||
}
|
||||
|
||||
if (!missingNamesRu.isEmpty()) {
|
||||
Collections.sort(missingNamesRu);
|
||||
System.out.println("========================================");
|
||||
System.out.println(" RUSSIAN");
|
||||
System.out.println("========================================");
|
||||
missingNamesRu.forEach((name) -> {
|
||||
System.out.println(" \"" + name + "\": \"\",");
|
||||
});
|
||||
}
|
||||
|
||||
System.out.println("========================================");
|
||||
}
|
||||
}
|
||||
|
||||
public static String fastTranslateEn(String text) {
|
||||
String[] words = text.substring(text.lastIndexOf('.') + 1).split("_");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
builder.append(Character.toUpperCase(word.charAt(0)));
|
||||
builder.append(word, 1, word.length());
|
||||
if (i < words.length - 1) {
|
||||
builder.append(' ');
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue