Skip to content

Commit

Permalink
Merge pull request #38 from aratakileo/move-to-elegantia
Browse files Browse the repository at this point in the history
Move to elegantia
  • Loading branch information
aratakileo authored Feb 21, 2024
2 parents 103f808 + 3567895 commit 8a7be58
Show file tree
Hide file tree
Showing 46 changed files with 527 additions and 1,734 deletions.
34 changes: 13 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,32 @@ apply from: 'util.gradle'

group = project.maven_group

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {
url = 'https://maven.terraformersmc.com/releases'
content {
includeGroup 'com.terraformersmc'
}
}
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation "maven.modrinth:elegantia:${project.elegantia_version}+fabric-${project.minecraft_version}"

implEmbeddedMod "maven.modrinth:suggestions-api:${project.suggestions_api_version}"
implEmbeddedMod "maven.modrinth:suggestions-api:${project.suggestions_api_version}+fabric"
}

processResources {
inputs.property "version", project.version
inputs.property "suggestions_api_version", suggestions_api_version
final var replaceProperties = [
"version": project.version,
"suggestions_api_version": suggestions_api_version,
"elegantia_version": elegantia_version,
"pack_format": pack_format
]

inputs.properties replaceProperties

filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version,
"suggestions_api_version": suggestions_api_version
filesMatching(["fabric.mod.json", "/resourcepacks/*/pack.mcmeta"]) {
expand replaceProperties
}
}

Expand Down
30 changes: 20 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs = -Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version = 1.20.1
# General Properties
# 1.20-1.20.1
#minecraft_version = 1.20.1
#loader_version = 0.14.25
#fabric_version = 0.83.0
#pack_format = 15

loader_version = 0.14.25
# 1.20.2-1.20.4
minecraft_version = 1.20.4
loader_version = 0.15.6
fabric_version = 0.96.0
pack_format = 22

quilt_loader = 0.23.1

# Mod Properties
support_minecraft_versions = 1.20-1.20.1
mod_version = 1.0.1
# 1.20-1.20.1
#support_minecraft_versions = 1.20-1.20.1
# 1.20.2-1.20.4
support_minecraft_versions = 1.20.2-1.20.4
mod_version = 2.0.0
maven_group = io.github.aratakileo
archives_base_name = emogg

# Dependencies
# check this on https://fabricmc.net/develop/
fabric_version = 0.83.0
modmenu_version = 7.2.2
suggestions_api_version = 1.0.4
suggestions_api_version = 1.0.6
elegantia_version=0.0.1-alpha
44 changes: 22 additions & 22 deletions src/main/java/io/github/aratakileo/emogg/Emogg.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.github.aratakileo.emogg;

import io.github.aratakileo.emogg.api.ModrinthApi;
import io.github.aratakileo.elegantia.gui.config.Config;
import io.github.aratakileo.elegantia.updatechecker.ModrinthUpdateChecker;
import io.github.aratakileo.elegantia.updatechecker.SuccessfulResponse;
import io.github.aratakileo.elegantia.util.ModInfo;
import io.github.aratakileo.elegantia.util.Platform;
import io.github.aratakileo.emogg.emoji.EmojiManager;
import io.github.aratakileo.emogg.gui.EmojiSuggestion;
import io.github.aratakileo.emogg.util.Platform;
import io.github.aratakileo.suggestionsapi.SuggestionsAPI;
import io.github.aratakileo.suggestionsapi.injector.Injector;
import io.github.aratakileo.suggestionsapi.util.Cast;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
Expand All @@ -22,15 +24,14 @@
import java.util.List;
import java.util.regex.Pattern;


public class Emogg implements ClientModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger(Emogg.class);

public static final String NAMESPACE_OR_ID = "emogg";
public final static Logger LOGGER = LoggerFactory.getLogger(Emogg.class);
public final static String NAMESPACE_OR_ID = "emogg";
public final static ModrinthUpdateChecker UPDATE_CHECKER = new ModrinthUpdateChecker(NAMESPACE_OR_ID);

@Override
public void onInitializeClient() {
ModrinthApi.checkUpdates();
final var lastResponse = UPDATE_CHECKER.check();

SuggestionsAPI.registerInjector(Injector.simple(
Pattern.compile("[::][A-Za-z0-9_]*([::])?$"),
Expand All @@ -44,30 +45,29 @@ public void onInitializeClient() {
}
));

LOGGER.info(String.format(
"[emogg] Installed v%s; %s to download (from modrinth.com)%s",
Platform.getModVersion(NAMESPACE_OR_ID),
switch (ModrinthApi.getResponseCode()) {
case SUCCESSFUL, NEEDS_TO_BE_UPDATED -> "available";
LOGGER.info("[emogg] Installed v%s; %s to download (from modrinth.com)%s".formatted(
ModInfo.getVersion(NAMESPACE_OR_ID).orElse("unknown").split("\\+")[0],
switch (lastResponse.getResponseCode()) {
case SUCCESSFUL, NEW_VERSION_IS_AVAILABLE -> "available";
default -> "not available";
},
switch (ModrinthApi.getResponseCode()) {
switch (lastResponse.getResponseCode()) {
case DOES_NOT_EXIST_AT_MODRINTH -> ", because does not exist for Minecraft v"
+ SharedConstants.getCurrentVersion().getName();
case SUCCESSFUL, NEEDS_TO_BE_UPDATED -> String.format(
" v%s - %s",
ModrinthApi.getUpdateVersion(),
ModrinthApi.getResponseCode() == ModrinthApi.ResponseCode.NEEDS_TO_BE_UPDATED
? "needs to be updated" : "not needs to be updated"
+ Platform.getCurrentMinecraftVersion();
case SUCCESSFUL, NEW_VERSION_IS_AVAILABLE -> " v%s - %s".formatted(
UPDATE_CHECKER.getLastResponseAsSuccessful()
.map(SuccessfulResponse::getDefinedVersion)
.orElse("unknown"),
lastResponse.isNewVersionAvailable() ? "needs to be updated" : "not needs to be updated"
);
default -> ", because something went wrong";
}
));

if (ModrinthApi.getResponseCode() == ModrinthApi.ResponseCode.DOES_NOT_EXIST_AT_MODRINTH)
if (lastResponse.doesNotExistAtModrinth())
LOGGER.warn("[emogg] It looks like you are using an unofficial version port!");

EmoggConfig.load();
EmoggConfig.instance = Config.init(EmoggConfig.class, NAMESPACE_OR_ID);
EmojiManager.init();

registerBuiltinResourcePack("builtin");
Expand Down
77 changes: 20 additions & 57 deletions src/main/java/io/github/aratakileo/emogg/EmoggConfig.java
Original file line number Diff line number Diff line change
@@ -1,74 +1,37 @@
package io.github.aratakileo.emogg;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.github.aratakileo.elegantia.gui.config.Config;
import io.github.aratakileo.elegantia.gui.config.ConfigField;
import io.github.aratakileo.elegantia.gui.config.Trigger;
import io.github.aratakileo.emogg.emoji.Emoji;
import io.github.aratakileo.emogg.emoji.EmojiManager;
import io.github.aratakileo.emogg.emoji.FueController;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class EmoggConfig {
// Non-JSON values
private final static File file = new File("config/emogg.json");
private final static Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.setPrettyPrinting()
.create();
public class EmoggConfig extends Config {
public static EmoggConfig instance;

public static @NotNull EmoggConfig instance = new EmoggConfig();

// JSON values
@Trigger("debug")
@ConfigField
public boolean enableDebugMode = false;
@ConfigField(triggeredBy = "debug")
public boolean enableAtlasDebugHUD = false;
public @NotNull ArrayList<FueController.EmojiStatistic> frequentlyUsedEmojis = new ArrayList<>();
public @NotNull ArrayList<String> hiddenCategoryNames = new ArrayList<>();
public boolean enableCustomShaders = true;

public static void setField(String field, Object value) {
try {
instance.getClass().getField(field).set(instance, value);
} catch (IllegalAccessException | NoSuchFieldException e) {
Emogg.LOGGER.warn("Failed to set config field "+field, e);
}
}

public static Object getField(String field) {
try {
return instance.getClass().getField(field).get(instance);
} catch (IllegalAccessException | NoSuchFieldException e) {
Emogg.LOGGER.warn("Failed to get config field "+field, e);
return null;
}
}
public @NotNull ArrayList<FueController.EmojiStatistic> frequentlyUsedEmojis = new ArrayList<>();
public @NotNull ArrayList<String> hiddenCategoryNames = new ArrayList<>();

public static void load() {
if (file.exists())
try {
final var fileReader = new FileReader(file);
instance = gson.fromJson(fileReader, EmoggConfig.class);
fileReader.close();
} catch (Exception e) {
Emogg.LOGGER.error("Failed to load emogg config: ", e);
save();
}
@ConfigField(triggeredBy = "debug")
public static void reloadAllEmojis() {
EmojiManager.getInstance().getEmojisStream()
.forEach(e -> e.reload(false));
}

public static void save() {
final File parentFile;

if (!(parentFile = file.getParentFile()).exists())
parentFile.mkdir();

try {
final var fileWriter = new FileWriter(file);
fileWriter.write(gson.toJson(instance));
fileWriter.close();
} catch (Exception e) {
Emogg.LOGGER.error("Failed to save emogg config: ", e);
}
@ConfigField(triggeredBy = "debug")
public static void forceLoadAllEmojis() {
EmojiManager.getInstance().getEmojisStream()
.forEach(Emoji::forceLoad);
}
}
14 changes: 7 additions & 7 deletions src/main/java/io/github/aratakileo/emogg/EmoggRenderTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public class EmoggRenderTypes {

private static RenderType setupEmojiRT(RenderType renderType) {
// 1.20.4
// Minecraft.getInstance()
// .renderBuffers()
// .bufferSource()
// .fixedBuffers
// .put(renderType, new BufferBuilder(renderType.bufferSize()));

// 1.20.1
Minecraft.getInstance()
.renderBuffers()
.bufferSource()
.fixedBuffers
.put(renderType, new BufferBuilder(renderType.bufferSize()));

// 1.20.1
// Minecraft.getInstance()
// .renderBuffers()
// .fixedBuffers
// .put(renderType, new BufferBuilder(renderType.bufferSize()));
return renderType;
}

Expand Down
13 changes: 0 additions & 13 deletions src/main/java/io/github/aratakileo/emogg/api/ModMenuApiImpl.java

This file was deleted.

Loading

0 comments on commit 8a7be58

Please sign in to comment.