aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/events')
-rw-r--r--src/main/kotlin/events/AllowChatEvent.kt4
-rw-r--r--src/main/kotlin/events/AttackBlockEvent.kt16
-rw-r--r--src/main/kotlin/events/ChestInventoryUpdateEvent.kt2
-rw-r--r--src/main/kotlin/events/CommandEvent.kt5
-rw-r--r--src/main/kotlin/events/CustomItemModelEvent.kt65
-rw-r--r--src/main/kotlin/events/EarlyResourceReloadEvent.kt2
-rw-r--r--src/main/kotlin/events/EntityDespawnEvent.kt2
-rw-r--r--src/main/kotlin/events/EntityInteractionEvent.kt6
-rw-r--r--src/main/kotlin/events/EntityRenderTintEvent.kt67
-rw-r--r--src/main/kotlin/events/EntityUpdateEvent.kt57
-rw-r--r--src/main/kotlin/events/FeaturesInitializedEvent.kt8
-rw-r--r--src/main/kotlin/events/FinalizeResourceManagerEvent.kt20
-rw-r--r--src/main/kotlin/events/HandledScreenClickEvent.kt4
-rw-r--r--src/main/kotlin/events/HandledScreenForegroundEvent.kt8
-rw-r--r--src/main/kotlin/events/HandledScreenKeyPressedEvent.kt54
-rw-r--r--src/main/kotlin/events/HandledScreenPushREIEvent.kt4
-rw-r--r--src/main/kotlin/events/HotbarItemRenderEvent.kt16
-rw-r--r--src/main/kotlin/events/HudRenderEvent.kt22
-rw-r--r--src/main/kotlin/events/IsSlotProtectedEvent.kt80
-rw-r--r--src/main/kotlin/events/ItemTooltipEvent.kt10
-rw-r--r--src/main/kotlin/events/JoinServerEvent.kt11
-rw-r--r--src/main/kotlin/events/ModifyChatEvent.kt6
-rw-r--r--src/main/kotlin/events/OutgoingPacketEvent.kt2
-rw-r--r--src/main/kotlin/events/ParticleSpawnEvent.kt8
-rw-r--r--src/main/kotlin/events/PlayerInventoryUpdate.kt21
-rw-r--r--src/main/kotlin/events/ProcessChatEvent.kt4
-rw-r--r--src/main/kotlin/events/ScreenChangeEvent.kt2
-rw-r--r--src/main/kotlin/events/ScreenRenderPostEvent.kt6
-rw-r--r--src/main/kotlin/events/ServerConnectedEvent.kt10
-rw-r--r--src/main/kotlin/events/SlotClickEvent.kt8
-rw-r--r--src/main/kotlin/events/SlotRenderEvents.kt17
-rw-r--r--src/main/kotlin/events/SoundReceiveEvent.kt14
-rw-r--r--src/main/kotlin/events/TickEvent.kt3
-rw-r--r--src/main/kotlin/events/UseBlockEvent.kt10
-rw-r--r--src/main/kotlin/events/UseItemEvent.kt12
-rw-r--r--src/main/kotlin/events/WorldKeyboardEvent.kt21
-rw-r--r--src/main/kotlin/events/WorldMouseMoveEvent.kt5
-rw-r--r--src/main/kotlin/events/WorldRenderLastEvent.kt21
-rw-r--r--src/main/kotlin/events/registration/ChatEvents.kt27
-rw-r--r--src/main/kotlin/events/subscription/Subscription.kt4
40 files changed, 420 insertions, 244 deletions
diff --git a/src/main/kotlin/events/AllowChatEvent.kt b/src/main/kotlin/events/AllowChatEvent.kt
index 3069843..86395c9 100644
--- a/src/main/kotlin/events/AllowChatEvent.kt
+++ b/src/main/kotlin/events/AllowChatEvent.kt
@@ -2,14 +2,14 @@
package moe.nea.firmament.events
+import net.minecraft.network.chat.Component
import moe.nea.firmament.util.unformattedString
-import net.minecraft.text.Text
/**
* Filter whether the user should see a chat message altogether. May or may not be called for every chat packet sent by
* the server. When that quality is desired, consider [ProcessChatEvent] instead.
*/
-data class AllowChatEvent(val text: Text) : FirmamentEvent.Cancellable() {
+data class AllowChatEvent(val text: Component) : FirmamentEvent.Cancellable() {
val unformattedString = text.unformattedString
companion object : FirmamentEventBus<AllowChatEvent>()
diff --git a/src/main/kotlin/events/AttackBlockEvent.kt b/src/main/kotlin/events/AttackBlockEvent.kt
index bbaa81d..81a2952 100644
--- a/src/main/kotlin/events/AttackBlockEvent.kt
+++ b/src/main/kotlin/events/AttackBlockEvent.kt
@@ -1,16 +1,16 @@
package moe.nea.firmament.events
-import net.minecraft.entity.player.PlayerEntity
-import net.minecraft.util.Hand
-import net.minecraft.util.math.BlockPos
-import net.minecraft.util.math.Direction
-import net.minecraft.world.World
+import net.minecraft.world.entity.player.Player
+import net.minecraft.world.InteractionHand
+import net.minecraft.core.BlockPos
+import net.minecraft.core.Direction
+import net.minecraft.world.level.Level
data class AttackBlockEvent(
- val player: PlayerEntity,
- val world: World,
- val hand: Hand,
+ val player: Player,
+ val world: Level,
+ val hand: InteractionHand,
val blockPos: BlockPos,
val direction: Direction
) : FirmamentEvent.Cancellable() {
diff --git a/src/main/kotlin/events/ChestInventoryUpdateEvent.kt b/src/main/kotlin/events/ChestInventoryUpdateEvent.kt
index ddf54fc..e3acd12 100644
--- a/src/main/kotlin/events/ChestInventoryUpdateEvent.kt
+++ b/src/main/kotlin/events/ChestInventoryUpdateEvent.kt
@@ -1,6 +1,6 @@
package moe.nea.firmament.events
-import net.minecraft.item.ItemStack
+import net.minecraft.world.item.ItemStack
import moe.nea.firmament.util.MC
sealed class ChestInventoryUpdateEvent : FirmamentEvent() {
diff --git a/src/main/kotlin/events/CommandEvent.kt b/src/main/kotlin/events/CommandEvent.kt
index cc9cf45..bdd63ca 100644
--- a/src/main/kotlin/events/CommandEvent.kt
+++ b/src/main/kotlin/events/CommandEvent.kt
@@ -4,7 +4,7 @@ package moe.nea.firmament.events
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.tree.LiteralCommandNode
-import net.minecraft.command.CommandRegistryAccess
+import net.minecraft.commands.CommandBuildContext
import moe.nea.firmament.commands.CaseInsensitiveLiteralCommandNode
import moe.nea.firmament.commands.DefaultSource
import moe.nea.firmament.commands.literal
@@ -12,7 +12,7 @@ import moe.nea.firmament.commands.thenLiteral
data class CommandEvent(
val dispatcher: CommandDispatcher<DefaultSource>,
- val ctx: CommandRegistryAccess,
+ val ctx: CommandBuildContext,
val serverCommands: CommandDispatcher<*>?,
) : FirmamentEvent() {
companion object : FirmamentEventBus<CommandEvent>()
@@ -23,6 +23,7 @@ data class CommandEvent(
*/
data class SubCommand(
val builder: CaseInsensitiveLiteralCommandNode.Builder<DefaultSource>,
+ val commandRegistryAccess: CommandBuildContext,
) : FirmamentEvent() {
companion object : FirmamentEventBus<SubCommand>()
diff --git a/src/main/kotlin/events/CustomItemModelEvent.kt b/src/main/kotlin/events/CustomItemModelEvent.kt
index e7b6eb8..3d96b34 100644
--- a/src/main/kotlin/events/CustomItemModelEvent.kt
+++ b/src/main/kotlin/events/CustomItemModelEvent.kt
@@ -1,32 +1,75 @@
package moe.nea.firmament.events
+import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull
-import net.minecraft.item.ItemStack
-import net.minecraft.util.Identifier
+import net.minecraft.core.component.DataComponents
+import net.minecraft.world.item.ItemStack
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.util.collections.WeakCache
+import moe.nea.firmament.util.collections.WeakCache.CacheFunction
+import moe.nea.firmament.util.mc.IntrospectableItemModelManager
// TODO: assert an order on these events
data class CustomItemModelEvent(
- val itemStack: ItemStack,
- var overrideModel: Identifier? = null,
+ val itemStack: ItemStack,
+ val itemModelManager: IntrospectableItemModelManager,
+ var overrideModel: ResourceLocation? = null,
) : FirmamentEvent() {
companion object : FirmamentEventBus<CustomItemModelEvent>() {
- val cache = WeakCache.memoize("ItemModelIdentifier", ::getModelIdentifier0)
+ val weakCache =
+ object : WeakCache<ItemStack, IntrospectableItemModelManager, Optional<ResourceLocation>>("ItemModelIdentifier") {
+ override fun mkRef(
+ key: ItemStack,
+ extraData: IntrospectableItemModelManager
+ ): WeakCache<ItemStack, IntrospectableItemModelManager, Optional<ResourceLocation>>.Ref {
+ return IRef(key, extraData)
+ }
+
+ inner class IRef(weakInstance: ItemStack, data: IntrospectableItemModelManager) :
+ Ref(weakInstance, data) {
+ override fun shouldBeEvicted(): Boolean = false
+ val isSimpleStack = weakInstance.componentsPatch.isEmpty || (weakInstance.componentsPatch.size() == 1 && weakInstance.get(
+ DataComponents.CUSTOM_DATA)?.isEmpty == true)
+ val item = weakInstance.item
+ override fun hashCode(): Int {
+ if (isSimpleStack)
+ return Objects.hash(item, extraData)
+ return super.hashCode()
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (other is IRef && isSimpleStack) {
+ return other.isSimpleStack && item == other.item
+ }
+ return super.equals(other)
+ }
+ }
+ }
+ val cache = CacheFunction.WithExtraData(weakCache, ::getModelIdentifier0)
@JvmStatic
- fun getModelIdentifier(itemStack: ItemStack?): Identifier? {
+ fun getModelIdentifier(itemStack: ItemStack?, itemModelManager: IntrospectableItemModelManager): ResourceLocation? {
if (itemStack == null) return null
- return cache.invoke(itemStack).getOrNull()
+ return cache.invoke(itemStack, itemModelManager).getOrNull()
}
- fun getModelIdentifier0(itemStack: ItemStack): Optional<Identifier> {
+ fun getModelIdentifier0(
+ itemStack: ItemStack,
+ itemModelManager: IntrospectableItemModelManager
+ ): Optional<ResourceLocation> {
// TODO: add an error / warning if the model does not exist
- return Optional.ofNullable(publish(CustomItemModelEvent(itemStack)).overrideModel)
+ return Optional.ofNullable(publish(CustomItemModelEvent(itemStack, itemModelManager)).overrideModel)
}
}
- fun overrideIfExists(overrideModel: Identifier) {
- this.overrideModel = overrideModel
+ fun overrideIfExists(overrideModel: ResourceLocation) {
+ if (itemModelManager.hasModel_firmament(overrideModel))
+ this.overrideModel = overrideModel
+ }
+
+ fun overrideIfEmpty(identifier: ResourceLocation) {
+ if (overrideModel == null)
+ overrideModel = identifier
}
}
diff --git a/src/main/kotlin/events/EarlyResourceReloadEvent.kt b/src/main/kotlin/events/EarlyResourceReloadEvent.kt
index ec8377a..b9cf717 100644
--- a/src/main/kotlin/events/EarlyResourceReloadEvent.kt
+++ b/src/main/kotlin/events/EarlyResourceReloadEvent.kt
@@ -2,7 +2,7 @@
package moe.nea.firmament.events
import java.util.concurrent.Executor
-import net.minecraft.resource.ResourceManager
+import net.minecraft.server.packs.resources.ResourceManager
data class EarlyResourceReloadEvent(val resourceManager: ResourceManager, val preparationExecutor: Executor) :
FirmamentEvent() {
diff --git a/src/main/kotlin/events/EntityDespawnEvent.kt b/src/main/kotlin/events/EntityDespawnEvent.kt
index 93dc477..d007f96 100644
--- a/src/main/kotlin/events/EntityDespawnEvent.kt
+++ b/src/main/kotlin/events/EntityDespawnEvent.kt
@@ -1,7 +1,7 @@
package moe.nea.firmament.events
-import net.minecraft.entity.Entity
+import net.minecraft.world.entity.Entity
data class EntityDespawnEvent(
val entity: Entity?, val entityId: Int,
diff --git a/src/main/kotlin/events/EntityInteractionEvent.kt b/src/main/kotlin/events/EntityInteractionEvent.kt
index 123ea39..8285e1b 100644
--- a/src/main/kotlin/events/EntityInteractionEvent.kt
+++ b/src/main/kotlin/events/EntityInteractionEvent.kt
@@ -1,13 +1,13 @@
package moe.nea.firmament.events
-import net.minecraft.entity.Entity
-import net.minecraft.util.Hand
+import net.minecraft.world.entity.Entity
+import net.minecraft.world.InteractionHand
data class EntityInteractionEvent(
val kind: InteractionKind,
val entity: Entity,
- val hand: Hand,
+ val hand: InteractionHand,
) : FirmamentEvent() {
companion object : FirmamentEventBus<EntityInteractionEvent>()
enum class InteractionKind {
diff --git a/src/main/kotlin/events/EntityRenderTintEvent.kt b/src/main/kotlin/events/EntityRenderTintEvent.kt
new file mode 100644
index 0000000..63528bc
--- /dev/null
+++ b/src/main/kotlin/events/EntityRenderTintEvent.kt
@@ -0,0 +1,67 @@
+package moe.nea.firmament.events
+
+import net.minecraft.client.renderer.GameRenderer
+import net.minecraft.client.renderer.texture.OverlayTexture
+import net.minecraft.client.renderer.entity.state.EntityRenderState
+import net.minecraft.world.entity.Entity
+import net.minecraft.world.entity.LivingEntity
+import moe.nea.firmament.events.EntityRenderTintEvent.Companion.overlayOverride
+import moe.nea.firmament.util.render.TintedOverlayTexture
+
+/**
+ * Change the tint color of a [LivingEntity]
+ */
+class EntityRenderTintEvent(
+ val entity: Entity,
+ val renderState: HasTintRenderState
+) : FirmamentEvent.Cancellable() {
+ init {
+ if (entity !is LivingEntity) {
+ cancel()
+ }
+ }
+
+ companion object : FirmamentEventBus<EntityRenderTintEvent>() {
+ /**
+ * Static variable containing an override for [GameRenderer.getOverlayTexture]. Should be only set briefly.
+ *
+ * This variable only affects render layers that naturally make use of the overlay texture, have proper overlay UVs set (`overlay u != 0`), and have a shader that makes use of the overlay (does not have the `NO_OVERLAY` flag set in its json definition).
+ *
+ * Currently supported layers: [net.minecraft.client.render.entity.equipment.EquipmentRenderer], [net.minecraft.client.render.entity.model.PlayerEntityModel], as well as some others naturally.
+ *
+ * @see moe.nea.firmament.mixins.render.entitytints.ReplaceOverlayTexture
+ * @see TintedOverlayTexture
+ */
+ @JvmField
+ var overlayOverride: OverlayTexture? = null
+ }
+
+ @Suppress("PropertyName", "FunctionName")
+ interface HasTintRenderState {
+ /**
+ * Multiplicative tint applied before the overlay.
+ */
+ var tint_firmament: Int
+
+ /**
+ * Must be set for [tint_firmament] to have any effect.
+ */
+ var hasTintOverride_firmament: Boolean
+
+ // TODO: allow for more specific selection of which layers get tinted
+ /**
+ * Specify a [TintedOverlayTexture] to be used. This does not apply to render layers not using the overlay texture.
+ * @see overlayOverride
+ */
+ var overlayTexture_firmament: TintedOverlayTexture?
+ fun reset_firmament()
+
+ companion object {
+ @JvmStatic
+ fun cast(state: EntityRenderState): HasTintRenderState {
+ return state as HasTintRenderState
+ }
+ }
+ }
+
+}
diff --git a/src/main/kotlin/events/EntityUpdateEvent.kt b/src/main/kotlin/events/EntityUpdateEvent.kt
index d091984..9f5a101 100644
--- a/src/main/kotlin/events/EntityUpdateEvent.kt
+++ b/src/main/kotlin/events/EntityUpdateEvent.kt
@@ -1,10 +1,14 @@
-
package moe.nea.firmament.events
-import net.minecraft.entity.Entity
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.data.DataTracker
-import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket
+import com.mojang.datafixers.util.Pair
+import net.minecraft.world.entity.Entity
+import net.minecraft.world.entity.EquipmentSlot
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.network.syncher.SynchedEntityData
+import net.minecraft.world.item.ItemStack
+import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket
+import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.util.MC
/**
* This event is fired when some entity properties are updated.
@@ -13,19 +17,44 @@ import net.minecraft.network.packet.s2c.play.EntityAttributesS2CPacket
* *after* the values have been applied to the entity.
*/
sealed class EntityUpdateEvent : FirmamentEvent() {
- companion object : FirmamentEventBus<EntityUpdateEvent>()
+ companion object : FirmamentEventBus<EntityUpdateEvent>() {
+ @Subscribe
+ fun onPlayerInventoryUpdate(event: PlayerInventoryUpdate) {
+ val p = MC.player ?: return
+ val updatedSlots = listOf(
+ EquipmentSlot.HEAD to 39,
+ EquipmentSlot.CHEST to 38,
+ EquipmentSlot.LEGS to 37,
+ EquipmentSlot.FEET to 36,
+ EquipmentSlot.OFFHAND to 40,
+ EquipmentSlot.MAINHAND to p.inventory.selectedSlot, // TODO: also equipment update when you swap your selected slot perhaps
+ ).mapNotNull { (slot, stackIndex) ->
+ val slotIndex = p.inventoryMenu.findSlot(p.inventory, stackIndex).asInt
+ event.getOrNull(slotIndex)?.let {
+ Pair.of(slot, it)
+ }
+ }
+ if (updatedSlots.isNotEmpty())
+ publish(EquipmentUpdate(p, updatedSlots))
+ }
+ }
- abstract val entity: Entity
+ abstract val entity: Entity
- data class AttributeUpdate(
+ data class AttributeUpdate(
override val entity: LivingEntity,
- val attributes: List<EntityAttributesS2CPacket.Entry>,
- ) : EntityUpdateEvent()
+ val attributes: List<ClientboundUpdateAttributesPacket.AttributeSnapshot>,
+ ) : EntityUpdateEvent()
+
+ data class TrackedDataUpdate(
+ override val entity: Entity,
+ val trackedValues: List<SynchedEntityData.DataValue<*>>,
+ ) : EntityUpdateEvent()
- data class TrackedDataUpdate(
+ data class EquipmentUpdate(
override val entity: Entity,
- val trackedValues: List<DataTracker.SerializedEntry<*>>,
- ) : EntityUpdateEvent()
+ val newEquipment: List<Pair<EquipmentSlot, ItemStack>>,
+ ) : EntityUpdateEvent()
-// TODO: onEntityPassengersSet, onEntityAttach?, onEntityEquipmentUpdate, onEntityStatusEffect
+// TODO: onEntityPassengersSet, onEntityAttach?, onEntityStatusEffect
}
diff --git a/src/main/kotlin/events/FeaturesInitializedEvent.kt b/src/main/kotlin/events/FeaturesInitializedEvent.kt
deleted file mode 100644
index ad2ad8a..0000000
--- a/src/main/kotlin/events/FeaturesInitializedEvent.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-
-package moe.nea.firmament.events
-
-import moe.nea.firmament.features.FirmamentFeature
-
-data class FeaturesInitializedEvent(val features: List<FirmamentFeature>) : FirmamentEvent() {
- companion object : FirmamentEventBus<FeaturesInitializedEvent>()
-}
diff --git a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
index 12167f8..72fa9c4 100644
--- a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
+++ b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
@@ -2,25 +2,25 @@ package moe.nea.firmament.events
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
-import net.minecraft.resource.ReloadableResourceManagerImpl
-import net.minecraft.resource.ResourceManager
-import net.minecraft.resource.ResourceReloader
+import net.minecraft.server.packs.resources.ReloadableResourceManager
+import net.minecraft.server.packs.resources.ResourceManager
+import net.minecraft.server.packs.resources.PreparableReloadListener
data class FinalizeResourceManagerEvent(
- val resourceManager: ReloadableResourceManagerImpl,
+ val resourceManager: ReloadableResourceManager,
) : FirmamentEvent() {
companion object : FirmamentEventBus<FinalizeResourceManagerEvent>()
inline fun registerOnApply(name: String, crossinline function: () -> Unit) {
- resourceManager.registerReloader(object : ResourceReloader {
+ resourceManager.registerReloadListener(object : PreparableReloadListener {
override fun reload(
- synchronizer: ResourceReloader.Synchronizer,
- manager: ResourceManager,
- prepareExecutor: Executor,
- applyExecutor: Executor
+ store: PreparableReloadListener.SharedState,
+ prepareExecutor: Executor,
+ reloadSynchronizer: PreparableReloadListener.PreparationBarrier,
+ applyExecutor: Executor
): CompletableFuture<Void> {
return CompletableFuture.completedFuture(Unit)
- .thenCompose(synchronizer::whenPrepared)
+ .thenCompose(reloadSynchronizer::wait)
.thenAcceptAsync({ function() }, applyExecutor)
}
diff --git a/src/main/kotlin/events/HandledScreenClickEvent.kt b/src/main/kotlin/events/HandledScreenClickEvent.kt
index 4c3003c..b937907 100644
--- a/src/main/kotlin/events/HandledScreenClickEvent.kt
+++ b/src/main/kotlin/events/HandledScreenClickEvent.kt
@@ -2,9 +2,9 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.screen.ingame.HandledScreen
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
-data class HandledScreenClickEvent(val screen: HandledScreen<*>, val mouseX: Double, val mouseY: Double, val button: Int) :
+data class HandledScreenClickEvent(val screen: AbstractContainerScreen<*>, val mouseX: Double, val mouseY: Double, val button: Int) :
FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<HandledScreenClickEvent>()
}
diff --git a/src/main/kotlin/events/HandledScreenForegroundEvent.kt b/src/main/kotlin/events/HandledScreenForegroundEvent.kt
index f16d30e..3a3d7f6 100644
--- a/src/main/kotlin/events/HandledScreenForegroundEvent.kt
+++ b/src/main/kotlin/events/HandledScreenForegroundEvent.kt
@@ -2,12 +2,12 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.ingame.HandledScreen
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
data class HandledScreenForegroundEvent(
- val screen: HandledScreen<*>,
- val context: DrawContext,
+ val screen: AbstractContainerScreen<*>,
+ val context: GuiGraphics,
val mouseX: Int,
val mouseY: Int,
val delta: Float
diff --git a/src/main/kotlin/events/HandledScreenKeyPressedEvent.kt b/src/main/kotlin/events/HandledScreenKeyPressedEvent.kt
index 183ec71..5a5f1e9 100644
--- a/src/main/kotlin/events/HandledScreenKeyPressedEvent.kt
+++ b/src/main/kotlin/events/HandledScreenKeyPressedEvent.kt
@@ -1,38 +1,40 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.screen.ingame.HandledScreen
-import net.minecraft.client.option.KeyBinding
-import moe.nea.firmament.keybindings.IKeyBinding
+import org.lwjgl.glfw.GLFW
+import net.minecraft.client.gui.screens.Screen
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
+import moe.nea.firmament.keybindings.GenericInputAction
+import moe.nea.firmament.keybindings.InputModifiers
+import moe.nea.firmament.keybindings.SavedKeyBinding
-sealed interface HandledScreenKeyEvent {
- val screen: HandledScreen<*>
- val keyCode: Int
- val scanCode: Int
- val modifiers: Int
-
- fun matches(keyBinding: KeyBinding): Boolean {
- return matches(IKeyBinding.minecraft(keyBinding))
- }
-
- fun matches(keyBinding: IKeyBinding): Boolean {
- return keyBinding.matches(keyCode, scanCode, modifiers)
- }
+sealed interface HandledScreenInputEvent {
+ val screen: Screen
+ val input: GenericInputAction
+ val modifiers: InputModifiers
}
data class HandledScreenKeyPressedEvent(
- override val screen: HandledScreen<*>,
- override val keyCode: Int,
- override val scanCode: Int,
- override val modifiers: Int
-) : FirmamentEvent.Cancellable(), HandledScreenKeyEvent {
+ override val screen: Screen,
+ override val input: GenericInputAction,
+ override val modifiers: InputModifiers,
+ // TODO: val isRepeat: Boolean,
+) : FirmamentEvent.Cancellable(), HandledScreenInputEvent {
+ fun matches(keyBinding: SavedKeyBinding, atLeast: Boolean = false): Boolean {
+ return keyBinding.matches(input, modifiers, atLeast)
+ }
+
+ fun isLeftClick() = input == GenericInputAction.mouse(GLFW.GLFW_MOUSE_BUTTON_LEFT)
companion object : FirmamentEventBus<HandledScreenKeyPressedEvent>()
}
data class HandledScreenKeyReleasedEvent(
- override val screen: HandledScreen<*>,
- override val keyCode: Int,
- override val scanCode: Int,
- override val modifiers: Int
-) : FirmamentEvent.Cancellable(), HandledScreenKeyEvent {
+ override val screen: AbstractContainerScreen<*>,
+ override val input: GenericInputAction,
+ override val modifiers: InputModifiers,
+) : FirmamentEvent.Cancellable(), HandledScreenInputEvent {
+ fun matches(keyBinding: SavedKeyBinding, atLeast: Boolean = false): Boolean {
+ return keyBinding.matches(input, modifiers, atLeast)
+ }
+
companion object : FirmamentEventBus<HandledScreenKeyReleasedEvent>()
}
diff --git a/src/main/kotlin/events/HandledScreenPushREIEvent.kt b/src/main/kotlin/events/HandledScreenPushREIEvent.kt
index 1bb495a..e2b5a40 100644
--- a/src/main/kotlin/events/HandledScreenPushREIEvent.kt
+++ b/src/main/kotlin/events/HandledScreenPushREIEvent.kt
@@ -3,10 +3,10 @@
package moe.nea.firmament.events
import me.shedaniel.math.Rectangle
-import net.minecraft.client.gui.screen.ingame.HandledScreen
+import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
data class HandledScreenPushREIEvent(
- val screen: HandledScreen<*>,
+ val screen: AbstractContainerScreen<*>,
val rectangles: MutableList<Rectangle> = mutableListOf()
) : FirmamentEvent() {
diff --git a/src/main/kotlin/events/HotbarItemRenderEvent.kt b/src/main/kotlin/events/HotbarItemRenderEvent.kt
index a1940e6..0d4e75b 100644
--- a/src/main/kotlin/events/HotbarItemRenderEvent.kt
+++ b/src/main/kotlin/events/HotbarItemRenderEvent.kt
@@ -2,16 +2,16 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.render.RenderTickCounter
-import net.minecraft.item.ItemStack
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.DeltaTracker
+import net.minecraft.world.item.ItemStack
data class HotbarItemRenderEvent(
- val item: ItemStack,
- val context: DrawContext,
- val x: Int,
- val y: Int,
- val tickDelta: RenderTickCounter,
+ val item: ItemStack,
+ val context: GuiGraphics,
+ val x: Int,
+ val y: Int,
+ val tickDelta: DeltaTracker,
) : FirmamentEvent() {
companion object : FirmamentEventBus<HotbarItemRenderEvent>()
}
diff --git a/src/main/kotlin/events/HudRenderEvent.kt b/src/main/kotlin/events/HudRenderEvent.kt
index a773a93..a397378 100644
--- a/src/main/kotlin/events/HudRenderEvent.kt
+++ b/src/main/kotlin/events/HudRenderEvent.kt
@@ -1,17 +1,21 @@
-
-
package moe.nea.firmament.events
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.render.RenderTickCounter
-import net.minecraft.world.GameMode
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.DeltaTracker
+import net.minecraft.world.level.GameType
import moe.nea.firmament.util.MC
/**
* Called when hud elements should be rendered, before the screen, but after the world.
*/
-data class HudRenderEvent(val context: DrawContext, val tickDelta: RenderTickCounter) : FirmamentEvent() {
- val isRenderingHud = !MC.options.hudHidden
- val isRenderingCursor = MC.interactionManager?.currentGameMode != GameMode.SPECTATOR && isRenderingHud
- companion object : FirmamentEventBus<HudRenderEvent>()
+data class HudRenderEvent(val context: GuiGraphics, val tickDelta: DeltaTracker) : FirmamentEvent.Cancellable() {
+ val isRenderingHud = !MC.options.hideGui
+ val isRenderingCursor = MC.interactionManager?.playerMode != GameType.SPECTATOR && isRenderingHud
+
+ init {
+ if (!isRenderingHud)
+ cancel()
+ }
+
+ companion object : FirmamentEventBus<HudRenderEvent>()
}
diff --git a/src/main/kotlin/events/IsSlotProtectedEvent.kt b/src/main/kotlin/events/IsSlotProtectedEvent.kt
index cd2b676..bda1bb3 100644
--- a/src/main/kotlin/events/IsSlotProtectedEvent.kt
+++ b/src/main/kotlin/events/IsSlotProtectedEvent.kt
@@ -1,46 +1,64 @@
-
-
package moe.nea.firmament.events
-import net.minecraft.item.ItemStack
-import net.minecraft.screen.slot.Slot
-import net.minecraft.screen.slot.SlotActionType
-import net.minecraft.text.Text
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.inventory.Slot
+import net.minecraft.world.inventory.ClickType
import moe.nea.firmament.util.CommonSoundEffects
import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.grey
+import moe.nea.firmament.util.hover
+import moe.nea.firmament.util.red
+import moe.nea.firmament.util.tr
data class IsSlotProtectedEvent(
val slot: Slot?,
- val actionType: SlotActionType,
+ val actionType: ClickType,
var isProtected: Boolean,
val itemStackOverride: ItemStack?,
+ val origin: MoveOrigin,
var silent: Boolean = false,
) : FirmamentEvent() {
- val itemStack get() = itemStackOverride ?: slot!!.stack
+ val itemStack get() = itemStackOverride ?: slot!!.item
+
+ fun protect() {
+ isProtected = true
+ silent = false
+ }
- fun protect() {
- isProtected = true
- }
+ fun protectSilent() {
+ if (!isProtected) {
+ silent = true
+ }
+ isProtected = true
+ }
- fun protectSilent() {
- if (!isProtected) {
- silent = true
- }
- isProtected = true
- }
+ enum class MoveOrigin {
+ DROP_FROM_HOTBAR,
+ SALVAGE,
+ INVENTORY_MOVE
+ ;
+ }
- companion object : FirmamentEventBus<IsSlotProtectedEvent>() {
- @JvmStatic
- @JvmOverloads
- fun shouldBlockInteraction(slot: Slot?, action: SlotActionType, itemStackOverride: ItemStack? = null): Boolean {
- if (slot == null && itemStackOverride == null) return false
- val event = IsSlotProtectedEvent(slot, action, false, itemStackOverride)
- publish(event)
- if (event.isProtected && !event.silent) {
- MC.sendChat(Text.translatable("firmament.protectitem").append(event.itemStack.name))
- CommonSoundEffects.playFailure()
- }
- return event.isProtected
- }
- }
+ companion object : FirmamentEventBus<IsSlotProtectedEvent>() {
+ @JvmStatic
+ @JvmOverloads
+ fun shouldBlockInteraction(
+ slot: Slot?, action: ClickType,
+ origin: MoveOrigin,
+ itemStackOverride: ItemStack? = null,
+ ): Boolean {
+ if (slot == null && itemStackOverride == null) return false
+ val event = IsSlotProtectedEvent(slot, action, false, itemStackOverride, origin)
+ publish(event)
+ if (event.isProtected && !event.silent) {
+ MC.sendChat(tr("firmament.protectitem", "Firmament protected your item: ${event.itemStack.hoverName}.\n")
+ .red()
+ .append(tr("firmament.protectitem.hoverhint", "Hover for more info.").grey())
+ .hover(tr("firmament.protectitem.hint",
+ "To unlock this item use the Lock Slot or Lock Item keybind from Firmament while hovering over this item.")))
+ CommonSoundEffects.playFailure()
+ }
+ return event.isProtected
+ }
+ }
}
diff --git a/src/main/kotlin/events/ItemTooltipEvent.kt b/src/main/kotlin/events/ItemTooltipEvent.kt
index d86e06f..9acd9bf 100644
--- a/src/main/kotlin/events/ItemTooltipEvent.kt
+++ b/src/main/kotlin/events/ItemTooltipEvent.kt
@@ -2,13 +2,13 @@
package moe.nea.firmament.events
-import net.minecraft.item.Item.TooltipContext
-import net.minecraft.item.ItemStack
-import net.minecraft.item.tooltip.TooltipType
-import net.minecraft.text.Text
+import net.minecraft.world.item.Item.TooltipContext
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.TooltipFlag
+import net.minecraft.network.chat.Component
data class ItemTooltipEvent(
- val stack: ItemStack, val context: TooltipContext, val type: TooltipType, val lines: MutableList<Text>
+ val stack: ItemStack, val context: TooltipContext, val type: TooltipFlag, val lines: MutableList<Component>
) : FirmamentEvent() {
companion object : FirmamentEventBus<ItemTooltipEvent>()
}
diff --git a/src/main/kotlin/events/JoinServerEvent.kt b/src/main/kotlin/events/JoinServerEvent.kt
new file mode 100644
index 0000000..6fafbd7
--- /dev/null
+++ b/src/main/kotlin/events/JoinServerEvent.kt
@@ -0,0 +1,11 @@
+package moe.nea.firmament.events
+
+import net.fabricmc.fabric.api.networking.v1.PacketSender
+import net.minecraft.client.multiplayer.ClientPacketListener
+
+data class JoinServerEvent(
+ val networkHandler: ClientPacketListener,
+ val packetSender: PacketSender,
+) : FirmamentEvent() {
+ companion object : FirmamentEventBus<JoinServerEvent>()
+}
diff --git a/src/main/kotlin/events/ModifyChatEvent.kt b/src/main/kotlin/events/ModifyChatEvent.kt
index a5868e8..5432490 100644
--- a/src/main/kotlin/events/ModifyChatEvent.kt
+++ b/src/main/kotlin/events/ModifyChatEvent.kt
@@ -2,16 +2,16 @@
package moe.nea.firmament.events
+import net.minecraft.network.chat.Component
import moe.nea.firmament.util.unformattedString
-import net.minecraft.text.Text
/**
* Allow modification of a chat message before it is sent off to the user. Intended for display purposes.
*/
-data class ModifyChatEvent(val originalText: Text) : FirmamentEvent() {
+data class ModifyChatEvent(val originalText: Component) : FirmamentEvent() {
var unformattedString = originalText.unformattedString
private set
- var replaceWith: Text = originalText
+ var replaceWith: Component = originalText
set(value) {
field = value
unformattedString = value.unformattedString
diff --git a/src/main/kotlin/events/OutgoingPacketEvent.kt b/src/main/kotlin/events/OutgoingPacketEvent.kt
index 93890ea..0385647 100644
--- a/src/main/kotlin/events/OutgoingPacketEvent.kt
+++ b/src/main/kotlin/events/OutgoingPacketEvent.kt
@@ -2,7 +2,7 @@
package moe.nea.firmament.events
-import net.minecraft.network.packet.Packet
+import net.minecraft.network.protocol.Packet
data class OutgoingPacketEvent(val packet: Packet<*>) : FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<OutgoingPacketEvent>()
diff --git a/src/main/kotlin/events/ParticleSpawnEvent.kt b/src/main/kotlin/events/ParticleSpawnEvent.kt
index 9359e4b..578fa0d 100644
--- a/src/main/kotlin/events/ParticleSpawnEvent.kt
+++ b/src/main/kotlin/events/ParticleSpawnEvent.kt
@@ -3,12 +3,12 @@
package moe.nea.firmament.events
import org.joml.Vector3f
-import net.minecraft.particle.ParticleEffect
-import net.minecraft.util.math.Vec3d
+import net.minecraft.core.particles.ParticleOptions
+import net.minecraft.world.phys.Vec3
data class ParticleSpawnEvent(
- val particleEffect: ParticleEffect,
- val position: Vec3d,
+ val particleEffect: ParticleOptions,
+ val position: Vec3,
val offset: Vector3f,
val longDistance: Boolean,
val count: Int,
diff --git a/src/main/kotlin/events/PlayerInventoryUpdate.kt b/src/main/kotlin/events/PlayerInventoryUpdate.kt
index 6e8203a..99bce9b 100644
--- a/src/main/kotlin/events/PlayerInventoryUpdate.kt
+++ b/src/main/kotlin/events/PlayerInventoryUpdate.kt
@@ -1,11 +1,22 @@
-
package moe.nea.firmament.events
-import net.minecraft.item.ItemStack
+import net.minecraft.world.item.ItemStack
sealed class PlayerInventoryUpdate : FirmamentEvent() {
- companion object : FirmamentEventBus<PlayerInventoryUpdate>()
- data class Single(val slot: Int, val stack: ItemStack) : PlayerInventoryUpdate()
- data class Multi(val contents: List<ItemStack>) : PlayerInventoryUpdate()
+ companion object : FirmamentEventBus<PlayerInventoryUpdate>()
+ data class Single(val slot: Int, val stack: ItemStack) : PlayerInventoryUpdate() {
+ override fun getOrNull(slot: Int): ItemStack? {
+ if (slot == this.slot) return stack
+ return null
+ }
+
+ }
+
+ data class Multi(val contents: List<ItemStack>) : PlayerInventoryUpdate() {
+ override fun getOrNull(slot: Int): ItemStack? {
+ return contents.getOrNull(slot)
+ }
+ }
+ abstract fun getOrNull(slot: Int): ItemStack?
}
diff --git a/src/main/kotlin/events/ProcessChatEvent.kt b/src/main/kotlin/events/ProcessChatEvent.kt
index 76c0b27..a276951 100644
--- a/src/main/kotlin/events/ProcessChatEvent.kt
+++ b/src/main/kotlin/events/ProcessChatEvent.kt
@@ -2,14 +2,14 @@
package moe.nea.firmament.events
-import net.minecraft.text.Text
+import net.minecraft.network.chat.Component
import moe.nea.firmament.util.unformattedString
/**
* Behaves like [AllowChatEvent], but is triggered even when cancelled by other mods. Intended for data collection.
* Make sure to subscribe to cancellable events as well when using.
*/
-data class ProcessChatEvent(val text: Text, val wasExternallyCancelled: Boolean) : FirmamentEvent.Cancellable() {
+data class ProcessChatEvent(val text: Component, val wasExternallyCancelled: Boolean) : FirmamentEvent.Cancellable() {
val unformattedString = text.unformattedString
val nameHeuristic: String? = run {
diff --git a/src/main/kotlin/events/ScreenChangeEvent.kt b/src/main/kotlin/events/ScreenChangeEvent.kt
index 489e487..8193186 100644
--- a/src/main/kotlin/events/ScreenChangeEvent.kt
+++ b/src/main/kotlin/events/ScreenChangeEvent.kt
@@ -2,7 +2,7 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.screen.Screen
+import net.minecraft.client.gui.screens.Screen
data class ScreenChangeEvent(val old: Screen?, val new: Screen?) : FirmamentEvent.Cancellable() {
var overrideScreen: Screen? = null
diff --git a/src/main/kotlin/events/ScreenRenderPostEvent.kt b/src/main/kotlin/events/ScreenRenderPostEvent.kt
index 79f4913..43b7c01 100644
--- a/src/main/kotlin/events/ScreenRenderPostEvent.kt
+++ b/src/main/kotlin/events/ScreenRenderPostEvent.kt
@@ -2,15 +2,15 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.Screen
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.Screen
data class ScreenRenderPostEvent(
val screen: Screen,
val mouseX: Int,
val mouseY: Int,
val tickDelta: Float,
- val drawContext: DrawContext
+ val drawContext: GuiGraphics
) : FirmamentEvent() {
companion object : FirmamentEventBus<ScreenRenderPostEvent>()
}
diff --git a/src/main/kotlin/events/ServerConnectedEvent.kt b/src/main/kotlin/events/ServerConnectedEvent.kt
index 26897f2..c9bc5e4 100644
--- a/src/main/kotlin/events/ServerConnectedEvent.kt
+++ b/src/main/kotlin/events/ServerConnectedEvent.kt
@@ -1,16 +1,16 @@
package moe.nea.firmament.events
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents
-import net.minecraft.client.MinecraftClient
-import net.minecraft.client.network.ClientPlayNetworkHandler
-import net.minecraft.network.ClientConnection
+import net.minecraft.client.Minecraft
+import net.minecraft.client.multiplayer.ClientPacketListener
+import net.minecraft.network.Connection
data class ServerConnectedEvent(
- val connection: ClientConnection
+ val connection: Connection
) : FirmamentEvent() {
companion object : FirmamentEventBus<ServerConnectedEvent>() {
init {
- ClientPlayConnectionEvents.INIT.register(ClientPlayConnectionEvents.Init { clientPlayNetworkHandler: ClientPlayNetworkHandler, minecraftClient: MinecraftClient ->
+ ClientPlayConnectionEvents.INIT.register(ClientPlayConnectionEvents.Init { clientPlayNetworkHandler: ClientPacketListener, minecraftClient: Minecraft ->
publishSync(ServerConnectedEvent(clientPlayNetworkHandler.connection))
})
}
diff --git a/src/main/kotlin/events/SlotClickEvent.kt b/src/main/kotlin/events/SlotClickEvent.kt
index d4abfb0..bfeadf9 100644
--- a/src/main/kotlin/events/SlotClickEvent.kt
+++ b/src/main/kotlin/events/SlotClickEvent.kt
@@ -1,15 +1,15 @@
package moe.nea.firmament.events
-import net.minecraft.item.ItemStack
-import net.minecraft.screen.slot.Slot
-import net.minecraft.screen.slot.SlotActionType
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.inventory.Slot
+import net.minecraft.world.inventory.ClickType
data class SlotClickEvent(
val slot: Slot,
val stack: ItemStack,
val button: Int,
- val actionType: SlotActionType,
+ val actionType: ClickType,
) : FirmamentEvent() {
companion object : FirmamentEventBus<SlotClickEvent>()
}
diff --git a/src/main/kotlin/events/SlotRenderEvents.kt b/src/main/kotlin/events/SlotRenderEvents.kt
index 5234176..c938ffc 100644
--- a/src/main/kotlin/events/SlotRenderEvents.kt
+++ b/src/main/kotlin/events/SlotRenderEvents.kt
@@ -2,19 +2,16 @@
package moe.nea.firmament.events
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.render.RenderLayer
-import net.minecraft.client.texture.Sprite
-import net.minecraft.screen.slot.Slot
-import net.minecraft.util.Identifier
-import moe.nea.firmament.util.MC
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.world.inventory.Slot
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.util.render.drawGuiTexture
interface SlotRenderEvents {
- val context: DrawContext
+ val context: GuiGraphics
val slot: Slot
- fun highlight(sprite: Identifier) {
+ fun highlight(sprite: ResourceLocation) {
context.drawGuiTexture(
slot.x, slot.y, 0, 16, 16,
sprite
@@ -22,14 +19,14 @@ interface SlotRenderEvents {
}
data class Before(
- override val context: DrawContext, override val slot: Slot,
+ override val context: GuiGraphics, override val slot: Slot,
) : FirmamentEvent(),
SlotRenderEvents {
companion object : FirmamentEventBus<Before>()
}
data class After(
- override val context: DrawContext, override val slot: Slot,
+ override val context: GuiGraphics, override val slot: Slot,
) : FirmamentEvent(),
SlotRenderEvents {
companion object : FirmamentEventBus<After>()
diff --git a/src/main/kotlin/events/SoundReceiveEvent.kt b/src/main/kotlin/events/SoundReceiveEvent.kt
index d1b85b6..063f657 100644
--- a/src/main/kotlin/events/SoundReceiveEvent.kt
+++ b/src/main/kotlin/events/SoundReceiveEvent.kt
@@ -1,15 +1,15 @@
package moe.nea.firmament.events
-import net.minecraft.registry.entry.RegistryEntry
-import net.minecraft.sound.SoundCategory
-import net.minecraft.sound.SoundEvent
-import net.minecraft.util.math.Vec3d
+import net.minecraft.core.Holder
+import net.minecraft.sounds.SoundSource
+import net.minecraft.sounds.SoundEvent
+import net.minecraft.world.phys.Vec3
data class SoundReceiveEvent(
- val sound: RegistryEntry<SoundEvent>,
- val category: SoundCategory,
- val position: Vec3d,
+ val sound: Holder<SoundEvent>,
+ val category: SoundSource,
+ val position: Vec3,
val pitch: Float,
val volume: Float,
val seed: Long
diff --git a/src/main/kotlin/events/TickEvent.kt b/src/main/kotlin/events/TickEvent.kt
index 18007f8..bf51774 100644
--- a/src/main/kotlin/events/TickEvent.kt
+++ b/src/main/kotlin/events/TickEvent.kt
@@ -3,5 +3,8 @@
package moe.nea.firmament.events
data class TickEvent(val tickCount: Int) : FirmamentEvent() {
+ // TODO: introduce a client / server tick system.
+ // client ticks should ignore the game state
+ // server ticks should per-tick count packets received by the server
companion object : FirmamentEventBus<TickEvent>()
}
diff --git a/src/main/kotlin/events/UseBlockEvent.kt b/src/main/kotlin/events/UseBlockEvent.kt
index 8bbe0de..f229931 100644
--- a/src/main/kotlin/events/UseBlockEvent.kt
+++ b/src/main/kotlin/events/UseBlockEvent.kt
@@ -1,11 +1,11 @@
package moe.nea.firmament.events
-import net.minecraft.entity.player.PlayerEntity
-import net.minecraft.util.Hand
-import net.minecraft.util.hit.BlockHitResult
-import net.minecraft.world.World
+import net.minecraft.world.entity.player.Player
+import net.minecraft.world.InteractionHand
+import net.minecraft.world.phys.BlockHitResult
+import net.minecraft.world.level.Level
-data class UseBlockEvent(val player: PlayerEntity, val world: World, val hand: Hand, val hitResult: BlockHitResult) : FirmamentEvent.Cancellable() {
+data class UseBlockEvent(val player: Player, val world: Level, val hand: InteractionHand, val hitResult: BlockHitResult) : FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<UseBlockEvent>()
}
diff --git a/src/main/kotlin/events/UseItemEvent.kt b/src/main/kotlin/events/UseItemEvent.kt
index e294bb1..5174a51 100644
--- a/src/main/kotlin/events/UseItemEvent.kt
+++ b/src/main/kotlin/events/UseItemEvent.kt
@@ -1,11 +1,11 @@
package moe.nea.firmament.events
-import net.minecraft.entity.player.PlayerEntity
-import net.minecraft.item.ItemStack
-import net.minecraft.util.Hand
-import net.minecraft.world.World
+import net.minecraft.world.entity.player.Player
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.InteractionHand
+import net.minecraft.world.level.Level
-data class UseItemEvent(val playerEntity: PlayerEntity, val world: World, val hand: Hand) : FirmamentEvent.Cancellable() {
+data class UseItemEvent(val playerEntity: Player, val world: Level, val hand: InteractionHand) : FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<UseItemEvent>()
- val item: ItemStack = playerEntity.getStackInHand(hand)
+ val item: ItemStack = playerEntity.getItemInHand(hand)
}
diff --git a/src/main/kotlin/events/WorldKeyboardEvent.kt b/src/main/kotlin/events/WorldKeyboardEvent.kt
index e8566fd..860db5c 100644
--- a/src/main/kotlin/events/WorldKeyboardEvent.kt
+++ b/src/main/kotlin/events/WorldKeyboardEvent.kt
@@ -1,18 +1,13 @@
-
-
package moe.nea.firmament.events
-import net.minecraft.client.option.KeyBinding
-import moe.nea.firmament.keybindings.IKeyBinding
-
-data class WorldKeyboardEvent(val keyCode: Int, val scanCode: Int, val modifiers: Int) : FirmamentEvent.Cancellable() {
- companion object : FirmamentEventBus<WorldKeyboardEvent>()
+import moe.nea.firmament.keybindings.GenericInputAction
+import moe.nea.firmament.keybindings.InputModifiers
+import moe.nea.firmament.keybindings.SavedKeyBinding
- fun matches(keyBinding: KeyBinding): Boolean {
- return matches(IKeyBinding.minecraft(keyBinding))
- }
+data class WorldKeyboardEvent(val action: GenericInputAction, val modifiers: InputModifiers) : FirmamentEvent.Cancellable() {
+ fun matches(keyBinding: SavedKeyBinding, atLeast: Boolean = false): Boolean {
+ return keyBinding.matches(action, modifiers, atLeast)
+ }
- fun matches(keyBinding: IKeyBinding): Boolean {
- return keyBinding.matches(keyCode, scanCode, modifiers)
- }
+ companion object : FirmamentEventBus<WorldKeyboardEvent>()
}
diff --git a/src/main/kotlin/events/WorldMouseMoveEvent.kt b/src/main/kotlin/events/WorldMouseMoveEvent.kt
new file mode 100644
index 0000000..7a17ba4
--- /dev/null
+++ b/src/main/kotlin/events/WorldMouseMoveEvent.kt
@@ -0,0 +1,5 @@
+package moe.nea.firmament.events
+
+data class WorldMouseMoveEvent(val deltaX: Double, val deltaY: Double) : FirmamentEvent.Cancellable() {
+ companion object : FirmamentEventBus<WorldMouseMoveEvent>()
+}
diff --git a/src/main/kotlin/events/WorldRenderLastEvent.kt b/src/main/kotlin/events/WorldRenderLastEvent.kt
index 3c2103d..394a674 100644
--- a/src/main/kotlin/events/WorldRenderLastEvent.kt
+++ b/src/main/kotlin/events/WorldRenderLastEvent.kt
@@ -2,23 +2,20 @@
package moe.nea.firmament.events
-import net.minecraft.client.render.Camera
-import net.minecraft.client.render.GameRenderer
-import net.minecraft.client.render.LightmapTextureManager
-import net.minecraft.client.render.RenderTickCounter
-import net.minecraft.client.render.VertexConsumerProvider
-import net.minecraft.client.util.math.MatrixStack
-import net.minecraft.util.math.Position
-import net.minecraft.util.math.Vec3d
+import net.minecraft.client.Camera
+import net.minecraft.client.DeltaTracker
+import net.minecraft.client.renderer.MultiBufferSource
+import net.minecraft.client.renderer.state.CameraRenderState
+import com.mojang.blaze3d.vertex.PoseStack
/**
* 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 tickCounter: RenderTickCounter,
- val camera: Camera,
- val vertexConsumers: VertexConsumerProvider.Immediate,
+ val matrices: PoseStack,
+ val tickCounter: Int,
+ val camera: CameraRenderState,
+ val vertexConsumers: MultiBufferSource.BufferSource,
) : FirmamentEvent() {
companion object : FirmamentEventBus<WorldRenderLastEvent>()
}
diff --git a/src/main/kotlin/events/registration/ChatEvents.kt b/src/main/kotlin/events/registration/ChatEvents.kt
index 1dcc91a..93a0f1a 100644
--- a/src/main/kotlin/events/registration/ChatEvents.kt
+++ b/src/main/kotlin/events/registration/ChatEvents.kt
@@ -1,19 +1,21 @@
package moe.nea.firmament.events.registration
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents
+import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents
import net.fabricmc.fabric.api.event.player.AttackBlockCallback
import net.fabricmc.fabric.api.event.player.UseBlockCallback
import net.fabricmc.fabric.api.event.player.UseItemCallback
-import net.minecraft.text.Text
-import net.minecraft.util.ActionResult
+import net.minecraft.network.chat.Component
+import net.minecraft.world.InteractionResult
import moe.nea.firmament.events.AllowChatEvent
import moe.nea.firmament.events.AttackBlockEvent
+import moe.nea.firmament.events.JoinServerEvent
import moe.nea.firmament.events.ModifyChatEvent
import moe.nea.firmament.events.ProcessChatEvent
import moe.nea.firmament.events.UseBlockEvent
import moe.nea.firmament.events.UseItemEvent
-private var lastReceivedMessage: Text? = null
+private var lastReceivedMessage: Component? = null
fun registerFirmamentEvents() {
ClientReceiveMessageEvents.ALLOW_CHAT.register(ClientReceiveMessageEvents.AllowChat { message, signedMessage, sender, params, receptionTimestamp ->
@@ -43,21 +45,24 @@ fun registerFirmamentEvents() {
AttackBlockCallback.EVENT.register(AttackBlockCallback { player, world, hand, pos, direction ->
if (AttackBlockEvent.publish(AttackBlockEvent(player, world, hand, pos, direction)).cancelled)
- ActionResult.CONSUME
- else ActionResult.PASS
+ InteractionResult.FAIL
+ else InteractionResult.PASS
})
UseBlockCallback.EVENT.register(UseBlockCallback { player, world, hand, hitResult ->
if (UseBlockEvent.publish(UseBlockEvent(player, world, hand, hitResult)).cancelled)
- ActionResult.CONSUME
- else ActionResult.PASS
+ InteractionResult.FAIL
+ else InteractionResult.PASS
})
UseBlockCallback.EVENT.register(UseBlockCallback { player, world, hand, hitResult ->
if (UseItemEvent.publish(UseItemEvent(player, world, hand)).cancelled)
- ActionResult.CONSUME
- else ActionResult.PASS
+ InteractionResult.FAIL
+ else InteractionResult.PASS
})
UseItemCallback.EVENT.register(UseItemCallback { playerEntity, world, hand ->
- if (UseItemEvent.publish(UseItemEvent(playerEntity, world, hand)).cancelled) ActionResult.CONSUME
- else ActionResult.PASS
+ if (UseItemEvent.publish(UseItemEvent(playerEntity, world, hand)).cancelled) InteractionResult.FAIL
+ else InteractionResult.PASS
})
+ ClientPlayConnectionEvents.JOIN.register { networkHandler, packetSender, _ ->
+ JoinServerEvent.publish(JoinServerEvent(networkHandler, packetSender))
+ }
}
diff --git a/src/main/kotlin/events/subscription/Subscription.kt b/src/main/kotlin/events/subscription/Subscription.kt
index 1c1d3bd..812da92 100644
--- a/src/main/kotlin/events/subscription/Subscription.kt
+++ b/src/main/kotlin/events/subscription/Subscription.kt
@@ -3,11 +3,7 @@ package moe.nea.firmament.events.subscription
import moe.nea.firmament.events.FirmamentEvent
import moe.nea.firmament.events.FirmamentEventBus
-import moe.nea.firmament.features.FirmamentFeature
-interface SubscriptionOwner {
- val delegateFeature: FirmamentFeature
-}
data class Subscription<T : FirmamentEvent>(
val owner: Any,