game

package
v0.0.0-...-f33b5a6 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlayerActionDig = PlayerActionType(iota)
	PlayerActionPlace
	PlayerActionUseItem
)

Variables

the world we are going to use

Functions

func BlockUpdate

func BlockUpdate(position minecraft.Position, blk block.Block)

This is done right after the chunk processes all of the block changes that happened in this tick the reason for this is to make sure the map is in the most updated state.

if you want to register future block updates just use the ticker to register a block update, and since right after the ticker the block updates happen it will just work

func GetPlayerCount

func GetPlayerCount() int32

func JoinPlayer

func JoinPlayer(player *Player)

Add a player to the server

func LeftPlayer

func LeftPlayer(player *Player)

func RegisterForTick

func RegisterForTick(cb func(), ticks int)

func StartGameLoop

func StartGameLoop()

Types

type BlockPlacement

type BlockPlacement struct {
	Hand            int32
	Location        minecraft.Position
	Face            minecraft.Face
	CursorPositionX float32
	CursorPositionY float32
	CursorPositionZ float32
}

type PendingChange

type PendingChange struct {
	Field      interface{}
	Value      interface{}
	ChangeFlag interface{}
}

type Player

type Player struct {
	// the socket
	socket.Socket

	// The entity player
	*entity.Player

	// Client settings we need to know about
	ViewDistance int

	// ping related
	Ping          time.Duration
	LastKeepAlive time.Time
	PingChanged   bool

	// The world we are in
	World *World

	ActionQueue *queue.Queue

	// the inventory of the player
	//	https://wiki.vg/images/1/13/Inventory-slots.png
	HeldItemIndex int
	Inventory     [46]*play.Slot
	// contains filtered or unexported fields
}

func NewPlayer

func NewPlayer(socket socket.Socket) *Player

func (*Player) Change

func (p *Player) Change(cb func())

func (*Player) ChangeHeldItem

func (p *Player) ChangeHeldItem(slot int)

func (*Player) String

func (p *Player) String() string

func (*Player) TransformItemToStateId

func (p *Player) TransformItemToStateId(itm *item.Item, face minecraft.Face) (uint16, bool)

Top level transformation function that turns an item to a block, this will also handle item uses like flint&steel and buckets.

The reason for that is that it is just easier to handle it on block placement rather than item use as the game sends more info

func (*Player) UnitVector

func (p *Player) UnitVector() math.Point

func (*Player) UpdateInventory

func (p *Player) UpdateInventory(slot int, item *play.Slot)

this is used when there is data from the player that should be updated on the server, this will also make sure to give back the player a confirmation about this

func (*Player) ViewRect

func (p *Player) ViewRect() *math.Rect

Get a rect with the area that a player can see

type PlayerAction

type PlayerAction struct {
	Type PlayerActionType
	Data interface{}
}

type PlayerActionType

type PlayerActionType int

type World

type World struct {
	// the minecraft world
	*world.World

	// The block changes in this world
	BlockChanges map[world.ChunkPos][]play.BlockRecord
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(generator world.Generator, provider world.Provider) *World

func (*World) AddPlayer

func (w *World) AddPlayer(player *Player)

func (*World) ForEntitiesInRange

func (w *World) ForEntitiesInRange(rect *math.Rect, cb func(entity entity.IEntity))

func (*World) RemovePlayer

func (w *World) RemovePlayer(p *Player)

func (*World) SendChunkToPlayer

func (w *World) SendChunkToPlayer(x, z int, p *Player)

func (*World) UpdateEntityPosition

func (w *World) UpdateEntityPosition(entity entity.IEntity)

Jump to

Keyboard shortcuts

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