Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/org/spongepowered/api/item/ItemGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.item;

import org.spongepowered.api.CatalogType;
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.util.annotation.CatalogedBy;

/**
* Represents an item group, or creative tab.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this compare to being used? They're just signified by where they show on clients? There's otherwise no other usable functionality to gain from this, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should document by answering these questions in some sense. That will fill out the javadoc for this class.

*
* <p>Item groups are signified by where they show on clients and otherwise have
* little usable functionality.</p>
*/
@CatalogedBy(ItemGroups.class)
public interface ItemGroup extends CatalogType, Translatable {

default boolean contains(ItemType itemType) {
return itemType.getItemGroups().contains(this);
}

}
64 changes: 64 additions & 0 deletions src/main/java/org/spongepowered/api/item/ItemGroups.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.item;

import org.spongepowered.api.util.generator.dummy.DummyObjectProvider;

/**
* An enumeration of the known vanilla {@link ItemGroup}s in Minecraft.
* Mods may change and/or introduce new groups at runtime.
*/
public final class ItemGroups {

// SORTFIELDS:ON

public static final ItemGroup BREWING = DummyObjectProvider.createFor(ItemGroup.class, "BREWING");

public static final ItemGroup BUILDING_BLOCKS = DummyObjectProvider.createFor(ItemGroup.class, "BUILDING_BLOCKS");

public static final ItemGroup COMBAT = DummyObjectProvider.createFor(ItemGroup.class, "COMBAT");

public static final ItemGroup DECORATIONS = DummyObjectProvider.createFor(ItemGroup.class, "DECORATIONS");

public static final ItemGroup FOOD = DummyObjectProvider.createFor(ItemGroup.class, "FOOD");

public static final ItemGroup MATERIALS = DummyObjectProvider.createFor(ItemGroup.class, "MATERIALS");

public static final ItemGroup MISC = DummyObjectProvider.createFor(ItemGroup.class, "MISC");

public static final ItemGroup REDSTONE = DummyObjectProvider.createFor(ItemGroup.class, "REDSTONE");

public static final ItemGroup TOOLS = DummyObjectProvider.createFor(ItemGroup.class, "TOOLS");

public static final ItemGroup TRANSPORTATION = DummyObjectProvider.createFor(ItemGroup.class, "TRANSPORTATION");

// SORTFIELDS:OFF
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed the SEARCH item group.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, SEARCH, along with HOTBAR and INVENTORY, were skipped because they are not so much item groups as they are creative tabs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you attempting to expose the tab itself, for say, GUI click events.

Or are you attempting to expose the property of items to belong to a creative tab?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just exposing the property of items to belong to an item group.


// Suppress default constructor to ensure non-instantiability.
private ItemGroups() {
throw new AssertionError("You should not be attempting to instantiate this class.");
}

}
8 changes: 8 additions & 0 deletions src/main/java/org/spongepowered/api/item/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.spongepowered.api.text.translation.Translatable;
import org.spongepowered.api.util.annotation.CatalogedBy;

import java.util.Collection;
import java.util.Optional;

/**
Expand All @@ -61,6 +62,13 @@ public interface ItemType extends CatalogType, Translatable, GameDictionary.Entr
@Override
String getName();

/**
* Gets the {@link ItemGroup}s that contain this item.
*
* @return A collection of item groups, possibly empty
*/
Collection<ItemGroup> getItemGroups();

/**
* Gets the default maximum quantity for
* {@link ItemStack}s of this item.
Expand Down