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
This commit is contained in:
simibubi 2024-08-11 16:54:51 +02:00
parent 879220efb4
commit af54e8ecf3
2 changed files with 46 additions and 9 deletions

View file

@ -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 {
* <b>Other mods should not use this field!</b> 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<CreativeModeTab>) null);
static {
REGISTRATE.setTooltipModifierFactory(item -> {

View file

@ -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<ItemAttribute> 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