Class ShopBuilder
java.lang.Object
com.pixelmonmod.pixelmon.api.shop.ShopBuilder
A builder for creating a shop that will be displayed to any number of players.
The shop can be created for a block or an entity, such as an NPC or a vending machine. But it is not required to have a block or entity to create a shop and it can be created without either.
The shop can be created with a list of items that can be bought and sold using the
The
The shop can be created for a block or an entity, such as an NPC or a vending machine. But it is not required to have a block or entity to create a shop and it can be created without either.
The shop can be created with a list of items that can be bought and sold using the
ShopItem
class.
The
ShopEvent
events are fired when a player interacts with the shop.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription@Nullable net.minecraft.core.BlockPos
blockPos()
Gets the block position of the shop.blockPos
(net.minecraft.core.BlockPos blockPos) Sets the block position of the shop.static ShopBuilder
builder()
Creates a newShopBuilder
instance.Sets the shop as not allowing players to sell items to it.canSell()
Sets the shop as allowing players to sell items to it.@Nullable Consumer<net.minecraft.server.level.ServerPlayer>
Gets the close handler for the shop.@Nullable net.minecraft.world.entity.Entity
entity()
Gets the entity of the shop.entity
(net.minecraft.world.entity.Entity entity) Sets the entity of the shop.@Nullable ShopItem
Finds an item in the shop by its unique identifier.items()
Gets the list of items in the shop.Sets the items in the shop.Sets the items in the shop.Sets the close handler for the shop.onPurchase
(BiConsumer<net.minecraft.server.level.ServerPlayer, ShopItem> purchaseHandler) Sets the purchase handler for the shop.onSell
(BiConsumer<net.minecraft.server.level.ServerPlayer, ShopItem> sellHandler) Sets the sell handler for the shop.@Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,
ShopItem> Gets the purchase handler for the shop.boolean
sellable()
Checks if items can be sold to the shop.sellable
(boolean sellable) Sets if the shop allows players to sell items to it.@Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,
ShopItem> Gets the sell handler for the shop.void
send
(net.minecraft.server.level.ServerPlayer... players) Sends the shop to the given players.
-
Constructor Details
-
ShopBuilder
protected ShopBuilder()
-
-
Method Details
-
builder
Creates a newShopBuilder
instance.- Returns:
- A new
ShopBuilder
instance
-
items
Gets the list of items in the shop.- Returns:
- The list of items in the shop
-
findItem
Finds an item in the shop by its unique identifier.- Parameters:
id
- The unique identifier of the item- Returns:
- The item if found, otherwise null
-
blockPos
@Nullable public @Nullable net.minecraft.core.BlockPos blockPos()Gets the block position of the shop.- Returns:
- The block position of the shop
-
entity
@Nullable public @Nullable net.minecraft.world.entity.Entity entity()Gets the entity of the shop.- Returns:
- The entity of the shop
-
sellable
public boolean sellable()Checks if items can be sold to the shop.- Returns:
- True if the player can sell items to the shop
-
closeHandler
Gets the close handler for the shop.- Returns:
- The close handler for the shop
-
purchaseHandler
@Nullable public @Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> purchaseHandler()Gets the purchase handler for the shop.- Returns:
- The purchase handler for the shop
-
sellHandler
@Nullable public @Nullable BiConsumer<net.minecraft.server.level.ServerPlayer,ShopItem> sellHandler()Gets the sell handler for the shop.- Returns:
- The sell handler for the shop
-
items
Sets the items in the shop.- Parameters:
items
- The items in the shop- Returns:
- This builder
-
items
Sets the items in the shop.- Parameters:
items
- The items in the shop- Returns:
- This builder
-
blockPos
Sets the block position of the shop.- Parameters:
blockPos
- The block position of the shop- Returns:
- This builder
-
entity
Sets the entity of the shop.- Parameters:
entity
- The entity of the shop- Returns:
- This builder
-
canSell
Sets the shop as allowing players to sell items to it.- Returns:
- This builder
-
cannotSell
Sets the shop as not allowing players to sell items to it.- Returns:
- This builder
-
sellable
Sets if the shop allows players to sell items to it.- Parameters:
sellable
- True if the shop allows players to sell items to it- Returns:
- This builder
-
onClose
Sets the close handler for the shop.- Parameters:
closeHandler
- The close handler for the shop- Returns:
- This builder
-
onPurchase
public ShopBuilder onPurchase(BiConsumer<net.minecraft.server.level.ServerPlayer, ShopItem> purchaseHandler) Sets the purchase handler for the shop.- Parameters:
purchaseHandler
- The purchase handler for the shop- Returns:
- This builder
-
onSell
Sets the sell handler for the shop.- Parameters:
sellHandler
- The sell handler for the shop- Returns:
- This builder
-
send
public void send(net.minecraft.server.level.ServerPlayer... players) Sends the shop to the given players.- Parameters:
players
- The players to send the shop to
-