github.com/df-mc/dragonfly@v0.9.13/server/world/provider.go (about)

     1  package world
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/goleveldb/leveldb"
     6  	"github.com/google/uuid"
     7  	"io"
     8  )
     9  
    10  // Provider represents a value that may provide world data to a World value. It usually does the reading and
    11  // writing of the world data so that the World may use it.
    12  type Provider interface {
    13  	io.Closer
    14  	// Settings loads the settings for a World and returns them.
    15  	Settings() *Settings
    16  	// SaveSettings saves the settings of a World.
    17  	SaveSettings(*Settings)
    18  
    19  	// LoadPlayerSpawnPosition loads the player spawn point if found, otherwise an error will be returned.
    20  	LoadPlayerSpawnPosition(uuid uuid.UUID) (pos cube.Pos, exists bool, err error)
    21  	// SavePlayerSpawnPosition saves the player spawn point. In vanilla, this can be done with beds in the overworld
    22  	// or respawn anchors in the nether.
    23  	SavePlayerSpawnPosition(uuid uuid.UUID, pos cube.Pos) error
    24  	// LoadColumn reads a world.Column from the DB at a position and dimension
    25  	// in the DB. If no column at that position exists, errors.Is(err,
    26  	// leveldb.ErrNotFound) equals true.
    27  	LoadColumn(pos ChunkPos, dim Dimension) (*Column, error)
    28  	// StoreColumn stores a world.Column at a position and dimension in the DB.
    29  	// An error is returned if storing was unsuccessful.
    30  	StoreColumn(pos ChunkPos, dim Dimension, col *Column) error
    31  }
    32  
    33  // Compile time check to make sure NopProvider implements Provider.
    34  var _ Provider = (*NopProvider)(nil)
    35  
    36  // NopProvider implements a Provider that does not perform any disk I/O. It generates values on the run and
    37  // dynamically, instead of reading and writing data, and otherwise returns empty values. A Settings struct can be passed
    38  // to initialize a world with specific settings. Since Settings is a pointer, using the same NopProvider for multiple
    39  // worlds means those worlds will share the same settings.
    40  type NopProvider struct {
    41  	Set *Settings
    42  }
    43  
    44  func (n NopProvider) Settings() *Settings {
    45  	if n.Set == nil {
    46  		return defaultSettings()
    47  	}
    48  	return n.Set
    49  }
    50  func (NopProvider) SaveSettings(*Settings)                          {}
    51  func (NopProvider) LoadColumn(ChunkPos, Dimension) (*Column, error) { return nil, leveldb.ErrNotFound }
    52  func (NopProvider) StoreColumn(ChunkPos, Dimension, *Column) error  { return nil }
    53  func (NopProvider) LoadPlayerSpawnPosition(uuid.UUID) (cube.Pos, bool, error) {
    54  	return cube.Pos{}, false, nil
    55  }
    56  func (NopProvider) SavePlayerSpawnPosition(uuid.UUID, cube.Pos) error { return nil }
    57  func (NopProvider) Close() error                                      { return nil }