-
Notifications
You must be signed in to change notification settings - Fork 12
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
17 changed files
with
548 additions
and
6 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/moe/nea/firmament/mixins/EntityDespawnPatch.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,25 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.mixins; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import moe.nea.firmament.events.EntityDespawnEvent; | ||
import net.minecraft.client.world.ClientWorld; | ||
import net.minecraft.entity.Entity; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ClientWorld.class) | ||
public class EntityDespawnPatch { | ||
@Inject(method = "removeEntity", at = @At(value = "TAIL")) | ||
private void onRemoved(int entityId, Entity.RemovalReason removalReason, CallbackInfo ci, @Local @Nullable Entity entity) { | ||
EntityDespawnEvent.Companion.publish(new EntityDespawnEvent(entity, entityId, removalReason)); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/moe/nea/firmament/mixins/EntityInteractEventPatch.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,39 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.mixins; | ||
|
||
import moe.nea.firmament.events.EntityInteractionEvent; | ||
import net.minecraft.client.network.ClientPlayerInteractionManager; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(ClientPlayerInteractionManager.class) | ||
public class EntityInteractEventPatch { | ||
@Inject(method = "attackEntity", at = @At("HEAD")) | ||
private void onAttack(PlayerEntity player, Entity target, CallbackInfo ci) { | ||
EntityInteractionEvent.Companion.publish(new EntityInteractionEvent(EntityInteractionEvent.InteractionKind.ATTACK, target, Hand.MAIN_HAND)); | ||
} | ||
|
||
@Inject(method = "interactEntity", at = @At("HEAD")) | ||
private void onInteract(PlayerEntity player, Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> cir) { | ||
EntityInteractionEvent.Companion.publish(new EntityInteractionEvent(EntityInteractionEvent.InteractionKind.INTERACT, entity, hand)); | ||
} | ||
|
||
@Inject(method = "interactEntityAtLocation", at = @At("HEAD")) | ||
private void onInteractAtLocation(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable<ActionResult> cir) { | ||
EntityInteractionEvent.Companion.publish(new EntityInteractionEvent(EntityInteractionEvent.InteractionKind.INTERACT_AT_LOCATION, entity, hand)); | ||
} | ||
|
||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/moe/nea/firmament/events/EntityDespawnEvent.kt
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,16 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.events | ||
|
||
import net.minecraft.entity.Entity | ||
|
||
data class EntityDespawnEvent( | ||
val entity: Entity?, val entityId: Int, | ||
val reason: Entity.RemovalReason, | ||
) : FirmamentEvent() { | ||
companion object: FirmamentEventBus<EntityDespawnEvent>() | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/moe/nea/firmament/events/EntityInteractionEvent.kt
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,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.events | ||
|
||
import net.minecraft.entity.Entity | ||
import net.minecraft.util.Hand | ||
|
||
data class EntityInteractionEvent( | ||
val kind: InteractionKind, | ||
val entity: Entity, | ||
val hand: Hand, | ||
) : FirmamentEvent() { | ||
companion object : FirmamentEventBus<EntityInteractionEvent>() | ||
enum class InteractionKind { | ||
/** | ||
* Is sent when left-clicking an entity | ||
*/ | ||
ATTACK, | ||
|
||
/** | ||
* Is a fallback when [INTERACT_AT_LOCATION] fails | ||
*/ | ||
INTERACT, | ||
|
||
/** | ||
* Is tried first on right click | ||
*/ | ||
INTERACT_AT_LOCATION, | ||
} | ||
} |
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
Oops, something went wrong.