Skip to content

Commit

Permalink
Client events & First Release!
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Jul 17, 2024
1 parent 12c1177 commit eaf0983
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "org.muonmc.gluon.base.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_21",
"mixins": [
"BootstrapAccessor",
"BuiltInRegistriesMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public final class ServerLevelTickEvents {

/**
* 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 -> (server, world) -> {
for (var callback : callbacks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public final class ServerTickEvents {
*
* <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 -> server -> {
for (var callback : callbacks) {
Expand Down
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);
}
}
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);
}
}
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();
}
}
Loading

0 comments on commit eaf0983

Please sign in to comment.