aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/lorenz/mod/dungeon
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-08 08:09:43 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-08 08:09:43 +0200
commitcbc6b4928fea6c8afecd84ec0c96f2ac489e267e (patch)
tree2182554912c2321134d1075f37b1e3e54b28758c /src/main/java/at/lorenz/mod/dungeon
parentcedeb7232dab102f58edbf01ccc2b22ddf5bfb19 (diff)
downloadSkyHanni-cbc6b4928fea6c8afecd84ec0c96f2ac489e267e.tar.gz
SkyHanni-cbc6b4928fea6c8afecd84ec0c96f2ac489e267e.tar.bz2
SkyHanni-cbc6b4928fea6c8afecd84ec0c96f2ac489e267e.zip
added DungeonHighlightClickedBlocks, changed chat manager from forge event to packet
Diffstat (limited to 'src/main/java/at/lorenz/mod/dungeon')
-rw-r--r--src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt
new file mode 100644
index 000000000..ce885df48
--- /dev/null
+++ b/src/main/java/at/lorenz/mod/dungeon/DungeonHighlightClickedBlocks.kt
@@ -0,0 +1,102 @@
+package at.lorenz.mod.dungeon
+
+import at.lorenz.mod.config.LorenzConfig
+import at.lorenz.mod.events.LorenzChatEvent
+import at.lorenz.mod.events.PacketEvent
+import at.lorenz.mod.utils.*
+import at.lorenz.mod.utils.BlockUtils.getBlockAt
+import at.lorenz.mod.utils.RenderUtils.drawSkytilsColor
+import at.lorenz.mod.utils.RenderUtils.drawString
+import net.minecraft.init.Blocks
+import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
+import net.minecraftforge.client.event.RenderWorldLastEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class DungeonHighlightClickedBlocks {
+
+ private val blocks = mutableListOf<ClickedBlock>()
+ private var colorIndex = 0
+ private val colors = listOf(LorenzColor.YELLOW, LorenzColor.AQUA, LorenzColor.GREEN, LorenzColor.LIGHT_PURPLE)
+
+ private fun getNextColor(): LorenzColor {
+ var id = colorIndex + 1
+ if (id == colors.size) id = 0
+ colorIndex = id
+ return colors[colorIndex]
+ }
+
+ @SubscribeEvent
+ fun onChatMessage(event: LorenzChatEvent) {
+ if (!LorenzConfig.lorenzDungeonHighlightClickedBlocks) return
+ //TODO add
+// if (!LorenzUtils.inDungeon) return
+
+ if (event.message == "§cYou hear the sound of something opening...") {
+ event.blockedReason = "dungeon_highlight_clicked_block"
+ }
+ }
+
+ @SubscribeEvent
+ fun onSendPacket(event: PacketEvent.SendEvent) {
+ if (!LorenzConfig.lorenzDungeonHighlightClickedBlocks) return
+ //TODO add
+// if (!LorenzUtils.inDungeon) return
+// TODO add
+// if (DungeonAPI.inBossRoom) return
+ if (event.packet !is C08PacketPlayerBlockPlacement || event.packet.stack == null) return
+
+ val position = event.packet.position.toLorenzVec()
+
+ if (blocks.any { it.position == position }) return
+
+ val type: ClickedBlockType = when (position.getBlockAt()) {
+ Blocks.chest, Blocks.trapped_chest -> ClickedBlockType.CHEST
+ Blocks.lever -> ClickedBlockType.LEVER
+ Blocks.skull -> ClickedBlockType.WITHER_ESSENCE
+ else -> return
+ }
+
+ if (type == ClickedBlockType.WITHER_ESSENCE) {
+ val text = BlockUtils.getSkinFromSkull(position.toBlocPos())
+ if (text != "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQ" +
+ "ubmV0L3RleHR1cmUvYzRkYjRhZGZhOWJmNDhmZjVkNDE3M" +
+ "DdhZTM0ZWE3OGJkMjM3MTY1OWZjZDhjZDg5MzQ3NDlhZjRjY2U5YiJ9fX0="
+ ) {
+ return
+ }
+ }
+
+// if (nearWaterRoom() && type == ClickedBlockType.LEVER) return
+
+ val color = getNextColor()
+ val displayText = color.getChatColor() + "Clicked " + type.display
+ blocks.add(ClickedBlock(position, displayText, color, System.currentTimeMillis()))
+ }
+
+ @SubscribeEvent
+ fun onWorldRender(event: RenderWorldLastEvent) {
+ if (!LorenzConfig.lorenzDungeonHighlightClickedBlocks) return
+ //TODO add
+// if (!LorenzUtils.inDungeon) return
+
+ blocks.removeAll { System.currentTimeMillis() > it.time + 3000 }
+ blocks.forEach {
+ event.drawSkytilsColor(it.position, it.color)
+ event.drawString(it.position.add(0.5, 0.5, 0.5), it.displayText, true)
+ }
+ }
+
+ class ClickedBlock(val position: LorenzVec, val displayText: String, val color: LorenzColor, val time: Long)
+
+ enum class ClickedBlockType(val display: String) {
+ LEVER("Lever"),
+ CHEST("Chest"),
+ WITHER_ESSENCE("Wither Essence"),
+ }
+
+// private fun nearWaterRoom(): Boolean {
+// val playerLoc =
+// LocationUtils.getPlayerLocation().add(LocationUtils.getPlayerLookingAtDirection().multiply(2)).add(0, 2, 0)
+// return WaterBoardSolver.waterRoomDisplays.any { it.distance(playerLoc) < 3 }
+// }
+} \ No newline at end of file