Documentation ¶
Index ¶
- Constants
- Variables
- func LoadGameRules(...) (err error)
- func SaveBlockDefs(writer io.Writer, blocks BlockTypeList) (err error)
- type BlockAttrs
- type BlockInstance
- type BlockType
- type BlockTypeList
- type ChestInventory
- type Click
- type Cow
- type CraftingInventory
- type Creeper
- type DispenserInventory
- type FurnaceAspect
- type FurnaceData
- type FurnaceInventory
- type Hen
- type IBlockAspect
- type IChunkBlock
- type ICommandFramework
- type IEntity
- type IGame
- type IInventory
- type IInventorySubscriber
- type INbtSerializable
- type INonPlayerEntity
- func NewActivatedTnt() INonPlayerEntity
- func NewArrow() INonPlayerEntity
- func NewBlankItem() INonPlayerEntity
- func NewBoat() INonPlayerEntity
- func NewCow() INonPlayerEntity
- func NewCreeper() INonPlayerEntity
- func NewEntityByTypeName(typeName string) INonPlayerEntity
- func NewFallingGravel() INonPlayerEntity
- func NewFallingSand() INonPlayerEntity
- func NewFishingFloat() INonPlayerEntity
- func NewHen() INonPlayerEntity
- func NewMinecart() INonPlayerEntity
- func NewPig() INonPlayerEntity
- func NewPoweredCart() INonPlayerEntity
- func NewSheep() INonPlayerEntity
- func NewSkeleton() INonPlayerEntity
- func NewSpider() INonPlayerEntity
- func NewSquid() INonPlayerEntity
- func NewStorageCart() INonPlayerEntity
- func NewThrownEgg() INonPlayerEntity
- func NewThrownSnowball() INonPlayerEntity
- func NewWolf() INonPlayerEntity
- func NewZombie() INonPlayerEntity
- type IPlayerClient
- type IPlayerShardClient
- type IShardConnecter
- type IShardShardClient
- type ITileEntity
- func NewChestTileEntity() ITileEntity
- func NewDispenserTileEntity() ITileEntity
- func NewFurnaceTileEntity() ITileEntity
- func NewMobSpawnerTileEntity() ITileEntity
- func NewMusicTileEntity() ITileEntity
- func NewRecordPlayerTileEntity() ITileEntity
- func NewSignTileEntity() ITileEntity
- func NewTileEntityByTypeName(typeName string) ITileEntity
- type IUnsubscribed
- type Inventory
- func (inv *Inventory) CanTakeItem(item *Slot) bool
- func (inv *Inventory) Click(click *Click) TxState
- func (inv *Inventory) Init(size int)
- func (inv *Inventory) MakeProtoSlots() []proto.WindowSlot
- func (inv *Inventory) MarshalNbt(tag *nbt.Compound) (err error)
- func (inv *Inventory) NumSlots() SlotId
- func (inv *Inventory) PutItem(item *Slot)
- func (inv *Inventory) SetSubscriber(subscriber IInventorySubscriber)
- func (inv *Inventory) Slot(slotId SlotId) Slot
- func (inv *Inventory) SlotUnmarshalNbt(tag *nbt.Compound, slotId SlotId) (err error)
- func (inv *Inventory) TakeAllItems() (items []Slot)
- func (inv *Inventory) TakeOneItem(slotId SlotId, into *Slot)
- func (inv *Inventory) TakeOnlyClick(click *Click) TxState
- func (inv *Inventory) UnmarshalNbt(tag *nbt.Compound) (err error)
- func (inv *Inventory) WriteProtoSlots(slots []proto.WindowSlot)
- type InventoryAspect
- func (aspect *InventoryAspect) Destroy(instance *BlockInstance)
- func (aspect *InventoryAspect) Interact(instance *BlockInstance, player IPlayerClient)
- func (aspect *InventoryAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
- func (aspect *InventoryAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
- func (aspect *InventoryAspect) Name() string
- type Item
- type ItemType
- type ItemTypeMap
- type Mob
- func (mob *Mob) FormatMetadata() []proto.EntityMetadata
- func (mob *Mob) Init(id EntityMobType)
- func (mob *Mob) MarshalNbt(tag *nbt.Compound) (err error)
- func (mob *Mob) SendSpawn(writer io.Writer) (err error)
- func (mob *Mob) SendUpdate(writer io.Writer) (err error)
- func (mob *Mob) SetBurning(burn bool)
- func (mob *Mob) SetLook(look LookDegrees)
- func (mob *Mob) Tick(blockQuerier physics.IBlockQuerier) (leftBlock bool)
- func (mob *Mob) UnmarshalNbt(tag *nbt.Compound) (err error)
- type MobSpawnerAspect
- type MobType
- type MobTypeMap
- type MusicAspect
- type Object
- type Pig
- type Reaction
- type Recipe
- type RecipeSet
- type RecipeSetMatcher
- type RecordPlayerAspect
- type SaplingAspect
- type Sheep
- type SignAspect
- type Skeleton
- type Slot
- func (s *Slot) Add(src *Slot) (changed bool)
- func (s *Slot) AddOne(src *Slot) (changed bool)
- func (s *Slot) AddWhole(src *Slot) (changed bool)
- func (s *Slot) Attr() (ItemTypeId, ItemCount, ItemData)
- func (s *Slot) Clear()
- func (s *Slot) Decrement() (changed bool)
- func (s *Slot) Equals(other *Slot) bool
- func (s *Slot) IsCompatible(other *Slot) bool
- func (s *Slot) IsEmpty() bool
- func (s *Slot) IsSameType(other *Slot) bool
- func (s *Slot) IsValidType() (ok bool)
- func (s *Slot) ItemType() (itemType *ItemType)
- func (s *Slot) MarshalNbt(tag *nbt.Compound) (err error)
- func (s *Slot) MaxStack() ItemCount
- func (s *Slot) Normalize()
- func (s *Slot) SendEquipmentUpdate(writer io.Writer, entityId EntityId, slotId SlotId) error
- func (s *Slot) SendUpdate(writer io.Writer, windowId WindowId, slotId SlotId) error
- func (s *Slot) SetWindowSlot(windowSlot *proto.WindowSlot)
- func (s *Slot) Split(src *Slot) (changed bool)
- func (s *Slot) Swap(src *Slot) (changed bool)
- func (s *Slot) UnmarshalNbt(tag *nbt.Compound) (err error)
- type Spider
- type Squid
- type StandardAspect
- func (aspect *StandardAspect) Check() error
- func (aspect *StandardAspect) Destroy(instance *BlockInstance)
- func (aspect *StandardAspect) Hit(instance *BlockInstance, player IPlayerClient, digStatus DigStatus) (destroyed bool)
- func (aspect *StandardAspect) Interact(instance *BlockInstance, player IPlayerClient)
- func (aspect *StandardAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
- func (aspect *StandardAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
- func (aspect *StandardAspect) Name() string
- func (aspect *StandardAspect) Tick(instance *BlockInstance) bool
- type TodoAspect
- type ToolTypeId
- type VoidAspect
- func (aspect *VoidAspect) Check() error
- func (aspect *VoidAspect) Destroy(instance *BlockInstance)
- func (aspect *VoidAspect) Hit(instance *BlockInstance, player IPlayerClient, digStatus DigStatus) (destroyed bool)
- func (aspect *VoidAspect) Interact(instance *BlockInstance, player IPlayerClient)
- func (aspect *VoidAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
- func (aspect *VoidAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
- func (aspect *VoidAspect) Name() string
- func (aspect *VoidAspect) Tick(instance *BlockInstance) bool
- type Wolf
- type Zombie
Constants ¶
const (
MaxStackDefault = ItemCount(64)
)
Variables ¶
var ( Blocks BlockTypeList Items ItemTypeMap Recipes *RecipeSet FurnaceReactions FurnaceData // TODO: Commands should maybe be accessible via IGame. CommandFramework ICommandFramework Permissions permission.IPermissions )
GameRules is a container type for block, item and recipe definitions.
var CowType = MobType{MobTypeIdCow, "cow"}
var CreeperType = MobType{MobTypeIdCreeper, "creeper"}
var EntityCreateByName = map[string]func() INonPlayerEntity{ "Item": NewBlankItem, "Hen": NewHen, "Chicken": NewHen, "Cow": NewCow, "Creeper": NewCreeper, "Pig": NewPig, "Sheep": NewSheep, "Skeleton": NewSkeleton, "Squid": NewSquid, "Spider": NewSpider, "Wolf": NewWolf, "Zombie": NewZombie, "Boat": NewBoat, "Minecart": NewMinecart, "StorageCart": NewStorageCart, "PoweredCart": NewPoweredCart, "ActivatedTnt": NewActivatedTnt, "Arrow": NewArrow, "ThrownSnowball": NewThrownSnowball, "ThrownEgg": NewThrownEgg, "FallingSand": NewFallingSand, "FallingGravel": NewFallingGravel, "FishingFloat": NewFishingFloat, }
var GhastType = MobType{MobTypeIdGhast, "ghast"}
var GiantZombieType = MobType{MobTypeIdGiantZombie, "giantzombie"}
var HenType = MobType{MobTypeIdHen, "hen"}
var Mobs = MobTypeMap{ MobTypeIdCreeper: &CreeperType, MobTypeIdSkeleton: &SkeletonType, MobTypeIdSpider: &SpiderType, MobTypeIdGiantZombie: &GiantZombieType, MobTypeIdZombie: &ZombieType, MobTypeIdSlime: &SlimeType, MobTypeIdGhast: &GhastType, MobTypeIdZombiePigman: &ZombiePigmanType, MobTypeIdPig: &PigType, MobTypeIdSheep: &SheepType, MobTypeIdCow: &CowType, MobTypeIdHen: &HenType, MobTypeIdSquid: &SquidType, MobTypeIdWolf: &WolfType, }
Used for protocol parsing.
var PigType = MobType{MobTypeIdPig, "pig"}
var SheepType = MobType{MobTypeIdSheep, "sheep"}
var SkeletonType = MobType{MobTypeIdSkeleton, "skeleton"}
var SlimeType = MobType{MobTypeIdSlime, "slime"}
var SpiderType = MobType{MobTypeIdSpider, "spider"}
var SquidType = MobType{MobTypeIdSquid, "squid"}
var TileEntityCreateByName = map[string]func() ITileEntity{ "Chest": NewChestTileEntity, "Furnace": NewFurnaceTileEntity, "Trap": NewDispenserTileEntity, "Sign": NewSignTileEntity, "MobSpawner": NewMobSpawnerTileEntity, "Music": NewMusicTileEntity, "RecordPlayer": NewRecordPlayerTileEntity, }
var WolfType = MobType{MobTypeIdWolf, "wolf"}
var ZombiePigmanType = MobType{MobTypeIdZombiePigman, "zombiepigman"}
var ZombieType = MobType{MobTypeIdZombie, "zombie"}
Functions ¶
func LoadGameRules ¶
func SaveBlockDefs ¶
func SaveBlockDefs(writer io.Writer, blocks BlockTypeList) (err error)
Types ¶
type BlockAttrs ¶
type BlockInstance ¶
type BlockInstance struct { Chunk IChunkBlock BlockLoc BlockXyz SubLoc SubChunkXyz Index BlockIndex BlockType *BlockType // Note that only the lower nibble of data is stored. Data byte }
BlockInstance represents the instance of a block within a chunk. It is used to pass context to a IBlockAspect method call. A BlockInstance belongs to the chunk that creates it - a copy must be made if a block aspect needs to persist the value of one.
type BlockType ¶
type BlockType struct { BlockAttrs Aspect IBlockAspect }
The core information about any block type.
type BlockTypeList ¶
type BlockTypeList []BlockType
Lookup table of blocks.
func LoadBlockDefs ¶
func LoadBlockDefs(reader io.Reader) (blocks BlockTypeList, err error)
func LoadBlocksFromFile ¶
func LoadBlocksFromFile(filename string) (blockTypes BlockTypeList, err error)
func (*BlockTypeList) CreateBlockItemTypes ¶
func (btl *BlockTypeList) CreateBlockItemTypes(itemTypes ItemTypeMap)
MergeBlockItems creates default item types from a defined list of block types. It does not override any pre-existing items types.
func (*BlockTypeList) Get ¶
func (btl *BlockTypeList) Get(id BlockId) (block *BlockType, ok bool)
Get returns the requested BlockType by ID. ok = false if the block type does not exist.
type ChestInventory ¶
type ChestInventory struct {
Inventory
}
func NewChestInventory ¶
func NewChestInventory() (inv *ChestInventory)
NewChestInventory creates a 9x3 chest inventory.
func (*ChestInventory) MarshalNbt ¶
func (inv *ChestInventory) MarshalNbt(tag *nbt.Compound) (err error)
type CraftingInventory ¶
type CraftingInventory struct { Inventory // contains filtered or unexported fields }
Inventory with extended function to perform crafting. It assumes that slot 0 is the output, and that the remaining slots are inputs.
func NewWorkbenchInventory ¶
func NewWorkbenchInventory() *CraftingInventory
NewWorkbenchInventory creates a 3x3 workbench crafting inventory.
func (*CraftingInventory) Click ¶
func (inv *CraftingInventory) Click(click *Click) (txState TxState)
Click handles window clicks from a user with special handling for crafting.
func (*CraftingInventory) InitPlayerCraftingInventory ¶
func (inv *CraftingInventory) InitPlayerCraftingInventory()
InitWorkbenchInventory initializes inv as a 2x2 player crafting inventory.
func (*CraftingInventory) TakeAllItems ¶
func (inv *CraftingInventory) TakeAllItems() (items []Slot)
TakeAllItems empties the inventory, and returns all items that were inside it inside a slice of Slots.
type Creeper ¶
type Creeper struct {
Mob
}
func (*Creeper) CreeperSetBlueAura ¶
func (c *Creeper) CreeperSetBlueAura()
func (*Creeper) SetNormalStatus ¶
func (c *Creeper) SetNormalStatus()
type DispenserInventory ¶
type DispenserInventory struct {
Inventory
}
func NewDispenserInventory ¶
func NewDispenserInventory() (inv *DispenserInventory)
NewDispenserInventory creates a 3x3 dispenser inventory.
func (*DispenserInventory) MarshalNbt ¶
func (inv *DispenserInventory) MarshalNbt(tag *nbt.Compound) (err error)
type FurnaceAspect ¶
type FurnaceAspect struct { InventoryAspect Inactive BlockId Active BlockId }
func (*FurnaceAspect) InventoryClick ¶
func (aspect *FurnaceAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
func (*FurnaceAspect) Tick ¶
func (aspect *FurnaceAspect) Tick(instance *BlockInstance) bool
type FurnaceData ¶
type FurnaceData struct { // FuelDuration contains a map of fuel types to number of ticks that the fuel // lasts for. Fuels map[ItemTypeId]Ticks // Reactions contains a map of input item type to output item type and data. Reactions map[ItemTypeId]Reaction }
FurnaceData contains data on furnace reactions.
func LoadFurnaceData ¶
func LoadFurnaceData(reader io.Reader) (furnaceData FurnaceData, err error)
LoadFurnaceData reads FurnaceData from the reader.
func LoadFurnaceDataFromFile ¶
func LoadFurnaceDataFromFile(filename string) (furnaceData FurnaceData, err error)
LoadFurnaceDataFromFile reads FurnaceData from the named file.
type FurnaceInventory ¶
type FurnaceInventory struct { Inventory // contains filtered or unexported fields }
func NewFurnaceInventory ¶
func NewFurnaceInventory() (inv *FurnaceInventory)
NewFurnaceInventory creates a furnace inventory.
func (*FurnaceInventory) Click ¶
func (inv *FurnaceInventory) Click(click *Click) (txState TxState)
func (*FurnaceInventory) IsLit ¶
func (inv *FurnaceInventory) IsLit() bool
func (*FurnaceInventory) MarshalNbt ¶
func (inv *FurnaceInventory) MarshalNbt(tag *nbt.Compound) (err error)
func (*FurnaceInventory) Tick ¶
func (inv *FurnaceInventory) Tick()
Tick runs the furnace for a single tick.
func (*FurnaceInventory) UnmarshalNbt ¶
func (inv *FurnaceInventory) UnmarshalNbt(tag *nbt.Compound) (err error)
type IBlockAspect ¶
type IBlockAspect interface { // Name is currently used purely for the serialization of aspect // configuration data. Name() string // Check tests that the block aspect has been configured correctly, // returning nil if it is correct. Check() error // Hit is called when the player hits a block. Hit(instance *BlockInstance, player IPlayerClient, digStatus DigStatus) (destroyed bool) // Interact is called when a player right-clicks a block. Interact(instance *BlockInstance, player IPlayerClient) // InventoryClick is called when the player clicked on a slot inside the // inventory for the block (assuming it still has one). InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click) // InventoryUnsubscribed is called when the player closes the window for the // inventory for the block (assuming it still has one). InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient) // Destroy is called when the block is destroyed by a player hitting it. // TODO And in other situations, maybe? Destroy(instance *BlockInstance) // Tick tells the aspect to run the block for a tick. It should return false // if the block should not tick again. Tick(instance *BlockInstance) bool // contains filtered or unexported methods }
Defines the behaviour of a block.
type IChunkBlock ¶
type IChunkBlock interface { Rand() *rand.Rand ItemType(itemTypeId ItemTypeId) (itemType *ItemType, ok bool) AddEntity(s INonPlayerEntity) SetBlockByIndex(blockIndex BlockIndex, blockId BlockId, blockData byte) TileEntity(blockIndex BlockIndex) ITileEntity SetTileEntity(blockIndex BlockIndex, extra ITileEntity) AddOnUnsubscribe(entityId EntityId, observer IUnsubscribed) RemoveOnUnsubscribe(entityId EntityId, observer IUnsubscribed) // AddActiveBlock flags a block in any chunk as active. AddActiveBlock(blockXyz *BlockXyz) // AddActiveBlockIndex flags a block in the chunk itself as active by index. AddActiveBlockIndex(blockIndex BlockIndex) }
The interface required of a chunk by block behaviour.
type ICommandFramework ¶
type ICommandFramework interface { Prefix() string Process(player IPlayerClient, cmd string, game IGame) }
type IEntity ¶
type IEntity interface { // Returns the entity's ID. GetEntityId() EntityId // SendSpawn writes the packets required to tell a client about the existance // and current state of the entity. SendSpawn(io.Writer) error // SendUpdate writes the packets required to tell a client about the new // state of the entity since the last SendUpdate or SendSpawn. SendUpdate(io.Writer) error // Returns the entity's current position. Position() *AbsXyz }
IEntity represents common elements to all types of non-block entities that can be present in a chunk.
type IGame ¶
type IGame interface { // Broadcast a packet to all players on the server. BroadcastPacket(packet []byte) // Broadcast a message to all players on the server. BroadcastMessage(msg string) // Return a player from their name. PlayerByName(name string) IPlayerClient // Return a player from an EntityId. PlayerByEntityId(id EntityId) IPlayerClient // Return an ItemType from a numeric item. The boolean flag indicates // whether or not 'id' was a valid item type. ItemTypeById(id int) (ItemType, bool) }
IGame provide an interface for interacting with and taking action on the game, including getting information about the game state, etc.
type IInventory ¶
type IInventory interface { NumSlots() SlotId Click(click *Click) (txState TxState) SetSubscriber(subscriber IInventorySubscriber) MakeProtoSlots() []proto.WindowSlot WriteProtoSlots(slots []proto.WindowSlot) TakeAllItems() (items []Slot) UnmarshalNbt(tag *nbt.Compound) (err error) MarshalNbt(tag *nbt.Compound) (err error) SlotUnmarshalNbt(tag *nbt.Compound, slotId SlotId) (err error) }
IInventory is the general interface provided by inventory implementations.
type IInventorySubscriber ¶
type IInventorySubscriber interface { // SlotUpdate is called when a slot inside the inventory changes its // contents. SlotUpdate(slot *Slot, slotId SlotId) // ProgressUpdate is called when a progress bar inside the inventory changes. ProgressUpdate(prgBarId PrgBarId, value PrgBarValue) }
type INbtSerializable ¶
type INbtSerializable interface { // UnmarshalNbt reads the NBT tag to set the state of the object. UnmarshalNbt(*nbt.Compound) error // MarshalNbt creates an NBT tag representing the entity. This can be nil if // the entity cannot be serialized. MarshalNbt(*nbt.Compound) error }
INbtSerializable is the interface for all objects that can be serialized to NBT data structures for persistency.
type INonPlayerEntity ¶
type INonPlayerEntity interface { IEntity INbtSerializable // Sets the entity's ID. SetEntityId(EntityId) // Runs the physics for the entity for a single server tick. Tick(physics.IBlockQuerier) (leftBlock bool) }
INonPlayerEntity is the interface for entities other than players which are controlled server-side.
func NewActivatedTnt ¶
func NewActivatedTnt() INonPlayerEntity
func NewArrow ¶
func NewArrow() INonPlayerEntity
func NewBlankItem ¶
func NewBlankItem() INonPlayerEntity
func NewBoat ¶
func NewBoat() INonPlayerEntity
func NewCow ¶
func NewCow() INonPlayerEntity
func NewCreeper ¶
func NewCreeper() INonPlayerEntity
func NewEntityByTypeName ¶
func NewEntityByTypeName(typeName string) INonPlayerEntity
NewEntityByTypeName creates the appropriate entity type based on the input string, e.g "Item" or "Zombie". Returns nil if typeName is unknown.
func NewFallingGravel ¶
func NewFallingGravel() INonPlayerEntity
func NewFallingSand ¶
func NewFallingSand() INonPlayerEntity
func NewFishingFloat ¶
func NewFishingFloat() INonPlayerEntity
func NewHen ¶
func NewHen() INonPlayerEntity
func NewMinecart ¶
func NewMinecart() INonPlayerEntity
func NewPig ¶
func NewPig() INonPlayerEntity
func NewPoweredCart ¶
func NewPoweredCart() INonPlayerEntity
func NewSheep ¶
func NewSheep() INonPlayerEntity
func NewSkeleton ¶
func NewSkeleton() INonPlayerEntity
func NewSpider ¶
func NewSpider() INonPlayerEntity
func NewSquid ¶
func NewSquid() INonPlayerEntity
func NewStorageCart ¶
func NewStorageCart() INonPlayerEntity
func NewThrownEgg ¶
func NewThrownEgg() INonPlayerEntity
func NewThrownSnowball ¶
func NewThrownSnowball() INonPlayerEntity
func NewWolf ¶
func NewWolf() INonPlayerEntity
func NewZombie ¶
func NewZombie() INonPlayerEntity
type IPlayerClient ¶
type IPlayerClient interface { GetEntityId() EntityId TransmitPacket(packet []byte) // NotifyChunkLoad informs Player that a chunk subscription request with // notify=true has completed. NotifyChunkLoad() // InventorySubscribed informs the player that an inventory has been // opened. InventorySubscribed(block BlockXyz, invTypeId InvTypeId, slots []proto.WindowSlot) // InventorySlotUpdate informs the player of a change to a slot in the // open inventory. InventorySlotUpdate(block BlockXyz, slot Slot, slotId SlotId) // InventoryProgressUpdate informs the player of a change of a progress // bar in a window. InventoryProgressUpdate(block BlockXyz, prgBarId PrgBarId, value PrgBarValue) // InventoryCursorUpdate informs the player of their new cursor contents. InventoryCursorUpdate(block BlockXyz, cursor Slot) // InventoryTxState requests that the player report the transaction state // as accepted or not. This is used by remote inventories when // TxStateDeferred is returned from Click. InventoryTxState(block BlockXyz, txId TxId, accepted bool) // InventorySubscribed informs the player that an inventory has been // closed. InventoryUnsubscribed(block BlockXyz) // PlaceHeldItem requests that the player frontend take one item from the // held item stack and send it in a ReqPlaceItem to the target block. The // player code may *not* honour this request (e.g there might be no suitable // held item). PlaceHeldItem(target BlockXyz, wasHeld Slot) // OfferItem requests that the player check if it can take the item. If // it can then it should ReqTakeItem from the chunk. OfferItem(fromChunk ChunkXz, entityId EntityId, item Slot) // GiveItemAtPosition requests that the player takes the item contents // into their inventory. If they cannot, then the player should drop the // item at the given position. GiveItemAtPosition(atPosition AbsXyz, item Slot) // GiveItem is a wrapper for GiveItemAtPosition that uses the player's // current position as the 'atPosition'. GiveItem(item Slot) // PositionLook returns the player's current position and look PositionLook() (AbsXyz, LookDegrees) // SetPositionLook changes the player's position and look SetPositionLook(AbsXyz, LookDegrees) // EchoMessage displays a message to the player EchoMessage(msg string) }
IShardClient is the interface by which shards communicate to players on the frontend.
type IPlayerShardClient ¶
type IPlayerShardClient interface { // Removes connection to shard, and removes all subscriptions to chunks in // the shard. Note that this does *not* send packets to tell the client to // unload the subscribed chunks. Disconnect() ReqSubscribeChunk(chunkLoc ChunkXz, notify bool) ReqUnsubscribeChunk(chunkLoc ChunkXz) ReqMulticastPlayers(chunkLoc ChunkXz, exclude EntityId, packet []byte) ReqAddPlayerData(chunkLoc ChunkXz, name string, position AbsXyz, look LookBytes, held ItemTypeId) ReqRemovePlayerData(chunkLoc ChunkXz, isDisconnect bool) ReqSetPlayerPosition(chunkLoc ChunkXz, position AbsXyz) ReqSetPlayerLook(chunkLoc ChunkXz, look LookBytes) // ReqHitBlock requests that the targetted block be hit. ReqHitBlock(held Slot, target BlockXyz, digStatus DigStatus, face Face) // ReqHitBlock requests that the targetted block be interacted with. ReqInteractBlock(held Slot, target BlockXyz, face Face) // ReqPlaceItem requests that the item passed be placed at the given target // location. The shard *may* choose not to do this, but if it cannot, then it // *must* account for the item in some way (maybe hand it back to the player // or just drop it on the ground). ReqPlaceItem(target BlockXyz, slot Slot) // ReqTakeItem requests that the item with the specified entityId is given to // the player. The chunk doesn't have to respect this (particularly if the // item no longer exists). ReqTakeItem(chunkLoc ChunkXz, entityId EntityId) // ReqDropItem requests that an item be created. ReqDropItem(content Slot, position AbsXyz, velocity AbsVelocity, pickupImmunity Ticks) // ReqInventoryClick requests that the given cursor be "clicked" onto the // inventory. The chunk should send a replying ReqInventoryCursorUpdate to // reflect the new state of the cursor afterwards - in addition to any // ReqInventorySlotUpdate to all subscribers to the inventory. ReqInventoryClick(block BlockXyz, click Click) // ReqInventoryUnsubscribed requests that the inventory for the block be // unsubscribed to. ReqInventoryUnsubscribed(block BlockXyz) }
IPlayerShardClient is the interface by which shards can be communicated to by player frontend code.
type IShardConnecter ¶
type IShardConnecter interface { // PlayerShardConnect makes a connection from a player to a shard. PlayerShardConnect(entityId EntityId, player IPlayerClient, shardLoc ShardXz) IPlayerShardClient // ShardShardConnect makes a connection from one shard to another. // TODO Consider making this package-private to shardserver. ShardShardConnect(shardLoc ShardXz) IShardShardClient }
IShardConnecter is used to look up shards and connect to them.
type IShardShardClient ¶
type IShardShardClient interface { Disconnect() ReqSetActiveBlocks(blocks []BlockXyz) ReqTransferEntity(loc ChunkXz, entity INonPlayerEntity) }
IShardShardClient provides an interface for shards to make requests against another shard. TODO Consider making this package-private to shardserver.
type ITileEntity ¶
type ITileEntity interface { INbtSerializable // SetChunk sets the parent chunk of the tile entity. This must be called // after the tile entity is deserialized and before any game event methods // are called. SetChunk(chunk IChunkBlock) // Block returns the position of the tile entity. Block() BlockXyz }
ITileEntity is the interface common to entities that are tile-based.
func NewChestTileEntity ¶
func NewChestTileEntity() ITileEntity
Creates a new tile entity for a chest. UnmarshalNbt and SetChunk must be called before any other methods.
func NewDispenserTileEntity ¶
func NewDispenserTileEntity() ITileEntity
func NewFurnaceTileEntity ¶
func NewFurnaceTileEntity() ITileEntity
Creates a new tile entity for a furnace. UnmarshalNbt and SetChunk must be called before any other methods.
func NewMobSpawnerTileEntity ¶
func NewMobSpawnerTileEntity() ITileEntity
func NewMusicTileEntity ¶
func NewMusicTileEntity() ITileEntity
func NewRecordPlayerTileEntity ¶
func NewRecordPlayerTileEntity() ITileEntity
func NewSignTileEntity ¶
func NewSignTileEntity() ITileEntity
func NewTileEntityByTypeName ¶
func NewTileEntityByTypeName(typeName string) ITileEntity
type IUnsubscribed ¶
type IUnsubscribed interface {
Unsubscribed(entityId EntityId)
}
IUnsubscribed is the interface by which blocks (and potentially other things) can register themselves to be called when a player unsubscribes from a chunk.
type Inventory ¶
type Inventory struct {
// contains filtered or unexported fields
}
func (*Inventory) CanTakeItem ¶
CanTakeItem returns true if it can take at least one item from the passed Slot.
func (*Inventory) Click ¶
Click takes the default actions upon a click event from a player. The Cursor attribute of click may be modified to represent the cursors new contents.
func (*Inventory) Init ¶
Init initializes the inventory. onUnsubscribed is called in a new goroutine when the number of subscribers to the inventory reaches zero (but is not called initially).
func (*Inventory) MakeProtoSlots ¶
func (inv *Inventory) MakeProtoSlots() []proto.WindowSlot
func (*Inventory) SetSubscriber ¶
func (inv *Inventory) SetSubscriber(subscriber IInventorySubscriber)
func (*Inventory) SlotUnmarshalNbt ¶
func (*Inventory) TakeAllItems ¶
TakeAllItems empties the inventory, and returns all items that were inside it inside a slice of Slots.
func (*Inventory) TakeOneItem ¶
func (*Inventory) TakeOnlyClick ¶
TakeOnlyClick is similar to Click, but only allows items to be taken from the slot, and it only allows the *whole* stack to be taken, otherwise no items are taken at all. This is intended for use by crafting/furnace output slots.
func (*Inventory) WriteProtoSlots ¶
func (inv *Inventory) WriteProtoSlots(slots []proto.WindowSlot)
WriteProtoSlots stores into the slots parameter the proto version of the item data in the inventory. Precondition: len(slots) == len(inv.slots)
type InventoryAspect ¶
type InventoryAspect struct { StandardAspect // contains filtered or unexported fields }
InventoryAspect is the common behaviour for blocks that have inventory.
func (*InventoryAspect) Destroy ¶
func (aspect *InventoryAspect) Destroy(instance *BlockInstance)
func (*InventoryAspect) Interact ¶
func (aspect *InventoryAspect) Interact(instance *BlockInstance, player IPlayerClient)
func (*InventoryAspect) InventoryClick ¶
func (aspect *InventoryAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
func (*InventoryAspect) InventoryUnsubscribed ¶
func (aspect *InventoryAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
func (*InventoryAspect) Name ¶
func (aspect *InventoryAspect) Name() string
type Item ¶
type Item struct { EntityId Slot physics.PointObject PickupImmunity Ticks // contains filtered or unexported fields }
type ItemType ¶
type ItemType struct { Id ItemTypeId Name string MaxStack ItemCount ToolType ToolTypeId ToolUses ItemData }
type ItemTypeMap ¶
type ItemTypeMap map[ItemTypeId]*ItemType
func LoadItemDefs ¶
func LoadItemDefs(reader io.Reader) (items ItemTypeMap, err error)
func LoadItemTypesFromFile ¶
func LoadItemTypesFromFile(filename string) (items ItemTypeMap, err error)
type Mob ¶
type Mob struct { EntityId physics.PointObject // contains filtered or unexported fields }
When using an object of type Mob or a sub-type, the caller must set an EntityId, most likely obtained from the EntityManager.
func (*Mob) FormatMetadata ¶
func (mob *Mob) FormatMetadata() []proto.EntityMetadata
func (*Mob) SetBurning ¶
type MobSpawnerAspect ¶
type MobSpawnerAspect struct {
StandardAspect
}
func (MobSpawnerAspect) Name ¶
func (aspect MobSpawnerAspect) Name() string
type MobTypeMap ¶
type MobTypeMap map[EntityMobType]*MobType
type MusicAspect ¶
type MusicAspect struct {
StandardAspect
}
func (MusicAspect) Name ¶
func (aspect MusicAspect) Name() string
type Object ¶
type Object struct { EntityId ObjTypeId physics.PointObject // contains filtered or unexported fields }
type Reaction ¶
type Reaction struct { Output ItemTypeId OutputData ItemData }
Reaction describes the output of a furnace reaction.
type RecipeSet ¶
type RecipeSet struct {
// contains filtered or unexported fields
}
func LoadRecipes ¶
func LoadRecipes(reader io.Reader, itemTypes ItemTypeMap) (recipes *RecipeSet, err error)
LoadRecipes reads recipes from a JSON template in reader. itemTypes must be provided to map item type IDs to known items.
func LoadRecipesFromFile ¶
func LoadRecipesFromFile(filename string, itemTypes ItemTypeMap) (recipes *RecipeSet, err error)
type RecipeSetMatcher ¶
type RecipeSetMatcher struct {
// contains filtered or unexported fields
}
RecipeSetMatcher looks up recipes within a RecipeSet, an instance must be used from a single goroutine.
func (*RecipeSetMatcher) Init ¶
func (r *RecipeSetMatcher) Init(recipes *RecipeSet)
func (*RecipeSetMatcher) Match ¶
func (r *RecipeSetMatcher) Match(width, height int, slots []Slot) (output Slot)
Match looks for a matching recipe for the input slots, and returns a Slot with the result of any matching recipe. output.ItemType==nil and output.Count==0 if nothing matched).
The order of slots is left to right, then top to bottom.
Precondition: len(slots) == width * height
type RecordPlayerAspect ¶
type RecordPlayerAspect struct {
StandardAspect
}
func (RecordPlayerAspect) Name ¶
func (aspect RecordPlayerAspect) Name() string
type SaplingAspect ¶
type SaplingAspect struct {
StandardAspect
}
func (*SaplingAspect) Name ¶
func (aspect *SaplingAspect) Name() string
func (*SaplingAspect) Tick ¶
func (aspect *SaplingAspect) Tick(instance *BlockInstance) bool
type SignAspect ¶
type SignAspect struct {
StandardAspect
}
func (SignAspect) Name ¶
func (aspect SignAspect) Name() string
type Slot ¶
type Slot struct { ItemTypeId ItemTypeId Count ItemCount Data ItemData }
Represents an inventory slot, e.g in a player's inventory, their cursor, a chest.
func (*Slot) Add ¶
Adds as many items from the passed slot to the destination (subject) slot as possible, depending on stacking allowances and item types etc. Returns true if slots changed as a result.
func (*Slot) AddOne ¶
Takes one item count from src and adds it to the subject s. It does nothing if the items in the slots are not compatible. Returns true if slots changed as a result.
func (*Slot) AddWhole ¶
AddWhole is similar to Add, but with the exception that if not all the items can be transferred, then none are transferred at all. Returns true if slots changed as a result.
func (*Slot) IsCompatible ¶
func (*Slot) IsSameType ¶
func (*Slot) IsValidType ¶
func (*Slot) MaxStack ¶
func (s *Slot) MaxStack() ItemCount
MaxStack returns the maximum number of items that can be held in the slot for its current item type. It returns 0 for unknown items or MaxStackDefault for empty slots.
func (*Slot) SendEquipmentUpdate ¶
func (*Slot) SendUpdate ¶
func (*Slot) SetWindowSlot ¶
func (s *Slot) SetWindowSlot(windowSlot *proto.WindowSlot)
func (*Slot) Split ¶
Splits the contents of the subject slot (s) into half, half remaining in s, and half moving to src (odd amounts put the spare item into the src slot). If src is not empty, then this does nothing. Returns true if slots changed as a result.
type StandardAspect ¶
type StandardAspect struct { // Items, up to one of which will potentially spawn when block destroyed. DroppedItems []blockDropItem BreakOn DigStatus // contains filtered or unexported fields }
Behaviour of a "standard" block. A StandardAspect block is one that is diggable, and drops items in a simple manner. StandardAspect blocks do not use block metadata.
func (*StandardAspect) Check ¶
func (aspect *StandardAspect) Check() error
func (*StandardAspect) Destroy ¶
func (aspect *StandardAspect) Destroy(instance *BlockInstance)
func (*StandardAspect) Hit ¶
func (aspect *StandardAspect) Hit(instance *BlockInstance, player IPlayerClient, digStatus DigStatus) (destroyed bool)
func (*StandardAspect) Interact ¶
func (aspect *StandardAspect) Interact(instance *BlockInstance, player IPlayerClient)
func (*StandardAspect) InventoryClick ¶
func (aspect *StandardAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
func (*StandardAspect) InventoryUnsubscribed ¶
func (aspect *StandardAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
func (*StandardAspect) Name ¶
func (aspect *StandardAspect) Name() string
func (*StandardAspect) Tick ¶
func (aspect *StandardAspect) Tick(instance *BlockInstance) bool
type TodoAspect ¶
type TodoAspect struct { VoidAspect Comment string }
TodoAspect has the same behaviour as that of a "void" block - i.e none. However, its purpose is intended to mark a block type whose behaviour is still to be implemented. A comment allows for notes to be made, but provides no functional change.
func (*TodoAspect) Name ¶
func (aspect *TodoAspect) Name() string
type ToolTypeId ¶
type ToolTypeId byte
type VoidAspect ¶
type VoidAspect struct{}
Behaviour of a "void" block which has no behaviour.
func (*VoidAspect) Check ¶
func (aspect *VoidAspect) Check() error
func (*VoidAspect) Destroy ¶
func (aspect *VoidAspect) Destroy(instance *BlockInstance)
func (*VoidAspect) Hit ¶
func (aspect *VoidAspect) Hit(instance *BlockInstance, player IPlayerClient, digStatus DigStatus) (destroyed bool)
func (*VoidAspect) Interact ¶
func (aspect *VoidAspect) Interact(instance *BlockInstance, player IPlayerClient)
func (*VoidAspect) InventoryClick ¶
func (aspect *VoidAspect) InventoryClick(instance *BlockInstance, player IPlayerClient, click *Click)
func (*VoidAspect) InventoryUnsubscribed ¶
func (aspect *VoidAspect) InventoryUnsubscribed(instance *BlockInstance, player IPlayerClient)
func (*VoidAspect) Name ¶
func (aspect *VoidAspect) Name() string
func (*VoidAspect) Tick ¶
func (aspect *VoidAspect) Tick(instance *BlockInstance) bool
Source Files ¶
- aspect_common.go
- block_aspect.go
- block_chest.go
- block_dispenser.go
- block_furnace.go
- block_inv_common.go
- block_inventory.go
- block_loader.go
- block_mobspawner.go
- block_music.go
- block_recordplayer.go
- block_sapling.go
- block_sign.go
- block_standard.go
- block_todo.go
- block_type.go
- block_void.go
- block_workbench.go
- entity.go
- entity_factory.go
- furnace_data.go
- gamerules.go
- inv_chest.go
- inv_crafting.go
- inv_dispenser.go
- inv_furnace.go
- inventory.go
- item.go
- itemtype.go
- itemtype_loader.go
- mob.go
- mobtype.go
- object.go
- recipe.go
- recipe_loader.go
- slot.go
- stub.go
- tile_entity_base.go