Skip to content

Commit a4dd140

Browse files
committed
add client config, integrate with sodium settings api
1 parent 68ba314 commit a4dd140

7 files changed

Lines changed: 165 additions & 56 deletions

File tree

build.gradle

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,101 @@
11
plugins {
2-
id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
3-
id 'maven-publish'
2+
id 'net.fabricmc.fabric-loom-remap' version "${loom_version}"
3+
id 'maven-publish'
44
}
55

66
version = project.mod_version
77
group = project.maven_group
88

99
base {
10-
archivesName = project.archives_base_name
10+
archivesName = project.archives_base_name
1111
}
1212

1313
repositories {
14-
// Add repositories to retrieve artifacts from in here.
15-
// You should only use this when depending on other mods because
16-
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
17-
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
18-
// for more information about repositories.
14+
maven {
15+
url = "https://maven.caffeinemc.net/releases"
16+
name = "CaffeineMC"
17+
}
18+
maven {
19+
url = "https://api.modrinth.com/maven"
20+
name = "Modrinth Maven"
21+
}
1922
}
2023

2124
loom {
22-
splitEnvironmentSourceSets()
25+
splitEnvironmentSourceSets()
2326

24-
mods {
25-
"basicstorage" {
26-
sourceSet sourceSets.main
27-
sourceSet sourceSets.client
28-
}
29-
}
27+
mods {
28+
"basicstorage" {
29+
sourceSet sourceSets.main
30+
sourceSet sourceSets.client
31+
}
32+
}
3033

3134
}
3235

3336
fabricApi {
34-
configureDataGeneration()
37+
configureDataGeneration()
3538
}
3639

3740
dependencies {
38-
// To change the versions see the gradle.properties file
39-
minecraft "com.mojang:minecraft:${project.minecraft_version}"
40-
mappings loom.officialMojangMappings()
41-
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
42-
43-
// Fabric API. This is technically optional, but you probably want it anyway.
44-
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
45-
41+
// To change the versions see the gradle.properties file
42+
minecraft "com.mojang:minecraft:${project.minecraft_version}"
43+
mappings loom.officialMojangMappings()
44+
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
45+
46+
// Fabric API. This is technically optional, but you probably want it anyway.
47+
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
48+
49+
// Sodium Integration
50+
modCompileOnly("net.caffeinemc:sodium-fabric:${project.sodium_version}") {
51+
transitive = false
52+
}
4653
}
4754

4855
processResources {
49-
inputs.property "version", project.version
56+
inputs.property "version", project.version
5057

51-
filesMatching("fabric.mod.json") {
52-
expand "version": inputs.properties.version
53-
}
58+
filesMatching("fabric.mod.json") {
59+
expand "version": inputs.properties.version
60+
}
5461
}
5562

5663
tasks.withType(JavaCompile).configureEach {
57-
it.options.release = 21
64+
it.options.release = 21
5865
}
5966

6067
java {
61-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
62-
// if it is present.
63-
// If you remove this line, sources will not be generated.
64-
withSourcesJar()
68+
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
69+
// if it is present.
70+
// If you remove this line, sources will not be generated.
71+
withSourcesJar()
6572

66-
sourceCompatibility = JavaVersion.VERSION_21
67-
targetCompatibility = JavaVersion.VERSION_21
73+
sourceCompatibility = JavaVersion.VERSION_21
74+
targetCompatibility = JavaVersion.VERSION_21
6875
}
6976

7077
jar {
71-
inputs.property "archivesName", project.base.archivesName
78+
inputs.property "archivesName", project.base.archivesName
7279

73-
from("LICENSE") {
74-
rename { "${it}_${inputs.properties.archivesName}"}
75-
}
80+
from("LICENSE") {
81+
rename { "${it}_${inputs.properties.archivesName}" }
82+
}
7683
}
7784

7885
// configure the maven publication
7986
publishing {
80-
publications {
81-
create("mavenJava", MavenPublication) {
82-
artifactId = project.archives_base_name
83-
from components.java
84-
}
85-
}
86-
87-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
88-
repositories {
89-
// Add repositories to publish to here.
90-
// Notice: This block does NOT have the same function as the block in the top level.
91-
// The repositories here will be used for publishing your artifact, not for
92-
// retrieving dependencies.
93-
}
87+
publications {
88+
create("mavenJava", MavenPublication) {
89+
artifactId = project.archives_base_name
90+
from components.java
91+
}
92+
}
93+
94+
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
95+
repositories {
96+
// Add repositories to publish to here.
97+
// Notice: This block does NOT have the same function as the block in the top level.
98+
// The repositories here will be used for publishing your artifact, not for
99+
// retrieving dependencies.
100+
}
94101
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ org.gradle.jvmargs=-Xmx1G
33
org.gradle.parallel=true
44
org.gradle.configuration-cache=false
55

6-
# Fabric Properties
7-
# check these on https://fabricmc.net/develop
6+
# Fabric Properties https://fabricmc.net/develop
87
minecraft_version=1.21.11
98
loader_version=0.18.4
109
loom_version=1.14-SNAPSHOT
@@ -16,3 +15,4 @@ archives_base_name=basicstorage
1615

1716
# Dependencies
1817
fabric_version=0.140.2+1.21.11
18+
sodium_version=0.8.2+mc1.21.11
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.khazoda.basicstorage;
2+
3+
import net.fabricmc.loader.api.FabricLoader;
4+
5+
import java.io.IOException;
6+
import java.io.Reader;
7+
import java.io.Writer;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.Properties;
11+
12+
public class BasicStorageClientConfig {
13+
private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("basicstorage-client.properties");
14+
public static final BasicStorageClientConfig INSTANCE = new BasicStorageClientConfig();
15+
private final Properties properties;
16+
17+
private BasicStorageClientConfig() {
18+
this.properties = new Properties();
19+
}
20+
21+
public void load() {
22+
if (Files.exists(CONFIG_PATH)) {
23+
try (Reader reader = Files.newBufferedReader(CONFIG_PATH)) {
24+
properties.load(reader);
25+
} catch (IOException e) {
26+
// use defaults
27+
}
28+
}
29+
30+
if (!properties.containsKey("show_crate_station_beams")) {
31+
properties.setProperty("show_crate_station_beams", "true");
32+
save();
33+
}
34+
}
35+
36+
public void save() {
37+
try {
38+
Files.createDirectories(CONFIG_PATH.getParent());
39+
try (Writer writer = Files.newBufferedWriter(CONFIG_PATH)) {
40+
writer.write("# Basic Storage Client Configuration\n\n");
41+
writer.write("# If true, crate station beams will be rendered\n");
42+
writer.write("show_crate_station_beams=" + properties.getProperty("show_crate_station_beams", "true") + "\n");
43+
}
44+
} catch (IOException e) {
45+
// ignore save errors
46+
}
47+
}
48+
49+
public boolean showCrateStationBeams() {
50+
return Boolean.parseBoolean(properties.getProperty("show_crate_station_beams", "true"));
51+
}
52+
53+
public void setShowCrateStationBeams(boolean value) {
54+
properties.setProperty("show_crate_station_beams", String.valueOf(value));
55+
}
56+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.khazoda.basicstorage.integration.sodium;
2+
3+
import com.khazoda.basicstorage.BasicStorageClientConfig;
4+
import com.khazoda.basicstorage.Constants;
5+
import net.caffeinemc.mods.sodium.api.config.ConfigEntryPoint;
6+
import net.caffeinemc.mods.sodium.api.config.option.OptionBinding;
7+
import net.caffeinemc.mods.sodium.api.config.option.OptionImpact;
8+
import net.caffeinemc.mods.sodium.api.config.structure.ConfigBuilder;
9+
import net.minecraft.network.chat.Component;
10+
11+
public class BasicStorageSodiumIntegration implements ConfigEntryPoint {
12+
@Override
13+
public void registerConfigLate(ConfigBuilder builder) {
14+
var modOptions = builder.registerOwnModOptions()
15+
.setName("Basic Storage");
16+
17+
modOptions.addPage(builder.createOptionPage()
18+
.setName(Component.translatable("basicstorage.options.performance.title"))
19+
.addOption(builder.createBooleanOption(Constants.ID("show_crate_station_beams"))
20+
.setName(Component.translatable("basicstorage.options.performance.show_crate_station_beams"))
21+
.setTooltip(Component.translatable("basicstorage.options.performance.show_crate_station_beams.tooltip"))
22+
.setImpact(OptionImpact.MEDIUM)
23+
.setBinding(new OptionBinding<>() {
24+
@Override
25+
public void save(Boolean value) {
26+
BasicStorageClientConfig.INSTANCE.setShowCrateStationBeams(value);
27+
BasicStorageClientConfig.INSTANCE.save();
28+
}
29+
30+
@Override
31+
public Boolean load() {
32+
return BasicStorageClientConfig.INSTANCE.showCrateStationBeams();
33+
}
34+
})
35+
.setDefaultValue(true)
36+
.setStorageHandler(BasicStorageClientConfig.INSTANCE::save)));
37+
}
38+
}

src/client/java/com/khazoda/basicstorage/renderer/ParticleBeamRendering.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.khazoda.basicstorage.renderer;
22

3+
import com.khazoda.basicstorage.BasicStorageClientConfig;
34
import com.khazoda.basicstorage.block.entity.CrateBlockEntity;
45
import com.khazoda.basicstorage.packet.StationBeamPayload;
56
import com.khazoda.basicstorage.registry.ParticleRegistry;
@@ -281,6 +282,7 @@ public boolean tick() {
281282
}
282283

283284
public void spawnParticles(double startProgress, double endProgress) {
285+
if (!BasicStorageClientConfig.INSTANCE.showCrateStationBeams()) return;
284286
int startStep = (int) (totalSteps * startProgress);
285287
int endStep = (int) (totalSteps * endProgress);
286288

src/main/resources/assets/basicstorage/lang/en_us.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
"advancement.basicstorage.eye_for_organization.title": "An Eye for Organization",
2828
"advancement.basicstorage.eye_for_organization.desc": "Transform a Frame into a functional Crate Station",
2929
"advancement.basicstorage.nodal_networking.title": "Nodal Networking",
30-
"advancement.basicstorage.nodal_networking.desc": "Expand your Station's reach with Crate Connectors"
30+
"advancement.basicstorage.nodal_networking.desc": "Expand your Station's reach with Crate Connectors",
31+
"basicstorage.options.performance.title": "Performance",
32+
"basicstorage.options.performance.show_crate_station_beams": "Show crate station beams",
33+
"basicstorage.options.performance.show_crate_station_beams.tooltip": "Crate Stations show particle beams when distributing items. If you have many items being distributed, disabling this option may improve your performance."
3134
}

src/main/resources/fabric.mod.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
],
2525
"fabric-datagen": [
2626
"com.khazoda.basicstorage.datagen.BasicStorageDataGenerator"
27+
],
28+
"sodium:config_api_user": [
29+
"com.khazoda.basicstorage.integration.sodium.BasicStorageSodiumIntegration"
2730
]
2831
},
2932
"mixins": [

0 commit comments

Comments
 (0)