provider

package
v0.0.0-...-18e7427 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 44 Imported by: 0

Documentation

Overview

Package provider bot implements a simple Minecraft client that can join a server or just ping it for getting information.

Runnable example could be found at examples/ .

Index

Constants

View Source
const DefaultPort = mcnet.DefaultPort
View Source
const ProtocolVersion = 763

ProtocolVersion is the protocol version number of minecraft net protocol

Variables

This section is empty.

Functions

func Advancements

func Advancements(c *Client, p pk.Packet, cancel context.CancelFunc) error

func AttachEntity

func AttachEntity(c *Client, p pk.Packet, cancel context.CancelFunc) error

func AwardStatistics

func AwardStatistics(c *Client, p pk.Packet, cancel context.CancelFunc) error

func BlockAction

func BlockAction(c *Client, p pk.Packet, cancel context.CancelFunc) error

func BlockChange

func BlockChange(c *Client, p pk.Packet, cancel context.CancelFunc) error

func BlockEntityData

func BlockEntityData(c *Client, p pk.Packet, cancel context.CancelFunc) error

func BossBar

func BossBar(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Camera

func Camera(c *Client, p pk.Packet, cancel context.CancelFunc) error

func ChangeGameState

func ChangeGameState(c *Client, p pk.Packet, cancel context.CancelFunc) error

func ChatMessage

func ChatMessage(c *Client, p pk.Packet, cancel context.CancelFunc) error

func ChunkData

func ChunkData(c *Client, p pk.Packet, cancel context.CancelFunc) error

func CloseContainer

func CloseContainer(c *Client, p pk.Packet, cancel context.CancelFunc) error

func CloseWindow

func CloseWindow(c *Client, p pk.Packet, cancel context.CancelFunc) error

func CollectItem

func CollectItem(c *Client, p pk.Packet, cancel context.CancelFunc) error

func CombatEvent

func CombatEvent(c *Client, p pk.Packet, cancel context.CancelFunc) error

func CraftRecipeResponse

func CraftRecipeResponse(c *Client, p pk.Packet, cancel context.CancelFunc) error

func DestroyEntities

func DestroyEntities(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Disconnect

func Disconnect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func DisplayScoreboard

func DisplayScoreboard(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Effect

func Effect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Entity

func Entity(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityAnimation

func EntityAnimation(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityEffect

func EntityEffect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityEquipment

func EntityEquipment(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityHeadRotation

func EntityHeadRotation(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityPosition

func EntityPosition(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityPositionRotation

func EntityPositionRotation(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityProperties

func EntityProperties(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityRotation

func EntityRotation(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityStatus

func EntityStatus(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityTeleport

func EntityTeleport(c *Client, p pk.Packet, cancel context.CancelFunc) error

func EntityVelocity

func EntityVelocity(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Explosion

func Explosion(c *Client, p pk.Packet, cancel context.CancelFunc) error

func InitializeBorder

func InitializeBorder(c *Client, p pk.Packet, cancel context.CancelFunc) error

func JoinGame

func JoinGame(c *Client, p pk.Packet, cancel context.CancelFunc) error

func KeepAlive

func KeepAlive(c *Client, p pk.Packet, cancel context.CancelFunc) error

func LookAt

func LookAt(client *Client, p pk.Packet, cancel context.CancelFunc) error

func Map

func Map(c *Client, p pk.Packet, cancel context.CancelFunc) error

func MultiBlockChange

func MultiBlockChange(c *Client, p pk.Packet, cancel context.CancelFunc) error

func NamedSoundEffect

func NamedSoundEffect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func OpenSignEditor

func OpenSignEditor(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Particle

func Particle(c *Client, p pk.Packet, cancel context.CancelFunc) error

func PlayerAbilities

func PlayerAbilities(c *Client, p pk.Packet, cancel context.CancelFunc) error

func PlayerInfoRemove

func PlayerInfoRemove(c *Client, p pk.Packet, cancel context.CancelFunc) error

func PlayerInfoUpdate

func PlayerInfoUpdate(c *Client, p pk.Packet, cancel context.CancelFunc) error

Since Mojang has done an horrible job at designing this, I will simply ignore it until I need it, fuck off

func PlayerListHeaderAndFooter

func PlayerListHeaderAndFooter(c *Client, p pk.Packet, cancel context.CancelFunc) error

func PluginMessage

func PluginMessage(c *Client, p pk.Packet, cancel context.CancelFunc) error

func RemoveEntityEffect

func RemoveEntityEffect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func ResourcePackSend

func ResourcePackSend(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Respawn

func Respawn(c *Client, p pk.Packet, cancel context.CancelFunc) error

func RunTransactions

func RunTransactions(c *Client, cancel context.CancelFunc) error

func ScoreboardObjective

func ScoreboardObjective(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SelectAdvancementTab

func SelectAdvancementTab(c *Client, p pk.Packet, cancel context.CancelFunc) error

func ServerDifficulty

func ServerDifficulty(c *Client, p pk.Packet) error

func SetBlockDestroyStage

func SetBlockDestroyStage(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetContainerContent

func SetContainerContent(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetContainerProperty

func SetContainerProperty(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetContainerSlot

func SetContainerSlot(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetCooldown

func SetCooldown(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetExperience

func SetExperience(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetHeldItem

func SetHeldItem(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SetPassengers

func SetPassengers(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SoundEffect

func SoundEffect(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SpawnEntity

func SpawnEntity(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SpawnExperienceOrb

func SpawnExperienceOrb(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SpawnPlayer

func SpawnPlayer(c *Client, p pk.Packet, cancel context.CancelFunc) error

func SpawnPosition

func SpawnPosition(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Step

func Step(cl *Client, cancel context.CancelFunc) error

Step is called every tick I don't have to code all the physic by myself thx minecrossoft 🙏

func SynchronizePlayerPosition

func SynchronizePlayerPosition(c *Client, p pk.Packet, cancel context.CancelFunc) error

func TabComplete

func TabComplete(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Teams

func Teams(c *Client, p pk.Packet, cancel context.CancelFunc) error

func TimeUpdate

func TimeUpdate(c *Client, p pk.Packet, cancel context.CancelFunc) error

func Title

func Title(c *Client, p pk.Packet, cancel context.CancelFunc) error

func UnloadChunk

func UnloadChunk(c *Client, p pk.Packet, cancel context.CancelFunc) error

func UnlockRecipes

func UnlockRecipes(c *Client, p pk.Packet, cancel context.CancelFunc) error

func UpdateHealth

func UpdateHealth(c *Client, p pk.Packet, cancel context.CancelFunc) error

func UpdateScore

func UpdateScore(c *Client, p pk.Packet, cancel context.CancelFunc) error

func VehicleMove

func VehicleMove(c *Client, p pk.Packet, cancel context.CancelFunc) error

Types

type Abilities

type Abilities struct {
	Invulnerable bool
	Flying       bool
	AllowFlying  bool
	InstantBreak bool
	CanBuild     bool
	FlyingSpeed  float64
	WalkingSpeed float64
}

func NewAbilities

func NewAbilities() *Abilities

func (*Abilities) ReadFrom

func (a *Abilities) ReadFrom(r io.Reader) (int64, error)

func (*Abilities) WriteTo

func (a *Abilities) WriteTo(w io.Writer) (int64, error)

type Client

type Client struct {
	Conn *net.Conn
	Auth data.Auth

	World      *world.World
	PlayerList *core.PlayerList
	Player     *Player

	Events      Events[Client]
	LoginPlugin map[string]func(data []byte) ([]byte, error)
}

Client is used to access Minecraft server

+--------------------------------+-------------------------------+
|                        Client framework                        |
+--------------------------------+-------------------------------+
|       World       |       PlayerList       | 	    Player       |
+-------------------+------------+-------------------------------+

func Attach

func Attach(c *Client) *Client

Attach attaches the core handlers to the client

func NewClient

func NewClient(auth data.Auth) *Client

NewClient creates a new Client If you wish to use online-mode, refer to microsoft.LoginFromCache and microsoft.MinecraftLogin

func (*Client) Close

func (cl *Client) Close() error

func (*Client) HandleGame

func (cl *Client) HandleGame() error

HandleGame receive server packet and response them correctly. Note that HandleGame will block if you don't receive from Events.

func (*Client) JoinServer

func (cl *Client) JoinServer(addr string) (err error)

JoinServer connect a Minecraft server for playing the game. Using roughly the same way to parse address as minecraft.

func (*Client) JoinServerWithDialer

func (cl *Client) JoinServerWithDialer(d *net.Dialer, addr string) (err error)

JoinServerWithDialer is similar to JoinServer but using a Dialer.

type Events

type Events[T any] struct {
	// contains filtered or unexported fields
}

func (*Events[T]) AddListener

func (e *Events[T]) AddListener(listeners ...PacketHandler[T])

AddListener adds a listener to the event. The listener will be called when the packet with the same ID is received. The listener will be called in the order of priority. The listeners cannot have multiple same ID.

func (*Events[T]) AddTicker

func (e *Events[T]) AddTicker(tickers ...TickHandler[T])

func (*Events[T]) HandlePacket

func (e *Events[T]) HandlePacket(cl *T, p pk.Packet) error

func (*Events[T]) Tick

func (e *Events[T]) Tick(cl *T) error

type PacketHandler

type PacketHandler[T any] struct {
	ID       int32
	Priority int
	F        func(*T, pk.Packet, context.CancelFunc) error
}

type Player

type Player struct {
	Settings     basic.Settings
	World        *world.World
	Controller   *core.Controller
	Manager      *screen.Manager
	PlayerInfo   world.PlayerInfo
	WorldInfo    world.WorldInfo
	EntityPlayer *core.EntityPlayer
	Transactions *util.Queue[[]*transactions.SlotAction]
	Abilities    *Abilities

	// Player info
	ExpBar                    float64
	TotalExp                  int32
	Level                     int32
	IsSpawn                   bool
	JumpTicks                 int32
	JumpTriggerTime           int32
	JumpRidingTicks           int32
	JumpRidingScale           float64
	SprintTriggerTime         int32
	FallTicks                 float64
	FallDistance              float64
	StepHeight                float64
	PositionReminder          int
	CollidedHorizontally      bool
	CollidedHorizontallyMinor bool
	CollidedVertically        bool
	CollidedVerticallyBelow   bool
	Collided                  bool
	UsingItem                 bool
}

func NewPlayer

func NewPlayer(settings basic.Settings, clientWorld *world.World, info data.Auth) *Player

NewPlayer creates a new Player The player should not have access to the Client struct but the player needs access to the world and the current authentication information

The player should not be created before the client is created.

func (*Player) Chat

func (pl *Player) Chat(c *Client, msg string) error

func (*Player) Respawn

func (pl *Player) Respawn(c *Client) (err error)

func (*Player) RidingJumpable

func (pl *Player) RidingJumpable() bool

func (*Player) UseItem

func (pl *Player) UseItem(c *Client, hand enums.Hand) (err error)

type Status

type Status struct {
	Version struct {
		Name     string `json:"name"`
		Protocol int    `json:"protocol"`
	} `json:"version"`
	Players struct {
		Max    int `json:"max"`
		Online int `json:"online"`
		Sample []struct {
			Name string `json:"name"`
			ID   string `json:"id"`
		} `json:"sample"`
	} `json:"players"`
	Description        chat.Message `json:"description"`
	Favicon            string       `json:"favicon"`
	EnforcesSecureChat bool         `json:"enforcesSecureChat"`
}

func PingAndList

func PingAndList(addr string) (Status, time.Duration, error)

PingAndList check server status and list online player. Returns a JSON data with server status, and the delay.

For more information for JSON format, see https://wiki.vg/Server_List_Ping#Response

func PingAndListContext

func PingAndListContext(ctx context.Context, addr string) (data Status, delay time.Duration, err error)

func PingAndListTimeout

func PingAndListTimeout(addr string, timeout time.Duration) (Status, time.Duration, error)

PingAndListTimeout is the version of PingAndList with max request time.

type TickHandler

type TickHandler[T any] struct {
	Priority int
	F        func(*T, context.CancelFunc) error
}

Jump to

Keyboard shortcuts

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