Skip to content

Commit

Permalink
- Ported to 1.20.4
Browse files Browse the repository at this point in the history
- Added NeoForge Support
- Changed the default emojis to be 9x9 textures of custom ones
  • Loading branch information
Buuz135 committed Mar 2, 2024
1 parent 75d9204 commit f463e5d
Show file tree
Hide file tree
Showing 27 changed files with 619 additions and 96 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,43 @@ jobs:
- name: build
run: ./gradlew build
- name: Publish Minecraft Mods Fabric
uses: Kir-Antipov/mc-publish@v2.1
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 284324
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files-primary: Fabric/build/libs/!(*-@(javadoc|sources)).jar
files-secondary: Fabric/build/libs/*-@(javadoc|sources).jar
version-type: release
version-type: beta
loaders: |
fabric
quilt
game-versions: 1.20.1
game-versions: 1.20.4
java: 17
name: ""
changelog: "https://github.com/InnovativeOnlineIndustries/Emojiful/commits/1.20"
changelog: "https://github.com/InnovativeOnlineIndustries/Emojiful/commits/1.20.4"
- name: Publish Minecraft Mods Forge
uses: Kir-Antipov/mc-publish@v2.1
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 284324
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files-primary: Forge/build/libs/!(*-@(javadoc|sources)).jar
files-secondary: Forge/build/libs/*-@(javadoc|sources).jar
version-type: release
version-type: beta
loaders: forge
game-versions: 1.20.1
game-versions: 1.20.4
java: 17
name: ""
changelog: "https://github.com/InnovativeOnlineIndustries/Emojiful/commits/1.20"
changelog: "https://github.com/InnovativeOnlineIndustries/Emojiful/commits/1.20.4"
- name: Publish Minecraft Mods NeoForge
uses: Kir-Antipov/mc-publish@v3.3.0
with:
curseforge-id: 284324
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files-primary: NeoForge/build/libs/!(*-@(javadoc|sources)).jar
files-secondary: NeoForge/build/libs/*-@(javadoc|sources).jar
version-type: beta
loaders: forge
game-versions: 1.20.4
java: 17
name: ""
changelog: "https://github.com/InnovativeOnlineIndustries/Emojiful/commits/1.20.4"
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ public static void indexEmojis() {
}

private static void preInitEmojis() {
CATEGORIES.addAll(Arrays.asList("Smileys & Emotion", "Animals & Nature", "Food & Drink", "Activities", "Travel & Places", "Objects", "Symbols", "Flags").stream().map(s -> new EmojiCategory(s, false)).collect(Collectors.toList()));
if (Services.CONFIG.loadCustom()) loadCustomEmojis();
//loadGithubEmojis();
if (Services.CONFIG.loadTwemoji()) loadTwemojis();
if (Services.CONFIG.loadTwemoji()){
CATEGORIES.addAll(Arrays.asList("Smileys & Emotion", "Animals & Nature", "Food & Drink", "Activities", "Travel & Places", "Objects", "Symbols", "Flags").stream().map(s -> new EmojiCategory(s, false)).collect(Collectors.toList()));
loadTwemojis();
}
if (Services.CONFIG.getProfanityFilter()) ProfanityFilter.loadConfigs();
}

private static void loadCustomEmojis() {
try {
YamlReader reader = new YamlReader(new StringReader(CommonClass.readStringFromURL("https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/master/Categories.yml")));
YamlReader reader = new YamlReader(new StringReader(CommonClass.readStringFromURL("https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/1.20-plus/Categories.yml")));
ArrayList<String> categories = (ArrayList<String>) reader.read();
for (String category : categories) {
CATEGORIES.add(0, new EmojiCategory(category.replace(".yml", ""), false));
CATEGORIES.add(new EmojiCategory(category.replace(".yml", ""), false));
List<Emoji> emojis = CommonClass.readCategory(category);
emojis.forEach(emoji -> emoji.location = CommonClass.cleanURL(emoji.location));
Constants.EMOJI_LIST.addAll(emojis);
Constants.EMOJI_MAP.put(category.replace(".yml", ""), emojis);
}
Expand Down
141 changes: 135 additions & 6 deletions Common/src/main/java/com/hrznstudio/emojiful/CommonClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.YamlReader;
import com.esotericsoftware.yamlbeans.YamlWriter;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
Expand All @@ -10,17 +11,19 @@
import com.hrznstudio.emojiful.api.EmojiFromGithub;
import com.hrznstudio.emojiful.datapack.EmojiRecipe;
import com.hrznstudio.emojiful.platform.Services;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import org.apache.commons.io.FileUtils;
import org.lwjgl.glfw.GLFW;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;


public class CommonClass {
Expand All @@ -45,21 +48,147 @@ public static JsonElement readJsonFromUrl(String url) {
return json;
}

public static void main(String[] s) {
public static void main(String[] s) throws IOException {
ClientEmojiHandler.loadTwemojis();
var folder = new File("raw_assets");
HashMap<String, List<YamlEmoji>> emojis = new HashMap<>();
for (String string : Constants.EMOJI_MAP.keySet()) {
for (Emoji emoji : Constants.EMOJI_MAP.get(string)) {
var found = false;
var emoji_name = emoji.name.replace("-", "_");
for (File file : folder.listFiles()) {
var filename = file.getName().replace(".png", "").replace("-", "_");
if (!found){
if (emoji_name.equals(filename) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").equals(filename)) ||
emoji_name.equals(filename.replace("woman", "female").replace("man", "male")) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").equals(filename.replace("woman", "female").replace("man", "male")))
){
found = true;
copy(string, file, emojis, emoji);
break;
}
}
}
if (!found){
System.out.println(emoji.name + "?");
}
}
}
for (String category : emojis.keySet()) {
var yamlFile = new File(category + ".yml");
if (!yamlFile.exists()) yamlFile.createNewFile();
YamlWriter writer = new YamlWriter(new FileWriter(category + ".yml"));
writer.write(emojis.get(category));
writer.close();
}
if (false){
emojis = new HashMap<>();
for (File file : folder.listFiles()) {
if (file.getName().contains("_tone")) continue;;
var filename = file.getName().replace(".png", "").replace("-", "_");
var fileNameSplit = filename.split("_");
var found = false;
for (String string : Constants.EMOJI_MAP.keySet()) {
if (!found){
for (Emoji emoji : Constants.EMOJI_MAP.get(string)) {
if (emoji.name.replace("-", "_").equals(filename) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").equals(filename)) ||
emoji.name.replace("-", "_").equals(filename.replace("woman", "female").replace("man", "male")) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").equals(filename.replace("woman", "female").replace("man", "male")))
){
found = true;
System.out.println(emoji.name + "=" + file.getName());
copy(string, file, emojis, emoji);
break;
}
}
}
}
for (String string : Constants.EMOJI_MAP.keySet()) {
if (!found){
for (Emoji emoji : Constants.EMOJI_MAP.get(string)) {
if (emoji.name.replace("-", "_").contains(filename) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").contains(filename)) ||
emoji.name.replace("-", "_").contains(filename.replace("woman", "female").replace("man", "male")) ||
emoji.strings.stream().anyMatch(s1 -> s1.replaceAll(":", "").replace("-", "_").contains(filename.replace("woman", "female").replace("man", "male")))
){
found = true;
System.out.println(emoji.name + "->" + file.getName());
copy(string, file, emojis, emoji);
break;
}
}
}
/*if (!found){
for (Emoji emoji : Constants.EMOJI_MAP.get(string)) {
if (Arrays.stream(fileNameSplit).anyMatch(s1 -> emoji.name.contains(s1)) || Arrays.stream(fileNameSplit).anyMatch(s1 -> emoji.texts.stream().anyMatch(s2 -> s2.contains(s1)))){
found = true;
copy(string, file);
break;
}
}
}*/
}
if (!found){
System.out.println();
//copy("Missing", file, new HashMap<>(), emoji);
}
}
for (String category : emojis.keySet()) {
var yamlFile = new File(category + ".yml");
if (!yamlFile.exists()) yamlFile.createNewFile();
YamlWriter writer = new YamlWriter(new FileWriter(category + ".yml"));

writer.write(emojis.get(category));
writer.close();
}
}

}

public static void copy(String category, File sourceFile, HashMap<String, List<YamlEmoji>> emojis, Emoji emoji){
var folderTo = new File("assets/" + category);
if (!folderTo.exists()) folderTo.mkdir();
try {
var name = sourceFile.getName().replace(".png", "").replace("-", "_");
emojis.computeIfAbsent(category, s -> new ArrayList<>()).add(new YamlEmoji(name, emoji.strings, "assets/" + category + "/" + sourceFile.getName()));
FileUtils.copyFile(sourceFile, new File(folderTo, sourceFile.getName()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static class YamlEmoji {
public String name;
public List<String> strings;
public String location;

public YamlEmoji() {
}

public YamlEmoji(String name, List<String> strings, String location) {
this.name = name;
this.strings = strings;
this.location = location;
}
}

public static List<Emoji> readCategory(String cat) throws YamlException {
YamlReader categoryReader = new YamlReader(new StringReader(readStringFromURL("https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/master/" + cat)));
YamlReader categoryReader = new YamlReader(new StringReader(readStringFromURL("https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/1.20-plus/" + cleanURL(cat))));
return Lists.newArrayList(categoryReader.read(Emoji[].class));
}

public static String cleanURL(String string){
return string.replaceAll(" ", "%20").replaceAll("&", "%26");
}

public static void onRecipesUpdated(RecipeManager manager) {
ClientEmojiHandler.CATEGORIES.removeIf(EmojiCategory::worldBased);
Constants.EMOJI_LIST.removeIf(Emoji::worldBased);
if (Services.CONFIG.loadDatapack()) {
RecipeType<EmojiRecipe> emojiRecipeRecipeType = Services.PLATFORM.getRecipeType();
List<EmojiRecipe> emojiList = manager.getAllRecipesFor(emojiRecipeRecipeType);
List<EmojiRecipe> emojiList = manager.getAllRecipesFor(emojiRecipeRecipeType).stream().map(RecipeHolder::value).toList();
for (EmojiRecipe emojiRecipe : emojiList) {
EmojiFromGithub emoji = new EmojiFromGithub();
emoji.name = emojiRecipe.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void run() {
}

public String getUrl() {
return "https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/master/" + location;
return "https://raw.githubusercontent.com/InnovativeOnlineIndustries/emojiful-assets/1.20-plus/" + location;
}

public File getCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

public class EmojiRecipe implements Recipe<Container> {

private final ResourceLocation recipeName;
private final String category;
private final String name;
private final String url;

public EmojiRecipe(ResourceLocation recipeName, String category, String name, String url) {
this.recipeName = recipeName;
public EmojiRecipe(String category, String name, String url) {
this.category = category;
this.name = name;
this.url = url;
Expand All @@ -44,11 +42,6 @@ public ItemStack getResultItem(RegistryAccess registryAccess) {
return ItemStack.EMPTY;
}

@Override
public ResourceLocation getId() {
return recipeName;
}

@Override
public RecipeSerializer<?> getSerializer() {
return Services.PLATFORM.getRecipeSerializer();
Expand All @@ -59,10 +52,6 @@ public RecipeType<?> getType() {
return Services.PLATFORM.getRecipeType();
}

public ResourceLocation getRecipeName() {
return recipeName;
}

public String getCategory() {
return category;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
package com.hrznstudio.emojiful.datapack;

import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;

public class EmojiRecipeSerializer implements RecipeSerializer<EmojiRecipe> {
import java.util.Objects;

public class EmojiRecipeSerializer implements RecipeSerializer<EmojiRecipe> {

private final Codec<EmojiRecipe> codec;
public EmojiRecipeSerializer() {

this.codec = RecordCodecBuilder.create(instance -> {
var test = instance.group(
ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter(Recipe::getGroup),
Codec.STRING.fieldOf("category").forGetter(EmojiRecipe::getCategory),
Codec.STRING.fieldOf("name").forGetter(EmojiRecipe::getName),
Codec.STRING.fieldOf("url").forGetter(EmojiRecipe::getUrl));
return test.apply(instance, (s, s2, s3, s4) -> new EmojiRecipe(s2, s3, s4));
});
}


@Override
public EmojiRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return new EmojiRecipe(recipeId, json.get("category").getAsString(), json.get("name").getAsString(), json.get("url").getAsString());
public EmojiRecipe fromNetwork(FriendlyByteBuf buffer) {
return new EmojiRecipe(buffer.readUtf(), buffer.readUtf(), buffer.readUtf());
}

@Override
public EmojiRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new EmojiRecipe(recipeId, buffer.readUtf(), buffer.readUtf(), buffer.readUtf());
public Codec<EmojiRecipe> codec() {
return codec;
}

@Override
Expand Down
Loading

0 comments on commit f463e5d

Please sign in to comment.