diff options
author | nea <romangraef@gmail.com> | 2022-11-13 01:04:59 +0100 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-11-13 01:04:59 +0100 |
commit | 2ba77d7d840b7fecbbf3825e1f507cd408c04f85 (patch) | |
tree | 64d7b515c6b33b57e82f7e47f57824453c8f5238 /src/main/kotlin | |
parent | 1e2c632527715472ff5c4f0be80d330e62691fee (diff) | |
download | neuhax-2ba77d7d840b7fecbbf3825e1f507cd408c04f85.tar.gz neuhax-2ba77d7d840b7fecbbf3825e1f507cd408c04f85.tar.bz2 neuhax-2ba77d7d840b7fecbbf3825e1f507cd408c04f85.zip |
fix crash
Diffstat (limited to 'src/main/kotlin')
4 files changed, 94 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/sky/NEUHax.kt b/src/main/kotlin/moe/nea/sky/NEUHax.kt index b37a619..46d5f88 100644 --- a/src/main/kotlin/moe/nea/sky/NEUHax.kt +++ b/src/main/kotlin/moe/nea/sky/NEUHax.kt @@ -2,6 +2,7 @@ package moe.nea.sky import moe.nea.sky.commands.NEUHaxCommand import moe.nea.sky.features.gui.Enchanting +import moe.nea.sky.features.world.AutoFishing import moe.nea.sky.util.CommandActionRegistry import net.minecraft.launchwrapper.Launch import net.minecraftforge.client.ClientCommandHandler @@ -29,8 +30,9 @@ object NEUHax { @EventHandler fun onInit(event: FMLInitializationEvent) { - listOf<Any>( - Enchanting + listOf( + Enchanting, + AutoFishing, ).forEach { MinecraftForge.EVENT_BUS.register(it) } diff --git a/src/main/kotlin/moe/nea/sky/config/HaxConfigFishing.kt b/src/main/kotlin/moe/nea/sky/config/HaxConfigFishing.kt new file mode 100644 index 0000000..634049b --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/config/HaxConfigFishing.kt @@ -0,0 +1,9 @@ +package moe.nea.sky.config + +interface HaxConfigFishing { + val neuHaxAutoFishEnable: Boolean + // TODO: val neuHaxAutoFishToggleButton: Int + val neuHaxAutoFishDelayMinimum: Int + val neuHaxAutoFishDelayMaximum: Int + val neuHaxReengageFishingRod: Boolean +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/sky/config/HaxConfigWorld.kt b/src/main/kotlin/moe/nea/sky/config/HaxConfigWorld.kt index db9a44d..fd48461 100644 --- a/src/main/kotlin/moe/nea/sky/config/HaxConfigWorld.kt +++ b/src/main/kotlin/moe/nea/sky/config/HaxConfigWorld.kt @@ -1,5 +1,5 @@ package moe.nea.sky.config interface HaxConfigWorld { - var neuHaxMushroomWallhacks: Boolean + var neuHaxWallhacks: Boolean }
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/sky/features/world/AutoFishing.kt b/src/main/kotlin/moe/nea/sky/features/world/AutoFishing.kt new file mode 100644 index 0000000..f3f917c --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/features/world/AutoFishing.kt @@ -0,0 +1,80 @@ +/** + * Copyright (C) 2022 Linnea Gräf + * + * This file is part of NEUHax. + * + * NEUHax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * NEUHax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with NEUHax. If not, see <https://www.gnu.org/licenses/>. + */ +package moe.nea.sky.features.world + +import cc.polyfrost.oneconfig.utils.dsl.mc +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper +import moe.nea.sky.config.HaxConfigFishing +import net.minecraft.entity.projectile.EntityFishHook +import net.minecraft.init.Items +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import kotlin.random.Random + +/** + * Auto Fishing that integrates with NEUs [FishingHelper] to automatically reel in fish. It waits a random, configurable + * amount before each catch and can automatically start fishing again. + * + * **Config**: [moe.nea.sky.mixin.config.MixinHaxConfigFishing] + */ +object AutoFishing { + + val config get() = NotEnoughUpdates.INSTANCE.config.fishing as HaxConfigFishing + + private fun randomDelay() = Random.Default.nextInt( + config.neuHaxAutoFishDelayMinimum, + config.neuHaxAutoFishDelayMaximum.coerceAtLeast(config.neuHaxAutoFishDelayMinimum) + ) + + private var delay = -1 + private var shouldReengage = false + private var lastFishingHook: EntityFishHook? = null + private fun shouldAutoFish(): Boolean { + if (!config.neuHaxAutoFishEnable) + return false + if (delay == 0) { + delay = -1 + return true + } + if (delay < 0) + delay = randomDelay() + delay -= 1 + return false + } + + @SubscribeEvent + fun onTick(ev: TickEvent.ClientTickEvent) { + if (ev.phase != TickEvent.Phase.END) return + val p = mc.thePlayer ?: return + if (shouldReengage) { + if (p.fishEntity == lastFishingHook) return + if (p.fishEntity != null || p.heldItem?.item != Items.fishing_rod) { + shouldReengage = false + delay = -1 + return + } + if (shouldAutoFish()) { + shouldReengage = false + mc.playerController.sendUseItem(p, p.worldObj, p.heldItem) + } + return + } + if (FishingHelper.getInstance().warningState != FishingHelper.PlayerWarningState.FISH_HOOKED) return + if (lastFishingHook != p.fishEntity && shouldAutoFish()) { + mc.playerController.sendUseItem(p, p.worldObj, p.heldItem) + lastFishingHook = p.fishEntity + if (config.neuHaxReengageFishingRod) { + shouldReengage = true + } + } + } + +}
\ No newline at end of file |