Add config
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -46,5 +46,5 @@ jobs:
|
|||||||
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
|
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: starminerrecrafted-fabric-${{ steps.ref.outputs.branch }}
|
name: dust-fabric-${{ steps.ref.outputs.branch }}
|
||||||
path: build/libs/*[0-9].jar
|
path: build/libs/*[0-9].jar
|
||||||
30
build.gradle
30
build.gradle
@@ -11,6 +11,27 @@ version = project.mod_version
|
|||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = "Modrinth"
|
||||||
|
url = "https://api.modrinth.com/maven"
|
||||||
|
content {
|
||||||
|
includeGroup "maven.modrinth"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url = "https://maven.shedaniel.me/"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url = "https://maven.terraformersmc.com"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = 'minelp'
|
||||||
|
url = 'https://repo.minelittlepony-mod.com/maven/snapshot'
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = 'minelp-release'
|
||||||
|
url = 'https://repo.minelittlepony-mod.com/maven/release'
|
||||||
|
}
|
||||||
// Add repositories to retrieve artifacts from in here.
|
// Add repositories to retrieve artifacts from in here.
|
||||||
// You should only use this when depending on other mods because
|
// You should only use this when depending on other mods because
|
||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||||
@@ -26,6 +47,15 @@ dependencies {
|
|||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}") {
|
||||||
|
exclude(group: "net.fabricmc.fabric-api")
|
||||||
|
}
|
||||||
|
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
|
modApi "com.minelittlepony:kirin:${project.kirin_version}"
|
||||||
|
include "com.minelittlepony:kirin:${project.kirin_version}"
|
||||||
|
|
||||||
|
//modImplementation "com.minelittlepony:minelittlepony:${project.minelp_version}"
|
||||||
|
modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|||||||
@@ -14,3 +14,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.46.4+1.18
|
fabric_version=0.46.4+1.18
|
||||||
|
clothconfig_version = 6.1.48
|
||||||
|
modmenu_version = 3.0.1
|
||||||
|
minelp_version=4.4.0-beta.2
|
||||||
|
kirin_version=1.10.0-beta.2
|
||||||
|
|||||||
@@ -1,22 +1,60 @@
|
|||||||
package net.fabricmc.example;
|
package net.fabricmc.example;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import com.minelittlepony.common.util.GamePaths;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class ExampleMod implements ModInitializer {
|
public class Dust implements ClientModInitializer {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("modid");
|
public static final Logger LOGGER = LoggerFactory.getLogger("dust");
|
||||||
|
|
||||||
|
private static Dust instance;
|
||||||
|
|
||||||
|
public static Dust getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dust() {
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DustConfig config;
|
||||||
|
|
||||||
|
public DustConfig getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitializeClient() {
|
||||||
ClientTickEvents.START_CLIENT_TICK.register((client) -> {
|
Path dustFolder = GamePaths.getConfigDirectory().resolve("dust");
|
||||||
if(!client.isPaused()){
|
config = new DustConfig(dustFolder.resolve("userconfig.json"), this);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
ClientTickEvents.END_CLIENT_TICK.register(this::createDust);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRandomNumberUsingInts(int min, int max) {
|
||||||
|
Random random = new Random();
|
||||||
|
return random.ints(min, max)
|
||||||
|
.findFirst()
|
||||||
|
.getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double lerp(double min, double max, double val) {
|
||||||
|
return 1 - ((val - min) / (max - min));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createDust(MinecraftClient client) {
|
||||||
|
if (getConfig().getDustEnabled()) {
|
||||||
|
if (!client.isPaused()) {
|
||||||
if (client.world != null) {
|
if (client.world != null) {
|
||||||
World world = client.world;
|
World world = client.world;
|
||||||
if (!client.player.clientWorld.isSkyVisible(client.player.getBlockPos())) {
|
if (!client.player.clientWorld.isSkyVisible(client.player.getBlockPos())) {
|
||||||
@@ -33,16 +71,6 @@ public class ExampleMod implements ModInitializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int getRandomNumberUsingInts(int min, int max) {
|
|
||||||
Random random = new Random();
|
|
||||||
return random.ints(min,max)
|
|
||||||
.findFirst()
|
|
||||||
.getAsInt();
|
|
||||||
}
|
|
||||||
public static double lerp(double min, double max, double val) {
|
|
||||||
return 1 - ((val - min) / (max - min));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
38
src/main/java/net/fabricmc/example/DustConfig.java
Normal file
38
src/main/java/net/fabricmc/example/DustConfig.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package net.fabricmc.example;
|
||||||
|
|
||||||
|
import net.fabricmc.example.utils.JsonFile;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
public class DustConfig extends JsonFile {
|
||||||
|
private transient final Dust dust;
|
||||||
|
private Vector dimensions;
|
||||||
|
private boolean dustEnabled = true;
|
||||||
|
|
||||||
|
public DustConfig(Path file, Dust dust) {
|
||||||
|
super(file);
|
||||||
|
|
||||||
|
this.dust = dust;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector setDimensions(){
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector getDimensions(){
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean toggleDust(){
|
||||||
|
dustEnabled = !dustEnabled;
|
||||||
|
save();
|
||||||
|
return dustEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDustEnabled(){
|
||||||
|
return dustEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/main/java/net/fabricmc/example/DustModMenuFactory.java
Normal file
11
src/main/java/net/fabricmc/example/DustModMenuFactory.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package net.fabricmc.example;
|
||||||
|
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
|
||||||
|
public class DustModMenuFactory implements ModMenuApi {
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return ModMenuScreen::new;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/main/java/net/fabricmc/example/ModMenuScreen.java
Normal file
41
src/main/java/net/fabricmc/example/ModMenuScreen.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package net.fabricmc.example;
|
||||||
|
|
||||||
|
import com.minelittlepony.common.client.gui.GameGui;
|
||||||
|
import com.minelittlepony.common.client.gui.element.*;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class ModMenuScreen extends GameGui {
|
||||||
|
public ModMenuScreen(@Nullable Screen parent) {
|
||||||
|
super(new TranslatableText("menu.dust.title"), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
int left = width / 2 - 100;
|
||||||
|
int row = height / 4 + 14;
|
||||||
|
|
||||||
|
DustConfig config = Dust.getInstance().getConfig();
|
||||||
|
|
||||||
|
addButton(new Label(width / 2, 30)).setCentered().getStyle()
|
||||||
|
.setText(getTitle());
|
||||||
|
|
||||||
|
addButton(new Button(left, row += 24).onClick(sender -> {
|
||||||
|
sender.getStyle().setText("menu.dust.global." + config.toggleDust());
|
||||||
|
})).getStyle()
|
||||||
|
.setText("menu.dust.global." + config.getDustEnabled());
|
||||||
|
|
||||||
|
addButton(new Button(left, row += 34)
|
||||||
|
.onClick(sender -> finish())).getStyle()
|
||||||
|
.setText("gui.done");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
renderBackground(matrices);
|
||||||
|
super.render(matrices, mouseX, mouseY, partialTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
src/main/java/net/fabricmc/example/utils/JsonFile.java
Normal file
54
src/main/java/net/fabricmc/example/utils/JsonFile.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package net.fabricmc.example.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.InstanceCreator;
|
||||||
|
import net.fabricmc.example.Dust;
|
||||||
|
|
||||||
|
public class JsonFile {
|
||||||
|
protected transient final Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(getClass(), (InstanceCreator<JsonFile>)t -> this)
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
|
||||||
|
private transient Path file;
|
||||||
|
|
||||||
|
JsonFile() { }
|
||||||
|
|
||||||
|
public JsonFile(Path file) {
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void load() {
|
||||||
|
if (Files.isReadable(file)) {
|
||||||
|
try (Reader reader = Files.newBufferedReader(file)) {
|
||||||
|
load(reader);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Dust.LOGGER.error("Invalid config", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void load(Reader reader) {
|
||||||
|
gson.fromJson(reader, getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void save() {
|
||||||
|
try {
|
||||||
|
Files.createDirectories(file.getParent());
|
||||||
|
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
|
||||||
|
gson.toJson(this, writer);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
src/main/resources/assets/modid/lang/en_us.json
Normal file
5
src/main/resources/assets/modid/lang/en_us.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"menu.dust.title": "Dust",
|
||||||
|
"menu.dust.global.false": "Dust: disabled",
|
||||||
|
"menu.dust.global.true": "Dust: enabled"
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
"LizIsTired"
|
"LizIsTired"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://github.com/LizIsTired/dust",
|
"issues": "https://github.com/LizIsTired/dust/issues",
|
||||||
"sources": "https://github.com/LizIsTired/dust"
|
"sources": "https://github.com/LizIsTired/dust"
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -18,8 +18,11 @@
|
|||||||
|
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"client": [
|
||||||
"net.fabricmc.example.ExampleMod"
|
"net.fabricmc.example.Dust"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"net.fabricmc.example.DustModMenuFactory"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -30,6 +33,14 @@
|
|||||||
"java": ">=17"
|
"java": ">=17"
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
"another-mod": "*"
|
"clothconfig": ">=6.1.48",
|
||||||
|
"modmenu": ">=3.0.1"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"modmenu": {
|
||||||
|
"links": {
|
||||||
|
"modmenu.discord": "https://discord.gg/AgBfPFMJgX"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user