Skip to content

Commit

Permalink
fix structure upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Nov 6, 2024
1 parent 56d5b90 commit d62e607
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ Make sure to clear this after each release
Put changelog here:

-----------------
- Fixed FrozenLib's capes causing severe performance issues when switching dimensions or respawning.
- Fixed `NbtFileUtils` creating a directory instead of a file.
- Added the `structure_upgrade` command, only accessible in development environments.
- This takes a string for the `namespace` parameter, and will grab all structure pieces under the given namespace then save them to `run/upgraded_structure,` upgraded to the latest DataVersion.
- Fixed structure upgrading not saving anything.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
min_loader_version=0.16.0

# Mod Properties
mod_version = 1.9.3
mod_version = 1.9.4
maven_group = net.frozenblock
archives_base_name = FrozenLib

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.NbtIo;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.FastBufferedInputStream;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -65,7 +71,19 @@ private static int upgradeAndExportPieces(@NotNull CommandSourceStack source, St
Map<ResourceLocation, CompoundTag> savedTemplates = new Object2ObjectLinkedOpenHashMap<>();

foundPieces.forEach((resourceLocation) -> {
savedTemplates.put(resourceLocation, structureTemplateManager.getOrCreate(resourceLocation).save(new CompoundTag()));
try {
InputStream inputStream = resourceManager.getResourceOrThrow(resourceLocation).open();
InputStream inputStream2 = new FastBufferedInputStream(inputStream);
CompoundTag compoundTag = NbtIo.readCompressed(inputStream2, NbtAccounter.unlimitedHeap());
StructureTemplate structureTemplate = structureTemplateManager.readStructure(compoundTag);

inputStream2.close();
inputStream.close();

savedTemplates.put(resourceLocation, structureTemplate.save(new CompoundTag()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});

Path outputPath = source.getServer().getServerDirectory()
Expand Down

0 comments on commit d62e607

Please sign in to comment.