mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 11:15:23 -05:00
add utility methods to unification helper for replacing tags to items
This commit is contained in:
parent
c9995bdabd
commit
5065b1a35e
3 changed files with 41 additions and 6 deletions
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning].
|
|||
- added support for custom ingredient types
|
||||
- added support for NeoForge compound ingredients
|
||||
- added API endpoint for registering custom ingredient unifiers
|
||||
- added unification helper methods to convert tags to items
|
||||
- fixed recipe viewer integration endpoints for Fabric
|
||||
- fixed unnecessary memory usage for debug handler
|
||||
- fixed Mekanism recipe unifier using wrong recipe keys
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.almostreliable.unified.api.unification.recipe;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
import com.almostreliable.unified.api.constant.RecipeConstants;
|
||||
import com.almostreliable.unified.api.unification.TagSubstitutions;
|
||||
|
@ -226,6 +228,27 @@ public interface UnificationHelper {
|
|||
*/
|
||||
boolean unifyOutputTag(JsonObject jsonObject, boolean tagsToItems);
|
||||
|
||||
/**
|
||||
* Handles the tag to item replacement.
|
||||
*
|
||||
* @param jsonObject the {@link JsonObject} to unify containing the tag
|
||||
* @param tag the tag to replace with the target item
|
||||
* @return true if the tag was changed, false otherwise
|
||||
* @since 1.2.0
|
||||
*/
|
||||
boolean handleTagToItemReplacement(JsonObject jsonObject, TagKey<Item> tag);
|
||||
|
||||
/**
|
||||
* Handles the tag to item replacement.
|
||||
*
|
||||
* @param jsonObject the {@link JsonObject} to unify containing the tag
|
||||
* @param key the key the item should be stored under
|
||||
* @param tag the tag to replace with the target item
|
||||
* @return true if the tag was changed, false otherwise
|
||||
* @since 1.2.0
|
||||
*/
|
||||
boolean handleTagToItemReplacement(JsonObject jsonObject, String key, TagKey<Item> tag);
|
||||
|
||||
/**
|
||||
* Unifies a {@link JsonObject} as an item output.<br>
|
||||
* The item will be converted to the target item of the tag if possible.
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.almostreliable.unified.unification.recipe;
|
|||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
import com.almostreliable.unified.api.AlmostUnified;
|
||||
import com.almostreliable.unified.api.constant.RecipeConstants;
|
||||
|
@ -196,12 +197,7 @@ public record UnificationHelperImpl(
|
|||
var tag = TagKey.create(Registries.ITEM, ResourceLocation.parse(jsonPrimitive.getAsString()));
|
||||
|
||||
if (tagsToItems) {
|
||||
var entry = getUnificationLookup.getTagTargetItem(tag);
|
||||
if (entry == null) return false;
|
||||
|
||||
jsonObject.remove(RecipeConstants.TAG);
|
||||
jsonObject.addProperty(RecipeConstants.ITEM, entry.id().toString());
|
||||
return true;
|
||||
return handleTagToItemReplacement(jsonObject, tag);
|
||||
}
|
||||
|
||||
var substituteTag = AlmostUnified.INSTANCE.getRuntimeOrThrow().getTagSubstitutions().getSubstituteTag(tag);
|
||||
|
@ -211,6 +207,21 @@ public record UnificationHelperImpl(
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleTagToItemReplacement(JsonObject jsonObject, TagKey<Item> tag) {
|
||||
return handleTagToItemReplacement(jsonObject, RecipeConstants.ITEM, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleTagToItemReplacement(JsonObject jsonObject, String key, TagKey<Item> tag) {
|
||||
var entry = getUnificationLookup.getTagTargetItem(tag);
|
||||
if (entry == null) return false;
|
||||
|
||||
jsonObject.remove(RecipeConstants.TAG);
|
||||
jsonObject.addProperty(key, entry.id().toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unifyOutputItem(JsonObject jsonObject) {
|
||||
boolean changed = unifyOutputItem(jsonObject, RecipeConstants.ITEM);
|
||||
|
|
Loading…
Reference in a new issue