Skip to content

Commit

Permalink
Add shiny pig tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Jun 14, 2024
1 parent cd1826a commit e4bd69a
Show file tree
Hide file tree
Showing 17 changed files with 548 additions and 6 deletions.
25 changes: 25 additions & 0 deletions src/main/java/moe/nea/firmament/mixins/EntityDespawnPatch.java
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));
}
}
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)
public class HudRenderEvents {
@Inject(method = "renderSleepOverlay", at = @At(value = "TAIL"))
public class HudRenderEventsPatch {
@Inject(method = "renderSleepOverlay", at = @At(value = "HEAD"))
public void renderCallBack(DrawContext context, float tickDelta, CallbackInfo ci) {
HudRenderEvent.Companion.publish(new HudRenderEvent(context, tickDelta));
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/moe/nea/firmament/commands/rome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package moe.nea.firmament.commands

import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.StringArgumentType.string
import io.ktor.client.statement.*
import io.ktor.client.statement.bodyAsText
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.minecraft.text.Text
import moe.nea.firmament.apis.UrsaManager
Expand Down Expand Up @@ -195,6 +195,13 @@ fun firmamentCommand() = literal("firmament") {
FairySouls.TConfig.showConfigEditor()
}
}
thenLiteral("simulate") {
thenArgument("message", RestArgumentType) { message ->
thenExecute {
MC.instance.messageHandler.onGameMessage(Text.literal(get(message)), false)
}
}
}
thenLiteral("sbdata") {
thenExecute {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.profile", SBData.profileId))
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/moe/nea/firmament/events/EntityDespawnEvent.kt
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 src/main/kotlin/moe/nea/firmament/events/EntityInteractionEvent.kt
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,
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import moe.nea.firmament.features.debug.DeveloperFeatures
import moe.nea.firmament.features.debug.MinorTrolling
import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.features.diana.DianaWaypoints
import moe.nea.firmament.features.events.anniversity.AnniversaryFeatures
import moe.nea.firmament.features.fixes.CompatibliltyFeatures
import moe.nea.firmament.features.fixes.Fixes
import moe.nea.firmament.features.inventory.CraftingOverlay
Expand Down Expand Up @@ -70,6 +71,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(ChatLinks)
loadFeature(InventoryButtons)
loadFeature(CompatibliltyFeatures)
loadFeature(AnniversaryFeatures)
loadFeature(QuickCommands)
loadFeature(SaveCursorPosition)
loadFeature(CustomSkyBlockTextures)
Expand Down
36 changes: 36 additions & 0 deletions src/main/kotlin/moe/nea/firmament/features/debug/PowerUserTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ package moe.nea.firmament.features.debug
import net.minecraft.block.SkullBlock
import net.minecraft.block.entity.SkullBlockEntity
import net.minecraft.component.DataComponentTypes
import net.minecraft.entity.Entity
import net.minecraft.entity.LivingEntity
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.text.Text
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.EntityHitResult
import net.minecraft.util.hit.HitResult
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.CustomItemModelEvent
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.events.ItemTooltipEvent
Expand All @@ -41,6 +45,7 @@ object PowerUserTools : FirmamentFeature {
val copyTexturePackId by keyBindingWithDefaultUnbound("copy-texture-pack-id")
val copyNbtData by keyBindingWithDefaultUnbound("copy-nbt-data")
val copySkullTexture by keyBindingWithDefaultUnbound("copy-skull-texture")
val copyEntityData by keyBindingWithDefaultUnbound("entity-data")
}

override val config
Expand All @@ -65,6 +70,37 @@ object PowerUserTools : FirmamentFeature {
}
}

fun debugFormat(itemStack: ItemStack): Text {
return Text.literal(itemStack.skyBlockId?.toString() ?: itemStack.toString())
}

@Subscribe
fun onEntityInfo(event: WorldKeyboardEvent) {
if (!event.matches(TConfig.copyEntityData)) return
val target = (MC.instance.crosshairTarget as? EntityHitResult)?.entity
if (target == null) {
MC.sendChat(Text.translatable("firmament.poweruser.entity.fail"))
return
}
showEntity(target)
}

fun showEntity(target: Entity) {
MC.sendChat(Text.translatable("firmament.poweruser.entity.type", target.type))
MC.sendChat(Text.translatable("firmament.poweruser.entity.name", target.name))
if (target is LivingEntity) {
MC.sendChat(Text.translatable("firmament.poweruser.entity.armor"))
for (armorItem in target.armorItems) {
MC.sendChat(Text.translatable("firmament.poweruser.entity.armor.item", debugFormat(armorItem)))
}
}
MC.sendChat(Text.stringifiedTranslatable("firmament.poweruser.entity.passengers", target.passengerList.size))
target.passengerList.forEach {
showEntity(target)
}
}


@Subscribe
fun copyInventoryInfo(it: HandledScreenKeyPressedEvent) {
if (it.screen !is AccessorHandledScreen) return
Expand Down
Loading

0 comments on commit e4bd69a

Please sign in to comment.