mcc

package
v0.0.0-...-8a7963f Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockAir         = 0
	BlockStone       = 1
	BlockGrass       = 2
	BlockDirt        = 3
	BlockCobblestone = 4
	BlockWood        = 5
	BlockSapling     = 6
	BlockBedrock     = 7
	BlockActiveWater = 8
	BlockWater       = 9
	BlockActiveLava  = 10
	BlockLava        = 11
	BlockSand        = 12
	BlockGravel      = 13
	BlockGoldOre     = 14
	BlockIronOre     = 15
	BlockCoal        = 16
	BlockLog         = 17
	BlockLeaves      = 18
	BlockSponge      = 19
	BlockGlass       = 20
	BlockRed         = 21
	BlockOrange      = 22
	BlockYellow      = 23
	BlockLime        = 24
	BlockGreen       = 25
	BlockAqua        = 26
	BlockCyan        = 27
	BlockBlue        = 28
	BlockPurple      = 29
	BlockIndigo      = 30
	BlockViolet      = 31
	BlockMagenta     = 32
	BlockPink        = 33
	BlockBlack       = 34
	BlockGray        = 35
	BlockWhite       = 36
	BlockDandelion   = 37
	BlockRose        = 38
	BlockBrownShroom = 39
	BlockRedShroom   = 40
	BlockGold        = 41
	BlockIron        = 42
	BlockDoubleSlab  = 43
	BlockSlab        = 44
	BlockBrick       = 45
	BlockTNT         = 46
	BlockBookshelf   = 47
	BlockMoss        = 48
	BlockObsidian    = 49

	BlockMaxClassic   = BlockObsidian
	BlockCountClassic = BlockMaxClassic + 1

	BlockCobblestoneSlab = 50
	BlockRope            = 51
	BlockSandstone       = 52
	BlockSnow            = 53
	BlockFire            = 54
	BlockLightPink       = 55
	BlockForestGreen     = 56
	BlockBrown           = 57
	BlockDeepBlue        = 58
	BlockTurquoise       = 59
	BlockIce             = 60
	BlockCeramicTile     = 61
	BlockMagma           = 62
	BlockPillar          = 63
	BlockCrate           = 64
	BlockStoneBrick      = 65

	BlockMaxCPE   = BlockStoneBrick
	BlockCountCPE = BlockMaxCPE + 1

	BlockMax   = 255
	BlockCount = BlockMax + 1
)
View Source
const (
	FacePosX = 0
	FaceNegX = 1
	FacePosY = 2
	FaceNegY = 3
	FacePosZ = 4
	FaceNegZ = 5
)
View Source
const (
	CollideModeWalk  = 0
	CollideModeSwim  = 1
	CollideModeSolid = 2
)
View Source
const (
	WalkSoundNone   = 0
	WalkSoundWood   = 1
	WalkSoundGravel = 2
	WalkSoundGrass  = 3
	WalkSoundStone  = 4
	WalkSoundMetal  = 5
	WalkSoundGlass  = 6
	WalkSoundWool   = 7
	WalkSoundSand   = 8
	WalkSoundSnow   = 9
)
View Source
const (
	BlockShapeSprite = 0
	BlockShapeCube   = 16
)
View Source
const (
	DrawModeOpaque = 0
	DrawModeGlass  = 1
	DrawModeLeaves = 2
	DrawModeIce    = 3
	DrawModeGas    = 4
)
View Source
const (
	ColorBlack       = "&0"
	ColorDarkBlue    = "&1"
	ColorDarkGreen   = "&2"
	ColorDarkAqua    = "&3"
	ColorDarkRed     = "&4"
	ColorDarkPurple  = "&5"
	ColorGold        = "&6"
	ColorGray        = "&7"
	ColorDarkGray    = "&8"
	ColorBlue        = "&9"
	ColorGreen       = "&a"
	ColorAqua        = "&b"
	ColorRed         = "&c"
	ColorLightPurple = "&d"
	ColorYellow      = "&e"
	ColorWhite       = "&f"

	ColorDefault = ColorWhite
)
View Source
const (
	KeyModNone  = 0
	KeyModCtrl  = 1
	KeyModShift = 2
	KeyModAlt   = 4
)
View Source
const (
	MessageChat         = 0
	MessageStatus1      = 1
	MessageStatus2      = 2
	MessageStatus3      = 3
	MessageBottomRight1 = 11
	MessageBottomRight2 = 12
	MessageBottomRight3 = 13
	MessageAnnouncement = 100
)
View Source
const (
	ModelChicken   = "chicken"
	ModelCreeper   = "creeper"
	ModelCrocodile = "croc"
	ModelHumanoid  = "humanoid"
	ModelPig       = "pig"
	ModelPrinter   = "printer"
	ModelSheep     = "sheep"
	ModelSkeleton  = "skeleton"
	ModelSpider    = "spider"
	ModelZombie    = "zombie"
	ModelHead      = "head"
	ModelSitting   = "sitting"
	ModelChibi     = "chibi"
)
View Source
const (
	EntityPropRotX   = 1 << 0
	EntityPropRotY   = 1 << 1
	EntityPropRotZ   = 1 << 2
	EntityPropScaleX = 1 << 3
	EntityPropScaleY = 1 << 4
	EntityPropScaleZ = 1 << 5

	EntityPropAll = (EntityPropScaleZ << 1) - 1
)
View Source
const (
	ButtonLeft   = 0
	ButtonRight  = 1
	ButtonMiddle = 2
)
View Source
const (
	ButtonPress   = 0
	ButtonRelease = 1
)
View Source
const (
	EventTypePlayerLogin = iota
	EventTypePlayerJoin
	EventTypePlayerQuit
	EventTypePlayerChat
	EventTypePlayerClick
	EventTypeEntityLevelChange
	EventTypeEntityMove
	EventTypeBlockPlace
	EventTypeBlockBreak
	EventTypeLevelLoad
	EventTypeLevelUnload
	EventTypeLevelSave
	EventTypeCommand
)
View Source
const (
	WeatherSunny   = 0
	WeatherRaining = 1
	WeatherSnowing = 2
)
View Source
const (
	EnvPropWeather     = 1 << 0
	EnvPropTexturePack = 1 << 1

	EnvPropSideBlock       = 1 << 2
	EnvPropEdgeBlock       = 1 << 3
	EnvPropEdgeHeight      = 1 << 4
	EnvPropCloudHeight     = 1 << 5
	EnvPropMaxViewDistance = 1 << 6
	EnvPropCloudSpeed      = 1 << 7
	EnvPropWeatherSpeed    = 1 << 8
	EnvPropWeatherFade     = 1 << 9
	EnvPropExpFog          = 1 << 10
	EnvPropSideOffset      = 1 << 11

	EnvPropSkyColor     = 1 << 12
	EnvPropCloudColor   = 1 << 13
	EnvPropFogColor     = 1 << 14
	EnvPropAmbientColor = 1 << 15
	EnvPropDiffuseColor = 1 << 16

	EnvPropAll = (EnvPropDiffuseColor << 1) - 1
)
View Source
const (
	NbtTagEnd       = 0
	NbtTagByte      = 1
	NbtTagShort     = 2
	NbtTagInt       = 3
	NbtTagLong      = 4
	NbtTagFloat     = 5
	NbtTagDouble    = 6
	NbtTagByteArray = 7
	NbtTagString    = 8
	NbtTagList      = 9
	NbtTagCompound  = 10
	NbtTagIntArray  = 11
	NbtTagLongArray = 12

	NbtTagMax   = NbtTagLongArray
	NbtTagCount = NbtTagMax + 1
)
View Source
const (
	CpeClickDistance = iota
	CpeCustomBlocks
	CpeHeldBlock
	CpeTextHotKey
	CpeExtPlayerList
	CpeEnvColors
	CpeSelectionCuboid
	CpeBlockPermissions
	CpeChangeModel
	CpeEnvWeatherType
	CpeHackControl
	CpeMessageTypes
	CpePlayerClick
	CpeLongerMessages
	CpeBlockDefinitions
	CpeBlockDefinitionsExt
	CpeBulkBlockUpdate
	CpeTextColors
	CpeEnvMapAspect
	CpeEntityProperty
	CpeExtEntityPositions
	CpeTwoWayPing
	CpeInventoryOrder
	CpeInstantMOTD
	CpeFastMap
	CpeExtendedTextures

	CpeMax   = CpeExtendedTextures
	CpeCount = CpeMax + 1
)
View Source
const (
	ServerSoftware = "go-mcc"

	UpdateInterval    = 50 * time.Millisecond
	HeartbeatInterval = 45 * time.Second
	SaveInterval      = 5 * time.Minute
)

Variables

View Source
var BlockName = [BlockCountCPE]string{
	"air", "stone", "grass", "dirt", "cobblestone", "wood", "sapling",
	"bedrock", "active_water", "water", "active_lava", "lava", "sand",
	"gravel", "gold_ore", "iron_ore", "coal", "log", "leaves", "sponge",
	"glass", "red", "orange", "yellow", "lime", "green", "aqua", "cyan",
	"blue", "purple", "indigo", "violet", "magenta", "pink", "black",
	"gray", "white", "dandelion", "rose", "brown_shroom", "red_shroom",
	"gold", "iron", "doubleslab", "slab", "brick", "tnt", "bookshelf",
	"moss", "obsidian", "cobblestone_slab", "rope", "sandstone", "snow",
	"fire", "light_pink", "forest_green", "brown", "deep_blue", "turquoise",
	"ice", "ceramic_tile", "magma", "pillar", "crate", "stone_brick",
}
View Source
var DefaultRank = func() (rank Rank) {
	for i := 0; i < BlockCount; i++ {
		rank.CanPlace[i] = true
		rank.CanBreak[i] = true
	}

	banned := []byte{BlockBedrock, BlockActiveWater, BlockWater, BlockActiveLava, BlockLava}
	for _, block := range banned {
		rank.CanPlace[block] = false
	}
	rank.CanBreak[BlockBedrock] = false

	return
}()

DefaultRank stores the default player permissions.

View Source
var Extensions = [CpeCount]ExtEntry{
	{"ClickDistance", 1},
	{"CustomBlocks", 1},
	{"HeldBlock", 1},
	{"TextHotKey", 1},
	{"ExtPlayerList", 2},
	{"EnvColors", 1},
	{"SelectionCuboid", 1},
	{"BlockPermissions", 1},
	{"ChangeModel", 1},
	{"EnvWeatherType", 1},
	{"HackControl", 1},
	{"MessageTypes", 1},
	{"PlayerClick", 1},
	{"LongerMessages", 1},
	{"BlockDefinitions", 1},
	{"BlockDefinitionsExt", 2},
	{"BulkBlockUpdate", 1},
	{"TextColors", 1},
	{"EnvMapAspect", 1},
	{"EntityProperty", 1},
	{"ExtEntityPositions", 1},
	{"TwoWayPing", 1},
	{"InventoryOrder", 1},
	{"InstantMOTD", 1},
	{"FastMap", 1},
	{"ExtendedTextures", 1},
}

Functions

func FallbackBlock

func FallbackBlock(block byte) byte

FallbackBlock converts a CPE block to a similar vanilla-compatible one.

func IsValidMessage

func IsValidMessage(message string) bool

IsValidMessage reports whether message is a valid chat message.

func IsValidName

func IsValidName(name string) bool

IsValidName reports whether name is a valid entity name.

func NbtMarshal

func NbtMarshal(w io.Writer, name string, v interface{}) error

NbtMarshal writes the NBT representation of v into w. name specifies the name of the root tag.

func NbtUnmarshal

func NbtUnmarshal(r io.Reader, v interface{}) error

NbtUnmarshal reads NBT data from r into v.

func RandomUUID

func RandomUUID() (uuid [16]byte)

RandomUUID returns a random (Version 4) UUID.

func WordWrap

func WordWrap(message string, width int) (result []string)

WordWrap wraps message at width characters.

Types

type AABB

type AABB struct {
	Min, Max Vector3
}

AABB represents an axis-aligned bounding box.

type BlockBuffer

type BlockBuffer struct {
	// contains filtered or unexported fields
}

BlockBuffer is a queue of block changes to apply to a level.

func NewBlockBuffer

func NewBlockBuffer(level *Level) *BlockBuffer

NewBlockBuffer returns a new BlockBuffer to queue changes to level.

func (*BlockBuffer) Flush

func (buffer *BlockBuffer) Flush()

Flush flushes any pending changes to the underlying level.

func (*BlockBuffer) Set

func (buffer *BlockBuffer) Set(x, y, z int, block byte)

Set sets the block at the specified coordinates.

type BlockDefinition

type BlockDefinition struct {
	Name     string
	Fallback byte

	Speed       float64
	CollideMode byte
	WalkSound   byte

	BlockLight bool
	FullBright bool
	DrawMode   byte
	Textures   [6]int

	Shape byte
	AABB  AABB

	FogDensity byte
	Fog        RGB
}

BlockDefinition describes a custom block.

type ColorDesc

type ColorDesc struct {
	RGBA
	Code, Fallback byte
}

ColorDesc describes a chat color.

type Command

type Command struct {
	Name        string
	Description string
	Usage       string
	Permissions uint32
	Handler     CommandHandler
}

Command describes a command.

func (*Command) PrintUsage

func (command *Command) PrintUsage(sender CommandSender)

PrintUsage sends the command usage message to sender.

type CommandHandler

type CommandHandler func(sender CommandSender, command *Command, message string)

CommandHandler is the type of the function called to execute a command. The sender argument is the entity that invoked the command. The message argument contains the arguments of the command.

type CommandSender

type CommandSender interface {
	Server() *Server
	Name() string
	SendMessage(message string)
	CanExecute(command *Command) bool
}

A CommandSender is a generic entity that can execute commands and receive messages.

type Config

type Config struct {
	Port       int    `json:"server-port"`
	Name       string `json:"server-name"`
	MOTD       string `json:"motd"`
	Verify     bool   `json:"verify-names"`
	Public     bool   `json:"public"`
	MaxPlayers int    `json:"max-players"`
	Heartbeat  string `json:"heartbeat,omitempty"`
	MainLevel  string `json:"main-level"`
}

Config is used to configure a server.

type CwBlockDefinitionMap

type CwBlockDefinitionMap map[string]cwBlockDefinition

type CwMetadataMap

type CwMetadataMap map[string]interface{}

type CwStorage

type CwStorage struct {

	// FixSpawnPosition controls whether to attempt to parse the spawn
	// position as block coordinates. This format is incorrectly used by
	// some client software.
	FixSpawnPosition bool
	// contains filtered or unexported fields
}

CwStorage is an implementation of the LevelStorage interface that can handle ClassicWorld (.cw) levels.

func NewCwStorage

func NewCwStorage(dirPath string) *CwStorage

NewCwStorage creates a new CwStorage that uses dirPath as the working directory.

func (*CwStorage) Load

func (storage *CwStorage) Load(name string) (level *Level, err error)

Load implements LevelStorage.

func (*CwStorage) Save

func (storage *CwStorage) Save(level *Level) (err error)

Save implements LevelStorage.

type Entity

type Entity struct {
	Model string
	Props EntityProps

	DisplayName string
	SkinName    string

	ListName  string
	GroupName string
	GroupRank byte
	// contains filtered or unexported fields
}

Entity represents a base entity.

func NewEntity

func NewEntity(name string, server *Server) *Entity

NewEntity creates a new Entity with the specified name.

func (*Entity) ID

func (entity *Entity) ID() byte

func (*Entity) Level

func (entity *Entity) Level() *Level

func (*Entity) Location

func (entity *Entity) Location() Location

func (*Entity) Name

func (entity *Entity) Name() string

func (*Entity) Respawn

func (entity *Entity) Respawn()

Respawn respawns the entity to all relevant players.

func (*Entity) SendListName

func (entity *Entity) SendListName()

SendListName sends the tab list name of the entity to all relevant players.

func (*Entity) SendModel

func (entity *Entity) SendModel()

SendModel sends the model of the entity to all relevant players.

func (*Entity) SendProps

func (entity *Entity) SendProps(mask uint32)

SendProps sends the EntityProps of the entity to all relevant players. mask controls which properties are sent.

func (*Entity) Server

func (entity *Entity) Server() *Server

func (*Entity) Teleport

func (entity *Entity) Teleport(location Location)

Teleport teleports the entity to location.

func (*Entity) TeleportLevel

func (entity *Entity) TeleportLevel(level *Level)

TeleportLevel teleports the entity to the spawn location of level.

type EntityProps

type EntityProps struct {
	RotX, RotY, RotZ       float64
	ScaleX, ScaleY, ScaleZ float64
}

EntityProps holds various entity properties.

type EnvConfig

type EnvConfig struct {
	Weather     byte
	TexturePack string

	SideBlock       byte
	EdgeBlock       byte
	EdgeHeight      int
	CloudHeight     int
	MaxViewDistance int
	CloudSpeed      float64
	WeatherSpeed    float64
	WeatherFade     float64
	ExpFog          bool
	SideOffset      int

	SkyColor     NullRGB
	CloudColor   NullRGB
	FogColor     NullRGB
	AmbientColor NullRGB
	DiffuseColor NullRGB
}

EnvConfig specifies the appearance of a level.

type EventBlockBreak

type EventBlockBreak struct {
	Player  *Player
	Level   *Level
	Block   byte
	X, Y, Z int
	Cancel  bool
}

EventBlockBreak is dispatched when a player breaks a block. If the event is cancelled, the block will not be broken.

type EventBlockPlace

type EventBlockPlace struct {
	Player   *Player
	Level    *Level
	Block    byte
	OldBlock byte
	X, Y, Z  int
	Cancel   bool
}

EventBlockPlace is dispatched when a player places a block. If the event is cancelled, the block will not be placed.

type EventCommand

type EventCommand struct {
	Sender  CommandSender
	Command *Command
	Message string
	Allow   bool
}

EventCommand is dispatched before a command is executed.

type EventEntityLevelChange

type EventEntityLevelChange struct {
	Entity   *Entity
	From, To *Level
}

EventEntityLevelChange is dispatched when an entity changes level.

type EventEntityMove

type EventEntityMove struct {
	Entity   *Entity
	From, To Location
	Cancel   bool
}

EventEntityMove is dispatched when an entity moves. If the event is cancelled, the entity will not move.

type EventHandler

type EventHandler func(eventType int, event interface{})

EventHandler is the type of the function called to handle an event.

type EventLevelLoad

type EventLevelLoad struct {
	Level *Level
}

EventLevelLoad is dispatched when a level is loaded.

type EventLevelSave

type EventLevelSave struct {
	Level *Level
}

EventLevelSave is dispatched when a level is saved.

type EventLevelUnload

type EventLevelUnload struct {
	Level *Level
}

EventLevelUnload is dispatched when a level is unloaded.

type EventPlayerChat

type EventPlayerChat struct {
	Player  *Player
	Targets []*Player
	Message string
	Format  string
	Cancel  bool
}

EventPlayerChat is dispatched when a player sends a message. If the event is cancelled, the message will not be sent.

type EventPlayerClick

type EventPlayerClick struct {
	Player                 *Player
	Button, Action         byte
	Yaw, Pitch             float64
	Target                 *Entity
	BlockX, BlockY, BlockZ int
	BlockFace              byte
}

EventPlayerClick is dispatched when a player makes a mouse click. If the player is currently targeting another entity, Target will be set. If the player is currently targeting a block, BlockX, BlockY, BlockZ, BlockFace will be set.

type EventPlayerJoin

type EventPlayerJoin struct {
	Player *Player
}

EventPlayerJoin is dispatched when a player joins the server.

type EventPlayerLogin

type EventPlayerLogin struct {
	Player       *Player
	Cancel       bool
	CancelReason string
}

EventPlayerLogin is dispatched when a player attempts to log in. If the event is cancelled, the player will be kicked.

type EventPlayerQuit

type EventPlayerQuit struct {
	Player *Player
}

EventPlayerQuit is dispatched when a player leaves the server.

type ExtEntry

type ExtEntry struct {
	Name    string
	Version int
}

type FlatGenerator

type FlatGenerator struct {
	GrassHeight  int
	SurfaceBlock byte
	SoilBlock    byte
}

FlatGenerator is an implementation of the Generator interface that can generate flat grass levels.

func (*FlatGenerator) Generate

func (generator *FlatGenerator) Generate(level *Level)

Generate implements Generator.

type Generator

type Generator interface {
	Generate(level *Level)
}

Generator is the interface that must be implemented by level generators.

func NewFlatGenerator

func NewFlatGenerator(args ...string) Generator

type GeneratorFunc

type GeneratorFunc func(args ...string) Generator

GeneratorFunc is the type of function called to create a new generator.

type HackConfig

type HackConfig struct {
	ReachDistance   float64
	Flying          bool
	NoClip          bool
	Speeding        bool
	SpawnControl    bool
	ThirdPersonView bool
	JumpHeight      float64
}

HackConfig holds configuration for client hacks/cheats.

type HotkeyDesc

type HotkeyDesc struct {
	Label, Action string
	Key           int
	KeyMods       byte
}

HotKeyDesc describes a text hotkey.

type LavaSimulator

type LavaSimulator struct {
	Level *Level
	// contains filtered or unexported fields
}

LavaSimulator is an implementation of the Simulator interface that handles lava physics.

func (*LavaSimulator) Tick

func (simulator *LavaSimulator) Tick()

Tick implements Simulator.

func (*LavaSimulator) Update

func (simulator *LavaSimulator) Update(block, old byte, index int)

Update implements Simulator.

type Level

type Level struct {
	Width  int
	Height int
	Length int
	Blocks []byte
	Dirty  bool

	Name        string
	UUID        [16]byte
	TimeCreated time.Time
	MOTD        string
	Spawn       Location
	EnvConfig   EnvConfig
	HackConfig  HackConfig
	BlockDefs   []*BlockDefinition
	Inventory   []byte

	Metadata, MetadataCPE map[string]interface{}
	// contains filtered or unexported fields
}

Level represents a level, which contains blocks and various metadata.

func NewLevel

func NewLevel(name string, width, height, length int) *Level

NewLevel creates a new empty Level with the specified name and dimensions.

func (*Level) AddSimulator

func (level *Level) AddSimulator(simulator Simulator)

AddSimulator registers a physics simulator.

func (*Level) Clone

func (level *Level) Clone(name string) *Level

Clone returns a duplicate of the level.

func (*Level) DefaultEnvConfig

func (level *Level) DefaultEnvConfig() EnvConfig

DefaultEnvConfig returns the default EnvConfig for this level.

func (*Level) FillLayers

func (level *Level) FillLayers(yStart, yEnd int, block byte)

FillLayers fills the specified range of layers with block.

func (*Level) ForEachEntity

func (level *Level) ForEachEntity(fn func(*Entity))

ForEachEntity calls fn for each entity in the level.

func (*Level) ForEachPlayer

func (level *Level) ForEachPlayer(fn func(*Player))

ForEachPlayer calls fn for each player in the level.

func (*Level) GetBlock

func (level *Level) GetBlock(x, y, z int) byte

GetBlock returns the block at the specified coordinates.

func (*Level) InBounds

func (level *Level) InBounds(x, y, z int) bool

InBounds reports whether the specified coordinates are within the bounds of the level.

func (*Level) Index

func (level *Level) Index(x, y, z int) int

Index converts the specified coordinates to an array index.

func (*Level) Position

func (level *Level) Position(index int) (x, y, z int)

Position converts the specified array index to block coordinates.

func (*Level) RemoveSimulator

func (level *Level) RemoveSimulator(simulator Simulator)

RemoveSimulator unregisters a physics simulator.

func (*Level) SendEnvConfig

func (level *Level) SendEnvConfig(mask uint32)

SendEnvConfig sends the EnvConfig of the level to all relevant players. mask controls which properties are sent.

func (*Level) SendHackConfig

func (level *Level) SendHackConfig()

SendHackConfig sends the HackConfig of the level to all relevant players.

func (*Level) SendMOTD

func (level *Level) SendMOTD()

SendMOTD sends the MOTD of the level to all relevant players.

func (*Level) Server

func (level *Level) Server() *Server

func (*Level) SetBlock

func (level *Level) SetBlock(x, y, z int, block byte)

SetBlock sets the block at the specified coordinates.

func (*Level) SetBlockFast

func (level *Level) SetBlockFast(x, y, z int, block byte)

SetBlockFast sets the block at the specified coordinates without notifying the physics simulators.

func (*Level) Size

func (level *Level) Size() int

Size returns the number of blocks.

func (*Level) UpdateBlock

func (level *Level) UpdateBlock(x, y, z int)

UpdateBlock updates the block at the specified coordinates.

type LevelStorage

type LevelStorage interface {
	Load(name string) (*Level, error)
	Save(level *Level) error
}

LevelStorage is the interface that must be implemented by storage backends that can import and export levels.

type Location

type Location struct {
	X, Y, Z, Yaw, Pitch float64
}

Location represents the location of an entity in a world. Yaw and Pitch are specified in degrees.

type LvlStorage

type LvlStorage struct {
	// contains filtered or unexported fields
}

LvlStorage is an implementation of the LevelStorage interface that can handle MCSharp (.lvl) levels.

func NewLvlStorage

func NewLvlStorage(dirPath string) *LvlStorage

NewLvlStorage creates a new LvlStorage that uses dirPath as the working directory.

func (*LvlStorage) Load

func (storage *LvlStorage) Load(name string) (level *Level, err error)

Load implements LevelStorage.

func (*LvlStorage) Save

func (storage *LvlStorage) Save(level *Level) (err error)

Save implements LevelStorage.

type NullRGB

type NullRGB struct {
	Valid   bool
	R, G, B uint8
}

NullRGB represents a 24-bit RGB color that may be null.

type Player

type Player struct {
	*Entity

	Nickname string
	Rank     *Rank
	// contains filtered or unexported fields
}

Player represents a game client.

func NewPlayer

func NewPlayer(conn net.Conn, server *Server) *Player

NewPlayer returns a new Player.

func (*Player) CanExecute

func (player *Player) CanExecute(command *Command) bool

CanExecute implements CommandSender.

func (*Player) CanReach

func (player *Player) CanReach(x, y, z int) bool

CanReach reports whether the player can reach the block at the specified coordinates.

func (*Player) Disconnect

func (player *Player) Disconnect()

Disconnect closes the remote connection.

func (*Player) HasExtension

func (player *Player) HasExtension(extension int) bool

HasExtension reports whether the player has the specified CPE extension.

func (*Player) HeldBlock

func (player *Player) HeldBlock() byte

HeldBlock returns the block that the player is holding. If the player does not support the HeldBlock extension, the function returns BlockAir.

func (*Player) Kick

func (player *Player) Kick(reason string)

Kick kicks and disconnects the player.

func (*Player) RemoteAddr

func (player *Player) RemoteAddr() string

RemoteAddr returns the remote network address as a string.

func (*Player) ResetSelection

func (player *Player) ResetSelection(id byte)

ResetSelection resets the selection with the specified ID.

func (*Player) SendMessage

func (player *Player) SendMessage(message string)

SendMessage sends a message to the player.

func (*Player) SendMessageExt

func (player *Player) SendMessageExt(msgType int, message string)

SendMessageExt sends a message with the specified type to the player.

func (*Player) SendPermissions

func (player *Player) SendPermissions()

SendPermissions sends the block permissions to the player.

func (*Player) SetHeldBlock

func (player *Player) SetHeldBlock(block byte, lock bool)

SetHeldBlock changes the block that the player is holding. lock controls whether the player can change the held block.

func (*Player) SetSelection

func (player *Player) SetSelection(id byte, label string, box AABB, color RGBA)

SetSelection marks a cuboid selection.

func (*Player) SetSpawn

func (player *Player) SetSpawn()

SetSpawn sets the spawn location of the player to the current player location.

type Plugin

type Plugin interface {
	Name() string
	Enable(*Server)
	Disable(*Server)
}

Plugin is the interface that must be implemented by all plugins.

type RGB

type RGB struct {
	R, G, B uint8
}

RGB represents a 24-bit RGB color.

type RGBA

type RGBA struct {
	R, G, B, A uint8
}

RGBA represents a 32-bit RGBA color.

type Rank

type Rank struct {
	Name        string
	Tag         string
	Permissions uint32
	Rules       map[string]bool
	CanPlace    [BlockCount]bool
	CanBreak    [BlockCount]bool
}

Rank represents a group of players that have the same permissions.

func (*Rank) CanExecute

func (rank *Rank) CanExecute(command *Command) bool

CanExecute returns whether the members of the rank can execute command.

type SandSimulator

type SandSimulator struct {
	Level *Level
}

SandSimulator is an implementation of the Simulator interface that handles falling block physics.

func (*SandSimulator) Tick

func (simulator *SandSimulator) Tick()

Tick implements Simulator.

func (*SandSimulator) Update

func (simulator *SandSimulator) Update(block, old byte, index int)

Update implements Simulator.

type Server

type Server struct {
	Config    *Config
	MainLevel *Level
	URL       string
	Colors    []ColorDesc
	Hotkeys   []HotkeyDesc
	// contains filtered or unexported fields
}

Server represents a game server.

func NewServer

func NewServer(config *Config, storage LevelStorage) *Server

NewServer returns a new Server.

func (*Server) AddCommand

func (server *Server) AddCommand(command *Command)

AddCommand registers the specified command.

func (*Server) AddEntity

func (server *Server) AddEntity(entity *Entity) bool

AddEntity adds entity to the server. It returns true on success, or false if the server is full.

func (*Server) AddGenerator

func (server *Server) AddGenerator(name string, fn GeneratorFunc)

AddGenerator registers a level generator.

func (*Server) AddHandler

func (server *Server) AddHandler(eventType int, handler EventHandler)

AddHandler registers a handler for the specified event type.

func (*Server) AddLevel

func (server *Server) AddLevel(level *Level)

AddLevel adds level to the server.

func (*Server) AddPlayer

func (server *Server) AddPlayer(player *Player)

AddPlayer adds player to the server.

func (*Server) AddPlugin

func (server *Server) AddPlugin(plugin Plugin)

AddPlugin registers and enables plugin.

func (*Server) BroadcastMessage

func (server *Server) BroadcastMessage(message string)

BroadcastMessage broadcasts a message to all players.

func (*Server) ExecuteCommand

func (server *Server) ExecuteCommand(sender CommandSender, message string)

ExecuteCommand executes the command specified by message, if it exists.

func (*Server) FindCommand

func (server *Server) FindCommand(name string) *Command

Findcommand returns the command with the specified name.

func (*Server) FindEntity

func (server *Server) FindEntity(name string) *Entity

FindEntity returns the entity with the specified name.

func (*Server) FindEntityByID

func (server *Server) FindEntityByID(id byte) *Entity

FindEntityByID returns the entity with the specified ID.

func (*Server) FindLevel

func (server *Server) FindLevel(name string) *Level

FindLevel returns the level with the specified name.

func (*Server) FindPlayer

func (server *Server) FindPlayer(name string) *Player

FindPlayer returns the player with the specified name.

func (*Server) FireEvent

func (server *Server) FireEvent(eventType int, event interface{})

FireEvent dispatches event to the server.

func (*Server) ForEachCommand

func (server *Server) ForEachCommand(fn func(*Command))

ForEachCommand calls fn for each command.

func (*Server) ForEachEntity

func (server *Server) ForEachEntity(fn func(*Entity))

ForEachEntity calls fn for each entity.

func (*Server) ForEachLevel

func (server *Server) ForEachLevel(fn func(*Level))

ForEachLevel calls fn for each level.

func (*Server) ForEachPlayer

func (server *Server) ForEachPlayer(fn func(*Player))

ForEachPlayer calls fn for each player.

func (*Server) LoadLevel

func (server *Server) LoadLevel(name string) (*Level, error)

LoadLevel attempts to load the level with the specified name.

func (*Server) NewGenerator

func (server *Server) NewGenerator(name string, args ...string) Generator

NewGenerator returns a new generator with the specified options.

func (*Server) RemoveEntity

func (server *Server) RemoveEntity(entity *Entity)

RemoveEntity removes entity from the server.

func (*Server) RemoveLevel

func (server *Server) RemoveLevel(level *Level)

RemoveLevel removes level from the server. All players in level will be moved to the main level.

func (*Server) RemovePlayer

func (server *Server) RemovePlayer(player *Player)

RemovePlayer removes player from the server.

func (*Server) SaveLevel

func (server *Server) SaveLevel(level *Level)

SaveLevel saves level.

func (*Server) Start

func (server *Server) Start(wg *sync.WaitGroup) (err error)

Start starts the server. When the server is stopped, wg will be notified.

func (*Server) Stop

func (server *Server) Stop()

Stop stops the server, disconnects all clients, disables all plugins and unloads all levels.

func (*Server) UnloadLevel

func (server *Server) UnloadLevel(level *Level)

UnloadLevel saves and removes level from the server. All players in level will be moved to the main level.

type Simulator

type Simulator interface {
	Update(block, old byte, index int)
	Tick()
}

Simulator is the interface that must be implemented by block-based physics simulators.

type Vector3

type Vector3 struct {
	X, Y, Z int
}

Vector3 represents a three-dimensional integer vector.

type WaterSimulator

type WaterSimulator struct {
	Level *Level
	// contains filtered or unexported fields
}

WaterSimulator is an implementation of the Simulator interface that handles water and sponge physics.

func (*WaterSimulator) Tick

func (simulator *WaterSimulator) Tick()

Tick implements Simulator.

func (*WaterSimulator) Update

func (simulator *WaterSimulator) Update(block, old byte, index int)

Update implements Simulator.

Jump to

Keyboard shortcuts

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