Documentation ¶
Overview ¶
The window package handles windows for inventories.
Index ¶
- type IInventory
- type IWindow
- type IWindowViewer
- type PlayerInventory
- func (w *PlayerInventory) CanTakeItem(item *gamerules.Slot) bool
- func (w *PlayerInventory) HeldItem() (slot gamerules.Slot, slotId SlotId)
- func (w *PlayerInventory) Init(entityId EntityId, viewer IWindowViewer)
- func (w *PlayerInventory) MarshalNbt(tag *nbt.Compound) (err error)
- func (w *PlayerInventory) NewWindow(invTypeId InvTypeId, windowId WindowId, inv IInventory) IWindow
- func (w *PlayerInventory) PutItem(item *gamerules.Slot)
- func (w *PlayerInventory) Resubscribe()
- func (w *PlayerInventory) SendFullEquipmentUpdate(writer io.Writer) (err error)
- func (w *PlayerInventory) SetHolding(holding SlotId)
- func (w *PlayerInventory) TakeOneHeldItem(into *gamerules.Slot)
- func (w *PlayerInventory) UnmarshalNbt(tag nbt.ITag) (err error)
- type Window
- func (w *Window) Click(click *gamerules.Click) TxState
- func (w *Window) Finalize(sendClosePacket bool)
- func (w *Window) Init(windowId WindowId, invTypeId InvTypeId, viewer IWindowViewer, title string, ...)
- func (w *Window) WindowId() WindowId
- func (w *Window) WriteWindowItems(writer io.Writer) (err error)
- func (w *Window) WriteWindowOpen(writer io.Writer) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IInventory ¶
type IInventory interface { NumSlots() SlotId Click(click *gamerules.Click) (txState TxState) SetSubscriber(subscriber gamerules.IInventorySubscriber) WriteProtoSlots(slots []proto.WindowSlot) }
IInventory is the interface that windows require of inventories.
type IWindow ¶
type IWindow interface { WindowId() WindowId Click(click *gamerules.Click) (txState TxState) WriteWindowOpen(writer io.Writer) (err error) WriteWindowItems(writer io.Writer) (err error) Finalize(sendClosePacket bool) }
IWindow is the interface on to types that represent a view on to multiple inventories.
type IWindowViewer ¶
type IWindowViewer interface {
TransmitPacket(packet []byte)
}
IWindowViewer is the required interface of types that wish to receive packet updates from changes to inventories viewed inside a window. Typically *player.Player implements this.
type PlayerInventory ¶
type PlayerInventory struct { Window // contains filtered or unexported fields }
func (*PlayerInventory) CanTakeItem ¶
func (w *PlayerInventory) CanTakeItem(item *gamerules.Slot) bool
CanTakeItem returns true if it can take at least one item from the passed Slot.
func (*PlayerInventory) HeldItem ¶
func (w *PlayerInventory) HeldItem() (slot gamerules.Slot, slotId SlotId)
HeldItem returns the slot that is the current "held" item. TODO need any changes to the held item slot to create notifications to players.
func (*PlayerInventory) Init ¶
func (w *PlayerInventory) Init(entityId EntityId, viewer IWindowViewer)
Init initializes PlayerInventory. entityId - The EntityId of the player who holds the inventory.
func (*PlayerInventory) MarshalNbt ¶
func (w *PlayerInventory) MarshalNbt(tag *nbt.Compound) (err error)
func (*PlayerInventory) NewWindow ¶
func (w *PlayerInventory) NewWindow(invTypeId InvTypeId, windowId WindowId, inv IInventory) IWindow
NewWindow creates a new window for the player that shares its player inventory sections with `w`. Returns nil for unrecognized inventory types. TODO implement more inventory types.
func (*PlayerInventory) PutItem ¶
func (w *PlayerInventory) PutItem(item *gamerules.Slot)
PutItem attempts to put the item stack into the player's inventory. The item will be modified as a result.
func (*PlayerInventory) Resubscribe ¶
func (w *PlayerInventory) Resubscribe()
Resubscribe should be called when another window has potentially been subscribed to the player's inventory, and subsequently closed.
func (*PlayerInventory) SendFullEquipmentUpdate ¶
func (w *PlayerInventory) SendFullEquipmentUpdate(writer io.Writer) (err error)
Writes packets for other players to see the equipped items.
func (*PlayerInventory) SetHolding ¶
func (w *PlayerInventory) SetHolding(holding SlotId)
SetHolding chooses the held item (0-8). Out of range values have no effect.
func (*PlayerInventory) TakeOneHeldItem ¶
func (w *PlayerInventory) TakeOneHeldItem(into *gamerules.Slot)
TakeOneHeldItem takes one item from the stack of items the player is holding and puts it in `into`. It does nothing if the player is holding no items, or if `into` cannot take any items of that type.
func (*PlayerInventory) UnmarshalNbt ¶
func (w *PlayerInventory) UnmarshalNbt(tag nbt.ITag) (err error)
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window represents the common base behaviour of an inventory window. It acts as a view onto multiple Inventories.
func NewWindow ¶
func NewWindow(windowId WindowId, invTypeId InvTypeId, viewer IWindowViewer, title string, inventories ...IInventory) (w *Window)
NewWindow creates a Window as a view onto the given inventories.
func (*Window) Finalize ¶
Finalize cleans up, subscriber information so that the window can be properly garbage collected. This should be called when the window is thrown away.
func (*Window) Init ¶
func (w *Window) Init(windowId WindowId, invTypeId InvTypeId, viewer IWindowViewer, title string, inventories ...IInventory)
Init is the same as NewWindow, but allows for direct embedding of the Window type.
func (*Window) WriteWindowItems ¶
WriteWindowItems writes a packet describing the window contents to the writer. It assumes that any required locks on the inventories are held.