From 415c54df96ba46744a524715f10ff26962929903 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 21 Mar 2023 20:08:26 +0100 Subject: Added wrong fungi cutter mode warning --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 1 + .../hannibal2/skyhanni/config/features/Garden.java | 5 ++ .../hannibal2/skyhanni/events/BlockClickEvent.kt | 5 +- .../features/garden/GardenCropMilestoneDisplay.kt | 1 + .../features/garden/WrongFungiCutterWarning.kt | 96 ++++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/BlockUtils.kt | 6 +- .../java/at/hannibal2/skyhanni/utils/SoundUtils.kt | 8 ++ 7 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/WrongFungiCutterWarning.kt (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index bfbdcb81d..ee3bdce7d 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -227,6 +227,7 @@ public class SkyHanniMod { loadModule(new CropMoneyDisplay()); loadModule(new JacobFarmingContestsInventory()); loadModule(new GardenNextJacobContest()); + loadModule(new WrongFungiCutterWarning()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index 27a131eda..75f934584 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -438,4 +438,9 @@ public class Garden { @ConfigOption(name = "Desk in Menu", desc = "Show a Desk button in the SkyBlock Menu. Opens the /desk command on click.") @ConfigEditorBoolean public boolean deskInSkyBlockMenu = true; + + @Expose + @ConfigOption(name = "Fungi Cutter Warning", desc = "Warn when breaking mushroom with the wrong Fungi Cutter mode.") + @ConfigEditorBoolean + public boolean fungiCutterWarn = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/events/BlockClickEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/BlockClickEvent.kt index eca74c707..b256113a3 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/BlockClickEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/BlockClickEvent.kt @@ -1,7 +1,10 @@ package at.hannibal2.skyhanni.events import at.hannibal2.skyhanni.data.ClickType +import at.hannibal2.skyhanni.utils.BlockUtils.getBlockStateAt import at.hannibal2.skyhanni.utils.LorenzVec import net.minecraft.item.ItemStack -class BlockClickEvent(val clickType: ClickType, val position: LorenzVec, val itemInHand: ItemStack?) : LorenzEvent() \ No newline at end of file +class BlockClickEvent(val clickType: ClickType, val position: LorenzVec, val itemInHand: ItemStack?) : LorenzEvent() { + val getBlockState by lazy { position.getBlockStateAt() } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt index 1faa8e3e7..c3c1f724d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt @@ -31,6 +31,7 @@ class GardenCropMilestoneDisplay { attenuationType = ISound.AttenuationType.NONE } } + private var lastPlaySoundTime = 0L private var needsInventory = false diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/WrongFungiCutterWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/WrongFungiCutterWarning.kt new file mode 100644 index 000000000..e012b60c3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/WrongFungiCutterWarning.kt @@ -0,0 +1,96 @@ +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) { + val crop = event.crop ?: "" + if (crop == "Mushroom") { + readItem(event.heldItem!!) + } 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 + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt index 776ba7f6c..5138ebf35 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/BlockUtils.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.client.Minecraft import net.minecraft.tileentity.TileEntitySkull import net.minecraft.util.BlockPos @@ -9,7 +10,10 @@ import net.minecraftforge.common.util.Constants object BlockUtils { fun LorenzVec.getBlockAt(): Block = - Minecraft.getMinecraft().theWorld.getBlockState(toBlocPos()).block + getBlockStateAt().block + + fun LorenzVec.getBlockStateAt(): IBlockState = + Minecraft.getMinecraft().theWorld.getBlockState(toBlocPos()) fun LorenzVec.isInLoadedChunk(): Boolean = Minecraft.getMinecraft().theWorld.chunkProvider.provideChunk(toBlocPos()).isLoaded diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 1fb107375..26f06df29 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -14,6 +14,14 @@ object SoundUtils { try { Minecraft.getMinecraft().soundHandler.playSound(this) } catch (e: Exception) { + if (e is IllegalArgumentException) { + e.message?.let { + if (it.startsWith("value already present:")) { + println("SkyHanni Sound error: $it") + return + } + } + } e.printStackTrace() } gameSettings.setSoundLevel(SoundCategory.PLAYERS, oldLevel) -- cgit