diff --git a/common/src/main/java/com/klikli_dev/modonomicon/api/ModonomiconConstants.java b/common/src/main/java/com/klikli_dev/modonomicon/api/ModonomiconConstants.java index ce40e8755..d54ff9ed6 100644 --- a/common/src/main/java/com/klikli_dev/modonomicon/api/ModonomiconConstants.java +++ b/common/src/main/java/com/klikli_dev/modonomicon/api/ModonomiconConstants.java @@ -193,6 +193,10 @@ public static class Command { public static final String SUCCESS_SAVE_PROGRESS = SUCCESS_PREFIX + "save_progress"; public static final String SUCCESS_LOAD_PROGRESS = SUCCESS_PREFIX + "load_progress"; + public static final String RELOAD_REQUESTED = PREFIX + "reload_requested"; + public static final String RELOAD_SUCCESS = SUCCESS_PREFIX + "reload_requested"; + + public static final String DEFAULT_FAILURE_MESSAGE = PREFIX + "failure"; } } diff --git a/common/src/main/java/com/klikli_dev/modonomicon/command/ReloadBooksCommand.java b/common/src/main/java/com/klikli_dev/modonomicon/command/ReloadBooksCommand.java new file mode 100644 index 000000000..8fc15377a --- /dev/null +++ b/common/src/main/java/com/klikli_dev/modonomicon/command/ReloadBooksCommand.java @@ -0,0 +1,38 @@ +/* + * SPDX-FileCopyrightText: 2022 klikli-dev + * + * SPDX-License-Identifier: MIT + */ + +package com.klikli_dev.modonomicon.command; + +import com.klikli_dev.modonomicon.api.ModonomiconConstants; +import com.klikli_dev.modonomicon.networking.ReloadResourcesOnClientMessage; +import com.klikli_dev.modonomicon.platform.Services; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; + +public class ReloadBooksCommand implements com.mojang.brigadier.Command { + + private static final ReloadBooksCommand CMD = new ReloadBooksCommand(); + + + public static ArgumentBuilder register(CommandDispatcher dispatcher) { + return Commands.literal("reload") + .requires(cs -> cs.hasPermission(2)) + .executes(CMD); + } + + + @Override + public int run(CommandContext context) throws CommandSyntaxException { + Services.NETWORK.sendTo(context.getSource().getPlayer(), new ReloadResourcesOnClientMessage()); + context.getSource().sendSuccess(() -> Component.translatable(ModonomiconConstants.I18n.Command.RELOAD_REQUESTED), true); + return 1; + } +} diff --git a/common/src/main/java/com/klikli_dev/modonomicon/datagen/EnUsProvider.java b/common/src/main/java/com/klikli_dev/modonomicon/datagen/EnUsProvider.java index c56dfc538..5bb9a6143 100644 --- a/common/src/main/java/com/klikli_dev/modonomicon/datagen/EnUsProvider.java +++ b/common/src/main/java/com/klikli_dev/modonomicon/datagen/EnUsProvider.java @@ -79,6 +79,8 @@ private void addMisc() { this.add(Command.SUCCESS_RESET_BOOK, "Successfully reset book: %s"); this.add(Command.SUCCESS_SAVE_PROGRESS, "Saved progress for book: %s. The unlock code has been copied to your clipboard."); this.add(Command.SUCCESS_LOAD_PROGRESS, "Successfully loaded progress for book: %s."); + this.add(Command.RELOAD_REQUESTED, "Requested reload of resource- and datapacks."); + this.add(Command.RELOAD_SUCCESS, "Successfully reloaded resource- and datapacks."); this.add(Command.ERROR_LOAD_PROGRESS, "Invalid unlock code!"); this.add(Command.ERROR_LOAD_PROGRESS_CLIENT, "Failed to decode unlock code. Make sure to have a valid unlock code in your clipboard! Current Clipboard content: \"%s\""); diff --git a/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesDoneMessage.java b/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesDoneMessage.java new file mode 100644 index 000000000..2a1650679 --- /dev/null +++ b/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesDoneMessage.java @@ -0,0 +1,86 @@ +/* + * SPDX-FileCopyrightText: 2022 klikli-dev + * + * SPDX-License-Identifier: MIT + */ + +package com.klikli_dev.modonomicon.networking; + +import com.google.common.collect.Lists; +import com.klikli_dev.modonomicon.Modonomicon; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.storage.WorldData; + +import java.util.Collection; + +import static com.klikli_dev.modonomicon.api.ModonomiconConstants.I18n.Command.RELOAD_SUCCESS; + +public class ReloadResourcesDoneMessage implements Message { + + public static final ResourceLocation ID = new ResourceLocation(Modonomicon.MOD_ID, "reload_resources_done"); + + public ReloadResourcesDoneMessage() { + } + + public ReloadResourcesDoneMessage(FriendlyByteBuf buf) { + this.decode(buf); + } + + @Override + public void encode(FriendlyByteBuf buf) { + } + + @Override + public void decode(FriendlyByteBuf buf) { + } + + @Override + public ResourceLocation getId() { + return ID; + } + + @Override + public void onServerReceived(MinecraftServer minecraftServer, ServerPlayer player) { + + if (!player.hasPermissions(2)) //same leve las the reload command + return; + + //below is copied from ReloadCommand, modified not to need a command source and to only post messages after reload is complete + PackRepository packrepository = minecraftServer.getPackRepository(); + WorldData worlddata = minecraftServer.getWorldData(); + Collection selectedIds = packrepository.getSelectedIds(); + Collection packs = discoverNewPacks(packrepository, worlddata, selectedIds); + reloadPacks(packs, player, minecraftServer); + } + + private static Collection discoverNewPacks(PackRepository pPackRepository, WorldData pWorldData, Collection pSelectedIds) { + pPackRepository.reload(); + Collection collection = Lists.newArrayList(pSelectedIds); + Collection collection1 = pWorldData.getDataConfiguration().dataPacks().getDisabled(); + + for(String s : pPackRepository.getAvailableIds()) { + if (!collection1.contains(s) && !collection.contains(s)) { + collection.add(s); + } + } + + return collection; + } + + public static void reloadPacks(Collection pSelectedIds, ServerPlayer player, MinecraftServer server) { + server.reloadResources(pSelectedIds).exceptionally((error) -> { + Modonomicon.LOG.warn("Failed to execute reload", error); + player.sendSystemMessage(Component.translatable("commands.reload.failure").withStyle(ChatFormatting.RED)); + return null; + }).thenRun(() -> { + player.sendSystemMessage(Component.translatable(RELOAD_SUCCESS).withStyle(ChatFormatting.GREEN)); + }); + } +} diff --git a/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesOnClientMessage.java b/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesOnClientMessage.java new file mode 100644 index 000000000..c7fa4ff22 --- /dev/null +++ b/common/src/main/java/com/klikli_dev/modonomicon/networking/ReloadResourcesOnClientMessage.java @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2022 klikli-dev + * + * SPDX-License-Identifier: MIT + */ + +package com.klikli_dev.modonomicon.networking; + +import com.klikli_dev.modonomicon.Modonomicon; +import com.klikli_dev.modonomicon.platform.Services; +import com.klikli_dev.modonomicon.platform.services.PlatformHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; + +public class ReloadResourcesOnClientMessage implements Message { + + public static final ResourceLocation ID = new ResourceLocation(Modonomicon.MOD_ID, "reload_resources_on_client"); + + public ReloadResourcesOnClientMessage() { + } + + public ReloadResourcesOnClientMessage(FriendlyByteBuf buf) { + this.decode(buf); + } + + @Override + public void encode(FriendlyByteBuf buf) { + } + + @Override + public void decode(FriendlyByteBuf buf) { + } + + @Override + public ResourceLocation getId() { + return ID; + } + + @Override + public void onClientReceived(Minecraft minecraft, Player player) { + minecraft.reloadResourcePacks().thenRun(() -> { + Services.NETWORK.sendToServer(new ReloadResourcesDoneMessage()); + }); + } +} diff --git a/common/src/main/java/com/klikli_dev/modonomicon/registry/CommandRegistry.java b/common/src/main/java/com/klikli_dev/modonomicon/registry/CommandRegistry.java index 022858d1d..92b224aaa 100644 --- a/common/src/main/java/com/klikli_dev/modonomicon/registry/CommandRegistry.java +++ b/common/src/main/java/com/klikli_dev/modonomicon/registry/CommandRegistry.java @@ -8,6 +8,7 @@ import com.klikli_dev.modonomicon.Modonomicon; import com.klikli_dev.modonomicon.command.LoadUnlocksCommand; +import com.klikli_dev.modonomicon.command.ReloadBooksCommand; import com.klikli_dev.modonomicon.command.ResetBookUnlocksCommand; import com.klikli_dev.modonomicon.command.SaveUnlocksCommand; import com.mojang.brigadier.CommandDispatcher; @@ -22,9 +23,10 @@ public static void registerCommands(CommandDispatcher dispat Commands.literal(Modonomicon.MOD_ID) .then(ResetBookUnlocksCommand.register(dispatcher)) .then(SaveUnlocksCommand.register(dispatcher)) + .then(ReloadBooksCommand.register(dispatcher)) ); - dispatcher.register(Commands.literal("modonomicon").redirect(modonomiconCommand)); + dispatcher.register(Commands.literal(Modonomicon.MOD_ID).redirect(modonomiconCommand)); } public static void registerClientCommands(CommandDispatcher dispatcher) { diff --git a/fabric/src/generated/resources/.cache/13ce76d12c64f3a9c0874320845bdcbe00b11956 b/fabric/src/generated/resources/.cache/13ce76d12c64f3a9c0874320845bdcbe00b11956 index eb256f8bb..427956a1b 100644 --- a/fabric/src/generated/resources/.cache/13ce76d12c64f3a9c0874320845bdcbe00b11956 +++ b/fabric/src/generated/resources/.cache/13ce76d12c64f3a9c0874320845bdcbe00b11956 @@ -1,8 +1,8 @@ -// 1.20.1 2024-01-08T09:19:58.146027 Modonomicon/Books: modonomicon +// 1.20.1 2024-01-09T11:06:30.7029862 Modonomicon/Books: modonomicon 149f724b78931be9fa643e1c9288933cc73a75c4 data\modonomicon\modonomicon\books\demo\entries\formatting\basic.json b9ad32b76e2efc9f44c8b76d56670f9dc63f2a94 data\modonomicon\modonomicon\books\demo\commands\test_command2.json -da6b6a832a9392085f982ba05f34e606d64fa13b data\modonomicon\modonomicon\books\demo\entries\formatting\always_locked.json 7cb4c581142b83471177183ec136e5db0f8a1540 data\modonomicon\modonomicon\books\demo\entries\features\multiblock.json +da6b6a832a9392085f982ba05f34e606d64fa13b data\modonomicon\modonomicon\books\demo\entries\formatting\always_locked.json b82c0b99b596152481f8281592d77c822fd7590e data\modonomicon\modonomicon\books\demo\categories\conditional.json 09d31cc11836a50dad4c92daa1695475a6c4fc1f data\modonomicon\modonomicon\books\demo\entries\conditional\always_locked.json a0b01243aa86122c9894a419e5f6998e2d1a2ca3 data\modonomicon\modonomicon\books\demo\entries\features\recipe.json diff --git a/fabric/src/generated/resources/.cache/3eecf17e0b3542fa44b02bae7aa93622bb4a80e9 b/fabric/src/generated/resources/.cache/3eecf17e0b3542fa44b02bae7aa93622bb4a80e9 index 513cce86f..0c9b283d4 100644 --- a/fabric/src/generated/resources/.cache/3eecf17e0b3542fa44b02bae7aa93622bb4a80e9 +++ b/fabric/src/generated/resources/.cache/3eecf17e0b3542fa44b02bae7aa93622bb4a80e9 @@ -1,2 +1,2 @@ -// 1.20.1 2024-01-08T09:19:58.1535555 Modonomicon/Languages: en_us -c02a2188ed3f6ed7de335e505e38a4d6cf90d9e1 assets\modonomicon\lang\en_us.json +// 1.20.1 2024-01-09T11:06:30.7079865 Modonomicon/Languages: en_us +619af0dd17a726e34764055a425bf703af4821e6 assets\modonomicon\lang\en_us.json diff --git a/fabric/src/generated/resources/.cache/e6530a5ab7a2c0d5d93ba510671319215bfabee3 b/fabric/src/generated/resources/.cache/e6530a5ab7a2c0d5d93ba510671319215bfabee3 index b7889665b..c69fa6618 100644 --- a/fabric/src/generated/resources/.cache/e6530a5ab7a2c0d5d93ba510671319215bfabee3 +++ b/fabric/src/generated/resources/.cache/e6530a5ab7a2c0d5d93ba510671319215bfabee3 @@ -1,4 +1,4 @@ -// 1.20.1 2024-01-08T09:19:58.1525565 Modonomicon/Model Definitions +// 1.20.1 2024-01-09T11:06:30.7069867 Modonomicon/Model Definitions b02e0bc9f75e0fde6807935577e74b75348413fb assets\modonomicon\models\item\modonomicon_blue.json 83adea7fd65acd9581797454e1a6dc6122d8a826 assets\modonomicon\models\item\modonomicon_green.json 4b35646623b74487675fa8ec1bb375535100c336 assets\modonomicon\models\item\modonomicon_purple.json diff --git a/fabric/src/generated/resources/.cache/fbe7fdca8a3d7d4724f001a760fe02aeb76403e5 b/fabric/src/generated/resources/.cache/fbe7fdca8a3d7d4724f001a760fe02aeb76403e5 index cfec62c2e..9443df372 100644 --- a/fabric/src/generated/resources/.cache/fbe7fdca8a3d7d4724f001a760fe02aeb76403e5 +++ b/fabric/src/generated/resources/.cache/fbe7fdca8a3d7d4724f001a760fe02aeb76403e5 @@ -1,4 +1,4 @@ -// 1.20.1 2024-01-08T09:19:58.1525565 Modonomicon/Multiblocks: modonomicon +// 1.20.1 2024-01-09T11:06:30.7069867 Modonomicon/Multiblocks: modonomicon 6af533f5fa171fb2cf2d27b166e16ec54b2c5c06 data\modonomicon\modonomicon\multiblocks\test_non_square.json 89b499dd4f3850c8099ad26ae3c286e95ac8cf99 data\modonomicon\modonomicon\multiblocks\demo_fluid.json 9dc306d79a39ee2085be7e1384d8e39640d79e49 data\modonomicon\modonomicon\multiblocks\demo_dense.json diff --git a/fabric/src/generated/resources/assets/modonomicon/lang/en_us.json b/fabric/src/generated/resources/assets/modonomicon/lang/en_us.json index 9470357eb..0bdca474c 100644 --- a/fabric/src/generated/resources/assets/modonomicon/lang/en_us.json +++ b/fabric/src/generated/resources/assets/modonomicon/lang/en_us.json @@ -97,7 +97,9 @@ "modonomicon.command.error.load_progress_client": "Failed to decode unlock code. Make sure to have a valid unlock code in your clipboard! Current Clipboard content: \"%s\"", "modonomicon.command.error.unknown_book": "Unknown book: %s", "modonomicon.command.failure": "Modonomicon tried to run a command for you (e.g. because you read an entry for the first time, or clicked a command button or command link). However, it seems you already reached the maximum use limit for this command.", + "modonomicon.command.reload_requested": "Requested reload of resource- and datapacks.", "modonomicon.command.success.load_progress": "Successfully loaded progress for book: %s.", + "modonomicon.command.success.reload_requested": "Successfully reloaded resource- and datapacks.", "modonomicon.command.success.reset_book": "Successfully reset book: %s", "modonomicon.command.success.save_progress": "Saved progress for book: %s. The unlock code has been copied to your clipboard.", "modonomicon.command.test_command.success": "You got an apple, because reading is cool!", diff --git a/fabric/src/main/java/com/klikli_dev/modonomicon/network/ClientNetworking.java b/fabric/src/main/java/com/klikli_dev/modonomicon/network/ClientNetworking.java index f39b84211..3087d7d76 100644 --- a/fabric/src/main/java/com/klikli_dev/modonomicon/network/ClientNetworking.java +++ b/fabric/src/main/java/com/klikli_dev/modonomicon/network/ClientNetworking.java @@ -18,5 +18,6 @@ public static void registerMessages() { ClientPlayNetworking.registerGlobalReceiver(SyncBookUnlockStatesMessage.ID, new ClientMessageHandler<>(SyncBookUnlockStatesMessage::new)); ClientPlayNetworking.registerGlobalReceiver(SyncBookVisualStatesMessage.ID, new ClientMessageHandler<>(SyncBookVisualStatesMessage::new)); ClientPlayNetworking.registerGlobalReceiver(SyncMultiblockDataMessage.ID, new ClientMessageHandler<>(SyncMultiblockDataMessage::new)); + ClientPlayNetworking.registerGlobalReceiver(ReloadResourcesOnClientMessage.ID, new ClientMessageHandler<>(ReloadResourcesOnClientMessage::new)); } } diff --git a/fabric/src/main/java/com/klikli_dev/modonomicon/network/Networking.java b/fabric/src/main/java/com/klikli_dev/modonomicon/network/Networking.java index 5f3ca7682..27b8ce8c7 100644 --- a/fabric/src/main/java/com/klikli_dev/modonomicon/network/Networking.java +++ b/fabric/src/main/java/com/klikli_dev/modonomicon/network/Networking.java @@ -21,5 +21,6 @@ public static void registerMessages() { ServerPlayNetworking.registerGlobalReceiver(SaveCategoryStateMessage.ID, new ServerMessageHandler<>(SaveCategoryStateMessage::new)); ServerPlayNetworking.registerGlobalReceiver(SaveEntryStateMessage.ID, new ServerMessageHandler<>(SaveEntryStateMessage::new)); ServerPlayNetworking.registerGlobalReceiver(SendUnlockCodeToServerMessage.ID, new ServerMessageHandler<>(SendUnlockCodeToServerMessage::new)); + ServerPlayNetworking.registerGlobalReceiver(ReloadResourcesDoneMessage.ID, new ServerMessageHandler<>(ReloadResourcesDoneMessage::new)); } } diff --git a/forge/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 b/forge/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 index 9fa7584d3..8428e897d 100644 --- a/forge/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 +++ b/forge/src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8 @@ -1,2 +1,2 @@ -// 1.20.1 2024-01-08T09:19:17.5634628 Languages: en_us -c02a2188ed3f6ed7de335e505e38a4d6cf90d9e1 assets/modonomicon/lang/en_us.json +// 1.20.1 2024-01-09T10:59:40.9721648 Languages: en_us +619af0dd17a726e34764055a425bf703af4821e6 assets/modonomicon/lang/en_us.json diff --git a/forge/src/generated/resources/assets/modonomicon/lang/en_us.json b/forge/src/generated/resources/assets/modonomicon/lang/en_us.json index 9470357eb..0bdca474c 100644 --- a/forge/src/generated/resources/assets/modonomicon/lang/en_us.json +++ b/forge/src/generated/resources/assets/modonomicon/lang/en_us.json @@ -97,7 +97,9 @@ "modonomicon.command.error.load_progress_client": "Failed to decode unlock code. Make sure to have a valid unlock code in your clipboard! Current Clipboard content: \"%s\"", "modonomicon.command.error.unknown_book": "Unknown book: %s", "modonomicon.command.failure": "Modonomicon tried to run a command for you (e.g. because you read an entry for the first time, or clicked a command button or command link). However, it seems you already reached the maximum use limit for this command.", + "modonomicon.command.reload_requested": "Requested reload of resource- and datapacks.", "modonomicon.command.success.load_progress": "Successfully loaded progress for book: %s.", + "modonomicon.command.success.reload_requested": "Successfully reloaded resource- and datapacks.", "modonomicon.command.success.reset_book": "Successfully reset book: %s", "modonomicon.command.success.save_progress": "Saved progress for book: %s. The unlock code has been copied to your clipboard.", "modonomicon.command.test_command.success": "You got an apple, because reading is cool!", diff --git a/forge/src/main/java/com/klikli_dev/modonomicon/network/Networking.java b/forge/src/main/java/com/klikli_dev/modonomicon/network/Networking.java index 3ffc7efeb..7d6278a38 100644 --- a/forge/src/main/java/com/klikli_dev/modonomicon/network/Networking.java +++ b/forge/src/main/java/com/klikli_dev/modonomicon/network/Networking.java @@ -108,6 +108,17 @@ public static void registerMessages() { SyncMultiblockDataMessage::new, MessageHandler::handle); + INSTANCE.registerMessage(nextID(), + ReloadResourcesOnClientMessage.class, + ReloadResourcesOnClientMessage::encode, + ReloadResourcesOnClientMessage::new, + MessageHandler::handle); + + INSTANCE.registerMessage(nextID(), + ReloadResourcesDoneMessage.class, + ReloadResourcesDoneMessage::encode, + ReloadResourcesDoneMessage::new, + MessageHandler::handle); } public static void sendToSplit(ServerPlayer player, T message) { diff --git a/gradle.properties b/gradle.properties index e171deeee..065327814 100644 --- a/gradle.properties +++ b/gradle.properties @@ -39,7 +39,7 @@ group=com.klikli_dev mod_id=modonomicon mod_name=Modonomicon mod_license=MIT AND CC-BY-4.0 -mod_version=1.48.1 +mod_version=1.49.0 mod_authors=Kli Kli mod_description=Data-driven minecraft in-game documentation with progress visualization.