Add LifecycleEvent.SETUP for manipulating things after normal init (#148)

* Add LifecycleEvent.SETUP for manipulating things after normal initialization

* Improve javadocs

* Fix broken english

* Update common/src/main/java/dev/architectury/event/events/common/LifecycleEvent.java

Co-authored-by: BasiqueEvangelist <basiqueevangelist@yandex.ru>
Signed-off-by: Max <maxh2709@gmail.com>
This commit is contained in:
shedaniel
2021-12-26 20:15:51 +01:00
committed by Max
parent 997af6b81a
commit eea1b5182c
6 changed files with 52 additions and 1 deletions

View File

@@ -48,6 +48,10 @@ public interface ClientLifecycleEvent {
* Invoked once client setup has begun.
* <p> This happens during {@code FMLClientSetupEvent} on Forge,
* or when Architectury API's client entrypoint initialises on Fabric.
* <p>
* Registries should have been initialised by this point, but there
* are no such guarantees, as you can modify the registry beyond this point
* on non-Forge environments.
*/
Event<ClientState> CLIENT_SETUP = EventFactory.createLoop();

View File

@@ -88,6 +88,16 @@ public interface LifecycleEvent {
* @see ServerLevelState#act(Level)
*/
Event<ServerLevelState> SERVER_LEVEL_SAVE = EventFactory.createLoop();
/**
* Invoked once common setup has begun.
* <p> This happens during {@code FMLCommonSetupEvent} on Forge,
* or when Architectury API's client/server entrypoint initialises on Fabric.
* <p>
* Registries should have been initialised by this point, but there
* are no such guarantees, as you can modify the registry beyond this point
* on non-Forge environments.
*/
Event<Runnable> SETUP = EventFactory.createLoop();
interface InstanceState<T> {
/**

View File

@@ -20,11 +20,13 @@
package dev.architectury.init.fabric;
import dev.architectury.event.events.client.ClientLifecycleEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.networking.fabric.SpawnEntityPacket;
import net.minecraft.client.Minecraft;
public class ArchitecturyClient {
public static void init() {
LifecycleEvent.SETUP.invoker().run();
ClientLifecycleEvent.CLIENT_SETUP.invoker().stateChanged(Minecraft.getInstance());
SpawnEntityPacket.Client.register();

View File

@@ -0,0 +1,28 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.init.fabric;
import dev.architectury.event.events.common.LifecycleEvent;
public class ArchitecturyServer {
public static void init() {
LifecycleEvent.SETUP.invoker().run();
}
}

View File

@@ -22,6 +22,9 @@
"main": [
"dev.architectury.utils.fabric.GameInstanceImpl::init"
],
"server": [
"dev.architectury.init.fabric.ArchitecturyServer::init"
],
"client": [
"dev.architectury.init.fabric.ArchitecturyClient::init"
],

View File

@@ -59,6 +59,7 @@ import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.server.ServerLifecycleHooks;
public class EventHandlerImplCommon {
@@ -423,6 +424,9 @@ public class EventHandlerImplCommon {
}
public static class ModBasedEventHandler {
@SubscribeEvent(priority = EventPriority.HIGH)
public static void event(FMLCommonSetupEvent event) {
LifecycleEvent.SETUP.invoker().run();
}
}
}