diff --git a/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java b/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java index 8f3b1d2636..e96c96bafa 100644 --- a/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java +++ b/src/main/java/org/spongepowered/api/entity/living/player/server/ServerPlayer.java @@ -46,6 +46,7 @@ import org.spongepowered.api.entity.living.player.tab.TabList; import org.spongepowered.api.event.Cause; import org.spongepowered.api.item.inventory.Container; +import org.spongepowered.api.item.inventory.ContainerType; import org.spongepowered.api.item.inventory.Inventory; import org.spongepowered.api.network.ServerSideConnection; import org.spongepowered.api.scoreboard.Scoreboard; @@ -58,6 +59,7 @@ import java.time.Instant; import java.util.Collection; import java.util.Optional; +import java.util.function.Supplier; public interface ServerPlayer extends Player, Subject { @@ -116,6 +118,31 @@ default boolean isViewingInventory() { */ Optional openInventory(Inventory inventory, Component displayName); + /** + * Constructs Container from a given type and opens it for player to view. + * + * @param type The container type to construct and view + * @return The opened Container if it was constructed and opened, otherwise {@link Optional#empty()} + */ + Optional openInventory(ContainerType type); + + default Optional openInventory(Supplier type) { + return this.openInventory(type.get()); + } + + /** + * Constructs Container from a given type and opens it for player to view with a custom displayName. + * + * @param type The container type to construct and view + * @param displayName The display name to set + * @return The opened Container if it was constructed and opened, otherwise {@link Optional#empty()} + */ + Optional openInventory(ContainerType type, Component displayName); + + default Optional openInventory(Supplier type, Component displayName) { + return this.openInventory(type.get(), displayName); + } + /** * Closes the currently viewed entity of this player, if it is currently * viewing one. diff --git a/src/main/java/org/spongepowered/api/item/inventory/ContainerTypes.java b/src/main/java/org/spongepowered/api/item/inventory/ContainerTypes.java index 85db4e22eb..0c25eb9956 100644 --- a/src/main/java/org/spongepowered/api/item/inventory/ContainerTypes.java +++ b/src/main/java/org/spongepowered/api/item/inventory/ContainerTypes.java @@ -61,6 +61,8 @@ public final class ContainerTypes { */ public static final DefaultedRegistryReference GENERIC_3X3 = ContainerTypes.key(ResourceKey.minecraft("generic_3x3")); + public static final DefaultedRegistryReference CRAFTER_3X3 = ContainerTypes.key(ResourceKey.minecraft("crafter_3x3")); + public static final DefaultedRegistryReference GENERIC_9X1 = ContainerTypes.key(ResourceKey.minecraft("generic_9x1")); public static final DefaultedRegistryReference GENERIC_9X2 = ContainerTypes.key(ResourceKey.minecraft("generic_9x2")); diff --git a/src/main/java/org/spongepowered/api/item/recipe/crafting/Ingredient.java b/src/main/java/org/spongepowered/api/item/recipe/crafting/Ingredient.java index c2e6062d19..bf0e89b750 100644 --- a/src/main/java/org/spongepowered/api/item/recipe/crafting/Ingredient.java +++ b/src/main/java/org/spongepowered/api/item/recipe/crafting/Ingredient.java @@ -30,7 +30,6 @@ import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.item.inventory.ItemStackSnapshot; -import org.spongepowered.api.registry.DefaultedRegistryReference; import java.util.List; import java.util.function.Predicate; @@ -119,7 +118,7 @@ static Ingredient of(ItemStackSnapshot @Nullable ... items) { * @return The new ingredient */ @SafeVarargs - static Ingredient of(DefaultedRegistryReference @Nullable ... itemTypes) { + static Ingredient of(Supplier @Nullable ... itemTypes) { if (itemTypes == null || itemTypes.length == 0) { return Ingredient.empty(); }