From af54e8ecf368a4aa94badad52be72a8e045bf012 Mon Sep 17 00:00:00 2001
From: simibubi <31564874+simibubi@users.noreply.github.com>
Date: Sun, 11 Aug 2024 16:54:51 +0200
Subject: [PATCH] Fix-ups from testing III
- Fixed hidden and invalid items being added to creative mode search tab
- Fixed In-ItemGroup item attribute not working properly
---
src/main/java/com/simibubi/create/Create.java | 5 +-
.../logistics/filter/ItemAttribute.java | 50 ++++++++++++++++---
2 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java
index d539a32de..963301a5e 100644
--- a/src/main/java/com/simibubi/create/Create.java
+++ b/src/main/java/com/simibubi/create/Create.java
@@ -39,8 +39,10 @@ import com.simibubi.create.infrastructure.data.CreateDatagen;
import com.simibubi.create.infrastructure.worldgen.AllFeatures;
import com.simibubi.create.infrastructure.worldgen.AllPlacementModifiers;
+import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
+import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.ForgeMod;
@@ -74,7 +76,8 @@ public class Create {
* Other mods should not use this field! If you are an addon developer, create your own instance of
* {@link CreateRegistrate}.
*/
- public static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID);
+ public static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID)
+ .defaultCreativeTab((ResourceKey) null);
static {
REGISTRATE.setTooltipModifierFactory(item -> {
diff --git a/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java
index bdb1a442f..d33b89bd5 100644
--- a/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java
+++ b/src/main/java/com/simibubi/create/content/logistics/filter/ItemAttribute.java
@@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.AllRecipeTypes;
+import com.simibubi.create.Create;
import com.simibubi.create.content.kinetics.fan.processing.AllFanProcessingTypes;
import com.simibubi.create.content.logistics.filter.attribute.BookAuthorAttribute;
import com.simibubi.create.content.logistics.filter.attribute.BookCopyAttribute;
@@ -36,20 +37,20 @@ import net.minecraft.world.Container;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BlockItem;
+import net.minecraft.world.item.CreativeModeTab;
+import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
-import net.minecraft.world.item.CreativeModeTab;
-import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
-import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.CreativeModeTabRegistry;
+import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.forgespi.language.IModInfo;
@@ -286,17 +287,50 @@ public interface ItemAttribute {
this.group = group;
}
+ @Override
+ public boolean appliesTo(ItemStack stack, Level world) {
+ if (group == null)
+ return false;
+
+ if (group.getDisplayItems()
+ .isEmpty()
+ && group.getSearchTabDisplayItems()
+ .isEmpty()) {
+
+ try {
+ group.buildContents(new CreativeModeTab.ItemDisplayParameters(world.enabledFeatures(), false,
+ world.registryAccess()));
+ } catch (RuntimeException | LinkageError e) {
+ Create.LOGGER.error("Attribute Filter: Item Group crashed while building contents.",
+ group.getDisplayName()
+ .getString(),
+ e);
+ group = null;
+ return false;
+ }
+
+ }
+
+ return tabContainsItem(group, stack);
+ }
+
@Override
public boolean appliesTo(ItemStack stack) {
- return group != null && group.contains(stack);
+ return false;
}
@Override
public List listAttributesOf(ItemStack stack) {
- return CreativeModeTabs.tabs().stream()
- .filter(tab -> !tab.hasSearchBar() && tab.contains(stack))
- .map(tab -> (ItemAttribute)new InItemGroup(tab))
- .toList();
+ return CreativeModeTabs.tabs()
+ .stream()
+ .filter(tab -> tab.getType() == CreativeModeTab.Type.CATEGORY)
+ .filter(tab -> tabContainsItem(tab, stack))
+ .map(tab -> (ItemAttribute) new InItemGroup(tab))
+ .toList();
+ }
+
+ private static boolean tabContainsItem(CreativeModeTab tab, ItemStack stack) {
+ return tab.contains(stack) || tab.contains(new ItemStack(stack.getItem()));
}
@Override