gamerules

package
v0.0.0-...-93088af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2013 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxStackDefault = ItemCount(64)
)

Variables

View Source
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.

View Source
var CowType = MobType{MobTypeIdCow, "cow"}
View Source
var CreeperType = MobType{MobTypeIdCreeper, "creeper"}
View Source
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,
	"FishingFloat":   NewFishingFloat,
}
View Source
var GhastType = MobType{MobTypeIdGhast, "ghast"}
View Source
var GiantZombieType = MobType{MobTypeIdGiantZombie, "giantzombie"}
View Source
var HenType = MobType{MobTypeIdHen, "hen"}
View Source
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.

View Source
var PigType = MobType{MobTypeIdPig, "pig"}
View Source
var SheepType = MobType{MobTypeIdSheep, "sheep"}
View Source
var SkeletonType = MobType{MobTypeIdSkeleton, "skeleton"}
View Source
var SlimeType = MobType{MobTypeIdSlime, "slime"}
View Source
var SpiderType = MobType{MobTypeIdSpider, "spider"}
View Source
var SquidType = MobType{MobTypeIdSquid, "squid"}
View Source
var TileEntityCreateByName = map[string]func() ITileEntity{
	"Chest":        NewChestTileEntity,
	"Furnace":      NewFurnaceTileEntity,
	"Trap":         NewDispenserTileEntity,
	"Sign":         NewSignTileEntity,
	"MobSpawner":   NewMobSpawnerTileEntity,
	"Music":        NewMusicTileEntity,
	"RecordPlayer": NewRecordPlayerTileEntity,
	"Workbench":    NewWorkbenchTileEntity,
}
View Source
var WolfType = MobType{MobTypeIdWolf, "wolf"}
View Source
var ZombiePigmanType = MobType{MobTypeIdZombiePigman, "zombiepigman"}
View Source
var ZombieType = MobType{MobTypeIdZombie, "zombie"}

Functions

func LoadGameRules

func LoadGameRules(blocksDefFile, itemsDefFile, recipesDefFile, furnaceDefFile, userDefFile, groupDefFile string) (err error)

func SaveBlockDefs

func SaveBlockDefs(writer io.Writer, blocks BlockTypeList) (err error)

Types

type BlockAttrs

type BlockAttrs struct {
	Name    string
	Opacity int8

	Destructable    bool
	Solid           bool
	Replaceable     bool
	Attachable      bool
	BlastResistance float32
	Luminance       int8
	// contains filtered or unexported fields
}

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 Click

type Click struct {
	SlotId       SlotId
	Cursor       Slot
	RightClick   bool
	ShiftClick   bool
	TxId         TxId
	ExpectedSlot Slot
}

type Cow

type Cow struct {
	Mob
}

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) MarshalNbt

func (inv *CraftingInventory) MarshalNbt(tag nbt.Compound) (err error)

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 Hen

type Hen struct {
	Mob
}

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

	// SpawnPackets appends and returns the packets required to tell a client
	// about the existance and current state of the entity.
	SpawnPackets([]proto.IPacket) []proto.IPacket

	// SendUpdate appends and returns the packets required to tell a client about
	// the new state of the entity since the last SendUpdate or SendSpawn.
	UpdatePackets([]proto.IPacket) []proto.IPacket

	// 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 proto.IPacket)

	// 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)

	// Get the maximum number of players
	GetMaxPlayers() int
}

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.ItemSlotSlice
	GetProtoSlots(slots proto.ItemSlotSlice)
	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 NewEnderCrystal

func NewEnderCrystal() 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 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.ItemSlotSlice)

	// 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

func NewWorkbenchTileEntity

func NewWorkbenchTileEntity() ITileEntity

Creates a new tile entity for a chest. UnmarshalNbt and SetChunk must be called before any other methods.

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

func (inv *Inventory) CanTakeItem(item *Slot) bool

CanTakeItem returns true if it can take at least one item from the passed Slot.

func (*Inventory) Click

func (inv *Inventory) Click(click *Click) TxState

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) GetProtoSlots

func (inv *Inventory) GetProtoSlots(slots proto.ItemSlotSlice)

WriteProtoSlots stores into the slots parameter the proto version of the item data in the inventory. Precondition: len(slots) == len(inv.slots)

func (*Inventory) Init

func (inv *Inventory) Init(size int)

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.ItemSlotSlice

func (*Inventory) MarshalNbt

func (inv *Inventory) MarshalNbt(tag nbt.Compound) (err error)

func (*Inventory) NumSlots

func (inv *Inventory) NumSlots() SlotId

func (*Inventory) PutItem

func (inv *Inventory) PutItem(item *Slot)

PutItem attempts to put the given item into the inventory.

func (*Inventory) SetSubscriber

func (inv *Inventory) SetSubscriber(subscriber IInventorySubscriber)

func (*Inventory) Slot

func (inv *Inventory) Slot(slotId SlotId) Slot

func (*Inventory) SlotUnmarshalNbt

func (inv *Inventory) SlotUnmarshalNbt(tag nbt.Compound, slotId SlotId) (err error)

func (*Inventory) TakeAllItems

func (inv *Inventory) TakeAllItems() (items []Slot)

TakeAllItems empties the inventory, and returns all items that were inside it inside a slice of Slots.

func (*Inventory) TakeOneItem

func (inv *Inventory) TakeOneItem(slotId SlotId, into *Slot)

func (*Inventory) TakeOnlyClick

func (inv *Inventory) TakeOnlyClick(click *Click) TxState

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) UnmarshalNbt

func (inv *Inventory) UnmarshalNbt(tag nbt.Compound) (err error)

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
}

func NewItem

func NewItem(itemTypeId ItemTypeId, count ItemCount, data ItemData, position AbsXyz, velocity AbsVelocity, pickupImmunity Ticks) (item *Item)

func (*Item) GetSlot

func (item *Item) GetSlot() *Slot

func (*Item) MarshalNbt

func (item *Item) MarshalNbt(tag nbt.Compound) (err error)

func (*Item) SpawnPackets

func (item *Item) SpawnPackets(pkts []proto.IPacket) []proto.IPacket

func (*Item) UnmarshalNbt

func (item *Item) UnmarshalNbt(tag nbt.Compound) (err error)

func (*Item) UpdatePackets

func (item *Item) UpdatePackets(pkts []proto.IPacket) []proto.IPacket

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.EntityMetadataTable

func (*Mob) Init

func (mob *Mob) Init(id EntityMobType)

func (*Mob) MarshalNbt

func (mob *Mob) MarshalNbt(tag nbt.Compound) (err error)

func (*Mob) SetBurning

func (mob *Mob) SetBurning(burn bool)

func (*Mob) SetLook

func (mob *Mob) SetLook(look LookDegrees)

func (*Mob) SpawnPackets

func (mob *Mob) SpawnPackets(pkts []proto.IPacket) []proto.IPacket

func (*Mob) Tick

func (mob *Mob) Tick(blockQuerier physics.IBlockQuerier) (leftBlock bool)

func (*Mob) UnmarshalNbt

func (mob *Mob) UnmarshalNbt(tag nbt.Compound) (err error)

func (*Mob) UpdatePackets

func (mob *Mob) UpdatePackets(pkts []proto.IPacket) []proto.IPacket

type MobSpawnerAspect

type MobSpawnerAspect struct {
	StandardAspect
}

func (MobSpawnerAspect) Name

func (aspect MobSpawnerAspect) Name() string

type MobType

type MobType struct {
	Id   EntityMobType
	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
}

func NewObject

func NewObject(objType ObjTypeId) (object *Object)

func (*Object) MarshalNbt

func (object *Object) MarshalNbt(tag nbt.Compound) (err error)

func (*Object) SpawnPackets

func (object *Object) SpawnPackets(pkts []proto.IPacket) []proto.IPacket

func (*Object) UnmarshalNbt

func (object *Object) UnmarshalNbt(tag nbt.Compound) (err error)

func (*Object) UpdatePackets

func (object *Object) UpdatePackets(pkts []proto.IPacket) []proto.IPacket

type Pig

type Pig struct {
	Mob
}

type Reaction

type Reaction struct {
	Output     ItemTypeId
	OutputData ItemData
}

Reaction describes the output of a furnace reaction.

type Recipe

type Recipe struct {
	Comment string
	Width   byte
	Height  byte
	Input   []Slot
	Output  Slot
}

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 Sheep

type Sheep struct {
	Mob
}

type SignAspect

type SignAspect struct {
	StandardAspect
}

func (SignAspect) Name

func (aspect SignAspect) Name() string

type Skeleton

type Skeleton struct {
	Mob
}

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

func (s *Slot) Add(src *Slot) (changed bool)

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

func (s *Slot) AddOne(src *Slot) (changed bool)

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

func (s *Slot) AddWhole(src *Slot) (changed bool)

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) Attr

func (s *Slot) Attr() (ItemTypeId, ItemCount, ItemData)

func (*Slot) Clear

func (s *Slot) Clear()

func (*Slot) Decrement

func (s *Slot) Decrement() (changed bool)

Decrement destroys one item count from the subject slot.

func (*Slot) Equals

func (s *Slot) Equals(other *Slot) bool

func (*Slot) EquipmentUpdatePacket

func (s *Slot) EquipmentUpdatePacket(entityId EntityId, slotId SlotId) *proto.PacketEntityEquipment

func (*Slot) IsCompatible

func (s *Slot) IsCompatible(other *Slot) bool

func (*Slot) IsEmpty

func (s *Slot) IsEmpty() bool

func (*Slot) IsSameType

func (s *Slot) IsSameType(other *Slot) bool

func (*Slot) IsValidType

func (s *Slot) IsValidType() (ok bool)

func (*Slot) ItemType

func (s *Slot) ItemType() (itemType *ItemType)

func (*Slot) MarshalNbt

func (s *Slot) MarshalNbt(tag nbt.Compound) (err error)

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) Normalize

func (s *Slot) Normalize()

func (*Slot) SetItemSlot

func (s *Slot) SetItemSlot(itemSlot *proto.ItemSlot)

func (*Slot) SetWindowSlot

func (s *Slot) SetWindowSlot(windowSlot *proto.ItemSlot)

func (*Slot) Split

func (s *Slot) Split(src *Slot) (changed bool)

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.

func (*Slot) Swap

func (s *Slot) Swap(src *Slot) (changed bool)

Swaps the contents of the slots. Returns true if slots changed as a result.

func (*Slot) UnmarshalNbt

func (s *Slot) UnmarshalNbt(tag nbt.Compound) (err error)

func (*Slot) UpdatePacket

func (s *Slot) UpdatePacket(windowId WindowId, slotIndex SlotId) *proto.PacketWindowSetSlot

type Spider

type Spider struct {
	Mob
}

type Squid

type Squid struct {
	Mob
}

type StandardAspect

type StandardAspect struct {

	// Items, up to one of which will potentially spawn when block destroyed.
	DroppedItems []blockDropItem
	BreakOn      DigStatus
	ToolType     int8
	ToolRequired bool
	ToolDamage   int8
	// 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 {
	StandardAspect
	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

type Wolf

type Wolf struct {
	Mob
}

type Zombie

type Zombie struct {
	Mob
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL