blob: 66042304dc907d8cae54aa83ebdb55030e771541 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ClickType
import at.hannibal2.skyhanni.data.SendTitleHelper
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.SoundUtils.playSound
import net.minecraft.client.audio.ISound
import net.minecraft.client.audio.PositionedSound
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class WrongFungiCutterWarning {
private var mode = FungiMode.UNKNOWN
private var lastPlaySoundTime = 0L
private val sound = object : PositionedSound(ResourceLocation("random.orb")) {
init {
volume = 50f
repeat = false
repeatDelay = 0
attenuationType = ISound.AttenuationType.NONE
}
}
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
val message = event.message
if (message == "§eFungi Cutter Mode: §r§cRed Mushrooms") {
mode = FungiMode.RED
}
if (message == "§eFungi Cutter Mode: §r§cBrown Mushrooms") {
mode = FungiMode.BROWN
}
}
@SubscribeEvent
fun onBlockClick(event: BlockClickEvent) {
if (event.clickType == ClickType.LEFT_CLICK) {
val toString = event.getBlockState.toString()
if (toString == "minecraft:red_mushroom") {
if (mode == FungiMode.BROWN) {
notifyWrong()
}
}
if (toString == "minecraft:brown_mushroom") {
if (mode == FungiMode.RED) {
notifyWrong()
}
}
}
}
private fun notifyWrong() {
if (!SkyHanniMod.feature.garden.fungiCutterWarn) return
SendTitleHelper.sendTitle("§cWrong Fungi Cutter Mode!", 2_000)
if (System.currentTimeMillis() > lastPlaySoundTime + 3_00) {
lastPlaySoundTime = System.currentTimeMillis()
sound.playSound()
}
}
@SubscribeEvent
fun onGardenToolChange(event: GardenToolChangeEvent) {
if (event.crop == CropType.MUSHROOM) {
readItem(event.toolItem!!)
} else {
mode = FungiMode.UNKNOWN
}
}
private fun readItem(item: ItemStack) {
for (line in item.getLore()) {
if (line == "§eMode: §cRed Mushrooms") {
mode = FungiMode.RED
}
if (line == "§eMode: §cBrown Mushrooms") {
mode = FungiMode.BROWN
}
}
}
enum class FungiMode {
RED,
BROWN,
UNKNOWN
}
}
|