From 3ff964323ccc5ae6551dd0226c1eefc4bcca5b47 Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:30:53 +0200 Subject: [PATCH] Breaking Changes: Big Refactoring Add MModdingPackets Renaming Config#getQualifier Add ClientOperations --- .../mmodding_lib/MModdingLibConfig.java | 8 +-- .../client/ClientPacketReceivers.java | 4 +- .../client/MModdingModConfigsScreen.java | 4 +- .../mmodding_lib/client/MModdingScreen.java | 2 +- .../mmodding_lib/impl/ModMenuApiImpl.java | 4 +- .../base/MModdingClientModInitializer.java | 2 +- .../library/base/MModdingModInitializer.java | 6 +- .../widgets/ConditionalFieldWidget.java | 2 +- .../screen}/widgets/NumberFieldWidget.java | 2 +- .../mmodding_lib/library/config/Config.java | 55 +++++++++++++++---- .../library/config/ConfigObject.java | 24 ++++---- .../{ => config}/client/TemporaryConfig.java | 12 ++-- .../screen/ConfigElementsListEntry.java | 8 +-- .../screen/ConfigElementsListWidget.java | 14 ++--- .../{ => client}/screen/ConfigScreen.java | 2 +- .../screen/ConfigScreenOptions.java | 2 +- .../screen/editing/BooleanEditScreen.java | 8 +-- .../screen/editing/EditScreen.java | 8 +-- .../screen/editing/NumberEditScreen.java | 10 ++-- .../screen/editing/StringEditScreen.java | 8 +-- .../library/potions/CustomPotion.java | 3 +- .../mixin/injectors/EntryListWidgetMixin.java | 2 +- .../networking/MModdingPackets.java | 8 +++ .../networking/client/ClientOperations.java | 7 +++ .../server/ServerOperations.java | 8 +-- 25 files changed, 133 insertions(+), 80 deletions(-) rename src/main/java/com/mmodding/mmodding_lib/library/{screens => client/screen}/widgets/ConditionalFieldWidget.java (91%) rename src/main/java/com/mmodding/mmodding_lib/library/{screens => client/screen}/widgets/NumberFieldWidget.java (90%) rename src/main/java/com/mmodding/mmodding_lib/library/{ => config}/client/TemporaryConfig.java (73%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/ConfigElementsListEntry.java (95%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/ConfigElementsListWidget.java (76%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/ConfigScreen.java (98%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/ConfigScreenOptions.java (70%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/editing/BooleanEditScreen.java (81%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/editing/EditScreen.java (91%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/editing/NumberEditScreen.java (73%) rename src/main/java/com/mmodding/mmodding_lib/library/config/{ => client}/screen/editing/StringEditScreen.java (78%) create mode 100644 src/main/java/com/mmodding/mmodding_lib/networking/MModdingPackets.java create mode 100644 src/main/java/com/mmodding/mmodding_lib/networking/client/ClientOperations.java rename src/main/java/com/mmodding/mmodding_lib/{library => networking}/server/ServerOperations.java (80%) diff --git a/src/main/java/com/mmodding/mmodding_lib/MModdingLibConfig.java b/src/main/java/com/mmodding/mmodding_lib/MModdingLibConfig.java index 48d5622..629c939 100644 --- a/src/main/java/com/mmodding/mmodding_lib/MModdingLibConfig.java +++ b/src/main/java/com/mmodding/mmodding_lib/MModdingLibConfig.java @@ -1,19 +1,19 @@ package com.mmodding.mmodding_lib; import com.mmodding.mmodding_lib.library.config.*; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreenOptions; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreenOptions; import net.minecraft.text.Text; public class MModdingLibConfig implements Config { @Override - public String getConfigName() { + public String getQualifier() { return "mmodding_lib"; } @Override - public String getFileName() { + public String getFilePath() { return "mmodding/common"; } diff --git a/src/main/java/com/mmodding/mmodding_lib/client/ClientPacketReceivers.java b/src/main/java/com/mmodding/mmodding_lib/client/ClientPacketReceivers.java index 2201d7b..cbe7dd6 100644 --- a/src/main/java/com/mmodding/mmodding_lib/client/ClientPacketReceivers.java +++ b/src/main/java/com/mmodding/mmodding_lib/client/ClientPacketReceivers.java @@ -4,7 +4,7 @@ import com.mmodding.mmodding_lib.library.events.client.ClientConfigNetworkingEvents; import com.mmodding.mmodding_lib.library.config.Config; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import net.minecraft.util.Identifier; +import com.mmodding.mmodding_lib.networking.MModdingPackets; import org.jetbrains.annotations.ApiStatus; import org.quiltmc.loader.api.minecraft.ClientOnly; import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; @@ -15,7 +15,7 @@ public class ClientPacketReceivers { public static void register() { - ClientPlayNetworking.registerGlobalReceiver(new Identifier("configs-channel"), ((client, handler, buf, responseSender) -> { + ClientPlayNetworking.registerGlobalReceiver(MModdingPackets.CONFIGS, ((client, handler, buf, responseSender) -> { String configName = buf.readString(); String configContent = buf.readString(); diff --git a/src/main/java/com/mmodding/mmodding_lib/client/MModdingModConfigsScreen.java b/src/main/java/com/mmodding/mmodding_lib/client/MModdingModConfigsScreen.java index 200eae7..9bd3426 100644 --- a/src/main/java/com/mmodding/mmodding_lib/client/MModdingModConfigsScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/client/MModdingModConfigsScreen.java @@ -2,9 +2,9 @@ import com.google.common.collect.ImmutableList; import com.mmodding.mmodding_lib.MModdingLib; -import com.mmodding.mmodding_lib.library.client.TemporaryConfig; +import com.mmodding.mmodding_lib.library.config.client.TemporaryConfig; import com.mmodding.mmodding_lib.library.config.Config; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; diff --git a/src/main/java/com/mmodding/mmodding_lib/client/MModdingScreen.java b/src/main/java/com/mmodding/mmodding_lib/client/MModdingScreen.java index 3870a30..bc68cc1 100644 --- a/src/main/java/com/mmodding/mmodding_lib/client/MModdingScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/client/MModdingScreen.java @@ -1,7 +1,7 @@ package com.mmodding.mmodding_lib.client; import com.mmodding.mmodding_lib.MModdingLib; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import com.mmodding.mmodding_lib.library.utils.Colors; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.screen.Screen; diff --git a/src/main/java/com/mmodding/mmodding_lib/impl/ModMenuApiImpl.java b/src/main/java/com/mmodding/mmodding_lib/impl/ModMenuApiImpl.java index 19c5165..d9786ec 100644 --- a/src/main/java/com/mmodding/mmodding_lib/impl/ModMenuApiImpl.java +++ b/src/main/java/com/mmodding/mmodding_lib/impl/ModMenuApiImpl.java @@ -2,7 +2,7 @@ import com.mmodding.mmodding_lib.MModdingLib; import com.mmodding.mmodding_lib.client.MModdingScreen; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; @@ -21,7 +21,7 @@ public Map> getProvidedConfigScreenFactories() { Map> configScreens = new HashMap<>(); MModdingLib.CONFIGS.forEach(((modId, config) -> { if (config.getConfigOptions() != null) { - configScreens.put(modId, screen -> new ConfigScreen(config.getConfigName(), config, screen)); + configScreens.put(modId, screen -> new ConfigScreen(config.getQualifier(), config, screen)); } })); return configScreens; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingClientModInitializer.java b/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingClientModInitializer.java index d8e2835..fea278a 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingClientModInitializer.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingClientModInitializer.java @@ -23,7 +23,7 @@ default void onInitializeClient(ModContainer mod) { this.getClientElementsInitializers().forEach(ClientElementsInitializer::registerClient); if (this.getClientConfig() != null) { this.getClientConfig().initializeConfig(); - MModdingLibClient.CLIENT_CONFIGS.put(this.getClientConfig().getConfigName(), this.getClientConfig()); + MModdingLibClient.CLIENT_CONFIGS.put(this.getClientConfig().getQualifier(), this.getClientConfig()); } } diff --git a/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingModInitializer.java b/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingModInitializer.java index 7f2039a..d48fe87 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingModInitializer.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/base/MModdingModInitializer.java @@ -2,7 +2,7 @@ import com.mmodding.mmodding_lib.MModdingLib; import com.mmodding.mmodding_lib.client.MModdingLibClient; -import com.mmodding.mmodding_lib.library.client.TemporaryConfig; +import com.mmodding.mmodding_lib.library.config.client.TemporaryConfig; import com.mmodding.mmodding_lib.library.config.Config; import com.mmodding.mmodding_lib.library.initializers.ElementsInitializer; import net.fabricmc.api.EnvType; @@ -27,9 +27,9 @@ default void onInitialize(ModContainer mod) { this.getElementsInitializers().forEach(ElementsInitializer::register); if (this.getConfig() != null) { this.getConfig().initializeConfig(); - MModdingLib.CONFIGS.put(this.getConfig().getConfigName(), this.getConfig()); + MModdingLib.CONFIGS.put(this.getConfig().getQualifier(), this.getConfig()); if (MinecraftQuiltLoader.getEnvironmentType() == EnvType.CLIENT) { - MModdingLibClient.CLIENT_CONFIGS.put(this.getConfig().getConfigName(), TemporaryConfig.fromConfig(this.getConfig())); + MModdingLibClient.CLIENT_CONFIGS.put(this.getConfig().getQualifier(), TemporaryConfig.fromConfig(this.getConfig())); } } } diff --git a/src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/ConditionalFieldWidget.java b/src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/ConditionalFieldWidget.java similarity index 91% rename from src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/ConditionalFieldWidget.java rename to src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/ConditionalFieldWidget.java index 5077223..b0f3843 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/ConditionalFieldWidget.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/ConditionalFieldWidget.java @@ -1,4 +1,4 @@ -package com.mmodding.mmodding_lib.library.screens.widgets; +package com.mmodding.mmodding_lib.library.client.screen.widgets; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.widget.TextFieldWidget; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/NumberFieldWidget.java b/src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/NumberFieldWidget.java similarity index 90% rename from src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/NumberFieldWidget.java rename to src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/NumberFieldWidget.java index 336074a..6437682 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/screens/widgets/NumberFieldWidget.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/client/screen/widgets/NumberFieldWidget.java @@ -1,4 +1,4 @@ -package com.mmodding.mmodding_lib.library.screens.widgets; +package com.mmodding.mmodding_lib.library.client.screen.widgets; import net.minecraft.client.font.TextRenderer; import net.minecraft.text.Text; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/Config.java b/src/main/java/com/mmodding/mmodding_lib/library/config/Config.java index 150906e..90e917e 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/Config.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/Config.java @@ -3,8 +3,9 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreenOptions; -import com.mmodding.mmodding_lib.library.server.ServerOperations; +import com.mmodding.mmodding_lib.MModdingLibConfig; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreenOptions; +import com.mmodding.mmodding_lib.networking.server.ServerOperations; import com.mmodding.mmodding_lib.library.utils.ConfigUtils; import net.minecraft.server.network.ServerPlayerEntity; import org.quiltmc.loader.api.QuiltLoader; @@ -14,18 +15,50 @@ public interface Config { - String getConfigName(); + /** + * The "identifier" of the config. Used to define the translations keys of the config. + * You can take example on {@link MModdingLibConfig#getQualifier()}. + * @return the qualifier of the config + */ + String getQualifier(); - String getFileName(); + /** + * The file path. + * You can take example on {@link MModdingLibConfig#getPath()}. + * @return the path of the file (from the config directory and without file extension) + */ + String getFilePath(); + /** + * The default config object. + * You can take example on {@link MModdingLibConfig#defaultConfig()}. + * @return the config object in its default state + * @see ConfigObject.Builder + */ ConfigObject defaultConfig(); + /** + * Some options used in the config screen. + * You can take example on {@link MModdingLibConfig#getConfigOptions()} + * @return the config screen options + * @see ConfigScreenOptions + */ ConfigScreenOptions getConfigOptions(); + /** + * The config content directly read from the config json file + * @return the config content + * @see ConfigObject + */ default ConfigObject getContent() { return new ConfigObject(this.getReader().getAsJsonObject()); } + /** + * This method allows to send a config from a server to a client + * @param player the targeted player + * @see ServerOperations + */ @DedicatedServerOnly default void sendServerConfigToClient(ServerPlayerEntity player) { ServerOperations.sendConfigToClient(this, player); @@ -41,17 +74,17 @@ private JsonElement getReader() { private String getPath() { return QuiltLoader.getConfigDir().toString() + ConfigUtils.getSeparator() + - this.getFileName() - .replace("\\", ConfigUtils.getSeparator()) - .replace("/", ConfigUtils.getSeparator()) - + ".json"; + this.getFilePath() + .replace("\\", ConfigUtils.getSeparator()) + .replace("/", ConfigUtils.getSeparator()) + + ".json"; } default void saveConfig(ConfigObject configObject) { try { FileWriter configWriter = new FileWriter(this.getPath()); String json = new GsonBuilder().setPrettyPrinting().create() - .toJson(ConfigObject.Builder.fromConfigObject(configObject).getJsonObject()); + .toJson(ConfigObject.Builder.fromConfigObject(configObject).getJsonObject()); configWriter.write(json); configWriter.close(); } catch (IOException e) { @@ -60,8 +93,8 @@ default void saveConfig(ConfigObject configObject) { } default void initializeConfig() { - if (this.getFileName().contains("\\") || this.getFileName().contains("/")) { - String path = this.getFileName().replace("\\", "/"); + if (this.getFilePath().contains("\\") || this.getFilePath().contains("/")) { + String path = this.getFilePath().replace("\\", "/"); String[] strings = path.split("/"); int counter = 0; StringBuilder temp = new StringBuilder(); diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/ConfigObject.java b/src/main/java/com/mmodding/mmodding_lib/library/config/ConfigObject.java index b0e190c..d4b581f 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/ConfigObject.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/ConfigObject.java @@ -69,11 +69,9 @@ public static Builder fromConfigObject(ConfigObject configObject) { public Builder addParameter(String parameter, Value value) { switch (value.getType()) { - case "string" -> this.jsonObject.addProperty(parameter, value.getValue()); - case "number" -> this.jsonObject.addProperty(parameter, Integer.valueOf(value.getValue())); - case "boolean" -> { - this.jsonObject.addProperty(parameter, Boolean.valueOf(value.getValue())); - } + case STRING -> this.jsonObject.addProperty(parameter, value.getValue()); + case NUMBER -> this.jsonObject.addProperty(parameter, Integer.valueOf(value.getValue())); + case BOOLEAN -> this.jsonObject.addProperty(parameter, Boolean.valueOf(value.getValue())); } return this; } @@ -132,7 +130,7 @@ public ConfigObject build() { public static class Value { private final T value; - private final String type; + private final Type type; public static Value fromJsonElement(JsonElement element) { if (element instanceof JsonPrimitive primitive) { @@ -147,11 +145,11 @@ public static Value fromJsonElement(JsonElement element) { public Value(T value) { this.value = value; if (value instanceof String) { - this.type = "string"; + this.type = Type.STRING; } else if (value instanceof Number) { - this.type = "number"; + this.type = Type.NUMBER; } else if (value instanceof Boolean) { - this.type = "boolean"; + this.type = Type.BOOLEAN; } else { throw new IllegalArgumentException("Invalid Parameter Type"); } @@ -161,8 +159,14 @@ public String getValue() { return String.valueOf(value); } - public String getType() { + public Type getType() { return this.type; } + + public enum Type { + STRING, + NUMBER, + BOOLEAN + } } } diff --git a/src/main/java/com/mmodding/mmodding_lib/library/client/TemporaryConfig.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/TemporaryConfig.java similarity index 73% rename from src/main/java/com/mmodding/mmodding_lib/library/client/TemporaryConfig.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/TemporaryConfig.java index 4235f39..ac4658e 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/client/TemporaryConfig.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/TemporaryConfig.java @@ -1,8 +1,8 @@ -package com.mmodding.mmodding_lib.library.client; +package com.mmodding.mmodding_lib.library.config.client; import com.mmodding.mmodding_lib.library.config.Config; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreenOptions; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreenOptions; public abstract class TemporaryConfig implements Config { @@ -22,13 +22,13 @@ public static TemporaryConfig fromConfig(Config config) { return new TemporaryConfig() { @Override - public String getConfigName() { - return config.getConfigName(); + public String getQualifier() { + return config.getQualifier(); } @Override - public String getFileName() { - return config.getFileName(); + public String getFilePath() { + return config.getFilePath(); } @Override diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListEntry.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListEntry.java similarity index 95% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListEntry.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListEntry.java index 4c3d7e5..38906e0 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListEntry.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListEntry.java @@ -1,4 +1,4 @@ -package com.mmodding.mmodding_lib.library.config.screen; +package com.mmodding.mmodding_lib.library.config.client.screen; import com.mmodding.mmodding_lib.library.config.ConfigObject; import net.minecraft.client.MinecraftClient; @@ -35,17 +35,17 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth int color; String stringValue; switch (this.fieldValue.getType()) { - case "string" -> { + case STRING -> { fieldType = Text.translatable("mmodding_lib.configs.string"); color = 4781378; stringValue = this.fieldValue.getValue(); } - case "number" -> { + case NUMBER -> { fieldType = Text.translatable("mmodding_lib.configs.integer"); color = 1641430; stringValue = this.fieldValue.getValue(); } - case "boolean" -> { + case BOOLEAN -> { fieldType = Text.translatable("mmodding_lib.configs.boolean"); color = 14027531; stringValue = this.fieldValue.getValue(); diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListWidget.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListWidget.java similarity index 76% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListWidget.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListWidget.java index a75a2de..cc3082a 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigElementsListWidget.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigElementsListWidget.java @@ -1,10 +1,10 @@ -package com.mmodding.mmodding_lib.library.config.screen; +package com.mmodding.mmodding_lib.library.config.client.screen; import com.mmodding.mmodding_lib.library.config.Config; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.editing.BooleanEditScreen; -import com.mmodding.mmodding_lib.library.config.screen.editing.NumberEditScreen; -import com.mmodding.mmodding_lib.library.config.screen.editing.StringEditScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.editing.BooleanEditScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.editing.NumberEditScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.editing.StringEditScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; @@ -60,9 +60,9 @@ public void removeParameter(ConfigElementsListEntry entry) { public void modifyParameter(ConfigElementsListEntry entry) { String stringValue = entry.getFieldValue().getValue(); switch (entry.getFieldValue().getType()) { - case "string" -> this.client.setScreen(new StringEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(stringValue))); - case "number" -> this.client.setScreen(new NumberEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(Integer.valueOf(stringValue)))); - case "boolean" -> this.client.setScreen(new BooleanEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(Boolean.valueOf(stringValue)))); + case STRING -> this.client.setScreen(new StringEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(stringValue))); + case NUMBER -> this.client.setScreen(new NumberEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(Integer.valueOf(stringValue)))); + case BOOLEAN -> this.client.setScreen(new BooleanEditScreen(this.screen, this, entry, this.mutableConfig, entry.getFieldName(), new ConfigObject.Value<>(Boolean.valueOf(stringValue)))); } } diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreen.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreen.java similarity index 98% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreen.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreen.java index 9d9707d..d874a8e 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreen.java @@ -1,4 +1,4 @@ -package com.mmodding.mmodding_lib.library.config.screen; +package com.mmodding.mmodding_lib.library.config.client.screen; import com.mmodding.mmodding_lib.library.config.Config; import com.mojang.blaze3d.systems.RenderSystem; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreenOptions.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreenOptions.java similarity index 70% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreenOptions.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreenOptions.java index c573a34..07f8e94 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/ConfigScreenOptions.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/ConfigScreenOptions.java @@ -1,4 +1,4 @@ -package com.mmodding.mmodding_lib.library.config.screen; +package com.mmodding.mmodding_lib.library.config.client.screen; import net.minecraft.text.Text; import net.minecraft.util.Identifier; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/BooleanEditScreen.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/BooleanEditScreen.java similarity index 81% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/BooleanEditScreen.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/BooleanEditScreen.java index ee83eb4..75d9c59 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/BooleanEditScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/BooleanEditScreen.java @@ -1,9 +1,9 @@ -package com.mmodding.mmodding_lib.library.config.screen.editing; +package com.mmodding.mmodding_lib.library.config.client.screen.editing; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListEntry; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListWidget; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListEntry; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/EditScreen.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/EditScreen.java similarity index 91% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/EditScreen.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/EditScreen.java index 1d020af..158f41b 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/EditScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/EditScreen.java @@ -1,9 +1,9 @@ -package com.mmodding.mmodding_lib.library.config.screen.editing; +package com.mmodding.mmodding_lib.library.config.client.screen.editing; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListEntry; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListWidget; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListEntry; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.Tessellator; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/NumberEditScreen.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/NumberEditScreen.java similarity index 73% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/NumberEditScreen.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/NumberEditScreen.java index 6c30656..4a61576 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/NumberEditScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/NumberEditScreen.java @@ -1,10 +1,10 @@ -package com.mmodding.mmodding_lib.library.config.screen.editing; +package com.mmodding.mmodding_lib.library.config.client.screen.editing; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListEntry; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListWidget; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; -import com.mmodding.mmodding_lib.library.screens.widgets.NumberFieldWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListEntry; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.client.screen.widgets.NumberFieldWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/StringEditScreen.java b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/StringEditScreen.java similarity index 78% rename from src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/StringEditScreen.java rename to src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/StringEditScreen.java index a57436f..77bd12e 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/config/screen/editing/StringEditScreen.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/config/client/screen/editing/StringEditScreen.java @@ -1,9 +1,9 @@ -package com.mmodding.mmodding_lib.library.config.screen.editing; +package com.mmodding.mmodding_lib.library.config.client.screen.editing; import com.mmodding.mmodding_lib.library.config.ConfigObject; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListEntry; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListWidget; -import com.mmodding.mmodding_lib.library.config.screen.ConfigScreen; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListEntry; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigScreen; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; diff --git a/src/main/java/com/mmodding/mmodding_lib/library/potions/CustomPotion.java b/src/main/java/com/mmodding/mmodding_lib/library/potions/CustomPotion.java index 5a589eb..f7c160a 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/potions/CustomPotion.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/potions/CustomPotion.java @@ -1,5 +1,6 @@ package com.mmodding.mmodding_lib.library.potions; +import com.mmodding.mmodding_lib.library.base.MModdingBootStrapInitializer; import com.mmodding.mmodding_lib.mixin.accessors.BrewingRecipeRegistryAccessor; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.item.Item; @@ -24,7 +25,7 @@ public CustomPotion(@Nullable String string, StatusEffectInstance... statusEffec * @apiNote Must be used in a class that extends MModdingBootStrapInitializer * @param basePotion the potion at the start of the potion creation * @param ingredient the ingredient needed to make the potion - * @see com.mmodding.mmodding_lib.library.base.MModdingBootStrapInitializer + * @see MModdingBootStrapInitializer */ public CustomPotion addBrewingRecipe(Potion basePotion, Item ingredient) { BrewingRecipeRegistryAccessor.registerPotionRecipe(basePotion, ingredient, this); diff --git a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/EntryListWidgetMixin.java b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/EntryListWidgetMixin.java index c27cbee..3dc8365 100644 --- a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/EntryListWidgetMixin.java +++ b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/EntryListWidgetMixin.java @@ -2,7 +2,7 @@ import com.mmodding.mmodding_lib.MModdingLib; import com.mmodding.mmodding_lib.client.MModdingModConfigsScreen; -import com.mmodding.mmodding_lib.library.config.screen.ConfigElementsListWidget; +import com.mmodding.mmodding_lib.library.config.client.screen.ConfigElementsListWidget; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.widget.EntryListWidget; import net.minecraft.client.util.math.MatrixStack; diff --git a/src/main/java/com/mmodding/mmodding_lib/networking/MModdingPackets.java b/src/main/java/com/mmodding/mmodding_lib/networking/MModdingPackets.java new file mode 100644 index 0000000..ec88063 --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/networking/MModdingPackets.java @@ -0,0 +1,8 @@ +package com.mmodding.mmodding_lib.networking; + +import com.mmodding.mmodding_lib.library.utils.MModdingIdentifier; + +public class MModdingPackets { + + public static final MModdingIdentifier CONFIGS = new MModdingIdentifier("networking/configs"); +} diff --git a/src/main/java/com/mmodding/mmodding_lib/networking/client/ClientOperations.java b/src/main/java/com/mmodding/mmodding_lib/networking/client/ClientOperations.java new file mode 100644 index 0000000..9c34681 --- /dev/null +++ b/src/main/java/com/mmodding/mmodding_lib/networking/client/ClientOperations.java @@ -0,0 +1,7 @@ +package com.mmodding.mmodding_lib.networking.client; + +import org.quiltmc.loader.api.minecraft.ClientOnly; + +@ClientOnly +public class ClientOperations { +} diff --git a/src/main/java/com/mmodding/mmodding_lib/library/server/ServerOperations.java b/src/main/java/com/mmodding/mmodding_lib/networking/server/ServerOperations.java similarity index 80% rename from src/main/java/com/mmodding/mmodding_lib/library/server/ServerOperations.java rename to src/main/java/com/mmodding/mmodding_lib/networking/server/ServerOperations.java index 4161caa..82319c4 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/server/ServerOperations.java +++ b/src/main/java/com/mmodding/mmodding_lib/networking/server/ServerOperations.java @@ -1,11 +1,11 @@ -package com.mmodding.mmodding_lib.library.server; +package com.mmodding.mmodding_lib.networking.server; import com.mmodding.mmodding_lib.library.config.Config; import com.mmodding.mmodding_lib.library.config.ConfigObject; import com.mmodding.mmodding_lib.library.events.server.ServerConfigNetworkingEvents; +import com.mmodding.mmodding_lib.networking.MModdingPackets; import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; import org.quiltmc.loader.api.minecraft.DedicatedServerOnly; import org.quiltmc.qsl.networking.api.PacketByteBufs; import org.quiltmc.qsl.networking.api.ServerPlayNetworking; @@ -15,12 +15,12 @@ public class ServerOperations { public static void sendConfigToClient(Config config, ServerPlayerEntity player) { PacketByteBuf packet = PacketByteBufs.create(); - packet.writeString(config.getConfigName()); + packet.writeString(config.getQualifier()); packet.writeString(ConfigObject.Builder.fromConfigObject(config.getContent()).getJsonObject().toString()); ServerConfigNetworkingEvents.BEFORE.invoker().beforeConfigSent(config); - ServerPlayNetworking.send(player, new Identifier("configs-channel"), packet); + ServerPlayNetworking.send(player, MModdingPackets.CONFIGS, packet); ServerConfigNetworkingEvents.AFTER.invoker().afterConfigSent(config); }