From dddd91d1cead43a8164425f28dffd6ea799ab22f Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 8 Sep 2023 12:13:03 -0300 Subject: Merge pull request #445 * Add nametags for minions as soon as they are placed --- .../skyhanni/features/minion/MinionFeatures.kt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index d876f2bb3..ec2a212c1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy @@ -21,9 +22,11 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.init.Blocks import net.minecraftforge.client.event.GuiScreenEvent import net.minecraftforge.client.event.RenderLivingEvent import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.event.entity.player.PlayerInteractEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.InputEvent @@ -34,6 +37,8 @@ class MinionFeatures { private val config get() = SkyHanniMod.feature.minions private var lastClickedEntity: LorenzVec? = null private var lastMinion: LorenzVec? = null + private var newMinion: LorenzVec? = null + private var newMinionName: String? = null private var lastMinionOpened = 0L private var minionInventoryOpen = false @@ -41,6 +46,24 @@ class MinionFeatures { private var coinsPerDay = "" private val minionUpgradePattern = "§aYou have upgraded your Minion to Tier (?.*)".toPattern() + @SubscribeEvent + fun onPlayerInteract(event: PlayerInteractEvent) { + if (!LorenzUtils.inSkyBlock) return + if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return + if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) return; + + val lookingAt = event.pos.offset(event.face) + val equipped = InventoryUtils.getItemInHand() ?: return + + if (equipped.displayName.contains(" Minion ") && event.world.getBlockState(lookingAt).block == Blocks.air) { + newMinion = lookingAt.toLorenzVec().add(0.5, 0.0, 0.5) + newMinionName = getMinionName(equipped.cleanName()) + } else { + newMinion = null + newMinionName = null + } + } + @SubscribeEvent fun onClick(event: InputEvent.MouseInputEvent) { if (!LorenzUtils.inSkyBlock) return @@ -212,6 +235,18 @@ class MinionFeatures { lastMinionOpened = 0L } } + if (message.startsWith("§bYou placed a minion!")) { + if (newMinion != null) { + minions = minions?.editCopy { + this[newMinion!!] = Storage.ProfileSpecific.MinionConfig().apply { + displayName = newMinionName + lastClicked = 0 + } + } + newMinion = null + newMinionName = null + } + } minionUpgradePattern.matchMatcher(message) { val newTier = group("tier").romanToDecimalIfNeeded() -- cgit