Add submerged whirlpool brewing, four servings and mixed soup colors

This commit is contained in:
2026-09-05 15:11:52 +03:00
parent 0801c08e99
commit 6c03e62761
14 changed files with 397 additions and 118 deletions
@@ -26,7 +26,7 @@ import java.util.*;
public final class Ingredients {
public record Ingredient(int nutrition, float saturation, List<ConsumeEffect> effects, Set<String> tags, Color color) {}
private record Custom(String id, ItemStack sample, int nutrition, float saturation, List<PotionEffect> effects) {}
private record Custom(String id, ItemStack sample, int nutrition, float saturation, List<PotionEffect> effects, Color color) {}
private final AstraSoupsPlugin plugin;
private final List<Custom> custom = new ArrayList<>();
private List<String> blocked;
@@ -36,6 +36,12 @@ public final class Ingredients {
public Ingredients(AstraSoupsPlugin plugin) {
this.plugin = plugin;
double seconds = plugin.getConfig().getDouble("brew-seconds", 4.0);
if (!Double.isFinite(seconds) || seconds < .5 || seconds > 60) {
throw new IllegalArgumentException("brew-seconds должно быть от 0.5 до 60");
}
int servings = plugin.getConfig().getInt("servings-per-brew", 4);
if (servings < 1 || servings > 16) throw new IllegalArgumentException("servings-per-brew должно быть от 1 до 16");
defaultColor = Color.fromRGB(Integer.parseInt(plugin.getConfig().getString("default-color", "#B77A36").replace("#", ""), 16));
blocked = plugin.getConfig().getStringList("blocked-ingredients");
for (Object value : plugin.getConfig().getList("incompatible", List.of())) {
@@ -68,7 +74,8 @@ public final class Ingredients {
effects.add(new PotionEffect(type, duration, amplifier));
}
normalize(sample);
custom.add(new Custom(id, sample.asOne(), nutrition, saturation, List.copyOf(effects)));
Color customColor = c.isString("color") ? Color.fromRGB(Integer.parseInt(c.getString("color").replace("#", ""), 16)) : null;
custom.add(new Custom(id, sample.asOne(), nutrition, saturation, List.copyOf(effects), customColor));
}
if (plugin.getServer().getPluginManager().isPluginEnabled("ItemsAdder")) {
try {
@@ -95,7 +102,8 @@ public final class Ingredients {
List<ConsumeEffect> effects = new ArrayList<>();
Consumable consumable = item.getData(DataComponentTypes.CONSUMABLE);
if (consumable != null) effects.addAll(consumable.consumeEffects());
Color color = defaultColor;
Color color = IngredientColors.food(item.getType(), defaultColor);
if (isCombined(item)) color = Color.fromRGB(meta.getPersistentDataContainer().getOrDefault(plugin.colorKey, PersistentDataType.INTEGER, defaultColor.asRGB()));
if (potion && meta instanceof PotionMeta pm) {
if (!pm.getAllEffects().isEmpty()) effects.add(ConsumeEffect.applyStatusEffects(pm.getAllEffects(), 1));
color = pm.computeEffectiveColor();
@@ -111,6 +119,7 @@ public final class Ingredients {
saturation = match.saturation;
tags.add("custom:" + match.id.toLowerCase(Locale.ROOT));
if (!match.effects.isEmpty()) effects.add(ConsumeEffect.applyStatusEffects(match.effects, 1));
if (match.color != null) color = match.color;
}
if (iaLookup != null) try {
Object ia = iaLookup.invoke(null, item);
@@ -150,24 +159,9 @@ public final class Ingredients {
List<ConsumeEffect> effects = ingredients.stream().flatMap(i -> i.effects.stream()).toList();
ItemStack soup = new ItemStack(Material.MUSHROOM_STEW);
ItemMeta meta = soup.getItemMeta();
meta.displayName(Component.text(plugin.getConfig().getString("soup-name", "Комбинированный суп"), NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, false));
List<Component> lore = new ArrayList<>();
lore.add(line("Голод: +" + nutrition, NamedTextColor.YELLOW));
lore.add(line(String.format(Locale.ROOT, "Насыщение: +%.1f", saturation), NamedTextColor.GOLD));
for (ConsumeEffect effect : effects) {
if (effect instanceof ConsumeEffect.ApplyStatusEffects apply) {
for (PotionEffect pe : apply.effects()) {
String duration = pe.isInfinite() ? "∞" : (pe.getDuration() / 1200) + ":" + String.format(Locale.ROOT, "%02d", (pe.getDuration() / 20) % 60);
lore.add(Component.translatable(pe.getType().translationKey()).color(NamedTextColor.AQUA)
.append(Component.text(" " + (pe.getAmplifier() + 1) + " • " + duration
+ (apply.probability() < 1 ? " • " + Math.round(apply.probability() * 100) + "%" : "")))
.decoration(TextDecoration.ITALIC, false));
}
} else lore.add(line(effect instanceof ConsumeEffect.TeleportRandomly ? "Случайная телепортация"
: effect instanceof ConsumeEffect.ClearAllStatusEffects ? "Снятие всех эффектов"
: effect instanceof ConsumeEffect.RemoveStatusEffects ? "Снятие эффектов" : "Звук при употреблении", NamedTextColor.GRAY));
}
meta.lore(lore);
meta.displayName(Component.text(plugin.getConfig().getString("soup-name", "Комбинированный суп"),
net.kyori.adventure.text.format.TextColor.color(color(ingredients).asRGB())).decoration(TextDecoration.ITALIC, false));
meta.lore(soupLore(nutrition, saturation, effects));
meta.getPersistentDataContainer().set(plugin.soupKey, PersistentDataType.BYTE, (byte) 1);
meta.getPersistentDataContainer().set(plugin.colorKey, PersistentDataType.INTEGER, color(ingredients).asRGB());
soup.setItemMeta(meta);
@@ -178,7 +172,27 @@ public final class Ingredients {
return soup;
}
private Component line(String s, NamedTextColor color) { return Component.text(s, color).decoration(TextDecoration.ITALIC, false); }
private static List<Component> soupLore(int nutrition, float saturation, List<ConsumeEffect> effects) {
List<Component> lore = new ArrayList<>();
lore.add(line("Голод: +" + nutrition, NamedTextColor.YELLOW));
lore.add(line(String.format(Locale.ROOT, "Насыщение: +%.1f", saturation), NamedTextColor.GOLD));
for (ConsumeEffect effect : effects) {
if (effect instanceof ConsumeEffect.ApplyStatusEffects apply) {
for (PotionEffect pe : apply.effects()) {
String duration = pe.isInfinite() ? "∞" : (pe.getDuration() / 1200) + ":" + String.format(Locale.ROOT, "%02d", (pe.getDuration() / 20) % 60);
lore.add(Component.translatable(pe.getType().translationKey()).color(NamedTextColor.AQUA)
.append(Component.text(" " + SoupText.roman(pe.getAmplifier() + 1) + " (" + duration + ")"
+ (apply.probability() < 1 ? " " + Math.round(apply.probability() * 100) + "%" : "")))
.decoration(TextDecoration.ITALIC, false));
}
} else lore.add(line(effect instanceof ConsumeEffect.TeleportRandomly ? "Случайная телепортация"
: effect instanceof ConsumeEffect.ClearAllStatusEffects ? "Снятие всех эффектов"
: effect instanceof ConsumeEffect.RemoveStatusEffects ? "Снятие эффектов" : "Звук при употреблении", NamedTextColor.GRAY));
}
return lore;
}
private static Component line(String s, NamedTextColor color) { return Component.text(s, color).decoration(TextDecoration.ITALIC, false); }
private Color color(List<Ingredient> ingredients) {
return Color.fromRGB((int) ingredients.stream().mapToInt(i -> i.color.getRed()).average().orElse(183),
(int) ingredients.stream().mapToInt(i -> i.color.getGreen()).average().orElse(122),
@@ -189,11 +203,20 @@ public final class Ingredients {
}
public static boolean normalize(ItemStack item) {
if (item == null) return false;
if (switch (item.getType()) { case MUSHROOM_STEW, RABBIT_STEW, BEETROOT_SOUP, SUSPICIOUS_STEW -> true; default -> false; }
&& !Objects.equals(item.getData(DataComponentTypes.MAX_STACK_SIZE), 16)) {
if (!switch (item.getType()) { case MUSHROOM_STEW, RABBIT_STEW, BEETROOT_SOUP, SUSPICIOUS_STEW -> true; default -> false; }) return false;
boolean changed = false;
if (!Objects.equals(item.getData(DataComponentTypes.MAX_STACK_SIZE), 16)) {
item.setData(DataComponentTypes.MAX_STACK_SIZE, 16);
return true;
changed = true;
}
return false;
ItemMeta meta = item.getItemMeta();
FoodProperties food = item.getData(DataComponentTypes.FOOD);
Consumable consumable = item.getData(DataComponentTypes.CONSUMABLE);
if (meta.getPersistentDataContainer().has(new NamespacedKey("astrasoups", "combined_soup"), PersistentDataType.BYTE)
&& food != null && consumable != null) {
List<Component> lore = soupLore(food.nutrition(), food.saturation(), consumable.consumeEffects());
if (!Objects.equals(meta.lore(), lore)) { meta.lore(lore); item.setItemMeta(meta); changed = true; }
}
return changed;
}
}