Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit c9e0c16

Browse files
committed
Dispatch BasicEventHooks and ServerLifecycleHooks to LifecycleEvents
1 parent c3fa9a1 commit c9e0c16

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/server/ServerLifecycleHooks.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import net.minecraft.server.MinecraftServer;
2323

24+
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
25+
2426
/**
2527
* This is a stub of the ServerLifecycleHooks class in Forge for mods that use getCurrentServer.
2628
*/
@@ -30,4 +32,20 @@ public class ServerLifecycleHooks {
3032
public static MinecraftServer getCurrentServer() {
3133
return currentServer;
3234
}
35+
36+
// Forge returns `!MinecraftForge.EVENT_BUS.post(...)`, so true == continue, false == cancel.
37+
public static boolean handleServerAboutToStart(final MinecraftServer server) {
38+
LifecycleEvents.handleServerAboutToStart(server);
39+
return true; // patchwork does not allow you to cancel server startup.
40+
}
41+
42+
// Forge returns `!MinecraftForge.EVENT_BUS.post(...)`, so true == continue, false == cancel.
43+
public static boolean handleServerStarting(final MinecraftServer server) {
44+
LifecycleEvents.handleServerStarting(server);
45+
return true; // patchwork does not allow you to cancel server startup.
46+
}
47+
48+
public static void handleServerStarted(final MinecraftServer server) {
49+
LifecycleEvents.handleServerStarted(server);
50+
}
3351
}

patchwork-god-classes/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ version = getSubprojectVersion(project, "0.1.0")
33

44
dependencies {
55
compile project(path: ':patchwork-fml', configuration: 'dev')
6+
compile project(path: ':patchwork-events-lifecycle', configuration: 'dev')
67
}

patchwork-god-classes/src/main/java/net/minecraftforge/fml/hooks/BasicEventHooks.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,39 @@
1919

2020
package net.minecraftforge.fml.hooks;
2121

22+
import net.minecraftforge.event.TickEvent;
23+
24+
import net.minecraft.entity.player.PlayerEntity;
25+
import net.minecraft.world.World;
26+
27+
import net.patchworkmc.impl.event.lifecycle.LifecycleEvents;
28+
2229
/*
2330
* Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules.
2431
* Do not keep implementation details here, methods should be thin wrappers around methods in other modules.
2532
*/
2633
public class BasicEventHooks {
34+
public static void onPlayerPreTick(PlayerEntity player) {
35+
LifecycleEvents.firePlayerTickEvent(TickEvent.Phase.START, player);
36+
}
37+
38+
public static void onPlayerPostTick(PlayerEntity player) {
39+
LifecycleEvents.firePlayerTickEvent(TickEvent.Phase.END, player);
40+
}
41+
42+
public static void onPreWorldTick(World world) {
43+
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, world);
44+
}
45+
46+
public static void onPostWorldTick(World world) {
47+
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.END, world);
48+
}
49+
50+
public static void onPreClientTick() {
51+
LifecycleEvents.fireClientTickEvent(TickEvent.Phase.START);
52+
}
53+
54+
public static void onPostClientTick() {
55+
LifecycleEvents.fireClientTickEvent(TickEvent.Phase.END);
56+
}
2757
}

patchwork-god-classes/src/main/resources/fabric.mod.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
],
1717
"depends": {
1818
"fabricloader": ">=0.8.4",
19-
"patchwork-fml": "*"
19+
"patchwork-fml": "*",
20+
"patchwork-events-lifecycle": "*"
2021
},
2122
"custom": {
2223
"modmenu:api": true,

0 commit comments

Comments
 (0)