Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version "${loom_version}"
id 'maven-publish'
}

Expand All @@ -11,12 +11,6 @@ base {
}

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 {
name = "Terraformers"
url = "https://maven.terraformersmc.com/"
Expand Down Expand Up @@ -46,7 +40,7 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}")

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") {
Expand All @@ -58,7 +52,7 @@ processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
expand "version": inputs.properties.version
}
}

Expand All @@ -77,8 +71,10 @@ java {
}

jar {
inputs.property "archivesName", project.base.archivesName

from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
rename { "${it}_${inputs.properties.archivesName}"}
}
}

Expand Down
16 changes: 9 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.9

minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.14
loom_version=1.10-SNAPSHOT

# Mod Properties
mod_version=1.1.3+1.21.2
mod_version=1.1.4+1.21.4
maven_group=borknbeans.lightweightinventorysorting
archives_base_name=lightweight-inventory-sorting

# Dependencies
fabric_version=0.106.1+1.21.2
modmenu_version=12.0.0
cloth_version=16.0.143
fabric_version=0.119.2+1.21.4
modmenu_version=13.0.3
cloth_version=17.0.144
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package borknbeans.lightweightinventorysorting;

import borknbeans.lightweightinventorysorting.config.LightweightInventorySortingConfig;
import borknbeans.lightweightinventorysorting.config.Config;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
Expand All @@ -13,17 +13,16 @@ public class LightweightInventorySortingClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
LightweightInventorySortingConfig.load();

Config.load();
registerKeyBindings();
}

private void registerKeyBindings() {
sortKeyBind = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.lightweight-inventory-sorting.sort",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_R,
"category.lightweight-inventory-sorting.title"
"key.lightweight-inventory-sorting.sort",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_R,
"category.lightweight-inventory-sorting.title"
));
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
package borknbeans.lightweightinventorysorting.config;

import borknbeans.lightweightinventorysorting.LightweightInventorySorting;
import net.minecraft.util.Identifier;

public enum ButtonSize {
SMALL,
MEDIUM,
LARGE;

public int getButtonSize() {
switch (this) {
case SMALL:
return 6;
case MEDIUM:
return 9;
case LARGE:
return 12;
}

return 0;
}

public Identifier getButtonTexture() {
String fileName = "sort_button_large";
switch (this) {
case SMALL:
fileName = "sort_button_small";
break;
case MEDIUM:
fileName = "sort_button_medium";
break;
case LARGE:
fileName = "sort_button_large";
break;
}

if (LightweightInventorySortingConfig.sortType == SortTypes.REVERSE_ALPHANUMERIC) {
fileName += "_z";
}

return Identifier.of(LightweightInventorySorting.MOD_ID, fileName);
}

public Identifier getButtonHoverTexture() {
String fileName = "sort_button_large_hover";
switch (this) {
case SMALL:
fileName = "sort_button_small_hover";
break;
case MEDIUM:
fileName = "sort_button_medium_hover";
break;
case LARGE:
fileName = "sort_button_large_hover";
break;
}

if (LightweightInventorySortingConfig.sortType == SortTypes.REVERSE_ALPHANUMERIC) {
fileName += "_z";
}

return Identifier.of(LightweightInventorySorting.MOD_ID, fileName);
}

}
package borknbeans.lightweightinventorysorting.config;

import borknbeans.lightweightinventorysorting.LightweightInventorySorting;
import net.minecraft.util.Identifier;

public enum ButtonSize {
SMALL,
MEDIUM,
LARGE;

public int getButtonSize() {
switch (this) {
case SMALL:
return 6;
case MEDIUM:
return 9;
case LARGE:
return 12;
}

return 0;
}

public Identifier getButtonTexture() {
String fileName = "sort_button_large";
switch (this) {
case SMALL:
fileName = "sort_button_small";
break;
case MEDIUM:
fileName = "sort_button_medium";
break;
case LARGE:
fileName = "sort_button_large";
break;
}

if (Config.sortType == SortTypes.REVERSE_ALPHANUMERIC) {
fileName += "_z";
}

return Identifier.of(LightweightInventorySorting.MOD_ID, fileName);
}

public Identifier getButtonHoverTexture() {
String fileName = "sort_button_large_hover";
switch (this) {
case SMALL:
fileName = "sort_button_small_hover";
break;
case MEDIUM:
fileName = "sort_button_medium_hover";
break;
case LARGE:
fileName = "sort_button_large_hover";
break;
}

if (Config.sortType == SortTypes.REVERSE_ALPHANUMERIC) {
fileName += "_z";
}

return Identifier.of(LightweightInventorySorting.MOD_ID, fileName);
}
}
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
package borknbeans.lightweightinventorysorting.config;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class LightweightInventorySortingConfig {

private static final File CONFIG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "lightweight-inventory-sorting.json");
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();

public static SortTypes sortType = SortTypes.ALPHANUMERIC;

public static ButtonSize buttonSize = ButtonSize.LARGE;
public static int xOffsetInventory = 0;
public static int yOffsetInventory = 0;
public static int xOffsetContainer = 0;
public static int yOffsetContainer = 0;

public static int sortDelay = 0;

public static void load() {
if (CONFIG_FILE.exists()) {
try (FileReader reader = new FileReader(CONFIG_FILE)) {
ConfigData data = GSON.fromJson(reader, ConfigData.class);
sortType = data.sortType == null ? SortTypes.ALPHANUMERIC : data.sortType;
buttonSize = data.buttonSize == null ? ButtonSize.MEDIUM : data.buttonSize;
xOffsetInventory = data.xOffsetInventory;
yOffsetInventory = data.yOffsetInventory;
xOffsetContainer = data.xOffsetContainer;
yOffsetContainer = data.yOffsetContainer;
sortDelay = data.sortDelay;
} catch (IOException e) {
e.printStackTrace();
}
}
}

public static void save() {
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
ConfigData data = new ConfigData();
data.sortType = sortType;
data.buttonSize = buttonSize;
data.xOffsetInventory = xOffsetInventory;
data.yOffsetInventory = yOffsetInventory;
data.xOffsetContainer = xOffsetContainer;
data.yOffsetContainer = yOffsetContainer;
data.sortDelay = sortDelay;
GSON.toJson(data, writer);
} catch (IOException e) {
e.printStackTrace();
}
}

private static class ConfigData {
SortTypes sortType;
ButtonSize buttonSize;
int xOffsetInventory;
int yOffsetInventory;
int xOffsetContainer;
int yOffsetContainer;
int sortDelay;
}
}
package borknbeans.lightweightinventorysorting.config;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import borknbeans.lightweightinventorysorting.LightweightInventorySorting;
import net.fabricmc.loader.api.FabricLoader;

public class Config {
private static final File CONFIG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "lightweight-inventory-sorting.json");
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();


public static SortTypes sortType = SortTypes.ALPHANUMERIC;
public static ButtonSize buttonSize = ButtonSize.LARGE;

public static int xOffsetInventory = 0;
public static int yOffsetInventory = 0;
public static int xOffsetContainer = 0;
public static int yOffsetContainer = 0;

public static int sortDelay = 0;

private static class ConfigData {
SortTypes sortType;
ButtonSize buttonSize;
int xOffsetInventory;
int yOffsetInventory;
int xOffsetContainer;
int yOffsetContainer;
int sortDelay;
}

public static void load() {
if (CONFIG_FILE.exists()) {
try (FileReader reader = new FileReader(CONFIG_FILE)) {
ConfigData data = GSON.fromJson(reader, ConfigData.class);
sortType = data.sortType == null ? SortTypes.ALPHANUMERIC : data.sortType;
buttonSize = data.buttonSize == null ? ButtonSize.MEDIUM : data.buttonSize;
xOffsetInventory = data.xOffsetInventory;
yOffsetInventory = data.yOffsetInventory;
xOffsetContainer = data.xOffsetContainer;
yOffsetContainer = data.yOffsetContainer;
sortDelay = data.sortDelay;
} catch (IOException e) {
LightweightInventorySorting.LOGGER.error("Failed to load config file (resetting to default): {}", e.getMessage());
save();
}
}
}

public static void save() {
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
ConfigData data = new ConfigData();
data.sortType = sortType;
data.buttonSize = buttonSize;
data.xOffsetInventory = xOffsetInventory;
data.yOffsetInventory = yOffsetInventory;
data.xOffsetContainer = xOffsetContainer;
data.yOffsetContainer = yOffsetContainer;
data.sortDelay = sortDelay;
GSON.toJson(data, writer);
} catch (IOException e) {
LightweightInventorySorting.LOGGER.error("Failed to save config file: {}", e.getMessage());
}
}
}
Loading