Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open container from type & some fixes #2504

Open
wants to merge 8 commits into
base: api-11
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -116,6 +118,31 @@ default boolean isViewingInventory() {
*/
Optional<Container> 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<Container> openInventory(ContainerType type);

default Optional<Container> openInventory(Supplier<ContainerType> 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<Container> openInventory(ContainerType type, Component displayName);

default Optional<Container> openInventory(Supplier<ContainerType> type, Component displayName) {
return this.openInventory(type.get(), displayName);
}

/**
* Closes the currently viewed entity of this player, if it is currently
* viewing one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public final class ContainerTypes {
*/
public static final DefaultedRegistryReference<ContainerType> GENERIC_3X3 = ContainerTypes.key(ResourceKey.minecraft("generic_3x3"));

public static final DefaultedRegistryReference<ContainerType> CRAFTER_3X3 = ContainerTypes.key(ResourceKey.minecraft("crafter_3x3"));

public static final DefaultedRegistryReference<ContainerType> GENERIC_9X1 = ContainerTypes.key(ResourceKey.minecraft("generic_9x1"));

public static final DefaultedRegistryReference<ContainerType> GENERIC_9X2 = ContainerTypes.key(ResourceKey.minecraft("generic_9x2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +118,7 @@ static Ingredient of(ItemStackSnapshot @Nullable ... items) {
* @return The new ingredient
*/
@SafeVarargs
static Ingredient of(DefaultedRegistryReference<? extends ItemType> @Nullable ... itemTypes) {
static Ingredient of(Supplier<? extends ItemType> @Nullable ... itemTypes) {
if (itemTypes == null || itemTypes.length == 0) {
return Ingredient.empty();
}
Expand Down
Loading