dfscript

package module
v0.0.0-...-1870e70 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: MIT Imports: 56 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventLoop

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

func NewEventLoop

func NewEventLoop(vm *goja.Runtime, opts ...Option) *EventLoop

func (*EventLoop) ClearInterval

func (loop *EventLoop) ClearInterval(i *Interval)

ClearInterval cancels an Interval returned by SetInterval. ClearInterval is safe to call inside or outside the loop.

func (*EventLoop) ClearTimeout

func (loop *EventLoop) ClearTimeout(t *Timer)

ClearTimeout cancels a Timer returned by SetTimeout if it has not run yet. ClearTimeout is safe to call inside or outside the loop.

func (*EventLoop) Run

func (loop *EventLoop) Run(fn func(*goja.Runtime))

Run calls the specified function, starts the event loop and waits until there are no more delayed jobs to run after which it stops the loop and returns. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. Do NOT use this function while the loop is already running. Use RunOnLoop() instead. If the loop is already started it will panic.

func (*EventLoop) RunOnLoop

func (loop *EventLoop) RunOnLoop(fn func(*goja.Runtime)) bool

RunOnLoop schedules to run the specified function in the context of the loop as soon as possible. The order of the runs is preserved (i.e. the functions will be called in the same order as calls to RunOnLoop()) The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. It is safe to call inside or outside the loop. Returns true on success or false if the loop is terminated (see Terminate()).

func (*EventLoop) SetInterval

func (loop *EventLoop) SetInterval(fn func(*goja.Runtime), timeout time.Duration) *Interval

SetInterval schedules to repeatedly run the specified function in the context of the loop as soon as possible after every specified timeout period. SetInterval returns an Interval which can be passed to ClearInterval. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. SetInterval is safe to call inside or outside the loop. If the loop is terminated (see Terminate()) returns nil.

func (*EventLoop) SetTimeout

func (loop *EventLoop) SetTimeout(fn func(*goja.Runtime), timeout time.Duration) *Timer

SetTimeout schedules to run the specified function in the context of the loop as soon as possible after the specified timeout period. SetTimeout returns a Timer which can be passed to ClearTimeout. The instance of goja.Runtime that is passed to the function and any Values derived from it must not be used outside the function. SetTimeout is safe to call inside or outside the loop. If the loop is terminated (see Terminate()) returns nil.

func (*EventLoop) Start

func (loop *EventLoop) Start()

Start the event loop in the background. The loop continues to run until Stop() is called. If the loop is already started it will panic.

func (*EventLoop) StartInForeground

func (loop *EventLoop) StartInForeground()

StartInForeground starts the event loop in the current goroutine. The loop continues to run until Stop() is called. If the loop is already started it will panic. Use this instead of Start if you want to recover from panics that may occur while calling native Go functions from within setInterval and setTimeout callbacks.

func (*EventLoop) Stop

func (loop *EventLoop) Stop() int

Stop the loop that was started with Start(). After this function returns there will be no more jobs executed by the loop. It is possible to call Start() or Run() again after this to resume the execution. Note, it does not cancel active timeouts (use Terminate() instead if you want this). It is not allowed to run Start() (or Run()) and Stop() or Terminate() concurrently. Calling Stop() on a non-running loop has no effect. It is not allowed to call Stop() from the loop, because it is synchronous and cannot complete until the loop is not running any jobs. Use StopNoWait() instead. return number of jobs remaining

func (*EventLoop) StopNoWait

func (loop *EventLoop) StopNoWait()

StopNoWait tells the loop to stop and returns immediately. Can be used inside the loop. Calling it on a non-running loop has no effect.

func (*EventLoop) Terminate

func (loop *EventLoop) Terminate()

Terminate stops the loop and clears all active timeouts and intervals. After it returns there are no active timers or goroutines associated with the loop. Any attempt to submit a task (by using RunOnLoop(), SetTimeout() or SetInterval()) will not succeed. After being terminated the loop can be restarted again by using Start() or Run(). This method must not be called concurrently with Stop*(), Start(), or Run().

type Immediate

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

type Interval

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

type Option

type Option func(*EventLoop)

func EnableConsole

func EnableConsole(enableConsole bool) Option

EnableConsole controls whether the "console" module is loaded into the runtime used by the loop. By default, loops are created with the "console" module loaded, pass EnableConsole(false) to NewEventLoop to disable this behavior.

func WithRegistry

func WithRegistry(registry *require.Registry) Option

type PlayerHandler

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

func (*PlayerHandler) HandleAttackEntity

func (p *PlayerHandler) HandleAttackEntity(ctx *player.Context, ent world.Entity, force *float64, height *float64, critical *bool)

func (*PlayerHandler) HandleBlockBreak

func (p *PlayerHandler) HandleBlockBreak(ctx *player.Context, pos cube.Pos, drops *[]item.Stack, xp *int)

func (*PlayerHandler) HandleBlockPick

func (p *PlayerHandler) HandleBlockPick(ctx *player.Context, pos cube.Pos, b world.Block)

func (*PlayerHandler) HandleBlockPlace

func (p *PlayerHandler) HandleBlockPlace(ctx *player.Context, pos cube.Pos, b world.Block)

func (*PlayerHandler) HandleChangeWorld

func (p *PlayerHandler) HandleChangeWorld(pl *player.Player, before, after *world.World)

func (*PlayerHandler) HandleChat

func (p *PlayerHandler) HandleChat(ctx *player.Context, message *string)

func (*PlayerHandler) HandleCommandExecution

func (p *PlayerHandler) HandleCommandExecution(ctx *player.Context, command cmd.Command, args []string)

func (*PlayerHandler) HandleDeath

func (p *PlayerHandler) HandleDeath(pl *player.Player, src world.DamageSource, keepInv *bool)

func (*PlayerHandler) HandleDiagnostics

func (p *PlayerHandler) HandleDiagnostics(pl *player.Player, d session.Diagnostics)

func (*PlayerHandler) HandleExperienceGain

func (p *PlayerHandler) HandleExperienceGain(ctx *player.Context, amount *int)

func (*PlayerHandler) HandleFireExtinguish

func (p *PlayerHandler) HandleFireExtinguish(ctx *player.Context, pos cube.Pos)

func (*PlayerHandler) HandleFoodLoss

func (p *PlayerHandler) HandleFoodLoss(ctx *player.Context, from int, to *int)

func (*PlayerHandler) HandleHeal

func (p *PlayerHandler) HandleHeal(ctx *player.Context, health *float64, src world.HealingSource)

func (*PlayerHandler) HandleHeldSlotChange

func (p *PlayerHandler) HandleHeldSlotChange(ctx *player.Context, from int, to int)

func (*PlayerHandler) HandleHurt

func (p *PlayerHandler) HandleHurt(ctx *player.Context, damage *float64, immune bool, attackImmunity *time.Duration, src world.DamageSource)

func (*PlayerHandler) HandleItemConsume

func (p *PlayerHandler) HandleItemConsume(ctx *player.Context, i item.Stack)

func (*PlayerHandler) HandleItemDamage

func (p *PlayerHandler) HandleItemDamage(ctx *player.Context, i item.Stack, damage int)

func (*PlayerHandler) HandleItemDrop

func (p *PlayerHandler) HandleItemDrop(ctx *player.Context, i item.Stack)

func (*PlayerHandler) HandleItemPickup

func (p *PlayerHandler) HandleItemPickup(ctx *player.Context, i *item.Stack)

func (*PlayerHandler) HandleItemRelease

func (p *PlayerHandler) HandleItemRelease(ctx *player.Context, i item.Stack, dur time.Duration)

func (*PlayerHandler) HandleItemUse

func (p *PlayerHandler) HandleItemUse(ctx *player.Context)

func (*PlayerHandler) HandleItemUseOnBlock

func (p *PlayerHandler) HandleItemUseOnBlock(ctx *player.Context, pos cube.Pos, face cube.Face, clickFace mgl64.Vec3)

func (*PlayerHandler) HandleItemUseOnEntity

func (p *PlayerHandler) HandleItemUseOnEntity(ctx *player.Context, e world.Entity)

func (*PlayerHandler) HandleJump

func (p *PlayerHandler) HandleJump(pl *player.Player)

func (*PlayerHandler) HandleLecternPageTurn

func (p *PlayerHandler) HandleLecternPageTurn(ctx *player.Context, pos cube.Pos, oldPage int, newPage *int)

func (*PlayerHandler) HandleMove

func (p *PlayerHandler) HandleMove(ctx *player.Context, newPos mgl64.Vec3, newRot cube.Rotation)

func (*PlayerHandler) HandlePunchAir

func (p *PlayerHandler) HandlePunchAir(ctx *player.Context)

func (*PlayerHandler) HandleQuit

func (p *PlayerHandler) HandleQuit(pl *player.Player)

func (*PlayerHandler) HandleRespawn

func (p *PlayerHandler) HandleRespawn(pl *player.Player, pos *mgl64.Vec3, w **world.World)

func (*PlayerHandler) HandleSignEdit

func (p *PlayerHandler) HandleSignEdit(ctx *player.Context, pos cube.Pos, frontSide bool, oldText string, newText string)

func (*PlayerHandler) HandleSkinChange

func (p *PlayerHandler) HandleSkinChange(ctx *player.Context, skin *skin.Skin)

func (*PlayerHandler) HandleStartBreak

func (p *PlayerHandler) HandleStartBreak(ctx *player.Context, pos cube.Pos)

func (*PlayerHandler) HandleTeleport

func (p *PlayerHandler) HandleTeleport(ctx *player.Context, pos mgl64.Vec3)

func (*PlayerHandler) HandleToggleSneak

func (p *PlayerHandler) HandleToggleSneak(ctx *player.Context, after bool)

func (*PlayerHandler) HandleToggleSprint

func (p *PlayerHandler) HandleToggleSprint(ctx *player.Context, after bool)

func (*PlayerHandler) HandleTransfer

func (p *PlayerHandler) HandleTransfer(ctx *player.Context, addr *net.UDPAddr)

type Runtime

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

func NewRuntime

func NewRuntime(s *server.Server, scriptDir string) (*Runtime, error)

func (*Runtime) AddWorld

func (r *Runtime) AddWorld(w *world.World) world.Handler

func (*Runtime) Close

func (r *Runtime) Close()

func (*Runtime) Loop

func (r *Runtime) Loop() *EventLoop

func (*Runtime) PlayerJoin

func (r *Runtime) PlayerJoin(p *player.Player) player.Handler

func (*Runtime) RemoveWorld

func (r *Runtime) RemoveWorld(name string)

func (*Runtime) Run

func (r *Runtime) Run(script string) bool

func (*Runtime) VM

func (r *Runtime) VM() *goja.Runtime

func (*Runtime) World

func (r *Runtime) World(name string) *world.World

type SqlDB

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

func (SqlDB) Begin

func (s SqlDB) Begin() (SqlTx, error)

func (SqlDB) Close

func (s SqlDB) Close() error

func (SqlDB) Exec

func (s SqlDB) Exec(query string, args ...any) (sql.Result, error)

func (SqlDB) Ping

func (s SqlDB) Ping() error

func (SqlDB) Prepare

func (s SqlDB) Prepare(query string) (SqlStmt, error)

func (SqlDB) Query

func (s SqlDB) Query(query string, args ...any) ([]map[string]any, error)

func (SqlDB) QueryRow

func (s SqlDB) QueryRow(query string, args ...any) (map[string]any, error)

func (SqlDB) SetConnMaxIdleTime

func (s SqlDB) SetConnMaxIdleTime(d time.Duration)

func (SqlDB) SetConnMaxLifetime

func (s SqlDB) SetConnMaxLifetime(d time.Duration)

func (SqlDB) SetMaxIdleConns

func (s SqlDB) SetMaxIdleConns(n int)

func (SqlDB) SetMaxOpenConns

func (s SqlDB) SetMaxOpenConns(n int)

func (SqlDB) Stats

func (s SqlDB) Stats() sql.DBStats

type SqlStmt

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

func (SqlStmt) Close

func (s SqlStmt) Close() error

func (SqlStmt) Exec

func (s SqlStmt) Exec(args ...any) (sql.Result, error)

func (SqlStmt) Query

func (s SqlStmt) Query(args ...any) ([]map[string]any, error)

func (SqlStmt) QueryRow

func (s SqlStmt) QueryRow(args ...any) map[string]any

type SqlTx

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

func (SqlTx) Commit

func (t SqlTx) Commit() error

func (SqlTx) Exec

func (t SqlTx) Exec(query string, args ...any) (sql.Result, error)

func (SqlTx) Prepare

func (t SqlTx) Prepare(query string) (SqlStmt, error)

func (SqlTx) Query

func (t SqlTx) Query(query string, args ...any) ([]map[string]any, error)

func (SqlTx) QueryRow

func (t SqlTx) QueryRow(query string, args ...any) (map[string]any, error)

func (SqlTx) Rollback

func (t SqlTx) Rollback() error

func (SqlTx) Stmt

func (t SqlTx) Stmt(stmt SqlStmt) SqlStmt

type Timer

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

type WorldHandler

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

func (*WorldHandler) HandleBlockBurn

func (w *WorldHandler) HandleBlockBurn(ctx *world.Context, pos cube.Pos)

func (*WorldHandler) HandleClose

func (w *WorldHandler) HandleClose(tx *world.Tx)

func (*WorldHandler) HandleCropTrample

func (w *WorldHandler) HandleCropTrample(ctx *world.Context, pos cube.Pos)

func (*WorldHandler) HandleEntityDespawn

func (w *WorldHandler) HandleEntityDespawn(tx *world.Tx, e world.Entity)

func (*WorldHandler) HandleEntitySpawn

func (w *WorldHandler) HandleEntitySpawn(tx *world.Tx, e world.Entity)

func (*WorldHandler) HandleExplosion

func (w *WorldHandler) HandleExplosion(ctx *world.Context, position mgl64.Vec3, entities *[]world.Entity, blocks *[]cube.Pos, itemDropChance *float64, spawnFire *bool)

func (*WorldHandler) HandleFireSpread

func (w *WorldHandler) HandleFireSpread(ctx *world.Context, from, to cube.Pos)

func (*WorldHandler) HandleLeavesDecay

func (w *WorldHandler) HandleLeavesDecay(ctx *world.Context, pos cube.Pos)

func (*WorldHandler) HandleLiquidDecay

func (w *WorldHandler) HandleLiquidDecay(ctx *world.Context, pos cube.Pos, before, after world.Liquid)

func (*WorldHandler) HandleLiquidFlow

func (w *WorldHandler) HandleLiquidFlow(ctx *world.Context, from, into cube.Pos, liquid world.Liquid, replaced world.Block)

func (*WorldHandler) HandleLiquidHarden

func (w *WorldHandler) HandleLiquidHarden(ctx *world.Context, pos cube.Pos, liquid, otherLiquid, newBlock world.Block)

func (*WorldHandler) HandleSound

func (w *WorldHandler) HandleSound(ctx *world.Context, s world.Sound, pos mgl64.Vec3)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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