forked from QuiltMC/quilt-standard-libraries
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
710 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Gluon Changelog | ||
|
||
## `0.1.0+1.21` | ||
### Added | ||
- Lifecycle Events | ||
### Changed | ||
- Rebranded from QSL to Gluon |
2 changes: 1 addition & 1 deletion
2
library/core/gluon_base/src/main/resources/gluon_base.mixins.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...nts/src/main/java/org/muonmc/gluon/lifecycle/api/event/client/ClientEntityTickEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2024 MuonMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.muonmc.gluon.lifecycle.api.event.client; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import org.muonmc.gluon.base.api.event.Event; | ||
import org.muonmc.gluon.base.api.event.client.ClientEventAwareListener; | ||
|
||
/** | ||
* Events related to a ticking Minecraft client's entities. | ||
* <h2>A note of warning</h2> | ||
* <p> | ||
* Callbacks registered to any of these events should ensure as little time as possible is spent executing, since the tick | ||
* loop is a very hot code path. | ||
*/ | ||
public final class ClientEntityTickEvents { | ||
/** | ||
* This event is invoked at the beginning of a tick. | ||
*/ | ||
public static final Event<Begin> BEGIN = Event.create(Begin.class, callbacks -> (minecraft, level) -> { | ||
for (var callback : callbacks) { | ||
callback.onEntityTickBegin(minecraft, level); | ||
} | ||
}); | ||
|
||
/** | ||
* This event is invoked at the end of a tick. | ||
* | ||
* <h2>Tick Count</h2> | ||
* Note that the tick count has increased since the beginning of the tick. That means that the current tick count is ahead by one. | ||
*/ | ||
public static final Event<End> END = Event.create(End.class, callbacks -> (minecraft, level) -> { | ||
for (var callback : callbacks) { | ||
callback.onEntityTickEnd(minecraft, level); | ||
} | ||
}); | ||
|
||
private ClientEntityTickEvents() { | ||
} | ||
|
||
/** | ||
* @see #BEGIN | ||
*/ | ||
@FunctionalInterface | ||
public interface Begin extends ClientEventAwareListener { | ||
/** | ||
* @see #BEGIN | ||
*/ | ||
void onEntityTickBegin(Minecraft minecraft, ClientLevel level); | ||
} | ||
|
||
/** | ||
* @see #END | ||
*/ | ||
@FunctionalInterface | ||
public interface End extends ClientEventAwareListener { | ||
/** | ||
* @see #END | ||
*/ | ||
void onEntityTickEnd(Minecraft minecraft, ClientLevel level); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...ents/src/main/java/org/muonmc/gluon/lifecycle/api/event/client/ClientLevelTickEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2024 MuonMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.muonmc.gluon.lifecycle.api.event.client; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import org.muonmc.gluon.base.api.event.Event; | ||
import org.muonmc.gluon.base.api.event.client.ClientEventAwareListener; | ||
|
||
/** | ||
* Events related to a ticking Minecraft client's level. | ||
* | ||
* <h2>Entity Ticking</h2> | ||
* <p> | ||
* Note that these events are only called in the method that handles time and world border ticking. For entity ticking events, see | ||
* {@link ClientEntityTickEvents}. | ||
* | ||
* <h2>A note of warning</h2> | ||
* <p> | ||
* Callbacks registered to any of these events should ensure as little time as possible is spent executing, since the tick loop is a very hot code path. | ||
* | ||
* @see ClientEntityTickEvents | ||
*/ | ||
public final class ClientLevelTickEvents { | ||
/** | ||
* This event is invoked at the beginning of a tick. | ||
* | ||
* <p> | ||
* This event triggers before level ticking occurs. | ||
*/ | ||
public static final Event<Begin> BEGIN = Event.create(Begin.class, callbacks -> (minecraft, level) -> { | ||
for (var callback : callbacks) { | ||
callback.onLevelTickBegin(minecraft, level); | ||
} | ||
}); | ||
|
||
/** | ||
* This event is invoked at the end of a tick. | ||
* | ||
* <p> | ||
* This event triggers after level ticking occurs. | ||
* | ||
* <h2>Tick Count</h2> | ||
* Note that the tick count has increased since the beginning of the tick. That means that the current tick count is ahead by one. | ||
*/ | ||
public static final Event<End> END = Event.create(End.class, callbacks -> (minecraft, level) -> { | ||
for (var callback : callbacks) { | ||
callback.onLevelTickEnd(minecraft, level); | ||
} | ||
}); | ||
|
||
private ClientLevelTickEvents() { | ||
} | ||
|
||
/** | ||
* @see #BEGIN | ||
*/ | ||
@FunctionalInterface | ||
public interface Begin extends ClientEventAwareListener { | ||
/** | ||
* @see #BEGIN | ||
*/ | ||
void onLevelTickBegin(Minecraft minecraft, ClientLevel level); | ||
} | ||
|
||
/** | ||
* @see #END | ||
*/ | ||
@FunctionalInterface | ||
public interface End extends ClientEventAwareListener { | ||
/** | ||
* @see #END | ||
*/ | ||
void onLevelTickEnd(Minecraft minecraft, ClientLevel level); | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
...ents/src/main/java/org/muonmc/gluon/lifecycle/api/event/client/ClientLifecycleEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 2024 MuonMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.muonmc.gluon.lifecycle.api.event.client; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import org.muonmc.gluon.base.api.event.Event; | ||
import org.muonmc.gluon.base.api.event.client.ClientEventAwareListener; | ||
|
||
/** | ||
* Events describing the lifecycle of a client. | ||
* | ||
* <h1>Client Lifecycle</h1> | ||
* <p> | ||
* Note that we do not have a preload event. Use {@link org.muonmc.gluon.base.api.entrypoint.client.ClientModInitializer} if you need to run code before the | ||
* loading screen appears. | ||
* | ||
* @see org.muonmc.gluon.base.api.entrypoint.client.ClientModInitializer | ||
*/ | ||
public final class ClientLifecycleEvents { | ||
/** | ||
* <h2>Ready</h2> | ||
* The first event triggered is {@link Ready}. This event triggers when the loading screen appears. This indicates that the client begins rendering and | ||
* ticking. | ||
*/ | ||
public static final Event<Ready> READY = Event.create(Ready.class, callbacks -> minecraft -> { | ||
for (var callback : callbacks) { | ||
callback.onReady(minecraft); | ||
} | ||
}); | ||
|
||
/** | ||
* <h2>Loaded</h2> | ||
* The next event is {@link Loaded}. This event triggers after loading has finished. The main menu appears after this event. | ||
*/ | ||
public static final Event<Loaded> LOADED = Event.create(Loaded.class, callbacks -> minecraft -> { | ||
for (var callback : callbacks) { | ||
callback.onLoaded(minecraft); | ||
} | ||
}); | ||
|
||
/** | ||
* <h2>Stopping</h2> | ||
* This event is triggered when the player initially quits the game. | ||
* | ||
* <h4>Warning</h4> | ||
* Note that if the game crashes irrecoverably, this event may not trigger. | ||
*/ | ||
public static final Event<Stopping> STOPPING = Event.create(Stopping.class, callbacks -> minecraft -> { | ||
for (var callback : callbacks) { | ||
callback.onStopping(minecraft); | ||
} | ||
}); | ||
|
||
/** | ||
* <h2>Stopped</h2> | ||
* This event is triggered when the client has completely quit and unloaded. | ||
* | ||
* <h4>Warning</h4> | ||
* Note that if the game crashes irrecoverably, this event may not trigger. | ||
*/ | ||
public static final Event<Stopped> STOPPED = Event.create(Stopped.class, callbacks -> () -> { | ||
for (var callback : callbacks) { | ||
callback.onStopped(); | ||
} | ||
}); | ||
|
||
private ClientLifecycleEvents() { | ||
} | ||
|
||
/** | ||
* @see #READY | ||
*/ | ||
@FunctionalInterface | ||
public interface Ready extends ClientEventAwareListener { | ||
/** | ||
* @see #READY | ||
*/ | ||
void onReady(Minecraft minecraft); | ||
} | ||
|
||
/** | ||
* @see #LOADED | ||
*/ | ||
@FunctionalInterface | ||
public interface Loaded extends ClientEventAwareListener { | ||
/** | ||
* @see #LOADED | ||
*/ | ||
void onLoaded(Minecraft minecraft); | ||
} | ||
|
||
/** | ||
* @see #STOPPING | ||
*/ | ||
@FunctionalInterface | ||
public interface Stopping extends ClientEventAwareListener { | ||
/** | ||
* @see #STOPPING | ||
*/ | ||
void onStopping(Minecraft minecraft); | ||
} | ||
|
||
/** | ||
* @see #STOPPED | ||
*/ | ||
@FunctionalInterface | ||
public interface Stopped extends ClientEventAwareListener { | ||
/** | ||
* @see #STOPPED | ||
*/ | ||
void onStopped(); | ||
} | ||
} |
Oops, something went wrong.