Skip to content

Commit 3413949

Browse files
authored
Fix recipe viewer displays (GregTechCEu#3134)
1 parent a8b6bd1 commit 3413949

37 files changed

+277
-266
lines changed

gradle/scripts/repositories.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repositories {
44

55
maven { // KubeJS and Rhino
66
name = "Saps.dev Maven"
7-
url = "https://maven.saps.dev/releases/"
7+
url = "https://maven.latvian.dev/releases/"
88
}
99

1010
maven { // JEI

src/generated/resources/assets/gtceu/lang/en_ud.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,14 +3307,6 @@
33073307
"gtceu.ownership.name.ftb": "sɯɐǝ⟘ ᗺ⟘Ⅎ",
33083308
"gtceu.ownership.name.player": "ɹǝʎɐןԀ",
33093309
"gtceu.recipe.amperage": "%s :ǝbɐɹǝdɯⱯ",
3310-
"gtceu.recipe.category.arc_furnace_recycling": "buıddɐɹɔS ɐɯsɐןԀ",
3311-
"gtceu.recipe.category.chem_dyes": "buıǝʎᗡ ןɐɔıɯǝɥƆ",
3312-
"gtceu.recipe.category.extractor_recycling": "buıʇןǝɯǝᴚ dɐɹɔS",
3313-
"gtceu.recipe.category.ingot_molding": "buıpןoW ןɐʇǝW",
3314-
"gtceu.recipe.category.macerator_recycling": "buıpuıɹ⅁ ʇɹɐԀ",
3315-
"gtceu.recipe.category.ore_bathing": "buıʇɐǝɹ⟘ ǝɹO",
3316-
"gtceu.recipe.category.ore_crushing": "buıpuıɹ⅁ ǝɹO",
3317-
"gtceu.recipe.category.ore_forging": "buıɥsnɹƆ ǝɹO",
33183310
"gtceu.recipe.chance": "ɹǝıʇ/%s+ %s :ǝɔuɐɥƆ",
33193311
"gtceu.recipe.cleanroom": "%s sǝɹınbǝᴚ",
33203312
"gtceu.recipe.cleanroom.display_name": "ɯooɹuɐǝןƆ",
@@ -5363,6 +5355,14 @@
53635355
"recipe.condition.rock_breaker.tooltip": "punoɹɐ sʞɔoןq pınןℲ",
53645356
"recipe.condition.steam_vent.tooltip": "ʇuǝʌ ɯɐǝʇs uɐǝןƆ",
53655357
"recipe.condition.thunder.tooltip": "%d :ןǝʌǝꞀ ɹǝpunɥ⟘",
5358+
"recipe_category.gtceu.arc_furnace_recycling": "buıddɐɹɔS ɐɯsɐןԀ",
5359+
"recipe_category.gtceu.chem_dyes": "buıǝʎᗡ ןɐɔıɯǝɥƆ",
5360+
"recipe_category.gtceu.extractor_recycling": "buıʇןǝɯǝᴚ dɐɹɔS",
5361+
"recipe_category.gtceu.ingot_molding": "buıpןoW ןɐʇǝW",
5362+
"recipe_category.gtceu.macerator_recycling": "buıpuıɹ⅁ ʇɹɐԀ",
5363+
"recipe_category.gtceu.ore_bathing": "buıʇɐǝɹ⟘ ǝɹO",
5364+
"recipe_category.gtceu.ore_crushing": "buıpuıɹ⅁ ǝɹO",
5365+
"recipe_category.gtceu.ore_forging": "buıɥsnɹƆ ǝɹO",
53665366
"recipe_type.gtceu.air_scrubber": "ɹǝqqnɹɔS ɹıⱯ",
53675367
"recipe_type.gtceu.alloy_blast_smelter": "ɹǝʇןǝɯS ʇsɐןᗺ ʎoןןⱯ",
53685368
"recipe_type.gtceu.alloy_smelter": "ɹǝʇןǝɯS ʎoןןⱯ",

src/generated/resources/assets/gtceu/lang/en_us.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,14 +3307,6 @@
33073307
"gtceu.ownership.name.ftb": "FTB Teams",
33083308
"gtceu.ownership.name.player": "Player",
33093309
"gtceu.recipe.amperage": "Amperage: %s",
3310-
"gtceu.recipe.category.arc_furnace_recycling": "Plasma Scrapping",
3311-
"gtceu.recipe.category.chem_dyes": "Chemical Dyeing",
3312-
"gtceu.recipe.category.extractor_recycling": "Scrap Remelting",
3313-
"gtceu.recipe.category.ingot_molding": "Metal Molding",
3314-
"gtceu.recipe.category.macerator_recycling": "Part Grinding",
3315-
"gtceu.recipe.category.ore_bathing": "Ore Treating",
3316-
"gtceu.recipe.category.ore_crushing": "Ore Grinding",
3317-
"gtceu.recipe.category.ore_forging": "Ore Crushing",
33183310
"gtceu.recipe.chance": "Chance: %s +%s/tier",
33193311
"gtceu.recipe.cleanroom": "Requires %s",
33203312
"gtceu.recipe.cleanroom.display_name": "Cleanroom",
@@ -5363,6 +5355,14 @@
53635355
"recipe.condition.rock_breaker.tooltip": "Fluid blocks around",
53645356
"recipe.condition.steam_vent.tooltip": "Clean steam vent",
53655357
"recipe.condition.thunder.tooltip": "Thunder Level: %d",
5358+
"recipe_category.gtceu.arc_furnace_recycling": "Plasma Scrapping",
5359+
"recipe_category.gtceu.chem_dyes": "Chemical Dyeing",
5360+
"recipe_category.gtceu.extractor_recycling": "Scrap Remelting",
5361+
"recipe_category.gtceu.ingot_molding": "Metal Molding",
5362+
"recipe_category.gtceu.macerator_recycling": "Part Grinding",
5363+
"recipe_category.gtceu.ore_bathing": "Ore Treating",
5364+
"recipe_category.gtceu.ore_crushing": "Ore Grinding",
5365+
"recipe_category.gtceu.ore_forging": "Ore Crushing",
53665366
"recipe_type.gtceu.air_scrubber": "Air Scrubber",
53675367
"recipe_type.gtceu.alloy_blast_smelter": "Alloy Blast Smelter",
53685368
"recipe_type.gtceu.alloy_smelter": "Alloy Smelter",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"values": [
3+
"gtceu:matches",
4+
"gtceu:matchbox",
5+
"gtceu:invar_lighter",
6+
"gtceu:platinum_lighter"
7+
]
8+
}

src/main/java/com/gregtechceu/gtceu/GTCEu.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.neoforged.neoforge.data.loading.DatagenModLoader;
2323
import net.neoforged.neoforge.server.ServerLifecycleHooks;
2424

25+
import com.mojang.serialization.Codec;
2526
import dev.emi.emi.config.EmiConfig;
2627
import me.shedaniel.rei.api.client.REIRuntime;
2728
import org.apache.logging.log4j.LogManager;
@@ -36,6 +37,10 @@ public class GTCEu {
3637

3738
public static final String MOD_ID = "gtceu";
3839
private static final ResourceLocation TEMPLATE_LOCATION = ResourceLocation.fromNamespaceAndPath(MOD_ID, "");
40+
public static final Codec<ResourceLocation> GTCEU_ID = Codec.STRING.comapFlatMap(
41+
str -> ResourceLocation.read(appendIdString(str)),
42+
s -> s.getNamespace().equals(MOD_ID) ? s.getPath() : s.toString());
43+
3944
public static final String NAME = "GTCEu";
4045
public static final Logger LOGGER = LogManager.getLogger(NAME);
4146

src/main/java/com/gregtechceu/gtceu/api/capability/recipe/ItemRecipeCapability.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.gregtechceu.gtceu.api.capability.recipe;
22

3+
import com.gregtechceu.gtceu.GTCEu;
34
import com.gregtechceu.gtceu.api.GTValues;
45
import com.gregtechceu.gtceu.api.gui.widget.SlotWidget;
56
import com.gregtechceu.gtceu.api.material.ChemicalHelper;
@@ -549,20 +550,14 @@ public void applyWidgetInfo(@NotNull Widget widget,
549550
// Maps ingredients to an ItemEntryList for XEI: either an ItemTagList or an ItemStackList
550551
private static ItemEntryList mapItem(final SizedIngredient ingredient) {
551552
if (ingredient.getContainedCustom() instanceof IntProviderIngredient intProvider) {
552-
final int amount = 1;
553-
var mapped = tryMapInner(intProvider.getInner(), amount);
553+
var mapped = tryMapInner(intProvider.getInner(), 1);
554554
if (mapped != null) return mapped;
555555
} else if (ingredient.getContainedCustom() instanceof IntersectionIngredient intersection) {
556556
return mapIntersection(intersection, ingredient.count());
557-
} else {
558-
var tagList = tryMapTag(ingredient.ingredient(), 1);
557+
} else if (!ingredient.ingredient().isCustom()) {
558+
var tagList = tryMapTag(ingredient.ingredient(), ingredient.count());
559559
if (tagList != null) return tagList;
560560
}
561-
if (ingredient instanceof SizedIngredient sizedIngredient) {
562-
final int amount = sizedIngredient.hashCode();
563-
var mapped = tryMapInner(sizedIngredient.ingredient(), amount);
564-
if (mapped != null) return mapped;
565-
}
566561
ItemStackList stackList = new ItemStackList();
567562
boolean isIntProvider = ingredient.getContainedCustom() instanceof IntProviderIngredient;
568563

@@ -573,10 +568,25 @@ private static ItemEntryList mapItem(final SizedIngredient ingredient) {
573568
return stackList;
574569
}
575570

576-
private static @Nullable ItemEntryList tryMapInner(final Ingredient inner, int amount) {
577-
if (inner.getCustomIngredient() instanceof IntersectionIngredient intersection)
578-
return mapIntersection(intersection, amount);
579-
return tryMapTag(inner, amount);
571+
@SuppressWarnings("SameParameterValue")
572+
private static @Nullable ItemEntryList tryMapInner(final Ingredient inner, int count) {
573+
if (inner.getCustomIngredient() instanceof IntProviderIngredient intProvider) {
574+
var mapped = tryMapInner(intProvider.getInner(), 1);
575+
if (mapped != null) return mapped;
576+
} else if (inner.getCustomIngredient() instanceof IntersectionIngredient intersection) {
577+
return mapIntersection(intersection, count);
578+
} else if (!inner.isCustom()) {
579+
var tagList = tryMapTag(inner, count);
580+
if (tagList != null) return tagList;
581+
}
582+
ItemStackList stackList = new ItemStackList();
583+
boolean isIntProvider = inner.getCustomIngredient() instanceof IntProviderIngredient;
584+
585+
UnaryOperator<ItemStack> setCount = stack -> isIntProvider ? stack.copyWithCount(1) : stack;
586+
Arrays.stream(inner.getItems())
587+
.map(setCount)
588+
.forEach(stackList::add);
589+
return stackList;
580590
}
581591

582592
// Map intersection ingredients to the items inside, as recipe viewers don't support them.
@@ -596,6 +606,11 @@ private static ItemEntryList mapIntersection(final IntersectionIngredient inters
596606
}
597607

598608
private static @Nullable ItemTagList tryMapTag(final Ingredient ingredient, int amount) {
609+
if (ingredient.isCustom()) {
610+
GTCEu.LOGGER.error("tried to map unexpected ingredient type {}", ingredient.getCustomIngredient());
611+
return null;
612+
}
613+
599614
var values = ingredient.getValues();
600615
if (values.length > 0 && values[0] instanceof Ingredient.TagValue(TagKey<Item> tag)) {
601616
return ItemTagList.of(tag, amount, DataComponentPatch.EMPTY);

src/main/java/com/gregtechceu/gtceu/api/capability/recipe/RecipeCapability.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.gregtechceu.gtceu.api.capability.recipe;
22

3+
import com.gregtechceu.gtceu.GTCEu;
34
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
45
import com.gregtechceu.gtceu.api.recipe.content.Content;
56
import com.gregtechceu.gtceu.api.recipe.content.ContentModifier;
@@ -13,13 +14,15 @@
1314
import com.lowdragmc.lowdraglib.gui.widget.Widget;
1415
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
1516

17+
import net.minecraft.core.Holder;
1618
import net.minecraft.core.HolderLookup;
1719
import net.minecraft.nbt.Tag;
1820
import net.minecraft.network.RegistryFriendlyByteBuf;
1921
import net.minecraft.network.chat.Component;
2022
import net.neoforged.neoforge.network.connection.ConnectionType;
2123

2224
import com.mojang.serialization.Codec;
25+
import com.mojang.serialization.DataResult;
2326
import com.mojang.serialization.codecs.DispatchedMapCodec;
2427
import io.netty.buffer.Unpooled;
2528
import it.unimi.dsi.fastutil.objects.Object2IntMap;
@@ -36,11 +39,20 @@
3639
*/
3740
public abstract class RecipeCapability<T> {
3841

39-
public static final Codec<RecipeCapability<?>> DIRECT_CODEC = GTRegistries.RECIPE_CAPABILITIES.byNameCodec();
42+
// spotless:off
43+
public static final Codec<RecipeCapability<?>> DIRECT_CODEC = GTCEu.GTCEU_ID
44+
.comapFlatMap(
45+
id -> GTRegistries.RECIPE_CAPABILITIES.getHolder(id)
46+
.map(DataResult::success)
47+
.orElseGet(() -> DataResult.error(() -> "Unknown registry key in " + GTRegistries.RECIPE_CAPABILITY_REGISTRY + ": " + id)),
48+
(Holder.Reference<RecipeCapability<?>> holder) -> holder.key().location()
49+
)
50+
.flatComapMap(Holder.Reference::value, cap -> safeReference(GTRegistries.RECIPE_CAPABILITIES.wrapAsHolder(cap)));
4051
public static final Codec<Map<RecipeCapability<?>, List<Content>>> CODEC = new DispatchedMapCodec<>(
4152
RecipeCapability.DIRECT_CODEC,
4253
RecipeCapability::contentCodec);
4354
public static final Comparator<RecipeCapability<?>> COMPARATOR = Comparator.comparingInt(o -> o.sortIndex);
55+
// spotless:on
4456

4557
public final String name;
4658
public final int color;
@@ -231,4 +243,10 @@ public Object2IntMap<T> makeChanceCache() {
231243
public boolean isTickSlot(int index, IO io, GTRecipe recipe) {
232244
return index >= (io == IO.IN ? recipe.getInputContents(this) : recipe.getOutputContents(this)).size();
233245
}
246+
247+
private static DataResult<Holder.Reference<RecipeCapability<?>>> safeReference(Holder<RecipeCapability<?>> value) {
248+
return value.getDelegate() instanceof Holder.Reference<RecipeCapability<?>> reference ?
249+
DataResult.success(reference) : DataResult.error(
250+
() -> "Unregistered holder in " + GTRegistries.RECIPE_CAPABILITY_REGISTRY + ": " + value);
251+
}
234252
}

src/main/java/com/gregtechceu/gtceu/api/fluid/FluidBuilder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import net.minecraft.sounds.SoundEvents;
1818
import net.minecraft.world.item.Items;
1919
import net.minecraft.world.level.material.Fluid;
20+
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions;
2021
import net.neoforged.neoforge.client.extensions.common.RegisterClientExtensionsEvent;
2122
import net.neoforged.neoforge.common.SoundActions;
2223
import net.neoforged.neoforge.fluids.FluidStack;
@@ -294,15 +295,26 @@ private static int convertViscosity(double viscosity) {
294295
.blockstate((ctx, prov) -> prov
295296
.simpleBlock(ctx.getEntry(), prov.models().getBuilder(this.name)
296297
.texture("particle", this.still)))
298+
.color(() -> () -> (state, level, pos, index) -> {
299+
return IClientFluidTypeExtensions.of(state.getFluidState())
300+
.getTintColor(state.getFluidState(), level, pos);
301+
})
297302
.register();
298-
} else builder.noBlock();
303+
} else {
304+
// noinspection DataFlowIssue
305+
builder.noBlock().fluidProperties(p -> p.block(null));
306+
}
299307
if (this.hasBucket) {
300308
builder.bucket((fluid, properties) -> new GTBucketItem(fluid, properties, material, langKey))
301309
.properties(p -> p.craftRemainder(Items.BUCKET).stacksTo(1))
302310
.setData(ProviderType.LANG, NonNullBiConsumer.noop())
303311
.setData(ProviderType.ITEM_MODEL, NonNullBiConsumer.noop())
312+
.color(() -> () -> GTBucketItem::color)
304313
.register();
305-
} else builder.noBucket();
314+
} else {
315+
// noinspection DataFlowIssue
316+
builder.noBucket().fluidProperties(p -> p.bucket(null));
317+
}
306318

307319
builder.onRegister(fluid -> {
308320
if (fluid.getSource() instanceof GTFluid gtSource) attributes.forEach(gtSource::addAttribute);

src/main/java/com/gregtechceu/gtceu/api/recipe/category/GTRecipeCategory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public GTRecipeCategory(@NotNull GTRecipeType recipeType) {
4141
this.recipeType = recipeType;
4242
this.name = recipeType.registryName.getPath();
4343
this.registryKey = recipeType.registryName;
44-
this.languageKey = recipeType.registryName.toLanguageKey();
44+
this.languageKey = recipeType.getTranslationKey();
4545
}
4646

4747
public GTRecipeCategory(@NotNull String categoryName, @NotNull GTRecipeType recipeType) {
4848
this.recipeType = recipeType;
4949
this.name = categoryName;
5050
this.registryKey = GTCEu.id(categoryName);
51-
this.languageKey = "%s.recipe.category.%s".formatted(GTCEu.MOD_ID, categoryName);
51+
this.languageKey = "recipe_category.%s.%s".formatted(GTCEu.MOD_ID, categoryName);
5252
}
5353

5454
public static GTRecipeCategory registerDefault(@NotNull GTRecipeType recipeType) {

src/main/java/com/gregtechceu/gtceu/client/forge/ForgeClientEventListener.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.gregtechceu.gtceu.GTCEu;
44
import com.gregtechceu.gtceu.api.GTValues;
5+
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
6+
import com.gregtechceu.gtceu.api.recipe.kind.GTRecipe;
7+
import com.gregtechceu.gtceu.api.registry.GTRegistries;
58
import com.gregtechceu.gtceu.client.EnvironmentalHazardClientHandler;
69
import com.gregtechceu.gtceu.client.renderer.BlockHighlightRenderer;
710
import com.gregtechceu.gtceu.client.renderer.MultiblockInWorldPreviewRenderer;
@@ -11,8 +14,10 @@
1114
import com.gregtechceu.gtceu.integration.map.ClientCacheManager;
1215

1316
import net.minecraft.client.gui.Gui;
17+
import net.minecraft.world.item.crafting.RecipeManager;
1418
import net.neoforged.api.distmarker.Dist;
1519
import net.neoforged.api.distmarker.OnlyIn;
20+
import net.neoforged.bus.api.EventPriority;
1621
import net.neoforged.bus.api.SubscribeEvent;
1722
import net.neoforged.fml.common.EventBusSubscriber;
1823
import net.neoforged.neoforge.client.event.*;
@@ -68,4 +73,15 @@ public static void registerClientCommand(RegisterClientCommandsEvent event) {
6873
public static void serverStopped(ServerStoppedEvent event) {
6974
ClientCacheManager.clearCaches();
7075
}
76+
77+
@SubscribeEvent(priority = EventPriority.HIGHEST)
78+
public static void recipesSynced(RecipesUpdatedEvent event) {
79+
RecipeManager manager = event.getRecipeManager();
80+
for (var category : GTRegistries.RECIPE_CATEGORIES) {
81+
GTRecipeType type = category.getRecipeType();
82+
for (GTRecipe recipe : type.getRecipesInCategory(category)) {
83+
manager.byKey(recipe.id).ifPresent(holder -> recipe.setId(holder.id()));
84+
}
85+
}
86+
}
7187
}

0 commit comments

Comments
 (0)