Skip to content

Commit cea0f11

Browse files
authored
Merge pull request #290 from Bedrock-OSS/update-export-targets
Update export targets
2 parents ed8bb81 + ca46b52 commit cea0f11

27 files changed

+419
-57
lines changed

docs/docs/guide/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Example config, with many options explained:
7676
// Export target defines where your files will be exported
7777
"export": {
7878
"target": "development",
79+
"build": "standard",
7980
"readOnly": false
8081
}
8182
}

docs/docs/guide/create-a-filter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ At this point, you need to edit your `config.json` so that `giant_mobs` is regis
4848
],
4949
"export": {
5050
"target": "development",
51+
"build": "standard",
5152
"readOnly": true
5253
}
5354
}

docs/docs/guide/export-targets.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ These are the export targets that Regolith offers.
2929

3030
## Development
3131

32-
The development export target will place the compiled packs into your `com.mojang` `development_*_packs` folders.
32+
The development export target will place the compiled packs into your `com.mojang` `development_*_packs` folders of the specified Minecraft build (standard, preview or education endition).
3333

3434
```json
3535
"export": {
36-
"target": "development"
36+
"target": "development",
37+
"build": "standard" // or "preview" or "education"
3738
}
3839
```
3940

@@ -42,6 +43,7 @@ Optionally, you can use `rpName` and `bpName` to specify the names of the folder
4243
```json
4344
"export": {
4445
"target": "development",
46+
"build": "standard",
4547
"rpName": "'my_rp'",
4648
"bpName": "'my_bp'"
4749
}
@@ -91,13 +93,14 @@ The exact export target doesn't support using `rpName` and `bpName`. The `rpPath
9193

9294
The World export target will place the compiled files into a specific world. This is useful for teams that prefer working in-world, as opposed to in the development pack folders.
9395

94-
You need to use *either* `worldName` or `worldPath` to select the world. `worldPath` supports environment variables by using the `%VARIABLE_NAME%` syntax.
96+
You need to use *either* `worldName` or `worldPath` to select the world. `worldPath` supports environment variables by using the `%VARIABLE_NAME%` syntax. If you use `worldName`, you have to specify the Minecraft build you're using - `standard`, `preview` or `education`.
9597

9698
Example:
9799

98100
```json
99101
"export": {
100102
"target": "world",
103+
"build": "standard",
101104
"worldName": "..." // This
102105
// "worldPath": "..." // OR this
103106
}
@@ -114,26 +117,6 @@ Optionally, you can use `rpName` and `bpName` to specify the names of the folder
114117
}
115118
```
116119

117-
118-
## Preview
119-
120-
The development export target will place the compiled packs into your **(minecraft preview)** `com.mojang` `development_*_packs` folder.
121-
122-
```json
123-
"export": {
124-
"target": "preview"
125-
}
126-
```
127-
128-
Optionally, you can use `rpName` and `bpName` to specify the names of the folders that will be created in the `development_*_packs` folders. You can read more about these options at the end of this page of the documentation.
129-
```json
130-
"export": {
131-
"target": "preview",
132-
"rpName": "'my_rp'",
133-
"bpName": "'my_bp'"
134-
}
135-
```
136-
137120
# The `rpName` and `bpName` expressions
138121

139122
The `rpName` and `bpName` are expressions evaulated using the [go-simple-eval](https://github.com/stirante/go-simple-eval/) library. They let you specify the names of the folders of the exported packs in some of the export targets.

docs/docs/guide/getting-started.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Next, open up `config.json`. We will be configuring a few fields here, for your
5151
"filters": [],
5252
"export": {
5353
"target": "development",
54+
"build": "standard",
5455
"readOnly": false
5556
}
5657
}
@@ -115,7 +116,8 @@ You should adjust the default profile in `config.json` to look like this:
115116
"default": {
116117
"export": {
117118
"readOnly": false,
118-
"target": "development"
119+
"target": "development",
120+
"build": "standard"
119121
},
120122
"filters": [
121123
{

docs/docs/guide/installing-filters.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ After installing, the filter will appear inside of `filter_definitions` of `conf
4949
"default": {
5050
"export": {
5151
"readOnly": false,
52-
"target": "development"
52+
"target": "development",
53+
"build": "standard"
5354
},
5455
"filters": [
5556
{

docs/docs/guide/profiles.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Here is an example `config.json` with a second profile called `package`.
4040
],
4141
"export": {
4242
"target": "development",
43+
"build": "standard"
4344
}
4445
},
4546

@@ -50,6 +51,7 @@ Here is an example `config.json` with a second profile called `package`.
5051
],
5152
"export": {
5253
"target": "development",
54+
"build": "standard"
5355
}
5456
}
5557
},

regolith/compatibility_other_os.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package regolith
55

66
import (
77
"os"
8+
89
"github.com/Bedrock-OSS/go-burrito/burrito"
910
)
1011

@@ -50,22 +51,30 @@ func (d *DirWatcher) Close() error {
5051
return burrito.WrappedError(notImplementedOnThisSystemError)
5152
}
5253

53-
func FindMojangDir() (string, error) {
54+
func FindStandardMojangDir() (string, error) {
5455
comMojang := os.Getenv("COM_MOJANG")
5556
if comMojang == "" {
56-
return "", burrito.WrappedError(comMojangEnvUnsetError)
57+
return "", burrito.WrappedError(comMojangEnvUnsetError)
5758
}
5859
return comMojang, nil
5960
}
6061

6162
func FindPreviewDir() (string, error) {
6263
comMojangPreview := os.Getenv("COM_MOJANG_PREVIEW")
6364
if comMojangPreview == "" {
64-
return "", burrito.WrappedError(comMojangPreviewEnvUnsetError)
65+
return "", burrito.WrappedError(comMojangPreviewEnvUnsetError)
6566
}
6667
return comMojangPreview, nil
6768
}
6869

70+
func FindEducationDir() (string, error) {
71+
comMojangEdu := os.Getenv("COM_MOJANG_EDU")
72+
if comMojangEdu == "" {
73+
return "", burrito.WrappedError(comMojangEduEnvUnsetError)
74+
}
75+
return comMojangEdu, nil
76+
}
77+
6978
func CheckSuspiciousLocation() error {
7079
return nil
7180
}

regolith/compatibility_windows.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func (d *DirWatcher) Close() error {
146146
return windows.CloseHandle(d.handle)
147147
}
148148

149-
// FindMojangDir returns path to the com.mojang folder.
150-
func FindMojangDir() (string, error) {
149+
// FindStandardMojangDir returns path to the com.mojang folder in the standard
150+
// Minecraft build.
151+
func FindStandardMojangDir() (string, error) {
151152
result := filepath.Join(
152153
os.Getenv("LOCALAPPDATA"), "Packages",
153154
"Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games",
@@ -161,6 +162,8 @@ func FindMojangDir() (string, error) {
161162
return result, nil
162163
}
163164

165+
// FindPreviewDir returns path to the com.mojang folder in the preview
166+
// Minecraft build.
164167
func FindPreviewDir() (string, error) {
165168
result := filepath.Join(
166169
os.Getenv("LOCALAPPDATA"), "Packages",
@@ -176,13 +179,29 @@ func FindPreviewDir() (string, error) {
176179
return result, nil
177180
}
178181

182+
// FindEducationDir returns path to the com.mojang folder in the education
183+
// edition Minecraft build.
184+
func FindEducationDir() (string, error) {
185+
result := filepath.Join(
186+
os.Getenv("APPDATA"), "Minecraft Education Edition", "games",
187+
"com.mojang")
188+
if _, err := os.Stat(result); err != nil {
189+
if os.IsNotExist(err) {
190+
return "", burrito.WrapErrorf(err, osStatErrorIsNotExist, result)
191+
}
192+
return "", burrito.WrapErrorf(
193+
err, osStatErrorAny, result)
194+
}
195+
return result, nil
196+
}
197+
179198
func CheckSuspiciousLocation() error {
180199
path, err := os.Getwd()
181200
if err != nil {
182201
return burrito.WrapErrorf(err, osGetwdError)
183202
}
184203
// Check if project directory is within mojang dir
185-
dir, err := FindMojangDir()
204+
dir, err := FindStandardMojangDir()
186205
if err == nil {
187206
dir1 := filepath.Join(dir, "development_behavior_packs")
188207
if isPathWithinDirectory(path, dir1) {

regolith/config.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package regolith
22

3-
import "github.com/Bedrock-OSS/go-burrito/burrito"
3+
import (
4+
"github.com/Bedrock-OSS/go-burrito/burrito"
5+
"golang.org/x/mod/semver"
6+
)
7+
8+
const latestCompatibleVersion = "1.4.0"
49

510
const StandardLibraryUrl = "github.com/Bedrock-OSS/regolith-filters"
611
const ConfigFilePath = "config.json"
@@ -26,7 +31,8 @@ type ExportTarget struct {
2631
BpName string `json:"bpName,omitempty"`
2732
WorldName string `json:"worldName,omitempty"`
2833
WorldPath string `json:"worldPath,omitempty"`
29-
ReadOnly bool `json:"readOnly"` // Whether the exported files should be read-only
34+
ReadOnly bool `json:"readOnly"` // Whether the exported files should be read-only
35+
Build string `json:"build,omitempty"` // The type of Minecraft build for the 'develop'
3036
}
3137

3238
// Packs is a part of "config.json" that points to the source behavior and
@@ -42,6 +48,7 @@ type RegolithProject struct {
4248
Profiles map[string]Profile `json:"profiles,omitempty"`
4349
FilterDefinitions map[string]FilterInstaller `json:"filterDefinitions"`
4450
DataPath string `json:"dataPath,omitempty"`
51+
FormatVersion string `json:"formatVersion,omitempty"`
4552
}
4653

4754
// ConfigFromObject creates a "Config" object from map[string]interface{}
@@ -109,6 +116,31 @@ func RegolithProjectFromObject(
109116
Profiles: make(map[string]Profile),
110117
FilterDefinitions: make(map[string]FilterInstaller),
111118
}
119+
// FormatVersion
120+
if version, ok := obj["formatVersion"]; !ok {
121+
Logger.Warn("Format version is missing. Defaulting to 1.2.0")
122+
result.FormatVersion = "1.2.0"
123+
} else {
124+
formatVersion, ok := version.(string)
125+
if !ok {
126+
return result, burrito.WrappedErrorf(
127+
jsonPropertyTypeError, "formatVersion", "string")
128+
}
129+
result.FormatVersion = formatVersion
130+
vFormatVersion := "v" + formatVersion
131+
if !semver.IsValid("v" + formatVersion) {
132+
return result, burrito.WrappedErrorf(
133+
"Invalid value of formatVersion. The formatVersion must "+
134+
"be a semver version:\n"+
135+
"Current value: %s", formatVersion)
136+
}
137+
if semver.Compare(vFormatVersion, "v"+latestCompatibleVersion) > 0 {
138+
return result, burrito.WrappedErrorf(
139+
incompatibleFormatVersionError,
140+
formatVersion, latestCompatibleVersion)
141+
}
142+
}
143+
112144
// DataPath
113145
if _, ok := obj["dataPath"]; !ok {
114146
return result, burrito.WrappedErrorf(jsonPropertyMissingError, "dataPath")
@@ -197,5 +229,8 @@ func ExportTargetFromObject(obj map[string]interface{}) (ExportTarget, error) {
197229
// ReadOnly - can be empty
198230
readOnly, _ := obj["readOnly"].(bool)
199231
result.ReadOnly = readOnly
232+
// Build - can be empty
233+
build, _ := obj["build"].(string)
234+
result.Build = build
200235
return result, nil
201236
}

regolith/errors.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ const (
149149
// Error used when env variable COM_MOJANG_PREVIEW is not set on non Windows system
150150
comMojangPreviewEnvUnsetError = "COM_MOJANG_PREVIEW environment variable is not set."
151151

152+
// Error used when env variable COM_MOJANG_EDU is not set on non Windows system
153+
comMojangEduEnvUnsetError = "COM_MOJANG_EDU environment variable is not set."
154+
152155
// Error used when SetupTmpFiles function fails
153156
setupTmpFilesError = "Failed to setup temporary files.\n" +
154157
"Regolith files path: %s" // .regolith
@@ -222,4 +225,23 @@ const (
222225

223226
resolverResolveUrlError = "Failed to resolve the URL of the resolver file for the download.\n" +
224227
"Short URL: %s"
228+
229+
// findMojangDirError is used when the FindMojangDir function fails
230+
findMojangDirError = "Failed to find \"com.mojang\" directory."
231+
232+
// findPreviewDirError is used when the FindPreviewDir function fails
233+
findPreviewDirError = "Failed to find the preview \"com.mojang\" directory."
234+
235+
// findEducationDirError is used when the FindEducationDir function fails
236+
findEducationDirError = "Failed to find the \"com.mojang\" directory."
237+
238+
invalidExportPathError = "The build property of the export is invalid:\n" +
239+
"Current value: %q\n" +
240+
"Valid values are: %s"
241+
242+
// Error used when the formatVersion of the config file is incompatible
243+
// with the current version of Regolith.
244+
incompatibleFormatVersionError = "Incompatible formatVersion: \n" +
245+
"Version in config: %s\n" +
246+
"Latest compatible version: %s"
225247
)

0 commit comments

Comments
 (0)