diff options
Diffstat (limited to 'src')
5 files changed, 160 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 8a0805a77..e91fbb1ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -160,6 +160,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorTimer +import at.hannibal2.skyhanni.features.garden.visitor.HighlightVisitorsOutsideOfGarden import at.hannibal2.skyhanni.features.garden.visitor.VisitorListener import at.hannibal2.skyhanni.features.inventory.AuctionsHighlighter import at.hannibal2.skyhanni.features.inventory.ChestValue @@ -354,6 +355,7 @@ class SkyHanniMod { loadModule(VisitorListener()) loadModule(OwnInventoryData()) loadModule(ToolTipData()) + loadModule(HighlightVisitorsOutsideOfGarden()) loadModule(GuiEditManager()) loadModule(UpdateManager) loadModule(CropAccessoryData()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index d550d3f72..a5d9847ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -331,6 +331,41 @@ public class GardenConfig { defaultKey = Keyboard.KEY_NONE ) public int acceptHotkey = Keyboard.KEY_NONE; + + + @Expose + @ConfigOption( + name = "Highlight Visitors in SkyBlock", + desc = "Highlights Visitors outside of the Garden" + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean highlightVisitors = false; + + + @Expose + @ConfigOption( + name = "Block Interacting with Visitors", + desc = "Blocks you from interacting with / unlocking Visitors to allow for Dedication Cycling" + ) + @ConfigEditorDropdown + public VisitorBlockBehaviour blockInteracting = VisitorBlockBehaviour.ONLY_ON_BINGO; + + public enum VisitorBlockBehaviour { + DONT("Don't"), ALWAYS("Always"), ONLY_ON_BINGO("Only on Bingo"); + + final String str; + + VisitorBlockBehaviour(String str) { + this.str = str; + } + + @Override + public String toString() { + return str; + } + } + } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt new file mode 100644 index 000000000..e0638c2f6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/HighlightVisitorsOutsideOfGarden.kt @@ -0,0 +1,101 @@ +package at.hannibal2.skyhanni.features.garden.visitor + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.GardenConfig.VisitorConfig.VisitorBlockBehaviour +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.EntityUtils.getSkinTexture +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.getLorenzVec +import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson +import at.hannibal2.skyhanni.utils.toLorenzVec +import io.github.moulberry.notenoughupdates.util.SBInfo +import net.minecraft.client.Minecraft +import net.minecraft.entity.Entity +import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.network.play.client.C02PacketUseEntity +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class HighlightVisitorsOutsideOfGarden { + var visitorJson = mapOf<String?, List<GardenJson.GardenVisitor>>() + + val config get() = SkyHanniMod.feature.garden.visitors + + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + visitorJson = event.getConstant<GardenJson>( + "Garden", GardenJson::class.java + ).visitors.values.groupBy { + it.mode + } + } + + fun getSkinOrTypeFor(entity: Entity): String { + if (entity is EntityPlayer) { + return entity.getSkinTexture() ?: "no skin" + } + return entity.javaClass.simpleName + } + + fun isVisitor(entity: Entity): Boolean { + val mode = SBInfo.getInstance().getLocation() + val possibleJsons = visitorJson[mode] ?: return false + val skinOrType = getSkinOrTypeFor(entity) + return possibleJsons.any { + ((it.position == null) || it.position!!.distance(entity.position.toLorenzVec()) < 1) + && it.skinOrType?.replace("\\n", "")?.replace("\n", "") == skinOrType + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!config.highlightVisitors) return + if (!event.repeatSeconds(1)) return + EntityUtils.getEntities<EntityLivingBase>() + .filter { it !is EntityArmorStand && isVisitor(it) } + .forEach { + RenderLivingEntityHelper.setEntityColor( + it, + LorenzColor.DARK_RED.toColor().withAlpha(50) + ) { config.highlightVisitors } + } + } + + val shouldBlock + get() = when (config.blockInteracting) { + VisitorBlockBehaviour.DONT -> false + VisitorBlockBehaviour.ALWAYS -> true + VisitorBlockBehaviour.ONLY_ON_BINGO -> SBInfo.getInstance().bingo + null -> false + } + + @SubscribeEvent + fun onClickEntity(event: PacketEvent.SendEvent) { + if (!shouldBlock) return + val world = Minecraft.getMinecraft().theWorld ?: return + val player = Minecraft.getMinecraft().thePlayer ?: return + if (player.isSneaking) return + val packet = event.packet as? C02PacketUseEntity ?: return + val entity = packet.getEntityFromWorld(world) ?: return + if (isVisitor(entity) + || (entity is EntityArmorStand && EntityUtils.getEntitiesNearby<EntityLivingBase>( + entity.getLorenzVec(), + 2.0 + ).any { isVisitor(it) }) + ) { + event.isCanceled = true + LorenzUtils.clickableChat( + "§e[SkyHanniBal] Blocked you from interacting with a visitor. Sneak to bypass or click here to change settings.", + "/sh block interacting with visitors" + ) + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt index b7c4ae4a1..97cd1c4ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyNearbyEntitiesCommand.kt @@ -45,6 +45,7 @@ object CopyNearbyEntitiesCommand { resultList.add("name: '" + entity.name + "'") resultList.add("displayName: '${displayName.formattedText}'") resultList.add("entityId: ${entity.entityId}") + resultList.add("uuid version: ${entity.uniqueID.version()} ${if(entity.uniqueID.version() != 4) "NPC " else ""}(${entity.uniqueID})") resultList.add("location data:") resultList.add("- vec: $vec") resultList.add("- distance: $distance") @@ -167,4 +168,4 @@ object CopyNearbyEntitiesCommand { resultList.add("- type: $type") } } -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java index 87a80d391..265e5b11e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/GardenJson.java @@ -1,7 +1,9 @@ package at.hannibal2.skyhanni.utils.jsonobjects; import at.hannibal2.skyhanni.features.garden.CropType; +import at.hannibal2.skyhanni.utils.LorenzVec; import com.google.gson.annotations.Expose; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Map; @@ -26,7 +28,24 @@ public class GardenJson { @Expose public String rarity; + @Nullable + @Expose + public LorenzVec position; + + /** + * Formatted as follows: + * - If this visitor is a player, get the encoded skin value + * - If this visitor is a mob, get their mob class name + */ + @Nullable + @Expose + public String skinOrType; + + @Nullable + @Expose + public String mode; + @Expose public List<String> need_items; } -}
\ No newline at end of file +} |