mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-13 16:53:35 -04:00
Add world unload event (And functional interface annotations to events) (#895)
* Add world unload event * Add functional interface annotations to all events
This commit is contained in:
parent
33df8bfb70
commit
3d76399a1e
13 changed files with 54 additions and 0 deletions
|
@ -78,10 +78,12 @@ public final class ClientBlockEntityEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onLoad(BlockEntity blockEntity, ClientWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onUnload(BlockEntity blockEntity, ClientWorld world);
|
||||
}
|
||||
|
|
|
@ -78,10 +78,12 @@ public final class ClientChunkEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onChunkLoad(ClientWorld world, WorldChunk chunk);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onChunkUnload(ClientWorld world, WorldChunk chunk);
|
||||
}
|
||||
|
|
|
@ -78,10 +78,12 @@ public final class ClientEntityEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onLoad(Entity entity, ClientWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onUnload(Entity entity, ClientWorld world);
|
||||
}
|
||||
|
|
|
@ -51,10 +51,12 @@ public final class ClientLifecycleEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ClientStarted {
|
||||
void onClientStarted(MinecraftClient client);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ClientStopping {
|
||||
void onClientStopping(MinecraftClient client);
|
||||
}
|
||||
|
|
|
@ -120,18 +120,22 @@ public final class ClientTickEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StartTick {
|
||||
void onStartTick(MinecraftClient client);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndTick {
|
||||
void onEndTick(MinecraftClient client);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StartWorldTick {
|
||||
void onStartTick(ClientWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndWorldTick {
|
||||
void onEndTick(ClientWorld world);
|
||||
}
|
||||
|
|
|
@ -75,10 +75,12 @@ public final class ServerBlockEntityEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onLoad(BlockEntity blockEntity, ServerWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onUnload(BlockEntity blockEntity, ServerWorld world);
|
||||
}
|
||||
|
|
|
@ -75,10 +75,12 @@ public final class ServerChunkEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onChunkLoad(ServerWorld world, WorldChunk chunk);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onChunkUnload(ServerWorld world, WorldChunk chunk);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ public final class ServerEntityEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onLoad(Entity entity, ServerWorld world);
|
||||
}
|
||||
|
|
|
@ -96,26 +96,32 @@ public final class ServerLifecycleEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServerStarting {
|
||||
void onServerStarting(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServerStarted {
|
||||
void onServerStarted(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServerStopping {
|
||||
void onServerStopping(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ServerStopped {
|
||||
void onServerStopped(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StartDataPackReload {
|
||||
void startDataPackReload(MinecraftServer server, ReloadableResourceManager serverResourceManager);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndDataPackReload {
|
||||
/**
|
||||
* Called after data packs on a Minecraft server have been reloaded.
|
||||
|
|
|
@ -117,18 +117,22 @@ public final class ServerTickEvents {
|
|||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StartTick {
|
||||
void onStartTick(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndTick {
|
||||
void onEndTick(MinecraftServer server);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StartWorldTick {
|
||||
void onStartTick(ServerWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndWorldTick {
|
||||
void onEndTick(ServerWorld world);
|
||||
}
|
||||
|
|
|
@ -35,10 +35,28 @@ public final class ServerWorldEvents {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Called before a world is unloaded by a Minecraft server.
|
||||
*
|
||||
* <p>This typically occurs after a server has {@link ServerLifecycleEvents#SERVER_STOPPING started shutting down}.
|
||||
* Mods which allow dynamic world (un)registration should use this event so mods can let go of world handles when a world is removed.
|
||||
*/
|
||||
public static final Event<Unload> UNLOAD = EventFactory.createArrayBacked(Unload.class, callbacks -> (server, world) -> {
|
||||
for (Unload callback : callbacks) {
|
||||
callback.onWorldUnload(server, world);
|
||||
}
|
||||
});
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Load {
|
||||
void onWorldLoad(MinecraftServer server, ServerWorld world);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Unload {
|
||||
void onWorldUnload(MinecraftServer server, ServerWorld world);
|
||||
}
|
||||
|
||||
private ServerWorldEvents() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,6 +99,11 @@ public abstract class MinecraftServerMixin {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Inject(method = "shutdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;close()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||
private void onUnloadWorldAtShutdown(CallbackInfo ci, Iterator<ServerWorld> worlds, ServerWorld world) {
|
||||
ServerWorldEvents.UNLOAD.invoker().onWorldUnload((MinecraftServer) (Object) this, world);
|
||||
}
|
||||
|
||||
@Inject(method = "reloadDataPacks", at = @At("HEAD"))
|
||||
private void startResourceReload(LevelProperties levelProperties, CallbackInfo cir) {
|
||||
ServerLifecycleEvents.START_DATA_PACK_RELOAD.invoker().startDataPackReload((MinecraftServer) (Object) this, this.dataManager);
|
||||
|
|
|
@ -46,5 +46,9 @@ public class ServerLifecycleTests implements ModInitializer {
|
|||
ServerWorldEvents.LOAD.register((server, world) -> {
|
||||
LOGGER.info("Loaded world " + world.dimension.getType().toString());
|
||||
});
|
||||
|
||||
ServerWorldEvents.UNLOAD.register((server, world) -> {
|
||||
LOGGER.info("Unloaded world " + world.dimension.getType().toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue