Skip to content

Commit

Permalink
Fix maps with no DataVersion not loading in 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tryashtar committed Sep 28, 2023
1 parent c407173 commit 8880282
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion ImageMap4.CMD/Models/JavaWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ public override void AddMaps(IEnumerable<Map> maps)
foreach (var map in maps)
{
var nbt = new NbtFile { BigEndian = true };
var data = map.Data.FullData ?? Version.CreateMapCompound(map.Data);
var data = map.Data.FullData;
if (data == null)
{
data = Version.CreateMapCompound(map.Data);
if (Version.DataVersion != null)
data.Add(new NbtInt("DataVersion", Version.DataVersion.Value));
}
data.Name = "";
nbt.RootTag = data;
var folder = Path.Combine(Folder, "data");
Expand Down
10 changes: 8 additions & 2 deletions ImageMap4.CMD/Versions/JavaVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IJavaVersion
bool StructuresSupported { get; }
NbtCompound CreateStructureFile(StructureGrid structure);
string StructureFileLocation(string world_folder, string identifier);
int? DataVersion { get; }
}

public class JavaVersionBuilder
Expand All @@ -34,7 +35,8 @@ public class JavaVersionBuilder
public bool StructuresSupported = false;
public string? StructureFolder;
public string? Name;
public void Add(JavaUpdate update)
public int? DataVersion;
public void Add(JavaUpdate update, int? data_version)
{
if (update.SetBaseColors != null)
{
Expand All @@ -55,6 +57,8 @@ public void Add(JavaUpdate update)
this.Name = update.Name ?? this.Name;
this.StructureFolder = update.StructureFolder ?? this.StructureFolder;
this.StructuresSupported |= update.StructuresSupported ?? false;
if (data_version != null)
this.DataVersion = data_version;
}
public IJavaVersion Build()
{
Expand All @@ -65,7 +69,8 @@ public IJavaVersion Build()
DataMaker = MapData,
StructureMaker = StructureItem,
StructureFolder = StructureFolder,
StructuresSupported = StructuresSupported
StructuresSupported = StructuresSupported,
DataVersion = DataVersion
};
}

Expand Down Expand Up @@ -104,6 +109,7 @@ public class JavaVersion : IJavaVersion
public string StructureFolder { get; init; }
public string Name { get; init; }
public bool StructuresSupported { get; init; }
public int? DataVersion { get; init; }
public JavaVersion(string name, IEnumerable<Color> palette)
{
Name = name;
Expand Down
2 changes: 1 addition & 1 deletion ImageMap4.CMD/Versions/VersionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static VersionManager()
var java = new JavaVersionBuilder();
foreach (var update in updates.Java)
{
java.Add(update);
java.Add(update, update.Check.DataVersion);
JavaVersions.Add((update.Check, java.Build()));
}
var bedrock = new BedrockVersionBuilder();
Expand Down
6 changes: 3 additions & 3 deletions ImageMap4/ImageMap4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<Copyright>Copyright © 2022 tryashtar</Copyright>
<PackageProjectUrl>https://github.com/tryashtar/image-map</PackageProjectUrl>
<RepositoryUrl>https://github.com/tryashtar/image-map</RepositoryUrl>
<AssemblyVersion>4.2.3.0</AssemblyVersion>
<FileVersion>4.2.3.0</FileVersion>
<Version>4.2.3</Version>
<AssemblyVersion>4.2.5.0</AssemblyVersion>
<FileVersion>4.2.5.0</FileVersion>
<Version>4.2.5</Version>
<SignAssembly>false</SignAssembly>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
Expand Down

0 comments on commit 8880282

Please sign in to comment.