Replace references to NEU with Firmament

This commit is contained in:
nea
2023-05-16 01:23:43 +02:00
parent 96c546cc73
commit ead6762eb1
70 changed files with 354 additions and 360 deletions

View File

@@ -0,0 +1,36 @@
package moe.nea.firmament.events
/**
* An event that can be fired by a [NEUEventBus].
*
* Typically, that event bus is implemented as a companion object
*
* ```
* class SomeEvent : NEUEvent() {
* companion object : NEUEventBus<SomeEvent>()
* }
* ```
*/
abstract class NEUEvent {
/**
* A [NEUEvent] that can be [cancelled]
*/
abstract class Cancellable : NEUEvent() {
/**
* Cancels this is event.
*
* @see cancelled
*/
fun cancel() {
cancelled = true
}
/**
* Whether this event is cancelled.
*
* Cancelled events will bypass handlers unless otherwise specified and will prevent the action that this
* event was originally fired for.
*/
var cancelled: Boolean = false
}
}

View File

@@ -0,0 +1,37 @@
package moe.nea.firmament.events
import java.util.concurrent.CopyOnWriteArrayList
import moe.nea.firmament.Firmament
/**
* A pubsub event bus.
*
* [subscribe] to events [publish]ed on this event bus.
* Subscriptions may not necessarily be delivered in the order or registering.
*/
open class NEUEventBus<T : NEUEvent> {
data class Handler<T>(val invocation: (T) -> Unit, val receivesCancelled: Boolean)
private val toHandle: MutableList<Handler<T>> = CopyOnWriteArrayList()
fun subscribe(handle: (T) -> Unit) {
subscribe(handle, false)
}
fun subscribe(handle: (T) -> Unit, receivesCancelled: Boolean) {
toHandle.add(Handler(handle, receivesCancelled))
}
fun publish(event: T): T {
for (function in toHandle) {
if (function.receivesCancelled || event !is NEUEvent.Cancellable || !event.cancelled) {
try {
function.invocation(event)
} catch (e: Exception) {
Firmament.logger.error("Caught exception during processing event $event", e)
}
}
}
return event
}
}

View File

@@ -0,0 +1,13 @@
package moe.nea.firmament.events
import net.minecraft.particle.ParticleEffect
import net.minecraft.util.math.Vec3d
data class ParticleSpawnEvent(
val particleEffect: ParticleEffect,
val position: Vec3d,
val offset: Vec3d,
val longDistance: Boolean,
) : NEUEvent() {
companion object : NEUEventBus<ParticleSpawnEvent>()
}

View File

@@ -0,0 +1,7 @@
package moe.nea.firmament.events
import net.minecraft.client.gui.screen.Screen
data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : NEUEvent.Cancellable() {
companion object : NEUEventBus<ScreenOpenEvent>()
}

View File

@@ -0,0 +1,13 @@
package moe.nea.firmament.events
import net.minecraft.text.Text
import moe.nea.firmament.util.unformattedString
/**
* This event gets published whenever the client receives a chat message from the server.
*/
data class ServerChatLineReceivedEvent(val text: Text) : NEUEvent.Cancellable() {
companion object : NEUEventBus<ServerChatLineReceivedEvent>()
val unformattedString = text.unformattedString
}

View File

@@ -0,0 +1,13 @@
package moe.nea.firmament.events
import moe.nea.firmament.util.Locraw
/**
* This event gets published whenever `/locraw` is queried and HyPixel returns a location different to the old one.
*
* **N.B.:** This event may get fired multiple times while on the server (for example, first to null, then to the
* correct location).
*/
data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : NEUEvent() {
companion object : NEUEventBus<SkyblockServerUpdateEvent>()
}

View File

@@ -0,0 +1,5 @@
package moe.nea.firmament.events
class WorldReadyEvent : NEUEvent() {
companion object : NEUEventBus<WorldReadyEvent>()
}

View File

@@ -0,0 +1,22 @@
package moe.nea.firmament.events
import org.joml.Matrix4f
import net.minecraft.client.render.Camera
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.LightmapTextureManager
import net.minecraft.client.util.math.MatrixStack
/**
* This event is called after all world rendering is done, but before any GUI rendering (including hand) has been done.
*/
data class WorldRenderLastEvent(
val matrices: MatrixStack,
val tickDelta: Float,
val renderBlockOutline: Boolean,
val camera: Camera,
val gameRenderer: GameRenderer,
val lightmapTextureManager: LightmapTextureManager,
val positionMatrix: Matrix4f,
) : NEUEvent() {
companion object : NEUEventBus<WorldRenderLastEvent>()
}