dacl dependency & translation support

This commit is contained in:
2025-11-07 17:46:57 +01:00
parent 76ed28afeb
commit 7f478b9ad6
8 changed files with 36 additions and 85 deletions

View File

@@ -12,9 +12,11 @@ base {
repositories { repositories {
maven { maven {
name = "Terraformers"
url = "https://maven.terraformersmc.com/" url = "https://maven.terraformersmc.com/"
} }
maven {
url = "https://maven.kasetoatz.com/"
}
} }
dependencies { dependencies {
@@ -24,8 +26,8 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation "com.kasetoatz:dumbassconfiglib:1.0" modCompileOnly "com.kasetoatz:dacl:${project.dacl_version}"
} }
processResources { processResources {
@@ -37,7 +39,8 @@ processResources {
filesMatching("fabric.mod.json") { filesMatching("fabric.mod.json") {
expand "version": project.version, expand "version": project.version,
"minecraft_version": project.minecraft_version, "minecraft_version": project.minecraft_version,
"loader_version": project.loader_version "loader_version": project.loader_version,
"dacl_version": project.dacl_version
} }
} }

View File

@@ -13,4 +13,5 @@ archives_base_name=fastghast
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # check this on https://modmuss50.me/fabric.html
fabric_version=0.136.0+1.21.10 fabric_version=0.136.0+1.21.10
modmenu_version=16.0.0-rc.1 modmenu_version=16.0.0-rc.1
dacl_version=1.1

View File

@@ -7,5 +7,3 @@ pluginManagement {
gradlePluginPortal() gradlePluginPortal()
} }
} }
includeBuild("../DumbassConfigLib")

View File

@@ -1,11 +1,8 @@
package com.kasetoatz.fastghast; package com.kasetoatz.fastghast;
import com.kasetoatz.dumbassconfig.DumbassConfig; import com.kasetoatz.dacl.DumbassConfig;
import com.kasetoatz.dumbassconfig.options.BoolOption; import com.kasetoatz.dacl.options.FloatOption;
import com.kasetoatz.dumbassconfig.options.FloatOption; import com.kasetoatz.dacl.options.validators.RangeValidator;
import com.kasetoatz.dumbassconfig.options.validators.RangeValidator;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.Leashable; import net.minecraft.entity.Leashable;
@@ -15,19 +12,18 @@ import net.minecraft.text.Text;
import java.util.EnumSet; import java.util.EnumSet;
import static com.kasetoatz.fastghast.config.Config.load; public class Fastghast implements ModInitializer
public class Fastghast implements ModInitializer, ModMenuApi
{ {
private final DumbassConfig config = DumbassConfig.builder(Text.of("TEST SCREEN")) public static final FloatOption UNMOUNTED_SPEED = new FloatOption(Text.translatable("fastghast.speed.unmounted"), "unmounted-speed", 0.05F, new RangeValidator<>(0.F, null));
.withOption(new BoolOption("Test Boolean Option", "test_bool_opt", false)) public static final FloatOption MOUNTED_SPEED = new FloatOption(Text.translatable("fastghast.speed.mounted"), "mounted-speed", 0.15F, new RangeValidator<>(0.F, null));
.withOption(new FloatOption("Test Float Option", "test_float_opt", 1.F, new RangeValidator<>(0.F, null))) public static final DumbassConfig CONFIG = DumbassConfig.builder(Text.translatable("fastghast.config.title"), "fastghast.json")
.withOption(UNMOUNTED_SPEED)
.withOption(MOUNTED_SPEED)
.build(); .build();
@Override @Override
public void onInitialize() public void onInitialize()
{ {
load();
ServerTickEvents.END_SERVER_TICK.register((server) -> server.getWorlds().forEach(world -> world.iterateEntities().forEach(entity -> { ServerTickEvents.END_SERVER_TICK.register((server) -> server.getWorlds().forEach(world -> world.iterateEntities().forEach(entity -> {
if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhastEntity ghast && leashed.getDistanceToCenter(ghast) > 8) if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhastEntity ghast && leashed.getDistanceToCenter(ghast) > 8)
{ {
@@ -35,10 +31,4 @@ public class Fastghast implements ModInitializer, ModMenuApi
} }
}))); })));
} }
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory()
{
return this.config::getUI;
}
} }

View File

@@ -1,62 +1,15 @@
package com.kasetoatz.fastghast.config; package com.kasetoatz.fastghast.config;
import com.google.gson.Gson; import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.google.gson.GsonBuilder; import com.terraformersmc.modmenu.api.ModMenuApi;
import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import java.io.IOException; import static com.kasetoatz.fastghast.Fastghast.CONFIG;
import java.nio.file.Files;
import java.nio.file.Path;
public class Config public class Config implements ModMenuApi
{ {
public static double UNMOUNTED_SPEED = 0.05; @Override
public static double MOUNTED_SPEED = 0.15; public ConfigScreenFactory<?> getModConfigScreenFactory()
private static final Path FILE = FabricLoader.getInstance().getConfigDir().resolve("fastghast.json");
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static void load() {
if (!Files.exists(FILE))
{
save();
return;
}
try
{
String json = Files.readString(FILE);
JsonObject data = GSON.fromJson(json, JsonObject.class);
if (data.has("unmounted-speed"))
{
UNMOUNTED_SPEED = data.get("unmounted-speed").getAsDouble();
}
if (data.has("mounted-speed"))
{
MOUNTED_SPEED = data.get("mounted-speed").getAsDouble();
}
save();
}
catch (IOException exc)
{
throw new CrashException(CrashReport.create(exc, "Loading config file."));
}
}
private static void save()
{ {
try return CONFIG::getUI;
{
JsonObject data = new JsonObject();
data.addProperty("unmounted-speed", UNMOUNTED_SPEED);
data.addProperty("mounted-speed", MOUNTED_SPEED);
Files.writeString(FILE, GSON.toJson(data));
}
catch (IOException exc)
{
throw new CrashException(CrashReport.create(exc, "Saving config file."));
}
} }
} }

View File

@@ -11,8 +11,8 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import static com.kasetoatz.fastghast.config.Config.MOUNTED_SPEED; import static com.kasetoatz.fastghast.Fastghast.MOUNTED_SPEED;
import static com.kasetoatz.fastghast.config.Config.UNMOUNTED_SPEED; import static com.kasetoatz.fastghast.Fastghast.UNMOUNTED_SPEED;
@Mixin(HappyGhastEntity.class) @Mixin(HappyGhastEntity.class)
public abstract class HappyGhastMixin public abstract class HappyGhastMixin
@@ -22,6 +22,6 @@ public abstract class HappyGhastMixin
@Redirect(method="travel", at=@At(value="INVOKE", target="Lnet/minecraft/entity/passive/HappyGhastEntity;getAttributeValue(Lnet/minecraft/registry/entry/RegistryEntry;)D")) @Redirect(method="travel", at=@At(value="INVOKE", target="Lnet/minecraft/entity/passive/HappyGhastEntity;getAttributeValue(Lnet/minecraft/registry/entry/RegistryEntry;)D"))
public double speed(HappyGhastEntity instance, RegistryEntry<EntityAttribute> registryEntry) public double speed(HappyGhastEntity instance, RegistryEntry<EntityAttribute> registryEntry)
{ {
return getControllingPassenger() instanceof PlayerEntity ? MOUNTED_SPEED : UNMOUNTED_SPEED; return getControllingPassenger() instanceof PlayerEntity ? MOUNTED_SPEED.getValue() : UNMOUNTED_SPEED.getValue();
} }
} }

View File

@@ -0,0 +1,5 @@
{
"fastghast.speed.unmounted": "Unmounted speed",
"fastghast.speed.mounted": "Mounted speed",
"fastghast.config.title": "FastGhast Config"
}

View File

@@ -19,7 +19,7 @@
"com.kasetoatz.fastghast.Fastghast" "com.kasetoatz.fastghast.Fastghast"
], ],
"modmenu": [ "modmenu": [
"com.kasetoatz.fastghast.Fastghast" "com.kasetoatz.fastghast.config.Config"
] ]
}, },
"mixins": [ "mixins": [
@@ -28,6 +28,7 @@
"depends": { "depends": {
"fabricloader": ">=${loader_version}", "fabricloader": ">=${loader_version}",
"fabric": "*", "fabric": "*",
"minecraft": "${minecraft_version}" "minecraft": "${minecraft_version}",
"dacl": ">=${dacl_version}"
} }
} }