1 /* 2 * Copyright (c) 2017-2020 sel-project 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 * 22 */ 23 /** 24 * Copyright: Copyright (c) 2017-2020 sel-project 25 * License: MIT 26 * Authors: Kripth 27 * Source: $(HTTP github.com/sel-project/sel-level/sel/level/data.d, sel/level/data.d) 28 */ 29 module sel.level.data; 30 31 import sel.level.util; 32 33 import sel.math : Vector2, Vector3; 34 35 import sel.nbt : Compound; 36 37 /** 38 * Informations about a level (world) usually found in level.dat 39 * in NBT format. 40 */ 41 struct LevelInfo { 42 43 /** 44 * Name of the world. 45 */ 46 string name; 47 48 /** 49 * Seed of the world. 50 */ 51 long seed; 52 53 /** 54 * Gamemode currently used in the world. 55 * 0 for survival, 1 for creative, 2 for adventure and 56 * 3 for spectator. 57 */ 58 ubyte gamemode; 59 60 /** 61 * Current difficulty of the world. 62 * 0 for peacefully, 1 for easy, 2 for normal and 63 * 3 for hard. 64 */ 65 ubyte difficulty; 66 67 /** 68 * Indicates whether the world is deleted when the 69 * player dies. 70 */ 71 bool hardcore; 72 73 ulong time; 74 ulong dayTime; 75 76 Vector3!int spawn; 77 78 bool raining; 79 uint rainTime; 80 bool thundering; 81 uint thunderTime; 82 83 bool commandsAllowed; 84 85 GameRule[string] gamerules; 86 87 static struct GameRule { 88 89 bool isBool; 90 91 union { 92 bool bool_; 93 int int_; 94 } 95 96 this(bool bool_) { 97 this.isBool = true; 98 this.bool_ = bool_; 99 } 100 101 this(int int_) { 102 this.isBool = false; 103 this.int_ = int_; 104 } 105 106 } 107 108 } 109 110 enum Dimension : Data!byte { 111 112 overworld = Data!byte(0, 0), 113 nether = Data!byte(1, -1), 114 end = Data!byte(2, 1), 115 116 } 117 118 class Chunk { 119 120 Vector2!int position; 121 immutable uint timestamp; 122 123 int[256] biomes; 124 125 Section[uint] sections; 126 127 this(Vector2!int position, uint timestamp) { 128 this.position = position; 129 this.timestamp = timestamp; 130 } 131 132 static struct Section { 133 134 byte[4096] blockLight, skyLight; 135 Block[4096] blocks; 136 137 } 138 139 static struct Block { 140 141 string name; 142 string[string] properties; 143 144 } 145 146 }