From de601769d8a1b5fc7543d5b0b4a95596db926416 Mon Sep 17 00:00:00 2001 From: Appability Date: Sat, 12 Nov 2022 14:35:15 -0800 Subject: placeholder custom end info, farming qol, thunder warning --- .../com/ambientaddons/features/misc/Farming.kt | 85 ++++++++++++++++++++++ .../com/ambientaddons/features/misc/Salvage.kt | 5 ++ .../ambientaddons/features/misc/ThunderWarning.kt | 41 +++++++++++ 3 files changed, 131 insertions(+) create mode 100644 src/main/kotlin/com/ambientaddons/features/misc/ThunderWarning.kt (limited to 'src/main/kotlin/com/ambientaddons/features/misc') diff --git a/src/main/kotlin/com/ambientaddons/features/misc/Farming.kt b/src/main/kotlin/com/ambientaddons/features/misc/Farming.kt index c90de6e..caa1285 100644 --- a/src/main/kotlin/com/ambientaddons/features/misc/Farming.kt +++ b/src/main/kotlin/com/ambientaddons/features/misc/Farming.kt @@ -1,7 +1,92 @@ package com.ambientaddons.features.misc +import AmbientAddons.Companion.config +import AmbientAddons.Companion.mc +import com.ambientaddons.events.HitBlockEvent +import com.ambientaddons.utils.Area +import com.ambientaddons.utils.Extensions.enchants +import com.ambientaddons.utils.Extensions.withModPrefix +import com.ambientaddons.utils.SBLocation +import gg.essential.universal.UChat +import net.minecraft.block.Block +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.util.BlockPos +import net.minecraftforge.client.event.GuiOpenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object Farming { + private val stems: Set = setOf(Blocks.melon_stem, Blocks.pumpkin_stem) + private val crops: Set = setOf(Blocks.wheat, Blocks.carrots, Blocks.potatoes, Blocks.cocoa, Blocks.nether_wart) + private val talls: Set = setOf(Blocks.cactus, Blocks.reeds) + private val shrooms: Set = setOf(Blocks.brown_mushroom, Blocks.red_mushroom) + private val dirts: Set = setOf(Blocks.dirt, Blocks.mycelium) + + private val whitelist = setOf(Items.melon_seeds, Items.pumpkin_seeds) + + private var lastHeldItemIndex = -1 + private var hasReplenish = false + private var nextWarningTime = System.currentTimeMillis() + + @SubscribeEvent + fun onGuiOpen(event: GuiOpenEvent) { + if (!config.farmingBlockMisclicks) return + lastHeldItemIndex = -1 + } + + @SubscribeEvent + fun onBlockHit(event: HitBlockEvent) { + if (!config.farmingBlockMisclicks || SBLocation.area != Area.PrivateIsland) return + val hitBlock = mc.theWorld?.getBlockState(event.blockPos)?.block ?: return + val currentItem = mc.thePlayer?.inventory?.getCurrentItem() + if (currentItem == null || whitelist.contains(currentItem.item)) return + if (lastHeldItemIndex != heldItemIndex) { + hasReplenish = currentItem.enchants?.get("replenish") != null + lastHeldItemIndex = heldItemIndex + } + when { + stems.contains(hitBlock) -> cancelAndWarn(event, "Blocked breaking a stem!") + crops.contains(hitBlock) -> { + if (!hasReplenish) cancelAndWarn(event, "Blocked breaking a crop without Replenish!") + } + talls.contains(hitBlock) -> { + if (mc.theWorld?.getBlockState(event.blockPos.down())?.block != hitBlock) { + cancelAndWarn(event, "Blocked breaking the bottom block of a tall crop!") + } + } + shrooms.contains(hitBlock) -> { + val belowPos = event.blockPos.down() + val nw = isBlockDirt(belowPos.north().west()) + val n = isBlockDirt(belowPos.north()) + val ne = isBlockDirt(belowPos.north().east()) + val sw = isBlockDirt(belowPos.south().west()) + val s = isBlockDirt(belowPos.south()) + val se = isBlockDirt(belowPos.south().east()) + val w = isBlockDirt(belowPos.west()) + val e = isBlockDirt(belowPos.east()) + val isRowNorth = nw && n && ne + val isRowSouth = sw && s && se + val isRowWest = nw && w && sw + val isRowEast = ne && e && se + if (isRowNorth || isRowSouth || isRowWest || isRowEast) { + cancelAndWarn(event, "Blocked breaking a source mushroom!") + } + } + } + } + + private fun isBlockDirt(pos: BlockPos): Boolean = dirts.contains(mc.theWorld?.getBlockState(pos)?.block) + + private fun cancelAndWarn(event: HitBlockEvent, message: String) { + if ((System.currentTimeMillis() - nextWarningTime) >= 0) { + UChat.chat("§c${message}".withModPrefix()) + mc.thePlayer?.playSound("random.pop", 1f, 0f) + nextWarningTime = System.currentTimeMillis() + 500 + } + event.isCanceled = true + } + + private val heldItemIndex: Int + get() = mc.thePlayer?.inventory?.currentItem ?: -1 } \ No newline at end of file diff --git a/src/main/kotlin/com/ambientaddons/features/misc/Salvage.kt b/src/main/kotlin/com/ambientaddons/features/misc/Salvage.kt index 914870f..a1ee583 100644 --- a/src/main/kotlin/com/ambientaddons/features/misc/Salvage.kt +++ b/src/main/kotlin/com/ambientaddons/features/misc/Salvage.kt @@ -8,6 +8,7 @@ import com.ambientaddons.utils.Extensions.itemQuality import com.ambientaddons.utils.Extensions.items import com.ambientaddons.utils.Extensions.skyblockID import com.ambientaddons.utils.Extensions.stars +import com.ambientaddons.utils.SBLocation import com.ambientaddons.utils.SalvageStrategy import com.ambientaddons.utils.render.OverlayUtils import net.minecraft.client.gui.inventory.GuiContainer @@ -30,6 +31,7 @@ object Salvage { @SubscribeEvent fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent) { + if (!SBLocation.inSkyblock) return val chest = event.gui?.chest ?: return if (config.salvageMode < 3 || chest.lowerChestInventory.name != "Salvage Item") return val color = chest.lowerChestInventory.items.last()?.itemDamage @@ -65,12 +67,14 @@ object Salvage { @SubscribeEvent fun onContainerOpen(event: GuiOpenEvent) { + if (!SBLocation.inSkyblock) return if (event.gui?.chest == null) return status = SalvageStatus.Idle } @SubscribeEvent fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!SBLocation.inSkyblock) return if (config.salvageMode < 2 || event.slot == null) return if (!isSlotInInventory(event.gui, event.slot)) return if (status != SalvageStatus.Idle @@ -91,6 +95,7 @@ object Salvage { @SubscribeEvent fun onDrawSlot(event: GuiContainerEvent.DrawSlotEvent) { + if (!SBLocation.inSkyblock) return if (config.salvageMode == 0 || !isSlotInInventory(event.gui, event.slot)) return val color = when (getSalvageStrategy(event.slot.stack ?: return)) { SalvageStrategy.Always -> Color.GREEN diff --git a/src/main/kotlin/com/ambientaddons/features/misc/ThunderWarning.kt b/src/main/kotlin/com/ambientaddons/features/misc/ThunderWarning.kt new file mode 100644 index 0000000..fb16c43 --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/features/misc/ThunderWarning.kt @@ -0,0 +1,41 @@ +package com.ambientaddons.features.misc + +import AmbientAddons.Companion.config +import AmbientAddons.Companion.mc +import com.ambientaddons.utils.Extensions.items +import com.ambientaddons.utils.Extensions.skyblockID +import com.ambientaddons.utils.SBLocation +import gg.essential.universal.UChat +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent + +object ThunderWarning { + private var hadChargedThunderBottle = false + private var ticks = 0 + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent.Load) { + hadChargedThunderBottle = false + } + + @SubscribeEvent + fun onTick(event: ClientTickEvent) { + if (!config.thunderWarning || !SBLocation.inSkyblock || event.phase != TickEvent.Phase.START) return + if (ticks % 10 == 0) { + if (hasChargedThunderBottle() && !hadChargedThunderBottle) { + mc.ingameGUI.displayTitle("§dThunder charged!", null, 5, 40, 5) + mc.ingameGUI.displayTitle(null, "", 5, 40, 5) + mc.ingameGUI.displayTitle(null, null, 5, 40, 5) + mc.thePlayer.playSound("random.orb", 1f, 0.5f) + } + hadChargedThunderBottle = hasChargedThunderBottle() + } + ticks++ + } + + private fun hasChargedThunderBottle(): Boolean = + mc.thePlayer?.inventory?.items?.any { it?.skyblockID == "THUNDER_IN_A_BOTTLE" } == true + +} \ No newline at end of file -- cgit