Preserve ingredient effects on registration and align AstraPlus dependency

This commit is contained in:
2026-09-19 21:17:20 +03:00
parent cc085f82ba
commit f146e04180
6 changed files with 41 additions and 8 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# AstraCauldron # AstraCauldron
Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**. Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**.
Требуется **AstraPlus 0.9.3+**. Требуется **AstraPlus 0.9.9+**.
Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks. Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks.
Модели супа зарегистрированы через AstraPlus и берутся из JAR. Пользовательские замены Модели супа зарегистрированы через AstraPlus и берутся из JAR. Пользовательские замены
можно положить в `astraplus/resources/assets/astradev_soups`; мод не переписывает их. можно положить в `astraplus/resources/assets/astradev_soups`; мод не переписывает их.
+2 -2
View File
@@ -6,9 +6,9 @@ group = "online.astradev"
version = "0.3.5" version = "0.3.5"
repositories { mavenCentral() } repositories { mavenCentral() }
val astraPlusApi = providers.gradleProperty("astraPlusApi") val astraPlusApi = providers.gradleProperty("astraPlusApi")
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.8-api.jar") .orElse("../AstraPlus/build/libs/AstraPlus-0.9.9-api.jar")
val astraPlusRuntime = providers.gradleProperty("astraPlusRuntime") val astraPlusRuntime = providers.gradleProperty("astraPlusRuntime")
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.8.jar") .orElse("../AstraPlus/build/libs/AstraPlus-0.9.9.jar")
dependencies { dependencies {
compileOnly(files(astraPlusApi)) compileOnly(files(astraPlusApi))
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4") testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
@@ -53,6 +53,13 @@ public final class SoupConfig {
public int amplifier; public int amplifier;
} }
Custom updateIngredient(String id, int nutrition, float saturation) {
var ingredient = customIngredients.computeIfAbsent(id, ignored -> new Custom());
ingredient.nutrition = nutrition;
ingredient.saturation = saturation;
return ingredient;
}
public static SoupConfig load(Path file) throws IOException { public static SoupConfig load(Path file) throws IOException {
SoupConfig config = SoupConfig config =
Files.exists(file) Files.exists(file)
@@ -99,7 +99,9 @@ public final class SoupPots implements AutoCloseable {
if (!id.matches("[a-z0-9_-]+") || player.getMainHandItem().isEmpty()) if (!id.matches("[a-z0-9_-]+") || player.getMainHandItem().isEmpty())
throw new IllegalArgumentException("Нужны ID и предмет в руке"); throw new IllegalArgumentException("Нужны ID и предмет в руке");
var next = SoupFiles.JSON.fromJson(SoupFiles.JSON.toJson(config), SoupConfig.class); var next = SoupFiles.JSON.fromJson(SoupFiles.JSON.toJson(config), SoupConfig.class);
var custom = new SoupConfig.Custom(); var custom = next.updateIngredient(id, nutrition, saturation);
custom.item = null;
custom.astraPlusId = null;
// Resolve by stable AstraPlus identity; definitions can evolve without invalidating the // Resolve by stable AstraPlus identity; definitions can evolve without invalidating the
// registration. // registration.
var plus = AstraPlusApi.current().flatMap(api -> api.find(player.getMainHandItem())); var plus = AstraPlusApi.current().flatMap(api -> api.find(player.getMainHandItem()));
@@ -109,9 +111,6 @@ public final class SoupPots implements AutoCloseable {
SoupFiles.encode( SoupFiles.encode(
Ingredients.normalizedCopy(player.getMainHandItem()), Ingredients.normalizedCopy(player.getMainHandItem()),
server.registryAccess()); server.registryAccess());
custom.nutrition = nutrition;
custom.saturation = saturation;
next.customIngredients.put(id, custom);
var validated = new Ingredients(next, server.registryAccess()); var validated = new Ingredients(next, server.registryAccess());
SoupFiles.write(configFile, SoupFiles.JSON.toJsonTree(next)); SoupFiles.write(configFile, SoupFiles.JSON.toJsonTree(next));
config = next; config = next;
@@ -21,6 +21,6 @@ side="SERVER"
[[dependencies.astracauldron]] [[dependencies.astracauldron]]
modId="astraplus" modId="astraplus"
type="required" type="required"
versionRange="[0.9.3,0.10)" versionRange="[0.9.9,0.10)"
ordering="AFTER" ordering="AFTER"
side="SERVER" side="SERVER"
@@ -0,0 +1,27 @@
package online.astradev.cauldron;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class IngredientUpdateTest {
@Test
void nutritionUpdatePreservesConfiguredColorAndEffects() {
var config = new SoupConfig();
var original = config.updateIngredient("herb", 2, .5f);
original.color = "#70AA40";
var effect = new SoupConfig.Effect();
effect.type = "minecraft:regeneration";
effect.duration = 100;
original.effects.add(effect);
var updated = config.updateIngredient("herb", 5, .8f);
assertSame(original, updated);
assertEquals(5, updated.nutrition);
assertEquals(.8f, updated.saturation);
assertEquals("#70AA40", updated.color);
assertEquals(1, updated.effects.size());
assertSame(effect, updated.effects.getFirst());
}
}