Tint soup item contents with the blended recipe color

This commit is contained in:
2026-09-06 11:45:41 +03:00
parent 1f08010db6
commit 2687e4d47c
13 changed files with 209 additions and 35 deletions
+25
View File
@@ -0,0 +1,25 @@
import com.google.gson.JsonParser;
import com.mojang.serialization.JsonOps;
import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.renderer.item.ItemModels;
import net.minecraft.client.color.item.ItemTintSources;
import net.minecraft.client.resources.model.cuboid.CuboidModel;
import java.nio.file.*;
// Run with the Minecraft 26.2 client and its libraries on the classpath.
class CheckSoupModels {
public static void main(String[] args) throws Exception {
ItemModels.bootstrap();
ItemTintSources.bootstrap();
Path assets = Path.of(args[0]);
try (var reader = Files.newBufferedReader(assets.resolve("items/combined_soup.json"))) {
ClientItem item = ClientItem.CODEC.parse(JsonOps.INSTANCE, JsonParser.parseReader(reader)).getOrThrow();
System.out.println("PASS: Minecraft 26.2 decodes composite bowl and custom model color tint: " + item.model());
}
try (var reader = Files.newBufferedReader(assets.resolve("models/item/soup_liquid.json"))) {
CuboidModel model = CuboidModel.fromStream(reader);
if (model.geometry() == null || model.transforms() == null) throw new AssertionError("Missing geometry/transforms");
System.out.println("PASS: Minecraft 26.2 decodes liquid geometry and item display transforms");
}
}
}
+19
View File
@@ -0,0 +1,19 @@
param([string]$MinecraftDirectory = "$env:APPDATA/.minecraft")
$ErrorActionPreference = 'Stop'
$repo = Split-Path $PSScriptRoot -Parent
$version = Get-Content -Raw -LiteralPath "$MinecraftDirectory/versions/26.2/26.2.json" | ConvertFrom-Json
$classpath = @("$MinecraftDirectory/versions/26.2/26.2.jar") + @(
$version.libraries | Where-Object { $_.downloads.artifact.path } | ForEach-Object {
"$MinecraftDirectory/libraries/" + $_.downloads.artifact.path
} | Where-Object { Test-Path -LiteralPath $_ }
)
New-Item -ItemType Directory -Force -Path "$repo/build" | Out-Null
$arguments = @(
'--class-path', ('"' + (($classpath -join ';').Replace('\', '/')) + '"'),
('"' + "$PSScriptRoot/CheckSoupModels.java".Replace('\', '/') + '"'),
('"' + "$repo/src/main/resources/astra-itemsadder/astradev_soups/resourcepack/assets/astradev_soups".Replace('\', '/') + '"')
)
$argumentFile = "$repo/build/check-models.args"
Set-Content -Encoding utf8 -LiteralPath $argumentFile -Value $arguments
& java "@$argumentFile"
if ($LASTEXITCODE -ne 0) { throw 'Minecraft model validation failed' }
+34 -2
View File
@@ -37,9 +37,20 @@ public final class SoupSmokeTest extends JavaPlugin {
private Block pot;
@Override public void onEnable() {
Bukkit.getScheduler().runTaskLater(this, () -> {
new org.bukkit.scheduler.BukkitRunnable() {
int attempts;
@Override public void run() {
String phase = Files.exists(getDataFolder().toPath().resolve("phase1.txt")) ? "phase2" : "phase1";
try {
if (phase.equals("phase1")) {
var ia = Bukkit.getPluginManager().getPlugin("ItemsAdder");
var api = Class.forName("dev.lone.itemsadder.api.ItemsAdder", true, ia.getClass().getClassLoader());
if (!(boolean) api.getMethod("areItemsLoaded").invoke(null)
|| !Files.exists(Path.of("plugins/ItemsAdder/output/generated.zip"))) {
if (++attempts < 180) return;
throw new IllegalStateException("ItemsAdder pack did not become ready");
}
}
setup();
if (phase.equals("phase1")) first(); else second();
results.add("PASS: ALL " + results.size() + " CHECKS (" + phase + ")");
@@ -50,8 +61,10 @@ public final class SoupSmokeTest extends JavaPlugin {
try { Files.createDirectories(getDataFolder().toPath()); Files.write(getDataFolder().toPath().resolve(phase + ".txt"), results); }
catch (Exception e) { throw new RuntimeException(e); }
results.forEach(getLogger()::info);
cancel();
Bukkit.shutdown();
}, 40);
}
}.runTaskTimer(this, 40, 20);
}
private void setup() {
@@ -117,11 +130,27 @@ public final class SoupSmokeTest extends JavaPlugin {
for (Material material : List.of(Material.MUSHROOM_STEW, Material.RABBIT_STEW, Material.BEETROOT_SOUP, Material.SUSPICIOUS_STEW)) {
ItemStack stack = item(material); Ingredients.normalize(stack);
check(stack.getMaxStackSize() == 16, "Vanilla soup stack size: " + material);
check(!stack.hasData(DataComponentTypes.CUSTOM_MODEL_DATA), "Vanilla soup keeps its original icon: " + material);
}
ItemStack soup = ingredients.brew(Arrays.asList(recipe()));
check(soup.getData(DataComponentTypes.FOOD).nutrition() == 10, "Example combines 10 hunger points");
check(Math.abs(soup.getData(DataComponentTypes.FOOD).saturation() - 13.2f) < .001, "Example combines 13.2 saturation points");
check(soup.getMaxStackSize() == 16, "Combined soup stacks to sixteen");
check(soup.getData(DataComponentTypes.ITEM_MODEL).asString().equals("astradev_soups:combined_soup"), "Combined soup selects the bundled colored bowl model");
ItemStack legacyIcon = soup.clone();
legacyIcon.resetData(DataComponentTypes.ITEM_MODEL);
legacyIcon.unsetData(DataComponentTypes.CUSTOM_MODEL_DATA);
check(Ingredients.normalize(legacyIcon) && legacyIcon.isSimilar(soup), "Old soup icon migrates while retaining all recipe components");
check(!Ingredients.normalize(legacyIcon), "Icon migration is idempotent");
ItemStack extendedData = soup.clone();
extendedData.setData(DataComponentTypes.CUSTOM_MODEL_DATA,
io.papermc.paper.datacomponent.item.CustomModelData.customModelData()
.addFloat(42).addFlag(true).addString("keep").addColor(Color.BLACK).addColor(Color.BLUE).build());
Ingredients.normalize(extendedData);
var retained = extendedData.getData(DataComponentTypes.CUSTOM_MODEL_DATA);
check(retained.floats().equals(List.of(42f)) && retained.flags().equals(List.of(true))
&& retained.strings().equals(List.of("keep")) && retained.colors().get(1).equals(Color.BLUE),
"Icon migration preserves unrelated custom model data slots");
var plain = net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText();
List<String> lore = soup.lore().stream().map(plain::serialize).toList();
check(lore.stream().anyMatch(s -> s.contains(" II (1:30)")) && lore.stream().anyMatch(s -> s.contains(" I (8:00)")), "Potion levels use Roman numerals with parenthesized durations");
@@ -135,11 +164,14 @@ public final class SoupSmokeTest extends JavaPlugin {
ItemStack colorExample = ingredients.brew(List.of(item(Material.SPIDER_EYE), item(Material.GOLDEN_APPLE), purple, green));
NamespacedKey colorKey = new NamespacedKey(plugin, "soup_color");
check(colorExample.getItemMeta().getPersistentDataContainer().get(colorKey, org.bukkit.persistence.PersistentDataType.INTEGER) == 0x9D7965, "Red eye, golden apple, purple and green potions blend into exact brown RGB");
check(colorExample.getData(DataComponentTypes.CUSTOM_MODEL_DATA).colors().getFirst().asRGB() == 0x9D7965, "Bowl liquid tint uses exactly the cauldron mixed RGB");
ItemStack redSoup = ingredients.brew(Collections.nCopies(4, item(Material.APPLE)));
ItemStack orangeSoup = ingredients.brew(Collections.nCopies(4, item(Material.CARROT)));
check(!redSoup.getItemMeta().getPersistentDataContainer().get(colorKey, org.bukkit.persistence.PersistentDataType.INTEGER)
.equals(orangeSoup.getItemMeta().getPersistentDataContainer().get(colorKey, org.bukkit.persistence.PersistentDataType.INTEGER)), "Different food colors produce different soup colors");
check(ingredients.read(redSoup).color().asRGB() == 0xC73735, "Reusing a combined soup preserves its stored liquid color");
check(!redSoup.getData(DataComponentTypes.CUSTOM_MODEL_DATA).colors()
.equals(orangeSoup.getData(DataComponentTypes.CUSTOM_MODEL_DATA).colors()), "Different mixtures have different icon tints");
List<ItemStack> reversed = new ArrayList<>(Arrays.asList(recipe())); Collections.reverse(reversed);
check(ingredients.brew(reversed).isSimilar(soup), "Same recipe stacks regardless of ingredient insertion order");
check(effects(soup).stream().anyMatch(e -> e.getType().equals(PotionEffectType.NIGHT_VISION) && e.getDuration() == 9600 && e.getAmplifier() == 0), "Extended night vision preserved");