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

     1  package leveldat
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  	"github.com/sandertv/gophertunnel/minecraft/protocol"
     7  	"math"
     8  	"time"
     9  )
    10  
    11  // Data holds a collection of data that specify a range of Settings of the
    12  // world. These Settings usually alter the way that players interact with the
    13  // world. The data held here is usually saved in a level.dat file of the world.
    14  // Data may be used in LevelDat.Unmarshal to collect the data of the level.dat.
    15  type Data struct {
    16  	BaseGameVersion                string `nbt:"baseGameVersion"`
    17  	BiomeOverride                  string
    18  	ConfirmedPlatformLockedContent bool
    19  	CenterMapsToOrigin             bool
    20  	CheatsEnabled                  bool  `nbt:"cheatsEnabled"`
    21  	DaylightCycle                  int32 `nbt:"daylightCycle"`
    22  	Difficulty                     int32
    23  	EduOffer                       int32 `nbt:"eduOffer"`
    24  	FlatWorldLayers                string
    25  	ForceGameType                  bool
    26  	GameType                       int32
    27  	Generator                      int32
    28  	InventoryVersion               string
    29  	LANBroadcast                   bool
    30  	LANBroadcastIntent             bool
    31  	LastPlayed                     int64
    32  	LevelName                      string
    33  	LimitedWorldOriginX            int32
    34  	LimitedWorldOriginY            int32
    35  	LimitedWorldOriginZ            int32
    36  	LimitedWorldDepth              int32 `nbt:"limitedWorldDepth"`
    37  	LimitedWorldWidth              int32 `nbt:"limitedWorldWidth"`
    38  	MinimumCompatibleClientVersion []int32
    39  	MultiPlayerGame                bool `nbt:"MultiplayerGame"`
    40  	MultiPlayerGameIntent          bool `nbt:"MultiplayerGameIntent"`
    41  	NetherScale                    int32
    42  	NetworkVersion                 int32
    43  	Platform                       int32
    44  	PlatformBroadcastIntent        int32
    45  	RandomSeed                     int64
    46  	ShowTags                       bool `nbt:"showtags"`
    47  	SingleUseWorld                 bool `nbt:"isSingleUseWorld"`
    48  	SpawnX, SpawnY, SpawnZ         int32
    49  	SpawnV1Villagers               bool
    50  	StorageVersion                 int32
    51  	Time                           int64
    52  	XBLBroadcast                   bool
    53  	XBLBroadcastIntent             int32
    54  	XBLBroadcastMode               int32
    55  	Abilities                      struct {
    56  		AttackMobs             bool    `nbt:"attackmobs"`
    57  		AttackPlayers          bool    `nbt:"attackplayers"`
    58  		Build                  bool    `nbt:"build"`
    59  		Mine                   bool    `nbt:"mine"`
    60  		DoorsAndSwitches       bool    `nbt:"doorsandswitches"`
    61  		FlySpeed               float32 `nbt:"flySpeed"`
    62  		Flying                 bool    `nbt:"flying"`
    63  		InstantBuild           bool    `nbt:"instabuild"`
    64  		Invulnerable           bool    `nbt:"invulnerable"`
    65  		Lightning              bool    `nbt:"lightning"`
    66  		MayFly                 bool    `nbt:"mayfly"`
    67  		OP                     bool    `nbt:"op"`
    68  		OpenContainers         bool    `nbt:"opencontainers"`
    69  		PermissionsLevel       int32   `nbt:"permissionsLevel"`
    70  		PlayerPermissionsLevel int32   `nbt:"playerPermissionsLevel"`
    71  		Teleport               bool    `nbt:"teleport"`
    72  		WalkSpeed              float32 `nbt:"walkSpeed"`
    73  	} `nbt:"abilities"`
    74  	BonusChestEnabled              bool           `nbt:"bonusChestEnabled"`
    75  	BonusChestSpawned              bool           `nbt:"bonusChestSpawned"`
    76  	CommandBlockOutput             bool           `nbt:"commandblockoutput"`
    77  	CommandBlocksEnabled           bool           `nbt:"commandblocksenabled"`
    78  	CommandsEnabled                bool           `nbt:"commandsEnabled"`
    79  	CurrentTick                    int64          `nbt:"currentTick"`
    80  	DoDayLightCycle                bool           `nbt:"dodaylightcycle"`
    81  	DoEntityDrops                  bool           `nbt:"doentitydrops"`
    82  	DoFireTick                     bool           `nbt:"dofiretick"`
    83  	DoImmediateRespawn             bool           `nbt:"doimmediaterespawn"`
    84  	DoInsomnia                     bool           `nbt:"doinsomnia"`
    85  	DoMobLoot                      bool           `nbt:"domobloot"`
    86  	DoMobSpawning                  bool           `nbt:"domobspawning"`
    87  	DoTileDrops                    bool           `nbt:"dotiledrops"`
    88  	DoWeatherCycle                 bool           `nbt:"doweathercycle"`
    89  	DrowningDamage                 bool           `nbt:"drowningdamage"`
    90  	EduLevel                       bool           `nbt:"eduLevel"`
    91  	EducationFeaturesEnabled       bool           `nbt:"educationFeaturesEnabled"`
    92  	ExperimentalGamePlay           bool           `nbt:"experimentalgameplay"`
    93  	FallDamage                     bool           `nbt:"falldamage"`
    94  	FireDamage                     bool           `nbt:"firedamage"`
    95  	FunctionCommandLimit           int32          `nbt:"functioncommandlimit"`
    96  	HasBeenLoadedInCreative        bool           `nbt:"hasBeenLoadedInCreative"`
    97  	HasLockedBehaviourPack         bool           `nbt:"hasLockedBehaviorPack"`
    98  	HasLockedResourcePack          bool           `nbt:"hasLockedResourcePack"`
    99  	ImmutableWorld                 bool           `nbt:"immutableWorld"`
   100  	IsCreatedInEditor              bool           `nbt:"isCreatedInEditor"`
   101  	IsExportedFromEditor           bool           `nbt:"isExportedFromEditor"`
   102  	IsFromLockedTemplate           bool           `nbt:"isFromLockedTemplate"`
   103  	IsFromWorldTemplate            bool           `nbt:"isFromWorldTemplate"`
   104  	IsWorldTemplateOptionLocked    bool           `nbt:"isWorldTemplateOptionLocked"`
   105  	KeepInventory                  bool           `nbt:"keepinventory"`
   106  	LastOpenedWithVersion          []int32        `nbt:"lastOpenedWithVersion"`
   107  	LightningLevel                 float32        `nbt:"lightningLevel"`
   108  	LightningTime                  int32          `nbt:"lightningTime"`
   109  	MaxCommandChainLength          int32          `nbt:"maxcommandchainlength"`
   110  	MobGriefing                    bool           `nbt:"mobgriefing"`
   111  	NaturalRegeneration            bool           `nbt:"naturalregeneration"`
   112  	PRID                           string         `nbt:"prid"`
   113  	PVP                            bool           `nbt:"pvp"`
   114  	RainLevel                      float32        `nbt:"rainLevel"`
   115  	RainTime                       int32          `nbt:"rainTime"`
   116  	RandomTickSpeed                int32          `nbt:"randomtickspeed"`
   117  	RequiresCopiedPackRemovalCheck bool           `nbt:"requiresCopiedPackRemovalCheck"`
   118  	SendCommandFeedback            bool           `nbt:"sendcommandfeedback"`
   119  	ServerChunkTickRange           int32          `nbt:"serverChunkTickRange"`
   120  	ShowCoordinates                bool           `nbt:"showcoordinates"`
   121  	ShowDeathMessages              bool           `nbt:"showdeathmessages"`
   122  	SpawnMobs                      bool           `nbt:"spawnMobs"`
   123  	SpawnRadius                    int32          `nbt:"spawnradius"`
   124  	StartWithMapEnabled            bool           `nbt:"startWithMapEnabled"`
   125  	TexturePacksRequired           bool           `nbt:"texturePacksRequired"`
   126  	TNTExplodes                    bool           `nbt:"tntexplodes"`
   127  	UseMSAGamerTagsOnly            bool           `nbt:"useMsaGamertagsOnly"`
   128  	WorldStartCount                int64          `nbt:"worldStartCount"`
   129  	Experiments                    map[string]any `nbt:"experiments"`
   130  	FreezeDamage                   bool           `nbt:"freezedamage"`
   131  	WorldPolicies                  map[string]any `nbt:"world_policies"`
   132  	WorldVersion                   int32          `nbt:"WorldVersion"`
   133  	RespawnBlocksExplode           bool           `nbt:"respawnblocksexplode"`
   134  	ShowBorderEffect               bool           `nbt:"showbordereffect"`
   135  	PermissionsLevel               int32          `nbt:"permissionsLevel"`
   136  	PlayerPermissionsLevel         int32          `nbt:"playerPermissionsLevel"`
   137  	IsRandomSeedAllowed            bool           `nbt:"isRandomSeedAllowed"`
   138  	DoLimitedCrafting              bool           `nbt:"dolimitedcrafting"`
   139  	EditorWorldType                int32          `nbt:"editorWorldType"`
   140  	PlayersSleepingPercentage      int32          `nbt:"playerssleepingpercentage"`
   141  	RecipesUnlock                  bool           `nbt:"recipesunlock"`
   142  	NaturalGeneration              bool           `nbt:"naturalgeneration"`
   143  	ProjectilesCanBreakBlocks      bool           `nbt:"projectilescanbreakblocks"`
   144  	ShowRecipeMessages             bool           `nbt:"showrecipemessages"`
   145  }
   146  
   147  // FillDefault fills out d with all the default level.dat values.
   148  func (d *Data) FillDefault() {
   149  	d.Abilities.AttackMobs = true
   150  	d.Abilities.AttackPlayers = true
   151  	d.Abilities.Build = true
   152  	d.Abilities.DoorsAndSwitches = true
   153  	d.Abilities.FlySpeed = 0.05
   154  	d.Abilities.Mine = true
   155  	d.Abilities.OpenContainers = true
   156  	d.Abilities.PlayerPermissionsLevel = 1
   157  	d.Abilities.WalkSpeed = 0.1
   158  	d.BaseGameVersion = "*"
   159  	d.CommandBlockOutput = true
   160  	d.CommandBlocksEnabled = true
   161  	d.CommandsEnabled = true
   162  	d.Difficulty = 2
   163  	d.DoDayLightCycle = true
   164  	d.DoEntityDrops = true
   165  	d.DoFireTick = true
   166  	d.DoInsomnia = true
   167  	d.DoMobLoot = true
   168  	d.DoMobSpawning = true
   169  	d.DoTileDrops = true
   170  	d.DoWeatherCycle = true
   171  	d.DrowningDamage = true
   172  	d.FallDamage = true
   173  	d.FireDamage = true
   174  	d.FreezeDamage = true
   175  	d.FunctionCommandLimit = 10000
   176  	d.GameType = 1
   177  	d.Generator = 2
   178  	d.HasBeenLoadedInCreative = true
   179  	d.InventoryVersion = protocol.CurrentVersion
   180  	d.LANBroadcast = true
   181  	d.LANBroadcastIntent = true
   182  	d.LastOpenedWithVersion = minimumCompatibleClientVersion
   183  	d.LevelName = "World"
   184  	d.LightningLevel = 1.0
   185  	d.LimitedWorldDepth = 16
   186  	d.LimitedWorldOriginY = math.MaxInt16
   187  	d.LimitedWorldWidth = 16
   188  	d.MaxCommandChainLength = math.MaxUint16
   189  	d.MinimumCompatibleClientVersion = minimumCompatibleClientVersion
   190  	d.MobGriefing = true
   191  	d.MultiPlayerGame = true
   192  	d.MultiPlayerGameIntent = true
   193  	d.NaturalRegeneration = true
   194  	d.NetherScale = 8
   195  	d.NetworkVersion = protocol.CurrentProtocol
   196  	d.PVP = true
   197  	d.Platform = 2
   198  	d.PlatformBroadcastIntent = 3
   199  	d.RainLevel = 1.0
   200  	d.RandomSeed = time.Now().Unix()
   201  	d.RandomTickSpeed = 1
   202  	d.RespawnBlocksExplode = true
   203  	d.SendCommandFeedback = true
   204  	d.ServerChunkTickRange = 6
   205  	d.ShowBorderEffect = true
   206  	d.ShowDeathMessages = true
   207  	d.ShowTags = true
   208  	d.SpawnMobs = true
   209  	d.SpawnRadius = 5
   210  	d.SpawnRadius = 5
   211  	d.SpawnY = math.MaxInt16
   212  	d.StorageVersion = 9
   213  	d.TNTExplodes = true
   214  	d.WorldVersion = 1
   215  	d.XBLBroadcastIntent = 3
   216  }
   217  
   218  // Settings returns a world.Settings value based on the properties stored in d.
   219  func (d *Data) Settings() *world.Settings {
   220  	d.WorldStartCount += 1
   221  	difficulty, _ := world.DifficultyByID(int(d.Difficulty))
   222  	mode, _ := world.GameModeByID(int(d.GameType))
   223  	return &world.Settings{
   224  		Name:            d.LevelName,
   225  		Spawn:           cube.Pos{int(d.SpawnX), int(d.SpawnY), int(d.SpawnZ)},
   226  		Time:            d.Time,
   227  		TimeCycle:       d.DoDayLightCycle,
   228  		RainTime:        int64(d.RainTime),
   229  		Raining:         d.RainLevel > 0,
   230  		ThunderTime:     int64(d.LightningTime),
   231  		Thundering:      d.LightningLevel > 0,
   232  		WeatherCycle:    d.DoWeatherCycle,
   233  		CurrentTick:     d.CurrentTick,
   234  		DefaultGameMode: mode,
   235  		Difficulty:      difficulty,
   236  		TickRange:       d.ServerChunkTickRange,
   237  	}
   238  }
   239  
   240  // PutSettings updates d with the Settings stored in s.
   241  func (d *Data) PutSettings(s *world.Settings) {
   242  	d.LevelName = s.Name
   243  	d.SpawnX, d.SpawnY, d.SpawnZ = int32(s.Spawn.X()), int32(s.Spawn.Y()), int32(s.Spawn.Z())
   244  	d.LimitedWorldOriginX, d.LimitedWorldOriginY, d.LimitedWorldOriginZ = d.SpawnX, d.SpawnY, d.SpawnZ
   245  	d.Time = s.Time
   246  	d.DoDayLightCycle = s.TimeCycle
   247  	d.DoWeatherCycle = s.WeatherCycle
   248  	d.RainTime, d.RainLevel = int32(s.RainTime), 0
   249  	d.LightningTime, d.LightningLevel = int32(s.ThunderTime), 0
   250  	if s.Raining {
   251  		d.RainLevel = 1
   252  	}
   253  	if s.Thundering {
   254  		d.LightningLevel = 1
   255  	}
   256  	d.CurrentTick = s.CurrentTick
   257  	d.ServerChunkTickRange = s.TickRange
   258  	mode, _ := world.GameModeID(s.DefaultGameMode)
   259  	d.GameType = int32(mode)
   260  	difficulty, _ := world.DifficultyID(s.Difficulty)
   261  	d.Difficulty = int32(difficulty)
   262  }