Skip to content

Commit 3dbc624

Browse files
authored
Merge branch '1.21.1' into optimize-load
2 parents 8dd052c + 09c6b98 commit 3dbc624

File tree

10 files changed

+74
-29
lines changed

10 files changed

+74
-29
lines changed

CHANGELOG.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog],
6-
and this project adheres to [Semantic Versioning].
7-
85
## Unreleased
96
- /
107

8+
## [1.2.2] - 2024-10-23
9+
10+
- fixed crash on empty recipe JSONs
11+
12+
## [1.2.1] - 2024-10-22
13+
14+
- added logging for cases where items are assigned to multiple unification tags
15+
- added logging for cases where the recipe type can't be found
16+
- added skipping logic for recipes with invalid recipe types
17+
- added Turkish translation ([#102](https://github.com/AlmostReliable/almostunified/pull/102))
18+
- fixed crash when runtime isn't loaded ([#101](https://github.com/AlmostReliable/almostunified/issues/101))
19+
- fixed newly created custom tags not being considered for unification
20+
- fixed runtime not being available when items are assigned to multiple unification tags
21+
1122
## [1.2.0] - 2024-10-06
1223

1324
- added support for custom ingredient types
@@ -32,11 +43,9 @@ and this project adheres to [Semantic Versioning].
3243

3344
Initial 1.21.1 port.
3445

35-
<!-- Links -->
36-
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
37-
[semantic versioning]: https://semver.org/spec/v2.0.0.html
38-
3946
<!-- Versions -->
47+
[1.2.2]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.21.1-1.2.2
48+
[1.2.1]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.21.1-1.2.1
4049
[1.2.0]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.21.1-1.2.0
4150
[1.1.0]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.21.1-1.1.0
4251
[1.0.0]: https://github.com/AlmostReliable/almostunified/releases/tag/v1.21.1-1.0.0

Common/src/main/java/com/almostreliable/unified/AlmostUnifiedCommon.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public static void onRecipeManagerReload(Map<ResourceLocation, JsonElement> reci
4646
}
4747

4848
public static void onRecipeManagerError(ResourceLocation recipe) {
49-
assert RUNTIME != null;
49+
if (RUNTIME == null) return;
5050
RUNTIME.getDebugHandler().collectRecipeError(recipe);
5151
}
5252

5353
public static void onRecipeManagerEnd() {
54-
assert RUNTIME != null;
54+
if (RUNTIME == null) return;
5555
RUNTIME.getDebugHandler().finish();
5656
}
5757
}

Common/src/main/java/com/almostreliable/unified/core/AlmostUnifiedRuntimeImpl.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,21 @@ public static AlmostUnifiedRuntimeImpl create(VanillaTagWrapper<Item> itemTags,
7676
var tagConfig = Config.load(TagConfig.NAME, TagConfig.SERIALIZER);
7777
var unificationConfigs = UnificationConfig.safeLoadConfigs();
7878

79-
var unificationTags = bakeAndValidateTags(
80-
unificationConfigs,
81-
itemTags,
82-
placeholderConfig,
83-
debugConfig.shouldLogInvalidTags()
84-
);
79+
TagReloadHandler.applyCustomTags(tagConfig.getCustomTags(), itemTags);
8580

8681
CustomIngredientUnifierRegistry ingredientUnifierRegistry = new CustomIngredientUnifierRegistryImpl();
8782
PluginManager.instance().registerCustomIngredientUnifiers(ingredientUnifierRegistry);
8883
RecipeUnifierRegistry recipeUnifierRegistry = new RecipeUnifierRegistryImpl();
8984
PluginManager.instance().registerRecipeUnifiers(recipeUnifierRegistry);
9085
// TODO: add plugin support for registering config defaults
9186

92-
TagReloadHandler.applyCustomTags(tagConfig.getCustomTags(), itemTags);
87+
var unificationTags = bakeAndValidateTags(
88+
unificationConfigs,
89+
itemTags,
90+
placeholderConfig,
91+
debugConfig.shouldLogInvalidTags()
92+
);
93+
9394
TagSubstitutionsImpl tagSubstitutions = TagSubstitutionsImpl.create(
9495
itemTags::has,
9596
unificationTags::contains,

Common/src/main/java/com/almostreliable/unified/unification/UnificationLookupImpl.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.world.item.ItemStack;
88
import net.minecraft.world.item.crafting.Ingredient;
99

10+
import com.almostreliable.unified.AlmostUnifiedCommon;
1011
import com.almostreliable.unified.api.unification.ModPriorities;
1112
import com.almostreliable.unified.api.unification.StoneVariants;
1213
import com.almostreliable.unified.api.unification.TagSubstitutions;
@@ -117,15 +118,22 @@ public boolean isUnifiedIngredientItem(Ingredient ingredient, ItemStack item) {
117118

118119
public static class Builder {
119120

120-
private final Set<UnificationEntry<Item>> createdEntries = new HashSet<>();
121+
private final Map<UnificationEntry<Item>, TagKey<Item>> entriesToTags = new HashMap<>();
121122
private final Map<TagKey<Item>, Set<UnificationEntry<Item>>> tagsToEntries = new HashMap<>();
122123

123124
private void put(TagKey<Item> tag, UnificationEntry<Item> entry) {
124-
if (createdEntries.contains(entry)) {
125-
throw new IllegalStateException("entry " + entry + " already created");
125+
if (entriesToTags.containsKey(entry)) {
126+
var boundTag = entriesToTags.get(entry);
127+
AlmostUnifiedCommon.LOGGER.error(
128+
"Unification entry for item '{}' with tag '#{}' is already part of tag '#{}'.",
129+
entry.id(),
130+
tag.location(),
131+
boundTag.location()
132+
);
133+
return;
126134
}
127135

128-
createdEntries.add(entry);
136+
entriesToTags.put(entry, tag);
129137
tagsToEntries.computeIfAbsent(tag, $ -> new HashSet<>()).add(entry);
130138
}
131139

Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeJsonImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public ResourceLocation getType() {
2828
try {
2929
return ResourceLocation.parse(json.get("type").getAsString());
3030
} catch (Exception e) {
31-
throw new IllegalArgumentException("could not detect recipe type");
31+
throw new IllegalArgumentException("could not detect recipe type for recipe " + id);
3232
}
3333
}
3434

Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeLink.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.resources.ResourceLocation;
44

5+
import com.almostreliable.unified.AlmostUnifiedCommon;
56
import com.almostreliable.unified.api.unification.recipe.RecipeData;
67
import com.almostreliable.unified.utils.JsonCompare;
78

@@ -17,7 +18,7 @@
1718
import java.util.Set;
1819
import java.util.stream.Collectors;
1920

20-
public class RecipeLink implements RecipeData {
21+
public final class RecipeLink implements RecipeData {
2122
/**
2223
* This cache is an optimization to avoid creating many ResourceLocations for just a few different types.
2324
* Having fewer ResourceLocation instances can greatly speed up equality checking when these are used as map keys.
@@ -30,15 +31,30 @@ public class RecipeLink implements RecipeData {
3031
@Nullable private DuplicateLink duplicateLink;
3132
@Nullable private JsonObject unifiedRecipe;
3233

33-
public RecipeLink(ResourceLocation id, JsonObject originalRecipe) {
34+
private RecipeLink(ResourceLocation id, JsonObject originalRecipe, ResourceLocation type) {
3435
this.id = id;
3536
this.originalRecipe = originalRecipe;
37+
this.type = type;
38+
}
39+
40+
@Nullable
41+
public static RecipeLink of(ResourceLocation id, JsonObject originalRecipe) {
42+
try {
43+
ResourceLocation type = ResourceLocation.parse(originalRecipe.get("type").getAsString());
44+
return new RecipeLink(id, originalRecipe, type);
45+
} catch (Exception e) {
46+
AlmostUnifiedCommon.LOGGER.warn("Could not detect recipe type for recipe '{}', skipping.", id);
47+
return null;
48+
}
49+
}
3650

51+
public static RecipeLink ofOrThrow(ResourceLocation id, JsonObject originalRecipe) {
3752
try {
3853
String typeString = originalRecipe.get("type").getAsString();
39-
this.type = PARSED_TYPE_CACHE.computeIfAbsent(typeString, ResourceLocation::parse);
54+
ResourceLocation type = PARSED_TYPE_CACHE.computeIfAbsent(typeString, ResourceLocation::parse);
55+
return new RecipeLink(id, originalRecipe, type);
4056
} catch (Exception e) {
41-
throw new IllegalArgumentException("could not detect recipe type");
57+
throw new IllegalArgumentException("could not detect recipe type for recipe " + id);
4258
}
4359
}
4460

Common/src/main/java/com/almostreliable/unified/unification/recipe/RecipeTransformer.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.LinkedHashSet;
3232
import java.util.List;
3333
import java.util.Map;
34+
import java.util.Objects;
3435
import java.util.Set;
3536
import java.util.function.Consumer;
3637
import java.util.stream.Collectors;
@@ -111,7 +112,9 @@ public Map<ResourceLocation, List<RecipeLink>> groupRecipesByType(Map<ResourceLo
111112
return recipes
112113
.entrySet()
113114
.stream()
114-
.map(entry -> new RecipeLink(entry.getKey(), entry.getValue().getAsJsonObject()))
115+
.filter(entry -> entry.getValue() instanceof JsonObject jsonObject && !jsonObject.isEmpty())
116+
.map(entry -> RecipeLink.of(entry.getKey(), entry.getValue().getAsJsonObject()))
117+
.filter(Objects::nonNull)
115118
.sorted(Comparator.comparing(entry -> entry.getId().toString()))
116119
.collect(Collectors.groupingByConcurrent(RecipeLink::getType));
117120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"almostunified.description": "Almost Unified tarafından değiştirildi!",
3+
"almostunified.warning": "Tarif sorunlarını orijinal sahibine bildirmeyin.",
4+
"almostunified.unified": "Birleştirilmiş",
5+
"almostunified.duplicate": "Kopyaları Vardı",
6+
"almostunified.yes": "Evet",
7+
"almostunified.no": "Hayır"
8+
}

Common/src/test/java/testmod/TestUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ public Set<TagKey<Item>> getReplacedTags() {
8383

8484
public static RecipeLink recipe(String jsonStr) {
8585
var json = json(jsonStr);
86-
return new RecipeLink(ResourceLocation.parse("test"), json);
86+
return RecipeLink.ofOrThrow(ResourceLocation.parse("test"), json);
8787
}
8888

8989
public static RecipeLink recipe(JsonObject json) {
90-
return new RecipeLink(ResourceLocation.parse("test"), json);
90+
return RecipeLink.ofOrThrow(ResourceLocation.parse("test"), json);
9191
}
9292

9393
public static JsonObject json(String json) {

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enableAccessWidener = false
88
minecraftVersion = 1.21.1
99

1010
# Mod
11-
modVersion = 1.2.0
11+
modVersion = 1.2.2
1212
modPackage = com.almostreliable.unified
1313
modId = almostunified
1414
modName = AlmostUnified

0 commit comments

Comments
 (0)