-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db5bbf9
commit ba65f7b
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ain/java/net/frozenblock/lib/worldgen/structure/impl/upgrade/CommandStructureUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters