Skip to content

Commit

Permalink
Merge branch 'master' into 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Nov 5, 2024
2 parents 5535066 + 7a8893c commit 0477c64
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 7 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ Make sure to clear this after each release
Put changelog here:

-----------------
- Block sound overwrites now actually work on servers, unlike last time.
- Fixed `.local` directories not being accounted for in transfer packets received by the server.
- 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.
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.7

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

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/frozenblock/lib/FrozenMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.frozenblock.lib.cape.impl.ServerCapeData;
import net.frozenblock.lib.config.api.instance.Config;
Expand Down Expand Up @@ -55,6 +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.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 Expand Up @@ -116,6 +118,9 @@ public void onInitialize(String modId, ModContainer container) {
ConfigCommand.register(dispatcher);
TagListCommand.register(dispatcher);
ScaleEntityCommand.register(dispatcher);
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
StructureUpgradeCommand.register(dispatcher);
}
});

ServerWorldEvents.LOAD.register((server, level) -> {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/frozenblock/lib/cape/api/CapeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public static void registerCapeWithWhitelist(ResourceLocation id, Component cape
}

public static void registerCapesFromURL(String urlString) {
if (CAPE_REPOS.contains(urlString))
return;

try {
URL url = URI.create(urlString).toURL();
URLConnection request = url.openConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
public class ServerCapeData {
private static final Map<UUID, Cape> CAPES_IN_SERVER = new HashMap<>();

public static void sendAllCapesToPlayer(ServerPlayer recipent) {
CAPES_IN_SERVER.forEach((uuid, cape) -> ServerPlayNetworking.send(recipent, CapeCustomizePacket.createPacket(uuid, cape)));
CapeUtil.getCapeRepos().forEach(repoURL -> ServerPlayNetworking.send(recipent, new LoadCapeRepoPacket(repoURL)));
public static void sendAllCapesToPlayer(ServerPlayer recipient) {
CAPES_IN_SERVER.forEach((uuid, cape) -> ServerPlayNetworking.send(recipient, CapeCustomizePacket.createPacket(uuid, cape)));
}

public static void sendCapeReposToPlayer(ServerPlayer recipient) {
CapeUtil.getCapeRepos().forEach(repoURL -> ServerPlayNetworking.send(recipient, new LoadCapeRepoPacket(repoURL)));
}

public static void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void saveToFile(CompoundTag compoundTag, @NotNull File file, Strin
}

public static void saveToFile(CompoundTag compoundTag, @NotNull File file) {
file.mkdirs();
file.getParentFile().mkdirs();
try {
NbtIo.writeCompressed(compoundTag, file.toPath());
} catch (IOException iOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static void registerNetworking() {

PlayerJoinEvents.ON_JOIN_SERVER.register((server, player) -> {
ConfigSyncPacket.sendS2C(player);
ServerCapeData.sendCapeReposToPlayer(player);
});

ResourceLoaderEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, error) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.frozenblock.lib.worldgen.structure.impl;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.frozenblock.lib.file.nbt.NbtFileUtils;
import net.minecraft.SharedConstants;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;

public class StructureUpgradeCommand {
private StructureUpgradeCommand() {}

public static void register(@NotNull CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("structure_upgrade")
.then(Commands.argument("namespace", StringArgumentType.string())
.executes(context -> upgradeAndExportPieces(context.getSource(), StringArgumentType.getString(context, "namespace"), false))
.then(Commands.argument("log", BoolArgumentType.bool())
.executes(context -> upgradeAndExportPieces(context.getSource(), StringArgumentType.getString(context, "namespace"), BoolArgumentType.getBool(context, "log")))
)
)
);
}

private static int upgradeAndExportPieces(@NotNull CommandSourceStack source, String namespace, boolean log) {
ResourceManager resourceManager = source.getServer().getResourceManager();

Set<ResourceLocation> foundPieces = resourceManager.listResources(
"structure",
resourceLocation -> resourceLocation.getPath().endsWith(".nbt") && resourceLocation.getNamespace().equals(namespace)
).keySet();

if (log) {
foundPieces.forEach(resourceLocation -> System.out.println("Found piece: " + resourceLocation.toString()));
}

StructureTemplateManager structureTemplateManager = source.getLevel().getStructureManager();
Map<ResourceLocation, CompoundTag> savedTemplates = new Object2ObjectLinkedOpenHashMap<>();

foundPieces.forEach((resourceLocation) -> {
savedTemplates.put(resourceLocation, structureTemplateManager.getOrCreate(resourceLocation).save(new CompoundTag()));
});

Path outputPath = source.getServer().getServerDirectory()
.resolve("upgraded_structure/data_version_" + SharedConstants.getCurrentVersion().getDataVersion().getVersion());

savedTemplates.forEach((resourceLocation, compoundTag) -> {
NbtFileUtils.saveToFile(
compoundTag,
outputPath.resolve(resourceLocation.getNamespace()).toFile(),
resourceLocation.getPath().replace(".nbt", "")
);
});

int templateCount = savedTemplates.size();
if (templateCount > 0) {
source.sendSuccess(() -> Component.translatable("commands.structure_upgrade.success", templateCount, namespace), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.structure_upgrade.failure", namespace), true);
}
return 1;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/frozenlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
"commands.frozenlib.taglist.footer": "Listed %s tags in %s.",
"commands.frozenlib.taglist.tag.invalid": "Invalid tag: %s",

"commands.structure_upgrade.success": "Upgraded and saved %s structure pieces for %s.",
"commands.structure_upgrade.failure": "No structure pieces found for %s.",

"commands.warden_spawn_tracker.clear.success.multiple": "Cleared warden spawn warnings from %s players",
"commands.warden_spawn_tracker.clear.success.single": "Cleared warden spawn warnings from %s",
"commands.warden_spawn_tracker.set.success.multiple": "Set warden spawn warning %s to %s players",
Expand Down

0 comments on commit 0477c64

Please sign in to comment.