Preserve ingredient effects on registration and align AstraPlus dependency
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# AstraCauldron
|
||||
|
||||
Серверный мод котлов для **Minecraft 26.2 / NeoForge 26.2.0.79 / Java 25+**.
|
||||
Требуется **AstraPlus 0.9.3+**.
|
||||
Требуется **AstraPlus 0.9.9+**.
|
||||
Игроку достаточно ванильного клиента и актуального ресурспака AstraPlus/AstraPacks.
|
||||
Модели супа зарегистрированы через AstraPlus и берутся из JAR. Пользовательские замены
|
||||
можно положить в `astraplus/resources/assets/astradev_soups`; мод не переписывает их.
|
||||
|
||||
+2
-2
@@ -6,9 +6,9 @@ group = "online.astradev"
|
||||
version = "0.3.5"
|
||||
repositories { mavenCentral() }
|
||||
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")
|
||||
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.8.jar")
|
||||
.orElse("../AstraPlus/build/libs/AstraPlus-0.9.9.jar")
|
||||
dependencies {
|
||||
compileOnly(files(astraPlusApi))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||
|
||||
@@ -53,6 +53,13 @@ public final class SoupConfig {
|
||||
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 {
|
||||
SoupConfig config =
|
||||
Files.exists(file)
|
||||
|
||||
@@ -99,7 +99,9 @@ public final class SoupPots implements AutoCloseable {
|
||||
if (!id.matches("[a-z0-9_-]+") || player.getMainHandItem().isEmpty())
|
||||
throw new IllegalArgumentException("Нужны ID и предмет в руке");
|
||||
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
|
||||
// registration.
|
||||
var plus = AstraPlusApi.current().flatMap(api -> api.find(player.getMainHandItem()));
|
||||
@@ -109,9 +111,6 @@ public final class SoupPots implements AutoCloseable {
|
||||
SoupFiles.encode(
|
||||
Ingredients.normalizedCopy(player.getMainHandItem()),
|
||||
server.registryAccess());
|
||||
custom.nutrition = nutrition;
|
||||
custom.saturation = saturation;
|
||||
next.customIngredients.put(id, custom);
|
||||
var validated = new Ingredients(next, server.registryAccess());
|
||||
SoupFiles.write(configFile, SoupFiles.JSON.toJsonTree(next));
|
||||
config = next;
|
||||
|
||||
@@ -21,6 +21,6 @@ side="SERVER"
|
||||
[[dependencies.astracauldron]]
|
||||
modId="astraplus"
|
||||
type="required"
|
||||
versionRange="[0.9.3,0.10)"
|
||||
versionRange="[0.9.9,0.10)"
|
||||
ordering="AFTER"
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user