Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

RisingInIris2017

Members
  • Joined

  • Last visited

Everything posted by RisingInIris2017

  1. Oh I got it. I'm using IDEA, so if I want to reload these JSONs, I have to make a datapack and put it into `/run`? Are there some more easier ways?
  2. Thanks for your kind-hearted explanation! I tried your method and now it can read JSONs from correct ResourceLocation. private void jsonRulesReader (AddReloadListenerEvent event) { event.addListener(new JsonReloadListener((new GsonBuilder()).create(), "rules") { @Override protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) { objectIn.forEach((resourceLocation, ruleJsonElement) -> { try { JsonObject jsonObject = JSONUtils.getJsonObject(ruleJsonElement, "rule"); LOGGER.warn(jsonObject); } catch (IllegalArgumentException | JsonParseException e) { LOGGER.error("Parsing error loading custom rules. Message: {}", e.getMessage()); } }); } }); } But I have a new problem: it cannot reload data when I type `/reload` command. To be more specific, I can reproduce this issue by following steps: 1. Start Minecraft and see it loading my mod's datapack. 2. After it finishes loading, modify a JSON. 3. Execute the `/reload` command. 4. In console log I find that it prints the version of JSON before it was modified. 5. Restart Minecraft, then I can see the modified JSON is loaded. This is not the behavior I want. I need it to be reloaded everytime the `/reload` command is executed. So how should I modify my codes to achieve that goal?
  3. I found that if I `new JsonReloadListener`, I should pass two arguments to two parameters of its constructor, the first one is a `Gson`, while second one is a `String`. I read the code of AdvancementManager, it passes `(new GsonBuilder()).create()` to the first parameter, and passes String `"advancement"` to the second one. So I wrote these codes: private void jsonRulesReader (AddReloadListenerEvent event) { event.addListener(new JsonReloadListener((new GsonBuilder()).create(), "some String") { @Override protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) { "something need to do" } }); } I wonder what the second parameters mean. What will that string be? Will it become a part of a certain `ResourceLocation`, or a part of file name?
  4. To put more specifically, I expect my mod has such a behavior: 1. When Minecraft instance(both client and server) start, load some data from a JSON file. 2. Using these data to do what it should do, until vanilla `/reload` command is executed. 3. Reload new data from that JSON file. 4. Continue to do what it should do. I wrote these codes in my mod's main class: @Mod("spellbind") public class Spellbind { public static final String MOD_ID = "spellbind"; public static final String MOD_NAME = "Spellbind"; private static final Logger LOGGER = LogManager.getLogger(); public Spellbind() { final IEventBus forgeBus = MinecraftForge.EVENT_BUS; forgeBus.addListener(this::jsonRulesReader); } // Read JSON logic // Read JSON from datapack, so that modpack makers can set their own "spells". private void jsonRulesReader (AddReloadListenerEvent event) { event.addListener("something missing"); } Then I did find something missing. I had no idea about how to use the `AddReloadListenerEvent`. I searched the Internet and get this: I tried to use the `JsonReloadListener`, but I found I did not understand it, neither. I do read many Forge forum posts and codes(from other mods and Minecraft vanilla itself), but I still feel difficult. You are highly appreciated if you could explain what code I should write to achieve my goal. Thanks in advance!

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.