Skip to content

Commit c02d157

Browse files
authored
Fixed /reload on Fabric (#100)
## Description Fixed /reload not reloading the Variants ## Changes - **Change 1**: Added an Reload Event on Fabric ## How has this been tested? * Joining world * Add Datapack with Variants * Type /reload * See the variants in game ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Cleanup - [ ] Breaking change - [ ] Documentation update ## Checklist - [x] My code follows the style guidelines of this project. [Contributing](https://github.com/MeAlam1/BlueLib/blob/1.21/CONTRIBUTING.md) - [x] I have performed a self-review of my own code. - [x] I have commented my code following the guidelines. [Contributing](https://github.com/MeAlam1/BlueLib/blob/1.21/CONTRIBUTING.md) - [x] My changes generate no new warnings. ## Related Issues <!-- List any issues that this PR is related to or closes. -->
1 parent bb16e49 commit c02d157

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

fabric/src/main/java/software/bluelib/BlueLib.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* </ul>
2424
*
2525
* @author MeAlam
26-
* @version 1.6.0
26+
* @version 1.7.0
2727
* @since 1.0.0
2828
*/
2929
public class BlueLib implements ModInitializer {
@@ -41,10 +41,6 @@ public class BlueLib implements ModInitializer {
4141
/**
4242
* A {@code public void} that registers a client tick event to initialize the BlueLib mod.
4343
* <p>
44-
* This method checks if the mod is being run in developer mode and if the Geckolib mod is loaded. If both conditions
45-
* are met, it initializes the entities and registers the event listeners for the reload handler.
46-
* </p>
47-
* <p>
4844
* This method uses {@link ClientTickEvents#END_CLIENT_TICK} to register a callback that checks
4945
* whether the mod has already been initialized and calls {@link BlueLibCommon#init()} if necessary.
5046
* </p>
@@ -72,6 +68,7 @@ public void onInitialize() {
7268
*/
7369
public static void registerModEventListeners() {
7470
ServerLifecycleEvents.SERVER_STARTING.register(ReloadHandler::onServerStart);
71+
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(ReloadHandler::onReload);
7572
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register(ChatHandler::onAllowChat);
7673
}
7774
}

fabric/src/main/java/software/bluelib/example/event/ReloadHandler.java

+10-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.concurrent.ScheduledThreadPoolExecutor;
88
import java.util.concurrent.TimeUnit;
99
import net.minecraft.server.MinecraftServer;
10+
import net.minecraft.server.packs.resources.CloseableResourceManager;
1011
import software.bluelib.BlueLibConstants;
1112
import software.bluelib.event.ReloadEventHandler;
1213
import software.bluelib.utils.logging.BaseLogLevel;
@@ -21,26 +22,16 @@
2122
* Key Methods:
2223
* <ul>
2324
* <li>{@link #onServerStart(MinecraftServer)} - Handles server starting events to initialize entity variants.</li>
24-
* <li>{@link #onReload()} - Handles reload events to refresh entity variants.</li>
25+
* <li>{@link #onReload(MinecraftServer, CloseableResourceManager, boolean)} - Handles reload events to refresh entity variants.</li>
2526
* <li>{@link #LoadEntityVariants(MinecraftServer)} - Loads entity variants from JSON files into the server.</li>
2627
* </ul>
2728
*
2829
* @author MeAlam
29-
* @version 1.4.0
30+
* @version 1.7.0
3031
* @since 1.0.0
3132
*/
3233
public class ReloadHandler extends ReloadEventHandler {
3334

34-
/**
35-
* The {@link MinecraftServer} instance for the server handling the events.
36-
* <p>
37-
* This is initialized when the server starts and used to load entity variants.
38-
* </p>
39-
*
40-
* @since 1.0.0
41-
*/
42-
private static MinecraftServer server;
43-
4435
/**
4536
* Handles the server starting event to initialize the {@link MinecraftServer} instance
4637
* and load entity variants.
@@ -51,8 +42,7 @@ public class ReloadHandler extends ReloadEventHandler {
5142
*/
5243
public static void onServerStart(MinecraftServer pServer) {
5344
BlueLibConstants.SCHEDULER = new ScheduledThreadPoolExecutor(1);
54-
server = pServer;
55-
ReloadHandler.LoadEntityVariants(server);
45+
ReloadHandler.LoadEntityVariants(pServer);
5646
BaseLogger.log(BaseLogLevel.INFO, "Entity variants loaded.", true);
5747
}
5848

@@ -65,14 +55,12 @@ public static void onServerStart(MinecraftServer pServer) {
6555
* @author MeAlam
6656
* @since 1.0.0
6757
*/
68-
public static void onReload() {
69-
if (server != null) {
70-
BlueLibConstants.SCHEDULER.schedule(() -> {
71-
server.execute(() -> {
72-
ReloadHandler.LoadEntityVariants(server);
73-
BaseLogger.log(BaseLogLevel.INFO, "Entity variants reloaded.", true);
74-
});
75-
}, 1, TimeUnit.SECONDS);
58+
public static void onReload(MinecraftServer pServer, CloseableResourceManager pCloseableResourceManager, boolean pBoolean) {
59+
if (pServer != null) {
60+
BlueLibConstants.SCHEDULER.schedule(() -> pServer.execute(() -> {
61+
ReloadHandler.LoadEntityVariants(pServer);
62+
BaseLogger.log(BaseLogLevel.INFO, "Entity variants reloaded.", true);
63+
}), 1, TimeUnit.SECONDS);
7664
}
7765
}
7866

0 commit comments

Comments
 (0)