Skip to content

Commit

Permalink
likely fix upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Nov 6, 2024
1 parent db5bbf9 commit ba65f7b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/frozenblock/lib/FrozenMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import net.frozenblock.lib.worldgen.feature.api.placementmodifier.FrozenPlacementModifiers;
import net.frozenblock.lib.worldgen.structure.impl.FrozenRuleBlockEntityModifiers;
import net.frozenblock.lib.worldgen.structure.impl.FrozenStructureProcessorTypes;
import net.frozenblock.lib.worldgen.structure.impl.command.StructureUpgradeCommand;
import net.frozenblock.lib.worldgen.structure.impl.upgrade.StructureUpgradeCommand;
import net.frozenblock.lib.worldgen.surface.impl.BiomeTagConditionSource;
import net.frozenblock.lib.worldgen.surface.impl.OptimizedBiomeTagConditionSource;
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2024 FrozenBlock
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.worldgen.structure.impl.upgrade;

import com.mojang.logging.LogUtils;
import net.minecraft.SharedConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.structures.SnbtToNbt;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

public class CommandStructureUpdater implements SnbtToNbt.Filter {
private static final Logger LOGGER = LogUtils.getLogger();

@Override
public @NotNull CompoundTag apply(String string, CompoundTag compoundTag) {
return update(string, compoundTag);
}

public static @NotNull CompoundTag update(String name, CompoundTag nbt) {
StructureTemplate structureTemplate = new StructureTemplate();
int i = NbtUtils.getDataVersion(nbt, 500);
int currentVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
if (i < currentVersion) {
LOGGER.warn("SNBT Too old, do not forget to update: {} < {}: {}", i, currentVersion, name);
}

CompoundTag compoundTag = DataFixTypes.STRUCTURE.updateToCurrentVersion(DataFixers.getDataFixer(), nbt, i);
structureTemplate.load(BuiltInRegistries.BLOCK.asLookup(), compoundTag);
return structureTemplate.save(new CompoundTag());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.worldgen.structure.impl.command;
package net.frozenblock.lib.worldgen.structure.impl.upgrade;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
Expand All @@ -27,7 +27,6 @@
import net.minecraft.data.PackOutput;
import net.minecraft.data.structures.NbtToSnbt;
import net.minecraft.data.structures.SnbtToNbt;
import net.minecraft.data.structures.StructureUpdater;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
Expand Down Expand Up @@ -129,7 +128,7 @@ private static int exportSNBTToNBT(@NotNull CommandSourceStack source, String na
outputPath.toFile().mkdirs();

PackOutput packOutput = new PackOutput(outputPath);
SnbtToNbt snbtToNbt = new SnbtToNbt(packOutput, Set.of(inputPath)).addFilter(new StructureUpdater());
SnbtToNbt snbtToNbt = new SnbtToNbt(packOutput, Set.of(inputPath)).addFilter(new CommandStructureUpdater());
CompletableFuture completableFuture = snbtToNbt.run(CachedOutput.NO_CACHE);

while (!completableFuture.isDone()) {
Expand Down

0 comments on commit ba65f7b

Please sign in to comment.