Fix return value of Recipe#isIncomplete being inaccurate for empty tags (#8549)

This commit is contained in:
Sara Freimer authored and GitHub committed 2022-04-04 18:10:41 -07:00
1 parent 56976e4d20
commit 954db14250
4 files changed
+38 -1

No files matched your search

@@ -13,3 +13,12 @@
}
}
@@ -55,7 +_,7 @@
default boolean m_142505_() {
NonNullList<Ingredient> nonnulllist = this.m_7527_();
return nonnulllist.isEmpty() || nonnulllist.stream().anyMatch((p_151268_) -> {
- return p_151268_.m_43908_().length == 0;
+ return net.minecraftforge.common.ForgeHooks.hasNoElements(p_151268_);
});
}
}
@@ -43,6 +43,15 @@
static NonNullList<Ingredient> m_44202_(String[] p_44203_, Map<String, Ingredient> p_44204_, int p_44205_, int p_44206_) {
NonNullList<Ingredient> nonnulllist = NonNullList.m_122780_(p_44205_ * p_44206_, Ingredient.f_43901_);
Set<String> set = Sets.newHashSet(p_44204_.keySet());
@@ -180,7 +_,7 @@
return nonnulllist.isEmpty() || nonnulllist.stream().filter((p_151277_) -> {
return !p_151277_.m_43947_();
}).anyMatch((p_151273_) -> {
- return p_151273_.m_43908_().length == 0;
+ return net.minecraftforge.common.ForgeHooks.hasNoElements(p_151273_);
});
}
@@ -202,15 +_,15 @@
static String[] m_44196_(JsonArray p_44197_) {
@@ -1,6 +1,11 @@
--- a/net/minecraft/world/item/crafting/UpgradeRecipe.java
+++ b/net/minecraft/world/item/crafting/UpgradeRecipe.java
@@ -72,7 +_,7 @@
@@ -68,11 +_,11 @@
public boolean m_142505_() {
return Stream.of(this.f_44518_, this.f_44519_).anyMatch((p_151284_) -> {
- return p_151284_.m_43908_().length == 0;
+ return net.minecraftforge.common.ForgeHooks.hasNoElements(p_151284_);
});
}
@@ -58,6 +58,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.gameevent.GameEvent;
@@ -1093,6 +1094,19 @@ public class ForgeHooks
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
}
public static boolean hasNoElements(Ingredient ingredient)
{
ItemStack[] items = ingredient.getItems();
if (items.length == 0) return true;
if (items.length == 1 && !ForgeConfig.SERVER.treatEmptyTagsAsAir.get())
{
//If we potentially added a barrier due to the ingredient being an empty tag, try and check if it is the stack we added
ItemStack item = items[0];
return item.getItem() == Items.BARRIER && item.getHoverName() instanceof TextComponent hoverName && hoverName.getText().startsWith("Empty Tag: ");
}
return false;
}
public static <T> void deserializeTagAdditions(List<Tag.Entry> list, JsonObject json, List<Tag.BuilderEntry> allList)
{
if (json.has("remove"))