mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-14 22:44:07 +01:00
Merge pull request #6389 from HateMeLikeAPro/item-group-attribute-filter
Added InItemGroup attribute filter
This commit is contained in:
commit
3a3ded66d9
@ -40,6 +40,8 @@ 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;
|
||||
@ -47,6 +49,7 @@ 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.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
@ -59,6 +62,7 @@ public interface ItemAttribute {
|
||||
|
||||
static ItemAttribute standard = register(StandardTraits.DUMMY);
|
||||
static ItemAttribute inTag = register(new InTag(ItemTags.LOGS));
|
||||
static ItemAttribute inItemGroup = register(InItemGroup.EMPTY);
|
||||
static ItemAttribute addedBy = register(new AddedBy("dummy"));
|
||||
static ItemAttribute hasEnchant = register(EnchantAttribute.EMPTY);
|
||||
static ItemAttribute shulkerFillLevel = register(ShulkerFillLevelAttribute.EMPTY);
|
||||
@ -273,6 +277,55 @@ public interface ItemAttribute {
|
||||
|
||||
}
|
||||
|
||||
public static class InItemGroup implements ItemAttribute {
|
||||
public static final InItemGroup EMPTY = new InItemGroup(null);
|
||||
|
||||
private CreativeModeTab group;
|
||||
|
||||
public InItemGroup(CreativeModeTab group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(ItemStack stack) {
|
||||
return group != null && group.contains(stack);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return "in_item_group";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getTranslationParameters() {
|
||||
return new Object[] { group == null ? "<none>" : group.getDisplayName().getString() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNBT(CompoundTag nbt) {
|
||||
if (group != null) {
|
||||
ResourceLocation groupId = CreativeModeTabRegistry.getName(group);
|
||||
|
||||
if (groupId != null) {
|
||||
nbt.putString("group", groupId.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemAttribute readNBT(CompoundTag nbt) {
|
||||
return nbt.contains("group") ? new InItemGroup(CreativeModeTabRegistry.getTab(new ResourceLocation(nbt.getString("group")))) : EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AddedBy implements ItemAttribute {
|
||||
|
||||
private String modId;
|
||||
|
Loading…
Reference in New Issue
Block a user