From 091de91da4df2d9470ef87db33eb34c52d51a8ba Mon Sep 17 00:00:00 2001 From: minecraft-simon Date: Tue, 13 Dec 2022 01:28:06 +0100 Subject: [PATCH 001/104] Added ActivityManager and Activity abstract class --- .../manager/managers/ActivityManager.kt | 29 ++++++++++ .../manager/managers/activities/Activity.kt | 56 +++++++++++++++++++ .../activities/SayAnnoyinglyActivity.kt | 17 ++++++ .../managers/activities/WaitAndSayActivity.kt | 20 +++++++ 4 files changed, 122 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt new file mode 100644 index 000000000..0106733ed --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -0,0 +1,29 @@ +package com.lambda.client.manager.managers + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.Manager +import com.lambda.client.manager.managers.activities.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +object ActivityManager : Manager, Activity() { + init { + safeListener { + if (subActivities.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener + + onTick() + } + } + + override fun SafeClientEvent.initialize(): ActivityStatus { + return ActivityStatus.RUNNING + } + + override fun SafeClientEvent.doTick(): ActivityStatus { + return ActivityStatus.RUNNING + } + + fun addActivity(activity: Activity) { + subActivities.add(activity) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt new file mode 100644 index 000000000..145b7381d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt @@ -0,0 +1,56 @@ +package com.lambda.client.manager.managers.activities + +import com.lambda.client.event.SafeClientEvent +import java.util.concurrent.ConcurrentLinkedDeque + +abstract class Activity { + val subActivities = ConcurrentLinkedDeque() + private var activityStatus = ActivityStatus.UNINITIALIZED + + enum class ActivityStatus { + UNINITIALIZED, + RUNNING, + SUCCESS, + FAILURE + } + + fun SafeClientEvent.onTick() { + when (activityStatus) { + ActivityStatus.UNINITIALIZED -> { + activityStatus = initialize() + } + ActivityStatus.RUNNING -> { + if (subActivities.peek()?.activityStatus == ActivityStatus.SUCCESS) { + subActivities.pop() + } + if (subActivities.isEmpty()) { + activityStatus = doTick() + } else { + with(subActivities.peek()) { + onTick() + } + } + } + ActivityStatus.SUCCESS -> { +// activityStatus = ActivityStatus.UNINITIALIZED +// subActivities.clear() + } + ActivityStatus.FAILURE -> { + activityStatus = ActivityStatus.UNINITIALIZED + subActivities.clear() + } + } + } + + abstract fun SafeClientEvent.initialize(): ActivityStatus + + abstract fun SafeClientEvent.doTick(): ActivityStatus + + private fun currentActivity(): Activity { + return subActivities.peek() ?: this + } + + override fun toString(): String { + return "Current activity: ${currentActivity()::class.simpleName}" + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt new file mode 100644 index 000000000..443469f2d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt @@ -0,0 +1,17 @@ +package com.lambda.client.manager.managers.activities + +import com.lambda.client.event.SafeClientEvent + +class SayAnnoyinglyActivity(private val sayWhat: String): Activity() { + override fun SafeClientEvent.initialize(): ActivityStatus { + sayWhat.split(" ").forEach { + subActivities.add(WaitAndSayActivity(it, System.currentTimeMillis() + 1000)) + } + return ActivityStatus.RUNNING + } + + override fun SafeClientEvent.doTick(): ActivityStatus { + return ActivityStatus.SUCCESS + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt new file mode 100644 index 000000000..b896d78a7 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt @@ -0,0 +1,20 @@ +package com.lambda.client.manager.managers.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.text.MessageSendHelper + +class WaitAndSayActivity(private val sayThis: String, private val waitUntil: Long): Activity() { + override fun SafeClientEvent.initialize(): ActivityStatus { + return ActivityStatus.RUNNING + } + + override fun SafeClientEvent.doTick(): ActivityStatus { + return if (System.currentTimeMillis() > waitUntil) { + MessageSendHelper.sendChatMessage(sayThis) + ActivityStatus.SUCCESS + } else { + ActivityStatus.RUNNING + } + } + +} \ No newline at end of file From e5100caf171865346f2789f71f6ffe152eac53f8 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 13 Dec 2022 19:35:38 +0100 Subject: [PATCH 002/104] More tests --- .../manager/managers/ActivityManager.kt | 15 +++-- ...amiMojiManager.kt => LambdaMojiManager.kt} | 0 .../manager/managers/activities/Activity.kt | 56 ------------------- .../managers/activities/WaitAndSayActivity.kt | 20 ------- .../manager/managers/activity/Activity.kt | 56 +++++++++++++++++++ .../SayAnnoyinglyActivity.kt | 11 +--- .../managers/activity/WaitAndSayActivity.kt | 27 +++++++++ .../activity/activities/AttemptingActivity.kt | 8 +++ .../activity/activities/TimedActivity.kt | 11 ++++ .../module/modules/misc/SayHelloWorld.kt | 18 ++++++ 10 files changed, 130 insertions(+), 92 deletions(-) rename src/main/kotlin/com/lambda/client/manager/managers/{KamiMojiManager.kt => LambdaMojiManager.kt} (100%) delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt rename src/main/kotlin/com/lambda/client/manager/managers/{activities => activity}/SayAnnoyinglyActivity.kt (50%) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 0106733ed..d2fffd358 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,8 +1,9 @@ package com.lambda.client.manager.managers +import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.Manager -import com.lambda.client.manager.managers.activities.Activity +import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent @@ -11,16 +12,14 @@ object ActivityManager : Manager, Activity() { safeListener { if (subActivities.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener - onTick() - } - } + updateActivities() - override fun SafeClientEvent.initialize(): ActivityStatus { - return ActivityStatus.RUNNING + LambdaMod.LOG.error(currentActivity().toString()) + } } - override fun SafeClientEvent.doTick(): ActivityStatus { - return ActivityStatus.RUNNING + override fun SafeClientEvent.initialize() { + activityStatus = ActivityStatus.RUNNING } fun addActivity(activity: Activity) { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/KamiMojiManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/LambdaMojiManager.kt similarity index 100% rename from src/main/kotlin/com/lambda/client/manager/managers/KamiMojiManager.kt rename to src/main/kotlin/com/lambda/client/manager/managers/LambdaMojiManager.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt deleted file mode 100644 index 145b7381d..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activities/Activity.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.lambda.client.manager.managers.activities - -import com.lambda.client.event.SafeClientEvent -import java.util.concurrent.ConcurrentLinkedDeque - -abstract class Activity { - val subActivities = ConcurrentLinkedDeque() - private var activityStatus = ActivityStatus.UNINITIALIZED - - enum class ActivityStatus { - UNINITIALIZED, - RUNNING, - SUCCESS, - FAILURE - } - - fun SafeClientEvent.onTick() { - when (activityStatus) { - ActivityStatus.UNINITIALIZED -> { - activityStatus = initialize() - } - ActivityStatus.RUNNING -> { - if (subActivities.peek()?.activityStatus == ActivityStatus.SUCCESS) { - subActivities.pop() - } - if (subActivities.isEmpty()) { - activityStatus = doTick() - } else { - with(subActivities.peek()) { - onTick() - } - } - } - ActivityStatus.SUCCESS -> { -// activityStatus = ActivityStatus.UNINITIALIZED -// subActivities.clear() - } - ActivityStatus.FAILURE -> { - activityStatus = ActivityStatus.UNINITIALIZED - subActivities.clear() - } - } - } - - abstract fun SafeClientEvent.initialize(): ActivityStatus - - abstract fun SafeClientEvent.doTick(): ActivityStatus - - private fun currentActivity(): Activity { - return subActivities.peek() ?: this - } - - override fun toString(): String { - return "Current activity: ${currentActivity()::class.simpleName}" - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt deleted file mode 100644 index b896d78a7..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activities/WaitAndSayActivity.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.client.manager.managers.activities - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.text.MessageSendHelper - -class WaitAndSayActivity(private val sayThis: String, private val waitUntil: Long): Activity() { - override fun SafeClientEvent.initialize(): ActivityStatus { - return ActivityStatus.RUNNING - } - - override fun SafeClientEvent.doTick(): ActivityStatus { - return if (System.currentTimeMillis() > waitUntil) { - MessageSendHelper.sendChatMessage(sayThis) - ActivityStatus.SUCCESS - } else { - ActivityStatus.RUNNING - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt new file mode 100644 index 000000000..41541a619 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -0,0 +1,56 @@ +package com.lambda.client.manager.managers.activity + +import com.lambda.client.event.LambdaEventBus +import com.lambda.client.event.SafeClientEvent +import java.util.concurrent.ConcurrentLinkedDeque + +abstract class Activity { + val subActivities = ConcurrentLinkedDeque() + var activityStatus = ActivityStatus.UNINITIALIZED + + enum class ActivityStatus { + UNINITIALIZED, + RUNNING, + SUCCESS, + FAILURE + } + + fun SafeClientEvent.updateActivities() { + when (activityStatus) { + ActivityStatus.UNINITIALIZED -> { + initialize() + } + ActivityStatus.RUNNING -> { + subActivities.peek()?.let { + with(it) { + if (it.activityStatus == ActivityStatus.SUCCESS) { + subActivities.pop() +// LambdaEventBus.unsubscribe(it) + } else { + updateActivities() + } + } + } ?: run { +// LambdaEventBus.subscribe(this) + } + } + ActivityStatus.SUCCESS -> { + // do nothing + } + ActivityStatus.FAILURE -> { +// activityStatus = ActivityStatus.UNINITIALIZED +// subActivities.clear() + } + } + } + + abstract fun SafeClientEvent.initialize() + + fun currentActivity(): Activity { + return subActivities.peek() ?: this + } + + override fun toString(): String { + return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt similarity index 50% rename from src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt index 443469f2d..4c9cf24e7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activities/SayAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt @@ -1,17 +1,12 @@ -package com.lambda.client.manager.managers.activities +package com.lambda.client.manager.managers.activity import com.lambda.client.event.SafeClientEvent class SayAnnoyinglyActivity(private val sayWhat: String): Activity() { - override fun SafeClientEvent.initialize(): ActivityStatus { + override fun SafeClientEvent.initialize() { sayWhat.split(" ").forEach { subActivities.add(WaitAndSayActivity(it, System.currentTimeMillis() + 1000)) } - return ActivityStatus.RUNNING + activityStatus = ActivityStatus.RUNNING } - - override fun SafeClientEvent.doTick(): ActivityStatus { - return ActivityStatus.SUCCESS - } - } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt new file mode 100644 index 000000000..3895f9322 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt @@ -0,0 +1,27 @@ +package com.lambda.client.manager.managers.activity + +import com.lambda.client.event.LambdaEventBus +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.text.MessageSendHelper +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +class WaitAndSayActivity(private val sayThis: String, private val waitUntil: Long): Activity() { + override fun SafeClientEvent.initialize() { + activityStatus = ActivityStatus.RUNNING + LambdaEventBus.subscribe(this) + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (System.currentTimeMillis() > waitUntil) { + MessageSendHelper.sendChatMessage(sayThis) + activityStatus = ActivityStatus.SUCCESS + LambdaEventBus.unsubscribe(this) + } + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt new file mode 100644 index 000000000..aae875f8f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt @@ -0,0 +1,8 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity + +class AttemptingActivity(private val attempts: Int) : Activity() { + override fun SafeClientEvent.initialize() {} +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt new file mode 100644 index 000000000..6d28cfe7e --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt @@ -0,0 +1,11 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.manager.managers.activity.Activity + +abstract class TimedActivity(private val maxAgeMilliSec: Long) : Activity() { + private fun checkForTimeout() { + if (System.currentTimeMillis() > maxAgeMilliSec) { + activityStatus = ActivityStatus.FAILURE + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt new file mode 100644 index 000000000..580d10a15 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt @@ -0,0 +1,18 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.activity.SayAnnoyinglyActivity +import com.lambda.client.module.Category +import com.lambda.client.module.Module + +object SayHelloWorld : Module( + name = "SayHelloWorld", + description = "", + category = Category.MISC +) { + init { + onEnable { + ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World!")) + } + } +} From 7fadcd83b424008e40422f98e5c0b310c0a8391c Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 14 Dec 2022 22:33:50 +0100 Subject: [PATCH 003/104] First working activity system with example --- .../manager/managers/ActivityManager.kt | 6 ----- .../manager/managers/activity/Activity.kt | 24 +++++++++++++---- .../activity/SayAnnoyinglyActivity.kt | 12 --------- .../managers/activity/WaitAndSayActivity.kt | 27 ------------------- .../activity/activities/AttemptingActivity.kt | 8 ------ .../activities/SayAnnoyinglyActivity.kt | 12 +++++++++ .../activity/activities/WaitAndSayActivity.kt | 11 ++++++++ .../activity/types/AttemptingActivity.kt | 23 ++++++++++++++++ .../activity/types/DelayedActivity.kt | 27 +++++++++++++++++++ .../activity/types/InstantActivity.kt | 17 ++++++++++++ .../{activities => types}/TimedActivity.kt | 2 +- .../module/modules/misc/SayHelloWorld.kt | 2 +- 12 files changed, 111 insertions(+), 60 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt rename src/main/kotlin/com/lambda/client/manager/managers/activity/{activities => types}/TimedActivity.kt (82%) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index d2fffd358..84598d98e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -13,15 +13,9 @@ object ActivityManager : Manager, Activity() { if (subActivities.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener updateActivities() - - LambdaMod.LOG.error(currentActivity().toString()) } } - override fun SafeClientEvent.initialize() { - activityStatus = ActivityStatus.RUNNING - } - fun addActivity(activity: Activity) { subActivities.add(activity) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 41541a619..0bdd646f4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -1,5 +1,6 @@ package com.lambda.client.manager.managers.activity +import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import java.util.concurrent.ConcurrentLinkedDeque @@ -24,14 +25,11 @@ abstract class Activity { subActivities.peek()?.let { with(it) { if (it.activityStatus == ActivityStatus.SUCCESS) { - subActivities.pop() -// LambdaEventBus.unsubscribe(it) + finalize(this@Activity) } else { updateActivities() } } - } ?: run { -// LambdaEventBus.subscribe(this) } } ActivityStatus.SUCCESS -> { @@ -44,7 +42,23 @@ abstract class Activity { } } - abstract fun SafeClientEvent.initialize() + private fun SafeClientEvent.initialize() { + onInitialize() + activityStatus = ActivityStatus.RUNNING + LambdaEventBus.subscribe(this@Activity) + LambdaMod.LOG.info("Initialized activity: ${this@Activity}") + } + + open fun SafeClientEvent.onInitialize() {} + + private fun SafeClientEvent.finalize(owner: Activity) { + onFinalize() + owner.subActivities.pop() + LambdaEventBus.unsubscribe(this@Activity) + LambdaMod.LOG.info("Finalized activity: ${this@Activity}") + } + + open fun SafeClientEvent.onFinalize() {} fun currentActivity(): Activity { return subActivities.peek() ?: this diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt deleted file mode 100644 index 4c9cf24e7..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/SayAnnoyinglyActivity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lambda.client.manager.managers.activity - -import com.lambda.client.event.SafeClientEvent - -class SayAnnoyinglyActivity(private val sayWhat: String): Activity() { - override fun SafeClientEvent.initialize() { - sayWhat.split(" ").forEach { - subActivities.add(WaitAndSayActivity(it, System.currentTimeMillis() + 1000)) - } - activityStatus = ActivityStatus.RUNNING - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt deleted file mode 100644 index 3895f9322..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/WaitAndSayActivity.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.lambda.client.manager.managers.activity - -import com.lambda.client.event.LambdaEventBus -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.text.MessageSendHelper -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -class WaitAndSayActivity(private val sayThis: String, private val waitUntil: Long): Activity() { - override fun SafeClientEvent.initialize() { - activityStatus = ActivityStatus.RUNNING - LambdaEventBus.subscribe(this) - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - if (System.currentTimeMillis() > waitUntil) { - MessageSendHelper.sendChatMessage(sayThis) - activityStatus = ActivityStatus.SUCCESS - LambdaEventBus.unsubscribe(this) - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt deleted file mode 100644 index aae875f8f..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/AttemptingActivity.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity - -class AttemptingActivity(private val attempts: Int) : Activity() { - override fun SafeClientEvent.initialize() {} -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt new file mode 100644 index 000000000..e0f9b5ca3 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt @@ -0,0 +1,12 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity + +class SayAnnoyinglyActivity(private val sayWhat: String): InstantActivity() { + override fun SafeClientEvent.onInitialize() { + sayWhat.split(" ").forEach { + subActivities.add(WaitAndSayActivity(it, 1000)) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt new file mode 100644 index 000000000..345e1da97 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt @@ -0,0 +1,11 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.DelayedActivity +import com.lambda.client.util.text.MessageSendHelper + +class WaitAndSayActivity(private val sayThis: String, delay: Long): DelayedActivity(delay) { + override fun SafeClientEvent.onDelayedActivity() { + MessageSendHelper.sendChatMessage(sayThis) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt new file mode 100644 index 000000000..f682eecbf --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt @@ -0,0 +1,23 @@ +package com.lambda.client.manager.managers.activity.types + +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +abstract class AttemptingActivity(private val attempts: Int) : Activity() { + private var attempt = 0 + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (attempt >= attempts) { + activityStatus = ActivityStatus.FAILURE + } + } + } + + fun attempt() { + attempt++ + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt new file mode 100644 index 000000000..cfc228ae6 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt @@ -0,0 +1,27 @@ +package com.lambda.client.manager.managers.activity.types + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +abstract class DelayedActivity(private val delay: Long) : Activity() { + private var creationTime = 0L + + override fun SafeClientEvent.onInitialize() { + creationTime = System.currentTimeMillis() + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (System.currentTimeMillis() > creationTime + delay) { + onDelayedActivity() + activityStatus = ActivityStatus.SUCCESS + } + } + } + + abstract fun SafeClientEvent.onDelayedActivity() +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt new file mode 100644 index 000000000..54d1b627b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt @@ -0,0 +1,17 @@ +package com.lambda.client.manager.managers.activity.types + +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +open class InstantActivity : Activity() { + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (subActivities.isEmpty()) { + activityStatus = ActivityStatus.SUCCESS + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt similarity index 82% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt index 6d28cfe7e..34f76fdf0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/TimedActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.manager.managers.activity.activities +package com.lambda.client.manager.managers.activity.types import com.lambda.client.manager.managers.activity.Activity diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt index 580d10a15..59f8e8fca 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt @@ -1,7 +1,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.SayAnnoyinglyActivity +import com.lambda.client.manager.managers.activity.activities.SayAnnoyinglyActivity import com.lambda.client.module.Category import com.lambda.client.module.Module From 3d105f5008fddd96c783ba72f20d583be786b4c0 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 15 Dec 2022 07:49:06 +0100 Subject: [PATCH 004/104] Implemented HUD and InventoryTransactions --- .../elements/misc/ActivityManagerHud.kt | 18 ++++ .../manager/managers/ActivityManager.kt | 2 - .../manager/managers/activity/Activity.kt | 32 +++++- .../activities/SayAnnoyinglyActivity.kt | 12 --- .../activity/activities/WaitAndSayActivity.kt | 11 -- .../example/SayAnnoyinglyActivity.kt | 19 ++++ .../example/SayVeryAnnoyinglyActivity.kt | 19 ++++ .../activities/example/WaitAndSayActivity.kt | 25 +++++ .../inventory/DumpInventoryActivity.kt | 16 +++ .../inventory/InventoryTransactionActivity.kt | 100 ++++++++++++++++++ .../inventory/SwapOrMoveToAnyBlockActivity.kt | 25 +++++ .../inventory/SwapWithSlotActivity.kt | 16 +++ .../inventory/SwitchToHotbarSlotActivity.kt | 12 +++ .../activity/types/DelayedActivity.kt | 4 +- .../managers/activity/types/TimedActivity.kt | 21 +++- .../module/modules/misc/SayHelloWorld.kt | 18 ---- .../modules/misc/TestActivityManager.kt | 34 ++++++ 17 files changed, 334 insertions(+), 50 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt new file mode 100644 index 000000000..ce8d285be --- /dev/null +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -0,0 +1,18 @@ +package com.lambda.client.gui.hudgui.elements.misc + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.LabelHud +import com.lambda.client.manager.managers.ActivityManager + +internal object ActivityManagerHud: LabelHud( + name = "ActivityManager", + category = Category.MISC, + description = "Display current activities." +) { + override fun SafeClientEvent.updateText() { + if (ActivityManager.subActivities.isEmpty()) return + + ActivityManager.appendInfo(displayText, primaryColor, secondaryColor, 0) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 84598d98e..7390565cc 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,7 +1,5 @@ package com.lambda.client.manager.managers -import com.lambda.client.LambdaMod -import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.Manager import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.threads.safeListener diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 0bdd646f4..c525c0f6e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -3,6 +3,10 @@ package com.lambda.client.manager.managers.activity import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.AbstractHudElement +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { @@ -60,11 +64,35 @@ abstract class Activity { open fun SafeClientEvent.onFinalize() {} - fun currentActivity(): Activity { - return subActivities.peek() ?: this + private fun currentActivity(): Activity { + return subActivities.peek()?.currentActivity() ?: this + } + + fun reset() { + LambdaEventBus.unsubscribe(currentActivity()) + subActivities.clear() } override fun toString(): String { return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" } + + open fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) {} + + fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder, depth: Int) { + if (this !is ActivityManager) { + textComponent.add("Name", primaryColor) + textComponent.add("${javaClass.simpleName} ", secondaryColor) + textComponent.add("State", primaryColor) + textComponent.add(activityStatus.name, secondaryColor) + addExtraInfo(textComponent, primaryColor, secondaryColor) + textComponent.addLine("") + } + subActivities.forEach { + repeat(depth) { + textComponent.add(" ") + } + it.appendInfo(textComponent, primaryColor, secondaryColor, depth + 1) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt deleted file mode 100644 index e0f9b5ca3..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SayAnnoyinglyActivity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity - -class SayAnnoyinglyActivity(private val sayWhat: String): InstantActivity() { - override fun SafeClientEvent.onInitialize() { - sayWhat.split(" ").forEach { - subActivities.add(WaitAndSayActivity(it, 1000)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt deleted file mode 100644 index 345e1da97..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/WaitAndSayActivity.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.DelayedActivity -import com.lambda.client.util.text.MessageSendHelper - -class WaitAndSayActivity(private val sayThis: String, delay: Long): DelayedActivity(delay) { - override fun SafeClientEvent.onDelayedActivity() { - MessageSendHelper.sendChatMessage(sayThis) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt new file mode 100644 index 000000000..8a30d80b6 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt @@ -0,0 +1,19 @@ +package com.lambda.client.manager.managers.activity.activities.example + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent + +class SayAnnoyinglyActivity(private val message: String): InstantActivity() { + override fun SafeClientEvent.onInitialize() { + message.split(" ").forEach { + subActivities.add(SayVeryAnnoyinglyActivity(it)) + } + } + + override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + textComponent.add("Message", primaryColor) + textComponent.add(message, secondaryColor) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt new file mode 100644 index 000000000..59f6597d9 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt @@ -0,0 +1,19 @@ +package com.lambda.client.manager.managers.activity.activities.example + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent + +class SayVeryAnnoyinglyActivity(private val message: String): InstantActivity() { + override fun SafeClientEvent.onInitialize() { + message.forEach { + subActivities.add(WaitAndSayActivity(it.toString(), 1000)) + } + } + + override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + textComponent.add("Message", primaryColor) + textComponent.add(message, secondaryColor) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt new file mode 100644 index 000000000..1be81b87f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt @@ -0,0 +1,25 @@ +package com.lambda.client.manager.managers.activity.activities.example + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.DelayedActivity +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.util.text.MessageSendHelper + +class WaitAndSayActivity(private val message: String, delay: Long): DelayedActivity(delay) { + override fun SafeClientEvent.onDelayedActivity() { + MessageSendHelper.sendChatMessage(message) + } + + override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + textComponent.add("Message", primaryColor) + textComponent.add(message, secondaryColor) + textComponent.add("Delay", primaryColor) + textComponent.add(delay.toString(), secondaryColor) + + if (activityStatus == ActivityStatus.RUNNING) { + textComponent.add("Waited", primaryColor) + textComponent.add((System.currentTimeMillis() - creationTime).toString(), secondaryColor) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt new file mode 100644 index 000000000..2378cc763 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt @@ -0,0 +1,16 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.items.allSlots +import net.minecraft.inventory.ClickType + +class DumpInventoryActivity : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + player.allSlots + .filter { it.hasStack } + .forEach { + subActivities.add(InventoryTransactionActivity(0, it.slotNumber, 1, ClickType.THROW)) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt new file mode 100644 index 000000000..1d7d28a16 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt @@ -0,0 +1,100 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.LambdaMod +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.types.TimedActivity +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.util.threads.safeListener +import net.minecraft.inventory.ClickType +import net.minecraft.inventory.Container +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.CPacketClickWindow +import net.minecraft.network.play.server.SPacketConfirmTransaction + +class InventoryTransactionActivity( + val windowId: Int = 0, + val slot: Int, + private val mouseButton: Int = 0, + val type: ClickType +) : Activity() { + private var transactionId: Short = -1 + + override fun SafeClientEvent.onInitialize() { + getContainerOrNull(windowId)?.let { activeContainer -> + player.inventory?.let { inventory -> + transactionId = activeContainer.getNextTransactionID(inventory) + + val itemStack = if (type == ClickType.PICKUP && slot != -999) { + activeContainer.inventorySlots?.getOrNull(slot)?.stack ?: ItemStack.EMPTY + } else { + ItemStack.EMPTY + } + + val packet = CPacketClickWindow( + windowId, + slot, + mouseButton, + type, + itemStack, + transactionId + ) + + connection.sendPacket(packet) + + playerController.updateController() + + LambdaMod.LOG.info("Sent packet: ${packet.javaClass.simpleName}") + } ?: run { + // ToDo: find out if this is possible + } + } ?: run { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("Container outdated. Skipping task. $this") + } + } + + init { + safeListener { + val packet = it.packet + + if (packet !is SPacketConfirmTransaction + || packet.windowId != windowId + || packet.actionNumber != transactionId) return@safeListener + + if (packet.wasAccepted()) { + getContainerOrNull(packet.windowId)?.let { container -> + container.slotClick(slot, mouseButton, type, player) + activityStatus = ActivityStatus.SUCCESS + LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") + } ?: run { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("Container is null") + } + } else { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("Denied packet: ${it.packet.javaClass.simpleName} $transactionId") + } + } + } + + private fun SafeClientEvent.getContainerOrNull(windowId: Int): Container? = + if (windowId == player.openContainer.windowId) { + player.openContainer + } else { + null + } + + override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + textComponent.add("WindowID", primaryColor) + textComponent.add(windowId.toString(), secondaryColor) + textComponent.add("Slot", primaryColor) + textComponent.add(slot.toString(), secondaryColor) + textComponent.add("MouseButton", primaryColor) + textComponent.add(mouseButton.toString(), secondaryColor) + textComponent.add("ClickType", primaryColor) + textComponent.add(type.name, secondaryColor) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt new file mode 100644 index 000000000..ccc358f8f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt @@ -0,0 +1,25 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.items.* +import net.minecraft.inventory.Slot +import net.minecraft.item.ItemBlock +import net.minecraft.item.ItemStack + +class SwapOrMoveToAnyBlockActivity( + private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true } +) : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + player.hotbarSlots.firstItem(predicateItem)?.let { + subActivities.add(SwitchToHotbarSlotActivity(it.hotbarSlot)) + } ?: run { + player.inventorySlots.firstItem(predicateItem)?.let { + val hotbarSlot = player.hotbarSlots.firstEmpty() ?: return@run + subActivities.add(SwapWithSlotActivity(it, hotbarSlot)) + subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt new file mode 100644 index 000000000..9a9c9eda7 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt @@ -0,0 +1,16 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.items.HotbarSlot +import net.minecraft.inventory.ClickType +import net.minecraft.inventory.Slot + +class SwapWithSlotActivity( + private val slotFrom: Slot, + private val slotTo: HotbarSlot +) : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + subActivities.add(InventoryTransactionActivity(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt new file mode 100644 index 000000000..8476a2599 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt @@ -0,0 +1,12 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity + +class SwitchToHotbarSlotActivity(private val slot: Int) : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + if (slot !in 0..8) return + player.inventory.currentItem = slot + playerController.updateController() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt index cfc228ae6..3e0c8f118 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt @@ -5,8 +5,8 @@ import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent -abstract class DelayedActivity(private val delay: Long) : Activity() { - private var creationTime = 0L +abstract class DelayedActivity(val delay: Long) : Activity() { + var creationTime = 0L override fun SafeClientEvent.onInitialize() { creationTime = System.currentTimeMillis() diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt index 34f76fdf0..d90b743cf 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt @@ -1,11 +1,26 @@ package com.lambda.client.manager.managers.activity.types +import com.lambda.client.LambdaMod +import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent abstract class TimedActivity(private val maxAgeMilliSec: Long) : Activity() { - private fun checkForTimeout() { - if (System.currentTimeMillis() > maxAgeMilliSec) { - activityStatus = ActivityStatus.FAILURE + private var creationTime = 0L + + override fun SafeClientEvent.onInitialize() { + creationTime = System.currentTimeMillis() + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (System.currentTimeMillis() > creationTime + maxAgeMilliSec) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("TimedActivity timed out!") + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt deleted file mode 100644 index 59f8e8fca..000000000 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SayHelloWorld.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.lambda.client.module.modules.misc - -import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.activities.SayAnnoyinglyActivity -import com.lambda.client.module.Category -import com.lambda.client.module.Module - -object SayHelloWorld : Module( - name = "SayHelloWorld", - description = "", - category = Category.MISC -) { - init { - onEnable { - ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World!")) - } - } -} diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt new file mode 100644 index 000000000..35de6a281 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -0,0 +1,34 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity +import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToAnyBlockActivity +import com.lambda.client.module.Category +import com.lambda.client.module.Module + +object TestActivityManager : Module( + name = "TestActivityManager", + description = "", + category = Category.MISC +) { + private val getBlock by setting("Get Block", false, consumer = { _, _-> + ActivityManager.addActivity(SwapOrMoveToAnyBlockActivity()) + false + }) + + private val dumpInventoryActivity by setting("Dump Inventory", false, consumer = { _, _-> + ActivityManager.addActivity(DumpInventoryActivity()) + false + }) + + private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> + ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World")) + false + }) + + private val reset by setting("Reset", false, consumer = { _, _-> + ActivityManager.reset() + false + }) +} From ba0d1ec17d4bc8f9ab6042aa01865899588b0d17 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 15 Dec 2022 21:00:50 +0100 Subject: [PATCH 005/104] Generic info gather --- .../manager/managers/activity/Activity.kt | 14 ++++++++++++-- .../example/SayAnnoyinglyActivity.kt | 5 ----- .../example/SayVeryAnnoyinglyActivity.kt | 5 ----- .../activities/example/WaitAndSayActivity.kt | 14 -------------- .../inventory/DumpInventoryActivity.kt | 3 +-- .../activities/inventory/DumpSlotActivity.kt | 18 ++++++++++++++++++ .../inventory/InventoryTransactionActivity.kt | 14 -------------- .../inventory/SwapOrMoveToAnyBlockActivity.kt | 4 ++++ 8 files changed, 35 insertions(+), 42 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index c525c0f6e..d10ae4783 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -3,10 +3,10 @@ package com.lambda.client.manager.managers.activity import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent -import com.lambda.client.gui.hudgui.AbstractHudElement import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { @@ -73,6 +73,10 @@ abstract class Activity { subActivities.clear() } + inline fun addSubActivity(block: () -> Activity) { + subActivities.add(block()) + } + override fun toString(): String { return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" } @@ -85,7 +89,13 @@ abstract class Activity { textComponent.add("${javaClass.simpleName} ", secondaryColor) textComponent.add("State", primaryColor) textComponent.add(activityStatus.name, secondaryColor) - addExtraInfo(textComponent, primaryColor, secondaryColor) + this::class.java.declaredFields.forEach { + it.isAccessible = true + val name = it.name + val value = it.get(this) + textComponent.add(name.capitalize(), primaryColor) + textComponent.add(value.toString(), secondaryColor) + } textComponent.addLine("") } subActivities.forEach { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt index 8a30d80b6..0e6e4caa3 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt @@ -11,9 +11,4 @@ class SayAnnoyinglyActivity(private val message: String): InstantActivity() { subActivities.add(SayVeryAnnoyinglyActivity(it)) } } - - override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { - textComponent.add("Message", primaryColor) - textComponent.add(message, secondaryColor) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt index 59f6597d9..282cd146c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt @@ -11,9 +11,4 @@ class SayVeryAnnoyinglyActivity(private val message: String): InstantActivity() subActivities.add(WaitAndSayActivity(it.toString(), 1000)) } } - - override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { - textComponent.add("Message", primaryColor) - textComponent.add(message, secondaryColor) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt index 1be81b87f..2c0ce954e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt @@ -2,24 +2,10 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.types.DelayedActivity -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper class WaitAndSayActivity(private val message: String, delay: Long): DelayedActivity(delay) { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) } - - override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { - textComponent.add("Message", primaryColor) - textComponent.add(message, secondaryColor) - textComponent.add("Delay", primaryColor) - textComponent.add(delay.toString(), secondaryColor) - - if (activityStatus == ActivityStatus.RUNNING) { - textComponent.add("Waited", primaryColor) - textComponent.add((System.currentTimeMillis() - creationTime).toString(), secondaryColor) - } - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt index 2378cc763..ac7561076 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt @@ -3,14 +3,13 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.types.InstantActivity import com.lambda.client.util.items.allSlots -import net.minecraft.inventory.ClickType class DumpInventoryActivity : InstantActivity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } .forEach { - subActivities.add(InventoryTransactionActivity(0, it.slotNumber, 1, ClickType.THROW)) + subActivities.add(DumpSlotActivity(it, 0)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt new file mode 100644 index 000000000..b1015b868 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt @@ -0,0 +1,18 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import net.minecraft.inventory.ClickType +import net.minecraft.inventory.Slot + +class DumpSlotActivity(private val slot: Slot, private val amount: Int) : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + if (slot.stack.count > amount || amount == 0) { + subActivities.add(InventoryTransactionActivity(0, slot.slotIndex, 1, ClickType.THROW)) + } else { + repeat(amount) { + subActivities.add(InventoryTransactionActivity(0, slot.slotNumber, 0, ClickType.THROW)) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt index 1d7d28a16..29d3a9e96 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt @@ -4,9 +4,6 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.types.TimedActivity -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.threads.safeListener import net.minecraft.inventory.ClickType import net.minecraft.inventory.Container @@ -86,15 +83,4 @@ class InventoryTransactionActivity( } else { null } - - override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { - textComponent.add("WindowID", primaryColor) - textComponent.add(windowId.toString(), secondaryColor) - textComponent.add("Slot", primaryColor) - textComponent.add(slot.toString(), secondaryColor) - textComponent.add("MouseButton", primaryColor) - textComponent.add(mouseButton.toString(), secondaryColor) - textComponent.add("ClickType", primaryColor) - textComponent.add(type.name, secondaryColor) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt index ccc358f8f..f1b47f373 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt @@ -19,6 +19,10 @@ class SwapOrMoveToAnyBlockActivity( val hotbarSlot = player.hotbarSlots.firstEmpty() ?: return@run subActivities.add(SwapWithSlotActivity(it, hotbarSlot)) subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) +// addSubActivity { +// SwapWithSlotActivity(it, hotbarSlot) +// SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot) +// } } } } From b95badf4a6fd2899b5dcb67ccf3addf467683796 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 15 Dec 2022 22:14:20 +0100 Subject: [PATCH 006/104] Inventory stuff --- .../interaction/PlaceBlockActivity.kt | 7 ++++ .../inventory/DumpInventoryActivity.kt | 4 +-- .../inventory/SwapOrMoveToAnyBlockActivity.kt | 29 ----------------- .../inventory/SwapOrMoveToItemActivity.kt | 32 +++++++++++++++++++ .../modules/misc/TestActivityManager.kt | 32 +++++++++++++++++-- 5 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt new file mode 100644 index 000000000..1623b85c5 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -0,0 +1,7 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.manager.managers.activity.Activity + +class PlaceBlockActivity : Activity() { + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt index ac7561076..3f006bc0c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt @@ -4,12 +4,12 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.types.InstantActivity import com.lambda.client.util.items.allSlots -class DumpInventoryActivity : InstantActivity() { +class DumpInventoryActivity(private val amount: Int = 0) : InstantActivity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } .forEach { - subActivities.add(DumpSlotActivity(it, 0)) + subActivities.add(DumpSlotActivity(it, amount)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt deleted file mode 100644 index f1b47f373..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToAnyBlockActivity.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities.inventory - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity -import com.lambda.client.util.items.* -import net.minecraft.inventory.Slot -import net.minecraft.item.ItemBlock -import net.minecraft.item.ItemStack - -class SwapOrMoveToAnyBlockActivity( - private val predicateItem: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true } -) : InstantActivity() { - override fun SafeClientEvent.onInitialize() { - player.hotbarSlots.firstItem(predicateItem)?.let { - subActivities.add(SwitchToHotbarSlotActivity(it.hotbarSlot)) - } ?: run { - player.inventorySlots.firstItem(predicateItem)?.let { - val hotbarSlot = player.hotbarSlots.firstEmpty() ?: return@run - subActivities.add(SwapWithSlotActivity(it, hotbarSlot)) - subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) -// addSubActivity { -// SwapWithSlotActivity(it, hotbarSlot) -// SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot) -// } - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt new file mode 100644 index 000000000..492270c17 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt @@ -0,0 +1,32 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.items.* +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class SwapOrMoveToItemActivity( + private val item: Item, + private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true } +) : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + player.hotbarSlots.firstOrNull { hotbarSlot -> + hotbarSlot.stack.item.id == item.id && predicateItem(hotbarSlot.stack) + }?.let { hotbarSlot -> + subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) + } ?: run { + player.storageSlots.firstOrNull { slot -> + slot.stack.item.id == item.id && predicateItem(slot.stack) + }?.let { slotFrom -> + val hotbarSlots = player.hotbarSlots + val slotTo = hotbarSlots.firstEmpty() + ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return + + subActivities.add(SwapWithSlotActivity(slotFrom, slotTo)) + subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 35de6a281..9a419f32e 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -3,17 +3,38 @@ package com.lambda.client.module.modules.misc import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToAnyBlockActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.util.items.block +import net.minecraft.block.BlockShulkerBox +import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.init.Enchantments +import net.minecraft.init.Items object TestActivityManager : Module( name = "TestActivityManager", description = "", category = Category.MISC ) { - private val getBlock by setting("Get Block", false, consumer = { _, _-> - ActivityManager.addActivity(SwapOrMoveToAnyBlockActivity()) + private val a by setting("Get Dia Pickaxe", false, consumer = { _, _-> + ActivityManager.addActivity(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) + false + }) + + private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> + ActivityManager.addActivity( + SwapOrMoveToItemActivity( + Items.DIAMOND_PICKAXE, + predicateItem = { + EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 + }, + predicateSlot = { + val item = it.item + item != Items.DIAMOND_PICKAXE && item.block !is BlockShulkerBox + } + ) + ) false }) @@ -22,6 +43,11 @@ object TestActivityManager : Module( false }) + private val onlyOne by setting("Dump only one Inventory", false, consumer = { _, _-> + ActivityManager.addActivity(DumpInventoryActivity(1)) + false + }) + private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World")) false From d16fee7bc9e3eebaf57bfff79a55998280d23f06 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 16 Dec 2022 00:40:14 +0100 Subject: [PATCH 007/104] PlaceBlockActivity and type tests --- .../manager/managers/PlayerPacketManager.kt | 6 +-- .../manager/managers/activity/Activity.kt | 11 ++++ .../interaction/OpenContainerActivity.kt | 4 ++ .../interaction/PlaceBlockAHeadActivity.kt | 19 +++++++ .../interaction/PlaceBlockActivity.kt | 52 ++++++++++++++++++- .../activity/types/TimeoutActivity.kt | 6 +++ .../modules/misc/TestActivityManager.kt | 6 +++ 7 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt index 7a27dcda5..7cfcc6c34 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt @@ -19,7 +19,7 @@ import java.util.* object PlayerPacketManager : Manager { /** TreeMap for all packets to be sent, sorted by their callers' priority */ - private val packetMap = TreeMap(compareByDescending { it.modulePriority }) + private val packetMap = TreeMap() var serverSidePosition: Vec3d = Vec3d.ZERO; private set var prevServerSidePosition: Vec3d = Vec3d.ZERO; private set @@ -80,13 +80,13 @@ object PlayerPacketManager : Manager { } } - inline fun AbstractModule.sendPlayerPacket(block: Packet.Builder.() -> Unit) { + inline fun Any.sendPlayerPacket(block: Packet.Builder.() -> Unit) { Packet.Builder().apply(block).build()?.let { sendPlayerPacket(it) } } - fun AbstractModule.sendPlayerPacket(packet: Packet) { + fun Any.sendPlayerPacket(packet: Packet) { packetMap[this] = packet } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index d10ae4783..44a2ffae4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.activity.types.TimeoutActivity import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize @@ -34,6 +35,13 @@ abstract class Activity { updateActivities() } } + } ?: run { + if (this@Activity is TimeoutActivity) { + if (System.currentTimeMillis() > creationTime + timeout) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("TimedActivity timed out!") + } + } } } ActivityStatus.SUCCESS -> { @@ -47,6 +55,9 @@ abstract class Activity { } private fun SafeClientEvent.initialize() { + if (this@Activity is TimeoutActivity) { + creationTime = System.currentTimeMillis() + } onInitialize() activityStatus = ActivityStatus.RUNNING LambdaEventBus.subscribe(this@Activity) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt new file mode 100644 index 000000000..e874710fc --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt @@ -0,0 +1,4 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +class OpenContainerActivity { +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt new file mode 100644 index 000000000..41ddaf834 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt @@ -0,0 +1,19 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.math.Direction +import net.minecraft.init.Blocks +import net.minecraft.util.math.BlockPos + +class PlaceBlockAHeadActivity : InstantActivity() { + override fun SafeClientEvent.onInitialize() { + subActivities.add( + PlaceBlockActivity( + BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), + Blocks.OBSIDIAN + ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index 1623b85c5..787024810 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -1,7 +1,57 @@ package com.lambda.client.manager.managers.activity.activities.interaction +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.types.TimeoutActivity +import com.lambda.client.util.items.blockBlacklist +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getNeighbour +import com.lambda.client.util.world.toPlacePacket +import net.minecraft.block.Block +import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.client.CPacketPlayer +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumHand +import net.minecraft.util.math.BlockPos -class PlaceBlockActivity : Activity() { +class PlaceBlockActivity( + private val blockPos: BlockPos, + private val block: Block, + override val timeout: Long = 1000L, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + getNeighbour(blockPos)?.let { + val currentBlock = world.getBlockState(it.pos).block + if (currentBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + + val rotation = getRotationTo(it.hitVec) + + connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) + connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) + player.swingArm(EnumHand.MAIN_HAND) + + if (currentBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + } ?: run { + activityStatus = ActivityStatus.FAILURE + } + } + + init { + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == block + ) { + activityStatus = ActivityStatus.SUCCESS + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt new file mode 100644 index 000000000..2ba0c4a81 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt @@ -0,0 +1,6 @@ +package com.lambda.client.manager.managers.activity.types + +interface TimeoutActivity { + val timeout: Long + var creationTime: Long +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 9a419f32e..38b8e4486 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -2,6 +2,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity +import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockAHeadActivity import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity import com.lambda.client.module.Category @@ -48,6 +49,11 @@ object TestActivityManager : Module( false }) + private val place by setting("PlaceAhed", false, consumer = { _, _-> + ActivityManager.addActivity(PlaceBlockAHeadActivity()) + false + }) + private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World")) false From fc26aeb9e883bb6f547965b7852096704b238c44 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 16 Dec 2022 01:18:02 +0100 Subject: [PATCH 008/104] Multi types using interfaces --- .../manager/managers/activity/Activity.kt | 36 +++++++++++++++++-- .../activity/activities/ActivityTypes.kt | 22 ++++++++++++ .../example/SayAnnoyinglyActivity.kt | 7 ++-- .../example/SayVeryAnnoyinglyActivity.kt | 7 ++-- .../activities/example/WaitAndSayActivity.kt | 9 +++-- .../interaction/PlaceBlockAHeadActivity.kt | 5 +-- .../interaction/PlaceBlockActivity.kt | 11 +++--- .../inventory/DumpInventoryActivity.kt | 5 +-- .../activities/inventory/DumpSlotActivity.kt | 5 +-- .../inventory/InventoryTransactionActivity.kt | 7 ++-- .../inventory/SwapOrMoveToItemActivity.kt | 5 +-- .../inventory/SwapWithSlotActivity.kt | 5 +-- .../inventory/SwitchToHotbarSlotActivity.kt | 5 +-- .../activity/types/AttemptingActivity.kt | 23 ------------ .../activity/types/DelayedActivity.kt | 27 -------------- .../activity/types/InstantActivity.kt | 17 --------- .../managers/activity/types/TimedActivity.kt | 26 -------------- .../activity/types/TimeoutActivity.kt | 6 ---- 18 files changed, 99 insertions(+), 129 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 44a2ffae4..6078f2523 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -4,7 +4,10 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.types.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.AttemptActivity +import com.lambda.client.manager.managers.activity.activities.DelayedActivity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize @@ -38,8 +41,34 @@ abstract class Activity { } ?: run { if (this@Activity is TimeoutActivity) { if (System.currentTimeMillis() > creationTime + timeout) { + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("TimedActivity fully timed out!") + } else { + usedAttempts++ + initialize() + LambdaMod.LOG.error("TimedActivity timed out!") + } + } else { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("TimedActivity fully timed out!") + } + } + } + if (this@Activity is InstantActivity) { + activityStatus = ActivityStatus.SUCCESS + } + if (this@Activity is DelayedActivity) { + if (System.currentTimeMillis() > creationTime + delay) { + onDelayedActivity() + activityStatus = ActivityStatus.SUCCESS + } + } + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("TimedActivity timed out!") + LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") } } } @@ -58,6 +87,9 @@ abstract class Activity { if (this@Activity is TimeoutActivity) { creationTime = System.currentTimeMillis() } + if (this@Activity is DelayedActivity) { + creationTime = System.currentTimeMillis() + } onInitialize() activityStatus = ActivityStatus.RUNNING LambdaEventBus.subscribe(this@Activity) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt new file mode 100644 index 000000000..e9a2ac591 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt @@ -0,0 +1,22 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent + +interface TimeoutActivity { + val timeout: Long + var creationTime: Long +} + +interface InstantActivity + +interface DelayedActivity { + val delay: Long + var creationTime: Long + + fun SafeClientEvent.onDelayedActivity() +} + +interface AttemptActivity { + val maxAttempts: Int + var usedAttempts: Int +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt index 0e6e4caa3..f1072d1c3 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt @@ -1,11 +1,10 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity -class SayAnnoyinglyActivity(private val message: String): InstantActivity() { +class SayAnnoyinglyActivity(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.split(" ").forEach { subActivities.add(SayVeryAnnoyinglyActivity(it)) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt index 282cd146c..743cc26ee 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt @@ -1,11 +1,10 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity -class SayVeryAnnoyinglyActivity(private val message: String): InstantActivity() { +class SayVeryAnnoyinglyActivity(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.forEach { subActivities.add(WaitAndSayActivity(it.toString(), 1000)) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt index 2c0ce954e..44aa693a8 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt @@ -1,10 +1,15 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.DelayedActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.DelayedActivity import com.lambda.client.util.text.MessageSendHelper -class WaitAndSayActivity(private val message: String, delay: Long): DelayedActivity(delay) { +class WaitAndSayActivity( + private val message: String, + override val delay: Long = 1000L, + override var creationTime: Long = 0L +): DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt index 41ddaf834..64ebc5c4f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt @@ -1,13 +1,14 @@ package com.lambda.client.manager.managers.activity.activities.interaction import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos -class PlaceBlockAHeadActivity : InstantActivity() { +class PlaceBlockAHeadActivity : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { subActivities.add( PlaceBlockActivity( diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index 787024810..f96d175a5 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -3,7 +3,8 @@ package com.lambda.client.manager.managers.activity.activities.interaction import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.types.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.AttemptActivity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.threads.safeListener @@ -19,9 +20,11 @@ import net.minecraft.util.math.BlockPos class PlaceBlockActivity( private val blockPos: BlockPos, private val block: Block, - override val timeout: Long = 1000L, - override var creationTime: Long = 0L -) : TimeoutActivity, Activity() { + override val timeout: Long = 10000L, + override var creationTime: Long = 0L, + override val maxAttempts: Int = 5, + override var usedAttempts: Int = 0 +) : TimeoutActivity, AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos)?.let { val currentBlock = world.getBlockState(it.pos).block diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt index 3f006bc0c..b07dc23fe 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt @@ -1,10 +1,11 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.allSlots -class DumpInventoryActivity(private val amount: Int = 0) : InstantActivity() { +class DumpInventoryActivity(private val amount: Int = 0) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt index b1015b868..28bc80804 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt @@ -1,11 +1,12 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot -class DumpSlotActivity(private val slot: Slot, private val amount: Int) : InstantActivity() { +class DumpSlotActivity(private val slot: Slot, private val amount: Int) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { if (slot.stack.count > amount || amount == 0) { subActivities.add(InventoryTransactionActivity(0, slot.slotIndex, 1, ClickType.THROW)) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt index 29d3a9e96..7cc386493 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.threads.safeListener import net.minecraft.inventory.ClickType import net.minecraft.inventory.Container @@ -15,8 +16,10 @@ class InventoryTransactionActivity( val windowId: Int = 0, val slot: Int, private val mouseButton: Int = 0, - val type: ClickType -) : Activity() { + val type: ClickType, + override val timeout: Long = 1000L, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { private var transactionId: Short = -1 override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt index 492270c17..05d564540 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt @@ -1,7 +1,8 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.* import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -10,7 +11,7 @@ class SwapOrMoveToItemActivity( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true } -) : InstantActivity() { +) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { hotbarSlot -> hotbarSlot.stack.item.id == item.id && predicateItem(hotbarSlot.stack) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt index 9a9c9eda7..4cb451937 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt @@ -1,7 +1,8 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot @@ -9,7 +10,7 @@ import net.minecraft.inventory.Slot class SwapWithSlotActivity( private val slotFrom: Slot, private val slotTo: HotbarSlot -) : InstantActivity() { +) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { subActivities.add(InventoryTransactionActivity(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt index 8476a2599..f1a9fb60b 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt @@ -1,9 +1,10 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.types.InstantActivity +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity -class SwitchToHotbarSlotActivity(private val slot: Int) : InstantActivity() { +class SwitchToHotbarSlotActivity(private val slot: Int) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { if (slot !in 0..8) return player.inventory.currentItem = slot diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt deleted file mode 100644 index f682eecbf..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/AttemptingActivity.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.lambda.client.manager.managers.activity.types - -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -abstract class AttemptingActivity(private val attempts: Int) : Activity() { - private var attempt = 0 - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - if (attempt >= attempts) { - activityStatus = ActivityStatus.FAILURE - } - } - } - - fun attempt() { - attempt++ - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt deleted file mode 100644 index 3e0c8f118..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/DelayedActivity.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.lambda.client.manager.managers.activity.types - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -abstract class DelayedActivity(val delay: Long) : Activity() { - var creationTime = 0L - - override fun SafeClientEvent.onInitialize() { - creationTime = System.currentTimeMillis() - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - if (System.currentTimeMillis() > creationTime + delay) { - onDelayedActivity() - activityStatus = ActivityStatus.SUCCESS - } - } - } - - abstract fun SafeClientEvent.onDelayedActivity() -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt deleted file mode 100644 index 54d1b627b..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/InstantActivity.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.lambda.client.manager.managers.activity.types - -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -open class InstantActivity : Activity() { - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - if (subActivities.isEmpty()) { - activityStatus = ActivityStatus.SUCCESS - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt deleted file mode 100644 index d90b743cf..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimedActivity.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.lambda.client.manager.managers.activity.types - -import com.lambda.client.LambdaMod -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -abstract class TimedActivity(private val maxAgeMilliSec: Long) : Activity() { - private var creationTime = 0L - - override fun SafeClientEvent.onInitialize() { - creationTime = System.currentTimeMillis() - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - if (System.currentTimeMillis() > creationTime + maxAgeMilliSec) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("TimedActivity timed out!") - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt deleted file mode 100644 index 2ba0c4a81..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/types/TimeoutActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.lambda.client.manager.managers.activity.types - -interface TimeoutActivity { - val timeout: Long - var creationTime: Long -} \ No newline at end of file From 073c78dab47cb9c9ee8eaacde6baf42922d873ee Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 16 Dec 2022 01:40:30 +0100 Subject: [PATCH 009/104] Added render block interface --- .../client/manager/managers/ActivityManager.kt | 17 +++++++++++++++++ .../manager/managers/activity/Activity.kt | 7 ++----- .../activity/activities/ActivityTypes.kt | 7 +++++++ .../interaction/PlaceBlockActivity.kt | 10 +++++++--- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 7390565cc..3e70dbe29 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,17 +1,34 @@ package com.lambda.client.manager.managers +import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity +import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { + private val renderer = ESPRenderer() + init { safeListener { if (subActivities.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener updateActivities() } + + safeListener { + val currentActivity = currentActivity() + + if (currentActivity !is RenderBlockActivity) return@safeListener + + renderer.aFilled = 26 + renderer.aOutline = 91 + renderer.thickness = 2.0f + renderer.add(currentActivity.renderBlockPos, currentActivity.color) + renderer.render(true) + } } fun addActivity(activity: Activity) { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 6078f2523..815896253 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -4,10 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.activities.AttemptActivity -import com.lambda.client.manager.managers.activity.activities.DelayedActivity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.* import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize @@ -107,7 +104,7 @@ abstract class Activity { open fun SafeClientEvent.onFinalize() {} - private fun currentActivity(): Activity { + fun currentActivity(): Activity { return subActivities.peek()?.currentActivity() ?: this } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt index e9a2ac591..f44df8276 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt @@ -1,6 +1,8 @@ package com.lambda.client.manager.managers.activity.activities import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.color.ColorHolder +import net.minecraft.util.math.BlockPos interface TimeoutActivity { val timeout: Long @@ -19,4 +21,9 @@ interface DelayedActivity { interface AttemptActivity { val maxAttempts: Int var usedAttempts: Int +} + +interface RenderBlockActivity { + var renderBlockPos: BlockPos + var color: ColorHolder } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index f96d175a5..fae0dfe92 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -4,7 +4,9 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.AttemptActivity +import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.threads.safeListener @@ -23,10 +25,12 @@ class PlaceBlockActivity( override val timeout: Long = 10000L, override var creationTime: Long = 0L, override val maxAttempts: Int = 5, - override var usedAttempts: Int = 0 -) : TimeoutActivity, AttemptActivity, Activity() { + override var usedAttempts: Int = 0, + override var renderBlockPos: BlockPos = blockPos, + override var color: ColorHolder = ColorHolder(35, 188, 254) +) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { override fun SafeClientEvent.onInitialize() { - getNeighbour(blockPos)?.let { + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { val currentBlock = world.getBlockState(it.pos).block if (currentBlock in blockBlacklist) { From d0066f81865793b1808bb97f457feac0be9aadc3 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 16 Dec 2022 08:00:39 +0100 Subject: [PATCH 010/104] Added BreakBlockActivity and some sketches --- .../manager/managers/ActivityManager.kt | 4 + .../manager/managers/activity/Activity.kt | 26 +++--- .../activity/activities/ActivityTypes.kt | 11 +++ .../interaction/BreakBlockActivity.kt | 80 +++++++++++++++++++ .../interaction/PlaceAndBreakBlockActivity.kt | 26 ++++++ .../interaction/PlaceBlockAHeadActivity.kt | 20 ----- .../interaction/PlaceBlockActivity.kt | 33 ++++++-- .../inventory/DumpInventoryActivity.kt | 4 +- .../activities/inventory/DumpSlotActivity.kt | 10 +-- .../inventory/InventoryTransactionActivity.kt | 9 ++- .../inventory/SwapHotbarSlotsActivity.kt | 16 ++++ .../modules/misc/TestActivityManager.kt | 24 ++++-- 12 files changed, 207 insertions(+), 56 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 3e70dbe29..a90ec7791 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -34,4 +34,8 @@ object ActivityManager : Manager, Activity() { fun addActivity(activity: Activity) { subActivities.add(activity) } + + fun addAllActivities(activity: List) { + subActivities.addAll(activity) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 815896253..4abc3b247 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -5,6 +5,7 @@ import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.activities.* +import com.lambda.client.manager.managers.activity.activities.AttemptActivity.Companion.doCheck import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize @@ -29,10 +30,17 @@ abstract class Activity { ActivityStatus.RUNNING -> { subActivities.peek()?.let { with(it) { - if (it.activityStatus == ActivityStatus.SUCCESS) { - finalize(this@Activity) - } else { - updateActivities() + when (it.activityStatus) { + ActivityStatus.SUCCESS -> { + finalize(this@Activity) + } + ActivityStatus.FAILURE -> { + subActivities.remove(it) + LambdaMod.LOG.error("Activity failed: $it") + } + else -> { + updateActivities() + } } } } ?: run { @@ -62,20 +70,14 @@ abstract class Activity { activityStatus = ActivityStatus.SUCCESS } } - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") - } - } + (this@Activity as? AttemptActivity)?.doCheck() } } ActivityStatus.SUCCESS -> { // do nothing } ActivityStatus.FAILURE -> { -// activityStatus = ActivityStatus.UNINITIALIZED -// subActivities.clear() + finalize(this@Activity) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt index f44df8276..c2ff89b78 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt @@ -1,6 +1,8 @@ package com.lambda.client.manager.managers.activity.activities +import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.color.ColorHolder import net.minecraft.util.math.BlockPos @@ -21,6 +23,15 @@ interface DelayedActivity { interface AttemptActivity { val maxAttempts: Int var usedAttempts: Int + + companion object { + fun T.doCheck() { + if (usedAttempts >= maxAttempts) { + (this as? Activity)?.activityStatus = Activity.ActivityStatus.FAILURE + LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") + } + } + } } interface RenderBlockActivity { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt new file mode 100644 index 000000000..f687d5e5c --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt @@ -0,0 +1,80 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.AttemptActivity +import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getHitVec +import com.lambda.client.util.world.getMiningSide +import net.minecraft.init.Blocks +import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumHand +import net.minecraft.util.SoundCategory +import net.minecraft.util.math.BlockPos +import kotlin.math.ceil + +class BreakBlockActivity( + private val blockPos: BlockPos, + private val playSound: Boolean = true, + private val miningSpeedFactor: Float = 1.0f, + override val timeout: Long = 500L, + override var creationTime: Long = 0L, + override val maxAttempts: Int = 8, + override var usedAttempts: Int = 0, + override var renderBlockPos: BlockPos = blockPos, + override var color: ColorHolder = ColorHolder(0, 0, 0) +) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { + private var ticksNeeded = 0 + private var currentState = Blocks.AIR.defaultState + + override fun SafeClientEvent.onInitialize() { + currentState = world.getBlockState(blockPos) + + if (currentState.block == Blocks.AIR) { + activityStatus = ActivityStatus.SUCCESS + color = ColorHolder(16, 74, 94) + } else { + getMiningSide(blockPos)?.let { side -> + ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + + if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + if (playSound) { + val soundType = currentState.block.getSoundType(currentState, world, blockPos, player) + world.playSound( + player, + blockPos, + soundType.breakSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } + } else { + playerController.onPlayerDamageBlock(blockPos, side) + } + getHitVec(blockPos, side) + } ?: run { + + } + } + } + + init { + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == Blocks.AIR + ) { + activityStatus = ActivityStatus.SUCCESS + color = ColorHolder(0, 255, 0) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt new file mode 100644 index 000000000..eacb5d58c --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt @@ -0,0 +1,26 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.items.item +import com.lambda.client.util.math.Direction +import net.minecraft.block.Block +import net.minecraft.init.Items +import net.minecraft.util.math.BlockPos + +class PlaceAndBreakBlockActivity(private val block: Block) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + subActivities.add(SwapOrMoveToItemActivity(block.item)) + subActivities.add(PlaceBlockActivity( + BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), + block + )) + subActivities.add(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) + subActivities.add(BreakBlockActivity( + BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)) + )) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt deleted file mode 100644 index 64ebc5c4f..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockAHeadActivity.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities.interaction - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.math.Direction -import net.minecraft.init.Blocks -import net.minecraft.util.math.BlockPos - -class PlaceBlockAHeadActivity : InstantActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - subActivities.add( - PlaceBlockActivity( - BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), - Blocks.OBSIDIAN - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index fae0dfe92..e60a58f4f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -17,23 +17,25 @@ import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand +import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos class PlaceBlockActivity( private val blockPos: BlockPos, private val block: Block, - override val timeout: Long = 10000L, + private val playSound: Boolean = true, + override val timeout: Long = 500L, override var creationTime: Long = 0L, - override val maxAttempts: Int = 5, + override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(35, 188, 254) + override var color: ColorHolder = ColorHolder(0, 0, 0) ) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { - val currentBlock = world.getBlockState(it.pos).block + val currentState = world.getBlockState(it.pos) - if (currentBlock in blockBlacklist) { + if (currentState.block in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } @@ -43,11 +45,29 @@ class PlaceBlockActivity( connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) player.swingArm(EnumHand.MAIN_HAND) - if (currentBlock in blockBlacklist) { + if (currentState.block in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } + + if (playSound) { + val soundType = currentState.block.getSoundType( + currentState, + world, + blockPos, + player + ) + world.playSound( + player, + blockPos, + soundType.placeSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } } ?: run { activityStatus = ActivityStatus.FAILURE + color = ColorHolder(16, 74, 94) } } @@ -58,6 +78,7 @@ class PlaceBlockActivity( && it.packet.blockState.block == block ) { activityStatus = ActivityStatus.SUCCESS + color = ColorHolder(35, 188, 254) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt index b07dc23fe..7ff7094aa 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt @@ -5,12 +5,12 @@ import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.allSlots -class DumpInventoryActivity(private val amount: Int = 0) : InstantActivity, Activity() { +class DumpInventoryActivity() : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } .forEach { - subActivities.add(DumpSlotActivity(it, amount)) + subActivities.add(DumpSlotActivity(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt index 28bc80804..9aacd75e0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt @@ -6,14 +6,8 @@ import com.lambda.client.manager.managers.activity.activities.InstantActivity import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot -class DumpSlotActivity(private val slot: Slot, private val amount: Int) : InstantActivity, Activity() { +class DumpSlotActivity(private val slot: Slot) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (slot.stack.count > amount || amount == 0) { - subActivities.add(InventoryTransactionActivity(0, slot.slotIndex, 1, ClickType.THROW)) - } else { - repeat(amount) { - subActivities.add(InventoryTransactionActivity(0, slot.slotNumber, 0, ClickType.THROW)) - } - } + subActivities.add(InventoryTransactionActivity(0, slot.slotNumber, 1, ClickType.THROW)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt index 7cc386493..5bf74c1a9 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.AttemptActivity import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.threads.safeListener import net.minecraft.inventory.ClickType @@ -17,9 +18,11 @@ class InventoryTransactionActivity( val slot: Int, private val mouseButton: Int = 0, val type: ClickType, - override val timeout: Long = 1000L, - override var creationTime: Long = 0L -) : TimeoutActivity, Activity() { + override val timeout: Long = 500L, + override var creationTime: Long = 0L, + override val maxAttempts: Int = 5, + override var usedAttempts: Int = 0 +) : TimeoutActivity, AttemptActivity, Activity() { private var transactionId: Short = -1 override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt new file mode 100644 index 000000000..df56e5c92 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt @@ -0,0 +1,16 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.items.HotbarSlot +import net.minecraft.inventory.ClickType + +class SwapHotbarSlotsActivity( + private val slotFrom: Int, + private val slotTo: Int +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + subActivities.add(InventoryTransactionActivity(0, slotFrom, slotTo, ClickType.SWAP)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 38b8e4486..a6746301d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,15 +1,18 @@ package com.lambda.client.module.modules.misc import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity -import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockAHeadActivity +import com.lambda.client.manager.managers.activity.activities.interaction.PlaceAndBreakBlockActivity import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapHotbarSlotsActivity import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.items.block import net.minecraft.block.BlockShulkerBox import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items @@ -44,13 +47,24 @@ object TestActivityManager : Module( false }) - private val onlyOne by setting("Dump only one Inventory", false, consumer = { _, _-> - ActivityManager.addActivity(DumpInventoryActivity(1)) + private val place by setting("PlaceAhed", false, consumer = { _, _-> + ActivityManager.addActivity(PlaceAndBreakBlockActivity(Blocks.SLIME_BLOCK)) false }) - private val place by setting("PlaceAhed", false, consumer = { _, _-> - ActivityManager.addActivity(PlaceBlockAHeadActivity()) + private val moin by setting("Ja Moin", false, consumer = { _, _-> + val activities = mutableListOf() + + activities.add(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) + repeat(9) { + activities.add(SwapHotbarSlotsActivity(36 + it, it + 1)) + } + repeat(4) { + activities.add(PlaceAndBreakBlockActivity(Blocks.SLIME_BLOCK)) + } + activities.add(DumpInventoryActivity()) + + ActivityManager.addAllActivities(activities) false }) From fe15918375fc93bbbbc39f15ced3b3c1e91c34ca Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 18 Dec 2022 00:26:31 +0100 Subject: [PATCH 011/104] Extract item from container --- .../manager/managers/activity/Activity.kt | 9 +- .../activity/activities/ActivityTypes.kt | 11 --- .../interaction/OpenContainerActivity.kt | 49 +++++++++- .../interaction/PlaceBlockActivity.kt | 10 +- .../inventory/SwapOrMoveToItemActivity.kt | 97 +++++++++++++++++-- .../inventory/SwapOrSwitchToSlotActivity.kt | 4 + .../inventory/SwitchToItemInHotbar.kt | 8 ++ 7 files changed, 160 insertions(+), 28 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 4abc3b247..10990156b 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -5,7 +5,6 @@ import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.activities.* -import com.lambda.client.manager.managers.activity.activities.AttemptActivity.Companion.doCheck import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize @@ -67,10 +66,14 @@ abstract class Activity { if (this@Activity is DelayedActivity) { if (System.currentTimeMillis() > creationTime + delay) { onDelayedActivity() - activityStatus = ActivityStatus.SUCCESS } } - (this@Activity as? AttemptActivity)?.doCheck() + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") + } + } } } ActivityStatus.SUCCESS -> { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt index c2ff89b78..f44df8276 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt @@ -1,8 +1,6 @@ package com.lambda.client.manager.managers.activity.activities -import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.color.ColorHolder import net.minecraft.util.math.BlockPos @@ -23,15 +21,6 @@ interface DelayedActivity { interface AttemptActivity { val maxAttempts: Int var usedAttempts: Int - - companion object { - fun T.doCheck() { - if (usedAttempts >= maxAttempts) { - (this as? Activity)?.activityStatus = Activity.ActivityStatus.FAILURE - LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") - } - } - } } interface RenderBlockActivity { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt index e874710fc..4abf60ea0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt @@ -1,4 +1,51 @@ package com.lambda.client.manager.managers.activity.activities.interaction -class OpenContainerActivity { +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getHitVec +import com.lambda.client.util.world.getHitVecOffset +import net.minecraft.network.play.client.CPacketPlayer +import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock +import net.minecraft.network.play.server.SPacketOpenWindow +import net.minecraft.network.play.server.SPacketWindowItems +import net.minecraft.util.EnumFacing +import net.minecraft.util.EnumHand +import net.minecraft.util.math.BlockPos + +class OpenContainerActivity(private val containerPos: BlockPos) : InstantActivity, Activity() { + private var isOpen = false + + override fun SafeClientEvent.onInitialize() { + val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) + val normalizedVec = diff.normalize() + + val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) + val hitVecOffset = getHitVecOffset(side) + + val rotation = getRotationTo(getHitVec(containerPos, side)) + + connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) + connection.sendPacket(CPacketPlayerTryUseItemOnBlock(containerPos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat())) + player.swingArm(EnumHand.MAIN_HAND) + } + + init { + safeListener { + when (it.packet) { + is SPacketOpenWindow -> { + isOpen = true + } + is SPacketWindowItems -> { + if (isOpen) { + activityStatus = ActivityStatus.SUCCESS + } + } + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index e60a58f4f..98a9acb76 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -33,9 +33,9 @@ class PlaceBlockActivity( ) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { - val currentState = world.getBlockState(it.pos) + val placedAtState = world.getBlockState(it.pos) - if (currentState.block in blockBlacklist) { + if (placedAtState.block in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } @@ -45,13 +45,13 @@ class PlaceBlockActivity( connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) player.swingArm(EnumHand.MAIN_HAND) - if (currentState.block in blockBlacklist) { + if (placedAtState.block in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } if (playSound) { - val soundType = currentState.block.getSoundType( - currentState, + val soundType = placedAtState.block.getSoundType( + placedAtState, world, blockPos, player diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt index 05d564540..19f3cfe72 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt @@ -3,9 +3,22 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainerActivity +import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockActivity import com.lambda.client.util.items.* +import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.world.getVisibleSides +import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.isReplaceable +import net.minecraft.inventory.ItemStackHelper +import net.minecraft.inventory.Slot import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack +import net.minecraft.util.EnumFacing +import net.minecraft.util.NonNullList +import net.minecraft.util.math.BlockPos class SwapOrMoveToItemActivity( private val item: Item, @@ -13,14 +26,12 @@ class SwapOrMoveToItemActivity( private val predicateSlot: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.hotbarSlots.firstOrNull { hotbarSlot -> - hotbarSlot.stack.item.id == item.id && predicateItem(hotbarSlot.stack) - }?.let { hotbarSlot -> - subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) - } ?: run { - player.storageSlots.firstOrNull { slot -> - slot.stack.item.id == item.id && predicateItem(slot.stack) - }?.let { slotFrom -> + player.allSlots.firstOrNull { slot -> + slot.stack.item == item && predicateItem(slot.stack) + }?.let { slotFrom -> + slotFrom.toHotbarSlotOrNull()?.let { hotbarSlot -> + subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) + } ?: run { val hotbarSlots = player.hotbarSlots val slotTo = hotbarSlots.firstEmpty() ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return @@ -28,6 +39,76 @@ class SwapOrMoveToItemActivity( subActivities.add(SwapWithSlotActivity(slotFrom, slotTo)) subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) } + } ?: run { + val candidates = mutableMapOf() + + player.allSlots.forEach { slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val count = inventory.count { it.item == item && predicateItem(it) } + + if (count > 0) candidates[slot] = count + } + } + + if (candidates.isEmpty()) return + + candidates.minBy { it.value }.key.let { slot -> + slot.toHotbarSlotOrNull()?.let { + subActivities.add(SwitchToHotbarSlotActivity(it.hotbarSlot)) + } ?: run { + val hotbarSlots = player.hotbarSlots + val slotTo = hotbarSlots.firstEmpty() + ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return + + subActivities.add(SwapWithSlotActivity(slot, slotTo)) + subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) + } + getRemotePos()?.let { remotePos -> + subActivities.add(PlaceBlockActivity(remotePos, slot.stack.item.block)) + subActivities.add(OpenContainerActivity(remotePos)) +// subActivities.add(MoveItemActivity(slot, slot.stack.item, predicateItem)) + } + } } } + + private fun getShulkerInventory(stack: ItemStack): NonNullList? { + if (stack.item !is ItemShulkerBox) return null + + stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { + if (it.hasKey("Items", 9)) { + val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) + ItemStackHelper.loadAllItems(it, shulkerInventory) + return shulkerInventory + } + } + + return null + } + + private fun SafeClientEvent.getRemotePos(): BlockPos? { + return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() + .filter { pos -> + world.isPlaceable(pos) + && !world.getBlockState(pos.down()).isReplaceable + && world.isAirBlock(pos.up()) + && getVisibleSides(pos.down()).contains(EnumFacing.UP) + && pos.y >= player.positionVector.y + }.sortedWith( + compareByDescending { + secureScore(it) + }.thenBy { + player.positionVector.distanceTo(it.toVec3dCenter()) + } + ).firstOrNull() + } + + private fun SafeClientEvent.secureScore(pos: BlockPos): Int { + var safe = 0 + if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ + return safe + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt new file mode 100644 index 000000000..ccb2c8d8c --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt @@ -0,0 +1,4 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +class SwapOrSwitchToSlotActivity { +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt new file mode 100644 index 000000000..f05108457 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt @@ -0,0 +1,8 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity + +class SwitchToItemInHotbar: Activity() { + override fun SafeClientEvent.onInitialize() {} +} \ No newline at end of file From e1e5b2b2a32490b2c975f1a352ac3732047946be Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 18 Dec 2022 03:55:27 +0100 Subject: [PATCH 012/104] Added CustomGoalActivity --- .../activities/travel/CustomGoalActivity.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt new file mode 100644 index 000000000..cbb9869e3 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt @@ -0,0 +1,29 @@ +package com.lambda.client.manager.managers.activity.activities.travel + +import baritone.api.pathing.goals.Goal +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +class CustomGoalActivity( + private val goal: Goal, + override val timeout: Long = 100000L, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { + init { + safeListener { event -> + if (event.phase != TickEvent.Phase.START) return@safeListener + + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) + + if (BaritoneUtils.primary?.customGoalProcess?.goal == null) { + activityStatus = ActivityStatus.FAILURE + } + + if (goal.isInGoal(player.flooredPosition)) activityStatus = ActivityStatus.SUCCESS + } + } +} \ No newline at end of file From 7d33b7bd03a7028d9f7ca9c15f113959cf82b676 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 18 Dec 2022 03:56:02 +0100 Subject: [PATCH 013/104] Remove not working code --- .../managers/activity/activities/travel/CustomGoalActivity.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt index cbb9869e3..035a8ce1d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt @@ -19,10 +19,6 @@ class CustomGoalActivity( BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) - if (BaritoneUtils.primary?.customGoalProcess?.goal == null) { - activityStatus = ActivityStatus.FAILURE - } - if (goal.isInGoal(player.flooredPosition)) activityStatus = ActivityStatus.SUCCESS } } From 87f9d652ae47f7490e31453771979b432bd495b9 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 18 Dec 2022 08:41:26 +0100 Subject: [PATCH 014/104] Added Storage Management --- .../manager/managers/activity/Activity.kt | 11 +- .../activity/activities/SetStateActivity.kt | 11 ++ .../activities/example/DoWorkyActivity.kt | 20 +++ .../activities/example/FailingActivity.kt | 15 +++ .../interaction/BreakBlockActivity.kt | 114 ++++++++++++++---- .../interaction/CloseContainerActivity.kt | 12 ++ .../interaction/PlaceBlockActivity.kt | 6 +- .../inventory/SwapOrMoveToItemActivity.kt | 89 ++------------ .../inventory/SwapOrSwitchToSlotActivity.kt | 26 +++- .../inventory/SwapToBestToolActivity.kt | 43 +++++++ .../ExtractItemFromShulkerBoxActivity.kt | 106 ++++++++++++++++ .../storage/PullItemFromContainerActivity.kt | 31 +++++ .../activities/travel/PickUpDropActivity.kt | 38 ++++++ .../modules/misc/TestActivityManager.kt | 14 +++ 14 files changed, 426 insertions(+), 110 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 10990156b..452f22204 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -5,9 +5,11 @@ import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.activities.* +import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize +import net.minecraft.util.math.BlockPos import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { @@ -115,6 +117,7 @@ abstract class Activity { fun reset() { LambdaEventBus.unsubscribe(currentActivity()) + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() } @@ -134,10 +137,10 @@ abstract class Activity { textComponent.add("${javaClass.simpleName} ", secondaryColor) textComponent.add("State", primaryColor) textComponent.add(activityStatus.name, secondaryColor) - this::class.java.declaredFields.forEach { - it.isAccessible = true - val name = it.name - val value = it.get(this) + this::class.java.declaredFields.forEach { field -> + field.isAccessible = true + val name = field.name + val value = field.get(this) textComponent.add(name.capitalize(), primaryColor) textComponent.add(value.toString(), secondaryColor) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt new file mode 100644 index 000000000..9244a06a3 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt @@ -0,0 +1,11 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity + +class SetStateActivity(private val activity: Activity, private val state: ActivityStatus) : Activity() { + override fun SafeClientEvent.onInitialize() { + activity.activityStatus = state + activityStatus = ActivityStatus.SUCCESS + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt new file mode 100644 index 000000000..440e173de --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt @@ -0,0 +1,20 @@ +package com.lambda.client.manager.managers.activity.activities.example + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +class DoWorkyActivity : Activity() { + override fun SafeClientEvent.onInitialize() { + subActivities.add(FailingActivity()) + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt new file mode 100644 index 000000000..6d4edb7bb --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt @@ -0,0 +1,15 @@ +package com.lambda.client.manager.managers.activity.activities.example + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import kotlin.random.Random + +class FailingActivity : Activity() { + override fun SafeClientEvent.onInitialize() { + activityStatus = if (Random.nextBoolean()) { + ActivityStatus.SUCCESS + } else { + ActivityStatus.FAILURE + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt index f687d5e5c..3a8c36ea7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt @@ -5,24 +5,32 @@ import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.AttemptActivity import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity +import com.lambda.client.manager.managers.activity.activities.SetStateActivity import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.travel.PickUpDropActivity import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.item +import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import net.minecraft.init.Blocks +import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent import kotlin.math.ceil class BreakBlockActivity( private val blockPos: BlockPos, private val playSound: Boolean = true, private val miningSpeedFactor: Float = 1.0f, - override val timeout: Long = 500L, + private val pickUpDrop: Boolean = false, + private val mode: Mode = Mode.PACKET, + override var timeout: Long = 200L, override var creationTime: Long = 0L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, @@ -30,51 +38,111 @@ class BreakBlockActivity( override var color: ColorHolder = ColorHolder(0, 0, 0) ) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { private var ticksNeeded = 0 - private var currentState = Blocks.AIR.defaultState + private var initState = Blocks.AIR.defaultState + + enum class Mode { + PLAYER_CONTROLLER, PACKET + } override fun SafeClientEvent.onInitialize() { - currentState = world.getBlockState(blockPos) + initState = world.getBlockState(blockPos) - if (currentState.block == Blocks.AIR) { + if (initState.block == Blocks.AIR) { activityStatus = ActivityStatus.SUCCESS color = ColorHolder(16, 74, 94) } else { + ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + } + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + getMiningSide(blockPos)?.let { side -> - ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + val rotation = getRotationTo(getHitVec(blockPos, side)) + + connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - if (playSound) { - val soundType = currentState.block.getSoundType(currentState, world, blockPos, player) - world.playSound( - player, - blockPos, - soundType.breakSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) + if (mode == Mode.PACKET) { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + if (playSound) { + val soundType = initState.block.getSoundType(initState, world, blockPos, player) + world.playSound( + player, + blockPos, + soundType.breakSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } + } else { + playerController.onPlayerDestroyBlock(blockPos) + finish() } } else { + timeout = ticksNeeded * 50L + 100L + playerController.onPlayerDamageBlock(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) + // cancel onPlayerDestroy NoGhostBlocks + +// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { +// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) +// player.swingArm(EnumHand.MAIN_HAND) +// if (playSound) { +// val soundType = initState.block.getSoundType(initState, world, blockPos, player) +// world.playSound( +// player, +// blockPos, +// soundType.breakSound, +// SoundCategory.BLOCKS, +// (soundType.getVolume() + 1.0f) / 2.0f, +// soundType.getPitch() * 0.8f +// ) +// } +// } else { +// player.swingArm(EnumHand.MAIN_HAND) +// if (playSound) { +// val soundType = initState.block.getSoundType(initState, world, blockPos, player) +// world.playSound( +// player, +// blockPos, +// soundType.hitSound, +// SoundCategory.BLOCKS, +// (soundType.getVolume() + 1.0f) / 2.0f, +// soundType.getPitch() * 0.8f +// ) +// } +// } } - getHitVec(blockPos, side) - } ?: run { + +// getHitVec(blockPos, side) } } - } - init { safeListener { if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos && it.packet.blockState.block == Blocks.AIR ) { - activityStatus = ActivityStatus.SUCCESS - color = ColorHolder(0, 255, 0) + finish() } } } + + private fun finish() { + if (pickUpDrop) { + color = ColorHolder(252, 3, 207) + timeout = 10000L + subActivities.add(PickUpDropActivity(initState.block.item)) + subActivities.add(SetStateActivity(this@BreakBlockActivity, ActivityStatus.SUCCESS)) + } else { + activityStatus = ActivityStatus.SUCCESS + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt new file mode 100644 index 000000000..4bcb322e8 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt @@ -0,0 +1,12 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity + +class CloseContainerActivity : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + player.closeScreen() + activityStatus = ActivityStatus.SUCCESS + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt index 98a9acb76..2038bcdc5 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt @@ -50,8 +50,10 @@ class PlaceBlockActivity( } if (playSound) { - val soundType = placedAtState.block.getSoundType( - placedAtState, + val thisState = world.getBlockState(blockPos) + + val soundType = thisState.block.getSoundType( + thisState, world, blockPos, player diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt index 19f3cfe72..d81adaed9 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt @@ -3,8 +3,12 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlockActivity +import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainerActivity import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainerActivity import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockActivity +import com.lambda.client.manager.managers.activity.activities.storage.ExtractItemFromShulkerBoxActivity +import com.lambda.client.manager.managers.activity.activities.storage.PullItemFromContainerActivity import com.lambda.client.util.items.* import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.toVec3dCenter @@ -23,92 +27,17 @@ import net.minecraft.util.math.BlockPos class SwapOrMoveToItemActivity( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true } + private val predicateSlot: (ItemStack) -> Boolean = { true }, + private val useShulkerBoxes: Boolean = false, + private val useEnderChest: Boolean = false ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) }?.let { slotFrom -> - slotFrom.toHotbarSlotOrNull()?.let { hotbarSlot -> - subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) - } ?: run { - val hotbarSlots = player.hotbarSlots - val slotTo = hotbarSlots.firstEmpty() - ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return - - subActivities.add(SwapWithSlotActivity(slotFrom, slotTo)) - subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) - } + subActivities.add(SwapOrSwitchToSlotActivity(slotFrom, predicateSlot)) } ?: run { - val candidates = mutableMapOf() - - player.allSlots.forEach { slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - val count = inventory.count { it.item == item && predicateItem(it) } - - if (count > 0) candidates[slot] = count - } - } - - if (candidates.isEmpty()) return - - candidates.minBy { it.value }.key.let { slot -> - slot.toHotbarSlotOrNull()?.let { - subActivities.add(SwitchToHotbarSlotActivity(it.hotbarSlot)) - } ?: run { - val hotbarSlots = player.hotbarSlots - val slotTo = hotbarSlots.firstEmpty() - ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return - - subActivities.add(SwapWithSlotActivity(slot, slotTo)) - subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) - } - getRemotePos()?.let { remotePos -> - subActivities.add(PlaceBlockActivity(remotePos, slot.stack.item.block)) - subActivities.add(OpenContainerActivity(remotePos)) -// subActivities.add(MoveItemActivity(slot, slot.stack.item, predicateItem)) - } - } + subActivities.add(ExtractItemFromShulkerBoxActivity(item, predicateItem, predicateSlot)) } } - - private fun getShulkerInventory(stack: ItemStack): NonNullList? { - if (stack.item !is ItemShulkerBox) return null - - stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { - if (it.hasKey("Items", 9)) { - val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) - ItemStackHelper.loadAllItems(it, shulkerInventory) - return shulkerInventory - } - } - - return null - } - - private fun SafeClientEvent.getRemotePos(): BlockPos? { - return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() - .filter { pos -> - world.isPlaceable(pos) - && !world.getBlockState(pos.down()).isReplaceable - && world.isAirBlock(pos.up()) - && getVisibleSides(pos.down()).contains(EnumFacing.UP) - && pos.y >= player.positionVector.y - }.sortedWith( - compareByDescending { - secureScore(it) - }.thenBy { - player.positionVector.distanceTo(it.toVec3dCenter()) - } - ).firstOrNull() - } - - private fun SafeClientEvent.secureScore(pos: BlockPos): Int { - var safe = 0 - if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ - return safe - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt index ccb2c8d8c..13fe14f78 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt @@ -1,4 +1,28 @@ package com.lambda.client.manager.managers.activity.activities.inventory -class SwapOrSwitchToSlotActivity { +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.items.firstEmpty +import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.items.toHotbarSlotOrNull +import net.minecraft.inventory.Slot +import net.minecraft.item.ItemStack + +class SwapOrSwitchToSlotActivity( + private val slot: Slot, + private val predicateSlot: (ItemStack) -> Boolean = { true } +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + slot.toHotbarSlotOrNull()?.let { hotbarSlot -> + subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) + } ?: run { + val hotbarSlots = player.hotbarSlots + val slotTo = hotbarSlots.firstEmpty() + ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return + + subActivities.add(SwapWithSlotActivity(slot, slotTo)) + subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt new file mode 100644 index 000000000..9f287e0f9 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt @@ -0,0 +1,43 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.toHotbarSlotOrNull +import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.init.Enchantments +import net.minecraft.util.math.BlockPos + +class SwapToBestToolActivity(private val blockPos: BlockPos) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + player.inventorySlots.asReversed().maxByOrNull { + val stack = it.stack + if (stack.isEmpty) { + 0.0f + } else { + var speed = stack.getDestroySpeed(world.getBlockState(blockPos)) + + if (speed > 1.0f) { + val efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack) + if (efficiency > 0) { + speed += efficiency * efficiency + 1.0f + } + } + + speed + } + }?.let { bestSlot -> + bestSlot.toHotbarSlotOrNull()?.let { hotbarSlot -> + subActivities.add(SwapOrSwitchToSlotActivity(hotbarSlot)) + } ?: run { + + } + } + + + + + + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt new file mode 100644 index 000000000..6c4c581b3 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt @@ -0,0 +1,106 @@ +package com.lambda.client.manager.managers.activity.activities.storage + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlockActivity +import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainerActivity +import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainerActivity +import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrSwitchToSlotActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapToBestToolActivity +import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.block +import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.world.getVisibleSides +import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.isReplaceable +import net.minecraft.inventory.ItemStackHelper +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox +import net.minecraft.item.ItemStack +import net.minecraft.util.EnumFacing +import net.minecraft.util.NonNullList +import net.minecraft.util.math.BlockPos + +class ExtractItemFromShulkerBoxActivity( + private val item: Item, + private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true } +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + val candidates = mutableMapOf() + + player.allSlots.forEach { slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val count = inventory.count { it.item == item && predicateItem(it) } + + if (count > 0) candidates[slot] = count + } + } + + if (candidates.isEmpty()) return + + candidates.minBy { it.value }.key.let { slot -> + getContainerPos()?.let { remotePos -> + subActivities.addAll(listOf( + SwapOrSwitchToSlotActivity(slot, predicateSlot), + PlaceBlockActivity(remotePos, slot.stack.item.block), + OpenContainerActivity(remotePos), + PullItemFromContainerActivity(item, predicateItem), + CloseContainerActivity(), + SwapToBestToolActivity(remotePos), + BreakBlockActivity( + remotePos, + pickUpDrop = true, + mode = BreakBlockActivity.Mode.PLAYER_CONTROLLER + ), + SwapOrMoveToItemActivity(item, predicateItem, predicateSlot) + )) + } + } + } + + private fun getShulkerInventory(stack: ItemStack): NonNullList? { + if (stack.item !is ItemShulkerBox) return null + + stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { + if (it.hasKey("Items", 9)) { + val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) + ItemStackHelper.loadAllItems(it, shulkerInventory) + return shulkerInventory + } + } + + return null + } + + private fun SafeClientEvent.getContainerPos(): BlockPos? { + return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() + .filter { pos -> + world.isPlaceable(pos) + && !world.getBlockState(pos.down()).isReplaceable + && world.isAirBlock(pos.up()) + && getVisibleSides(pos.down()).contains(EnumFacing.UP) + && pos.y >= player.positionVector.y + }.sortedWith( + compareByDescending { + secureScore(it) + }.thenBy { + player.positionVector.distanceTo(it.toVec3dCenter()) + } + ).firstOrNull() + } + + private fun SafeClientEvent.secureScore(pos: BlockPos): Int { + var safe = 0 + if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ + return safe + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt new file mode 100644 index 000000000..a3dd0a913 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt @@ -0,0 +1,31 @@ +package com.lambda.client.manager.managers.activity.activities.storage + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.inventory.InventoryTransactionActivity +import net.minecraft.inventory.ClickType +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class PullItemFromContainerActivity( + private val item: Item, + private val predicateItem: (ItemStack) -> Boolean = { true }, + override var timeout: Long = 100L, + override var creationTime: Long = 0L +) : InstantActivity, TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + player.openContainer.inventorySlots.filter { slot -> + slot.stack.item == item && predicateItem(slot.stack) + }.forEach { + timeout += 100L + subActivities.add(InventoryTransactionActivity( + player.openContainer.windowId, + it.slotNumber, + 0, + ClickType.QUICK_MOVE + )) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt new file mode 100644 index 000000000..282410ba8 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt @@ -0,0 +1,38 @@ +package com.lambda.client.manager.managers.activity.activities.travel + +import baritone.api.pathing.goals.GoalBlock +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.threads.safeListener +import net.minecraft.entity.item.EntityItem +import net.minecraft.item.Item +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.gameevent.TickEvent + +class PickUpDropActivity( + private val item: Item, + private val predicate: (ItemStack) -> Boolean = { true }, + private val maxRange: Float = 5.0f, + override val timeout: Long = 10000L, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + allDrops().minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(drop.position)) + } ?: run { + activityStatus = ActivityStatus.SUCCESS + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) + } + } + } + + private fun SafeClientEvent.allDrops() = world.loadedEntityList.filterIsInstance().filter { + it.item.item == item && player.distanceTo(it.positionVector) <= maxRange && predicate(it.item) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index a6746301d..13ca46d80 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,12 +1,15 @@ package com.lambda.client.module.modules.misc +import baritone.api.pathing.goals.GoalBlock import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.example.FailingActivity import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity import com.lambda.client.manager.managers.activity.activities.interaction.PlaceAndBreakBlockActivity import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity import com.lambda.client.manager.managers.activity.activities.inventory.SwapHotbarSlotsActivity import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity +import com.lambda.client.manager.managers.activity.activities.travel.CustomGoalActivity import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.items.block @@ -15,6 +18,7 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items +import net.minecraft.util.math.BlockPos object TestActivityManager : Module( name = "TestActivityManager", @@ -73,6 +77,16 @@ object TestActivityManager : Module( false }) + private val fail by setting("maybe fail", false, consumer = { _, _-> + ActivityManager.addActivity(FailingActivity()) + false + }) + + private val bur by setting("baritone", false, consumer = { _, _-> + ActivityManager.addActivity(CustomGoalActivity(GoalBlock(BlockPos(0, 0, 0)))) + false + }) + private val reset by setting("Reset", false, consumer = { _, _-> ActivityManager.reset() false From 8f443209e5e5e37e1c6ab388d26b6eb5769128f0 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 19 Dec 2022 01:21:25 +0100 Subject: [PATCH 015/104] Refactor names and small stuff --- .../manager/managers/activity/Activity.kt | 1 - .../activity/activities/ActivityTypes.kt | 9 ++++ .../{SetStateActivity.kt => SetState.kt} | 2 +- .../managers/activity/activities/Wait.kt | 13 ++++++ .../activities/example/FailingActivity.kt | 2 + .../{BreakBlockActivity.kt => BreakBlock.kt} | 10 ++--- ...ContainerActivity.kt => CloseContainer.kt} | 2 +- .../activities/interaction/LookAtBlock.kt | 23 ++++++++++ ...nContainerActivity.kt => OpenContainer.kt} | 13 ++---- ...BlockActivity.kt => PlaceAndBreakBlock.kt} | 12 ++--- .../{PlaceBlockActivity.kt => PlaceBlock.kt} | 2 +- ...pInventoryActivity.kt => DumpInventory.kt} | 4 +- .../{DumpSlotActivity.kt => DumpSlot.kt} | 4 +- ...ionActivity.kt => InventoryTransaction.kt} | 2 +- ...barSlotsActivity.kt => SwapHotbarSlots.kt} | 8 ++-- .../activities/inventory/SwapOrMoveToItem.kt | 27 +++++++++++ .../inventory/SwapOrMoveToItemActivity.kt | 43 ------------------ ...oSlotActivity.kt => SwapOrSwitchToSlot.kt} | 8 ++-- ...oBestToolActivity.kt => SwapToBestTool.kt} | 14 +----- ...wapWithSlotActivity.kt => SwapWithSlot.kt} | 4 +- ...rSlotActivity.kt => SwitchToHotbarSlot.kt} | 7 +-- ...tivity.kt => ExtractItemFromShulkerBox.kt} | 37 ++++++++------- ...rActivity.kt => PullItemsFromContainer.kt} | 23 +++++----- .../{CustomGoalActivity.kt => CustomGoal.kt} | 2 +- .../activities/travel/PickUpDropActivity.kt | 38 ---------------- .../activity/activities/travel/PickUpDrops.kt | 23 ++++++++++ .../activities/travel/PickUpEntityItem.kt | 41 +++++++++++++++++ .../modules/misc/TestActivityManager.kt | 45 +++++++------------ 28 files changed, 227 insertions(+), 192 deletions(-) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/{SetStateActivity.kt => SetState.kt} (75%) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/{BreakBlockActivity.kt => BreakBlock.kt} (96%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/{CloseContainerActivity.kt => CloseContainer.kt} (86%) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/{OpenContainerActivity.kt => OpenContainer.kt} (84%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/{PlaceAndBreakBlockActivity.kt => PlaceAndBreakBlock.kt} (70%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/{PlaceBlockActivity.kt => PlaceBlock.kt} (99%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{DumpInventoryActivity.kt => DumpInventory.kt} (79%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{DumpSlotActivity.kt => DumpSlot.kt} (69%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{InventoryTransactionActivity.kt => InventoryTransaction.kt} (98%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{SwapHotbarSlotsActivity.kt => SwapHotbarSlots.kt} (68%) create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{SwapOrSwitchToSlotActivity.kt => SwapOrSwitchToSlot.kt} (78%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{SwapToBestToolActivity.kt => SwapToBestTool.kt} (77%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{SwapWithSlotActivity.kt => SwapWithSlot.kt} (79%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/{SwitchToHotbarSlotActivity.kt => SwitchToHotbarSlot.kt} (60%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/{ExtractItemFromShulkerBoxActivity.kt => ExtractItemFromShulkerBox.kt} (82%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/{PullItemFromContainerActivity.kt => PullItemsFromContainer.kt} (65%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/{CustomGoalActivity.kt => CustomGoal.kt} (97%) delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 452f22204..7cab9c6d3 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -9,7 +9,6 @@ import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.capitalize -import net.minecraft.util.math.BlockPos import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt index f44df8276..b7d25e2c9 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.color.ColorHolder import net.minecraft.util.math.BlockPos @@ -26,4 +27,12 @@ interface AttemptActivity { interface RenderBlockActivity { var renderBlockPos: BlockPos var color: ColorHolder +} + +interface CallbackActivity { + val owner: Activity +} + +interface ThrowableActivity { + val throwable: Throwable } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt similarity index 75% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt index 9244a06a3..c48cc7e55 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetStateActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt @@ -3,7 +3,7 @@ package com.lambda.client.manager.managers.activity.activities import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity -class SetStateActivity(private val activity: Activity, private val state: ActivityStatus) : Activity() { +class SetState(private val activity: Activity, private val state: ActivityStatus) : Activity() { override fun SafeClientEvent.onInitialize() { activity.activityStatus = state activityStatus = ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt new file mode 100644 index 000000000..47345e93d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt @@ -0,0 +1,13 @@ +package com.lambda.client.manager.managers.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity + +class Wait( + override val delay: Long, + override var creationTime: Long = 0L +) : DelayedActivity, Activity() { + override fun SafeClientEvent.onDelayedActivity() { + activityStatus = ActivityStatus.SUCCESS + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt index 6d4edb7bb..dbf2ff72c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt @@ -2,6 +2,8 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.ThrowableActivity +import java.lang.Exception import kotlin.random.Random class FailingActivity : Activity() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt similarity index 96% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt index 3a8c36ea7..6656794fa 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt @@ -5,9 +5,9 @@ import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.AttemptActivity import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity -import com.lambda.client.manager.managers.activity.activities.SetStateActivity +import com.lambda.client.manager.managers.activity.activities.SetState import com.lambda.client.manager.managers.activity.activities.TimeoutActivity -import com.lambda.client.manager.managers.activity.activities.travel.PickUpDropActivity +import com.lambda.client.manager.managers.activity.activities.travel.PickUpDrops import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.item import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -24,7 +24,7 @@ import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent import kotlin.math.ceil -class BreakBlockActivity( +class BreakBlock( private val blockPos: BlockPos, private val playSound: Boolean = true, private val miningSpeedFactor: Float = 1.0f, @@ -139,8 +139,8 @@ class BreakBlockActivity( if (pickUpDrop) { color = ColorHolder(252, 3, 207) timeout = 10000L - subActivities.add(PickUpDropActivity(initState.block.item)) - subActivities.add(SetStateActivity(this@BreakBlockActivity, ActivityStatus.SUCCESS)) + subActivities.add(PickUpDrops(initState.block.item)) + subActivities.add(SetState(this@BreakBlock, ActivityStatus.SUCCESS)) } else { activityStatus = ActivityStatus.SUCCESS } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt similarity index 86% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt index 4bcb322e8..99a4ff874 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainerActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt @@ -4,7 +4,7 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -class CloseContainerActivity : InstantActivity, Activity() { +class CloseContainer : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.closeScreen() activityStatus = ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt new file mode 100644 index 000000000..6a9d8ec6b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt @@ -0,0 +1,23 @@ +package com.lambda.client.manager.managers.activity.activities.interaction + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.world.getHitVec +import net.minecraft.network.play.client.CPacketPlayer +import net.minecraft.util.EnumFacing +import net.minecraft.util.math.BlockPos + +class LookAtBlock(private val blockPos: BlockPos) : Activity() { + override fun SafeClientEvent.onInitialize() { + val diff = player.getPositionEyes(1f).subtract(blockPos.toVec3dCenter()) + val normalizedVec = diff.normalize() + + val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) + + val rotation = getRotationTo(getHitVec(blockPos, side)) + + connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt similarity index 84% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt index 4abf60ea0..05f042889 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainerActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt @@ -4,6 +4,8 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.SetState +import com.lambda.client.manager.managers.activity.activities.Wait import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener @@ -17,9 +19,7 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -class OpenContainerActivity(private val containerPos: BlockPos) : InstantActivity, Activity() { - private var isOpen = false - +class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() @@ -38,12 +38,7 @@ class OpenContainerActivity(private val containerPos: BlockPos) : InstantActivit safeListener { when (it.packet) { is SPacketOpenWindow -> { - isOpen = true - } - is SPacketWindowItems -> { - if (isOpen) { - activityStatus = ActivityStatus.SUCCESS - } + subActivities.add(SetState(this@OpenContainer, ActivityStatus.SUCCESS)) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt similarity index 70% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt index eacb5d58c..d7b564174 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt @@ -3,7 +3,7 @@ package com.lambda.client.manager.managers.activity.activities.interaction import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.items.item import com.lambda.client.util.math.Direction @@ -11,15 +11,15 @@ import net.minecraft.block.Block import net.minecraft.init.Items import net.minecraft.util.math.BlockPos -class PlaceAndBreakBlockActivity(private val block: Block) : InstantActivity, Activity() { +class PlaceAndBreakBlock(private val block: Block) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(SwapOrMoveToItemActivity(block.item)) - subActivities.add(PlaceBlockActivity( + subActivities.add(SwapOrMoveToItem(block.item)) + subActivities.add(PlaceBlock( BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), block )) - subActivities.add(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) - subActivities.add(BreakBlockActivity( + subActivities.add(SwapOrMoveToItem(Items.DIAMOND_PICKAXE)) + subActivities.add(BreakBlock( BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)) )) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt similarity index 99% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt index 2038bcdc5..b449ab4c0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt @@ -20,7 +20,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -class PlaceBlockActivity( +class PlaceBlock( private val blockPos: BlockPos, private val block: Block, private val playSound: Boolean = true, diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt similarity index 79% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt index 7ff7094aa..89aeb3c5e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventoryActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt @@ -5,12 +5,12 @@ import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.allSlots -class DumpInventoryActivity() : InstantActivity, Activity() { +class DumpInventory() : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } .forEach { - subActivities.add(DumpSlotActivity(it)) + subActivities.add(DumpSlot(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt similarity index 69% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt index 9aacd75e0..7455325af 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt @@ -6,8 +6,8 @@ import com.lambda.client.manager.managers.activity.activities.InstantActivity import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot -class DumpSlotActivity(private val slot: Slot) : InstantActivity, Activity() { +class DumpSlot(private val slot: Slot) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransactionActivity(0, slot.slotNumber, 1, ClickType.THROW)) + subActivities.add(InventoryTransaction(0, slot.slotNumber, 1, ClickType.THROW)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt similarity index 98% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt index 5bf74c1a9..f065fec94 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransactionActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketClickWindow import net.minecraft.network.play.server.SPacketConfirmTransaction -class InventoryTransactionActivity( +class InventoryTransaction( val windowId: Int = 0, val slot: Int, private val mouseButton: Int = 0, diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt similarity index 68% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt index df56e5c92..a4a454c6c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlotsActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt @@ -6,11 +6,11 @@ import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType -class SwapHotbarSlotsActivity( - private val slotFrom: Int, - private val slotTo: Int +class SwapHotbarSlots( + private val slotFrom: HotbarSlot, + private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransactionActivity(0, slotFrom, slotTo, ClickType.SWAP)) + subActivities.add(InventoryTransaction(0, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt new file mode 100644 index 000000000..6d3571255 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt @@ -0,0 +1,27 @@ +package com.lambda.client.manager.managers.activity.activities.inventory + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.manager.managers.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.util.items.* +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class SwapOrMoveToItem( + private val item: Item, + private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true }, + private val useShulkerBoxes: Boolean = false, + private val useEnderChest: Boolean = false +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + player.allSlots.firstOrNull { slot -> + slot.stack.item == item && predicateItem(slot.stack) + }?.let { slotFrom -> + subActivities.add(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + } ?: run { + subActivities.add(ExtractItemFromShulkerBox(item, 0, predicateItem, predicateSlot)) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt deleted file mode 100644 index d81adaed9..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItemActivity.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities.inventory - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlockActivity -import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainerActivity -import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainerActivity -import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockActivity -import com.lambda.client.manager.managers.activity.activities.storage.ExtractItemFromShulkerBoxActivity -import com.lambda.client.manager.managers.activity.activities.storage.PullItemFromContainerActivity -import com.lambda.client.util.items.* -import com.lambda.client.util.math.VectorUtils -import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import com.lambda.client.util.world.getVisibleSides -import com.lambda.client.util.world.isPlaceable -import com.lambda.client.util.world.isReplaceable -import net.minecraft.inventory.ItemStackHelper -import net.minecraft.inventory.Slot -import net.minecraft.item.Item -import net.minecraft.item.ItemShulkerBox -import net.minecraft.item.ItemStack -import net.minecraft.util.EnumFacing -import net.minecraft.util.NonNullList -import net.minecraft.util.math.BlockPos - -class SwapOrMoveToItemActivity( - private val item: Item, - private val predicateItem: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true }, - private val useShulkerBoxes: Boolean = false, - private val useEnderChest: Boolean = false -) : InstantActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - player.allSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) - }?.let { slotFrom -> - subActivities.add(SwapOrSwitchToSlotActivity(slotFrom, predicateSlot)) - } ?: run { - subActivities.add(ExtractItemFromShulkerBoxActivity(item, predicateItem, predicateSlot)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt similarity index 78% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt index 13fe14f78..a1b50b1c7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -9,20 +9,20 @@ import com.lambda.client.util.items.toHotbarSlotOrNull import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack -class SwapOrSwitchToSlotActivity( +class SwapOrSwitchToSlot( private val slot: Slot, private val predicateSlot: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { slot.toHotbarSlotOrNull()?.let { hotbarSlot -> - subActivities.add(SwitchToHotbarSlotActivity(hotbarSlot.hotbarSlot)) + subActivities.add(SwitchToHotbarSlot(hotbarSlot)) } ?: run { val hotbarSlots = player.hotbarSlots val slotTo = hotbarSlots.firstEmpty() ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return - subActivities.add(SwapWithSlotActivity(slot, slotTo)) - subActivities.add(SwitchToHotbarSlotActivity(slotTo.hotbarSlot)) + subActivities.add(SwapWithSlot(slot, slotTo)) + subActivities.add(SwitchToHotbarSlot(slotTo)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt similarity index 77% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt index 9f287e0f9..2101559b8 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestToolActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt @@ -4,12 +4,11 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.inventorySlots -import com.lambda.client.util.items.toHotbarSlotOrNull import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments import net.minecraft.util.math.BlockPos -class SwapToBestToolActivity(private val blockPos: BlockPos) : InstantActivity, Activity() { +class SwapToBestTool(private val blockPos: BlockPos) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack @@ -28,16 +27,7 @@ class SwapToBestToolActivity(private val blockPos: BlockPos) : InstantActivity, speed } }?.let { bestSlot -> - bestSlot.toHotbarSlotOrNull()?.let { hotbarSlot -> - subActivities.add(SwapOrSwitchToSlotActivity(hotbarSlot)) - } ?: run { - - } + subActivities.add(SwapOrSwitchToSlot(bestSlot)) } - - - - - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt similarity index 79% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt index 4cb451937..4f6910094 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt @@ -7,11 +7,11 @@ import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot -class SwapWithSlotActivity( +class SwapWithSlot( private val slotFrom: Slot, private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransactionActivity(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) + subActivities.add(InventoryTransaction(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt similarity index 60% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt index f1a9fb60b..6b4edf4f7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlotActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt @@ -3,11 +3,12 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.items.HotbarSlot -class SwitchToHotbarSlotActivity(private val slot: Int) : InstantActivity, Activity() { +class SwitchToHotbarSlot(private val slot: HotbarSlot) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (slot !in 0..8) return - player.inventory.currentItem = slot + if (slot.hotbarSlot !in 0..8) return + player.inventory.currentItem = slot.hotbarSlot playerController.updateController() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt similarity index 82% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt index 6c4c581b3..123e51653 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBoxActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -3,13 +3,14 @@ package com.lambda.client.manager.managers.activity.activities.storage import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlockActivity -import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainerActivity -import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainerActivity -import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlockActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrSwitchToSlotActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapToBestToolActivity +import com.lambda.client.manager.managers.activity.activities.Wait +import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlock +import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainer +import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainer +import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlock +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.manager.managers.activity.activities.inventory.SwapToBestTool import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block import com.lambda.client.util.math.VectorUtils @@ -26,8 +27,9 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.NonNullList import net.minecraft.util.math.BlockPos -class ExtractItemFromShulkerBoxActivity( +class ExtractItemFromShulkerBox( private val item: Item, + private val amount: Int, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { @@ -47,18 +49,19 @@ class ExtractItemFromShulkerBoxActivity( candidates.minBy { it.value }.key.let { slot -> getContainerPos()?.let { remotePos -> subActivities.addAll(listOf( - SwapOrSwitchToSlotActivity(slot, predicateSlot), - PlaceBlockActivity(remotePos, slot.stack.item.block), - OpenContainerActivity(remotePos), - PullItemFromContainerActivity(item, predicateItem), - CloseContainerActivity(), - SwapToBestToolActivity(remotePos), - BreakBlockActivity( + SwapOrSwitchToSlot(slot, predicateSlot), + PlaceBlock(remotePos, slot.stack.item.block), + OpenContainer(remotePos), + Wait(50L), + PullItemsFromContainer(item, amount, predicateItem), + CloseContainer(), + SwapToBestTool(remotePos), + BreakBlock( remotePos, pickUpDrop = true, - mode = BreakBlockActivity.Mode.PLAYER_CONTROLLER + mode = BreakBlock.Mode.PLAYER_CONTROLLER ), - SwapOrMoveToItemActivity(item, predicateItem, predicateSlot) + SwapOrMoveToItem(item, predicateItem, predicateSlot) )) } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt similarity index 65% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt index a3dd0a913..45abdd54a 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemFromContainerActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt @@ -3,24 +3,27 @@ package com.lambda.client.manager.managers.activity.activities.storage import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity -import com.lambda.client.manager.managers.activity.activities.inventory.InventoryTransactionActivity +import com.lambda.client.manager.managers.activity.activities.inventory.InventoryTransaction +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.inventorySlots import net.minecraft.inventory.ClickType import net.minecraft.item.Item import net.minecraft.item.ItemStack -class PullItemFromContainerActivity( +class PullItemsFromContainer( private val item: Item, - private val predicateItem: (ItemStack) -> Boolean = { true }, - override var timeout: Long = 100L, - override var creationTime: Long = 0L -) : InstantActivity, TimeoutActivity, Activity() { + private val amount: Int, // 0 = all + private val predicateItem: (ItemStack) -> Boolean = { true } +) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { + val maxEmpty = player.inventorySlots.countEmpty() - 1 + + val take = if (amount > 0) amount.coerceAtMost(maxEmpty) else maxEmpty + player.openContainer.inventorySlots.filter { slot -> slot.stack.item == item && predicateItem(slot.stack) - }.forEach { - timeout += 100L - subActivities.add(InventoryTransactionActivity( + }.take(take).forEach { + subActivities.add(InventoryTransaction( player.openContainer.windowId, it.slotNumber, 0, diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt similarity index 97% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt index 035a8ce1d..cbc7215e5 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoalActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt @@ -8,7 +8,7 @@ import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent -class CustomGoalActivity( +class CustomGoal( private val goal: Goal, override val timeout: Long = 100000L, override var creationTime: Long = 0L diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt deleted file mode 100644 index 282410ba8..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDropActivity.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities.travel - -import baritone.api.pathing.goals.GoalBlock -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity -import com.lambda.client.util.BaritoneUtils -import com.lambda.client.util.math.VectorUtils.distanceTo -import com.lambda.client.util.threads.safeListener -import net.minecraft.entity.item.EntityItem -import net.minecraft.item.Item -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.gameevent.TickEvent - -class PickUpDropActivity( - private val item: Item, - private val predicate: (ItemStack) -> Boolean = { true }, - private val maxRange: Float = 5.0f, - override val timeout: Long = 10000L, - override var creationTime: Long = 0L -) : TimeoutActivity, Activity() { - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - allDrops().minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(drop.position)) - } ?: run { - activityStatus = ActivityStatus.SUCCESS - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) - } - } - } - - private fun SafeClientEvent.allDrops() = world.loadedEntityList.filterIsInstance().filter { - it.item.item == item && player.distanceTo(it.positionVector) <= maxRange && predicate(it.item) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt new file mode 100644 index 000000000..a577071c7 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt @@ -0,0 +1,23 @@ +package com.lambda.client.manager.managers.activity.activities.travel + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.InstantActivity +import com.lambda.client.util.math.VectorUtils.distanceTo +import net.minecraft.entity.item.EntityItem +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class PickUpDrops( + private val item: Item, + private val predicate: (ItemStack) -> Boolean = { true }, + private val maxRange: Float = 10.0f +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + world.loadedEntityList.filterIsInstance().filter { + it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) + }.sortedBy { drop -> player.distanceTo(drop.positionVector) }.forEach { drop -> + subActivities.add(PickUpEntityItem(drop)) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt new file mode 100644 index 000000000..9e197c069 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt @@ -0,0 +1,41 @@ +package com.lambda.client.manager.managers.activity.activities.travel + +import baritone.api.pathing.goals.GoalBlock +import com.lambda.client.manager.managers.activity.Activity +import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.manager.managers.activity.activities.inventory.DumpSlot +import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.threads.safeListener +import net.minecraft.entity.item.EntityItem +import net.minecraftforge.fml.common.gameevent.TickEvent + +class PickUpEntityItem( + entityItem: EntityItem, + override val timeout: Long = 10000L, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + if (world.loadedEntityList.contains(entityItem)) { + val emptySlots = player.inventory.mainInventory.filter { it.isEmpty } + + if (emptySlots.isNotEmpty()) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) + } else { + player.inventorySlots.firstOrNull { slot -> + InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) + }?.let { slot -> + subActivities.add(DumpSlot(slot)) + } + } + } else { + activityStatus = ActivityStatus.SUCCESS + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 13ca46d80..93b422b7a 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,24 +1,24 @@ package com.lambda.client.module.modules.misc -import baritone.api.pathing.goals.GoalBlock +import com.lambda.client.LambdaMod import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.example.FailingActivity import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity -import com.lambda.client.manager.managers.activity.activities.interaction.PlaceAndBreakBlockActivity -import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventoryActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapHotbarSlotsActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItemActivity -import com.lambda.client.manager.managers.activity.activities.travel.CustomGoalActivity +import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventory +import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.manager.managers.activity.activities.travel.PickUpDrops import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.items.block +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.item +import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockShulkerBox import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items -import net.minecraft.util.math.BlockPos object TestActivityManager : Module( name = "TestActivityManager", @@ -26,13 +26,13 @@ object TestActivityManager : Module( category = Category.MISC ) { private val a by setting("Get Dia Pickaxe", false, consumer = { _, _-> - ActivityManager.addActivity(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) + ActivityManager.addActivity(SwapOrMoveToItem(Items.DIAMOND_PICKAXE)) false }) private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> ActivityManager.addActivity( - SwapOrMoveToItemActivity( + SwapOrMoveToItem( Items.DIAMOND_PICKAXE, predicateItem = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 @@ -47,28 +47,20 @@ object TestActivityManager : Module( }) private val dumpInventoryActivity by setting("Dump Inventory", false, consumer = { _, _-> - ActivityManager.addActivity(DumpInventoryActivity()) + ActivityManager.addActivity(DumpInventory()) false }) - private val place by setting("PlaceAhed", false, consumer = { _, _-> - ActivityManager.addActivity(PlaceAndBreakBlockActivity(Blocks.SLIME_BLOCK)) + private val po by setting("Pickup Obby", false, consumer = { _, _-> + ActivityManager.addActivity(PickUpDrops(Blocks.OBSIDIAN.item)) false }) - private val moin by setting("Ja Moin", false, consumer = { _, _-> - val activities = mutableListOf() - - activities.add(SwapOrMoveToItemActivity(Items.DIAMOND_PICKAXE)) - repeat(9) { - activities.add(SwapHotbarSlotsActivity(36 + it, it + 1)) - } - repeat(4) { - activities.add(PlaceAndBreakBlockActivity(Blocks.SLIME_BLOCK)) + private val ti by setting("count", false, consumer = { _, _-> + runSafe { + LambdaMod.LOG.info(player.inventorySlots.countEmpty()) } - activities.add(DumpInventoryActivity()) - ActivityManager.addAllActivities(activities) false }) @@ -82,11 +74,6 @@ object TestActivityManager : Module( false }) - private val bur by setting("baritone", false, consumer = { _, _-> - ActivityManager.addActivity(CustomGoalActivity(GoalBlock(BlockPos(0, 0, 0)))) - false - }) - private val reset by setting("Reset", false, consumer = { _, _-> ActivityManager.reset() false From 4b5edb3930ecd2f79c6f31dcc36956b7f4e21b65 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 19 Dec 2022 02:35:18 +0100 Subject: [PATCH 016/104] Owner property added --- .../elements/misc/ActivityManagerHud.kt | 3 +-- .../manager/managers/ActivityManager.kt | 10 +--------- .../manager/managers/activity/Activity.kt | 10 +++++++--- .../managers/activity/activities/SetState.kt | 4 ++-- .../activities/example/DoWorkyActivity.kt | 20 ------------------- .../{FailingActivity.kt => Failing.kt} | 4 +--- ...AnnoyinglyActivity.kt => SayAnnoyingly.kt} | 4 ++-- ...yinglyActivity.kt => SayVeryAnnoyingly.kt} | 4 ++-- .../{WaitAndSayActivity.kt => WaitAndSay.kt} | 2 +- .../activities/interaction/BreakBlock.kt | 6 ++++-- .../activities/interaction/OpenContainer.kt | 2 +- .../interaction/PlaceAndBreakBlock.kt | 20 ++++++++++--------- .../activities/inventory/DumpInventory.kt | 4 ++-- .../activity/activities/inventory/DumpSlot.kt | 2 +- .../activities/inventory/SwapHotbarSlots.kt | 3 ++- .../activities/inventory/SwapOrMoveToItem.kt | 5 +++-- .../inventory/SwapOrSwitchToSlot.kt | 8 +++++--- .../activities/inventory/SwapToBestTool.kt | 3 ++- .../activities/inventory/SwapWithSlot.kt | 2 +- .../storage/ExtractItemFromShulkerBox.kt | 4 ++-- .../storage/PullItemsFromContainer.kt | 3 ++- .../activity/activities/travel/PickUpDrops.kt | 2 +- .../activities/travel/PickUpEntityItem.kt | 3 ++- .../modules/misc/TestActivityManager.kt | 19 ++++++++++-------- 24 files changed, 67 insertions(+), 80 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/{FailingActivity.kt => Failing.kt} (74%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/{SayAnnoyinglyActivity.kt => SayAnnoyingly.kt} (70%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/{SayVeryAnnoyinglyActivity.kt => SayVeryAnnoyingly.kt} (68%) rename src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/{WaitAndSayActivity.kt => WaitAndSay.kt} (95%) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index ce8d285be..d46503234 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -10,9 +10,8 @@ internal object ActivityManagerHud: LabelHud( description = "Display current activities." ) { override fun SafeClientEvent.updateText() { - if (ActivityManager.subActivities.isEmpty()) return + if (ActivityManager.noSubActivities()) return ActivityManager.appendInfo(displayText, primaryColor, secondaryColor, 0) } - } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index a90ec7791..bd56edb05 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -13,7 +13,7 @@ object ActivityManager : Manager, Activity() { init { safeListener { - if (subActivities.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener + if (noSubActivities() || it.phase != TickEvent.Phase.START) return@safeListener updateActivities() } @@ -30,12 +30,4 @@ object ActivityManager : Manager, Activity() { renderer.render(true) } } - - fun addActivity(activity: Activity) { - subActivities.add(activity) - } - - fun addAllActivities(activity: List) { - subActivities.addAll(activity) - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt index 7cab9c6d3..4eee0bf5d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt @@ -12,8 +12,9 @@ import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { - val subActivities = ConcurrentLinkedDeque() + private val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED + var owner: Activity = ActivityManager enum class ActivityStatus { UNINITIALIZED, @@ -120,10 +121,13 @@ abstract class Activity { subActivities.clear() } - inline fun addSubActivity(block: () -> Activity) { - subActivities.add(block()) + fun Activity.addSubActivities(vararg activities: Activity) { + activities.forEach { it.owner = this } + subActivities.addAll(activities) } + fun noSubActivities() = subActivities.isEmpty() + override fun toString(): String { return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt index c48cc7e55..364d48b0f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt @@ -3,9 +3,9 @@ package com.lambda.client.manager.managers.activity.activities import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity -class SetState(private val activity: Activity, private val state: ActivityStatus) : Activity() { +class SetState(private val state: ActivityStatus) : Activity() { override fun SafeClientEvent.onInitialize() { - activity.activityStatus = state + owner.activityStatus = state activityStatus = ActivityStatus.SUCCESS } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt deleted file mode 100644 index 440e173de..000000000 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/DoWorkyActivity.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.client.manager.managers.activity.activities.example - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -class DoWorkyActivity : Activity() { - override fun SafeClientEvent.onInitialize() { - subActivities.add(FailingActivity()) - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt similarity index 74% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt index dbf2ff72c..a7e0c00f1 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/FailingActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt @@ -2,11 +2,9 @@ package com.lambda.client.manager.managers.activity.activities.example import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.ThrowableActivity -import java.lang.Exception import kotlin.random.Random -class FailingActivity : Activity() { +class Failing : Activity() { override fun SafeClientEvent.onInitialize() { activityStatus = if (Random.nextBoolean()) { ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt similarity index 70% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt index f1072d1c3..27f9c0929 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt @@ -4,10 +4,10 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -class SayAnnoyinglyActivity(private val message: String): InstantActivity, Activity() { +class SayAnnoyingly(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.split(" ").forEach { - subActivities.add(SayVeryAnnoyinglyActivity(it)) + addSubActivities(SayVeryAnnoyingly(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt similarity index 68% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt index 743cc26ee..df1fbfd9a 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyinglyActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt @@ -4,10 +4,10 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity -class SayVeryAnnoyinglyActivity(private val message: String): InstantActivity, Activity() { +class SayVeryAnnoyingly(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.forEach { - subActivities.add(WaitAndSayActivity(it.toString(), 1000)) + addSubActivities(WaitAndSay(it.toString(), 1000)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt similarity index 95% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt rename to src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt index 44aa693a8..fb29aff92 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSayActivity.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt @@ -5,7 +5,7 @@ import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.DelayedActivity import com.lambda.client.util.text.MessageSendHelper -class WaitAndSayActivity( +class WaitAndSay( private val message: String, override val delay: Long = 1000L, override var creationTime: Long = 0L diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt index 6656794fa..cb2b380bb 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt @@ -139,8 +139,10 @@ class BreakBlock( if (pickUpDrop) { color = ColorHolder(252, 3, 207) timeout = 10000L - subActivities.add(PickUpDrops(initState.block.item)) - subActivities.add(SetState(this@BreakBlock, ActivityStatus.SUCCESS)) + addSubActivities( + PickUpDrops(initState.block.item), + SetState(ActivityStatus.SUCCESS) + ) } else { activityStatus = ActivityStatus.SUCCESS } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt index 05f042889..42087e5b4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt @@ -38,7 +38,7 @@ class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activ safeListener { when (it.packet) { is SPacketOpenWindow -> { - subActivities.add(SetState(this@OpenContainer, ActivityStatus.SUCCESS)) + addSubActivities(SetState(ActivityStatus.SUCCESS)) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt index d7b564174..4f37e20ac 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt @@ -13,14 +13,16 @@ import net.minecraft.util.math.BlockPos class PlaceAndBreakBlock(private val block: Block) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(SwapOrMoveToItem(block.item)) - subActivities.add(PlaceBlock( - BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), - block - )) - subActivities.add(SwapOrMoveToItem(Items.DIAMOND_PICKAXE)) - subActivities.add(BreakBlock( - BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)) - )) + addSubActivities( + SwapOrMoveToItem(block.item), + PlaceBlock( + BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), + block + ), + SwapOrMoveToItem(Items.DIAMOND_PICKAXE), + BreakBlock( + BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)) + ) + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt index 89aeb3c5e..8193aac78 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt @@ -5,12 +5,12 @@ import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.allSlots -class DumpInventory() : InstantActivity, Activity() { +class DumpInventory : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } .forEach { - subActivities.add(DumpSlot(it)) + addSubActivities(DumpSlot(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt index 7455325af..69d9ed160 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt @@ -8,6 +8,6 @@ import net.minecraft.inventory.Slot class DumpSlot(private val slot: Slot) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransaction(0, slot.slotNumber, 1, ClickType.THROW)) + addSubActivities(InventoryTransaction(0, slot.slotNumber, 1, ClickType.THROW)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt index a4a454c6c..ee3059435 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot @@ -11,6 +12,6 @@ class SwapHotbarSlots( private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransaction(0, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) + addSubActivities(InventoryTransaction(0, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt index 6d3571255..6de4d469b 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.manager.managers.activity.activities.storage.ExtractItemFromShulkerBox @@ -19,9 +20,9 @@ class SwapOrMoveToItem( player.allSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) }?.let { slotFrom -> - subActivities.add(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) } ?: run { - subActivities.add(ExtractItemFromShulkerBox(item, 0, predicateItem, predicateSlot)) + addSubActivities(ExtractItemFromShulkerBox(item, 0, predicateItem, predicateSlot)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt index a1b50b1c7..b98ce7242 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -15,14 +15,16 @@ class SwapOrSwitchToSlot( ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { slot.toHotbarSlotOrNull()?.let { hotbarSlot -> - subActivities.add(SwitchToHotbarSlot(hotbarSlot)) + addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { val hotbarSlots = player.hotbarSlots val slotTo = hotbarSlots.firstEmpty() ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return - subActivities.add(SwapWithSlot(slot, slotTo)) - subActivities.add(SwitchToHotbarSlot(slotTo)) + addSubActivities( + SwapWithSlot(slot, slotTo), + SwitchToHotbarSlot(slotTo) + ) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt index 2101559b8..02d79ef2e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities.inventory import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.inventorySlots @@ -27,7 +28,7 @@ class SwapToBestTool(private val blockPos: BlockPos) : InstantActivity, Activity speed } }?.let { bestSlot -> - subActivities.add(SwapOrSwitchToSlot(bestSlot)) + addSubActivities(SwapOrSwitchToSlot(bestSlot)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt index 4f6910094..b39286db7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt @@ -12,6 +12,6 @@ class SwapWithSlot( private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - subActivities.add(InventoryTransaction(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) + addSubActivities(InventoryTransaction(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt index 123e51653..977c70bd7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -48,7 +48,7 @@ class ExtractItemFromShulkerBox( candidates.minBy { it.value }.key.let { slot -> getContainerPos()?.let { remotePos -> - subActivities.addAll(listOf( + addSubActivities( SwapOrSwitchToSlot(slot, predicateSlot), PlaceBlock(remotePos, slot.stack.item.block), OpenContainer(remotePos), @@ -62,7 +62,7 @@ class ExtractItemFromShulkerBox( mode = BreakBlock.Mode.PLAYER_CONTROLLER ), SwapOrMoveToItem(item, predicateItem, predicateSlot) - )) + ) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt index 45abdd54a..7086466aa 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities.storage import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.manager.managers.activity.activities.inventory.InventoryTransaction @@ -23,7 +24,7 @@ class PullItemsFromContainer( player.openContainer.inventorySlots.filter { slot -> slot.stack.item == item && predicateItem(slot.stack) }.take(take).forEach { - subActivities.add(InventoryTransaction( + addSubActivities(InventoryTransaction( player.openContainer.windowId, it.slotNumber, 0, diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt index a577071c7..15cc73bcb 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt @@ -17,7 +17,7 @@ class PickUpDrops( world.loadedEntityList.filterIsInstance().filter { it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) }.sortedBy { drop -> player.distanceTo(drop.positionVector) }.forEach { drop -> - subActivities.add(PickUpEntityItem(drop)) + addSubActivities(PickUpEntityItem(drop)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt index 9e197c069..1495c43ee 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers.activity.activities.travel import baritone.api.pathing.goals.GoalBlock +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.manager.managers.activity.activities.inventory.DumpSlot @@ -29,7 +30,7 @@ class PickUpEntityItem( player.inventorySlots.firstOrNull { slot -> InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> - subActivities.add(DumpSlot(slot)) + addSubActivities(DumpSlot(slot)) } } } else { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 93b422b7a..71ecaa564 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -2,8 +2,9 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.activities.example.FailingActivity -import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyinglyActivity +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.manager.managers.activity.activities.example.Failing +import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyingly import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventory import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.manager.managers.activity.activities.travel.PickUpDrops @@ -26,12 +27,14 @@ object TestActivityManager : Module( category = Category.MISC ) { private val a by setting("Get Dia Pickaxe", false, consumer = { _, _-> - ActivityManager.addActivity(SwapOrMoveToItem(Items.DIAMOND_PICKAXE)) + ActivityManager.addSubActivities( + SwapOrMoveToItem(Items.DIAMOND_PICKAXE) + ) false }) private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> - ActivityManager.addActivity( + ActivityManager.addSubActivities( SwapOrMoveToItem( Items.DIAMOND_PICKAXE, predicateItem = { @@ -47,12 +50,12 @@ object TestActivityManager : Module( }) private val dumpInventoryActivity by setting("Dump Inventory", false, consumer = { _, _-> - ActivityManager.addActivity(DumpInventory()) + ActivityManager.addSubActivities(DumpInventory()) false }) private val po by setting("Pickup Obby", false, consumer = { _, _-> - ActivityManager.addActivity(PickUpDrops(Blocks.OBSIDIAN.item)) + ActivityManager.addSubActivities(PickUpDrops(Blocks.OBSIDIAN.item)) false }) @@ -65,12 +68,12 @@ object TestActivityManager : Module( }) private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> - ActivityManager.addActivity(SayAnnoyinglyActivity("Hello World")) + ActivityManager.addSubActivities(SayAnnoyingly("Hello World")) false }) private val fail by setting("maybe fail", false, consumer = { _, _-> - ActivityManager.addActivity(FailingActivity()) + ActivityManager.addSubActivities(Failing()) false }) From 1e6065a73d6f6e34bece0c2208b87216037e1f7f Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 22 Dec 2022 19:17:54 +0100 Subject: [PATCH 017/104] Move package --- .../managers => }/activity/Activity.kt | 136 ++++++++++-------- .../activity/activities/ActivityTypes.kt | 4 +- .../activity/activities/SetState.kt | 4 +- .../managers => }/activity/activities/Wait.kt | 4 +- .../activity/activities/example/Failing.kt | 4 +- .../activities/example/SayAnnoyingly.kt | 6 +- .../activities/example/SayVeryAnnoyingly.kt | 6 +- .../activity/activities/example/WaitAndSay.kt | 7 +- .../activities/interaction/BreakBlock.kt | 14 +- .../activities/interaction/CloseContainer.kt | 6 +- .../activities/interaction/LookAtBlock.kt | 4 +- .../activities/interaction/OpenContainer.kt | 12 +- .../interaction/PlaceAndBreakBlock.kt | 8 +- .../activities/interaction/PlaceBlock.kt | 10 +- .../activities/inventory/DumpInventory.kt | 6 +- .../activity/activities/inventory/DumpSlot.kt | 6 +- .../inventory/InventoryTransaction.kt | 8 +- .../activities/inventory/SwapHotbarSlots.kt | 6 +- .../activities/inventory/SwapOrMoveToItem.kt | 8 +- .../inventory/SwapOrSwitchToSlot.kt | 6 +- .../activities/inventory/SwapToBestTool.kt | 6 +- .../activities/inventory/SwapWithSlot.kt | 6 +- .../inventory/SwitchToHotbarSlot.kt | 6 +- .../inventory/SwitchToItemInHotbar.kt | 4 +- .../storage/ExtractItemFromShulkerBox.kt | 22 +-- .../storage/PullItemsFromContainer.kt | 9 +- .../activity/activities/travel/CustomGoal.kt | 6 +- .../activity/activities/travel/PickUpDrops.kt | 6 +- .../activities/travel/PickUpEntityItem.kt | 9 +- .../lambda/client/event/ListenerManager.kt | 4 +- .../elements/misc/ActivityManagerHud.kt | 13 +- .../manager/managers/ActivityManager.kt | 22 ++- .../modules/misc/TestActivityManager.kt | 10 +- 33 files changed, 213 insertions(+), 175 deletions(-) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/Activity.kt (51%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/ActivityTypes.kt (84%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/SetState.kt (67%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/Wait.kt (69%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/example/Failing.kt (70%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/example/SayAnnoyingly.kt (57%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/example/SayVeryAnnoyingly.kt (57%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/example/WaitAndSay.kt (64%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/BreakBlock.kt (91%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/CloseContainer.kt (52%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/LookAtBlock.kt (86%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/OpenContainer.kt (81%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/PlaceAndBreakBlock.kt (74%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/interaction/PlaceBlock.kt (89%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/DumpInventory.kt (62%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/DumpSlot.kt (61%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/InventoryTransaction.kt (91%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwapHotbarSlots.kt (70%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwapOrMoveToItem.kt (75%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwapOrSwitchToSlot.kt (81%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwapToBestTool.kt (84%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwapWithSlot.kt (68%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwitchToHotbarSlot.kt (64%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/inventory/SwitchToItemInHotbar.kt (51%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/storage/ExtractItemFromShulkerBox.kt (81%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/storage/PullItemsFromContainer.kt (72%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/travel/CustomGoal.kt (78%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/travel/PickUpDrops.kt (79%) rename src/main/kotlin/com/lambda/client/{manager/managers => }/activity/activities/travel/PickUpEntityItem.kt (80%) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt similarity index 51% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt rename to src/main/kotlin/com/lambda/client/activity/Activity.kt index 4eee0bf5d..3cee8db27 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,13 +1,18 @@ -package com.lambda.client.manager.managers.activity +package com.lambda.client.activity import com.lambda.client.LambdaMod -import com.lambda.client.event.LambdaEventBus +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.DelayedActivity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager -import com.lambda.client.manager.managers.activity.activities.* +import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque @@ -15,6 +20,7 @@ abstract class Activity { private val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED var owner: Activity = ActivityManager + var depth = 0 enum class ActivityStatus { UNINITIALIZED, @@ -23,71 +29,58 @@ abstract class Activity { FAILURE } - fun SafeClientEvent.updateActivities() { + fun SafeClientEvent.updateActivity() { when (activityStatus) { ActivityStatus.UNINITIALIZED -> { initialize() + updateActivity() } ActivityStatus.RUNNING -> { - subActivities.peek()?.let { - with(it) { - when (it.activityStatus) { - ActivityStatus.SUCCESS -> { - finalize(this@Activity) - } - ActivityStatus.FAILURE -> { - subActivities.remove(it) - LambdaMod.LOG.error("Activity failed: $it") - } - else -> { - updateActivities() - } - } - } - } ?: run { - if (this@Activity is TimeoutActivity) { - if (System.currentTimeMillis() > creationTime + timeout) { - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("TimedActivity fully timed out!") - } else { - usedAttempts++ - initialize() - LambdaMod.LOG.error("TimedActivity timed out!") - } - } else { + if (this@Activity is TimeoutActivity) { + if (System.currentTimeMillis() > creationTime + timeout) { + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE LambdaMod.LOG.error("TimedActivity fully timed out!") + } else { + usedAttempts++ + initialize() + LambdaMod.LOG.error("TimedActivity timed out!") } + } else { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("TimedActivity fully timed out!") } } - if (this@Activity is InstantActivity) { - activityStatus = ActivityStatus.SUCCESS - } - if (this@Activity is DelayedActivity) { - if (System.currentTimeMillis() > creationTime + delay) { - onDelayedActivity() - } + } + if (this@Activity is InstantActivity) { + activityStatus = ActivityStatus.SUCCESS + } + if (this@Activity is DelayedActivity) { + if (System.currentTimeMillis() > creationTime + delay) { + onDelayedActivity() } - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") - } + } + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") } } } ActivityStatus.SUCCESS -> { - // do nothing + finalize() + LambdaMod.LOG.info("${this@Activity} activity finished successfully!") } ActivityStatus.FAILURE -> { - finalize(this@Activity) + finalize() + LambdaMod.LOG.error("Activity ${this@Activity} failed!") } } } private fun SafeClientEvent.initialize() { + activityStatus = ActivityStatus.RUNNING if (this@Activity is TimeoutActivity) { creationTime = System.currentTimeMillis() } @@ -95,35 +88,51 @@ abstract class Activity { creationTime = System.currentTimeMillis() } onInitialize() - activityStatus = ActivityStatus.RUNNING - LambdaEventBus.subscribe(this@Activity) LambdaMod.LOG.info("Initialized activity: ${this@Activity}") } open fun SafeClientEvent.onInitialize() {} - private fun SafeClientEvent.finalize(owner: Activity) { + private fun SafeClientEvent.finalize() { onFinalize() - owner.subActivities.pop() - LambdaEventBus.unsubscribe(this@Activity) + owner.subActivities.remove(this@Activity) LambdaMod.LOG.info("Finalized activity: ${this@Activity}") } open fun SafeClientEvent.onFinalize() {} - - fun currentActivity(): Activity { - return subActivities.peek()?.currentActivity() ?: this - } + fun currentActivity(): Activity = subActivities.peek()?.currentActivity() ?: this fun reset() { - LambdaEventBus.unsubscribe(currentActivity()) + LambdaMod.LOG.info("Resetting activity: ${this@Activity::class.simpleName}" ) +// LambdaEventBus.unsubscribe(currentActivity()) + ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager }.forEach { + ListenerManager.unregister(it) + LambdaMod.LOG.info("Unsubscribed ${it::class.simpleName}") + } BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() } - fun Activity.addSubActivities(vararg activities: Activity) { - activities.forEach { it.owner = this } + fun Activity.addSubActivities(activities: List) { + if (activities.isEmpty()) return + + if (depth > MAX_DEPTH) { + MessageSendHelper.sendErrorMessage("Activity depth exceeded $MAX_DEPTH!") + ActivityManager.reset() + return + } + + activities.forEach { + it.owner = this + it.depth = depth + 1 + } subActivities.addAll(activities) + + LambdaMod.LOG.info("Added ${activities.size} sub activities to ${this::class.simpleName}") + } + + fun Activity.addSubActivities(vararg activities: Activity) { + addSubActivities(activities.toList()) } fun noSubActivities() = subActivities.isEmpty() @@ -134,8 +143,14 @@ abstract class Activity { open fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) {} - fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder, depth: Int) { + fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { if (this !is ActivityManager) { + ListenerManager.listenerMap[this@Activity]?.let { + textComponent.add("SYNC", secondaryColor) + } + ListenerManager.asyncListenerMap[this@Activity]?.let { + textComponent.add("ASYNC", secondaryColor) + } textComponent.add("Name", primaryColor) textComponent.add("${javaClass.simpleName} ", secondaryColor) textComponent.add("State", primaryColor) @@ -149,11 +164,12 @@ abstract class Activity { } textComponent.addLine("") } + addExtraInfo(textComponent, primaryColor, secondaryColor) subActivities.forEach { repeat(depth) { textComponent.add(" ") } - it.appendInfo(textComponent, primaryColor, secondaryColor, depth + 1) + it.appendInfo(textComponent, primaryColor, secondaryColor) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt similarity index 84% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt rename to src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index b7d25e2c9..3b0c45c92 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities +package com.lambda.client.activity.activities +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.color.ColorHolder import net.minecraft.util.math.BlockPos diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/SetState.kt similarity index 67% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt rename to src/main/kotlin/com/lambda/client/activity/activities/SetState.kt index 364d48b0f..4b29b111e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/SetState.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/SetState.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities +package com.lambda.client.activity.activities +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity class SetState(private val state: ActivityStatus) : Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/Wait.kt similarity index 69% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt rename to src/main/kotlin/com/lambda/client/activity/activities/Wait.kt index 47345e93d..7da075bab 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/Wait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/Wait.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities +package com.lambda.client.activity.activities +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity class Wait( override val delay: Long, diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt similarity index 70% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt rename to src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt index a7e0c00f1..755530de0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/Failing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities.example +package com.lambda.client.activity.activities.example +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity import kotlin.random.Random class Failing : Activity() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt similarity index 57% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt rename to src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt index 27f9c0929..33a213d33 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.example +package com.lambda.client.activity.activities.example +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity class SayAnnoyingly(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt similarity index 57% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt rename to src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt index df1fbfd9a..b70a4e838 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/SayVeryAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.example +package com.lambda.client.activity.activities.example +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity class SayVeryAnnoyingly(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt similarity index 64% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt rename to src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt index fb29aff92..4e112a729 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/example/WaitAndSay.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.example +package com.lambda.client.activity.activities.example +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.DelayedActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.DelayedActivity import com.lambda.client.util.text.MessageSendHelper class WaitAndSay( @@ -12,5 +12,6 @@ class WaitAndSay( ): DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) + activityStatus = ActivityStatus.SUCCESS } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index cb2b380bb..b8f37af0d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,13 +1,13 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.SetState +import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.AttemptActivity -import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity -import com.lambda.client.manager.managers.activity.activities.SetState -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity -import com.lambda.client.manager.managers.activity.activities.travel.PickUpDrops import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.item import com.lambda.client.util.math.RotationUtils.getRotationTo diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt similarity index 52% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt index 99a4ff874..173f2f673 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/CloseContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity class CloseContainer : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt similarity index 86% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt index 6a9d8ec6b..24d4b0118 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/LookAtBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.world.getHitVec diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt similarity index 81% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 42087e5b4..a2ba3cb45 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,11 +1,11 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.SetState -import com.lambda.client.manager.managers.activity.activities.Wait import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener @@ -14,10 +14,10 @@ import com.lambda.client.util.world.getHitVecOffset import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketOpenWindow -import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt similarity index 74% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt index 4f37e20ac..594251433 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceAndBreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt @@ -1,9 +1,9 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.items.item import com.lambda.client.util.math.Direction diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt similarity index 89% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index b449ab4c0..8170ab678 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,11 +1,11 @@ -package com.lambda.client.manager.managers.activity.activities.interaction +package com.lambda.client.activity.activities.interaction +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.AttemptActivity -import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.RotationUtils.getRotationTo diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt similarity index 62% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt index 8193aac78..e41a3e0fc 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpInventory.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.allSlots class DumpInventory : InstantActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt similarity index 61% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt index 69d9ed160..89aacd30d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/DumpSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index f065fec94..20acd1e0e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -1,11 +1,11 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.AttemptActivity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity import com.lambda.client.util.threads.safeListener import net.minecraft.inventory.ClickType import net.minecraft.inventory.Container diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt similarity index 70% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt index ee3059435..de9f1e0e4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt @@ -1,9 +1,9 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt similarity index 75% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 6de4d469b..99208801e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -1,10 +1,10 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.util.items.* import net.minecraft.item.Item import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt similarity index 81% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt index b98ce7242..98a0ef809 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.firstEmpty import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.toHotbarSlotOrNull diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt similarity index 84% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt index 02d79ef2e..a41ee1aee 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt @@ -1,9 +1,9 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.inventorySlots import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt similarity index 68% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index b39286db7..e7186085c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt similarity index 64% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt index 6b4edf4f7..8d4e623b5 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToHotbarSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.items.HotbarSlot class SwitchToHotbarSlot(private val slot: HotbarSlot) : InstantActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt similarity index 51% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt index f05108457..ed8fa0c8f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/inventory/SwitchToItemInHotbar.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt @@ -1,7 +1,7 @@ -package com.lambda.client.manager.managers.activity.activities.inventory +package com.lambda.client.activity.activities.inventory +import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity class SwitchToItemInHotbar: Activity() { override fun SafeClientEvent.onInitialize() {} diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt similarity index 81% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 977c70bd7..f94aedd7c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,16 +1,16 @@ -package com.lambda.client.manager.managers.activity.activities.storage +package com.lambda.client.activity.activities.storage +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.Wait +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.CloseContainer +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.Wait -import com.lambda.client.manager.managers.activity.activities.interaction.BreakBlock -import com.lambda.client.manager.managers.activity.activities.interaction.CloseContainer -import com.lambda.client.manager.managers.activity.activities.interaction.OpenContainer -import com.lambda.client.manager.managers.activity.activities.interaction.PlaceBlock -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.manager.managers.activity.activities.inventory.SwapToBestTool import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block import com.lambda.client.util.math.VectorUtils diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt similarity index 72% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 7086466aa..107c8fdb4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -1,10 +1,9 @@ -package com.lambda.client.manager.managers.activity.activities.storage +package com.lambda.client.activity.activities.storage +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.inventory.InventoryTransaction import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity -import com.lambda.client.manager.managers.activity.activities.inventory.InventoryTransaction import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import net.minecraft.inventory.ClickType diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt similarity index 78% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt rename to src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index cbc7215e5..c89405c4a 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.travel +package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.Goal -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.TimeoutActivity import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt similarity index 79% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt rename to src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 15cc73bcb..6d3b37de0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -1,8 +1,8 @@ -package com.lambda.client.manager.managers.activity.activities.travel +package com.lambda.client.activity.activities.travel +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.InstantActivity import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem import net.minecraft.item.Item diff --git a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt similarity index 80% rename from src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt rename to src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 1495c43ee..d2ba0524e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -1,10 +1,9 @@ -package com.lambda.client.manager.managers.activity.activities.travel +package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock -import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.TimeoutActivity -import com.lambda.client.manager.managers.activity.activities.inventory.DumpSlot +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.inventory.DumpSlot import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.inventorySlots diff --git a/src/main/kotlin/com/lambda/client/event/ListenerManager.kt b/src/main/kotlin/com/lambda/client/event/ListenerManager.kt index 4ef7a8ba4..f78fbf2c4 100644 --- a/src/main/kotlin/com/lambda/client/event/ListenerManager.kt +++ b/src/main/kotlin/com/lambda/client/event/ListenerManager.kt @@ -10,9 +10,9 @@ import java.util.concurrent.CopyOnWriteArrayList */ object ListenerManager { - private val listenerMap = ConcurrentHashMap>>() + val listenerMap = ConcurrentHashMap>>() - private val asyncListenerMap = ConcurrentHashMap>>() + val asyncListenerMap = ConcurrentHashMap>>() /** * Register the [listener] to the [ListenerManager] diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index d46503234..b9965d074 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -1,5 +1,7 @@ package com.lambda.client.gui.hudgui.elements.misc +import com.lambda.client.activity.Activity +import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.LabelHud import com.lambda.client.manager.managers.ActivityManager @@ -12,6 +14,15 @@ internal object ActivityManagerHud: LabelHud( override fun SafeClientEvent.updateText() { if (ActivityManager.noSubActivities()) return - ActivityManager.appendInfo(displayText, primaryColor, secondaryColor, 0) + ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) + + displayText.addLine("") + displayText.addLine("Subscribers:") + ListenerManager.listenerMap.keys.filterIsInstance().forEach { + displayText.addLine("${it::class.simpleName}") + } + ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { + displayText.addLine("${it::class.simpleName}") + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index bd56edb05..6f293baad 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,21 +1,33 @@ package com.lambda.client.manager.managers +import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager -import com.lambda.client.manager.managers.activity.Activity -import com.lambda.client.manager.managers.activity.activities.RenderBlockActivity import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() + const val MAX_DEPTH = 25 init { - safeListener { - if (noSubActivities() || it.phase != TickEvent.Phase.START) return@safeListener + safeListener { event -> + if (noSubActivities() || event.phase != TickEvent.Phase.START) return@safeListener - updateActivities() + val currentActivity = currentActivity() + +// ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager && it != currentActivity }.forEach { +// ListenerManager.unregister(it) +// LambdaMod.LOG.info("Unsubscribed ${it::class.simpleName}") +// } + + with(currentActivity) { + updateActivity() + } } safeListener { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 71ecaa564..24f6a1da8 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,13 +1,13 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod +import com.lambda.client.activity.activities.example.Failing +import com.lambda.client.activity.activities.example.SayAnnoyingly +import com.lambda.client.activity.activities.inventory.DumpInventory +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.activity.activities.example.Failing -import com.lambda.client.manager.managers.activity.activities.example.SayAnnoyingly -import com.lambda.client.manager.managers.activity.activities.inventory.DumpInventory -import com.lambda.client.manager.managers.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.manager.managers.activity.activities.travel.PickUpDrops import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.items.block From 3df5d25c4086b4a999f3d7ecd24f9aed8b557cc2 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 22 Dec 2022 20:29:56 +0100 Subject: [PATCH 018/104] Test case for listener --- .../activities/example/ListenAndWait.kt | 31 +++++++++++++++++++ .../activities/example/SayVeryAnnoyingly.kt | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt new file mode 100644 index 000000000..e42c8de13 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -0,0 +1,31 @@ +package com.lambda.client.activity.activities.example + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.event.LambdaEventBus +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.text.MessageSendHelper +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +class ListenAndWait( + private val message: String, + override val timeout: Long, + override var creationTime: Long = 0L +) : TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + LambdaEventBus.subscribe(this@ListenAndWait) + } + + override fun SafeClientEvent.onFinalize() { + LambdaEventBus.unsubscribe(this@ListenAndWait) + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + MessageSendHelper.sendChatMessage(message) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt index b70a4e838..f7bf029bb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt @@ -7,7 +7,7 @@ import com.lambda.client.event.SafeClientEvent class SayVeryAnnoyingly(private val message: String): InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.forEach { - addSubActivities(WaitAndSay(it.toString(), 1000)) + addSubActivities(ListenAndWait(it.toString(), 250)) } } } \ No newline at end of file From fd209911f733eaad7847b93c2aca88af79f31bed Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 22 Dec 2022 20:55:31 +0100 Subject: [PATCH 019/104] Fix for listening objects --- .../client/manager/managers/ActivityManager.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 6f293baad..2e0060fac 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,8 +1,8 @@ package com.lambda.client.manager.managers -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager @@ -13,6 +13,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 + private var lastActivity: Activity = this init { safeListener { event -> @@ -20,12 +21,15 @@ object ActivityManager : Manager, Activity() { val currentActivity = currentActivity() -// ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager && it != currentActivity }.forEach { -// ListenerManager.unregister(it) -// LambdaMod.LOG.info("Unsubscribed ${it::class.simpleName}") -// } - with(currentActivity) { + if (currentActivity != lastActivity) { + if (lastActivity !is ActivityManager) { + LambdaEventBus.unsubscribe(lastActivity) + ListenerManager.unregister(lastActivity) + } + LambdaEventBus.subscribe(currentActivity) + lastActivity = currentActivity + } updateActivity() } } From 79ee5d3ea3857c1a640911dbb07946c25898e2a2 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 22 Dec 2022 22:52:04 +0100 Subject: [PATCH 020/104] Added BreakDownEnderChests --- .../com/lambda/client/activity/Activity.kt | 2 + .../activity/activities/ActivityUtils.kt | 55 ++++++++++++++++++ .../activities/example/ListenAndWait.kt | 10 ---- .../highlevel/BreakDownEnderChests.kt | 48 +++++++++++++++ .../activities/interaction/OpenContainer.kt | 1 - .../storage/ExtractItemFromShulkerBox.kt | 47 ++------------- .../storage/PushItemsToContainer.kt | 49 ++++++++++++++++ .../storage/StoreItemToShulkerBox.kt | 58 +++++++++++++++++++ .../modules/misc/TestActivityManager.kt | 24 ++++++++ .../module/modules/player/NoGhostItems.kt | 2 + 10 files changed, 244 insertions(+), 52 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 3cee8db27..2eb9f26d8 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -5,6 +5,7 @@ import com.lambda.client.activity.activities.AttemptActivity import com.lambda.client.activity.activities.DelayedActivity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager @@ -107,6 +108,7 @@ abstract class Activity { // LambdaEventBus.unsubscribe(currentActivity()) ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager }.forEach { ListenerManager.unregister(it) + LambdaEventBus.unsubscribe(it) LambdaMod.LOG.info("Unsubscribed ${it::class.simpleName}") } BaritoneUtils.primary?.pathingBehavior?.cancelEverything() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt new file mode 100644 index 000000000..9d29afcfa --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt @@ -0,0 +1,55 @@ +package com.lambda.client.activity.activities + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.world.getVisibleSides +import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.isReplaceable +import net.minecraft.inventory.ItemStackHelper +import net.minecraft.item.ItemShulkerBox +import net.minecraft.item.ItemStack +import net.minecraft.util.EnumFacing +import net.minecraft.util.NonNullList +import net.minecraft.util.math.BlockPos + +fun getShulkerInventory(stack: ItemStack): NonNullList? { + if (stack.item !is ItemShulkerBox) return null + + val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) + + stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { + if (it.hasKey("Items", 9)) { + ItemStackHelper.loadAllItems(it, shulkerInventory) + return shulkerInventory + } + } + + return shulkerInventory +} + +fun SafeClientEvent.getContainerPos(): BlockPos? { + return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() + .filter { pos -> + world.isPlaceable(pos) + && !world.getBlockState(pos.down()).isReplaceable + && world.isAirBlock(pos.up()) + && getVisibleSides(pos.down()).contains(EnumFacing.UP) + && pos.y >= player.positionVector.y + }.sortedWith( + compareByDescending { + secureScore(it) + }.thenBy { + player.positionVector.distanceTo(it.toVec3dCenter()) + } + ).firstOrNull() +} + +fun SafeClientEvent.secureScore(pos: BlockPos): Int { + var safe = 0 + if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ + return safe +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt index e42c8de13..623147530 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -2,8 +2,6 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.TimeoutActivity -import com.lambda.client.event.LambdaEventBus -import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent @@ -13,14 +11,6 @@ class ListenAndWait( override val timeout: Long, override var creationTime: Long = 0L ) : TimeoutActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - LambdaEventBus.subscribe(this@ListenAndWait) - } - - override fun SafeClientEvent.onFinalize() { - LambdaEventBus.unsubscribe(this@ListenAndWait) - } - init { safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt new file mode 100644 index 000000000..c5b8c3823 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -0,0 +1,48 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.SetState +import com.lambda.client.activity.activities.getContainerPos +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.item +import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.init.Blocks +import net.minecraft.init.Enchantments +import net.minecraft.init.Items + +class BreakDownEnderChests( + +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + getContainerPos()?.let { remotePos -> + if (player.inventorySlots.countEmpty() == 0) { + addSubActivities( + StoreItemToShulkerBox(Blocks.OBSIDIAN.item), + SetState(ActivityStatus.UNINITIALIZED) + ) + } else { + addSubActivities( + SwapOrMoveToItem(Blocks.ENDER_CHEST.item), + PlaceBlock(remotePos, Blocks.ENDER_CHEST), + SwapOrMoveToItem(Items.DIAMOND_PICKAXE, predicateItem = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 }), +// SwapToBestTool(remotePos), + BreakBlock( + remotePos, + pickUpDrop = true, + mode = BreakBlock.Mode.PLAYER_CONTROLLER + ), + SetState(ActivityStatus.UNINITIALIZED) + ) + } + } + + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index a2ba3cb45..6a5ba40a9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,6 +1,5 @@ package com.lambda.client.activity.activities.interaction -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.SetState diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index f94aedd7c..b37a774f3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -3,6 +3,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.Wait +import com.lambda.client.activity.activities.getContainerPos +import com.lambda.client.activity.activities.getShulkerInventory import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer @@ -13,6 +15,7 @@ import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block +import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.world.getVisibleSides @@ -29,11 +32,13 @@ import net.minecraft.util.math.BlockPos class ExtractItemFromShulkerBox( private val item: Item, - private val amount: Int, // 0 = all + private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { +// if (player.inventorySlots.item) + val candidates = mutableMapOf() player.allSlots.forEach { slot -> @@ -66,44 +71,4 @@ class ExtractItemFromShulkerBox( } } } - - private fun getShulkerInventory(stack: ItemStack): NonNullList? { - if (stack.item !is ItemShulkerBox) return null - - stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { - if (it.hasKey("Items", 9)) { - val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) - ItemStackHelper.loadAllItems(it, shulkerInventory) - return shulkerInventory - } - } - - return null - } - - private fun SafeClientEvent.getContainerPos(): BlockPos? { - return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() - .filter { pos -> - world.isPlaceable(pos) - && !world.getBlockState(pos.down()).isReplaceable - && world.isAirBlock(pos.up()) - && getVisibleSides(pos.down()).contains(EnumFacing.UP) - && pos.y >= player.positionVector.y - }.sortedWith( - compareByDescending { - secureScore(it) - }.thenBy { - player.positionVector.distanceTo(it.toVec3dCenter()) - } - ).firstOrNull() - } - - private fun SafeClientEvent.secureScore(pos: BlockPos): Int { - var safe = 0 - if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ - return safe - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt new file mode 100644 index 000000000..519dd3e8d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -0,0 +1,49 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.inventory.InventoryTransaction +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.getSlots +import com.lambda.client.util.items.inventorySlots +import net.minecraft.inventory.ClickType +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class PushItemsToContainer( + private val item: Item, + private val amount: Int = 0, // 0 = all + private val predicateItem: (ItemStack) -> Boolean = { true } +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { +// val maxEmpty = player.openContainer.inventorySlots.countEmpty() +// +// val store = if (amount > 0) amount.coerceAtMost(maxEmpty) else maxEmpty + +// player.openContainer.getSlots(0..26) +// player.openContainer.getSlots(27..62) + + player.openContainer.getSlots(27..62).filter { slot -> + slot.stack.item == item && predicateItem(slot.stack) + }.forEach { + addSubActivities(InventoryTransaction( + player.openContainer.windowId, + it.slotNumber, + 0, + ClickType.QUICK_MOVE + )) + } + +// player.inventorySlots.filter { slot -> +// slot.stack.item == item && predicateItem(slot.stack) +// }.take(store).forEach { +// addSubActivities(InventoryTransaction( +// player.openContainer.windowId, +// it.slotNumber, +// 0, +// ClickType.QUICK_MOVE +// )) +// } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt new file mode 100644 index 000000000..8a49c24e6 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -0,0 +1,58 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.CloseContainer +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.block +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class StoreItemToShulkerBox( + private val item: Item, + private val amount: Int = 0, // 0 = all + private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true } +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + val candidates = mutableMapOf() + + player.allSlots.forEach { slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + if (inventory.all { it.item == item || it.isEmpty }) { + candidates[slot] = inventory.count { it.item == item && predicateItem(it) } + } + } + } + + if (candidates.isEmpty()) return + + candidates.maxBy { it.value }.key.let { slot -> + getContainerPos()?.let { remotePos -> + addSubActivities( + SwapOrSwitchToSlot(slot, predicateSlot), + PlaceBlock(remotePos, slot.stack.item.block), + OpenContainer(remotePos), + Wait(50L), + PushItemsToContainer(item, amount, predicateItem), + CloseContainer(), + SwapToBestTool(remotePos), + BreakBlock( + remotePos, + pickUpDrop = true, + mode = BreakBlock.Mode.PLAYER_CONTROLLER + ), + SwapOrMoveToItem(item, predicateItem, predicateSlot) + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 24f6a1da8..3059e1d1c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -3,8 +3,11 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.Failing import com.lambda.client.activity.activities.example.SayAnnoyingly +import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities @@ -33,6 +36,27 @@ object TestActivityManager : Module( false }) + private val tie by setting("Store Obby", false, consumer = { _, _-> + ActivityManager.addSubActivities( + StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + ) + false + }) + + private val ctiectie by setting("Auto Obby", false, consumer = { _, _-> + ActivityManager.addSubActivities( + BreakDownEnderChests() + ) + false + }) + + private val etit by setting("Extract Obby", false, consumer = { _, _-> + ActivityManager.addSubActivities( + ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item) + ) + false + }) + private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> ActivityManager.addSubActivities( SwapOrMoveToItem( diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/NoGhostItems.kt b/src/main/kotlin/com/lambda/client/module/modules/player/NoGhostItems.kt index 1fabbde5b..355925cbf 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/NoGhostItems.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/NoGhostItems.kt @@ -5,6 +5,7 @@ import com.lambda.client.manager.managers.PlayerInventoryManager import com.lambda.client.manager.managers.PlayerInventoryManager.addInventoryTask import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import com.lambda.mixin.player.MixinPlayerControllerMP @@ -30,6 +31,7 @@ object NoGhostItems : Module( init { safeListener { + MessageSendHelper.sendChatMessage("${it.windowId} ${it.slotId} ${it.mouseButton} ${it.type}") if (syncMode == SyncMode.MODULES) return@safeListener addInventoryTask(PlayerInventoryManager.ClickInfo(it.windowId, it.slotId, it.mouseButton, it.type)) From b74af7331b34a8d329ac7c7a259a5e488b98a5dc Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 23 Dec 2022 00:51:45 +0100 Subject: [PATCH 021/104] Cleanup --- .../activities/example/SayAnnoyingly.kt | 2 +- .../activities/example/SayVeryAnnoyingly.kt | 2 +- .../activity/activities/example/WaitAndSay.kt | 2 +- .../highlevel/BreakDownEnderChests.kt | 12 +++++---- .../activities/interaction/BreakBlock.kt | 7 +++-- .../activities/interaction/OpenContainer.kt | 1 - .../activities/inventory/SwapHotbarSlots.kt | 1 - .../activities/inventory/SwapOrMoveToItem.kt | 26 ++++++++++++++----- .../activities/inventory/SwapToBestTool.kt | 1 - .../inventory/SwitchToItemInHotbar.kt | 2 +- .../storage/ExtractItemFromShulkerBox.kt | 11 -------- .../storage/PushItemsToContainer.kt | 20 -------------- .../storage/StoreItemToShulkerBox.kt | 11 ++++---- .../activity/activities/travel/PickUpDrops.kt | 16 +++++++++--- .../activities/travel/PickUpEntityItem.kt | 10 ++++--- .../modules/misc/TestActivityManager.kt | 2 +- 16 files changed, 60 insertions(+), 66 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt index 33a213d33..a5c907558 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -class SayAnnoyingly(private val message: String): InstantActivity, Activity() { +class SayAnnoyingly(private val message: String) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.split(" ").forEach { addSubActivities(SayVeryAnnoyingly(it)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt index f7bf029bb..f92a0ac93 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -class SayVeryAnnoyingly(private val message: String): InstantActivity, Activity() { +class SayVeryAnnoyingly(private val message: String) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { message.forEach { addSubActivities(ListenAndWait(it.toString(), 250)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt index 4e112a729..5ae5f57da 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt @@ -9,7 +9,7 @@ class WaitAndSay( private val message: String, override val delay: Long = 1000L, override var creationTime: Long = 0L -): DelayedActivity, Activity() { +) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) activityStatus = ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index c5b8c3823..201794137 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -7,7 +7,6 @@ import com.lambda.client.activity.activities.getContainerPos import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty @@ -18,9 +17,7 @@ import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items -class BreakDownEnderChests( - -) : InstantActivity, Activity() { +class BreakDownEnderChests : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { remotePos -> if (player.inventorySlots.countEmpty() == 0) { @@ -32,7 +29,12 @@ class BreakDownEnderChests( addSubActivities( SwapOrMoveToItem(Blocks.ENDER_CHEST.item), PlaceBlock(remotePos, Blocks.ENDER_CHEST), - SwapOrMoveToItem(Items.DIAMOND_PICKAXE, predicateItem = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 }), + SwapOrMoveToItem( + Items.DIAMOND_PICKAXE, + predicateItem = { + EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 + } + ), // SwapToBestTool(remotePos), BreakBlock( remotePos, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index b8f37af0d..d6db26957 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -9,7 +9,6 @@ import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.item import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec @@ -22,6 +21,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.* import kotlin.math.ceil class BreakBlock( @@ -52,6 +52,7 @@ class BreakBlock( color = ColorHolder(16, 74, 94) } else { ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + timeout = ticksNeeded * 50L + 100L } } @@ -84,8 +85,6 @@ class BreakBlock( finish() } } else { - timeout = ticksNeeded * 50L + 100L - playerController.onPlayerDamageBlock(blockPos, side) player.swingArm(EnumHand.MAIN_HAND) // cancel onPlayerDestroy NoGhostBlocks @@ -140,7 +139,7 @@ class BreakBlock( color = ColorHolder(252, 3, 207) timeout = 10000L addSubActivities( - PickUpDrops(initState.block.item), + PickUpDrops(initState.block.getItemDropped(initState, Random(), 0)), SetState(ActivityStatus.SUCCESS) ) } else { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 6a5ba40a9..7a6825925 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -16,7 +16,6 @@ import net.minecraft.network.play.server.SPacketOpenWindow import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt index de9f1e0e4..6871b65a2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 99208801e..68528d3d3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -4,8 +4,9 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.util.items.* +import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -13,16 +14,27 @@ class SwapOrMoveToItem( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, - private val useShulkerBoxes: Boolean = false, + private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.allSlots.firstOrNull { slot -> + player.hotbarSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) - }?.let { slotFrom -> - addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + }?.let { + addSubActivities(SwitchToHotbarSlot(it)) } ?: run { - addSubActivities(ExtractItemFromShulkerBox(item, 0, predicateItem, predicateSlot)) + player.allSlots.firstOrNull { slot -> + slot.stack.item == item && predicateItem(slot.stack) + }?.let { slotFrom -> + addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + } ?: run { + if (useShulkerBoxes) { + addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) + } else { + activityStatus = ActivityStatus.FAILURE + MessageSendHelper.sendErrorMessage("No $item found in inventory (shulkers are disabled)") + } + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt index a41ee1aee..a8440b0bd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.util.items.inventorySlots import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt index ed8fa0c8f..16a9a6b96 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt @@ -3,6 +3,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -class SwitchToItemInHotbar: Activity() { +class SwitchToItemInHotbar : Activity() { override fun SafeClientEvent.onInitialize() {} } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index b37a774f3..7fa8d7c13 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -15,20 +15,9 @@ import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block -import com.lambda.client.util.items.inventorySlots -import com.lambda.client.util.math.VectorUtils -import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import com.lambda.client.util.world.getVisibleSides -import com.lambda.client.util.world.isPlaceable -import com.lambda.client.util.world.isReplaceable -import net.minecraft.inventory.ItemStackHelper import net.minecraft.inventory.Slot import net.minecraft.item.Item -import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack -import net.minecraft.util.EnumFacing -import net.minecraft.util.NonNullList -import net.minecraft.util.math.BlockPos class ExtractItemFromShulkerBox( private val item: Item, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index 519dd3e8d..2afc85657 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -4,9 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.inventory.InventoryTransaction import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots -import com.lambda.client.util.items.inventorySlots import net.minecraft.inventory.ClickType import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -17,13 +15,6 @@ class PushItemsToContainer( private val predicateItem: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { -// val maxEmpty = player.openContainer.inventorySlots.countEmpty() -// -// val store = if (amount > 0) amount.coerceAtMost(maxEmpty) else maxEmpty - -// player.openContainer.getSlots(0..26) -// player.openContainer.getSlots(27..62) - player.openContainer.getSlots(27..62).filter { slot -> slot.stack.item == item && predicateItem(slot.stack) }.forEach { @@ -34,16 +25,5 @@ class PushItemsToContainer( ClickType.QUICK_MOVE )) } - -// player.inventorySlots.filter { slot -> -// slot.stack.item == item && predicateItem(slot.stack) -// }.take(store).forEach { -// addSubActivities(InventoryTransaction( -// player.openContainer.windowId, -// it.slotNumber, -// 0, -// ClickType.QUICK_MOVE -// )) -// } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 8a49c24e6..1af92b848 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,12 +1,14 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.Wait +import com.lambda.client.activity.activities.getContainerPos +import com.lambda.client.activity.activities.getShulkerInventory import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent @@ -27,7 +29,7 @@ class StoreItemToShulkerBox( player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> - if (inventory.all { it.item == item || it.isEmpty }) { + if (inventory.all { (it.item == item && predicateItem(it)) || it.isEmpty }) { candidates[slot] = inventory.count { it.item == item && predicateItem(it) } } } @@ -49,8 +51,7 @@ class StoreItemToShulkerBox( remotePos, pickUpDrop = true, mode = BreakBlock.Mode.PLAYER_CONTROLLER - ), - SwapOrMoveToItem(item, predicateItem, predicateSlot) + ) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 6d3b37de0..da7c35ad6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem @@ -14,10 +15,19 @@ class PickUpDrops( private val maxRange: Float = 10.0f ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - world.loadedEntityList.filterIsInstance().filter { + val drops = world.loadedEntityList.filterIsInstance().filter { it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) - }.sortedBy { drop -> player.distanceTo(drop.positionVector) }.forEach { drop -> - addSubActivities(PickUpEntityItem(drop)) + } + + if (drops.isEmpty()) { + activityStatus = ActivityStatus.SUCCESS + } else { + drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> + addSubActivities( + PickUpEntityItem(drop), + SetState(ActivityStatus.UNINITIALIZED) + ) + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index d2ba0524e..aa65598e7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -7,18 +7,19 @@ import com.lambda.client.activity.activities.inventory.DumpSlot import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem import net.minecraftforge.fml.common.gameevent.TickEvent class PickUpEntityItem( - entityItem: EntityItem, + private val entityItem: EntityItem, override val timeout: Long = 10000L, override var creationTime: Long = 0L ) : TimeoutActivity, Activity() { init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener + safeListener { event -> + if (event.phase != TickEvent.Phase.START) return@safeListener if (world.loadedEntityList.contains(entityItem)) { val emptySlots = player.inventory.mainInventory.filter { it.isEmpty } @@ -30,6 +31,9 @@ class PickUpEntityItem( InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) + } ?: run { + activityStatus = ActivityStatus.FAILURE + MessageSendHelper.sendErrorMessage("No empty slots or items to dump!") } } } else { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 3059e1d1c..315b94ab7 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -29,7 +29,7 @@ object TestActivityManager : Module( description = "", category = Category.MISC ) { - private val a by setting("Get Dia Pickaxe", false, consumer = { _, _-> + private val a by setting("Get any Dia Pickaxe", false, consumer = { _, _-> ActivityManager.addSubActivities( SwapOrMoveToItem(Items.DIAMOND_PICKAXE) ) From 2ff065ce8963897b9dd2dd1c158c7b7c541968fc Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 23 Dec 2022 07:13:53 +0100 Subject: [PATCH 022/104] Rotation and timing optimizations --- .../com/lambda/client/activity/Activity.kt | 41 ++++++++++++------- .../activity/activities/ActivityTypes.kt | 13 ++++++ .../highlevel/BreakDownEnderChests.kt | 6 +-- .../activities/highlevel/BuildBlock.kt | 20 +++++++++ .../activities/highlevel/PlaceBlockSafely.kt | 25 +++++++++++ .../activities/interaction/BreakBlock.kt | 38 ++++++++++++----- .../activities/interaction/OpenContainer.kt | 12 ++++-- .../activities/interaction/PlaceBlock.kt | 2 +- .../inventory/SwitchToItemInHotbar.kt | 8 ---- .../storage/ExtractItemFromShulkerBox.kt | 4 ++ .../storage/PushItemsToContainer.kt | 7 +++- .../storage/StoreItemToShulkerBox.kt | 4 +- .../manager/managers/ActivityManager.kt | 31 ++++++++------ .../manager/managers/PlayerPacketManager.kt | 11 ++--- 14 files changed, 161 insertions(+), 61 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 2eb9f26d8..103cf6ae3 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,15 +1,13 @@ package com.lambda.client.activity import com.lambda.client.LambdaMod -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.DelayedActivity -import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.* import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH +import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent @@ -42,15 +40,15 @@ abstract class Activity { if (this@Activity is AttemptActivity) { if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("TimedActivity fully timed out!") + LambdaMod.LOG.error("${this@Activity::class.simpleName} fully timed out!") } else { usedAttempts++ initialize() - LambdaMod.LOG.error("TimedActivity timed out!") + LambdaMod.LOG.error("${this@Activity::class.simpleName} timed out!") } } else { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("TimedActivity fully timed out!") + LambdaMod.LOG.error("${this@Activity::class.simpleName} fully timed out!") } } } @@ -65,17 +63,22 @@ abstract class Activity { if (this@Activity is AttemptActivity) { if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("AttemptActivity failed after $maxAttempts attempts!") + LambdaMod.LOG.error("${this@Activity::class.simpleName} failed after $maxAttempts attempts!") + } + } + if (this@Activity is RotatingActivity) { + sendPlayerPacket { + rotate(rotation) } } } ActivityStatus.SUCCESS -> { finalize() - LambdaMod.LOG.info("${this@Activity} activity finished successfully!") +// LambdaMod.LOG.info("${this@Activity} activity finished successfully!") } ActivityStatus.FAILURE -> { finalize() - LambdaMod.LOG.error("Activity ${this@Activity} failed!") + LambdaMod.LOG.error("Activity ${this@Activity::class.simpleName} failed!") } } } @@ -89,7 +92,12 @@ abstract class Activity { creationTime = System.currentTimeMillis() } onInitialize() - LambdaMod.LOG.info("Initialized activity: ${this@Activity}") + if (this@Activity is RotatingActivity) { + sendPlayerPacket { + rotate(rotation) + } + } +// LambdaMod.LOG.info("Initialized activity: ${this@Activity}") } open fun SafeClientEvent.onInitialize() {} @@ -97,7 +105,13 @@ abstract class Activity { private fun SafeClientEvent.finalize() { onFinalize() owner.subActivities.remove(this@Activity) - LambdaMod.LOG.info("Finalized activity: ${this@Activity}") +// LambdaMod.LOG.info("Finalized activity: ${this@Activity}") + + if (this@Activity is InstantActivity) { + with(ActivityManager) { + runActivity() + } + } } open fun SafeClientEvent.onFinalize() {} @@ -105,7 +119,6 @@ abstract class Activity { fun reset() { LambdaMod.LOG.info("Resetting activity: ${this@Activity::class.simpleName}" ) -// LambdaEventBus.unsubscribe(currentActivity()) ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager }.forEach { ListenerManager.unregister(it) LambdaEventBus.unsubscribe(it) @@ -130,7 +143,7 @@ abstract class Activity { } subActivities.addAll(activities) - LambdaMod.LOG.info("Added ${activities.size} sub activities to ${this::class.simpleName}") +// LambdaMod.LOG.info("Added ${activities.size} sub activities to ${this::class.simpleName}") } fun Activity.addSubActivities(vararg activities: Activity) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index 3b0c45c92..0aa0654c2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.math.Vec2f import net.minecraft.util.math.BlockPos interface TimeoutActivity { @@ -12,6 +13,18 @@ interface TimeoutActivity { interface InstantActivity +interface ChainedActivity { + val nextActivity: Activity +} + +interface LoopingActivity { + val loopingAmount: Int +} + +interface RotatingActivity { + var rotation: Vec2f +} + interface DelayedActivity { val delay: Long var creationTime: Long diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 201794137..c5347b241 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -20,22 +20,20 @@ import net.minecraft.init.Items class BreakDownEnderChests : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { remotePos -> - if (player.inventorySlots.countEmpty() == 0) { + if (player.inventorySlots.countEmpty() < 2) { addSubActivities( StoreItemToShulkerBox(Blocks.OBSIDIAN.item), SetState(ActivityStatus.UNINITIALIZED) ) } else { addSubActivities( - SwapOrMoveToItem(Blocks.ENDER_CHEST.item), - PlaceBlock(remotePos, Blocks.ENDER_CHEST), + PlaceBlockSafely(remotePos, Blocks.ENDER_CHEST), SwapOrMoveToItem( Items.DIAMOND_PICKAXE, predicateItem = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 } ), -// SwapToBestTool(remotePos), BreakBlock( remotePos, pickUpDrop = true, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt new file mode 100644 index 000000000..e21b09462 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -0,0 +1,20 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class BuildBlock( + private val blockPos: BlockPos, + private val targetState: IBlockState, +) : Activity() { + override fun SafeClientEvent.onInitialize() { + when (val currentState = world.getBlockState(blockPos)) { + targetState -> activityStatus = ActivityStatus.SUCCESS + else -> { + + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt new file mode 100644 index 000000000..1297defe0 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt @@ -0,0 +1,25 @@ +package com.lambda.client.activity.activities.highlevel + +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.item +import net.minecraft.block.Block +import net.minecraft.util.math.BlockPos + +class PlaceBlockSafely( + private val blockPos: BlockPos, + private val block: Block, +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities( + SwapOrMoveToItem(block.item), + CustomGoal(GoalNear(blockPos, 3)), + PlaceBlock(blockPos, block) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index d6db26957..0c81e5d02 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,15 +1,13 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.RenderBlockActivity -import com.lambda.client.activity.activities.SetState -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.* import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide @@ -17,9 +15,12 @@ import net.minecraft.init.Blocks import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.network.play.server.SPacketSpawnGlobalEntity +import net.minecraft.network.play.server.SPacketSpawnObject import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3i import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil @@ -35,11 +36,15 @@ class BreakBlock( override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(0, 0, 0) -) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { + override var color: ColorHolder = ColorHolder(0, 0, 0), + override var rotation: Vec2f = Vec2f.ZERO +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderBlockActivity, Activity() { private var ticksNeeded = 0 private var initState = Blocks.AIR.defaultState +// private var blockChanged = false +// private var dropped = false + enum class Mode { PLAYER_CONTROLLER, PACKET } @@ -52,7 +57,7 @@ class BreakBlock( color = ColorHolder(16, 74, 94) } else { ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 100L + timeout = ticksNeeded * 50L + 1000L } } @@ -61,9 +66,7 @@ class BreakBlock( if (it.phase != TickEvent.Phase.START) return@safeListener getMiningSide(blockPos)?.let { side -> - val rotation = getRotationTo(getHitVec(blockPos, side)) - - connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) + rotation = getRotationTo(getHitVec(blockPos, side)) if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { if (mode == Mode.PACKET) { @@ -131,6 +134,20 @@ class BreakBlock( ) { finish() } + +// if (it.packet is SPacketSpawnObject +// && it.packet.type == 2 +// && blockPos.distanceSq(Vec3i(it.packet.x, it.packet.y, it.packet.z)) < 1.0 +// ) { +// dropped = true +// if (pickUpDrop) { +// if (blockChanged) { +// finish() +// } +// } else { +// finish() +// } +// } } } @@ -139,6 +156,7 @@ class BreakBlock( color = ColorHolder(252, 3, 207) timeout = 10000L addSubActivities( + Wait(50L), PickUpDrops(initState.block.getItemDropped(initState, Random(), 0)), SetState(ActivityStatus.SUCCESS) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 7a6825925..12237c945 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -2,10 +2,12 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.RotatingActivity import com.lambda.client.activity.activities.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec @@ -17,7 +19,10 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activity() { +class OpenContainer( + private val containerPos: BlockPos, + override var rotation: Vec2f = Vec2f.ZERO, +) : InstantActivity, RotatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() @@ -25,9 +30,8 @@ class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activ val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) val hitVecOffset = getHitVecOffset(side) - val rotation = getRotationTo(getHitVec(containerPos, side)) + rotation = getRotationTo(getHitVec(containerPos, side)) - connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) connection.sendPacket(CPacketPlayerTryUseItemOnBlock(containerPos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat())) player.swingArm(EnumHand.MAIN_HAND) } @@ -36,7 +40,7 @@ class OpenContainer(private val containerPos: BlockPos) : InstantActivity, Activ safeListener { when (it.packet) { is SPacketOpenWindow -> { - addSubActivities(SetState(ActivityStatus.SUCCESS)) + activityStatus = ActivityStatus.SUCCESS } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 8170ab678..4c2f078c4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -24,7 +24,7 @@ class PlaceBlock( private val blockPos: BlockPos, private val block: Block, private val playSound: Boolean = true, - override val timeout: Long = 500L, + override val timeout: Long = 1000L, override var creationTime: Long = 0L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt deleted file mode 100644 index 16a9a6b96..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToItemInHotbar.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.lambda.client.activity.activities.inventory - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent - -class SwitchToItemInHotbar : Activity() { - override fun SafeClientEvent.onInitialize() {} -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 7fa8d7c13..8e7f3c4d6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,10 +1,12 @@ package com.lambda.client.activity.activities.storage +import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.Wait import com.lambda.client.activity.activities.getContainerPos import com.lambda.client.activity.activities.getShulkerInventory +import com.lambda.client.activity.activities.highlevel.PlaceBlockSafely import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer @@ -12,6 +14,7 @@ import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block @@ -43,6 +46,7 @@ class ExtractItemFromShulkerBox( candidates.minBy { it.value }.key.let { slot -> getContainerPos()?.let { remotePos -> addSubActivities( + CustomGoal(GoalNear(remotePos, 3)), SwapOrSwitchToSlot(slot, predicateSlot), PlaceBlock(remotePos, slot.stack.item.block), OpenContainer(remotePos), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index 2afc85657..39b6c7c42 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -5,6 +5,7 @@ import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.inventory.InventoryTransaction import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.getSlots +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.inventory.ClickType import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -15,7 +16,11 @@ class PushItemsToContainer( private val predicateItem: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.openContainer.getSlots(27..62).filter { slot -> + val openContainer = player.openContainer + + if (openContainer.inventorySlots.size != 63) return + + openContainer.getSlots(27..62).filter { slot -> slot.stack.item == item && predicateItem(slot.stack) }.forEach { addSubActivities(InventoryTransaction( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 1af92b848..fa0580cc6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -30,7 +30,9 @@ class StoreItemToShulkerBox( player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> if (inventory.all { (it.item == item && predicateItem(it)) || it.isEmpty }) { - candidates[slot] = inventory.count { it.item == item && predicateItem(it) } + val count = inventory.count { it.item == item && predicateItem(it) } + + if (count < 27) candidates[slot] = count } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 2e0060fac..3f41bb1e7 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -4,6 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.RenderBlockActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager +import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager import com.lambda.client.util.graphics.ESPRenderer @@ -19,19 +20,7 @@ object ActivityManager : Manager, Activity() { safeListener { event -> if (noSubActivities() || event.phase != TickEvent.Phase.START) return@safeListener - val currentActivity = currentActivity() - - with(currentActivity) { - if (currentActivity != lastActivity) { - if (lastActivity !is ActivityManager) { - LambdaEventBus.unsubscribe(lastActivity) - ListenerManager.unregister(lastActivity) - } - LambdaEventBus.subscribe(currentActivity) - lastActivity = currentActivity - } - updateActivity() - } + runActivity() } safeListener { @@ -46,4 +35,20 @@ object ActivityManager : Manager, Activity() { renderer.render(true) } } + + fun SafeClientEvent.runActivity() { + val currentActivity = currentActivity() + + with(currentActivity) { + if (currentActivity != lastActivity) { + if (lastActivity !is ActivityManager) { + LambdaEventBus.unsubscribe(lastActivity) + ListenerManager.unregister(lastActivity) + } + LambdaEventBus.subscribe(currentActivity) + lastActivity = currentActivity + } + updateActivity() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt index 7cfcc6c34..e06883d1d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/PlayerPacketManager.kt @@ -15,11 +15,12 @@ import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* +import java.util.concurrent.ConcurrentLinkedDeque object PlayerPacketManager : Manager { /** TreeMap for all packets to be sent, sorted by their callers' priority */ - private val packetMap = TreeMap() + private val packetMap = ConcurrentLinkedDeque() var serverSidePosition: Vec3d = Vec3d.ZERO; private set var prevServerSidePosition: Vec3d = Vec3d.ZERO; private set @@ -33,7 +34,7 @@ object PlayerPacketManager : Manager { listener(Int.MIN_VALUE) { if (it.phase != Phase.PERI || packetMap.isEmpty()) return@listener - it.apply(packetMap.values.first()) + it.apply(packetMap.first()) packetMap.clear() } @@ -80,14 +81,14 @@ object PlayerPacketManager : Manager { } } - inline fun Any.sendPlayerPacket(block: Packet.Builder.() -> Unit) { + inline fun sendPlayerPacket(block: Packet.Builder.() -> Unit) { Packet.Builder().apply(block).build()?.let { sendPlayerPacket(it) } } - fun Any.sendPlayerPacket(packet: Packet) { - packetMap[this] = packet + fun sendPlayerPacket(packet: Packet) { + packetMap.push(packet) } class Packet private constructor( From 0f660aa79377f0abbdc2ce3b23e38750472f7bbb Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 23 Dec 2022 07:49:50 +0100 Subject: [PATCH 023/104] Remove unneeded activity --- .../{Failing.kt => ProbablyFailing.kt} | 2 +- .../interaction/PlaceAndBreakBlock.kt | 28 ------------------- .../modules/misc/TestActivityManager.kt | 4 +-- 3 files changed, 3 insertions(+), 31 deletions(-) rename src/main/kotlin/com/lambda/client/activity/activities/example/{Failing.kt => ProbablyFailing.kt} (91%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt rename to src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt index 755530de0..65dcc19a4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/Failing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import kotlin.random.Random -class Failing : Activity() { +class ProbablyFailing : Activity() { override fun SafeClientEvent.onInitialize() { activityStatus = if (Random.nextBoolean()) { ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt deleted file mode 100644 index 594251433..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceAndBreakBlock.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.items.item -import com.lambda.client.util.math.Direction -import net.minecraft.block.Block -import net.minecraft.init.Items -import net.minecraft.util.math.BlockPos - -class PlaceAndBreakBlock(private val block: Block) : InstantActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - addSubActivities( - SwapOrMoveToItem(block.item), - PlaceBlock( - BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)), - block - ), - SwapOrMoveToItem(Items.DIAMOND_PICKAXE), - BreakBlock( - BlockPos(player.flooredPosition.add(Direction.fromEntity(player).directionVec)) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 315b94ab7..ac760a6bb 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,7 +1,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod -import com.lambda.client.activity.activities.example.Failing +import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.inventory.DumpInventory @@ -97,7 +97,7 @@ object TestActivityManager : Module( }) private val fail by setting("maybe fail", false, consumer = { _, _-> - ActivityManager.addSubActivities(Failing()) + ActivityManager.addSubActivities(ProbablyFailing()) false }) From 952fe6c0877a3194e432041650729e929d4007b6 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 27 Dec 2022 23:43:14 +0100 Subject: [PATCH 024/104] Sketch: Inventory 2.0 --- .../com/lambda/client/activity/Activity.kt | 13 +--- .../highlevel/BreakDownEnderChests.kt | 5 +- .../activities/interaction/BreakBlock.kt | 6 +- .../activities/interaction/OpenContainer.kt | 2 - .../activity/activities/inventory/DumpSlot.kt | 2 +- .../activities/inventory/SwapHotbarSlots.kt | 2 +- .../activities/inventory/SwapWithSlot.kt | 2 +- .../storage/ExtractItemFromShulkerBox.kt | 7 +- .../activities/storage/OpenShulkerInSlot.kt | 28 ++++++++ .../storage/StoreItemToShulkerBox.kt | 6 +- .../activity/activities/travel/PickUpDrops.kt | 2 +- .../activities/{ => utils}/ActivityUtils.kt | 2 +- .../activities/{ => utils}/SetState.kt | 2 +- .../activity/activities/{ => utils}/Wait.kt | 3 +- .../manager/managers/ActivityManager.kt | 39 +++++++--- .../modules/player/InventoryManagerTwo.kt | 71 +++++++++++++++++++ .../client/module/modules/render/NoRender.kt | 5 +- 17 files changed, 150 insertions(+), 47 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt rename src/main/kotlin/com/lambda/client/activity/activities/{ => utils}/ActivityUtils.kt (97%) rename src/main/kotlin/com/lambda/client/activity/activities/{ => utils}/SetState.kt (85%) rename src/main/kotlin/com/lambda/client/activity/activities/{ => utils}/Wait.kt (73%) create mode 100644 src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 103cf6ae3..afd0f2e7f 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -16,7 +16,7 @@ import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { - private val subActivities = ConcurrentLinkedDeque() + val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED var owner: Activity = ActivityManager var depth = 0 @@ -117,17 +117,6 @@ abstract class Activity { open fun SafeClientEvent.onFinalize() {} fun currentActivity(): Activity = subActivities.peek()?.currentActivity() ?: this - fun reset() { - LambdaMod.LOG.info("Resetting activity: ${this@Activity::class.simpleName}" ) - ListenerManager.listenerMap.keys.filterIsInstance().filter { it !is ActivityManager }.forEach { - ListenerManager.unregister(it) - LambdaEventBus.unsubscribe(it) - LambdaMod.LOG.info("Unsubscribed ${it::class.simpleName}") - } - BaritoneUtils.primary?.pathingBehavior?.cancelEverything() - subActivities.clear() - } - fun Activity.addSubActivities(activities: List) { if (activities.isEmpty()) return diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index c5347b241..2f861743e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -2,10 +2,9 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.SetState -import com.lambda.client.activity.activities.getContainerPos +import com.lambda.client.activity.activities.utils.SetState +import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 0c81e5d02..fb53040a9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -3,6 +3,8 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.* import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.utils.SetState +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder @@ -12,15 +14,11 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import net.minecraft.init.Blocks -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.network.play.server.SPacketSpawnGlobalEntity -import net.minecraft.network.play.server.SPacketSpawnObject import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3i import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 12237c945..ebfb4a5de 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.RotatingActivity -import com.lambda.client.activity.activities.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -12,7 +11,6 @@ import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketOpenWindow import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt index 89aacd30d..ea4042a6e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt @@ -8,6 +8,6 @@ import net.minecraft.inventory.Slot class DumpSlot(private val slot: Slot) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - addSubActivities(InventoryTransaction(0, slot.slotNumber, 1, ClickType.THROW)) + addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 1, ClickType.THROW)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt index 6871b65a2..2e4aa758e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt @@ -11,6 +11,6 @@ class SwapHotbarSlots( private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - addSubActivities(InventoryTransaction(0, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) + addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index e7186085c..b0b552d9d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -12,6 +12,6 @@ class SwapWithSlot( private val slotTo: HotbarSlot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - addSubActivities(InventoryTransaction(0, slotFrom.slotIndex, slotTo.hotbarSlot, ClickType.SWAP)) + addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 8e7f3c4d6..df3a07eb1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -3,10 +3,9 @@ package com.lambda.client.activity.activities.storage import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.Wait -import com.lambda.client.activity.activities.getContainerPos -import com.lambda.client.activity.activities.getShulkerInventory -import com.lambda.client.activity.activities.highlevel.PlaceBlockSafely +import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt new file mode 100644 index 000000000..1a3223851 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt @@ -0,0 +1,28 @@ +package com.lambda.client.activity.activities.storage + +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.block +import net.minecraft.inventory.Slot + +class OpenShulkerInSlot( + private val slot: Slot +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + getContainerPos()?.let { containerPos -> + addSubActivities( + CustomGoal(GoalNear(containerPos, 3)), + SwapOrSwitchToSlot(slot), + PlaceBlock(containerPos, slot.stack.item.block), + OpenContainer(containerPos) + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index fa0580cc6..43c39ddae 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -2,9 +2,9 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.Wait -import com.lambda.client.activity.activities.getContainerPos -import com.lambda.client.activity.activities.getShulkerInventory +import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index da7c35ad6..463fb4e67 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.SetState +import com.lambda.client.activity.activities.utils.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt similarity index 97% rename from src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt rename to src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt index 9d29afcfa..ad3c7b4d0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities +package com.lambda.client.activity.activities.utils import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils diff --git a/src/main/kotlin/com/lambda/client/activity/activities/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt similarity index 85% rename from src/main/kotlin/com/lambda/client/activity/activities/SetState.kt rename to src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt index 4b29b111e..f7f710289 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/SetState.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities +package com.lambda.client.activity.activities.utils import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt similarity index 73% rename from src/main/kotlin/com/lambda/client/activity/activities/Wait.kt rename to src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt index 7da075bab..3b8f56a34 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/Wait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt @@ -1,6 +1,7 @@ -package com.lambda.client.activity.activities +package com.lambda.client.activity.activities.utils import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.DelayedActivity import com.lambda.client.event.SafeClientEvent class Wait( diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 3f41bb1e7..1028ce245 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -7,6 +7,7 @@ import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager +import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent @@ -37,18 +38,36 @@ object ActivityManager : Manager, Activity() { } fun SafeClientEvent.runActivity() { + with(currentActivity()) { + updateListener() + updateActivity() + } + } + + fun reset() { + if (lastActivity !is ActivityManager) { + LambdaEventBus.unsubscribe(lastActivity) + ListenerManager.unregister(lastActivity) + } + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + subActivities.clear() + + lastActivity = ActivityManager + } + + private fun updateListener() { val currentActivity = currentActivity() - with(currentActivity) { - if (currentActivity != lastActivity) { - if (lastActivity !is ActivityManager) { - LambdaEventBus.unsubscribe(lastActivity) - ListenerManager.unregister(lastActivity) - } - LambdaEventBus.subscribe(currentActivity) - lastActivity = currentActivity - } - updateActivity() + if (currentActivity == lastActivity) return + + if (lastActivity !is ActivityManager) { + LambdaEventBus.unsubscribe(lastActivity) + ListenerManager.unregister(lastActivity) } + + LambdaEventBus.subscribe(currentActivity) + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + + lastActivity = currentActivity } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt new file mode 100644 index 000000000..26728d9c7 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -0,0 +1,71 @@ +package com.lambda.client.module.modules.player + +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.events.GuiEvent +import com.lambda.client.event.events.WindowClickEvent +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.util.items.block +import com.lambda.client.util.items.item +import com.lambda.client.util.threads.safeListener +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiShulkerBox +import net.minecraft.init.Blocks +import net.minecraft.inventory.ClickType +import net.minecraft.item.ItemShulkerBox +import net.minecraft.util.math.BlockPos + +object InventoryManagerTwo : Module( + name = "InventoryManagerTwo", + description = "Manages your inventory automatically", + category = Category.PLAYER +) { + private val placedShulkerBoxes = mutableListOf() + + init { + safeListener { + if (it.type != ClickType.PICKUP) return@safeListener + + player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> + if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener + + getContainerPos()?.let { containerPos -> + placedShulkerBoxes.add(containerPos) + ActivityManager.addSubActivities( + CustomGoal(GoalNear(containerPos, 3)), + SwapOrSwitchToSlot(slot), + PlaceBlock(containerPos, slot.stack.item.block), + OpenContainer(containerPos) + ) + } + + it.cancel() + } + } + + safeListener { + if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener + + placedShulkerBoxes.firstOrNull()?.let { containerPos -> + ActivityManager.addSubActivities( + CustomGoal(GoalNear(containerPos, 3)), + SwapToBestTool(containerPos), + BreakBlock( + containerPos, + pickUpDrop = true + ) + ) + placedShulkerBoxes.remove(containerPos) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/NoRender.kt b/src/main/kotlin/com/lambda/client/module/modules/render/NoRender.kt index dc4cddbb1..f5bb04fe2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/NoRender.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/NoRender.kt @@ -58,8 +58,9 @@ object NoRender : Module( private val items = setting("Items", false, { page == Page.ENTITIES }) private val crystal = setting("Crystals", false, { page == Page.ENTITIES }) private val firework = setting("Firework", false, { page == Page.ENTITIES }) + private val tileEntity = setting("TileEntities", false, { page == Page.ENTITIES }) - //Armor + // Armor private val armorPlayer by setting("Players", false, { page == Page.ARMOR }) private val armorStands by setting("Armour Stands", false, { page == Page.ARMOR }) private val armorMobs by setting("Mobs", false, { page == Page.ARMOR }) @@ -68,7 +69,7 @@ object NoRender : Module( private val leggings by setting("Leggings", true, { page == Page.ARMOR }) private val boots by setting("Boots", true, { page == Page.ARMOR }) - //Overlay + // Overlay val hurtCamera by setting("Hurt Camera", false, { page == Page.OVERLAY }) private val fire by setting("Fire", false, { page == Page.OVERLAY }) private val water by setting("Water", false, { page == Page.OVERLAY }) From ed0e315ee5e15fa224f3c69cc9723f5fc4ffdcc4 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 28 Dec 2022 01:25:15 +0100 Subject: [PATCH 025/104] Cleanup --- .../com/lambda/client/activity/Activity.kt | 2 -- .../highlevel/BreakDownEnderChests.kt | 4 +-- .../activities/interaction/BreakBlock.kt | 5 +++- .../activities/inventory/QuickMoveSlot.kt | 15 ++++++++++ .../storage/BreakAndCollectShulker.kt | 22 +++++++++++++++ .../storage/ExtractItemFromShulkerBox.kt | 28 ++++--------------- ...hulkerInSlot.kt => OpenContainerInSlot.kt} | 8 ++++-- .../storage/PullItemsFromContainer.kt | 10 ++----- .../storage/PushItemsToContainer.kt | 11 ++------ .../storage/StoreItemToShulkerBox.kt | 26 ++++------------- .../modules/player/InventoryManagerTwo.kt | 22 +++------------ 11 files changed, 66 insertions(+), 87 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/{OpenShulkerInSlot.kt => OpenContainerInSlot.kt} (87%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index afd0f2e7f..d69c0cf05 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -2,13 +2,11 @@ package com.lambda.client.activity import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.* -import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket -import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 2f861743e..41b8b7fd0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -2,11 +2,11 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.utils.SetState -import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox +import com.lambda.client.activity.activities.utils.SetState +import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index fb53040a9..f164788fe 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,7 +1,10 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.activity.activities.TimeoutActivity import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.utils.SetState import com.lambda.client.activity.activities.utils.Wait diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt new file mode 100644 index 000000000..77b36bed0 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt @@ -0,0 +1,15 @@ +package com.lambda.client.activity.activities.inventory + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.inventory.ClickType +import net.minecraft.inventory.Slot + +class QuickMoveSlot( + private val slot: Slot +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 0, ClickType.QUICK_MOVE)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt new file mode 100644 index 000000000..3a4e4c5fc --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt @@ -0,0 +1,22 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.event.SafeClientEvent +import net.minecraft.util.math.BlockPos + +class BreakAndCollectShulker( + private val blockPos: BlockPos +) : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities( + SwapToBestTool(blockPos), + BreakBlock( + blockPos, + pickUpDrop = true + ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index df3a07eb1..40ef61931 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,22 +1,13 @@ package com.lambda.client.activity.activities.storage -import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.utils.Wait -import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.activity.activities.utils.getShulkerInventory -import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.inventory.SwapToBestTool -import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.block import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -43,21 +34,12 @@ class ExtractItemFromShulkerBox( if (candidates.isEmpty()) return candidates.minBy { it.value }.key.let { slot -> - getContainerPos()?.let { remotePos -> + getContainerPos()?.let { containerPos -> addSubActivities( - CustomGoal(GoalNear(remotePos, 3)), - SwapOrSwitchToSlot(slot, predicateSlot), - PlaceBlock(remotePos, slot.stack.item.block), - OpenContainer(remotePos), - Wait(50L), + OpenContainerInSlot(slot), PullItemsFromContainer(item, amount, predicateItem), CloseContainer(), - SwapToBestTool(remotePos), - BreakBlock( - remotePos, - pickUpDrop = true, - mode = BreakBlock.Mode.PLAYER_CONTROLLER - ), + BreakAndCollectShulker(containerPos), SwapOrMoveToItem(item, predicateItem, predicateSlot) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt similarity index 87% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index 1a3223851..1373a5528 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -3,16 +3,17 @@ package com.lambda.client.activity.activities.storage import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.block import net.minecraft.inventory.Slot -class OpenShulkerInSlot( +class OpenContainerInSlot( private val slot: Slot ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { @@ -21,7 +22,8 @@ class OpenShulkerInSlot( CustomGoal(GoalNear(containerPos, 3)), SwapOrSwitchToSlot(slot), PlaceBlock(containerPos, slot.stack.item.block), - OpenContainer(containerPos) + OpenContainer(containerPos), + Wait(50L) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 107c8fdb4..baf18717e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -2,11 +2,10 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.inventory.InventoryTransaction +import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots -import net.minecraft.inventory.ClickType import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -23,12 +22,7 @@ class PullItemsFromContainer( player.openContainer.inventorySlots.filter { slot -> slot.stack.item == item && predicateItem(slot.stack) }.take(take).forEach { - addSubActivities(InventoryTransaction( - player.openContainer.windowId, - it.slotNumber, - 0, - ClickType.QUICK_MOVE - )) + addSubActivities(QuickMoveSlot(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index 39b6c7c42..19a9a8fbe 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -2,11 +2,9 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.inventory.InventoryTransaction +import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.getSlots -import com.lambda.client.util.text.MessageSendHelper -import net.minecraft.inventory.ClickType import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -23,12 +21,7 @@ class PushItemsToContainer( openContainer.getSlots(27..62).filter { slot -> slot.stack.item == item && predicateItem(slot.stack) }.forEach { - addSubActivities(InventoryTransaction( - player.openContainer.windowId, - it.slotNumber, - 0, - ClickType.QUICK_MOVE - )) + addSubActivities(QuickMoveSlot(it)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 43c39ddae..379981364 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -2,18 +2,11 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.utils.getShulkerInventory -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.block import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -21,8 +14,7 @@ import net.minecraft.item.ItemStack class StoreItemToShulkerBox( private val item: Item, private val amount: Int = 0, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true } + private val predicateItem: (ItemStack) -> Boolean = { true } ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { val candidates = mutableMapOf() @@ -40,20 +32,12 @@ class StoreItemToShulkerBox( if (candidates.isEmpty()) return candidates.maxBy { it.value }.key.let { slot -> - getContainerPos()?.let { remotePos -> + getContainerPos()?.let { containerPos -> addSubActivities( - SwapOrSwitchToSlot(slot, predicateSlot), - PlaceBlock(remotePos, slot.stack.item.block), - OpenContainer(remotePos), - Wait(50L), + OpenContainerInSlot(slot), PushItemsToContainer(item, amount, predicateItem), CloseContainer(), - SwapToBestTool(remotePos), - BreakBlock( - remotePos, - pickUpDrop = true, - mode = BreakBlock.Mode.PLAYER_CONTROLLER - ) + BreakAndCollectShulker(containerPos) ) } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 26728d9c7..f470095c5 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,20 +1,14 @@ package com.lambda.client.module.modules.player -import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.inventory.SwapToBestTool -import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.activity.activities.storage.BreakAndCollectShulker +import com.lambda.client.activity.activities.storage.OpenContainerInSlot import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module -import com.lambda.client.util.items.block import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener import net.minecraft.client.gui.inventory.GuiChest @@ -41,10 +35,7 @@ object InventoryManagerTwo : Module( getContainerPos()?.let { containerPos -> placedShulkerBoxes.add(containerPos) ActivityManager.addSubActivities( - CustomGoal(GoalNear(containerPos, 3)), - SwapOrSwitchToSlot(slot), - PlaceBlock(containerPos, slot.stack.item.block), - OpenContainer(containerPos) + OpenContainerInSlot(slot) ) } @@ -57,12 +48,7 @@ object InventoryManagerTwo : Module( placedShulkerBoxes.firstOrNull()?.let { containerPos -> ActivityManager.addSubActivities( - CustomGoal(GoalNear(containerPos, 3)), - SwapToBestTool(containerPos), - BreakBlock( - containerPos, - pickUpDrop = true - ) + BreakAndCollectShulker(containerPos) ) placedShulkerBoxes.remove(containerPos) } From 7cfeedd3ffa9e027f6028ff430ee967df63cbf1f Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 28 Dec 2022 03:16:49 +0100 Subject: [PATCH 026/104] First BuildBlockState test --- .../com/lambda/client/activity/Activity.kt | 30 ++++++++++++++----- .../activity/activities/ActivityTypes.kt | 2 -- .../activities/example/ListenAndWait.kt | 3 +- .../activity/activities/example/WaitAndSay.kt | 3 +- .../highlevel/BreakDownEnderChests.kt | 2 +- .../activities/highlevel/BuildBlock.kt | 29 +++++++++++++++--- .../activities/highlevel/PlaceBlockSafely.kt | 7 +++-- .../highlevel/SurroundWithObsidian.kt | 20 +++++++++++++ .../activities/interaction/BreakBlock.kt | 1 - .../activities/interaction/PlaceBlock.kt | 16 +++++----- .../inventory/InventoryTransaction.kt | 1 - .../activities/storage/OpenContainerInSlot.kt | 2 +- .../activity/activities/travel/CustomGoal.kt | 3 +- .../activities/travel/PickUpEntityItem.kt | 3 +- .../client/activity/activities/utils/Wait.kt | 3 +- .../elements/misc/ActivityManagerHud.kt | 2 ++ .../modules/misc/TestActivityManager.kt | 9 ++++++ 17 files changed, 98 insertions(+), 38 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index d69c0cf05..bf79f2794 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED + private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 @@ -83,12 +84,7 @@ abstract class Activity { private fun SafeClientEvent.initialize() { activityStatus = ActivityStatus.RUNNING - if (this@Activity is TimeoutActivity) { - creationTime = System.currentTimeMillis() - } - if (this@Activity is DelayedActivity) { - creationTime = System.currentTimeMillis() - } + creationTime = System.currentTimeMillis() onInitialize() if (this@Activity is RotatingActivity) { sendPlayerPacket { @@ -103,7 +99,7 @@ abstract class Activity { private fun SafeClientEvent.finalize() { onFinalize() owner.subActivities.remove(this@Activity) -// LambdaMod.LOG.info("Finalized activity: ${this@Activity}") + LambdaMod.LOG.info("Finalized activity: ${this@Activity} after ${System.currentTimeMillis() - creationTime}ms") if (this@Activity is InstantActivity) { with(ActivityManager) { @@ -137,8 +133,28 @@ abstract class Activity { addSubActivities(activities.toList()) } + fun getAllSubActivities(): MutableList { + val activities = mutableListOf() + + if (this !is ActivityManager) { + activities.add(this) + } + + activities.addAll(subActivities.flatMap { it.getAllSubActivities() }) + + return activities + } + fun noSubActivities() = subActivities.isEmpty() + fun setSuccess() { + activityStatus = ActivityStatus.SUCCESS + } + + fun setFailure() { + activityStatus = ActivityStatus.FAILURE + } + override fun toString(): String { return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index 0aa0654c2..c765ba18d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -8,7 +8,6 @@ import net.minecraft.util.math.BlockPos interface TimeoutActivity { val timeout: Long - var creationTime: Long } interface InstantActivity @@ -27,7 +26,6 @@ interface RotatingActivity { interface DelayedActivity { val delay: Long - var creationTime: Long fun SafeClientEvent.onDelayedActivity() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt index 623147530..0740a00d9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -8,8 +8,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class ListenAndWait( private val message: String, - override val timeout: Long, - override var creationTime: Long = 0L + override val timeout: Long ) : TimeoutActivity, Activity() { init { safeListener { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt index 5ae5f57da..f28275e96 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt @@ -7,8 +7,7 @@ import com.lambda.client.util.text.MessageSendHelper class WaitAndSay( private val message: String, - override val delay: Long = 1000L, - override var creationTime: Long = 0L + override val delay: Long = 1000L ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 41b8b7fd0..5eb04863a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -26,7 +26,7 @@ class BreakDownEnderChests : InstantActivity, Activity() { ) } else { addSubActivities( - PlaceBlockSafely(remotePos, Blocks.ENDER_CHEST), + PlaceBlockSafely(remotePos, Blocks.ENDER_CHEST.defaultState), SwapOrMoveToItem( Items.DIAMOND_PICKAXE, predicateItem = { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index e21b09462..ff016ec4b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -1,19 +1,40 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.world.isReplaceable import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos class BuildBlock( private val blockPos: BlockPos, private val targetState: IBlockState, -) : Activity() { +) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { - when (val currentState = world.getBlockState(blockPos)) { - targetState -> activityStatus = ActivityStatus.SUCCESS - else -> { + val currentState = world.getBlockState(blockPos) + when { + /* is in desired state */ + currentState == targetState -> setSuccess() +// /* is blocked by entity */ +// world.checkNoEntityCollision(currentState.getSelectedBoundingBox(world, blockPos), null) -> setFailure() + /* block needs to be placed */ + targetState.block != Blocks.AIR && currentState.isReplaceable -> { + addSubActivities( + PlaceBlockSafely(blockPos, targetState) + ) + } + /* only option left is breaking the block */ + else -> { + addSubActivities( + SwapToBestTool(blockPos), + BreakBlock(blockPos), + PlaceBlockSafely(blockPos, targetState) + ) } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt index 1297defe0..757d4a55b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt @@ -9,17 +9,18 @@ import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.util.math.BlockPos class PlaceBlockSafely( private val blockPos: BlockPos, - private val block: Block, + private val blockState: IBlockState, ) : InstantActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( - SwapOrMoveToItem(block.item), + SwapOrMoveToItem(blockState.block.item), CustomGoal(GoalNear(blockPos, 3)), - PlaceBlock(blockPos, block) + PlaceBlock(blockPos, blockState) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt new file mode 100644 index 000000000..114d4251a --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -0,0 +1,20 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.EntityUtils.flooredPosition +import net.minecraft.init.Blocks + +class SurroundWithObsidian : InstantActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + player.flooredPosition.let { + addSubActivities( + BuildBlock(it.north(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(it.south(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(it.east(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(it.west(), Blocks.SLIME_BLOCK.defaultState) + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index f164788fe..3fcfecc6d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -33,7 +33,6 @@ class BreakBlock( private val pickUpDrop: Boolean = false, private val mode: Mode = Mode.PACKET, override var timeout: Long = 200L, - override var creationTime: Long = 0L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override var renderBlockPos: BlockPos = blockPos, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 4c2f078c4..5185cc944 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -3,18 +3,19 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.AttemptActivity import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.RotatingActivity import com.lambda.client.activity.activities.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.toPlacePacket -import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory @@ -22,15 +23,15 @@ import net.minecraft.util.math.BlockPos class PlaceBlock( private val blockPos: BlockPos, - private val block: Block, + private val targetState: IBlockState, private val playSound: Boolean = true, + override var rotation: Vec2f = Vec2f.ZERO, override val timeout: Long = 1000L, - override var creationTime: Long = 0L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override var renderBlockPos: BlockPos = blockPos, override var color: ColorHolder = ColorHolder(0, 0, 0) -) : TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { val placedAtState = world.getBlockState(it.pos) @@ -39,9 +40,8 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } - val rotation = getRotationTo(it.hitVec) + rotation = getRotationTo(it.hitVec) - connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) player.swingArm(EnumHand.MAIN_HAND) @@ -77,7 +77,7 @@ class PlaceBlock( safeListener { if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos - && it.packet.blockState.block == block + && it.packet.blockState.block == targetState.block ) { activityStatus = ActivityStatus.SUCCESS color = ColorHolder(35, 188, 254) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index 20acd1e0e..09123f78b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -19,7 +19,6 @@ class InventoryTransaction( private val mouseButton: Int = 0, val type: ClickType, override val timeout: Long = 500L, - override var creationTime: Long = 0L, override val maxAttempts: Int = 5, override var usedAttempts: Int = 0 ) : TimeoutActivity, AttemptActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index 1373a5528..a8169d1b4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -21,7 +21,7 @@ class OpenContainerInSlot( addSubActivities( CustomGoal(GoalNear(containerPos, 3)), SwapOrSwitchToSlot(slot), - PlaceBlock(containerPos, slot.stack.item.block), + PlaceBlock(containerPos, slot.stack.item.block.defaultState), OpenContainer(containerPos), Wait(50L) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index c89405c4a..d9243f5d3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -10,8 +10,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class CustomGoal( private val goal: Goal, - override val timeout: Long = 100000L, - override var creationTime: Long = 0L + override val timeout: Long = 100000L ) : TimeoutActivity, Activity() { init { safeListener { event -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index aa65598e7..88f194bd5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -14,8 +14,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class PickUpEntityItem( private val entityItem: EntityItem, - override val timeout: Long = 10000L, - override var creationTime: Long = 0L + override val timeout: Long = 10000L ) : TimeoutActivity, Activity() { init { safeListener { event -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt index 3b8f56a34..f3937eae8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt @@ -5,8 +5,7 @@ import com.lambda.client.activity.activities.DelayedActivity import com.lambda.client.event.SafeClientEvent class Wait( - override val delay: Long, - override var creationTime: Long = 0L + override val delay: Long ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { activityStatus = ActivityStatus.SUCCESS diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index b9965d074..9ff336cc7 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -14,6 +14,8 @@ internal object ActivityManagerHud: LabelHud( override fun SafeClientEvent.updateText() { if (ActivityManager.noSubActivities()) return + displayText.addLine("Current Activities ${ActivityManager.getAllSubActivities().size}") + ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) displayText.addLine("") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index ac760a6bb..3ec06405c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,6 +4,8 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests +import com.lambda.client.activity.activities.highlevel.BuildBlock +import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox @@ -91,6 +93,13 @@ object TestActivityManager : Module( false }) + private val tiectie by setting("Surround me", false, consumer = { _, _-> + ActivityManager.addSubActivities( + SurroundWithObsidian() + ) + false + }) + private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> ActivityManager.addSubActivities(SayAnnoyingly("Hello World")) false From 0d89f021872464cb7404645a1f98fee0a5ca9433 Mon Sep 17 00:00:00 2001 From: minecraft-simon Date: Thu, 29 Dec 2022 01:01:36 +0100 Subject: [PATCH 027/104] added some activities for auto-xp --- .../activities/highlevel/RaiseXPLevel.kt | 28 ++++++++++++++++ .../interaction/UseThrowableItem.kt | 32 +++++++++++++++++++ .../activities/inventory/SlotMustBeEmpty.kt | 18 +++++++++++ .../activities/inventory/TakeOffArmor.kt | 25 +++++++++++++++ .../inventory/TryClearSlotWithQuickMove.kt | 23 +++++++++++++ .../modules/misc/TestActivityManager.kt | 7 ++++ 6 files changed, 133 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt new file mode 100644 index 000000000..955694558 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt @@ -0,0 +1,28 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.interaction.CloseContainer +import com.lambda.client.activity.activities.interaction.UseThrowableItem +import com.lambda.client.activity.activities.inventory.InventoryTransaction +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.TakeOffArmor +import com.lambda.client.event.SafeClientEvent +import net.minecraft.init.Items +import net.minecraft.inventory.ClickType +import net.minecraft.util.math.BlockPos + +class RaiseXPLevel( + private val desiredLevel: Int, + private val xpSupply: BlockPos +) : InstantActivity, Activity() { + + override fun SafeClientEvent.onInitialize() { + addSubActivities( + TakeOffArmor(), + SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE, useShulkerBoxes = false), + UseThrowableItem() + ) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt new file mode 100644 index 000000000..2e1e87ea9 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt @@ -0,0 +1,32 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.manager.managers.PlayerPacketManager +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import net.minecraft.network.play.client.CPacketPlayerTryUseItem +import net.minecraft.network.play.server.SPacketOpenWindow +import net.minecraft.util.EnumHand +import net.minecraftforge.fml.common.gameevent.TickEvent + +class UseThrowableItem( + override var rotation: Vec2f = Vec2f.ZERO, + ) : RotatingActivity, Activity() { + + override fun SafeClientEvent.onInitialize() { + rotation = Vec2f(player.rotationYaw, 90f) + } + + init { + safeListener { + if (it.phase == TickEvent.Phase.END) { + connection.sendPacket(CPacketPlayerTryUseItem(EnumHand.MAIN_HAND)) + activityStatus = ActivityStatus.SUCCESS + } + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt new file mode 100644 index 000000000..6d8980dd0 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt @@ -0,0 +1,18 @@ +package com.lambda.client.activity.activities.inventory + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.inventory.Slot + +class SlotMustBeEmpty( + private val slot: Slot +) : Activity() { + + override fun SafeClientEvent.onInitialize() { + activityStatus = if (slot.stack.isEmpty) { + ActivityStatus.SUCCESS + } else { + ActivityStatus.FAILURE + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt new file mode 100644 index 000000000..9444fc266 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt @@ -0,0 +1,25 @@ +package com.lambda.client.activity.activities.inventory + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.armorSlots +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.offhandSlot +import net.minecraft.inventory.ClickType + +class TakeOffArmor : InstantActivity, Activity() { + + override fun SafeClientEvent.onInitialize() { + player.armorSlots.forEach { + addSubActivities( + TryClearSlotWithQuickMove(it) + ) + } + addSubActivities( + TryClearSlotWithQuickMove(player.offhandSlot) + ) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt new file mode 100644 index 000000000..46f4bafe5 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt @@ -0,0 +1,23 @@ +package com.lambda.client.activity.activities.inventory + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.inventory.Slot + +class TryClearSlotWithQuickMove( + private val slot: Slot +) : InstantActivity, Activity() { + + override fun SafeClientEvent.onInitialize() { + if (slot.stack.isEmpty) { + activityStatus = ActivityStatus.SUCCESS + } else { + addSubActivities( + QuickMoveSlot(slot), + SlotMustBeEmpty(slot) + ) + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 3ec06405c..760d93099 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -5,6 +5,7 @@ import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.highlevel.BuildBlock +import com.lambda.client.activity.activities.highlevel.RaiseXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem @@ -25,6 +26,7 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items +import net.minecraft.util.math.BlockPos object TestActivityManager : Module( name = "TestActivityManager", @@ -114,4 +116,9 @@ object TestActivityManager : Module( ActivityManager.reset() false }) + + val raiseXPLevel by setting("RaiseXPLevel", false, consumer = { _, _-> + ActivityManager.addSubActivities(RaiseXPLevel(3, BlockPos.ORIGIN)) + false + }) } From 405813749193dd2a07c2094e6587f0aa5687629a Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 04:36:28 +0100 Subject: [PATCH 028/104] General throwable usage --- .../activities/highlevel/RaiseXPLevel.kt | 13 +++--- .../activities/interaction/BreakBlock.kt | 27 +++++------ .../interaction/UseThrowableItem.kt | 32 ------------- .../interaction/UseThrowableOnEntity.kt | 46 +++++++++++++++++++ .../activities/inventory/SwapOrMoveToItem.kt | 4 +- .../modules/misc/TestActivityManager.kt | 10 ++++ .../com/lambda/client/util/items/Slot.kt | 2 +- 7 files changed, 79 insertions(+), 55 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt index 955694558..a47591055 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt @@ -2,14 +2,11 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.InstantActivity -import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.UseThrowableItem -import com.lambda.client.activity.activities.inventory.InventoryTransaction +import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.TakeOffArmor import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items -import net.minecraft.inventory.ClickType import net.minecraft.util.math.BlockPos class RaiseXPLevel( @@ -20,9 +17,11 @@ class RaiseXPLevel( override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), - SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE, useShulkerBoxes = false), - UseThrowableItem() + SwapOrMoveToItem( + Items.EXPERIENCE_BOTTLE, + useShulkerBoxes = false + ), + UseThrowableOnEntity(player) ) } - } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 3fcfecc6d..505dfc9dd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -57,7 +57,7 @@ class BreakBlock( color = ColorHolder(16, 74, 94) } else { ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 1000L + timeout = ticksNeeded * 50L + 500L } } @@ -85,8 +85,9 @@ class BreakBlock( } } else { playerController.onPlayerDestroyBlock(blockPos) - finish() + player.swingArm(EnumHand.MAIN_HAND) } + finish() } else { playerController.onPlayerDamageBlock(blockPos, side) player.swingArm(EnumHand.MAIN_HAND) @@ -121,8 +122,6 @@ class BreakBlock( // } // } } - - // getHitVec(blockPos, side) } } @@ -135,6 +134,7 @@ class BreakBlock( finish() } + // Sync with drops // if (it.packet is SPacketSpawnObject // && it.packet.type == 2 // && blockPos.distanceSq(Vec3i(it.packet.x, it.packet.y, it.packet.z)) < 1.0 @@ -152,16 +152,17 @@ class BreakBlock( } private fun finish() { - if (pickUpDrop) { - color = ColorHolder(252, 3, 207) - timeout = 10000L - addSubActivities( - Wait(50L), - PickUpDrops(initState.block.getItemDropped(initState, Random(), 0)), - SetState(ActivityStatus.SUCCESS) - ) - } else { + if (!pickUpDrop) { activityStatus = ActivityStatus.SUCCESS + return } + + color = ColorHolder(252, 3, 207) + + addSubActivities( + Wait(50L), + PickUpDrops(initState.block.getItemDropped(initState, Random(), 0)), + SetState(ActivityStatus.SUCCESS) + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt deleted file mode 100644 index 2e1e87ea9..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableItem.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.RotatingActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent -import com.lambda.client.manager.managers.PlayerPacketManager -import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.threads.safeListener -import net.minecraft.network.play.client.CPacketPlayerTryUseItem -import net.minecraft.network.play.server.SPacketOpenWindow -import net.minecraft.util.EnumHand -import net.minecraftforge.fml.common.gameevent.TickEvent - -class UseThrowableItem( - override var rotation: Vec2f = Vec2f.ZERO, - ) : RotatingActivity, Activity() { - - override fun SafeClientEvent.onInitialize() { - rotation = Vec2f(player.rotationYaw, 90f) - } - - init { - safeListener { - if (it.phase == TickEvent.Phase.END) { - connection.sendPacket(CPacketPlayerTryUseItem(EnumHand.MAIN_HAND)) - activityStatus = ActivityStatus.SUCCESS - } - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt new file mode 100644 index 000000000..6b8c832dc --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -0,0 +1,46 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.math.RotationUtils.getRotationToEntity +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import net.minecraft.entity.Entity +import net.minecraft.network.play.client.CPacketPlayerTryUseItem +import net.minecraft.util.EnumHand +import net.minecraftforge.fml.common.gameevent.TickEvent + +class UseThrowableOnEntity( + private val targetEntity: Entity, + private val amount: Int = 1, + private val useHand: EnumHand = EnumHand.MAIN_HAND, + override var rotation: Vec2f = Vec2f.ZERO, +) : RotatingActivity, Activity() { + private var used = 0 + + override fun SafeClientEvent.onInitialize() { + rotation = getRotation() + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + rotation = getRotation() + used++ + + if (used == amount) { + activityStatus = ActivityStatus.SUCCESS + } else { + connection.sendPacket(CPacketPlayerTryUseItem(useHand)) + } + } + } + + private fun SafeClientEvent.getRotation() = if (targetEntity == player) { + Vec2f(player.rotationYaw, 90f) + } else { + getRotationToEntity(targetEntity) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 68528d3d3..5f0c83b80 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -20,8 +20,8 @@ class SwapOrMoveToItem( override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) - }?.let { - addSubActivities(SwitchToHotbarSlot(it)) + }?.let { hotbarSlot -> + addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { player.allSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 760d93099..d217ba10d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -7,6 +7,7 @@ import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.highlevel.BuildBlock import com.lambda.client.activity.activities.highlevel.RaiseXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox @@ -102,6 +103,15 @@ object TestActivityManager : Module( false }) + private val ctirsgn by setting("Throw", false, consumer = { _, _-> + runSafe { + ActivityManager.addSubActivities( + UseThrowableOnEntity(player, amount = 64) + ) + } + false + }) + private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> ActivityManager.addSubActivities(SayAnnoyingly("Hello World")) false diff --git a/src/main/kotlin/com/lambda/client/util/items/Slot.kt b/src/main/kotlin/com/lambda/client/util/items/Slot.kt index c1e433c97..39f5da297 100644 --- a/src/main/kotlin/com/lambda/client/util/items/Slot.kt +++ b/src/main/kotlin/com/lambda/client/util/items/Slot.kt @@ -131,7 +131,7 @@ fun Slot.toHotbarSlotOrNull() = if (this.slotNumber in 36..44 && this.inventory == Wrapper.player?.inventory) HotbarSlot(this) else null -class HotbarSlot(slot: Slot) : Slot(slot.inventory, slot.slotIndex, slot.xPos, slot.yPos) { +class HotbarSlot(val slot: Slot) : Slot(slot.inventory, slot.slotIndex, slot.xPos, slot.yPos) { init { slotNumber = slot.slotNumber } From c6afc0b3be2ef797f56992efd4f5e45a7b599f90 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 07:26:59 +0100 Subject: [PATCH 029/104] Iterative instant activity updates --- .../com/lambda/client/activity/Activity.kt | 108 ++++++++++-------- .../activity/activities/ActivityTypes.kt | 14 +-- .../activities/example/ProbablyFailing.kt | 6 +- .../activities/example/SayAnnoyingly.kt | 3 +- .../activities/example/SayVeryAnnoyingly.kt | 3 +- .../activity/activities/example/WaitAndSay.kt | 2 +- .../highlevel/BreakDownEnderChests.kt | 4 +- .../activities/highlevel/BuildBlock.kt | 6 +- .../activities/highlevel/PlaceBlockSafely.kt | 3 +- .../activities/highlevel/RaiseXPLevel.kt | 4 +- .../highlevel/SurroundWithObsidian.kt | 3 +- .../activities/interaction/BreakBlock.kt | 10 +- .../activities/interaction/CloseContainer.kt | 5 +- .../activities/interaction/LookAtBlock.kt | 23 ---- .../activities/interaction/OpenContainer.kt | 22 +++- .../activities/interaction/PlaceBlock.kt | 20 ++-- .../interaction/UseThrowableOnEntity.kt | 2 +- .../activities/inventory/DumpInventory.kt | 3 +- .../activity/activities/inventory/DumpSlot.kt | 3 +- .../inventory/InventoryTransaction.kt | 2 +- .../activities/inventory/QuickMoveSlot.kt | 3 +- .../activities/inventory/SlotMustBeEmpty.kt | 6 +- .../activities/inventory/SwapHotbarSlots.kt | 4 +- .../activities/inventory/SwapOrMoveToItem.kt | 6 +- .../inventory/SwapOrSwitchToSlot.kt | 4 +- .../activities/inventory/SwapToBestTool.kt | 3 +- .../activities/inventory/SwapWithSlot.kt | 4 +- .../inventory/SwitchToHotbarSlot.kt | 4 +- .../activities/inventory/TakeOffArmor.kt | 5 +- .../inventory/TryClearSlotWithQuickMove.kt | 5 +- .../storage/BreakAndCollectShulker.kt | 3 +- .../storage/ExtractItemFromShulkerBox.kt | 3 +- .../activities/storage/OpenContainerInSlot.kt | 7 +- .../storage/PullItemsFromContainer.kt | 3 +- .../storage/PushItemsToContainer.kt | 3 +- .../storage/StoreItemToShulkerBox.kt | 3 +- .../activity/activities/travel/CustomGoal.kt | 9 +- .../activity/activities/travel/PickUpDrops.kt | 10 +- .../activities/travel/PickUpEntityItem.kt | 2 +- .../activity/activities/utils/SetState.kt | 11 +- .../client/activity/activities/utils/Wait.kt | 2 +- .../manager/managers/ActivityManager.kt | 49 ++++---- .../modules/misc/TestActivityManager.kt | 20 +++- .../modules/player/InventoryManagerTwo.kt | 12 +- 44 files changed, 214 insertions(+), 213 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index bf79f2794..304e1dad9 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -19,10 +19,13 @@ abstract class Activity { private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 + val name get() = this::class.simpleName + val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this enum class ActivityStatus { UNINITIALIZED, RUNNING, + PENDING, SUCCESS, FAILURE } @@ -34,50 +37,57 @@ abstract class Activity { updateActivity() } ActivityStatus.RUNNING -> { - if (this@Activity is TimeoutActivity) { - if (System.currentTimeMillis() > creationTime + timeout) { - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("${this@Activity::class.simpleName} fully timed out!") - } else { - usedAttempts++ - initialize() - LambdaMod.LOG.error("${this@Activity::class.simpleName} timed out!") - } - } else { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("${this@Activity::class.simpleName} fully timed out!") - } - } - } - if (this@Activity is InstantActivity) { - activityStatus = ActivityStatus.SUCCESS - } - if (this@Activity is DelayedActivity) { - if (System.currentTimeMillis() > creationTime + delay) { - onDelayedActivity() - } - } + if (!ListenerManager.listenerMap.containsKey(this@Activity) + && noSubActivities() + && this@Activity !is DelayedActivity + ) finalize() + } + ActivityStatus.PENDING -> { + owner.subActivities.remove(this@Activity) + owner.subActivities.add(this@Activity) + } + ActivityStatus.SUCCESS -> { + finalize() + } + ActivityStatus.FAILURE -> { + finalize() + LambdaMod.LOG.error("$name failed!") + } + } + } + + fun SafeClientEvent.updateTypesOnTick() { + if (this@Activity is TimeoutActivity) { + if (System.currentTimeMillis() > creationTime + timeout) { if (this@Activity is AttemptActivity) { if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("${this@Activity::class.simpleName} failed after $maxAttempts attempts!") - } - } - if (this@Activity is RotatingActivity) { - sendPlayerPacket { - rotate(rotation) + LambdaMod.LOG.error("$name fully timed out!") + } else { + usedAttempts++ + initialize() + LambdaMod.LOG.warn("$name timed out!") } + } else { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("$name fully timed out!") } } - ActivityStatus.SUCCESS -> { - finalize() -// LambdaMod.LOG.info("${this@Activity} activity finished successfully!") + } + if (this@Activity is DelayedActivity) { + if (System.currentTimeMillis() > creationTime + delay) { + onDelayedActivity() } - ActivityStatus.FAILURE -> { - finalize() - LambdaMod.LOG.error("Activity ${this@Activity::class.simpleName} failed!") + } + if (this@Activity is AttemptActivity) { + if (usedAttempts >= maxAttempts) { + activityStatus = ActivityStatus.FAILURE + LambdaMod.LOG.error("$name failed after $maxAttempts attempts!") + } + } + if (this@Activity is RotatingActivity) { + sendPlayerPacket { + rotate(rotation) } } } @@ -91,7 +101,7 @@ abstract class Activity { rotate(rotation) } } -// LambdaMod.LOG.info("Initialized activity: ${this@Activity}") + LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") } open fun SafeClientEvent.onInitialize() {} @@ -99,17 +109,15 @@ abstract class Activity { private fun SafeClientEvent.finalize() { onFinalize() owner.subActivities.remove(this@Activity) - LambdaMod.LOG.info("Finalized activity: ${this@Activity} after ${System.currentTimeMillis() - creationTime}ms") +// LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") + MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") - if (this@Activity is InstantActivity) { - with(ActivityManager) { - runActivity() - } + with(ActivityManager) { + updateCurrentActivity() } } open fun SafeClientEvent.onFinalize() {} - fun currentActivity(): Activity = subActivities.peek()?.currentActivity() ?: this fun Activity.addSubActivities(activities: List) { if (activities.isEmpty()) return @@ -126,7 +134,7 @@ abstract class Activity { } subActivities.addAll(activities) -// LambdaMod.LOG.info("Added ${activities.size} sub activities to ${this::class.simpleName}") +// LambdaMod.LOG.info("${System.currentTimeMillis()} Added ${activities.size} sub activities to $name") } fun Activity.addSubActivities(vararg activities: Activity) { @@ -147,12 +155,14 @@ abstract class Activity { fun noSubActivities() = subActivities.isEmpty() - fun setSuccess() { - activityStatus = ActivityStatus.SUCCESS + fun SafeClientEvent.onSuccess() { + finalize() } - fun setFailure() { - activityStatus = ActivityStatus.FAILURE + fun SafeClientEvent.onFailure() { + finalize() + + LambdaMod.LOG.warn("$name failed!") } override fun toString(): String { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index c765ba18d..7c823487e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -10,10 +10,10 @@ interface TimeoutActivity { val timeout: Long } -interface InstantActivity +interface CompoundActivity -interface ChainedActivity { - val nextActivity: Activity +interface ConcurrentActivity { + val max: Int } interface LoopingActivity { @@ -38,12 +38,4 @@ interface AttemptActivity { interface RenderBlockActivity { var renderBlockPos: BlockPos var color: ColorHolder -} - -interface CallbackActivity { - val owner: Activity -} - -interface ThrowableActivity { - val throwable: Throwable } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt index 65dcc19a4..331cef958 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt @@ -6,10 +6,10 @@ import kotlin.random.Random class ProbablyFailing : Activity() { override fun SafeClientEvent.onInitialize() { - activityStatus = if (Random.nextBoolean()) { - ActivityStatus.SUCCESS + if (Random.nextBoolean()) { + onSuccess() } else { - ActivityStatus.FAILURE + onFailure() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt index a5c907558..fbe48b267 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt @@ -1,10 +1,9 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -class SayAnnoyingly(private val message: String) : InstantActivity, Activity() { +class SayAnnoyingly(private val message: String) : Activity() { override fun SafeClientEvent.onInitialize() { message.split(" ").forEach { addSubActivities(SayVeryAnnoyingly(it)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt index f92a0ac93..429eab227 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt @@ -1,10 +1,9 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -class SayVeryAnnoyingly(private val message: String) : InstantActivity, Activity() { +class SayVeryAnnoyingly(private val message: String) : Activity() { override fun SafeClientEvent.onInitialize() { message.forEach { addSubActivities(ListenAndWait(it.toString(), 250)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt index f28275e96..05b320edf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt @@ -11,6 +11,6 @@ class WaitAndSay( ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) - activityStatus = ActivityStatus.SUCCESS + onSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 5eb04863a..ca097d703 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox @@ -16,7 +15,7 @@ import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items -class BreakDownEnderChests : InstantActivity, Activity() { +class BreakDownEnderChests : Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { remotePos -> if (player.inventorySlots.countEmpty() < 2) { @@ -36,6 +35,7 @@ class BreakDownEnderChests : InstantActivity, Activity() { BreakBlock( remotePos, pickUpDrop = true, + minPickUpAmount = 64, mode = BreakBlock.Mode.PLAYER_CONTROLLER ), SetState(ActivityStatus.UNINITIALIZED) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index ff016ec4b..d0e10a565 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent @@ -13,13 +13,13 @@ import net.minecraft.util.math.BlockPos class BuildBlock( private val blockPos: BlockPos, private val targetState: IBlockState, -) : InstantActivity, Activity() { +) : CompoundActivity, Activity() { override fun SafeClientEvent.onInitialize() { val currentState = world.getBlockState(blockPos) when { /* is in desired state */ - currentState == targetState -> setSuccess() + currentState == targetState -> onSuccess() // /* is blocked by entity */ // world.checkNoEntityCollision(currentState.getSelectedBoundingBox(world, blockPos), null) -> setFailure() /* block needs to be placed */ diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt index 757d4a55b..c192bc38b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.highlevel import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.travel.CustomGoal @@ -15,7 +14,7 @@ import net.minecraft.util.math.BlockPos class PlaceBlockSafely( private val blockPos: BlockPos, private val blockState: IBlockState, -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( SwapOrMoveToItem(blockState.block.item), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt index a47591055..f2b470581 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.TakeOffArmor @@ -12,8 +11,7 @@ import net.minecraft.util.math.BlockPos class RaiseXPLevel( private val desiredLevel: Int, private val xpSupply: BlockPos -) : InstantActivity, Activity() { - +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index 114d4251a..0b3bf806b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -1,12 +1,11 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import net.minecraft.init.Blocks -class SurroundWithObsidian : InstantActivity, Activity() { +class SurroundWithObsidian : Activity() { override fun SafeClientEvent.onInitialize() { player.flooredPosition.let { addSubActivities( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 505dfc9dd..5bd6e82b7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -31,6 +31,7 @@ class BreakBlock( private val playSound: Boolean = true, private val miningSpeedFactor: Float = 1.0f, private val pickUpDrop: Boolean = false, + private val minPickUpAmount: Int = 1, private val mode: Mode = Mode.PACKET, override var timeout: Long = 200L, override val maxAttempts: Int = 8, @@ -53,7 +54,7 @@ class BreakBlock( initState = world.getBlockState(blockPos) if (initState.block == Blocks.AIR) { - activityStatus = ActivityStatus.SUCCESS + onSuccess() color = ColorHolder(16, 74, 94) } else { ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() @@ -151,17 +152,16 @@ class BreakBlock( } } - private fun finish() { + private fun SafeClientEvent.finish() { if (!pickUpDrop) { - activityStatus = ActivityStatus.SUCCESS + onSuccess() return } color = ColorHolder(252, 3, 207) addSubActivities( - Wait(50L), - PickUpDrops(initState.block.getItemDropped(initState, Random(), 0)), + PickUpDrops(initState.block.getItemDropped(initState, Random(), 0), minAmount = minPickUpAmount), SetState(ActivityStatus.SUCCESS) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt index 173f2f673..2fcc8c3d7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt @@ -1,12 +1,11 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent -class CloseContainer : InstantActivity, Activity() { +class CloseContainer : Activity() { override fun SafeClientEvent.onInitialize() { player.closeScreen() - activityStatus = ActivityStatus.SUCCESS + onSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt deleted file mode 100644 index 24d4b0118..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/LookAtBlock.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.math.RotationUtils.getRotationTo -import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import com.lambda.client.util.world.getHitVec -import net.minecraft.network.play.client.CPacketPlayer -import net.minecraft.util.EnumFacing -import net.minecraft.util.math.BlockPos - -class LookAtBlock(private val blockPos: BlockPos) : Activity() { - override fun SafeClientEvent.onInitialize() { - val diff = player.getPositionEyes(1f).subtract(blockPos.toVec3dCenter()) - val normalizedVec = diff.normalize() - - val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) - - val rotation = getRotationTo(getHitVec(blockPos, side)) - - connection.sendPacket(CPacketPlayer.Rotation(rotation.x, rotation.y, player.onGround)) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index ebfb4a5de..6cf9e2b21 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.RotatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent @@ -13,14 +12,17 @@ import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketOpenWindow +import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraftforge.client.event.GuiOpenEvent +import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( private val containerPos: BlockPos, override var rotation: Vec2f = Vec2f.ZERO, -) : InstantActivity, RotatingActivity, Activity() { +) : RotatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() @@ -35,10 +37,18 @@ class OpenContainer( } init { - safeListener { - when (it.packet) { - is SPacketOpenWindow -> { - activityStatus = ActivityStatus.SUCCESS +// safeListener { +// when (it.packet) { +// is SPacketWindowItems -> { +// onSuccess() +// } +// } +// } + + safeListener { + if (it.phase == TickEvent.Phase.END) { + if (player.openContainer.windowId != 0) { + onSuccess() } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 5185cc944..13fcb3639 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,10 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.RenderBlockActivity -import com.lambda.client.activity.activities.RotatingActivity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder @@ -34,9 +31,9 @@ class PlaceBlock( ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { - val placedAtState = world.getBlockState(it.pos) + val placedAtBlock = world.getBlockState(it.pos).block - if (placedAtState.block in blockBlacklist) { + if (placedAtBlock in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } @@ -45,7 +42,7 @@ class PlaceBlock( connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) player.swingArm(EnumHand.MAIN_HAND) - if (placedAtState.block in blockBlacklist) { + if (placedAtBlock in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } @@ -67,8 +64,10 @@ class PlaceBlock( soundType.getPitch() * 0.8f ) } + +// activityStatus = ActivityStatus.PENDING } ?: run { - activityStatus = ActivityStatus.FAILURE + onFailure() color = ColorHolder(16, 74, 94) } } @@ -78,10 +77,7 @@ class PlaceBlock( if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos && it.packet.blockState.block == targetState.block - ) { - activityStatus = ActivityStatus.SUCCESS - color = ColorHolder(35, 188, 254) - } + ) onSuccess() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt index 6b8c832dc..ca00b6245 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -31,7 +31,7 @@ class UseThrowableOnEntity( used++ if (used == amount) { - activityStatus = ActivityStatus.SUCCESS + onSuccess() } else { connection.sendPacket(CPacketPlayerTryUseItem(useHand)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt index e41a3e0fc..39249c8d7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt @@ -1,11 +1,10 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots -class DumpInventory : InstantActivity, Activity() { +class DumpInventory : Activity() { override fun SafeClientEvent.onInitialize() { player.allSlots .filter { it.hasStack } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt index ea4042a6e..a27bb4aec 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt @@ -1,12 +1,11 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot -class DumpSlot(private val slot: Slot) : InstantActivity, Activity() { +class DumpSlot(private val slot: Slot) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 1, ClickType.THROW)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index 09123f78b..5f93a291d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -69,7 +69,7 @@ class InventoryTransaction( if (packet.wasAccepted()) { getContainerOrNull(packet.windowId)?.let { container -> container.slotClick(slot, mouseButton, type, player) - activityStatus = ActivityStatus.SUCCESS + onSuccess() LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") } ?: run { activityStatus = ActivityStatus.FAILURE diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt index 77b36bed0..b9a4b361d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt @@ -1,14 +1,13 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot class QuickMoveSlot( private val slot: Slot -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 0, ClickType.QUICK_MOVE)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt index 6d8980dd0..15b96dc83 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt @@ -9,10 +9,10 @@ class SlotMustBeEmpty( ) : Activity() { override fun SafeClientEvent.onInitialize() { - activityStatus = if (slot.stack.isEmpty) { - ActivityStatus.SUCCESS + if (slot.stack.isEmpty) { + onSuccess() } else { - ActivityStatus.FAILURE + onFailure() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt index 2e4aa758e..0810a4236 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType @@ -9,7 +9,7 @@ import net.minecraft.inventory.ClickType class SwapHotbarSlots( private val slotFrom: HotbarSlot, private val slotTo: HotbarSlot -) : InstantActivity, Activity() { +) : CompoundActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 5f0c83b80..46e41bcfa 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots @@ -16,7 +16,7 @@ class SwapOrMoveToItem( private val predicateSlot: (ItemStack) -> Boolean = { true }, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false -) : InstantActivity, Activity() { +) : CompoundActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) @@ -31,7 +31,7 @@ class SwapOrMoveToItem( if (useShulkerBoxes) { addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) } else { - activityStatus = ActivityStatus.FAILURE + onFailure() MessageSendHelper.sendErrorMessage("No $item found in inventory (shulkers are disabled)") } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt index 98a0ef809..1b11647e4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.firstEmpty import com.lambda.client.util.items.hotbarSlots @@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack class SwapOrSwitchToSlot( private val slot: Slot, private val predicateSlot: (ItemStack) -> Boolean = { true } -) : InstantActivity, Activity() { +) : CompoundActivity, Activity() { override fun SafeClientEvent.onInitialize() { slot.toHotbarSlotOrNull()?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt index a8440b0bd..eda53622f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt @@ -1,14 +1,13 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.inventorySlots import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments import net.minecraft.util.math.BlockPos -class SwapToBestTool(private val blockPos: BlockPos) : InstantActivity, Activity() { +class SwapToBestTool(private val blockPos: BlockPos) : Activity() { override fun SafeClientEvent.onInitialize() { player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index b0b552d9d..b9c152068 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity +import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType @@ -10,7 +10,7 @@ import net.minecraft.inventory.Slot class SwapWithSlot( private val slotFrom: Slot, private val slotTo: HotbarSlot -) : InstantActivity, Activity() { +) : CompoundActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt index 8d4e623b5..85939c4f9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt @@ -1,14 +1,14 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.HotbarSlot -class SwitchToHotbarSlot(private val slot: HotbarSlot) : InstantActivity, Activity() { +class SwitchToHotbarSlot(private val slot: HotbarSlot) : Activity() { override fun SafeClientEvent.onInitialize() { if (slot.hotbarSlot !in 0..8) return player.inventory.currentItem = slot.hotbarSlot playerController.updateController() + onSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt index 9444fc266..107a98099 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt @@ -1,15 +1,12 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.armorSlots -import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.offhandSlot import net.minecraft.inventory.ClickType -class TakeOffArmor : InstantActivity, Activity() { +class TakeOffArmor : Activity() { override fun SafeClientEvent.onInitialize() { player.armorSlots.forEach { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt index 46f4bafe5..682608684 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt @@ -1,17 +1,16 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.inventory.Slot class TryClearSlotWithQuickMove( private val slot: Slot -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { if (slot.stack.isEmpty) { - activityStatus = ActivityStatus.SUCCESS + onSuccess() } else { addSubActivities( QuickMoveSlot(slot), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt index 3a4e4c5fc..d8ae50bd6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent @@ -9,7 +8,7 @@ import net.minecraft.util.math.BlockPos class BreakAndCollectShulker( private val blockPos: BlockPos -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( SwapToBestTool(blockPos), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 40ef61931..da37e418d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.utils.getContainerPos @@ -17,7 +16,7 @@ class ExtractItemFromShulkerBox( private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true } -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { // if (player.inventorySlots.item) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index a8169d1b4..9c325338f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -2,12 +2,10 @@ package com.lambda.client.activity.activities.storage import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.travel.CustomGoal -import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.block @@ -15,15 +13,14 @@ import net.minecraft.inventory.Slot class OpenContainerInSlot( private val slot: Slot -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { containerPos -> addSubActivities( CustomGoal(GoalNear(containerPos, 3)), SwapOrSwitchToSlot(slot), PlaceBlock(containerPos, slot.stack.item.block.defaultState), - OpenContainer(containerPos), - Wait(50L) + OpenContainer(containerPos) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index baf18717e..4ed34ca1e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty @@ -13,7 +12,7 @@ class PullItemsFromContainer( private val item: Item, private val amount: Int, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { val maxEmpty = player.inventorySlots.countEmpty() - 1 diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index 19a9a8fbe..f7d189361 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.getSlots @@ -12,7 +11,7 @@ class PushItemsToContainer( private val item: Item, private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { val openContainer = player.openContainer diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 379981364..7d814f83c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.utils.getShulkerInventory @@ -15,7 +14,7 @@ class StoreItemToShulkerBox( private val item: Item, private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } -) : InstantActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { val candidates = mutableMapOf() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index d9243f5d3..7ec3e9e9e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.Goal import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener @@ -12,13 +13,19 @@ class CustomGoal( private val goal: Goal, override val timeout: Long = 100000L ) : TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + if (!goal.isInGoal(player.flooredPosition)) return + + onSuccess() + } + init { safeListener { event -> if (event.phase != TickEvent.Phase.START) return@safeListener BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) - if (goal.isInGoal(player.flooredPosition)) activityStatus = ActivityStatus.SUCCESS + if (goal.isInGoal(player.flooredPosition)) onSuccess() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 463fb4e67..7e61efd85 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.InstantActivity import com.lambda.client.activity.activities.utils.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo @@ -12,16 +11,19 @@ import net.minecraft.item.ItemStack class PickUpDrops( private val item: Item, private val predicate: (ItemStack) -> Boolean = { true }, - private val maxRange: Float = 10.0f -) : InstantActivity, Activity() { + private val maxRange: Float = 10.0f, + private val minAmount: Int = 1, +) : Activity() { override fun SafeClientEvent.onInitialize() { val drops = world.loadedEntityList.filterIsInstance().filter { it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) } if (drops.isEmpty()) { - activityStatus = ActivityStatus.SUCCESS + onSuccess() } else { + if (drops.size < minAmount) return + drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> addSubActivities( PickUpEntityItem(drop), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 88f194bd5..c6a09fef6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -36,7 +36,7 @@ class PickUpEntityItem( } } } else { - activityStatus = ActivityStatus.SUCCESS + onSuccess() BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt index f7f710289..05412fe5b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt @@ -5,7 +5,14 @@ import com.lambda.client.event.SafeClientEvent class SetState(private val state: ActivityStatus) : Activity() { override fun SafeClientEvent.onInitialize() { - owner.activityStatus = state - activityStatus = ActivityStatus.SUCCESS + with(owner) { + when (state) { + ActivityStatus.UNINITIALIZED -> activityStatus = state + ActivityStatus.SUCCESS -> onSuccess() + ActivityStatus.RUNNING -> activityStatus = state + ActivityStatus.PENDING -> activityStatus = state + ActivityStatus.FAILURE -> onFailure() + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt index f3937eae8..5dd654886 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt @@ -8,6 +8,6 @@ class Wait( override val delay: Long ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { - activityStatus = ActivityStatus.SUCCESS + onSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 1028ce245..35d86ce7e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -15,17 +15,23 @@ import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 - private var lastActivity: Activity = this + var lastActivity: Activity = this init { safeListener { event -> if (noSubActivities() || event.phase != TickEvent.Phase.START) return@safeListener - runActivity() + with(currentActivity) { + if (activityStatus == ActivityStatus.RUNNING) updateTypesOnTick() + } + + repeat(10) { + updateCurrentActivity() + } } safeListener { - val currentActivity = currentActivity() + val currentActivity = currentActivity if (currentActivity !is RenderBlockActivity) return@safeListener @@ -37,15 +43,28 @@ object ActivityManager : Manager, Activity() { } } - fun SafeClientEvent.runActivity() { - with(currentActivity()) { - updateListener() + fun SafeClientEvent.updateCurrentActivity() { + val currentActivity = currentActivity + + with(currentActivity) { + if (currentActivity != lastActivity) { + if (lastActivity !is ActivityManager) { + LambdaEventBus.unsubscribe(lastActivity) + ListenerManager.unregister(lastActivity) + } + + LambdaEventBus.subscribe(currentActivity) + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + + lastActivity = currentActivity + } + updateActivity() } } fun reset() { - if (lastActivity !is ActivityManager) { + if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } @@ -54,20 +73,4 @@ object ActivityManager : Manager, Activity() { lastActivity = ActivityManager } - - private fun updateListener() { - val currentActivity = currentActivity() - - if (currentActivity == lastActivity) return - - if (lastActivity !is ActivityManager) { - LambdaEventBus.unsubscribe(lastActivity) - ListenerManager.unregister(lastActivity) - } - - LambdaEventBus.subscribe(currentActivity) - BaritoneUtils.primary?.pathingBehavior?.cancelEverything() - - lastActivity = currentActivity - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index d217ba10d..b657964b8 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -11,6 +11,8 @@ import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.storage.OpenContainerInSlot +import com.lambda.client.activity.activities.storage.PushItemsToContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.manager.managers.ActivityManager @@ -122,8 +124,17 @@ object TestActivityManager : Module( false }) - private val reset by setting("Reset", false, consumer = { _, _-> - ActivityManager.reset() + private val pullll by setting("pull", false, consumer = { _, _-> + ActivityManager.addSubActivities( + ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item, amount = 1) + ) + false + }) + + private val pusshhh by setting("push", false, consumer = { _, _-> + ActivityManager.addSubActivities( + PushItemsToContainer(Blocks.OBSIDIAN.item, amount = 1) + ) false }) @@ -131,4 +142,9 @@ object TestActivityManager : Module( ActivityManager.addSubActivities(RaiseXPLevel(3, BlockPos.ORIGIN)) false }) + + private val reset by setting("Reset", false, consumer = { _, _-> + ActivityManager.reset() + false + }) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index f470095c5..43bd37055 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -11,12 +11,14 @@ import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener +import net.minecraft.block.BlockShulkerBox import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.inventory.ClickType import net.minecraft.item.ItemShulkerBox import net.minecraft.util.math.BlockPos +import java.util.* object InventoryManagerTwo : Module( name = "InventoryManagerTwo", @@ -27,7 +29,7 @@ object InventoryManagerTwo : Module( init { safeListener { - if (it.type != ClickType.PICKUP) return@safeListener + if (it.type != ClickType.PICKUP || it.mouseButton != 1) return@safeListener player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener @@ -37,9 +39,8 @@ object InventoryManagerTwo : Module( ActivityManager.addSubActivities( OpenContainerInSlot(slot) ) + it.cancel() } - - it.cancel() } } @@ -47,10 +48,13 @@ object InventoryManagerTwo : Module( if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener placedShulkerBoxes.firstOrNull()?.let { containerPos -> + placedShulkerBoxes.remove(containerPos) + + if (world.getBlockState(containerPos).block !is BlockShulkerBox) return@safeListener + ActivityManager.addSubActivities( BreakAndCollectShulker(containerPos) ) - placedShulkerBoxes.remove(containerPos) } } } From 5e91ba7692b7017225e604b643034211f1a94231 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 07:47:26 +0100 Subject: [PATCH 030/104] Added LoopingAmountActivity type --- .../kotlin/com/lambda/client/activity/Activity.kt | 13 +++++++++++-- .../client/activity/activities/ActivityTypes.kt | 8 ++++++-- .../activities/highlevel/BreakDownEnderChests.kt | 14 +++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 304e1dad9..4d2a7a731 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -109,12 +109,21 @@ abstract class Activity { private fun SafeClientEvent.finalize() { onFinalize() owner.subActivities.remove(this@Activity) -// LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") - MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") + + if (this@Activity is LoopingAmountActivity) { + if (loops++ < loopingAmount || loopingAmount == 0) { + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.add(this@Activity) + LambdaMod.LOG.info("Looping $name [$loops/${if (loopingAmount == 0) "∞" else loopingAmount}] ") + } + } with(ActivityManager) { updateCurrentActivity() } + + // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") + MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") } open fun SafeClientEvent.onFinalize() {} diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index 7c823487e..a80c8e023 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -1,6 +1,5 @@ package com.lambda.client.activity.activities -import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.math.Vec2f @@ -16,8 +15,13 @@ interface ConcurrentActivity { val max: Int } -interface LoopingActivity { +interface LoopingAmountActivity { val loopingAmount: Int + var loops: Int +} + +interface LoopingTimeActivity { + val loopUntilTimestamp: Long } interface RotatingActivity { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index ca097d703..2076d0af0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -1,10 +1,10 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.LoopingAmountActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox -import com.lambda.client.activity.activities.utils.SetState import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty @@ -15,13 +15,15 @@ import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items -class BreakDownEnderChests : Activity() { +class BreakDownEnderChests( + override val loopingAmount: Int = 0, + override var loops: Int = 0 +) : LoopingAmountActivity, Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { remotePos -> if (player.inventorySlots.countEmpty() < 2) { addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item), - SetState(ActivityStatus.UNINITIALIZED) + StoreItemToShulkerBox(Blocks.OBSIDIAN.item) ) } else { addSubActivities( @@ -37,11 +39,9 @@ class BreakDownEnderChests : Activity() { pickUpDrop = true, minPickUpAmount = 64, mode = BreakBlock.Mode.PLAYER_CONTROLLER - ), - SetState(ActivityStatus.UNINITIALIZED) + ) ) } } - } } \ No newline at end of file From cb672e432feb8cc95fa5641ab118c4a6d7fc1fc1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 08:50:47 +0100 Subject: [PATCH 031/104] Added LoopingUntilActivity type and removed CompoundActivity --- .../kotlin/com/lambda/client/activity/Activity.kt | 13 +++++++++++-- .../client/activity/activities/ActivityTypes.kt | 13 ++++++++----- .../activities/highlevel/BreakDownEnderChests.kt | 4 ++-- .../activity/activities/highlevel/BuildBlock.kt | 3 +-- .../activities/highlevel/PlaceBlockSafely.kt | 1 - .../activity/activities/highlevel/RaiseXPLevel.kt | 14 ++++++++------ .../activities/interaction/UseThrowableOnEntity.kt | 9 ++++----- .../activities/inventory/SwapHotbarSlots.kt | 3 +-- .../activities/inventory/SwapOrMoveToItem.kt | 3 +-- .../activities/inventory/SwapOrSwitchToSlot.kt | 3 +-- .../activity/activities/inventory/SwapWithSlot.kt | 3 +-- .../activity/activities/inventory/TakeOffArmor.kt | 14 ++++---------- .../inventory/TryClearSlotWithQuickMove.kt | 2 -- .../module/modules/misc/TestActivityManager.kt | 2 +- 14 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 4d2a7a731..3543fbffc 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -111,10 +111,19 @@ abstract class Activity { owner.subActivities.remove(this@Activity) if (this@Activity is LoopingAmountActivity) { - if (loops++ < loopingAmount || loopingAmount == 0) { + if (currentLoops++ < maxLoops || maxLoops == 0) { activityStatus = ActivityStatus.UNINITIALIZED owner.subActivities.add(this@Activity) - LambdaMod.LOG.info("Looping $name [$loops/${if (loopingAmount == 0) "∞" else loopingAmount}] ") + LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") + } + } + + if (this@Activity is LoopingUntilActivity) { + if (!loopUntil()) { + currentLoops++ + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.add(this@Activity) + LambdaMod.LOG.info("Looping $name ($currentLoops) ") } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt index a80c8e023..488e90810 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt @@ -9,15 +9,18 @@ interface TimeoutActivity { val timeout: Long } -interface CompoundActivity - interface ConcurrentActivity { - val max: Int + val maxActivities: Int } interface LoopingAmountActivity { - val loopingAmount: Int - var loops: Int + val maxLoops: Int + var currentLoops: Int +} + +interface LoopingUntilActivity { + val loopUntil: SafeClientEvent.() -> Boolean + var currentLoops: Int } interface LoopingTimeActivity { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 2076d0af0..2df9ea16e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -16,8 +16,8 @@ import net.minecraft.init.Enchantments import net.minecraft.init.Items class BreakDownEnderChests( - override val loopingAmount: Int = 0, - override var loops: Int = 0 + override val maxLoops: Int = 0, + override var currentLoops: Int = 0 ) : LoopingAmountActivity, Activity() { override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { remotePos -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index d0e10a565..95cf5bb9f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent @@ -13,7 +12,7 @@ import net.minecraft.util.math.BlockPos class BuildBlock( private val blockPos: BlockPos, private val targetState: IBlockState, -) : CompoundActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { val currentState = world.getBlockState(blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt index c192bc38b..740c99420 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt @@ -7,7 +7,6 @@ import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item -import net.minecraft.block.Block import net.minecraft.block.state.IBlockState import net.minecraft.util.math.BlockPos diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt index f2b470581..658be454a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.LoopingUntilActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.TakeOffArmor @@ -10,15 +11,16 @@ import net.minecraft.util.math.BlockPos class RaiseXPLevel( private val desiredLevel: Int, - private val xpSupply: BlockPos -) : Activity() { + private val xpSupply: BlockPos, + override val loopUntil: SafeClientEvent.() -> Boolean = { + player.experienceLevel >= desiredLevel + }, + override var currentLoops: Int = 0 +) : LoopingUntilActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), - SwapOrMoveToItem( - Items.EXPERIENCE_BOTTLE, - useShulkerBoxes = false - ), + SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE), UseThrowableOnEntity(player) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt index ca00b6245..da43331d5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -28,13 +28,12 @@ class UseThrowableOnEntity( if (it.phase != TickEvent.Phase.START) return@safeListener rotation = getRotation() + + connection.sendPacket(CPacketPlayerTryUseItem(useHand)) + used++ - if (used == amount) { - onSuccess() - } else { - connection.sendPacket(CPacketPlayerTryUseItem(useHand)) - } + if (used == amount) onSuccess() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt index 0810a4236..819dff237 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType @@ -9,7 +8,7 @@ import net.minecraft.inventory.ClickType class SwapHotbarSlots( private val slotFrom: HotbarSlot, private val slotTo: HotbarSlot -) : CompoundActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 46e41bcfa..0bfd5cc84 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots @@ -16,7 +15,7 @@ class SwapOrMoveToItem( private val predicateSlot: (ItemStack) -> Boolean = { true }, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false -) : CompoundActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt index 1b11647e4..8de6b5628 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.firstEmpty import com.lambda.client.util.items.hotbarSlots @@ -12,7 +11,7 @@ import net.minecraft.item.ItemStack class SwapOrSwitchToSlot( private val slot: Slot, private val predicateSlot: (ItemStack) -> Boolean = { true } -) : CompoundActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { slot.toHotbarSlotOrNull()?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index b9c152068..30cf6ea3d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.CompoundActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType @@ -10,7 +9,7 @@ import net.minecraft.inventory.Slot class SwapWithSlot( private val slotFrom: Slot, private val slotTo: HotbarSlot -) : CompoundActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt index 107a98099..c49347d3b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt @@ -4,19 +4,13 @@ import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.armorSlots import com.lambda.client.util.items.offhandSlot -import net.minecraft.inventory.ClickType class TakeOffArmor : Activity() { - override fun SafeClientEvent.onInitialize() { - player.armorSlots.forEach { - addSubActivities( - TryClearSlotWithQuickMove(it) - ) + (player.armorSlots + player.offhandSlot).forEach { slot -> + if (slot.stack.isEmpty) return@forEach + + addSubActivities(TryClearSlotWithQuickMove(slot)) } - addSubActivities( - TryClearSlotWithQuickMove(player.offhandSlot) - ) } - } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt index 682608684..300a35046 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt @@ -7,7 +7,6 @@ import net.minecraft.inventory.Slot class TryClearSlotWithQuickMove( private val slot: Slot ) : Activity() { - override fun SafeClientEvent.onInitialize() { if (slot.stack.isEmpty) { onSuccess() @@ -18,5 +17,4 @@ class TryClearSlotWithQuickMove( ) } } - } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index b657964b8..bdccb63a7 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -139,7 +139,7 @@ object TestActivityManager : Module( }) val raiseXPLevel by setting("RaiseXPLevel", false, consumer = { _, _-> - ActivityManager.addSubActivities(RaiseXPLevel(3, BlockPos.ORIGIN)) + ActivityManager.addSubActivities(RaiseXPLevel(57, BlockPos.ORIGIN)) false }) From 566cfde348fcaae0842c9a26e959443b5b6ba01b Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 08:56:14 +0100 Subject: [PATCH 032/104] Change example --- .../highlevel/{RaiseXPLevel.kt => ReachXPLevel.kt} | 4 ++-- .../client/module/modules/misc/TestActivityManager.kt | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) rename src/main/kotlin/com/lambda/client/activity/activities/highlevel/{RaiseXPLevel.kt => ReachXPLevel.kt} (89%) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt similarity index 89% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt rename to src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 658be454a..215c20433 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/RaiseXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -9,9 +9,9 @@ import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items import net.minecraft.util.math.BlockPos -class RaiseXPLevel( +class ReachXPLevel( private val desiredLevel: Int, - private val xpSupply: BlockPos, +// private val xpSupply: BlockPos, should be replaced with using ecosystem for stashes override val loopUntil: SafeClientEvent.() -> Boolean = { player.experienceLevel >= desiredLevel }, diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index bdccb63a7..98bad9d6f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,14 +4,12 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests -import com.lambda.client.activity.activities.highlevel.BuildBlock -import com.lambda.client.activity.activities.highlevel.RaiseXPLevel +import com.lambda.client.activity.activities.highlevel.ReachXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox -import com.lambda.client.activity.activities.storage.OpenContainerInSlot import com.lambda.client.activity.activities.storage.PushItemsToContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops @@ -138,8 +136,8 @@ object TestActivityManager : Module( false }) - val raiseXPLevel by setting("RaiseXPLevel", false, consumer = { _, _-> - ActivityManager.addSubActivities(RaiseXPLevel(57, BlockPos.ORIGIN)) + val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> + ActivityManager.addSubActivities(ReachXPLevel(30, BlockPos.ORIGIN)) false }) From a1d45dfb2812da9bcdccd78f6b7079add0cffe63 Mon Sep 17 00:00:00 2001 From: minecraft-simon Date: Fri, 30 Dec 2022 18:05:36 +0100 Subject: [PATCH 033/104] proposal for activity events --- .../com/lambda/client/activity/Activity.kt | 4 +++ .../activities/highlevel/ReachXPLevel.kt | 27 ++++++++++++++----- .../modules/misc/TestActivityManager.kt | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 3543fbffc..875e84b19 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -14,6 +14,9 @@ import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { + var executeOnSuccess: (() -> Unit)? = null + var executeOnFailure: ((Exception) -> Unit)? = null + var executeOnFinalize: (() -> Unit)? = null val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED private var creationTime = 0L @@ -108,6 +111,7 @@ abstract class Activity { private fun SafeClientEvent.finalize() { onFinalize() + executeOnFinalize?.invoke() owner.subActivities.remove(this@Activity) if (this@Activity is LoopingAmountActivity) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 215c20433..4f4516c45 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -3,25 +3,40 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.LoopingUntilActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity +import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.TakeOffArmor import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.onSuccess import net.minecraft.init.Items import net.minecraft.util.math.BlockPos class ReachXPLevel( private val desiredLevel: Int, // private val xpSupply: BlockPos, should be replaced with using ecosystem for stashes - override val loopUntil: SafeClientEvent.() -> Boolean = { - player.experienceLevel >= desiredLevel - }, - override var currentLoops: Int = 0 -) : LoopingUntilActivity, Activity() { + //override val loopUntil: SafeClientEvent.() -> Boolean = { + // player.experienceLevel >= desiredLevel + //}, + //override var currentLoops: Int = 0 +) : Activity() { override fun SafeClientEvent.onInitialize() { + val useThrowableOnEntity = UseThrowableOnEntity(player) + useThrowableOnEntity.executeOnSuccess = { + println("Successfully used throwable on entity") + } + useThrowableOnEntity.executeOnFailure = { + println("Error: ${it.message}") + } + useThrowableOnEntity.executeOnFinalize = { + println("Finalized throwable on entity") + addSubActivities( + DumpInventory() + ) + } addSubActivities( TakeOffArmor(), SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE), - UseThrowableOnEntity(player) + useThrowableOnEntity ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 98bad9d6f..7ee1e301a 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -137,7 +137,7 @@ object TestActivityManager : Module( }) val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> - ActivityManager.addSubActivities(ReachXPLevel(30, BlockPos.ORIGIN)) + ActivityManager.addSubActivities(ReachXPLevel(30)) false }) From b4a41c55be06ad1475721dc120dbbb3de470f492 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 18:59:36 +0100 Subject: [PATCH 034/104] Use instead of SetState --- .../com/lambda/client/activity/Activity.kt | 17 +++++++++-------- .../activities/interaction/BreakBlock.kt | 9 +++++++-- .../activity/activities/travel/PickUpDrops.kt | 9 +++++++-- .../activity/activities/utils/SetState.kt | 2 +- .../client/manager/managers/ActivityManager.kt | 4 +++- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 875e84b19..d1ab01b61 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -14,9 +14,6 @@ import com.lambda.client.util.text.capitalize import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { - var executeOnSuccess: (() -> Unit)? = null - var executeOnFailure: ((Exception) -> Unit)? = null - var executeOnFinalize: (() -> Unit)? = null val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED private var creationTime = 0L @@ -25,10 +22,14 @@ abstract class Activity { val name get() = this::class.simpleName val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this + var executeOnSuccess: (() -> Unit)? = null + var executeOnFailure: ((Exception) -> Unit)? = null + var executeOnFinalize: (() -> Unit)? = null + enum class ActivityStatus { UNINITIALIZED, RUNNING, - PENDING, +// PENDING, SUCCESS, FAILURE } @@ -45,10 +46,10 @@ abstract class Activity { && this@Activity !is DelayedActivity ) finalize() } - ActivityStatus.PENDING -> { - owner.subActivities.remove(this@Activity) - owner.subActivities.add(this@Activity) - } +// ActivityStatus.PENDING -> { +// owner.subActivities.remove(this@Activity) +// owner.subActivities.add(this@Activity) +// } ActivityStatus.SUCCESS -> { finalize() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 5bd6e82b7..a882f618c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -161,8 +161,13 @@ class BreakBlock( color = ColorHolder(252, 3, 207) addSubActivities( - PickUpDrops(initState.block.getItemDropped(initState, Random(), 0), minAmount = minPickUpAmount), - SetState(ActivityStatus.SUCCESS) + PickUpDrops(initState.block.getItemDropped(initState, Random(), 0), minAmount = minPickUpAmount).also { + executeOnSuccess = { + with(owner) { + onSuccess() + } + } + } ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 7e61efd85..81ae9f60b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -26,8 +26,13 @@ class PickUpDrops( drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> addSubActivities( - PickUpEntityItem(drop), - SetState(ActivityStatus.UNINITIALIZED) + PickUpEntityItem(drop).also { + executeOnFinalize = { + with(owner) { + onSuccess() + } + } + } ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt index 05412fe5b..c7fc58b02 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt @@ -10,7 +10,7 @@ class SetState(private val state: ActivityStatus) : Activity() { ActivityStatus.UNINITIALIZED -> activityStatus = state ActivityStatus.SUCCESS -> onSuccess() ActivityStatus.RUNNING -> activityStatus = state - ActivityStatus.PENDING -> activityStatus = state +// ActivityStatus.PENDING -> activityStatus = state ActivityStatus.FAILURE -> onFailure() } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 35d86ce7e..0f2c6b537 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -48,6 +48,7 @@ object ActivityManager : Manager, Activity() { with(currentActivity) { if (currentActivity != lastActivity) { +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) @@ -64,7 +65,8 @@ object ActivityManager : Manager, Activity() { } fun reset() { - if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { + if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } From 5a23c0b3df07d99353523ad37c04cdc96b3fe976 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 22:58:49 +0100 Subject: [PATCH 035/104] Fix stuff --- .../com/lambda/client/activity/Activity.kt | 34 ++++++++++++------- .../activities/example/ProbablyFailing.kt | 3 +- .../activities/highlevel/BuildStructure.kt | 22 ++++++++++++ .../activities/highlevel/ReachXPLevel.kt | 28 +++++---------- .../highlevel/SurroundWithObsidian.kt | 27 ++++++++++----- .../activities/interaction/PlaceBlock.kt | 3 +- .../activities/inventory/SlotMustBeEmpty.kt | 3 +- .../activities/inventory/SwapOrMoveToItem.kt | 3 +- .../activity/activities/utils/SetState.kt | 5 +-- .../manager/managers/ActivityManager.kt | 8 ++--- .../modules/misc/TestActivityManager.kt | 29 ++++++++++++++-- 11 files changed, 111 insertions(+), 54 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index d1ab01b61..6da520625 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -11,6 +11,7 @@ import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.text.capitalize +import java.util.ConcurrentModificationException import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { @@ -29,7 +30,7 @@ abstract class Activity { enum class ActivityStatus { UNINITIALIZED, RUNNING, -// PENDING, + PENDING, SUCCESS, FAILURE } @@ -38,7 +39,6 @@ abstract class Activity { when (activityStatus) { ActivityStatus.UNINITIALIZED -> { initialize() - updateActivity() } ActivityStatus.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) @@ -46,14 +46,16 @@ abstract class Activity { && this@Activity !is DelayedActivity ) finalize() } -// ActivityStatus.PENDING -> { -// owner.subActivities.remove(this@Activity) -// owner.subActivities.add(this@Activity) -// } + ActivityStatus.PENDING -> { + owner.subActivities.remove(this@Activity) + owner.subActivities.add(this@Activity) + } ActivityStatus.SUCCESS -> { + executeOnSuccess?.invoke() finalize() } ActivityStatus.FAILURE -> { + executeOnFailure?.invoke(Exception("Activity failed")) finalize() LambdaMod.LOG.error("$name failed!") } @@ -105,7 +107,7 @@ abstract class Activity { rotate(rotation) } } - LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") +// LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") } open fun SafeClientEvent.onInitialize() {} @@ -132,12 +134,12 @@ abstract class Activity { } } - with(ActivityManager) { - updateCurrentActivity() - } +// with(ActivityManager) { +// updateCurrentActivity() +// } // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") - MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") +// MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") } open fun SafeClientEvent.onFinalize() {} @@ -179,15 +181,23 @@ abstract class Activity { fun noSubActivities() = subActivities.isEmpty() fun SafeClientEvent.onSuccess() { + executeOnSuccess?.invoke() finalize() } - fun SafeClientEvent.onFailure() { + fun SafeClientEvent.onFailure(exception: Exception) { + executeOnFailure?.invoke(exception) finalize() LambdaMod.LOG.warn("$name failed!") } + fun refresh() { + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.remove(this) + owner.subActivities.add(this) + } + override fun toString(): String { return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt index 331cef958..a8c89798c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent +import java.lang.Exception import kotlin.random.Random class ProbablyFailing : Activity() { @@ -9,7 +10,7 @@ class ProbablyFailing : Activity() { if (Random.nextBoolean()) { onSuccess() } else { - onFailure() + onFailure(Exception("Randomly failed")) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt new file mode 100644 index 000000000..8f559020f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -0,0 +1,22 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class BuildStructure( + private val structure: Map +) : Activity() { + override fun SafeClientEvent.onInitialize() { + structure.forEach { (pos, state) -> + addSubActivities( + BuildBlock(pos, state).also { + executeOnFailure = { + refresh() + } + } + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 4f4516c45..89caa5517 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -13,30 +13,18 @@ import net.minecraft.util.math.BlockPos class ReachXPLevel( private val desiredLevel: Int, -// private val xpSupply: BlockPos, should be replaced with using ecosystem for stashes - //override val loopUntil: SafeClientEvent.() -> Boolean = { - // player.experienceLevel >= desiredLevel - //}, - //override var currentLoops: Int = 0 -) : Activity() { + override val loopUntil: SafeClientEvent.() -> Boolean = { + player.experienceLevel >= desiredLevel + }, + override var currentLoops: Int = 0 +) : LoopingUntilActivity, Activity() { override fun SafeClientEvent.onInitialize() { - val useThrowableOnEntity = UseThrowableOnEntity(player) - useThrowableOnEntity.executeOnSuccess = { - println("Successfully used throwable on entity") - } - useThrowableOnEntity.executeOnFailure = { - println("Error: ${it.message}") - } - useThrowableOnEntity.executeOnFinalize = { - println("Finalized throwable on entity") - addSubActivities( - DumpInventory() - ) - } + + addSubActivities( TakeOffArmor(), SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE), - useThrowableOnEntity + UseThrowableOnEntity(player) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index 0b3bf806b..f36f29294 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -1,19 +1,28 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.LoopingUntilActivity +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.MovementUtils.centerPlayer import net.minecraft.init.Blocks +import net.minecraft.util.math.BlockPos -class SurroundWithObsidian : Activity() { +class SurroundWithObsidian( + private val originPos: BlockPos, + override val loopUntil: SafeClientEvent.() -> Boolean = { + originPos != player.flooredPosition + }, + override var currentLoops: Int = 0 +) : LoopingUntilActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.flooredPosition.let { - addSubActivities( - BuildBlock(it.north(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(it.south(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(it.east(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(it.west(), Blocks.SLIME_BLOCK.defaultState) - ) - } + addSubActivities( + BuildBlock(originPos.north(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(originPos.south(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(originPos.east(), Blocks.SLIME_BLOCK.defaultState), + BuildBlock(originPos.west(), Blocks.SLIME_BLOCK.defaultState), + Wait(10L) + ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 13fcb3639..cebb21b24 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -17,6 +17,7 @@ import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos +import java.lang.Exception class PlaceBlock( private val blockPos: BlockPos, @@ -67,7 +68,7 @@ class PlaceBlock( // activityStatus = ActivityStatus.PENDING } ?: run { - onFailure() + onFailure(Exception("No neighbour found")) color = ColorHolder(16, 74, 94) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt index 15b96dc83..bfee77f03 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import net.minecraft.inventory.Slot +import java.lang.Exception class SlotMustBeEmpty( private val slot: Slot @@ -12,7 +13,7 @@ class SlotMustBeEmpty( if (slot.stack.isEmpty) { onSuccess() } else { - onFailure() + onFailure(Exception("Slot must be empty")) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index 0bfd5cc84..b6f8c618c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -8,6 +8,7 @@ import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.text.MessageSendHelper import net.minecraft.item.Item import net.minecraft.item.ItemStack +import java.lang.Exception class SwapOrMoveToItem( private val item: Item, @@ -30,7 +31,7 @@ class SwapOrMoveToItem( if (useShulkerBoxes) { addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) } else { - onFailure() + onFailure(Exception("No $item found in inventory (shulkers are disabled)")) MessageSendHelper.sendErrorMessage("No $item found in inventory (shulkers are disabled)") } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt index c7fc58b02..37680cd7b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.utils import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent +import java.lang.Exception class SetState(private val state: ActivityStatus) : Activity() { override fun SafeClientEvent.onInitialize() { @@ -10,8 +11,8 @@ class SetState(private val state: ActivityStatus) : Activity() { ActivityStatus.UNINITIALIZED -> activityStatus = state ActivityStatus.SUCCESS -> onSuccess() ActivityStatus.RUNNING -> activityStatus = state -// ActivityStatus.PENDING -> activityStatus = state - ActivityStatus.FAILURE -> onFailure() + ActivityStatus.PENDING -> activityStatus = state + ActivityStatus.FAILURE -> onFailure(Exception("SetState forced fail")) } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 0f2c6b537..4630c72d0 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -48,8 +48,8 @@ object ActivityManager : Manager, Activity() { with(currentActivity) { if (currentActivity != lastActivity) { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { - if (lastActivity !is ActivityManager) { + if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +// if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } @@ -65,8 +65,8 @@ object ActivityManager : Manager, Activity() { } fun reset() { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { - if (lastActivity !is ActivityManager) { + if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +// if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 7ee1e301a..a764d4922 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests +import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.highlevel.ReachXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity @@ -17,12 +18,16 @@ import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.MovementUtils.centerPlayer import com.lambda.client.util.items.block import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item +import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockShulkerBox +import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments @@ -97,9 +102,27 @@ object TestActivityManager : Module( }) private val tiectie by setting("Surround me", false, consumer = { _, _-> - ActivityManager.addSubActivities( - SurroundWithObsidian() - ) + runSafe { + player.centerPlayer() + ActivityManager.addSubActivities( + SurroundWithObsidian(player.flooredPosition) + ) + } + false + }) + + private val citectie by setting("Clear out", false, consumer = { _, _-> + runSafe { + val structure = mutableMapOf() + + VectorUtils.getBlockPosInSphere(player.positionVector, 3.0f).forEach { + if (it.up() != player.flooredPosition) structure[it] = Blocks.AIR.defaultState + } + + ActivityManager.addSubActivities( + BuildStructure(structure) + ) + } false }) From d0ff8d897a10c91ea723aaa806d790e3e77a59fe Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 30 Dec 2022 23:22:39 +0100 Subject: [PATCH 036/104] Add anon option to hud --- .../kotlin/com/lambda/client/activity/Activity.kt | 13 +++++++++++-- .../gui/hudgui/elements/misc/ActivityManagerHud.kt | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 6da520625..304d766fa 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.* import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.elements.misc.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket @@ -11,6 +12,9 @@ import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.text.capitalize +import net.minecraft.entity.Entity +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d import java.util.ConcurrentModificationException import java.util.concurrent.ConcurrentLinkedDeque @@ -220,8 +224,13 @@ abstract class Activity { field.isAccessible = true val name = field.name val value = field.get(this) - textComponent.add(name.capitalize(), primaryColor) - textComponent.add(value.toString(), secondaryColor) + + if (!ActivityManagerHud.anonymize + || !(value is BlockPos || value is Vec3d || value is Entity) + ) { + textComponent.add(name.capitalize(), primaryColor) + textComponent.add(value.toString(), secondaryColor) + } } textComponent.addLine("") } diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index 9ff336cc7..59b6ea9e2 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -11,6 +11,8 @@ internal object ActivityManagerHud: LabelHud( category = Category.MISC, description = "Display current activities." ) { + val anonymize by setting("Anonymize", false) + override fun SafeClientEvent.updateText() { if (ActivityManager.noSubActivities()) return From b730d344a603f732d462e05bfd753dc5f1c720d7 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sat, 31 Dec 2022 08:12:22 +0100 Subject: [PATCH 037/104] Fix collecting drops --- .../com/lambda/client/activity/Activity.kt | 54 +++--- .../highlevel/BreakDownEnderChests.kt | 10 +- .../activities/highlevel/BuildBlock.kt | 7 +- .../activities/highlevel/BuildHighway.kt | 37 ++++ .../activities/highlevel/PlaceBlockSafely.kt | 24 --- .../activities/interaction/BreakBlock.kt | 166 +----------------- .../activities/interaction/BreakBlockRaw.kt | 149 ++++++++++++++++ .../activities/interaction/PlaceBlock.kt | 80 ++------- .../activities/interaction/PlaceBlockRaw.kt | 84 +++++++++ .../storage/BreakAndCollectShulker.kt | 21 --- .../storage/ExtractItemFromShulkerBox.kt | 3 +- .../activities/storage/OpenContainerInSlot.kt | 5 +- .../storage/StoreItemToShulkerBox.kt | 3 +- .../activity/activities/travel/PickUpDrops.kt | 19 +- .../activities/travel/PickUpEntityItem.kt | 37 ++-- .../modules/misc/TestActivityManager.kt | 41 ++++- .../modules/player/InventoryManagerTwo.kt | 5 +- 17 files changed, 385 insertions(+), 360 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 304d766fa..230749b93 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -13,6 +13,7 @@ import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.text.capitalize import net.minecraft.entity.Entity +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import java.util.ConcurrentModificationException @@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED - private var creationTime = 0L + var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 val name get() = this::class.simpleName @@ -51,8 +52,7 @@ abstract class Activity { ) finalize() } ActivityStatus.PENDING -> { - owner.subActivities.remove(this@Activity) - owner.subActivities.add(this@Activity) + refresh() } ActivityStatus.SUCCESS -> { executeOnSuccess?.invoke() @@ -71,16 +71,14 @@ abstract class Activity { if (System.currentTimeMillis() > creationTime + timeout) { if (this@Activity is AttemptActivity) { if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("$name fully timed out!") + onFailure(Exception("failed after $usedAttempts attempts")) } else { usedAttempts++ initialize() - LambdaMod.LOG.warn("$name timed out!") + MessageSendHelper.sendErrorMessage("$name: attempt $usedAttempts/$maxAttempts timed out") } } else { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("$name fully timed out!") + onFailure(Exception("fully timed out")) } } } @@ -92,7 +90,7 @@ abstract class Activity { if (this@Activity is AttemptActivity) { if (usedAttempts >= maxAttempts) { activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("$name failed after $maxAttempts attempts!") + MessageSendHelper.sendErrorMessage("$name failed after $maxAttempts attempts!") } } if (this@Activity is RotatingActivity) { @@ -121,28 +119,22 @@ abstract class Activity { executeOnFinalize?.invoke() owner.subActivities.remove(this@Activity) - if (this@Activity is LoopingAmountActivity) { - if (currentLoops++ < maxLoops || maxLoops == 0) { - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.add(this@Activity) - LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") - } + if (this@Activity is LoopingAmountActivity + && (currentLoops++ < maxLoops || maxLoops == 0) + ) { + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.add(this@Activity) + LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") } - if (this@Activity is LoopingUntilActivity) { - if (!loopUntil()) { - currentLoops++ - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.add(this@Activity) - LambdaMod.LOG.info("Looping $name ($currentLoops) ") - } + if (this@Activity is LoopingUntilActivity && !loopUntil()) { + currentLoops++ + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.add(this@Activity) + LambdaMod.LOG.info("Looping $name ($currentLoops) ") } -// with(ActivityManager) { -// updateCurrentActivity() -// } - - // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") +// LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") // MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") } @@ -185,15 +177,15 @@ abstract class Activity { fun noSubActivities() = subActivities.isEmpty() fun SafeClientEvent.onSuccess() { - executeOnSuccess?.invoke() finalize() + executeOnSuccess?.invoke() } fun SafeClientEvent.onFailure(exception: Exception) { - executeOnFailure?.invoke(exception) finalize() + executeOnFailure?.invoke(exception) - LambdaMod.LOG.warn("$name failed!") + MessageSendHelper.sendErrorMessage("$name ${exception.message}") } fun refresh() { @@ -226,7 +218,7 @@ abstract class Activity { val value = field.get(this) if (!ActivityManagerHud.anonymize - || !(value is BlockPos || value is Vec3d || value is Entity) + || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) ) { textComponent.add(name.capitalize(), primaryColor) textComponent.add(value.toString(), secondaryColor) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 2df9ea16e..26c7853f0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -3,6 +3,8 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.LoopingAmountActivity import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.BreakBlockRaw +import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.utils.getContainerPos @@ -27,7 +29,7 @@ class BreakDownEnderChests( ) } else { addSubActivities( - PlaceBlockSafely(remotePos, Blocks.ENDER_CHEST.defaultState), + PlaceBlock(remotePos, Blocks.ENDER_CHEST.defaultState), SwapOrMoveToItem( Items.DIAMOND_PICKAXE, predicateItem = { @@ -36,9 +38,9 @@ class BreakDownEnderChests( ), BreakBlock( remotePos, - pickUpDrop = true, - minPickUpAmount = 64, - mode = BreakBlock.Mode.PLAYER_CONTROLLER + useBestTool = false, + collectDrops = true, + minCollectAmount = 64 ) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 95cf5bb9f..aa1139d1a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.world.isReplaceable import net.minecraft.block.state.IBlockState @@ -24,15 +24,14 @@ class BuildBlock( /* block needs to be placed */ targetState.block != Blocks.AIR && currentState.isReplaceable -> { addSubActivities( - PlaceBlockSafely(blockPos, targetState) + PlaceBlock(blockPos, targetState) ) } /* only option left is breaking the block */ else -> { addSubActivities( - SwapToBestTool(blockPos), BreakBlock(blockPos), - PlaceBlockSafely(blockPos, targetState) + PlaceBlock(blockPos, targetState) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt new file mode 100644 index 000000000..19a03797d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt @@ -0,0 +1,37 @@ +package com.lambda.client.activity.activities.highlevel + +import baritone.api.pathing.goals.GoalBlock +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.LoopingAmountActivity +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.multiply +import net.minecraft.block.Block +import net.minecraft.util.math.BlockPos + +class BuildHighway( + private val origin: BlockPos, + private val direction: Direction, + private val material: Block, + override val maxLoops: Int = 100, + override var currentLoops: Int = 0 +) : LoopingAmountActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + val currentPos = origin.add(direction.directionVec.multiply(currentLoops + 1)) + +// VectorUtils.getBlockPosInSphere(player.getPositionEyes(1f), 5.0f).forEach { +// if (it != origin.down()) addSubActivities( +// BuildBlock(it, Blocks.AIR.defaultState) +// ) +// } + + addSubActivities( + BuildBlock(currentPos.add(direction.clockwise(1).directionVec), material.defaultState), + BuildBlock(currentPos.add(direction.counterClockwise(1).directionVec), material.defaultState), + BuildBlock(currentPos.add(direction.clockwise(1).directionVec).up(), material.defaultState), + BuildBlock(currentPos.add(direction.counterClockwise(1).directionVec).up(), material.defaultState), + CustomGoal(GoalBlock(currentPos.add(direction.directionVec))) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt deleted file mode 100644 index 740c99420..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/PlaceBlockSafely.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.lambda.client.activity.activities.highlevel - -import baritone.api.pathing.goals.GoalNear -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.travel.CustomGoal -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.item -import net.minecraft.block.state.IBlockState -import net.minecraft.util.math.BlockPos - -class PlaceBlockSafely( - private val blockPos: BlockPos, - private val blockState: IBlockState, -) : Activity() { - override fun SafeClientEvent.onInitialize() { - addSubActivities( - SwapOrMoveToItem(blockState.block.item), - CustomGoal(GoalNear(blockPos, 3)), - PlaceBlock(blockPos, blockState) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index a882f618c..7726c7b37 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,173 +1,21 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.RenderBlockActivity -import com.lambda.client.activity.activities.RotatingActivity -import com.lambda.client.activity.activities.TimeoutActivity -import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.utils.SetState -import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.math.RotationUtils.getRotationTo -import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getHitVec -import com.lambda.client.util.world.getMiningSide -import net.minecraft.init.Blocks -import net.minecraft.network.play.client.CPacketPlayerDigging -import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.util.EnumHand -import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent -import java.util.* -import kotlin.math.ceil class BreakBlock( private val blockPos: BlockPos, private val playSound: Boolean = true, + private val useBestTool: Boolean = true, private val miningSpeedFactor: Float = 1.0f, - private val pickUpDrop: Boolean = false, - private val minPickUpAmount: Int = 1, - private val mode: Mode = Mode.PACKET, - override var timeout: Long = 200L, - override val maxAttempts: Int = 8, - override var usedAttempts: Int = 0, - override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(0, 0, 0), - override var rotation: Vec2f = Vec2f.ZERO -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderBlockActivity, Activity() { - private var ticksNeeded = 0 - private var initState = Blocks.AIR.defaultState - -// private var blockChanged = false -// private var dropped = false - - enum class Mode { - PLAYER_CONTROLLER, PACKET - } - + private val collectDrops: Boolean = false, + private val minCollectAmount: Int = 1 +) : Activity() { override fun SafeClientEvent.onInitialize() { - initState = world.getBlockState(blockPos) - - if (initState.block == Blocks.AIR) { - onSuccess() - color = ColorHolder(16, 74, 94) - } else { - ticksNeeded = ceil((1 / initState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 500L - } - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - getMiningSide(blockPos)?.let { side -> - rotation = getRotationTo(getHitVec(blockPos, side)) - - if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { - if (mode == Mode.PACKET) { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - if (playSound) { - val soundType = initState.block.getSoundType(initState, world, blockPos, player) - world.playSound( - player, - blockPos, - soundType.breakSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) - } - } else { - playerController.onPlayerDestroyBlock(blockPos) - player.swingArm(EnumHand.MAIN_HAND) - } - finish() - } else { - playerController.onPlayerDamageBlock(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) - // cancel onPlayerDestroy NoGhostBlocks - -// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { -// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) -// player.swingArm(EnumHand.MAIN_HAND) -// if (playSound) { -// val soundType = initState.block.getSoundType(initState, world, blockPos, player) -// world.playSound( -// player, -// blockPos, -// soundType.breakSound, -// SoundCategory.BLOCKS, -// (soundType.getVolume() + 1.0f) / 2.0f, -// soundType.getPitch() * 0.8f -// ) -// } -// } else { -// player.swingArm(EnumHand.MAIN_HAND) -// if (playSound) { -// val soundType = initState.block.getSoundType(initState, world, blockPos, player) -// world.playSound( -// player, -// blockPos, -// soundType.hitSound, -// SoundCategory.BLOCKS, -// (soundType.getVolume() + 1.0f) / 2.0f, -// soundType.getPitch() * 0.8f -// ) -// } -// } - } -// getHitVec(blockPos, side) - } - } - - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && it.packet.blockState.block == Blocks.AIR - ) { - finish() - } - - // Sync with drops -// if (it.packet is SPacketSpawnObject -// && it.packet.type == 2 -// && blockPos.distanceSq(Vec3i(it.packet.x, it.packet.y, it.packet.z)) < 1.0 -// ) { -// dropped = true -// if (pickUpDrop) { -// if (blockChanged) { -// finish() -// } -// } else { -// finish() -// } -// } - } - } - - private fun SafeClientEvent.finish() { - if (!pickUpDrop) { - onSuccess() - return - } - - color = ColorHolder(252, 3, 207) + if (useBestTool) addSubActivities(SwapToBestTool(blockPos)) - addSubActivities( - PickUpDrops(initState.block.getItemDropped(initState, Random(), 0), minAmount = minPickUpAmount).also { - executeOnSuccess = { - with(owner) { - onSuccess() - } - } - } - ) + addSubActivities(BreakBlockRaw(blockPos, playSound, miningSpeedFactor, collectDrops, minCollectAmount)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt new file mode 100644 index 000000000..dc96e8267 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt @@ -0,0 +1,149 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.AttemptActivity +import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.block +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getHitVec +import com.lambda.client.util.world.getMiningSide +import net.minecraft.entity.item.EntityItem +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.Item +import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.network.play.server.SPacketEntityMetadata +import net.minecraft.network.play.server.SPacketSpawnObject +import net.minecraft.util.EnumHand +import net.minecraft.util.SoundCategory +import net.minecraft.util.math.BlockPos +import net.minecraftforge.event.entity.EntityJoinWorldEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.lang.Exception +import java.util.* +import kotlin.math.ceil + +class BreakBlockRaw( + private val blockPos: BlockPos, + private val playSound: Boolean = true, + private val miningSpeedFactor: Float = 1.0f, + private val collectDrops: Boolean = false, + private val minCollectAmount: Int = 1, + override var timeout: Long = 200L, + override val maxAttempts: Int = 8, + override var usedAttempts: Int = 0, + override var renderBlockPos: BlockPos = blockPos, + override var color: ColorHolder = ColorHolder(0, 0, 0), + override var rotation: Vec2f = Vec2f.ZERO +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderBlockActivity, Activity() { + private var ticksNeeded = 0 + private var initState = Blocks.AIR.defaultState + private var drop: Item = Items.AIR + + override fun SafeClientEvent.onInitialize() { + val currentState = world.getBlockState(blockPos) + + if (currentState.block == Blocks.AIR) { + onSuccess() + return + } + + initState = currentState + drop = currentState.block.getItemDropped(currentState, Random(), 0) + ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + timeout = ticksNeeded * 50L + 2000L + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + getMiningSide(blockPos)?.let { side -> + rotation = getRotationTo(getHitVec(blockPos, side)) + + if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { + playerController.onPlayerDestroyBlock(blockPos) + player.swingArm(EnumHand.MAIN_HAND) + } else { + playerController.onPlayerDamageBlock(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) + // cancel onPlayerDestroy NoGhostBlocks + +// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { +// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) +// player.swingArm(EnumHand.MAIN_HAND) +// } else { +// player.swingArm(EnumHand.MAIN_HAND) +// } + } + } ?: run { + onFailure(Exception("No block surface exposed to player")) + } + } + + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == Blocks.AIR + ) finish() + } + } + + private fun SafeClientEvent.playSound() { + if (playSound) { + val soundType = initState.block.getSoundType(initState, world, blockPos, player) + world.playSound( + player, + blockPos, + soundType.breakSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } + + if (playSound) { + val soundType = initState.block.getSoundType(initState, world, blockPos, player) + world.playSound( + player, + blockPos, + soundType.hitSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } + } + + private fun SafeClientEvent.finish() { + if (!collectDrops) { + onSuccess() + return + } + + color = ColorHolder(252, 3, 207) + + if (drop.block == Blocks.AIR) return + + addSubActivities( + PickUpDrops(drop, minAmount = minCollectAmount).also { + executeOnSuccess = { + with(owner) { + onSuccess() + } + } + } + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index cebb21b24..5abe8b632 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,84 +1,24 @@ package com.lambda.client.activity.activities.interaction +import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.blockBlacklist -import com.lambda.client.util.math.RotationUtils.getRotationTo -import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.toPlacePacket +import com.lambda.client.util.items.item import net.minecraft.block.state.IBlockState -import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.util.EnumHand -import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -import java.lang.Exception class PlaceBlock( private val blockPos: BlockPos, private val targetState: IBlockState, private val playSound: Boolean = true, - override var rotation: Vec2f = Vec2f.ZERO, - override val timeout: Long = 1000L, - override val maxAttempts: Int = 8, - override var usedAttempts: Int = 0, - override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(0, 0, 0) -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { + private val swapToItem: Boolean = true, + private val getInReach: Boolean = true, +) : Activity() { override fun SafeClientEvent.onInitialize() { - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { - val placedAtBlock = world.getBlockState(it.pos).block - - if (placedAtBlock in blockBlacklist) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) - } - - rotation = getRotationTo(it.hitVec) - - connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) - player.swingArm(EnumHand.MAIN_HAND) - - if (placedAtBlock in blockBlacklist) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) - } - - if (playSound) { - val thisState = world.getBlockState(blockPos) - - val soundType = thisState.block.getSoundType( - thisState, - world, - blockPos, - player - ) - world.playSound( - player, - blockPos, - soundType.placeSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) - } - -// activityStatus = ActivityStatus.PENDING - } ?: run { - onFailure(Exception("No neighbour found")) - color = ColorHolder(16, 74, 94) - } - } - - init { - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && it.packet.blockState.block == targetState.block - ) onSuccess() - } + if (swapToItem) addSubActivities(SwapOrMoveToItem(targetState.block.item)) + if (getInReach) addSubActivities(CustomGoal(GoalNear(blockPos, 4))) + addSubActivities(PlaceBlockRaw(blockPos, targetState, playSound)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt new file mode 100644 index 000000000..0116851a9 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt @@ -0,0 +1,84 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.* +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.blockBlacklist +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getNeighbour +import com.lambda.client.util.world.toPlacePacket +import net.minecraft.block.state.IBlockState +import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumHand +import net.minecraft.util.SoundCategory +import net.minecraft.util.math.BlockPos +import java.lang.Exception + +class PlaceBlockRaw( + private val blockPos: BlockPos, + private val targetState: IBlockState, + private val playSound: Boolean = true, + override var rotation: Vec2f = Vec2f.ZERO, + override val timeout: Long = 1000L, + override val maxAttempts: Int = 8, + override var usedAttempts: Int = 0, + override var renderBlockPos: BlockPos = blockPos, + override var color: ColorHolder = ColorHolder(0, 0, 0) +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { + val placedAtBlock = world.getBlockState(it.pos).block + + if (placedAtBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + + rotation = getRotationTo(it.hitVec) + + connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) + player.swingArm(EnumHand.MAIN_HAND) + + if (placedAtBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + + if (playSound) { + val thisState = world.getBlockState(blockPos) + + val soundType = thisState.block.getSoundType( + thisState, + world, + blockPos, + player + ) + world.playSound( + player, + blockPos, + soundType.placeSound, + SoundCategory.BLOCKS, + (soundType.getVolume() + 1.0f) / 2.0f, + soundType.getPitch() * 0.8f + ) + } + +// activityStatus = ActivityStatus.PENDING + } ?: run { + onFailure(Exception("No neighbour found")) + color = ColorHolder(16, 74, 94) + } + } + + init { + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == targetState.block + ) onSuccess() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt deleted file mode 100644 index d8ae50bd6..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakAndCollectShulker.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.inventory.SwapToBestTool -import com.lambda.client.event.SafeClientEvent -import net.minecraft.util.math.BlockPos - -class BreakAndCollectShulker( - private val blockPos: BlockPos -) : Activity() { - override fun SafeClientEvent.onInitialize() { - addSubActivities( - SwapToBestTool(blockPos), - BreakBlock( - blockPos, - pickUpDrop = true - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index da37e418d..661f658a3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.utils.getContainerPos @@ -38,7 +39,7 @@ class ExtractItemFromShulkerBox( OpenContainerInSlot(slot), PullItemsFromContainer(item, amount, predicateItem), CloseContainer(), - BreakAndCollectShulker(containerPos), + BreakBlock(containerPos, collectDrops = true), SwapOrMoveToItem(item, predicateItem, predicateSlot) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index 9c325338f..0f03b35ea 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -1,11 +1,9 @@ package com.lambda.client.activity.activities.storage -import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.block @@ -17,9 +15,8 @@ class OpenContainerInSlot( override fun SafeClientEvent.onInitialize() { getContainerPos()?.let { containerPos -> addSubActivities( - CustomGoal(GoalNear(containerPos, 3)), SwapOrSwitchToSlot(slot), - PlaceBlock(containerPos, slot.stack.item.block.defaultState), + PlaceBlock(containerPos, slot.stack.item.block.defaultState, swapToItem = false), OpenContainer(containerPos) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 7d814f83c..1c3ef1e2f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.utils.getShulkerInventory @@ -36,7 +37,7 @@ class StoreItemToShulkerBox( OpenContainerInSlot(slot), PushItemsToContainer(item, amount, predicateItem), CloseContainer(), - BreakAndCollectShulker(containerPos) + BreakBlock(containerPos, collectDrops = true) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 81ae9f60b..7f8ec0229 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -19,22 +19,13 @@ class PickUpDrops( it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) } - if (drops.isEmpty()) { + if (drops.isEmpty() || drops.sumOf { it.item.count } < minAmount) { onSuccess() - } else { - if (drops.size < minAmount) return + return + } - drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> - addSubActivities( - PickUpEntityItem(drop).also { - executeOnFinalize = { - with(owner) { - onSuccess() - } - } - } - ) - } + drops.sortedBy { drop -> player.distanceTo(drop.positionVector) }.forEach { drop -> + addSubActivities(PickUpEntityItem(drop)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index c6a09fef6..7f6027a62 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -10,7 +10,9 @@ import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem +import net.minecraftforge.event.entity.player.EntityItemPickupEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import java.lang.Exception class PickUpEntityItem( private val entityItem: EntityItem, @@ -20,24 +22,25 @@ class PickUpEntityItem( safeListener { event -> if (event.phase != TickEvent.Phase.START) return@safeListener - if (world.loadedEntityList.contains(entityItem)) { - val emptySlots = player.inventory.mainInventory.filter { it.isEmpty } - - if (emptySlots.isNotEmpty()) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) - } else { - player.inventorySlots.firstOrNull { slot -> - InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) - }?.let { slot -> - addSubActivities(DumpSlot(slot)) - } ?: run { - activityStatus = ActivityStatus.FAILURE - MessageSendHelper.sendErrorMessage("No empty slots or items to dump!") - } - } - } else { - onSuccess() + if (!world.loadedEntityList.contains(entityItem)) { BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) + onSuccess() + return@safeListener + } + + val emptySlots = player.inventory.mainInventory.filter { it.isEmpty } + + if (emptySlots.isNotEmpty()) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) + return@safeListener + } + + player.inventorySlots.firstOrNull { slot -> + InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) + }?.let { slot -> + addSubActivities(DumpSlot(slot)) + } ?: run { + onFailure(Exception("No empty slots or items to dump!")) } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index a764d4922..a4b97c366 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -3,10 +3,9 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly -import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests -import com.lambda.client.activity.activities.highlevel.BuildStructure -import com.lambda.client.activity.activities.highlevel.ReachXPLevel -import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.highlevel.* +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem @@ -24,6 +23,8 @@ import com.lambda.client.util.items.block import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.RotationUtils import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockShulkerBox @@ -111,6 +112,18 @@ object TestActivityManager : Module( false }) + private val ctiectiectie by setting("Place break obby", false, consumer = { _, _-> + runSafe { + val origin = player.flooredPosition.add(Direction.fromEntity(player).directionVec) + + ActivityManager.addSubActivities( + PlaceBlock(origin, Blocks.OBSIDIAN.defaultState), + BreakBlock(origin) + ) + } + false + }) + private val citectie by setting("Clear out", false, consumer = { _, _-> runSafe { val structure = mutableMapOf() @@ -145,20 +158,34 @@ object TestActivityManager : Module( false }) - private val pullll by setting("pull", false, consumer = { _, _-> + private val pullll by setting("Extract", false, consumer = { _, _-> ActivityManager.addSubActivities( ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item, amount = 1) ) false }) - private val pusshhh by setting("push", false, consumer = { _, _-> + private val pusshhh by setting("Store", false, consumer = { _, _-> ActivityManager.addSubActivities( - PushItemsToContainer(Blocks.OBSIDIAN.item, amount = 1) + StoreItemToShulkerBox(Blocks.OBSIDIAN.item, amount = 1) ) false }) + private val cnrsgt by setting("Build", false, consumer = { _, _-> + runSafe { + ActivityManager.addSubActivities( + BuildHighway( + player.flooredPosition, + Direction.fromEntity(player), + Blocks.OBSIDIAN + ) + ) + } + + false + }) + val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> ActivityManager.addSubActivities(ReachXPLevel(30)) false diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 43bd37055..f444ffd86 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,7 +1,7 @@ package com.lambda.client.module.modules.player +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.activity.activities.storage.BreakAndCollectShulker import com.lambda.client.activity.activities.storage.OpenContainerInSlot import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent @@ -18,7 +18,6 @@ import net.minecraft.init.Blocks import net.minecraft.inventory.ClickType import net.minecraft.item.ItemShulkerBox import net.minecraft.util.math.BlockPos -import java.util.* object InventoryManagerTwo : Module( name = "InventoryManagerTwo", @@ -53,7 +52,7 @@ object InventoryManagerTwo : Module( if (world.getBlockState(containerPos).block !is BlockShulkerBox) return@safeListener ActivityManager.addSubActivities( - BreakAndCollectShulker(containerPos) + BreakBlock(containerPos, collectDrops = true) ) } } From 3b779406a503d9f9b0179c9d9b712b9f7063a1ca Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 2 Jan 2023 01:13:50 +0100 Subject: [PATCH 038/104] Exception system --- .../com/lambda/client/activity/Activity.kt | 165 ++++++++---------- .../activity/activities/ActivityTypes.kt | 48 ----- .../activities/example/ListenAndWait.kt | 20 ++- .../activities/example/ProbablyFailing.kt | 4 +- .../activity/activities/example/WaitAndSay.kt | 4 +- .../highlevel/BreakDownEnderChests.kt | 3 +- .../activities/highlevel/BuildBlock.kt | 10 +- .../activities/highlevel/BuildHighway.kt | 2 +- .../activities/highlevel/BuildStructure.kt | 5 +- .../activities/highlevel/ReachXPLevel.kt | 7 +- .../highlevel/SurroundWithObsidian.kt | 3 +- .../activities/interaction/BreakBlockRaw.kt | 71 ++++---- .../activities/interaction/CloseContainer.kt | 2 +- .../activities/interaction/OpenContainer.kt | 8 +- .../activities/interaction/PlaceBlockRaw.kt | 11 +- .../interaction/UseThrowableOnEntity.kt | 4 +- .../inventory/InventoryTransaction.kt | 36 ++-- .../activities/inventory/SlotMustBeEmpty.kt | 6 +- .../activities/inventory/SwapOrMoveToItem.kt | 5 +- .../inventory/SwitchToHotbarSlot.kt | 2 +- .../inventory/TryClearSlotWithQuickMove.kt | 12 +- .../storage/ExtractItemFromShulkerBox.kt | 30 ++-- .../activities/storage/OpenContainerInSlot.kt | 20 ++- .../storage/StoreItemToShulkerBox.kt | 28 ++- .../activity/activities/travel/CustomGoal.kt | 6 +- .../activity/activities/travel/PickUpDrops.kt | 3 +- .../activities/travel/PickUpEntityItem.kt | 10 +- .../activities/types/AttemptActivity.kt | 28 +++ .../activities/types/DelayedActivity.kt | 20 +++ .../activities/types/LoopingAmountActivity.kt | 27 +++ .../activities/types/LoopingUntilActivity.kt | 25 +++ .../activities/types/RenderBlockActivity.kt | 9 + .../activities/types/RotatingActivity.kt | 22 +++ .../activities/types/TimeoutActivity.kt | 27 +++ .../activity/activities/utils/SetState.kt | 19 -- .../client/activity/activities/utils/Wait.kt | 4 +- .../elements/misc/ActivityManagerHud.kt | 15 +- .../manager/managers/ActivityManager.kt | 12 +- 38 files changed, 429 insertions(+), 304 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 230749b93..5b071062e 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,13 +1,17 @@ package com.lambda.client.activity -import com.lambda.client.LambdaMod -import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt +import com.lambda.client.activity.activities.types.DelayedActivity +import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed +import com.lambda.client.activity.activities.types.LoopingAmountActivity.Companion.checkLoopingAmount +import com.lambda.client.activity.activities.types.LoopingUntilActivity.Companion.checkLoopingUntil +import com.lambda.client.activity.activities.types.RotatingActivity.Companion.checkRotating +import com.lambda.client.activity.activities.types.TimeoutActivity.Companion.checkTimeout import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.misc.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH -import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper @@ -16,7 +20,6 @@ import net.minecraft.entity.Entity import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import java.util.ConcurrentModificationException import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { @@ -26,19 +29,28 @@ abstract class Activity { var owner: Activity = ActivityManager var depth = 0 val name get() = this::class.simpleName + val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this var executeOnSuccess: (() -> Unit)? = null var executeOnFailure: ((Exception) -> Unit)? = null - var executeOnFinalize: (() -> Unit)? = null + private var executeOnFinalize: (() -> Unit)? = null - enum class ActivityStatus { - UNINITIALIZED, - RUNNING, - PENDING, - SUCCESS, - FAILURE - } + open fun SafeClientEvent.onInitialize() {} + + open fun SafeClientEvent.onSuccess() {} + + /* Return true to stop the activity + * */ + open fun SafeClientEvent.onFailure(exception: Exception): Boolean = true + + open fun SafeClientEvent.onFinalize() {} + + open fun addExtraInfo( + textComponent: TextComponent, + primaryColor: ColorHolder, + secondaryColor: ColorHolder + ) {} fun SafeClientEvent.updateActivity() { when (activityStatus) { @@ -59,86 +71,61 @@ abstract class Activity { finalize() } ActivityStatus.FAILURE -> { - executeOnFailure?.invoke(Exception("Activity failed")) - finalize() - LambdaMod.LOG.error("$name failed!") + // } } } - fun SafeClientEvent.updateTypesOnTick() { - if (this@Activity is TimeoutActivity) { - if (System.currentTimeMillis() > creationTime + timeout) { - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - onFailure(Exception("failed after $usedAttempts attempts")) - } else { - usedAttempts++ - initialize() - MessageSendHelper.sendErrorMessage("$name: attempt $usedAttempts/$maxAttempts timed out") - } - } else { - onFailure(Exception("fully timed out")) - } - } - } - if (this@Activity is DelayedActivity) { - if (System.currentTimeMillis() > creationTime + delay) { - onDelayedActivity() - } - } - if (this@Activity is AttemptActivity) { - if (usedAttempts >= maxAttempts) { - activityStatus = ActivityStatus.FAILURE - MessageSendHelper.sendErrorMessage("$name failed after $maxAttempts attempts!") - } - } - if (this@Activity is RotatingActivity) { - sendPlayerPacket { - rotate(rotation) - } - } + fun SafeClientEvent.updateTypesOnTick(activity: Activity) { + checkTimeout(activity) + checkDelayed(activity) + checkAttempt(activity) + checkRotating(activity) } - private fun SafeClientEvent.initialize() { + fun SafeClientEvent.initialize() { activityStatus = ActivityStatus.RUNNING creationTime = System.currentTimeMillis() onInitialize() - if (this@Activity is RotatingActivity) { - sendPlayerPacket { - rotate(rotation) - } - } + + checkRotating(this@Activity) + // LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") } - open fun SafeClientEvent.onInitialize() {} - private fun SafeClientEvent.finalize() { + val activity = this@Activity + onFinalize() executeOnFinalize?.invoke() - owner.subActivities.remove(this@Activity) - - if (this@Activity is LoopingAmountActivity - && (currentLoops++ < maxLoops || maxLoops == 0) - ) { - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.add(this@Activity) - LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") - } + owner.subActivities.remove(activity) - if (this@Activity is LoopingUntilActivity && !loopUntil()) { - currentLoops++ - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.add(this@Activity) - LambdaMod.LOG.info("Looping $name ($currentLoops) ") - } + checkLoopingAmount(activity) + checkLoopingUntil(activity) // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") // MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") } - open fun SafeClientEvent.onFinalize() {} + fun SafeClientEvent.success() { + finalize() + executeOnSuccess?.invoke() + } + + fun SafeClientEvent.failedWith(exception: Exception) { + if (onFailure(exception)) { + executeOnFailure?.invoke(exception) + + MessageSendHelper.sendErrorMessage("Exception in ${this@Activity::class.simpleName}: ${exception.message}") + ActivityManager.reset() + } + } + + fun refresh() { + activityStatus = ActivityStatus.UNINITIALIZED + owner.subActivities.remove(this) + owner.subActivities.add(this) + } fun Activity.addSubActivities(activities: List) { if (activities.isEmpty()) return @@ -176,30 +163,14 @@ abstract class Activity { fun noSubActivities() = subActivities.isEmpty() - fun SafeClientEvent.onSuccess() { - finalize() - executeOnSuccess?.invoke() - } - - fun SafeClientEvent.onFailure(exception: Exception) { - finalize() - executeOnFailure?.invoke(exception) - - MessageSendHelper.sendErrorMessage("$name ${exception.message}") - } - - fun refresh() { - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.remove(this) - owner.subActivities.add(this) - } - - override fun toString(): String { - return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" + enum class ActivityStatus { + UNINITIALIZED, + RUNNING, + PENDING, + SUCCESS, + FAILURE } - open fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) {} - fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { if (this !is ActivityManager) { ListenerManager.listenerMap[this@Activity]?.let { @@ -224,9 +195,9 @@ abstract class Activity { textComponent.add(value.toString(), secondaryColor) } } - textComponent.addLine("") } addExtraInfo(textComponent, primaryColor, secondaryColor) + textComponent.addLine("") subActivities.forEach { repeat(depth) { textComponent.add(" ") @@ -234,4 +205,8 @@ abstract class Activity { it.appendInfo(textComponent, primaryColor, secondaryColor) } } -} \ No newline at end of file + + override fun toString(): String { + return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" + } +} diff --git a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt b/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt deleted file mode 100644 index 488e90810..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/ActivityTypes.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.lambda.client.activity.activities - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.math.Vec2f -import net.minecraft.util.math.BlockPos - -interface TimeoutActivity { - val timeout: Long -} - -interface ConcurrentActivity { - val maxActivities: Int -} - -interface LoopingAmountActivity { - val maxLoops: Int - var currentLoops: Int -} - -interface LoopingUntilActivity { - val loopUntil: SafeClientEvent.() -> Boolean - var currentLoops: Int -} - -interface LoopingTimeActivity { - val loopUntilTimestamp: Long -} - -interface RotatingActivity { - var rotation: Vec2f -} - -interface DelayedActivity { - val delay: Long - - fun SafeClientEvent.onDelayedActivity() -} - -interface AttemptActivity { - val maxAttempts: Int - var usedAttempts: Int -} - -interface RenderBlockActivity { - var renderBlockPos: BlockPos - var color: ColorHolder -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt index 0740a00d9..705b2198c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -1,10 +1,14 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent +import java.lang.Exception class ListenAndWait( private val message: String, @@ -17,4 +21,18 @@ class ListenAndWait( MessageSendHelper.sendChatMessage(message) } } + + override fun SafeClientEvent.onFailure(exception: Exception) = + if (exception is TimeoutActivity.Companion.TimeoutException) { + success() + false + } else { + MessageSendHelper.sendChatMessage("Failure!") + true + } + + override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + textComponent.add("Age", primaryColor) + textComponent.add(age.toString(), secondaryColor) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt index a8c89798c..967f356ae 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt @@ -8,9 +8,9 @@ import kotlin.random.Random class ProbablyFailing : Activity() { override fun SafeClientEvent.onInitialize() { if (Random.nextBoolean()) { - onSuccess() + success() } else { - onFailure(Exception("Randomly failed")) + failedWith(Exception("Randomly failed")) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt index 05b320edf..f76025ad8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.DelayedActivity +import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.text.MessageSendHelper @@ -11,6 +11,6 @@ class WaitAndSay( ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { MessageSendHelper.sendChatMessage(message) - onSuccess() + success() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 26c7853f0..9a25972d9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -1,9 +1,8 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.LoopingAmountActivity +import com.lambda.client.activity.activities.types.LoopingAmountActivity import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.BreakBlockRaw import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index aa1139d1a..fdd239938 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -18,9 +18,11 @@ class BuildBlock( when { /* is in desired state */ - currentState == targetState -> onSuccess() -// /* is blocked by entity */ -// world.checkNoEntityCollision(currentState.getSelectedBoundingBox(world, blockPos), null) -> setFailure() + currentState == targetState -> success() + /* is blocked by entity */ + !world.checkNoEntityCollision(currentState.getSelectedBoundingBox(world, blockPos), null) -> { + failedWith(EntityCollisionException()) + } /* block needs to be placed */ targetState.block != Blocks.AIR && currentState.isReplaceable -> { addSubActivities( @@ -36,4 +38,6 @@ class BuildBlock( } } } + + class EntityCollisionException : Exception("entity collision") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt index 19a03797d..82f7f6ffb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.highlevel import baritone.api.pathing.goals.GoalBlock import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.LoopingAmountActivity +import com.lambda.client.activity.activities.types.LoopingAmountActivity import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.Direction diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 8f559020f..f85a9ddca 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.BreakBlockRaw import com.lambda.client.event.SafeClientEvent import net.minecraft.block.state.IBlockState import net.minecraft.util.math.BlockPos @@ -12,9 +13,7 @@ class BuildStructure( structure.forEach { (pos, state) -> addSubActivities( BuildBlock(pos, state).also { - executeOnFailure = { - refresh() - } + executeOnFailure = { if (it is BreakBlockRaw.ExceptionNoSurfaceExposed) refresh() } } ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 89caa5517..0e5a06b3c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -1,15 +1,12 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.LoopingUntilActivity +import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity -import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.inventory.TakeOffArmor import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.onSuccess import net.minecraft.init.Items -import net.minecraft.util.math.BlockPos class ReachXPLevel( private val desiredLevel: Int, @@ -19,8 +16,6 @@ class ReachXPLevel( override var currentLoops: Int = 0 ) : LoopingUntilActivity, Activity() { override fun SafeClientEvent.onInitialize() { - - addSubActivities( TakeOffArmor(), SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index f36f29294..639c85e91 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -1,11 +1,10 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.LoopingUntilActivity +import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.MovementUtils.centerPlayer import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt index dc96e8267..8c1045c27 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt @@ -1,37 +1,31 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.RenderBlockActivity -import com.lambda.client.activity.activities.RotatingActivity -import com.lambda.client.activity.activities.TimeoutActivity -import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.types.RenderBlockActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide -import net.minecraft.entity.item.EntityItem +import net.minecraft.block.material.Material import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item -import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.network.play.server.SPacketEntityMetadata -import net.minecraft.network.play.server.SPacketSpawnObject import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.gameevent.TickEvent -import java.lang.Exception import java.util.* +import kotlin.Exception import kotlin.math.ceil class BreakBlockRaw( @@ -54,8 +48,8 @@ class BreakBlockRaw( override fun SafeClientEvent.onInitialize() { val currentState = world.getBlockState(blockPos) - if (currentState.block == Blocks.AIR) { - onSuccess() + if (currentState.material == Material.AIR) { + success() return } @@ -72,23 +66,27 @@ class BreakBlockRaw( getMiningSide(blockPos)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) - if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { - playerController.onPlayerDestroyBlock(blockPos) - player.swingArm(EnumHand.MAIN_HAND) - } else { - playerController.onPlayerDamageBlock(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) - // cancel onPlayerDestroy NoGhostBlocks - -// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { -// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) -// player.swingArm(EnumHand.MAIN_HAND) -// } else { -// player.swingArm(EnumHand.MAIN_HAND) -// } - } + playerController.onPlayerDamageBlock(blockPos, side) + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) + +// if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { +// playerController.onPlayerDestroyBlock(blockPos) +// player.swingArm(EnumHand.MAIN_HAND) +// } else { +// playerController.onPlayerDamageBlock(blockPos, side) +// player.swingArm(EnumHand.MAIN_HAND) +// // cancel onPlayerDestroy NoGhostBlocks +// +//// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { +//// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) +//// player.swingArm(EnumHand.MAIN_HAND) +//// } else { +//// player.swingArm(EnumHand.MAIN_HAND) +//// } +// } } ?: run { - onFailure(Exception("No block surface exposed to player")) + failedWith(ExceptionNoSurfaceExposed()) } } @@ -128,7 +126,7 @@ class BreakBlockRaw( private fun SafeClientEvent.finish() { if (!collectDrops) { - onSuccess() + success() return } @@ -139,11 +137,16 @@ class BreakBlockRaw( addSubActivities( PickUpDrops(drop, minAmount = minCollectAmount).also { executeOnSuccess = { - with(owner) { - onSuccess() - } + with(owner) { success() } } } ) } + + override fun SafeClientEvent.onFailure(exception: Exception): Boolean { + playerController.resetBlockRemoving() + return true + } + + class ExceptionNoSurfaceExposed : Exception("No block surface exposed to player") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt index 2fcc8c3d7..50a9c9adc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt @@ -6,6 +6,6 @@ import com.lambda.client.event.SafeClientEvent class CloseContainer : Activity() { override fun SafeClientEvent.onInitialize() { player.closeScreen() - onSuccess() + success() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 6cf9e2b21..a52fee92d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,9 +1,8 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.toVec3dCenter @@ -11,12 +10,9 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock -import net.minecraft.network.play.server.SPacketOpenWindow -import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraftforge.client.event.GuiOpenEvent import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( @@ -48,7 +44,7 @@ class OpenContainer( safeListener { if (it.phase == TickEvent.Phase.END) { if (player.openContainer.windowId != 0) { - onSuccess() + success() } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt index 0116851a9..3a90c42ce 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt @@ -1,7 +1,10 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.* +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.RenderBlockActivity +import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder @@ -68,7 +71,7 @@ class PlaceBlockRaw( // activityStatus = ActivityStatus.PENDING } ?: run { - onFailure(Exception("No neighbour found")) + failedWith(NoNeighbourException()) color = ColorHolder(16, 74, 94) } } @@ -78,7 +81,9 @@ class PlaceBlockRaw( if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos && it.packet.blockState.block == targetState.block - ) onSuccess() + ) success() } } + + class NoNeighbourException : Exception("no neighbour found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt index da43331d5..817974be9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.RotatingActivity +import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.RotationUtils.getRotationToEntity import com.lambda.client.util.math.Vec2f @@ -33,7 +33,7 @@ class UseThrowableOnEntity( used++ - if (used == amount) onSuccess() + if (used == amount) success() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index 5f93a291d..4eaa8ad91 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -2,8 +2,8 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.AttemptActivity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.threads.safeListener @@ -53,8 +53,7 @@ class InventoryTransaction( // ToDo: find out if this is possible } } ?: run { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("Container outdated. Skipping task. $this") + failedWith(ContainerOutdatedException(windowId)) } } @@ -64,20 +63,20 @@ class InventoryTransaction( if (packet !is SPacketConfirmTransaction || packet.windowId != windowId - || packet.actionNumber != transactionId) return@safeListener + || packet.actionNumber != transactionId + ) return@safeListener - if (packet.wasAccepted()) { - getContainerOrNull(packet.windowId)?.let { container -> - container.slotClick(slot, mouseButton, type, player) - onSuccess() - LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") - } ?: run { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("Container is null") - } - } else { - activityStatus = ActivityStatus.FAILURE - LambdaMod.LOG.error("Denied packet: ${it.packet.javaClass.simpleName} $transactionId") + if (!packet.wasAccepted()) { + failedWith(DeniedException(packet.actionNumber)) + return@safeListener + } + + getContainerOrNull(packet.windowId)?.let { container -> + container.slotClick(slot, mouseButton, type, player) + success() + LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") + } ?: run { + failedWith(ContainerOutdatedException(packet.windowId)) } } } @@ -88,4 +87,7 @@ class InventoryTransaction( } else { null } + + class ContainerOutdatedException(windowId: Int) : Exception("WindowID $windowId of container outdated") + class DeniedException(transactionId: Short) : Exception("InventoryTransaction $transactionId was denied") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt index bfee77f03..0e15f5433 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt @@ -11,9 +11,11 @@ class SlotMustBeEmpty( override fun SafeClientEvent.onInitialize() { if (slot.stack.isEmpty) { - onSuccess() + success() } else { - onFailure(Exception("Slot must be empty")) + failedWith(ExceptionSlotNotEmpty()) } } + + class ExceptionSlotNotEmpty : Exception("Slot must be empty") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt index b6f8c618c..801ce09ab 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt @@ -31,10 +31,11 @@ class SwapOrMoveToItem( if (useShulkerBoxes) { addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) } else { - onFailure(Exception("No $item found in inventory (shulkers are disabled)")) - MessageSendHelper.sendErrorMessage("No $item found in inventory (shulkers are disabled)") + failedWith(NoItemFoundException(item)) } } } } + + class NoItemFoundException(item: Item) : Exception("No ${item.registryName} found in inventory (shulkers are disabled)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt index 85939c4f9..c69dcf124 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt @@ -9,6 +9,6 @@ class SwitchToHotbarSlot(private val slot: HotbarSlot) : Activity() { if (slot.hotbarSlot !in 0..8) return player.inventory.currentItem = slot.hotbarSlot playerController.updateController() - onSuccess() + success() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt index 300a35046..543e50815 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt @@ -9,10 +9,18 @@ class TryClearSlotWithQuickMove( ) : Activity() { override fun SafeClientEvent.onInitialize() { if (slot.stack.isEmpty) { - onSuccess() + success() } else { addSubActivities( - QuickMoveSlot(slot), + QuickMoveSlot(slot).also { + executeOnSuccess = { + if (slot.stack.isEmpty) { + success() + } else { + failedWith(SlotMustBeEmpty.ExceptionSlotNotEmpty()) + } + } + }, SlotMustBeEmpty(slot) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 661f658a3..399399b29 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -11,6 +11,7 @@ import com.lambda.client.util.items.allSlots import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack +import net.minecraft.util.math.BlockPos class ExtractItemFromShulkerBox( private val item: Item, @@ -31,18 +32,27 @@ class ExtractItemFromShulkerBox( } } - if (candidates.isEmpty()) return + if (candidates.isEmpty()) { + failedWith(NoShulkerBoxFoundExtractException(item)) + return + } candidates.minBy { it.value }.key.let { slot -> - getContainerPos()?.let { containerPos -> - addSubActivities( - OpenContainerInSlot(slot), - PullItemsFromContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true), - SwapOrMoveToItem(item, predicateItem, predicateSlot) - ) - } + var containerPos: BlockPos = BlockPos.ORIGIN + + addSubActivities( + OpenContainerInSlot(slot).also { + executeOnSuccess = { + containerPos = it.containerPos + } + }, + PullItemsFromContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(containerPos, collectDrops = true), + SwapOrMoveToItem(item, predicateItem, predicateSlot) + ) } } + + class NoShulkerBoxFoundExtractException(item: Item) : Exception("No shulker box was found containing ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index 0f03b35ea..854de7a3e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -8,17 +8,25 @@ import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.block import net.minecraft.inventory.Slot +import net.minecraft.util.math.BlockPos class OpenContainerInSlot( private val slot: Slot ) : Activity() { + var containerPos: BlockPos = BlockPos.ORIGIN + override fun SafeClientEvent.onInitialize() { - getContainerPos()?.let { containerPos -> - addSubActivities( - SwapOrSwitchToSlot(slot), - PlaceBlock(containerPos, slot.stack.item.block.defaultState, swapToItem = false), - OpenContainer(containerPos) - ) + containerPos = getContainerPos() ?: run { + failedWith(NoContainerPlacePositionFoundException()) + return } + + addSubActivities( + SwapOrSwitchToSlot(slot), + PlaceBlock(containerPos, slot.stack.item.block.defaultState, swapToItem = false), + OpenContainer(containerPos) + ) } + + class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 1c3ef1e2f..0837cc8d7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -10,6 +10,7 @@ import com.lambda.client.util.items.allSlots import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack +import net.minecraft.util.math.BlockPos class StoreItemToShulkerBox( private val item: Item, @@ -29,17 +30,26 @@ class StoreItemToShulkerBox( } } - if (candidates.isEmpty()) return + if (candidates.isEmpty()) { + failedWith(NoShulkerBoxFoundStoreException(item)) + return + } candidates.maxBy { it.value }.key.let { slot -> - getContainerPos()?.let { containerPos -> - addSubActivities( - OpenContainerInSlot(slot), - PushItemsToContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true) - ) - } + var containerPos: BlockPos = BlockPos.ORIGIN + + addSubActivities( + OpenContainerInSlot(slot).also { + executeOnSuccess = { + containerPos = it.containerPos + } + }, + PushItemsToContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(containerPos, collectDrops = true) + ) } } + + class NoShulkerBoxFoundStoreException(item: Item) : Exception("No shulker box was found with space to store ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index 7ec3e9e9e..e57f23a49 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.Goal import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition @@ -16,7 +16,7 @@ class CustomGoal( override fun SafeClientEvent.onInitialize() { if (!goal.isInGoal(player.flooredPosition)) return - onSuccess() + success() } init { @@ -25,7 +25,7 @@ class CustomGoal( BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) - if (goal.isInGoal(player.flooredPosition)) onSuccess() + if (goal.isInGoal(player.flooredPosition)) success() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 7f8ec0229..ac71224b2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.utils.SetState import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem @@ -20,7 +19,7 @@ class PickUpDrops( } if (drops.isEmpty() || drops.sumOf { it.item.count } < minAmount) { - onSuccess() + success() return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 7f6027a62..45209ab60 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -2,15 +2,13 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.TimeoutActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.inventory.DumpSlot import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.inventorySlots -import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem -import net.minecraftforge.event.entity.player.EntityItemPickupEvent import net.minecraftforge.fml.common.gameevent.TickEvent import java.lang.Exception @@ -24,7 +22,7 @@ class PickUpEntityItem( if (!world.loadedEntityList.contains(entityItem)) { BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) - onSuccess() + success() return@safeListener } @@ -40,8 +38,10 @@ class PickUpEntityItem( }?.let { slot -> addSubActivities(DumpSlot(slot)) } ?: run { - onFailure(Exception("No empty slots or items to dump!")) + failedWith(InventoryFullException()) } } } + + class InventoryFullException : Exception("No empty slots or items to dump!") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt new file mode 100644 index 000000000..911daa463 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -0,0 +1,28 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.text.MessageSendHelper + +interface AttemptActivity { + val maxAttempts: Int + var usedAttempts: Int + + companion object { + fun SafeClientEvent.checkAttempt(activity: Activity) { + if (activity !is AttemptActivity) return + + with(activity) { + if (usedAttempts >= maxAttempts) { + failedWith(MaxAttemptsExceededException(usedAttempts)) + } else { + usedAttempts++ + initialize() + MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") + } + } + } + + class MaxAttemptsExceededException(usedAttempts: Int) : Exception("exceeded $usedAttempts attempts") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt new file mode 100644 index 000000000..9245cf76f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt @@ -0,0 +1,20 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent + +interface DelayedActivity { + val delay: Long + + fun SafeClientEvent.onDelayedActivity() + + companion object { + fun SafeClientEvent.checkDelayed(activity: Activity) { + if (activity !is DelayedActivity) return + + with(activity) { + if (age > delay) onDelayedActivity() + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt new file mode 100644 index 000000000..01ac41e28 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt @@ -0,0 +1,27 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.activityStatus +import com.lambda.client.manager.managers.ActivityManager.name +import com.lambda.client.manager.managers.ActivityManager.owner + +interface LoopingAmountActivity { + val maxLoops: Int + var currentLoops: Int + + companion object { + fun checkLoopingAmount(activity: Activity) { + if (activity !is LoopingAmountActivity) return + + with(activity) { + if (currentLoops++ >= maxLoops || maxLoops != 0) return + + activityStatus = Activity.ActivityStatus.UNINITIALIZED + owner.subActivities.add(activity) + LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt new file mode 100644 index 000000000..267539d14 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt @@ -0,0 +1,25 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent + +interface LoopingUntilActivity { + val loopUntil: SafeClientEvent.() -> Boolean + var currentLoops: Int + + companion object { + fun SafeClientEvent.checkLoopingUntil(activity: Activity) { + if (activity !is LoopingUntilActivity) return + + with(activity) { + if (!loopUntil()) return + + currentLoops++ + activityStatus = Activity.ActivityStatus.UNINITIALIZED + owner.subActivities.add(activity) + LambdaMod.LOG.info("Looping $name ($currentLoops)") + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt new file mode 100644 index 000000000..0f201f00f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt @@ -0,0 +1,9 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.util.color.ColorHolder +import net.minecraft.util.math.BlockPos + +interface RenderBlockActivity { + var renderBlockPos: BlockPos + var color: ColorHolder +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt new file mode 100644 index 000000000..98eb9b5f5 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt @@ -0,0 +1,22 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.PlayerPacketManager +import com.lambda.client.util.math.Vec2f + +interface RotatingActivity { + var rotation: Vec2f + + companion object { + fun checkRotating(activity: Activity) { + if (activity !is RotatingActivity) return + + with(activity) { + PlayerPacketManager.sendPlayerPacket { + rotate(rotation) + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt new file mode 100644 index 000000000..7c7c5d90b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -0,0 +1,27 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt +import com.lambda.client.event.SafeClientEvent + +interface TimeoutActivity { + val timeout: Long + + companion object { + fun SafeClientEvent.checkTimeout(activity: Activity) { + if (activity !is TimeoutActivity) return + + with(activity) { + if (age <= timeout) return + + if (activity is AttemptActivity) { + checkAttempt(activity) + } else { + failedWith(TimeoutException(age, timeout)) + } + } + } + + class TimeoutException(age: Long, timeout: Long): Exception("exceeded maximum age ($age) of $timeout ms") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt deleted file mode 100644 index 37680cd7b..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/SetState.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.lambda.client.activity.activities.utils - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import java.lang.Exception - -class SetState(private val state: ActivityStatus) : Activity() { - override fun SafeClientEvent.onInitialize() { - with(owner) { - when (state) { - ActivityStatus.UNINITIALIZED -> activityStatus = state - ActivityStatus.SUCCESS -> onSuccess() - ActivityStatus.RUNNING -> activityStatus = state - ActivityStatus.PENDING -> activityStatus = state - ActivityStatus.FAILURE -> onFailure(Exception("SetState forced fail")) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt index 5dd654886..1fcd8159d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt @@ -1,13 +1,13 @@ package com.lambda.client.activity.activities.utils import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.DelayedActivity +import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.event.SafeClientEvent class Wait( override val delay: Long ) : DelayedActivity, Activity() { override fun SafeClientEvent.onDelayedActivity() { - onSuccess() + success() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index 59b6ea9e2..3bc6002ff 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -20,13 +20,14 @@ internal object ActivityManagerHud: LabelHud( ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) - displayText.addLine("") - displayText.addLine("Subscribers:") - ListenerManager.listenerMap.keys.filterIsInstance().forEach { - displayText.addLine("${it::class.simpleName}") - } - ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { - displayText.addLine("${it::class.simpleName}") + val sync = ListenerManager.listenerMap.keys.filterIsInstance() + val async = ListenerManager.asyncListenerMap.keys.filterIsInstance() + + if (sync.isNotEmpty() || async.isNotEmpty()) { + displayText.addLine("") + displayText.addLine("Subscribers:") + if (sync.isNotEmpty()) displayText.addLine("SYNC ${sync.map { it::class.simpleName }}") + if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.map { it::class.simpleName }}") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 4630c72d0..93860ff73 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,7 +1,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.RenderBlockActivity +import com.lambda.client.activity.activities.types.RenderBlockActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent @@ -15,14 +15,16 @@ import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 - var lastActivity: Activity = this + private var lastActivity: Activity = this init { safeListener { event -> if (noSubActivities() || event.phase != TickEvent.Phase.START) return@safeListener + val currentActivity = currentActivity + with(currentActivity) { - if (activityStatus == ActivityStatus.RUNNING) updateTypesOnTick() + if (activityStatus == ActivityStatus.RUNNING) updateTypesOnTick(currentActivity) } repeat(10) { @@ -43,13 +45,12 @@ object ActivityManager : Manager, Activity() { } } - fun SafeClientEvent.updateCurrentActivity() { + private fun SafeClientEvent.updateCurrentActivity() { val currentActivity = currentActivity with(currentActivity) { if (currentActivity != lastActivity) { if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { -// if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } @@ -66,7 +67,6 @@ object ActivityManager : Manager, Activity() { fun reset() { if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { -// if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } From 124d9f9d1c19b05604b7564984e3048e85522148 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 2 Jan 2023 06:11:52 +0100 Subject: [PATCH 039/104] Decision chains and exception improvement --- .../com/lambda/client/activity/Activity.kt | 49 +++++++------------ .../activities/example/ListenAndWait.kt | 5 +- .../highlevel/BreakDownEnderChests.kt | 45 +++++++++-------- .../activities/highlevel/BuildBlock.kt | 2 +- .../activities/highlevel/BuildStructure.kt | 7 ++- .../activities/highlevel/ReachXPLevel.kt | 4 +- .../highlevel/SurroundWithObsidian.kt | 4 +- .../activities/interaction/BreakBlockRaw.kt | 40 +++++++-------- .../activities/interaction/PlaceBlockRaw.kt | 4 +- .../inventory/InventoryTransaction.kt | 38 +++++++------- .../activities/inventory/SlotMustBeEmpty.kt | 21 -------- .../inventory/TryClearSlotWithQuickMove.kt | 7 +-- .../storage/ExtractItemFromShulkerBox.kt | 27 +++++----- .../activities/storage/OpenContainerInSlot.kt | 21 ++++++-- .../storage/PushItemsToContainer.kt | 15 ++++-- .../storage/StoreItemToShulkerBox.kt | 26 +++++----- .../activities/types/AttemptActivity.kt | 14 ++++-- .../activities/types/LoopingAmountActivity.kt | 2 +- .../activities/types/LoopingUntilActivity.kt | 4 +- .../activities/types/TimeoutActivity.kt | 10 ++-- .../manager/managers/ActivityManager.kt | 6 ++- 21 files changed, 179 insertions(+), 172 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 5b071062e..007d12c35 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -25,26 +25,23 @@ import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity { val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED - var creationTime = 0L + private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 val name get() = this::class.simpleName val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this - var executeOnSuccess: (() -> Unit)? = null - var executeOnFailure: ((Exception) -> Unit)? = null - private var executeOnFinalize: (() -> Unit)? = null + var executeOnInitialize: (SafeClientEvent.() -> Unit)? = null + var executeOnSuccess: (SafeClientEvent.() -> Unit)? = null + var executeOnFailure: ((Exception) -> Boolean)? = null open fun SafeClientEvent.onInitialize() {} open fun SafeClientEvent.onSuccess() {} - /* Return true to stop the activity - * */ - open fun SafeClientEvent.onFailure(exception: Exception): Boolean = true - - open fun SafeClientEvent.onFinalize() {} + /* Return true to catch the exception */ + open fun SafeClientEvent.onFailure(exception: Exception): Boolean = false open fun addExtraInfo( textComponent: TextComponent, @@ -61,14 +58,10 @@ abstract class Activity { if (!ListenerManager.listenerMap.containsKey(this@Activity) && noSubActivities() && this@Activity !is DelayedActivity - ) finalize() + ) success() } ActivityStatus.PENDING -> { - refresh() - } - ActivityStatus.SUCCESS -> { - executeOnSuccess?.invoke() - finalize() +// refresh() } ActivityStatus.FAILURE -> { // @@ -79,7 +72,6 @@ abstract class Activity { fun SafeClientEvent.updateTypesOnTick(activity: Activity) { checkTimeout(activity) checkDelayed(activity) - checkAttempt(activity) checkRotating(activity) } @@ -87,38 +79,34 @@ abstract class Activity { activityStatus = ActivityStatus.RUNNING creationTime = System.currentTimeMillis() onInitialize() + executeOnInitialize?.invoke(this) checkRotating(this@Activity) // LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") } - private fun SafeClientEvent.finalize() { + fun SafeClientEvent.success() { val activity = this@Activity - onFinalize() - executeOnFinalize?.invoke() + onSuccess() + executeOnSuccess?.invoke(this) owner.subActivities.remove(activity) checkLoopingAmount(activity) checkLoopingUntil(activity) // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") -// MessageSendHelper.sendRawChatMessage("$name took ${System.currentTimeMillis() - creationTime}ms") - } - - fun SafeClientEvent.success() { - finalize() - executeOnSuccess?.invoke() +// MessageSendHelper.sendRawChatMessage("$name took ${age}ms") } fun SafeClientEvent.failedWith(exception: Exception) { - if (onFailure(exception)) { - executeOnFailure?.invoke(exception) + MessageSendHelper.sendErrorMessage("Exception in $name: ${exception.message}") + if (checkAttempt(this@Activity, exception)) return + if (executeOnFailure?.invoke(exception) == true) return + if (onFailure(exception)) return - MessageSendHelper.sendErrorMessage("Exception in ${this@Activity::class.simpleName}: ${exception.message}") - ActivityManager.reset() - } + ActivityManager.reset() } fun refresh() { @@ -167,7 +155,6 @@ abstract class Activity { UNINITIALIZED, RUNNING, PENDING, - SUCCESS, FAILURE } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt index 705b2198c..4cf0a3fa8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -25,11 +25,8 @@ class ListenAndWait( override fun SafeClientEvent.onFailure(exception: Exception) = if (exception is TimeoutActivity.Companion.TimeoutException) { success() - false - } else { - MessageSendHelper.sendChatMessage("Failure!") true - } + } else false override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { textComponent.add("Age", primaryColor) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 9a25972d9..a2bc77618 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.LoopingAmountActivity import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.BreakBlockRaw import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox @@ -21,28 +22,32 @@ class BreakDownEnderChests( override var currentLoops: Int = 0 ) : LoopingAmountActivity, Activity() { override fun SafeClientEvent.onInitialize() { + if (player.inventorySlots.countEmpty() < 2) { + addSubActivities( + StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + ) + return + } + getContainerPos()?.let { remotePos -> - if (player.inventorySlots.countEmpty() < 2) { - addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + addSubActivities( + PlaceBlock(remotePos, Blocks.ENDER_CHEST.defaultState), + SwapOrMoveToItem( + Items.DIAMOND_PICKAXE, + predicateItem = { + EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 + } + ), + BreakBlockRaw( + remotePos, + collectDrops = true, + minCollectAmount = 64 ) - } else { - addSubActivities( - PlaceBlock(remotePos, Blocks.ENDER_CHEST.defaultState), - SwapOrMoveToItem( - Items.DIAMOND_PICKAXE, - predicateItem = { - EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 - } - ), - BreakBlock( - remotePos, - useBestTool = false, - collectDrops = true, - minCollectAmount = 64 - ) - ) - } + ) + } ?: run { + failedWith(NoEnderChestPosFoundException()) } } + + class NoEnderChestPosFoundException : Exception("No free ender chest position was found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index fdd239938..b9b86315b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -39,5 +39,5 @@ class BuildBlock( } } - class EntityCollisionException : Exception("entity collision") + class EntityCollisionException : Exception("Entity collision while placing block") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index f85a9ddca..b19bd5e46 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -13,7 +13,12 @@ class BuildStructure( structure.forEach { (pos, state) -> addSubActivities( BuildBlock(pos, state).also { - executeOnFailure = { if (it is BreakBlockRaw.ExceptionNoSurfaceExposed) refresh() } + executeOnFailure = { + if (it is BreakBlockRaw.ExceptionNoSurfaceExposed) { + refresh() + true + } else false + } } ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 0e5a06b3c..cfc4e0a3e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -10,8 +10,8 @@ import net.minecraft.init.Items class ReachXPLevel( private val desiredLevel: Int, - override val loopUntil: SafeClientEvent.() -> Boolean = { - player.experienceLevel >= desiredLevel + override val loopWhile: SafeClientEvent.() -> Boolean = { + player.experienceLevel < desiredLevel }, override var currentLoops: Int = 0 ) : LoopingUntilActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index 639c85e91..1b31b1d77 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -10,8 +10,8 @@ import net.minecraft.util.math.BlockPos class SurroundWithObsidian( private val originPos: BlockPos, - override val loopUntil: SafeClientEvent.() -> Boolean = { - originPos != player.flooredPosition + override val loopWhile: SafeClientEvent.() -> Boolean = { + originPos == player.flooredPosition }, override var currentLoops: Int = 0 ) : LoopingUntilActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt index 8c1045c27..357c61ada 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt @@ -94,7 +94,24 @@ class BreakBlockRaw( if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos && it.packet.blockState.block == Blocks.AIR - ) finish() + ) { + if (!collectDrops) { + success() + return@safeListener + } + + color = ColorHolder(252, 3, 207) + + if (drop.block == Blocks.AIR) return@safeListener + + addSubActivities( + PickUpDrops(drop, minAmount = minCollectAmount).also { + executeOnSuccess = { + with(owner) { success() } + } + } + ) + } } } @@ -124,28 +141,9 @@ class BreakBlockRaw( } } - private fun SafeClientEvent.finish() { - if (!collectDrops) { - success() - return - } - - color = ColorHolder(252, 3, 207) - - if (drop.block == Blocks.AIR) return - - addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount).also { - executeOnSuccess = { - with(owner) { success() } - } - } - ) - } - override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() - return true + return false } class ExceptionNoSurfaceExposed : Exception("No block surface exposed to player") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt index 3a90c42ce..5538b219e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt @@ -71,7 +71,7 @@ class PlaceBlockRaw( // activityStatus = ActivityStatus.PENDING } ?: run { - failedWith(NoNeighbourException()) + failedWith(NoNeighbourException(blockPos)) color = ColorHolder(16, 74, 94) } } @@ -85,5 +85,5 @@ class PlaceBlockRaw( } } - class NoNeighbourException : Exception("no neighbour found") + class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for $blockPos found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index 4eaa8ad91..12542260d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -26,32 +26,28 @@ class InventoryTransaction( override fun SafeClientEvent.onInitialize() { getContainerOrNull(windowId)?.let { activeContainer -> - player.inventory?.let { inventory -> - transactionId = activeContainer.getNextTransactionID(inventory) + transactionId = activeContainer.getNextTransactionID(player.inventory) - val itemStack = if (type == ClickType.PICKUP && slot != -999) { - activeContainer.inventorySlots?.getOrNull(slot)?.stack ?: ItemStack.EMPTY - } else { - ItemStack.EMPTY - } + val itemStack = if (type == ClickType.PICKUP && slot != -999) { + activeContainer.inventorySlots?.getOrNull(slot)?.stack ?: ItemStack.EMPTY + } else { + ItemStack.EMPTY + } - val packet = CPacketClickWindow( - windowId, - slot, - mouseButton, - type, - itemStack, - transactionId - ) + val packet = CPacketClickWindow( + windowId, + slot, + mouseButton, + type, + itemStack, + transactionId + ) - connection.sendPacket(packet) + connection.sendPacket(packet) - playerController.updateController() + playerController.updateController() - LambdaMod.LOG.info("Sent packet: ${packet.javaClass.simpleName}") - } ?: run { - // ToDo: find out if this is possible - } + LambdaMod.LOG.info("Sent packet: ${packet.javaClass.simpleName}") } ?: run { failedWith(ContainerOutdatedException(windowId)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt deleted file mode 100644 index 0e15f5433..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SlotMustBeEmpty.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.lambda.client.activity.activities.inventory - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import net.minecraft.inventory.Slot -import java.lang.Exception - -class SlotMustBeEmpty( - private val slot: Slot -) : Activity() { - - override fun SafeClientEvent.onInitialize() { - if (slot.stack.isEmpty) { - success() - } else { - failedWith(ExceptionSlotNotEmpty()) - } - } - - class ExceptionSlotNotEmpty : Exception("Slot must be empty") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt index 543e50815..6f0e1355b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt @@ -17,12 +17,13 @@ class TryClearSlotWithQuickMove( if (slot.stack.isEmpty) { success() } else { - failedWith(SlotMustBeEmpty.ExceptionSlotNotEmpty()) + failedWith(ExceptionSlotNotEmpty()) } } - }, - SlotMustBeEmpty(slot) + } ) } } + + class ExceptionSlotNotEmpty : Exception("Slot is still not empty") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 399399b29..d259d12b9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -38,19 +38,22 @@ class ExtractItemFromShulkerBox( } candidates.minBy { it.value }.key.let { slot -> - var containerPos: BlockPos = BlockPos.ORIGIN - - addSubActivities( - OpenContainerInSlot(slot).also { - executeOnSuccess = { - containerPos = it.containerPos + val openContainerInSlot = OpenContainerInSlot(slot) + + with(openContainerInSlot) { + executeOnSuccess = { + with(owner) { + addSubActivities( + PullItemsFromContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(containerPos, collectDrops = true), + SwapOrMoveToItem(item, predicateItem, predicateSlot) + ) } - }, - PullItemsFromContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true), - SwapOrMoveToItem(item, predicateItem, predicateSlot) - ) + } + } + + addSubActivities(openContainerInSlot) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt index 854de7a3e..ba0062d88 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt @@ -3,16 +3,22 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.interaction.PlaceBlockRaw import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.block +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.inventory.Slot import net.minecraft.util.math.BlockPos class OpenContainerInSlot( - private val slot: Slot -) : Activity() { + private val slot: Slot, + override val maxAttempts: Int = 5, + override var usedAttempts: Int = 0 +) : AttemptActivity, Activity() { var containerPos: BlockPos = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { @@ -23,7 +29,16 @@ class OpenContainerInSlot( addSubActivities( SwapOrSwitchToSlot(slot), - PlaceBlock(containerPos, slot.stack.item.block.defaultState, swapToItem = false), + PlaceBlockRaw(containerPos, slot.stack.item.block.defaultState).also { + executeOnFailure = { + if (it is PlaceBlockRaw.NoNeighbourException) { + usedAttempts++ + initialize() + MessageSendHelper.sendErrorMessage("No neighbour found, retrying...") + true + } else false + } + }, OpenContainer(containerPos) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index f7d189361..6a205837c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -2,7 +2,9 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot +import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -10,16 +12,21 @@ import net.minecraft.item.ItemStack class PushItemsToContainer( private val item: Item, private val amount: Int = 0, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true } -) : Activity() { + private val predicateItem: (ItemStack) -> Boolean = { true }, + override val loopWhile: SafeClientEvent.() -> Boolean = { + player.openContainer.inventorySlots.size == 63 + && player.openContainer.getSlots(27..62).countEmpty() > 0 + }, + override var currentLoops: Int = 0 +) : LoopingUntilActivity, Activity() { override fun SafeClientEvent.onInitialize() { val openContainer = player.openContainer if (openContainer.inventorySlots.size != 63) return - openContainer.getSlots(27..62).filter { slot -> + openContainer.getSlots(27..62).firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) - }.forEach { + }?.let { addSubActivities(QuickMoveSlot(it)) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 0837cc8d7..ceab057f3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer +import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent @@ -36,18 +37,21 @@ class StoreItemToShulkerBox( } candidates.maxBy { it.value }.key.let { slot -> - var containerPos: BlockPos = BlockPos.ORIGIN - - addSubActivities( - OpenContainerInSlot(slot).also { - executeOnSuccess = { - containerPos = it.containerPos + val openContainerInSlot = OpenContainerInSlot(slot) + + with(openContainerInSlot) { + executeOnSuccess = { + with(owner) { + addSubActivities( + PushItemsToContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(containerPos, collectDrops = true) + ) } - }, - PushItemsToContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true) - ) + } + } + + addSubActivities(openContainerInSlot) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 911daa463..8fad53723 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -9,20 +9,24 @@ interface AttemptActivity { var usedAttempts: Int companion object { - fun SafeClientEvent.checkAttempt(activity: Activity) { - if (activity !is AttemptActivity) return + fun SafeClientEvent.checkAttempt(activity: Activity, causeException: Exception): Boolean { + if (activity !is AttemptActivity) return false + if (causeException is MaxAttemptsExceededException + || causeException is TimeoutActivity.Companion.TimeoutException) return false with(activity) { if (usedAttempts >= maxAttempts) { - failedWith(MaxAttemptsExceededException(usedAttempts)) + failedWith(MaxAttemptsExceededException(usedAttempts, causeException)) + return false } else { usedAttempts++ + MessageSendHelper.sendErrorMessage("$name caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") initialize() - MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") + return true } } } - class MaxAttemptsExceededException(usedAttempts: Int) : Exception("exceeded $usedAttempts attempts") + class MaxAttemptsExceededException(usedAttempts: Int, causeException: Exception) : Exception("Exceeded $usedAttempts attempts caused by ${causeException::class.simpleName}: ${causeException.message}") } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt index 01ac41e28..8613960ce 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt @@ -16,7 +16,7 @@ interface LoopingAmountActivity { if (activity !is LoopingAmountActivity) return with(activity) { - if (currentLoops++ >= maxLoops || maxLoops != 0) return + if (currentLoops++ >= maxLoops && maxLoops != 0) return activityStatus = Activity.ActivityStatus.UNINITIALIZED owner.subActivities.add(activity) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt index 267539d14..d69df91e1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt @@ -5,7 +5,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent interface LoopingUntilActivity { - val loopUntil: SafeClientEvent.() -> Boolean + val loopWhile: SafeClientEvent.() -> Boolean var currentLoops: Int companion object { @@ -13,7 +13,7 @@ interface LoopingUntilActivity { if (activity !is LoopingUntilActivity) return with(activity) { - if (!loopUntil()) return + if (!loopWhile()) return currentLoops++ activityStatus = Activity.ActivityStatus.UNINITIALIZED diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index 7c7c5d90b..820229e6f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -1,8 +1,8 @@ package com.lambda.client.activity.activities.types import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.text.MessageSendHelper interface TimeoutActivity { val timeout: Long @@ -15,13 +15,17 @@ interface TimeoutActivity { if (age <= timeout) return if (activity is AttemptActivity) { - checkAttempt(activity) + with(activity) { + usedAttempts++ + initialize() + MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") + } } else { failedWith(TimeoutException(age, timeout)) } } } - class TimeoutException(age: Long, timeout: Long): Exception("exceeded maximum age ($age) of $timeout ms") + class TimeoutException(age: Long, timeout: Long): Exception("Exceeded maximum age ($age) of $timeout ms") } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 93860ff73..795d01697 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -50,7 +50,8 @@ object ActivityManager : Manager, Activity() { with(currentActivity) { if (currentActivity != lastActivity) { - if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { + if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } @@ -66,7 +67,8 @@ object ActivityManager : Manager, Activity() { } fun reset() { - if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { + if (lastActivity !is ActivityManager) { LambdaEventBus.unsubscribe(lastActivity) ListenerManager.unregister(lastActivity) } From 14856931dcfc94d332fe106683c198539e5163f4 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 3 Jan 2023 11:01:11 +0100 Subject: [PATCH 040/104] Big refactor for exception handling --- .../com/lambda/client/activity/Activity.kt | 93 +++++++++++++++---- .../highlevel/BreakDownEnderChests.kt | 46 ++++----- .../activities/highlevel/BuildStructure.kt | 10 +- .../activities/highlevel/ReachXPLevel.kt | 4 +- .../activities/interaction/BreakBlockRaw.kt | 23 +++-- .../activities/interaction/OpenContainer.kt | 19 +++- .../activities/interaction/PlaceBlock.kt | 8 +- .../activities/interaction/PlaceBlockRaw.kt | 19 ++-- ...veToItem.kt => AcquireItemInActiveHand.kt} | 12 ++- .../inventory/InventoryTransaction.kt | 4 +- .../activities/inventory/QuickMoveSlot.kt | 25 ++++- .../inventory/SwapOrSwitchToSlot.kt | 3 +- .../activities/inventory/TakeOffArmor.kt | 2 +- .../inventory/TryClearSlotWithQuickMove.kt | 29 ------ .../storage/ExtractItemFromShulkerBox.kt | 39 ++++---- .../activities/storage/OpenContainerInSlot.kt | 47 ---------- .../activities/storage/PlaceContainer.kt | 39 ++++++++ .../storage/PushItemsToContainer.kt | 33 +++++-- .../storage/StoreItemToShulkerBox.kt | 38 ++++---- .../activities/travel/PickUpEntityItem.kt | 11 ++- .../activities/types/AttemptActivity.kt | 4 +- ...BlockActivity.kt => RenderAABBActivity.kt} | 6 +- .../activities/types/TimeoutActivity.kt | 12 ++- .../activities/utils/ActivityUtils.kt | 10 +- .../elements/misc/ActivityManagerHud.kt | 16 +++- .../manager/managers/ActivityManager.kt | 9 +- .../client/module/modules/combat/AutoTrap.kt | 5 +- .../module/modules/combat/CrystalBasePlace.kt | 3 +- .../client/module/modules/combat/Surround.kt | 2 +- .../module/modules/misc/AutoObsidian.kt | 2 +- .../modules/misc/TestActivityManager.kt | 12 +-- .../modules/player/InventoryManagerTwo.kt | 31 ++++--- .../com/lambda/client/util/world/Check.kt | 7 +- .../com/lambda/client/util/world/Interact.kt | 12 ++- 34 files changed, 374 insertions(+), 261 deletions(-) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{SwapOrMoveToItem.kt => AcquireItemInActiveHand.kt} (80%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt rename src/main/kotlin/com/lambda/client/activity/activities/types/{RenderBlockActivity.kt => RenderAABBActivity.kt} (54%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 007d12c35..dbc58d330 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -17,10 +17,14 @@ import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.text.capitalize import net.minecraft.entity.Entity +import net.minecraft.item.ItemBlock import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import org.apache.commons.lang3.time.DurationFormatUtils +import java.util.* import java.util.concurrent.ConcurrentLinkedDeque +import kotlin.collections.ArrayDeque abstract class Activity { val subActivities = ConcurrentLinkedDeque() @@ -28,21 +32,23 @@ abstract class Activity { private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 - val name get() = this::class.simpleName + val name get() = this::class.simpleName ?: "Activity" val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this - var executeOnInitialize: (SafeClientEvent.() -> Unit)? = null - var executeOnSuccess: (SafeClientEvent.() -> Unit)? = null - var executeOnFailure: ((Exception) -> Boolean)? = null - open fun SafeClientEvent.onInitialize() {} + open fun SafeClientEvent.onChildInitialize(childActivity: Activity) {} + open fun SafeClientEvent.onSuccess() {} + open fun SafeClientEvent.onChildSuccess(childActivity: Activity) {} + /* Return true to catch the exception */ open fun SafeClientEvent.onFailure(exception: Exception): Boolean = false + open fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean = false + open fun addExtraInfo( textComponent: TextComponent, primaryColor: ColorHolder, @@ -76,12 +82,17 @@ abstract class Activity { } fun SafeClientEvent.initialize() { + val activity = this@Activity + activityStatus = ActivityStatus.RUNNING creationTime = System.currentTimeMillis() onInitialize() - executeOnInitialize?.invoke(this) - checkRotating(this@Activity) +// with(owner) { +// onChildInitialize(activity) +// } + + checkRotating(activity) // LambdaMod.LOG.info("${System.currentTimeMillis()} Initialized $name ${System.currentTimeMillis() - ActivityManager.lastActivity.creationTime}ms after last activity creation") } @@ -89,10 +100,12 @@ abstract class Activity { fun SafeClientEvent.success() { val activity = this@Activity - onSuccess() - executeOnSuccess?.invoke(this) - owner.subActivities.remove(activity) + with(owner) { + onChildSuccess(activity) + subActivities.remove(activity) + } + onSuccess() checkLoopingAmount(activity) checkLoopingUntil(activity) @@ -101,14 +114,35 @@ abstract class Activity { } fun SafeClientEvent.failedWith(exception: Exception) { - MessageSendHelper.sendErrorMessage("Exception in $name: ${exception.message}") - if (checkAttempt(this@Activity, exception)) return - if (executeOnFailure?.invoke(exception) == true) return + val activity = this@Activity + + with(owner) { + if (childFailure(ArrayDeque(listOf(activity)), exception)) return + } + + if (checkAttempt(activity, exception)) return if (onFailure(exception)) return + MessageSendHelper.sendErrorMessage("Exception in $name: ${exception.message}") + ActivityManager.reset() } + private fun SafeClientEvent.childFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (onChildFailure(childActivities, childException)) return true + + if (onFailure(childException)) return true + MessageSendHelper.sendErrorMessage("${childActivities.joinToString { it.name }}: ${childException.message}") + + if (owner == ActivityManager) return false + + childActivities.add(this@Activity) + with(owner) { + childFailure(childActivities, childException) + } + return false + } + fun refresh() { activityStatus = ActivityStatus.UNINITIALIZED owner.subActivities.remove(this) @@ -170,16 +204,37 @@ abstract class Activity { textComponent.add("${javaClass.simpleName} ", secondaryColor) textComponent.add("State", primaryColor) textComponent.add(activityStatus.name, secondaryColor) - this::class.java.declaredFields.forEach { field -> + + if (activityStatus == ActivityStatus.RUNNING) { + textComponent.add("Runtime", primaryColor) + textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), secondaryColor) + } + this::class.java.declaredFields.forEachIndexed { index, field -> field.isAccessible = true val name = field.name val value = field.get(this) - if (!ActivityManagerHud.anonymize - || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) - ) { - textComponent.add(name.capitalize(), primaryColor) - textComponent.add(value.toString(), secondaryColor) + if (index.mod(6) == 0) { + textComponent.addLine("", primaryColor) + repeat(depth) { + textComponent.add(" ") + } + } + + value?.let { + if (!ActivityManagerHud.anonymize + || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) + ) { + textComponent.add(name.capitalize(), primaryColor) + when (value) { + is ItemBlock -> { + textComponent.add(value.block.localizedName, secondaryColor) + } + else -> { + textComponent.add(value.toString(), secondaryColor) + } + } + } } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index a2bc77618..eace40239 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -2,12 +2,10 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.LoopingAmountActivity -import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.BreakBlockRaw -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox -import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots @@ -29,25 +27,27 @@ class BreakDownEnderChests( return } - getContainerPos()?.let { remotePos -> - addSubActivities( - PlaceBlock(remotePos, Blocks.ENDER_CHEST.defaultState), - SwapOrMoveToItem( - Items.DIAMOND_PICKAXE, - predicateItem = { - EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 - } - ), - BreakBlockRaw( - remotePos, - collectDrops = true, - minCollectAmount = 64 - ) - ) - } ?: run { - failedWith(NoEnderChestPosFoundException()) - } + addSubActivities( + AcquireItemInActiveHand(Blocks.ENDER_CHEST.item), + PlaceContainer(Blocks.ENDER_CHEST.defaultState) + ) } - class NoEnderChestPosFoundException : Exception("No free ender chest position was found") + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PlaceContainer) return + + addSubActivities( + AcquireItemInActiveHand( + Items.DIAMOND_PICKAXE, + predicateItem = { + EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 + } + ), + BreakBlockRaw( + childActivity.containerPos, + collectDrops = true, + minCollectAmount = 64 + ) + ) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index b19bd5e46..04d39ef42 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlockRaw import com.lambda.client.event.SafeClientEvent import net.minecraft.block.state.IBlockState import net.minecraft.util.math.BlockPos @@ -12,14 +11,7 @@ class BuildStructure( override fun SafeClientEvent.onInitialize() { structure.forEach { (pos, state) -> addSubActivities( - BuildBlock(pos, state).also { - executeOnFailure = { - if (it is BreakBlockRaw.ExceptionNoSurfaceExposed) { - refresh() - true - } else false - } - } + BuildBlock(pos, state) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index cfc4e0a3e..4fc5d15bd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items @@ -18,7 +18,7 @@ class ReachXPLevel( override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), - SwapOrMoveToItem(Items.EXPERIENCE_BOTTLE), + AcquireItemInActiveHand(Items.EXPERIENCE_BOTTLE), UseThrowableOnEntity(player) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt index 357c61ada..d8036aa09 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt @@ -5,7 +5,7 @@ import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.RenderBlockActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder @@ -22,6 +22,7 @@ import net.minecraft.item.Item import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* @@ -37,10 +38,10 @@ class BreakBlockRaw( override var timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, - override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(0, 0, 0), + override var renderAABB: AxisAlignedBB = AxisAlignedBB(blockPos), + override var color: ColorHolder = ColorHolder(240, 222, 60), override var rotation: Vec2f = Vec2f.ZERO -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderBlockActivity, Activity() { +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, Activity() { private var ticksNeeded = 0 private var initState = Blocks.AIR.defaultState private var drop: Item = Items.AIR @@ -55,6 +56,7 @@ class BreakBlockRaw( initState = currentState drop = currentState.block.getItemDropped(currentState, Random(), 0) + renderAABB = currentState.getSelectedBoundingBox(world, blockPos) ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() timeout = ticksNeeded * 50L + 2000L } @@ -65,6 +67,7 @@ class BreakBlockRaw( getMiningSide(blockPos)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) + renderAABB = world.getBlockState(blockPos).getSelectedBoundingBox(world, blockPos) playerController.onPlayerDamageBlock(blockPos, side) mc.effectRenderer.addBlockHitEffects(blockPos, side) @@ -105,16 +108,18 @@ class BreakBlockRaw( if (drop.block == Blocks.AIR) return@safeListener addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount).also { - executeOnSuccess = { - with(owner) { success() } - } - } + PickUpDrops(drop, minAmount = minCollectAmount) ) } } } + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PickUpDrops) return + + success() + } + private fun SafeClientEvent.playSound() { if (playSound) { val soundType = initState.block.getSoundType(initState, world, blockPos, player) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index a52fee92d..307a808f2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,8 +1,11 @@ package com.lambda.client.activity.activities.interaction +import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.toVec3dCenter @@ -10,6 +13,7 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock +import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos @@ -18,7 +22,8 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( private val containerPos: BlockPos, override var rotation: Vec2f = Vec2f.ZERO, -) : RotatingActivity, Activity() { + override val timeout: Long = 3000L, +) : RotatingActivity, TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() @@ -36,14 +41,22 @@ class OpenContainer( // safeListener { // when (it.packet) { // is SPacketWindowItems -> { -// onSuccess() +// success() +// LambdaMod.LOG.info(it.packet.itemStacks.size) +// it.packet.itemStacks.forEach { stack -> +// LambdaMod.LOG.info(stack.displayName) +// } +// LambdaMod.LOG.info(player.openContainer.inventorySlots.size) +// player.openContainer.inventorySlots.forEach { slot -> +// LambdaMod.LOG.info(slot.stack.displayName) +// } // } // } // } safeListener { if (it.phase == TickEvent.Phase.END) { - if (player.openContainer.windowId != 0) { + if (player.openContainer.inventorySlots.size == 63) { success() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 5abe8b632..9a2e74d78 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,9 +1,7 @@ package com.lambda.client.activity.activities.interaction -import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item import net.minecraft.block.state.IBlockState @@ -17,8 +15,8 @@ class PlaceBlock( private val getInReach: Boolean = true, ) : Activity() { override fun SafeClientEvent.onInitialize() { - if (swapToItem) addSubActivities(SwapOrMoveToItem(targetState.block.item)) - if (getInReach) addSubActivities(CustomGoal(GoalNear(blockPos, 4))) + if (swapToItem) addSubActivities(AcquireItemInActiveHand(targetState.block.item)) +// if (getInReach) addSubActivities(CustomGoal(GoalNear(blockPos, 4))) addSubActivities(PlaceBlockRaw(blockPos, targetState, playSound)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt index 5538b219e..c186d5f40 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt @@ -2,13 +2,14 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RenderBlockActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.blockBlacklist +import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener @@ -19,24 +20,27 @@ import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import java.lang.Exception class PlaceBlockRaw( private val blockPos: BlockPos, - private val targetState: IBlockState, + private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks private val playSound: Boolean = true, override var rotation: Vec2f = Vec2f.ZERO, override val timeout: Long = 1000L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, - override var renderBlockPos: BlockPos = blockPos, - override var color: ColorHolder = ColorHolder(0, 0, 0) -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderBlockActivity, Activity() { + override var renderAABB: AxisAlignedBB = AxisAlignedBB(blockPos), + override var color: ColorHolder = ColorHolder(35, 188, 254) +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { override fun SafeClientEvent.onInitialize() { getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { val placedAtBlock = world.getBlockState(it.pos).block + renderAABB = targetState.getSelectedBoundingBox(world, blockPos) + if (placedAtBlock in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } @@ -72,7 +76,6 @@ class PlaceBlockRaw( // activityStatus = ActivityStatus.PENDING } ?: run { failedWith(NoNeighbourException(blockPos)) - color = ColorHolder(16, 74, 94) } } @@ -80,10 +83,10 @@ class PlaceBlockRaw( safeListener { if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos - && it.packet.blockState.block == targetState.block + && it.packet.blockState.block == targetState.block // TODO: Calculate correct resulting state of placed block to enable rotation checks ) success() } } - class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for $blockPos found") + class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt similarity index 80% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 801ce09ab..cb49b52e8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrMoveToItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -5,12 +5,12 @@ import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots -import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.inventory.EntityEquipmentSlot import net.minecraft.item.Item import net.minecraft.item.ItemStack import java.lang.Exception -class SwapOrMoveToItem( +class AcquireItemInActiveHand( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, @@ -37,5 +37,13 @@ class SwapOrMoveToItem( } } + override fun SafeClientEvent.onSuccess() { + val currentItem = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).item + + if (currentItem != item) { + failedWith(Exception("Failed to move item ${item.registryName} to hotbar (current item: ${currentItem.registryName})")) + } + } + class NoItemFoundException(item: Item) : Exception("No ${item.registryName} found in inventory (shulkers are disabled)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index 12542260d..f610bfada 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -47,7 +47,7 @@ class InventoryTransaction( playerController.updateController() - LambdaMod.LOG.info("Sent packet: ${packet.javaClass.simpleName}") +// LambdaMod.LOG.info("Sent packet: ${packet.javaClass.simpleName}") } ?: run { failedWith(ContainerOutdatedException(windowId)) } @@ -70,7 +70,7 @@ class InventoryTransaction( getContainerOrNull(packet.windowId)?.let { container -> container.slotClick(slot, mouseButton, type, player) success() - LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") +// LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") } ?: run { failedWith(ContainerOutdatedException(packet.windowId)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt index b9a4b361d..75cf2246a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt @@ -9,6 +9,29 @@ class QuickMoveSlot( private val slot: Slot ) : Activity() { override fun SafeClientEvent.onInitialize() { - addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 0, ClickType.QUICK_MOVE)) + if (slot.stack.isEmpty) { + success() + } else { + addSubActivities(InventoryTransaction(player.openContainer.windowId, slot.slotNumber, 0, ClickType.QUICK_MOVE)) + } } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is InventoryTransaction) return + + if (slot.stack.isEmpty) { + success() + } else { + failedWith(ExceptionSlotNotEmpty()) + } + } + + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is InventoryTransaction.DeniedException) return false + + failedWith(ExceptionSlotNotEmpty()) + return true + } + + class ExceptionSlotNotEmpty : Exception("Slot not empty") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt index 8de6b5628..e800e3070 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -18,7 +18,8 @@ class SwapOrSwitchToSlot( } ?: run { val hotbarSlots = player.hotbarSlots val slotTo = hotbarSlots.firstEmpty() - ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } ?: return + ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } + ?: return addSubActivities( SwapWithSlot(slot, slotTo), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt index c49347d3b..1796c80e9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt @@ -10,7 +10,7 @@ class TakeOffArmor : Activity() { (player.armorSlots + player.offhandSlot).forEach { slot -> if (slot.stack.isEmpty) return@forEach - addSubActivities(TryClearSlotWithQuickMove(slot)) + addSubActivities(QuickMoveSlot(slot)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt deleted file mode 100644 index 6f0e1355b..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TryClearSlotWithQuickMove.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.lambda.client.activity.activities.inventory - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import net.minecraft.inventory.Slot - -class TryClearSlotWithQuickMove( - private val slot: Slot -) : Activity() { - override fun SafeClientEvent.onInitialize() { - if (slot.stack.isEmpty) { - success() - } else { - addSubActivities( - QuickMoveSlot(slot).also { - executeOnSuccess = { - if (slot.stack.isEmpty) { - success() - } else { - failedWith(ExceptionSlotNotEmpty()) - } - } - } - ) - } - } - - class ExceptionSlotNotEmpty : Exception("Slot is still not empty") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index d259d12b9..1d21bf3e4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -3,15 +3,16 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.block import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack -import net.minecraft.util.math.BlockPos class ExtractItemFromShulkerBox( private val item: Item, @@ -38,24 +39,24 @@ class ExtractItemFromShulkerBox( } candidates.minBy { it.value }.key.let { slot -> - val openContainerInSlot = OpenContainerInSlot(slot) - - with(openContainerInSlot) { - executeOnSuccess = { - with(owner) { - addSubActivities( - PullItemsFromContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true), - SwapOrMoveToItem(item, predicateItem, predicateSlot) - ) - } - } - } - - addSubActivities(openContainerInSlot) + addSubActivities( + SwapOrSwitchToSlot(slot), + PlaceContainer(slot.stack.item.block.defaultState) + ) } } + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PlaceContainer) return + + addSubActivities( + OpenContainer(childActivity.containerPos), + PullItemsFromContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(childActivity.containerPos, collectDrops = true), + AcquireItemInActiveHand(item, predicateItem, predicateSlot) + ) + } + class NoShulkerBoxFoundExtractException(item: Item) : Exception("No shulker box was found containing ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt deleted file mode 100644 index ba0062d88..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenContainerInSlot.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.interaction.PlaceBlockRaw -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.utils.Wait -import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.block -import com.lambda.client.util.text.MessageSendHelper -import net.minecraft.inventory.Slot -import net.minecraft.util.math.BlockPos - -class OpenContainerInSlot( - private val slot: Slot, - override val maxAttempts: Int = 5, - override var usedAttempts: Int = 0 -) : AttemptActivity, Activity() { - var containerPos: BlockPos = BlockPos.ORIGIN - - override fun SafeClientEvent.onInitialize() { - containerPos = getContainerPos() ?: run { - failedWith(NoContainerPlacePositionFoundException()) - return - } - - addSubActivities( - SwapOrSwitchToSlot(slot), - PlaceBlockRaw(containerPos, slot.stack.item.block.defaultState).also { - executeOnFailure = { - if (it is PlaceBlockRaw.NoNeighbourException) { - usedAttempts++ - initialize() - MessageSendHelper.sendErrorMessage("No neighbour found, retrying...") - true - } else false - } - }, - OpenContainer(containerPos) - ) - } - - class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt new file mode 100644 index 000000000..d0f847dff --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -0,0 +1,39 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.PlaceBlockRaw +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt +import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.event.SafeClientEvent +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class PlaceContainer( + private val targetState: IBlockState, + override val maxAttempts: Int = 5, + override var usedAttempts: Int = 0 +) : AttemptActivity, Activity() { + var containerPos: BlockPos = BlockPos.ORIGIN + + override fun SafeClientEvent.onInitialize() { + containerPos = getContainerPos(targetState) ?: run { + failedWith(NoContainerPlacePositionFoundException()) + return + } + + addSubActivities( + PlaceBlockRaw(containerPos, targetState) + ) + } + + override fun SafeClientEvent.onChildFailure(childActivity: ArrayDeque, childException: Exception): Boolean { + if (childActivity.firstOrNull() !is PlaceBlockRaw) return false + if (childException !is PlaceBlockRaw.NoNeighbourException) return false + + checkAttempt(this@PlaceContainer, NoContainerPlacePositionFoundException()) + return true + } + + class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index 6a205837c..e6ce15ffd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -4,8 +4,11 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots +import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.inventory.ContainerShulkerBox import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -13,21 +16,35 @@ class PushItemsToContainer( private val item: Item, private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true }, - override val loopWhile: SafeClientEvent.() -> Boolean = { - player.openContainer.inventorySlots.size == 63 - && player.openContainer.getSlots(27..62).countEmpty() > 0 - }, - override var currentLoops: Int = 0 -) : LoopingUntilActivity, Activity() { +) : Activity() { override fun SafeClientEvent.onInitialize() { val openContainer = player.openContainer if (openContainer.inventorySlots.size != 63) return - openContainer.getSlots(27..62).firstOrNull { slot -> + var candidateSlots = openContainer.getSlots(27..62).filter { slot -> slot.stack.item == item && predicateItem(slot.stack) - }?.let { + } + + if (amount != 0) candidateSlots = candidateSlots.take(amount) + + candidateSlots.forEach { addSubActivities(QuickMoveSlot(it)) } + +// if (subActivities.isEmpty()) { +// failedWith(NoItemFoundPushException(item)) +// } } + + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is QuickMoveSlot.ExceptionSlotNotEmpty) return false + + success() + return true + } + + class NotShulkerBoxException : Exception("No shulker box open") + +// class NoItemFoundPushException(item: Item) : Exception("No item found to push to container: ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index ceab057f3..1fb57ebdf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -3,17 +3,17 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem -import com.lambda.client.activity.activities.utils.getContainerPos +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.block import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack -import net.minecraft.util.math.BlockPos -class StoreItemToShulkerBox( +class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes private val item: Item, private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } @@ -37,23 +37,23 @@ class StoreItemToShulkerBox( } candidates.maxBy { it.value }.key.let { slot -> - val openContainerInSlot = OpenContainerInSlot(slot) - - with(openContainerInSlot) { - executeOnSuccess = { - with(owner) { - addSubActivities( - PushItemsToContainer(item, amount, predicateItem), - CloseContainer(), - BreakBlock(containerPos, collectDrops = true) - ) - } - } - } - - addSubActivities(openContainerInSlot) + addSubActivities( + SwapOrSwitchToSlot(slot), + PlaceContainer(slot.stack.item.block.defaultState) + ) } } + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PlaceContainer) return + + addSubActivities( + OpenContainer(childActivity.containerPos), + PushItemsToContainer(item, amount, predicateItem), + CloseContainer(), + BreakBlock(childActivity.containerPos, collectDrops = true) + ) + } + class NoShulkerBoxFoundStoreException(item: Item) : Exception("No shulker box was found with space to store ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 45209ab60..78580b9c6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -4,13 +4,13 @@ import baritone.api.pathing.goals.GoalBlock import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.inventory.DumpSlot +import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem import net.minecraftforge.fml.common.gameevent.TickEvent -import java.lang.Exception class PickUpEntityItem( private val entityItem: EntityItem, @@ -37,11 +37,16 @@ class PickUpEntityItem( InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) - } ?: run { - failedWith(InventoryFullException()) } } } + override fun SafeClientEvent.onFailure(exception: Exception): Boolean { + if (exception !is TimeoutActivity.Companion.TimeoutException) return false + + onFailure(InventoryFullException()) + return true + } + class InventoryFullException : Exception("No empty slots or items to dump!") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 8fad53723..5e07df3d0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -17,14 +17,14 @@ interface AttemptActivity { with(activity) { if (usedAttempts >= maxAttempts) { failedWith(MaxAttemptsExceededException(usedAttempts, causeException)) - return false } else { usedAttempts++ MessageSendHelper.sendErrorMessage("$name caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") + subActivities.clear() initialize() - return true } } + return true } class MaxAttemptsExceededException(usedAttempts: Int, causeException: Exception) : Exception("Exceeded $usedAttempts attempts caused by ${causeException::class.simpleName}: ${causeException.message}") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt similarity index 54% rename from src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt rename to src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt index 0f201f00f..26aa3c8a4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderBlockActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt @@ -1,9 +1,9 @@ package com.lambda.client.activity.activities.types import com.lambda.client.util.color.ColorHolder -import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.AxisAlignedBB -interface RenderBlockActivity { - var renderBlockPos: BlockPos +interface RenderAABBActivity { + var renderAABB: AxisAlignedBB var color: ColorHolder } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index 820229e6f..ea2c4e312 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.types import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.text.MessageSendHelper @@ -15,11 +16,12 @@ interface TimeoutActivity { if (age <= timeout) return if (activity is AttemptActivity) { - with(activity) { - usedAttempts++ - initialize() - MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") - } + checkAttempt(activity, TimeoutException(age, timeout)) +// with(activity) { +// usedAttempts++ +// initialize() +// MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") +// } } else { failedWith(TimeoutException(age, timeout)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt index ad3c7b4d0..e2ef14534 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt @@ -1,16 +1,19 @@ package com.lambda.client.activity.activities.utils import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.world.getVisibleSides import com.lambda.client.util.world.isPlaceable import com.lambda.client.util.world.isReplaceable +import net.minecraft.block.state.IBlockState import net.minecraft.inventory.ItemStackHelper import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraft.util.NonNullList +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos fun getShulkerInventory(stack: ItemStack): NonNullList? { @@ -28,14 +31,15 @@ fun getShulkerInventory(stack: ItemStack): NonNullList? { return shulkerInventory } -fun SafeClientEvent.getContainerPos(): BlockPos? { +fun SafeClientEvent.getContainerPos(targetState: IBlockState): BlockPos? { return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() .filter { pos -> - world.isPlaceable(pos) +// world.isPlaceable(pos, targetState.getSelectedBoundingBox(world, pos)) // TODO: Calculate correct resulting state of placed block to enable rotation checks + world.isPlaceable(pos, AxisAlignedBB(pos)) && !world.getBlockState(pos.down()).isReplaceable && world.isAirBlock(pos.up()) && getVisibleSides(pos.down()).contains(EnumFacing.UP) - && pos.y >= player.positionVector.y + && pos.y >= player.flooredPosition.y }.sortedWith( compareByDescending { secureScore(it) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index 3bc6002ff..1343c3e8c 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -5,6 +5,7 @@ import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.LabelHud import com.lambda.client.manager.managers.ActivityManager +import org.apache.commons.lang3.time.DurationFormatUtils internal object ActivityManagerHud: LabelHud( name = "ActivityManager", @@ -12,11 +13,22 @@ internal object ActivityManagerHud: LabelHud( description = "Display current activities." ) { val anonymize by setting("Anonymize", false) + private var startTime = 0L override fun SafeClientEvent.updateText() { - if (ActivityManager.noSubActivities()) return + if (ActivityManager.noSubActivities()) { + startTime = 0L + return + } + + if (startTime == 0L) startTime = System.currentTimeMillis() - displayText.addLine("Current Activities ${ActivityManager.getAllSubActivities().size}") + displayText.add("Runtime:", primaryColor) + displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), secondaryColor) + displayText.add("Amount:", primaryColor) + displayText.add(ActivityManager.getAllSubActivities().size.toString(), secondaryColor) + displayText.add("Current:", primaryColor) + displayText.addLine(ActivityManager.currentActivity.name, secondaryColor) ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 795d01697..97eef83fc 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,7 +1,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RenderBlockActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent @@ -35,12 +35,15 @@ object ActivityManager : Manager, Activity() { safeListener { val currentActivity = currentActivity - if (currentActivity !is RenderBlockActivity) return@safeListener + if (currentActivity !is RenderAABBActivity) return@safeListener renderer.aFilled = 26 renderer.aOutline = 91 renderer.thickness = 2.0f - renderer.add(currentActivity.renderBlockPos, currentActivity.color) + renderer.add( + currentActivity.renderAABB, + currentActivity.color + ) renderer.render(true) } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/combat/AutoTrap.kt b/src/main/kotlin/com/lambda/client/module/modules/combat/AutoTrap.kt index 2cd3c0ffd..ff5fab290 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/combat/AutoTrap.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/combat/AutoTrap.kt @@ -24,6 +24,7 @@ import com.lambda.client.util.world.isPlaceable import kotlinx.coroutines.Job import kotlinx.coroutines.launch import net.minecraft.init.Blocks +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.InputEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -79,7 +80,9 @@ object AutoTrap : Module( private fun SafeClientEvent.canRun(): Boolean { (if (selfTrap.value) player else CombatManager.target)?.positionVector?.toBlockPos()?.let { for (offset in trapMode.offset) { - if (!world.isPlaceable(it.add(offset))) continue + val targetPos = it.add(offset) + + if (!world.isPlaceable(targetPos, AxisAlignedBB(targetPos))) continue return true } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/combat/CrystalBasePlace.kt b/src/main/kotlin/com/lambda/client/module/modules/combat/CrystalBasePlace.kt index fff57a8a1..3c66df1f1 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/combat/CrystalBasePlace.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/combat/CrystalBasePlace.kt @@ -27,6 +27,7 @@ import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.hasNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityEnderCrystal import net.minecraft.init.Blocks import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -149,7 +150,7 @@ object CrystalBasePlace : Module( for (pos in posList) { // Placeable check - if (!world.isPlaceable(pos)) continue + if (!world.isPlaceable(pos, entity.entityBoundingBox)) continue // Neighbour blocks check if (!hasNeighbour(pos)) continue diff --git a/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt b/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt index f8dde7012..53d09df40 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/combat/Surround.kt @@ -162,7 +162,7 @@ object Surround : Module( private fun SafeClientEvent.canRun(): Boolean { val playerPos = player.positionVector.toBlockPos() return SurroundUtils.surroundOffset.any { - world.isPlaceable(playerPos.add(it), true) + world.isPlaceable(playerPos.add(it), Blocks.OBSIDIAN.defaultState.getSelectedBoundingBox(world, playerPos.add(it)), true) } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/AutoObsidian.kt index 54c5bc25f..3b2a36815 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/AutoObsidian.kt @@ -272,7 +272,7 @@ object AutoObsidian : Module( private fun SafeClientEvent.isPositionValid(pos: BlockPos, blockState: IBlockState, eyePos: Vec3d) = !world.getBlockState(pos.down()).isReplaceable && (blockState.block.let { it == Blocks.ENDER_CHEST || it is BlockShulkerBox } - || world.isPlaceable(pos)) + || world.isPlaceable(pos, blockState.getSelectedBoundingBox(world, pos))) && world.isAirBlock(pos.up()) && world.rayTraceBlocks(eyePos, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index a4b97c366..3be6e7e1f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -8,9 +8,8 @@ import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory -import com.lambda.client.activity.activities.inventory.SwapOrMoveToItem +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox -import com.lambda.client.activity.activities.storage.PushItemsToContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.manager.managers.ActivityManager @@ -24,7 +23,6 @@ import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item import com.lambda.client.util.math.Direction -import com.lambda.client.util.math.RotationUtils import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockShulkerBox @@ -42,7 +40,7 @@ object TestActivityManager : Module( ) { private val a by setting("Get any Dia Pickaxe", false, consumer = { _, _-> ActivityManager.addSubActivities( - SwapOrMoveToItem(Items.DIAMOND_PICKAXE) + AcquireItemInActiveHand(Items.DIAMOND_PICKAXE) ) false }) @@ -70,7 +68,7 @@ object TestActivityManager : Module( private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> ActivityManager.addSubActivities( - SwapOrMoveToItem( + AcquireItemInActiveHand( Items.DIAMOND_PICKAXE, predicateItem = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 @@ -114,7 +112,9 @@ object TestActivityManager : Module( private val ctiectiectie by setting("Place break obby", false, consumer = { _, _-> runSafe { - val origin = player.flooredPosition.add(Direction.fromEntity(player).directionVec) +// val origin = player.flooredPosition.add(Direction.fromEntity(player).directionVec) + + val origin = player.flooredPosition ActivityManager.addSubActivities( PlaceBlock(origin, Blocks.OBSIDIAN.defaultState), diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index f444ffd86..2ecd78cb2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,14 +1,15 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.activity.activities.storage.OpenContainerInSlot +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.util.items.block import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockShulkerBox @@ -17,14 +18,13 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.inventory.ClickType import net.minecraft.item.ItemShulkerBox -import net.minecraft.util.math.BlockPos object InventoryManagerTwo : Module( name = "InventoryManagerTwo", description = "Manages your inventory automatically", category = Category.PLAYER ) { - private val placedShulkerBoxes = mutableListOf() + private val placedShulkerBoxes = mutableListOf() init { safeListener { @@ -33,26 +33,27 @@ object InventoryManagerTwo : Module( player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener - getContainerPos()?.let { containerPos -> - placedShulkerBoxes.add(containerPos) - ActivityManager.addSubActivities( - OpenContainerInSlot(slot) - ) - it.cancel() - } + val placeContainer = PlaceContainer(slot.stack.item.block.defaultState) + + placedShulkerBoxes.add(placeContainer) + + ActivityManager.addSubActivities( + SwapOrSwitchToSlot(slot), + placeContainer + ) } } safeListener { if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener - placedShulkerBoxes.firstOrNull()?.let { containerPos -> - placedShulkerBoxes.remove(containerPos) + placedShulkerBoxes.firstOrNull()?.let { placeContainerInSlot -> + placedShulkerBoxes.remove(placeContainerInSlot) - if (world.getBlockState(containerPos).block !is BlockShulkerBox) return@safeListener + if (world.getBlockState(placeContainerInSlot.containerPos).block !is BlockShulkerBox) return@safeListener ActivityManager.addSubActivities( - BreakBlock(containerPos, collectDrops = true) + BreakBlock(placeContainerInSlot.containerPos, collectDrops = true) ) } } diff --git a/src/main/kotlin/com/lambda/client/util/world/Check.kt b/src/main/kotlin/com/lambda/client/util/world/Check.kt index 9e25de3d2..96b5c7d6c 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Check.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Check.kt @@ -3,6 +3,7 @@ package com.lambda.client.util.world import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.Wrapper import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.util.EnumFacing import net.minecraft.util.math.AxisAlignedBB @@ -105,8 +106,6 @@ fun SafeClientEvent.hasNeighbour(pos: BlockPos): Boolean { * * @return true playing is not colliding with [pos] and there is block below it */ -fun World.isPlaceable(pos: BlockPos, ignoreSelfCollide: Boolean = false) = +fun World.isPlaceable(pos: BlockPos, targetBoundingBox: AxisAlignedBB, ignoreSelfCollide: Boolean = false) = this.getBlockState(pos).isReplaceable - && checkNoEntityCollision(AxisAlignedBB(pos), if (ignoreSelfCollide) Wrapper.player else null) - && worldBorder.contains(pos) - && !isOutsideBuildHeight(pos) \ No newline at end of file + && this.checkNoEntityCollision(targetBoundingBox, if (ignoreSelfCollide) Wrapper.player else null) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/world/Interact.kt b/src/main/kotlin/com/lambda/client/util/world/Interact.kt index 1b09e15ed..c5d7ad657 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Interact.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Interact.kt @@ -13,6 +13,7 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import java.util.* @@ -91,7 +92,10 @@ private fun SafeClientEvent.getNeighbour( } } - if (attempts < 2) return null + if (attempts > 1) { + for (side in sides) { + val newPos = pos.offset(side) + if (!world.isPlaceable(newPos, AxisAlignedBB(newPos))) continue sides.forEach { posSide -> val newPos = pos.offset(posSide) @@ -126,7 +130,7 @@ private fun SafeClientEvent.checkNeighbour( if (dist > range) return null if (visibleSideCheck && !getVisibleSides(offsetPos, true).contains(oppositeSide)) return null if (checkReplaceable && world.getBlockState(offsetPos).isReplaceable) return null - if (!world.isPlaceable(pos)) return null + if (!world.isPlaceable(pos, AxisAlignedBB(pos))) return null val hitVecOffset = getHitVecOffset(oppositeSide) return PlaceInfo(offsetPos, oppositeSide, dist, hitVecOffset, hitVec, pos) @@ -241,7 +245,7 @@ private fun SafeClientEvent.getStructurePlaceInfo( for (offset in structureOffset) { val pos = center.add(offset) if (toIgnore.contains(pos)) continue - if (!world.isPlaceable(pos)) continue + if (!world.isPlaceable(pos, AxisAlignedBB(pos))) continue return getNeighbour(pos, attempts, range, visibleSideCheck) ?: continue } @@ -277,7 +281,7 @@ fun SafeClientEvent.placeBlock( placeInfo: PlaceInfo, hand: EnumHand = EnumHand.MAIN_HAND ) { - if (!world.isPlaceable(placeInfo.placedPos)) return + if (!world.isPlaceable(placeInfo.placedPos, AxisAlignedBB(placeInfo.placedPos))) return connection.sendPacket(placeInfo.toPlacePacket(hand)) player.swingArm(hand) From 4c91c2720db6a3266ceb6ec71f3378628f40cbd1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 3 Jan 2023 11:23:42 +0100 Subject: [PATCH 041/104] Fix the InventoryManagerTwo sketch --- .../activities/storage/OpenShulkerFromSlot.kt | 34 +++++++++++++++++++ .../modules/player/InventoryManagerTwo.kt | 28 +++++++-------- 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt new file mode 100644 index 000000000..1178e146a --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt @@ -0,0 +1,34 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.block +import net.minecraft.inventory.Slot +import net.minecraft.util.math.BlockPos + +class OpenShulkerFromSlot( + private val slot: Slot +) : Activity() { + var containerPos: BlockPos = BlockPos.ORIGIN + + override fun SafeClientEvent.onInitialize() { + val targetState = slot.stack.item.block.defaultState + + addSubActivities( + SwapOrSwitchToSlot(slot), + PlaceContainer(targetState) + ) + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PlaceContainer) return + + containerPos = childActivity.containerPos + + addSubActivities( + OpenContainer(containerPos) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 2ecd78cb2..b3d032d8f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,17 +1,16 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.storage.PlaceContainer +import com.lambda.client.activity.activities.storage.OpenShulkerFromSlot import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module -import com.lambda.client.util.items.block import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener +import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockShulkerBox import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiShulkerBox @@ -24,7 +23,7 @@ object InventoryManagerTwo : Module( description = "Manages your inventory automatically", category = Category.PLAYER ) { - private val placedShulkerBoxes = mutableListOf() + private val placedShulkerBoxes = mutableListOf() init { safeListener { @@ -33,27 +32,28 @@ object InventoryManagerTwo : Module( player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener - val placeContainer = PlaceContainer(slot.stack.item.block.defaultState) + val openShulkerFromSlot = OpenShulkerFromSlot(slot) - placedShulkerBoxes.add(placeContainer) + placedShulkerBoxes.add(openShulkerFromSlot) - ActivityManager.addSubActivities( - SwapOrSwitchToSlot(slot), - placeContainer - ) + ActivityManager.addSubActivities(openShulkerFromSlot) + + it.cancel() } } safeListener { if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener - placedShulkerBoxes.firstOrNull()?.let { placeContainerInSlot -> - placedShulkerBoxes.remove(placeContainerInSlot) + placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> + placedShulkerBoxes.remove(openShulkerFromSlot) + + val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block - if (world.getBlockState(placeContainerInSlot.containerPos).block !is BlockShulkerBox) return@safeListener + if (!(currentBlock is BlockShulkerBox || currentBlock !is BlockEnderChest)) return@safeListener ActivityManager.addSubActivities( - BreakBlock(placeContainerInSlot.containerPos, collectDrops = true) + BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) ) } } From 3d357b403b485bae7cd31672b70b48bec6ac7588 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 08:27:02 +0100 Subject: [PATCH 042/104] Macro and micro management --- .../com/lambda/client/activity/Activity.kt | 46 ++-- .../highlevel/BreakDownEnderChests.kt | 13 +- .../activities/highlevel/BuildBlock.kt | 23 +- .../activities/highlevel/BuildHighway.kt | 37 --- .../activities/highlevel/BuildStructure.kt | 45 +++- .../activities/highlevel/ReachXPLevel.kt | 4 +- .../highlevel/SurroundWithObsidian.kt | 4 +- .../activities/interaction/BreakBlock.kt | 124 ++++++++++- .../activities/interaction/BreakBlockRaw.kt | 155 ------------- .../interaction/BreakBlockWithTool.kt | 20 ++ .../activities/interaction/OpenContainer.kt | 10 +- .../activities/interaction/PlaceBlock.kt | 106 ++++++++- .../activities/interaction/PlaceBlockRaw.kt | 92 -------- .../interaction/PlaceBlockWithItem.kt | 20 ++ .../storage/ExtractItemFromShulkerBox.kt | 19 +- .../activities/storage/PlaceContainer.kt | 8 +- .../storage/PushItemsToContainer.kt | 5 - .../storage/StoreItemToShulkerBox.kt | 10 +- .../activity/activities/travel/BreakGoal.kt | 48 ++++ .../activity/activities/travel/PlaceGoal.kt | 60 +++++ .../activities/types/AttemptActivity.kt | 3 +- .../activities/types/ConcurrentActivity.kt | 31 +++ .../activities/types/EndlessActivity.kt | 3 + ...gUntilActivity.kt => LoopWhileActivity.kt} | 7 +- .../activities/types/LoopingAmountActivity.kt | 27 --- .../activities/types/RenderAABBActivity.kt | 62 +++++- .../activities/types/RepeatingActivity.kt | 23 ++ .../activities/utils/VoxelShapeUtils.kt | 2 + .../manager/managers/ActivityManager.kt | 73 +++--- .../lambda/client/module/AbstractModule.kt | 1 + .../module/modules/client/BuildTools.kt | 145 ++++++++++++ .../module/modules/misc/HighwayTools.kt | 210 ++++++++++++++++++ .../modules/misc/TestActivityManager.kt | 23 +- .../modules/player/InventoryManagerTwo.kt | 68 +++++- .../client/util/graphics/ESPRenderer.kt | 6 + 35 files changed, 1078 insertions(+), 455 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt rename src/main/kotlin/com/lambda/client/activity/activities/types/{LoopingUntilActivity.kt => LoopWhileActivity.kt} (74%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt create mode 100644 src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index dbc58d330..569b94804 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -3,15 +3,19 @@ package com.lambda.client.activity import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed -import com.lambda.client.activity.activities.types.LoopingAmountActivity.Companion.checkLoopingAmount -import com.lambda.client.activity.activities.types.LoopingUntilActivity.Companion.checkLoopingUntil +import com.lambda.client.activity.activities.types.EndlessActivity +import com.lambda.client.activity.activities.types.LoopWhileActivity.Companion.checkLoopingUntil +import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.activities.types.RepeatingActivity.Companion.checkRepeat import com.lambda.client.activity.activities.types.RotatingActivity.Companion.checkRotating import com.lambda.client.activity.activities.types.TimeoutActivity.Companion.checkTimeout +import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.misc.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH +import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper @@ -22,7 +26,6 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils -import java.util.* import java.util.concurrent.ConcurrentLinkedDeque import kotlin.collections.ArrayDeque @@ -34,7 +37,8 @@ abstract class Activity { var depth = 0 val name get() = this::class.simpleName ?: "Activity" val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L - val currentActivity: Activity get() = subActivities.peek()?.currentActivity ?: this + val currentActivity: Activity get() = subActivities.firstOrNull { it.activityStatus != ActivityStatus.PENDING } + ?.currentActivity ?: subActivities.firstOrNull()?.currentActivity ?: this open fun SafeClientEvent.onInitialize() {} @@ -60,15 +64,13 @@ abstract class Activity { ActivityStatus.UNINITIALIZED -> { initialize() } - ActivityStatus.RUNNING -> { + ActivityStatus.PENDING, ActivityStatus.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) && noSubActivities() + && this@Activity !is EndlessActivity && this@Activity !is DelayedActivity ) success() } - ActivityStatus.PENDING -> { -// refresh() - } ActivityStatus.FAILURE -> { // } @@ -79,6 +81,7 @@ abstract class Activity { checkTimeout(activity) checkDelayed(activity) checkRotating(activity) + checkRender() } fun SafeClientEvent.initialize() { @@ -88,6 +91,8 @@ abstract class Activity { creationTime = System.currentTimeMillis() onInitialize() + LambdaEventBus.subscribe(activity) + // with(owner) { // onChildInitialize(activity) // } @@ -100,15 +105,20 @@ abstract class Activity { fun SafeClientEvent.success() { val activity = this@Activity + LambdaEventBus.unsubscribe(activity) + ListenerManager.unregister(activity) + with(owner) { onChildSuccess(activity) subActivities.remove(activity) } onSuccess() - checkLoopingAmount(activity) + checkRepeat(activity) checkLoopingUntil(activity) + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") // MessageSendHelper.sendRawChatMessage("$name took ${age}ms") } @@ -143,12 +153,6 @@ abstract class Activity { return false } - fun refresh() { - activityStatus = ActivityStatus.UNINITIALIZED - owner.subActivities.remove(this) - owner.subActivities.add(this) - } - fun Activity.addSubActivities(activities: List) { if (activities.isEmpty()) return @@ -214,12 +218,12 @@ abstract class Activity { val name = field.name val value = field.get(this) - if (index.mod(6) == 0) { - textComponent.addLine("", primaryColor) - repeat(depth) { - textComponent.add(" ") - } - } +// if (index.mod(6) == 0) { +// textComponent.addLine("", primaryColor) +// repeat(depth) { +// textComponent.add(" ") +// } +// } value?.let { if (!ActivityManagerHud.anonymize diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index eace40239..6115f73f4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -1,8 +1,8 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopingAmountActivity -import com.lambda.client.activity.activities.interaction.BreakBlockRaw +import com.lambda.client.activity.activities.types.RepeatingActivity +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox @@ -16,9 +16,9 @@ import net.minecraft.init.Enchantments import net.minecraft.init.Items class BreakDownEnderChests( - override val maxLoops: Int = 0, - override var currentLoops: Int = 0 -) : LoopingAmountActivity, Activity() { + override val maximumRepeats: Int = 0, + override var repeated: Int = 0 +) : RepeatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { if (player.inventorySlots.countEmpty() < 2) { addSubActivities( @@ -28,7 +28,6 @@ class BreakDownEnderChests( } addSubActivities( - AcquireItemInActiveHand(Blocks.ENDER_CHEST.item), PlaceContainer(Blocks.ENDER_CHEST.defaultState) ) } @@ -43,7 +42,7 @@ class BreakDownEnderChests( EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 } ), - BreakBlockRaw( + BreakBlock( childActivity.containerPos, collectDrops = true, minCollectAmount = 64 diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index b9b86315b..5eb91a87d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -3,7 +3,14 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.travel.BreakGoal +import com.lambda.client.activity.activities.travel.PlaceGoal +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.item import com.lambda.client.util.world.isReplaceable import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks @@ -12,32 +19,30 @@ import net.minecraft.util.math.BlockPos class BuildBlock( private val blockPos: BlockPos, private val targetState: IBlockState, -) : Activity() { + override val maxAttempts: Int = 3, + override var usedAttempts: Int = 0 +) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { val currentState = world.getBlockState(blockPos) when { /* is in desired state */ - currentState == targetState -> success() - /* is blocked by entity */ - !world.checkNoEntityCollision(currentState.getSelectedBoundingBox(world, blockPos), null) -> { - failedWith(EntityCollisionException()) - } + currentState.block == targetState.block -> success() /* block needs to be placed */ targetState.block != Blocks.AIR && currentState.isReplaceable -> { addSubActivities( - PlaceBlock(blockPos, targetState) + PlaceBlock(blockPos, targetState, doPending = true) ) } /* only option left is breaking the block */ else -> { addSubActivities( + SwapToBestTool(blockPos), + BreakGoal(blockPos), BreakBlock(blockPos), PlaceBlock(blockPos, targetState) ) } } } - - class EntityCollisionException : Exception("Entity collision while placing block") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt deleted file mode 100644 index 82f7f6ffb..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildHighway.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.lambda.client.activity.activities.highlevel - -import baritone.api.pathing.goals.GoalBlock -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopingAmountActivity -import com.lambda.client.activity.activities.travel.CustomGoal -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.math.Direction -import com.lambda.client.util.math.VectorUtils.multiply -import net.minecraft.block.Block -import net.minecraft.util.math.BlockPos - -class BuildHighway( - private val origin: BlockPos, - private val direction: Direction, - private val material: Block, - override val maxLoops: Int = 100, - override var currentLoops: Int = 0 -) : LoopingAmountActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - val currentPos = origin.add(direction.directionVec.multiply(currentLoops + 1)) - -// VectorUtils.getBlockPosInSphere(player.getPositionEyes(1f), 5.0f).forEach { -// if (it != origin.down()) addSubActivities( -// BuildBlock(it, Blocks.AIR.defaultState) -// ) -// } - - addSubActivities( - BuildBlock(currentPos.add(direction.clockwise(1).directionVec), material.defaultState), - BuildBlock(currentPos.add(direction.counterClockwise(1).directionVec), material.defaultState), - BuildBlock(currentPos.add(direction.clockwise(1).directionVec).up(), material.defaultState), - BuildBlock(currentPos.add(direction.counterClockwise(1).directionVec).up(), material.defaultState), - CustomGoal(GoalBlock(currentPos.add(direction.directionVec))) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 04d39ef42..951634eb2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,18 +1,55 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.RenderAABBActivity +import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.math.VectorUtils.multiply import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos class BuildStructure( - private val structure: Map -) : Activity() { + private val structure: Map, + private val direction: Direction = Direction.NORTH, + private val offsetMove: BlockPos = BlockPos.ORIGIN, + override val toRender: MutableSet = mutableSetOf(), + override val maximumRepeats: Int = 1, + override var repeated: Int = 0, +) : RepeatingActivity, RenderAABBActivity, Activity() { + private var currentOffset = BlockPos.ORIGIN + override fun SafeClientEvent.onInitialize() { - structure.forEach { (pos, state) -> + toRender.clear() + structure.asSequence().sortedBy { player.distanceTo(it.key) }.forEach { (pos, state) -> + val offsetPos = pos.add(currentOffset) + + if (isInPadding(offsetPos)) return@forEach + + if (state.block != Blocks.AIR) toRender.add( + RenderAABBActivity.Companion.RenderBlockPos(offsetPos, ColorHolder(255, 255, 255, 50)) + ) + addSubActivities( - BuildBlock(pos, state) + BuildBlock(offsetPos, state) ) } } + + override fun SafeClientEvent.onSuccess() { + currentOffset = currentOffset.add(offsetMove) + } + + private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) + + private fun isBehindPos(origin: BlockPos, check: BlockPos): Boolean { + val a = origin.add(direction.counterClockwise(2).directionVec.multiply(100)) + val b = origin.add(direction.clockwise(2).directionVec.multiply(100)) + + return ((b.x - a.x) * (check.z - a.z) - (b.z - a.z) * (check.x - a.x)) > 0 + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index 4fc5d15bd..a186c6f89 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopingUntilActivity +import com.lambda.client.activity.activities.types.LoopWhileActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor @@ -14,7 +14,7 @@ class ReachXPLevel( player.experienceLevel < desiredLevel }, override var currentLoops: Int = 0 -) : LoopingUntilActivity, Activity() { +) : LoopWhileActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index 1b31b1d77..39909fae1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopingUntilActivity +import com.lambda.client.activity.activities.types.LoopWhileActivity import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition @@ -14,7 +14,7 @@ class SurroundWithObsidian( originPos == player.flooredPosition }, override var currentLoops: Int = 0 -) : LoopingUntilActivity, Activity() { +) : LoopWhileActivity, Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( BuildBlock(originPos.north(), Blocks.SLIME_BLOCK.defaultState), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 7726c7b37..fafa0d105 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,21 +1,131 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.block +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getHitVec +import com.lambda.client.util.world.getMiningSide +import net.minecraft.block.material.Material +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.Item +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.* +import kotlin.Exception +import kotlin.math.ceil class BreakBlock( private val blockPos: BlockPos, - private val playSound: Boolean = true, - private val useBestTool: Boolean = true, private val miningSpeedFactor: Float = 1.0f, private val collectDrops: Boolean = false, - private val minCollectAmount: Int = 1 -) : Activity() { + private val minCollectAmount: Int = 1, + override var timeout: Long = 200L, + override val maxAttempts: Int = 8, + override var usedAttempts: Int = 0, + override val toRender: MutableSet = mutableSetOf(), + override var rotation: Vec2f = Vec2f.ZERO +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, Activity() { + private var ticksNeeded = 0 + private var initState = Blocks.AIR.defaultState + private var drop: Item = Items.AIR + + private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, + ColorHolder(222, 0, 0) + ).also { toRender.add(it) } + override fun SafeClientEvent.onInitialize() { - if (useBestTool) addSubActivities(SwapToBestTool(blockPos)) + val currentState = world.getBlockState(blockPos) + + if (currentState.material == Material.AIR) { + success() + return + } + + initState = currentState + drop = currentState.block.getItemDropped(currentState, Random(), 0) + + renderActivity.color = ColorHolder(240, 222, 60) + + ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() + timeout = ticksNeeded * 50L + 2000L + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + getMiningSide(blockPos)?.let { side -> + rotation = getRotationTo(getHitVec(blockPos, side)) + + playerController.onPlayerDamageBlock(blockPos, side) + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) - addSubActivities(BreakBlockRaw(blockPos, playSound, miningSpeedFactor, collectDrops, minCollectAmount)) +// if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { +// playerController.onPlayerDestroyBlock(blockPos) +// player.swingArm(EnumHand.MAIN_HAND) +// } else { +// playerController.onPlayerDamageBlock(blockPos, side) +// player.swingArm(EnumHand.MAIN_HAND) +// // cancel onPlayerDestroy NoGhostBlocks +// +//// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { +//// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) +//// player.swingArm(EnumHand.MAIN_HAND) +//// } else { +//// player.swingArm(EnumHand.MAIN_HAND) +//// } +// } + } ?: run { + failedWith(ExceptionNoSurfaceExposed()) + } + } + + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == Blocks.AIR + ) { + if (!collectDrops) { + success() + return@safeListener + } + + renderActivity.color = ColorHolder(252, 3, 207) + + if (drop.block == Blocks.AIR) return@safeListener + + addSubActivities( + PickUpDrops(drop, minAmount = minCollectAmount) + ) + } + } + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PickUpDrops) return + + success() } + + override fun SafeClientEvent.onFailure(exception: Exception): Boolean { + playerController.resetBlockRemoving() + return false + } + + class ExceptionNoSurfaceExposed : Exception("No block surface exposed to player") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt deleted file mode 100644 index d8036aa09..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockRaw.kt +++ /dev/null @@ -1,155 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RotatingActivity -import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.block -import com.lambda.client.util.math.RotationUtils.getRotationTo -import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getHitVec -import com.lambda.client.util.world.getMiningSide -import net.minecraft.block.material.Material -import net.minecraft.init.Blocks -import net.minecraft.init.Items -import net.minecraft.item.Item -import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.util.EnumHand -import net.minecraft.util.SoundCategory -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent -import java.util.* -import kotlin.Exception -import kotlin.math.ceil - -class BreakBlockRaw( - private val blockPos: BlockPos, - private val playSound: Boolean = true, - private val miningSpeedFactor: Float = 1.0f, - private val collectDrops: Boolean = false, - private val minCollectAmount: Int = 1, - override var timeout: Long = 200L, - override val maxAttempts: Int = 8, - override var usedAttempts: Int = 0, - override var renderAABB: AxisAlignedBB = AxisAlignedBB(blockPos), - override var color: ColorHolder = ColorHolder(240, 222, 60), - override var rotation: Vec2f = Vec2f.ZERO -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, Activity() { - private var ticksNeeded = 0 - private var initState = Blocks.AIR.defaultState - private var drop: Item = Items.AIR - - override fun SafeClientEvent.onInitialize() { - val currentState = world.getBlockState(blockPos) - - if (currentState.material == Material.AIR) { - success() - return - } - - initState = currentState - drop = currentState.block.getItemDropped(currentState, Random(), 0) - renderAABB = currentState.getSelectedBoundingBox(world, blockPos) - ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 2000L - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - getMiningSide(blockPos)?.let { side -> - rotation = getRotationTo(getHitVec(blockPos, side)) - renderAABB = world.getBlockState(blockPos).getSelectedBoundingBox(world, blockPos) - - playerController.onPlayerDamageBlock(blockPos, side) - mc.effectRenderer.addBlockHitEffects(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) - -// if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { -// playerController.onPlayerDestroyBlock(blockPos) -// player.swingArm(EnumHand.MAIN_HAND) -// } else { -// playerController.onPlayerDamageBlock(blockPos, side) -// player.swingArm(EnumHand.MAIN_HAND) -// // cancel onPlayerDestroy NoGhostBlocks -// -//// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { -//// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) -//// player.swingArm(EnumHand.MAIN_HAND) -//// } else { -//// player.swingArm(EnumHand.MAIN_HAND) -//// } -// } - } ?: run { - failedWith(ExceptionNoSurfaceExposed()) - } - } - - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && it.packet.blockState.block == Blocks.AIR - ) { - if (!collectDrops) { - success() - return@safeListener - } - - color = ColorHolder(252, 3, 207) - - if (drop.block == Blocks.AIR) return@safeListener - - addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount) - ) - } - } - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is PickUpDrops) return - - success() - } - - private fun SafeClientEvent.playSound() { - if (playSound) { - val soundType = initState.block.getSoundType(initState, world, blockPos, player) - world.playSound( - player, - blockPos, - soundType.breakSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) - } - - if (playSound) { - val soundType = initState.block.getSoundType(initState, world, blockPos, player) - world.playSound( - player, - blockPos, - soundType.hitSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) - } - } - - override fun SafeClientEvent.onFailure(exception: Exception): Boolean { - playerController.resetBlockRemoving() - return false - } - - class ExceptionNoSurfaceExposed : Exception("No block surface exposed to player") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt new file mode 100644 index 000000000..6194ae2dc --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt @@ -0,0 +1,20 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.event.SafeClientEvent +import net.minecraft.util.math.BlockPos + +class BreakBlockWithTool( + private val blockPos: BlockPos, + private val miningSpeedFactor: Float = 1.0f, + private val collectDrops: Boolean = false, + private val minCollectAmount: Int = 1 +) : Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities( + SwapToBestTool(blockPos), + BreakBlock(blockPos, miningSpeedFactor, collectDrops, minCollectAmount) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 307a808f2..27bbb5411 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -1,11 +1,10 @@ package com.lambda.client.activity.activities.interaction -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.toVec3dCenter @@ -13,7 +12,6 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock -import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos @@ -22,8 +20,10 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( private val containerPos: BlockPos, override var rotation: Vec2f = Vec2f.ZERO, - override val timeout: Long = 3000L, -) : RotatingActivity, TimeoutActivity, Activity() { + override val timeout: Long = 1000L, + override val maxAttempts: Int = 3, + override var usedAttempts: Int = 0, +) : RotatingActivity, TimeoutActivity, AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 9a2e74d78..41fdc5894 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -2,21 +2,111 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.travel.PlaceGoal +import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity +import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.block +import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.items.item +import com.lambda.client.util.math.CoordinateConverter.asString +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getNeighbour +import com.lambda.client.util.world.toPlacePacket import net.minecraft.block.state.IBlockState +import net.minecraft.inventory.EntityEquipmentSlot +import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import java.lang.Exception class PlaceBlock( private val blockPos: BlockPos, - private val targetState: IBlockState, - private val playSound: Boolean = true, - private val swapToItem: Boolean = true, - private val getInReach: Boolean = true, -) : Activity() { + private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks + private val doPending: Boolean = false, + override var rotation: Vec2f = Vec2f.ZERO, + override val timeout: Long = 200L, + override val maxAttempts: Int = 8, + override var usedAttempts: Int = 0, + override val toRender: MutableSet = mutableSetOf() +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { + private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, + ColorHolder(35, 188, 254) + ).also { toRender.add(it) } + override fun SafeClientEvent.onInitialize() { - if (swapToItem) addSubActivities(AcquireItemInActiveHand(targetState.block.item)) -// if (getInReach) addSubActivities(CustomGoal(GoalNear(blockPos, 4))) - addSubActivities(PlaceBlockRaw(blockPos, targetState, playSound)) + if (world.getBlockState(blockPos).block == targetState.block) { + success() + return + } + + if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).item.block != targetState.block) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item)) + return + } + + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.95f)?.let { + val placedAtBlock = world.getBlockState(it.pos).block + + renderActivity.color = ColorHolder(11, 66, 89) + + if (placedAtBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + + rotation = getRotationTo(it.hitVec) + +// connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) + playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) + player.swingArm(EnumHand.MAIN_HAND) + + if (placedAtBlock in blockBlacklist) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + + if (doPending) { + addSubActivities(Wait(45L)) + } + } ?: run { + addSubActivities(PlaceGoal(blockPos)) +// failedWith(NoNeighbourException(blockPos)) + } + } + + init { + safeListener { + if (it.packet is SPacketBlockChange + && it.packet.blockPosition == blockPos + && it.packet.blockState.block == targetState.block // TODO: Calculate correct resulting state of placed block to enable rotation checks + ) { + if (doPending) { + with(owner) { + success() + } + } + + success() + } + } } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + when (childActivity) { + is Wait -> if (doPending) owner.activityStatus = ActivityStatus.PENDING + else -> { +// activityStatus = ActivityStatus.UNINITIALIZED + } + } + } + + class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt deleted file mode 100644 index c186d5f40..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockRaw.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.activity.activities.types.RotatingActivity -import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.blockBlacklist -import com.lambda.client.util.math.CoordinateConverter.asString -import com.lambda.client.util.math.RotationUtils.getRotationTo -import com.lambda.client.util.math.Vec2f -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.toPlacePacket -import net.minecraft.block.state.IBlockState -import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.util.EnumHand -import net.minecraft.util.SoundCategory -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import java.lang.Exception - -class PlaceBlockRaw( - private val blockPos: BlockPos, - private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks - private val playSound: Boolean = true, - override var rotation: Vec2f = Vec2f.ZERO, - override val timeout: Long = 1000L, - override val maxAttempts: Int = 8, - override var usedAttempts: Int = 0, - override var renderAABB: AxisAlignedBB = AxisAlignedBB(blockPos), - override var color: ColorHolder = ColorHolder(35, 188, 254) -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true)?.let { - val placedAtBlock = world.getBlockState(it.pos).block - - renderAABB = targetState.getSelectedBoundingBox(world, blockPos) - - if (placedAtBlock in blockBlacklist) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) - } - - rotation = getRotationTo(it.hitVec) - - connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) - player.swingArm(EnumHand.MAIN_HAND) - - if (placedAtBlock in blockBlacklist) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) - } - - if (playSound) { - val thisState = world.getBlockState(blockPos) - - val soundType = thisState.block.getSoundType( - thisState, - world, - blockPos, - player - ) - world.playSound( - player, - blockPos, - soundType.placeSound, - SoundCategory.BLOCKS, - (soundType.getVolume() + 1.0f) / 2.0f, - soundType.getPitch() * 0.8f - ) - } - -// activityStatus = ActivityStatus.PENDING - } ?: run { - failedWith(NoNeighbourException(blockPos)) - } - } - - init { - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && it.packet.blockState.block == targetState.block // TODO: Calculate correct resulting state of placed block to enable rotation checks - ) success() - } - } - - class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt new file mode 100644 index 000000000..bd0b6670b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt @@ -0,0 +1,20 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.item +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class PlaceBlockWithItem( + private val blockPos: BlockPos, + private val targetState: IBlockState +) : Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities( + AcquireItemInActiveHand(targetState.block.item), + PlaceBlock(blockPos, targetState) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 1d21bf3e4..2a69deaf6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,7 +1,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests +import com.lambda.client.activity.activities.interaction.BreakBlockWithTool import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand @@ -10,6 +11,8 @@ import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block +import com.lambda.client.util.items.item +import net.minecraft.init.Blocks import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -34,7 +37,17 @@ class ExtractItemFromShulkerBox( } if (candidates.isEmpty()) { - failedWith(NoShulkerBoxFoundExtractException(item)) + if (item != Blocks.OBSIDIAN.item) { + failedWith(NoShulkerBoxFoundExtractException(item)) + return + } + + if (owner is BreakDownEnderChests) return + + addSubActivities( + BreakDownEnderChests(maximumRepeats = 64), + AcquireItemInActiveHand(Blocks.OBSIDIAN.item) + ) return } @@ -53,7 +66,7 @@ class ExtractItemFromShulkerBox( OpenContainer(childActivity.containerPos), PullItemsFromContainer(item, amount, predicateItem), CloseContainer(), - BreakBlock(childActivity.containerPos, collectDrops = true), + BreakBlockWithTool(childActivity.containerPos, collectDrops = true), AcquireItemInActiveHand(item, predicateItem, predicateSlot) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index d0f847dff..032936c28 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.PlaceBlockRaw +import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.utils.getContainerPos @@ -23,13 +23,13 @@ class PlaceContainer( } addSubActivities( - PlaceBlockRaw(containerPos, targetState) + PlaceBlock(containerPos, targetState) ) } override fun SafeClientEvent.onChildFailure(childActivity: ArrayDeque, childException: Exception): Boolean { - if (childActivity.firstOrNull() !is PlaceBlockRaw) return false - if (childException !is PlaceBlockRaw.NoNeighbourException) return false + if (childActivity.firstOrNull() !is PlaceBlock) return false + if (childException !is PlaceBlock.NoNeighbourException) return false checkAttempt(this@PlaceContainer, NoContainerPlacePositionFoundException()) return true diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt index e6ce15ffd..b9590360c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt @@ -2,13 +2,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot -import com.lambda.client.activity.activities.types.LoopingUntilActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots -import com.lambda.client.util.text.MessageSendHelper -import net.minecraft.inventory.ContainerShulkerBox import net.minecraft.item.Item import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 1fb57ebdf..8e615c46f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.BreakBlockWithTool import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot @@ -9,6 +9,7 @@ import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block +import com.lambda.client.util.items.countItem import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -21,6 +22,11 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes override fun SafeClientEvent.onInitialize() { val candidates = mutableMapOf() + if (player.allSlots.countItem(item) == 0) { + success() + return + } + player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> if (inventory.all { (it.item == item && predicateItem(it)) || it.isEmpty }) { @@ -51,7 +57,7 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes OpenContainer(childActivity.containerPos), PushItemsToContainer(item, amount, predicateItem), CloseContainer(), - BreakBlock(childActivity.containerPos, collectDrops = true) + BreakBlockWithTool(childActivity.containerPos, collectDrops = true) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt new file mode 100644 index 000000000..ae7311c49 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt @@ -0,0 +1,48 @@ +package com.lambda.client.activity.activities.travel + +import baritone.api.pathing.goals.GoalBlock +import baritone.api.pathing.goals.GoalInverted +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.threads.safeListener +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent + +class BreakGoal( + private val blockPos: BlockPos, + override val timeout: Long = 60000L +) : TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + if (isInBlockAABB(blockPos) + && GoalNear(blockPos, 3).isInGoal(player.flooredPosition)) success() + } + + init { + safeListener { event -> + if (event.phase != TickEvent.Phase.START) return@safeListener + + if (isInBlockAABB(blockPos.up())) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalInverted(GoalBlock(blockPos.up()))) + return@safeListener + } + + val nearGoal = GoalNear(blockPos, 3) + + if (!nearGoal.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(nearGoal) + return@safeListener + } + + success() + } + } + + private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos): Boolean { + return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt new file mode 100644 index 000000000..c1624ba96 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -0,0 +1,60 @@ +package com.lambda.client.activity.activities.travel + +import baritone.api.pathing.goals.GoalBlock +import baritone.api.pathing.goals.GoalInverted +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getNeighbour +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent + +class PlaceGoal( + private val blockPos: BlockPos, + override val timeout: Long = 60000L +) : TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + if (!isInBlockAABB(blockPos) && GoalNear(blockPos, 4).isInGoal(player.flooredPosition)) success() + } + + init { + safeListener { event -> + if (event.phase != TickEvent.Phase.START) return@safeListener + + if (isInBlockAABB(blockPos)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalInverted(GoalBlock(blockPos))) + return@safeListener + } + + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.95f)?.let { + success() + } ?: run { + getNeighbour(blockPos, attempts = 1, range = 4.95f)?.let { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 2)) + } ?: run { + val nearGoal = GoalNear(blockPos, 3) + + if (!nearGoal.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(nearGoal) + return@safeListener + } + +// activityStatus = ActivityStatus.PENDING + +// failedWith(NoPathToPlaceFound()) + } + } + } + } + + private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos): Boolean { + return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) + } + + class NoPathToPlaceFound : Exception("No path to place position found") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 5e07df3d0..76863383e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -11,8 +11,7 @@ interface AttemptActivity { companion object { fun SafeClientEvent.checkAttempt(activity: Activity, causeException: Exception): Boolean { if (activity !is AttemptActivity) return false - if (causeException is MaxAttemptsExceededException - || causeException is TimeoutActivity.Companion.TimeoutException) return false + if (causeException is MaxAttemptsExceededException) return false with(activity) { if (usedAttempts >= maxAttempts) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt new file mode 100644 index 000000000..5c79a98b2 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt @@ -0,0 +1,31 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent + +interface ConcurrentActivity { + val maxInstancesPerTick: Int + var currentInstances: Int + val root: Activity + + companion object { + fun SafeClientEvent.doConcurrent(activity: Activity): Boolean { + if (activity !is ConcurrentActivity) return false + + with(activity) { + if (currentInstances >= maxInstancesPerTick) return false + currentInstances++ +// root.refresh(activity.owner.owner) + root.addSubActivities(activity) + } + return true + } + + fun SafeClientEvent.checkConcurrent(activity: Activity): Boolean { + if (activity !is ConcurrentActivity) return false + + activity.currentInstances = 0 + return true + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt new file mode 100644 index 000000000..eb5495828 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt @@ -0,0 +1,3 @@ +package com.lambda.client.activity.activities.types + +interface EndlessActivity \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt similarity index 74% rename from src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt rename to src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt index d69df91e1..6fd477821 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingUntilActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt @@ -1,16 +1,15 @@ package com.lambda.client.activity.activities.types -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -interface LoopingUntilActivity { +interface LoopWhileActivity { val loopWhile: SafeClientEvent.() -> Boolean var currentLoops: Int companion object { fun SafeClientEvent.checkLoopingUntil(activity: Activity) { - if (activity !is LoopingUntilActivity) return + if (activity !is LoopWhileActivity) return with(activity) { if (!loopWhile()) return @@ -18,7 +17,7 @@ interface LoopingUntilActivity { currentLoops++ activityStatus = Activity.ActivityStatus.UNINITIALIZED owner.subActivities.add(activity) - LambdaMod.LOG.info("Looping $name ($currentLoops)") +// LambdaMod.LOG.info("Looping $name ($currentLoops)") } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt deleted file mode 100644 index 8613960ce..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopingAmountActivity.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.lambda.client.activity.activities.types - -import com.lambda.client.LambdaMod -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.activityStatus -import com.lambda.client.manager.managers.ActivityManager.name -import com.lambda.client.manager.managers.ActivityManager.owner - -interface LoopingAmountActivity { - val maxLoops: Int - var currentLoops: Int - - companion object { - fun checkLoopingAmount(activity: Activity) { - if (activity !is LoopingAmountActivity) return - - with(activity) { - if (currentLoops++ >= maxLoops && maxLoops != 0) return - - activityStatus = Activity.ActivityStatus.UNINITIALIZED - owner.subActivities.add(activity) - LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt index 26aa3c8a4..9bae2ccbe 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt @@ -1,9 +1,67 @@ package com.lambda.client.activity.activities.types +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.util.EntityUtils import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.LambdaTessellator +import net.minecraft.entity.Entity import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos interface RenderAABBActivity { - var renderAABB: AxisAlignedBB - var color: ColorHolder + val toRender: MutableSet + + companion object { + val normalizedRender: MutableSet = mutableSetOf() + + fun SafeClientEvent.checkRender() { + normalizedRender.clear() + + ActivityManager.getAllSubActivities() + .filterIsInstance() + .forEach { activity -> + activity.toRender.forEach { compound -> + when (compound) { + is RenderAABB -> normalizedRender.add(compound) + is RenderBlockPos -> { + with(compound) { + normalizedRender.add(toRenderAABB()) + } + } + is RenderEntity -> { + with(compound) { + normalizedRender.add(toRenderAABB()) + } + } + } + } + } + } + + interface RenderAABBCompound + + data class RenderAABB( + var renderAABB: AxisAlignedBB, + var color: ColorHolder + ) : RenderAABBCompound + + data class RenderBlockPos( + var renderBlockPos: BlockPos, + var color: ColorHolder + ) : RenderAABBCompound { + fun SafeClientEvent.toRenderAABB() = + RenderAABB(world.getBlockState(renderBlockPos).getSelectedBoundingBox(world, renderBlockPos), color) + } + + data class RenderEntity( + var renderEntity: Entity, + var color: ColorHolder + ) : RenderAABBCompound { + fun toRenderAABB() = + RenderAABB(renderEntity.renderBoundingBox.offset( + EntityUtils.getInterpolatedAmount(renderEntity, LambdaTessellator.pTicks()) + ), color) + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt new file mode 100644 index 000000000..2a0fbe5b4 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt @@ -0,0 +1,23 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent + +interface RepeatingActivity { + val maximumRepeats: Int + var repeated: Int + + companion object { + fun SafeClientEvent.checkRepeat(activity: Activity) { + if (activity !is RepeatingActivity) return + + with(activity) { + if (repeated++ >= maximumRepeats && maximumRepeats != 0) return + + activityStatus = Activity.ActivityStatus.UNINITIALIZED + owner.subActivities.add(activity) +// LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt new file mode 100644 index 000000000..f33b95ead --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt @@ -0,0 +1,2 @@ +package com.lambda.client.activity.activities.utils + diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 97eef83fc..4319a239e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -3,10 +3,14 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.LambdaEventBus +import com.lambda.client.event.LambdaEventBus.subscribedListeners +import com.lambda.client.event.LambdaEventBus.subscribedListenersAsync import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager +import com.lambda.client.manager.managers.ActivityManager.updateTypesOnTick +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener @@ -23,27 +27,34 @@ object ActivityManager : Manager, Activity() { val currentActivity = currentActivity + getAllSubActivities().filter { it.activityStatus == ActivityStatus.RUNNING + || it.activityStatus == ActivityStatus.PENDING }.forEach { + with(it) { + updateTypesOnTick(it) + } + } + with(currentActivity) { - if (activityStatus == ActivityStatus.RUNNING) updateTypesOnTick(currentActivity) + if (activityStatus == ActivityStatus.RUNNING + || activityStatus == ActivityStatus.PENDING) updateTypesOnTick(currentActivity) } - repeat(10) { + repeat(100) { updateCurrentActivity() } } safeListener { - val currentActivity = currentActivity + if (noSubActivities()) return@safeListener + + renderer.aFilled = BuildTools.aFilled + renderer.aOutline = BuildTools.aOutline + renderer.thickness = BuildTools.thickness - if (currentActivity !is RenderAABBActivity) return@safeListener + RenderAABBActivity.normalizedRender.forEach { renderAABB -> + renderer.add(renderAABB.renderAABB, renderAABB.color) + } - renderer.aFilled = 26 - renderer.aOutline = 91 - renderer.thickness = 2.0f - renderer.add( - currentActivity.renderAABB, - currentActivity.color - ) renderer.render(true) } } @@ -52,28 +63,38 @@ object ActivityManager : Manager, Activity() { val currentActivity = currentActivity with(currentActivity) { - if (currentActivity != lastActivity) { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { - if (lastActivity !is ActivityManager) { - LambdaEventBus.unsubscribe(lastActivity) - ListenerManager.unregister(lastActivity) - } - - LambdaEventBus.subscribe(currentActivity) - BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + BaritoneUtils.settings?.allowPlace?.value = false + BaritoneUtils.settings?.allowBreak?.value = false + BaritoneUtils.settings?.allowInventory?.value = false - lastActivity = currentActivity - } +// if (currentActivity != lastActivity) { +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { +//// if (lastActivity !is ActivityManager) { +// LambdaEventBus.unsubscribe(lastActivity) +// ListenerManager.unregister(lastActivity) +// } +// +// LambdaEventBus.subscribe(currentActivity) +// BaritoneUtils.primary?.pathingBehavior?.cancelEverything() +// +// lastActivity = currentActivity +// } updateActivity() } } fun reset() { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { - if (lastActivity !is ActivityManager) { - LambdaEventBus.unsubscribe(lastActivity) - ListenerManager.unregister(lastActivity) +// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) + ListenerManager.listenerMap.keys.filterIsInstance().forEach { + if (it is ActivityManager) return@forEach + LambdaEventBus.unsubscribe(it) + ListenerManager.unregister(it) + } + ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { + if (it is ActivityManager) return@forEach + LambdaEventBus.unsubscribe(it) + ListenerManager.unregister(it) } BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index 98801b158..6270d42d8 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -1,5 +1,6 @@ package com.lambda.client.module +import com.lambda.client.activity.Activity import com.lambda.client.commons.interfaces.Alias import com.lambda.client.commons.interfaces.Nameable import com.lambda.client.event.LambdaEventBus diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt new file mode 100644 index 000000000..7f4adad7d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -0,0 +1,145 @@ +package com.lambda.client.module.modules.client + +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.setting.settings.impl.collection.CollectionSetting +import com.lambda.client.util.Bind +import com.lambda.client.util.items.shulkerList +import net.minecraft.block.Block +import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.Item + +object BuildTools : Module( + name = "BuildTools", + description = "Settings for internal build engine", + category = Category.CLIENT, + showOnArray = false, + alwaysEnabled = true +) { + private val page by setting("Page", Page.BEHAVIOR, description = "Switch between setting pages") + + /* behavior */ + val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") + val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") + val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") + val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") + val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag", unit = " ticks") +// private val clearQueue by setting("Clear build queue", false, { page == Page.BEHAVIOR }, consumer = { _, it -> +// if (it) BuildToolsManager.resetAll() +// false +// }) + + /* mining */ + val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.MINING }, description = "Sets the delay ticks between break tasks", unit = " ticks") + val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.MINING }, description = "Factor to manipulate calculated mining speed") + val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") + val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") + val packetFlood by setting("Packet Flood", false, { page == Page.MINING }, description = "Exploit for faster packet breaks. Sends START and STOP packet on same tick") + + /* placing */ + val placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.PLACING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") + val illegalPlacements by setting("Illegal Placements", false, { page == Page.PLACING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") + val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") + val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") + + /* storage management */ + val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") + val searchEChest by setting("Search Ender Chest", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Allow access to your ender chest") + val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers") + val grindObsidian by setting("Grind Obsidian", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Destroy Ender Chests to obtain Obsidian") + val pickupRadius by setting("Pickup radius", 8, 1..50, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the radius for pickup", unit = " blocks") + val fastFill by setting("Fast Fill", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Moves as many item stacks to inventory as possible") + val keepFreeSlots by setting("Free Slots", 1, 0..30, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many inventory slots are untouched on refill", unit = " slots") + val lockSlotHotkey by setting("Lock Slot Hotkey", Bind(), { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the hotkey for locking a slot") + val manageFood by setting("Manage Food", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") + val manageTools by setting("Manage Tools", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") + val leastTools by setting("Least Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT && manageTools && storageManagement }, description = "How many tools are saved") + val leastEnder by setting("Least Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many ender chests are saved") + val leastFood by setting("Least Food", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && manageFood && storageManagement }, description = "How many food items are saved") + val preferEnderChests by setting("Prefer Ender Chests", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Prevent using raw material shulkers") + + /* render */ + val info by setting("Show Info", true, { page == Page.RENDER }, description = "Prints session stats in chat") + val goalRender by setting("Baritone Goal", false, { page == Page.RENDER }, description = "Renders the baritone goal") + val showCurrentPos by setting("Current Pos", false, { page == Page.RENDER }, description = "Renders the current position") + val filled by setting("Filled", true, { page == Page.RENDER }, description = "Renders colored task surfaces") + val outline by setting("Outline", true, { page == Page.RENDER }, description = "Renders colored task outlines") + val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") + val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") + val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") + val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") + val distScaleFactor by setting("Distance Scale Factor", 0.05f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) + val minDistScale by setting("Min Distance Scale", 0.35f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) + val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.RENDER }, description = "Sets the opacity") + val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.RENDER }, description = "Sets the opacity") + val thickness by setting("Thickness", 2.0f, 0.25f..4.0f, 0.25f, { outline && page == Page.RENDER }, description = "Sets thickness of outline") + + /* misc */ + val disableWarnings by setting("Disable Warnings", false, { page == Page.MISC }, description = "DANGEROUS: Disable warnings on enable") + val debugLevel by setting("Debug Level", DebugLevel.IMPORTANT, { page == Page.MISC }, description = "Sets the debug log depth level") + val fakeSounds by setting("Fake Sounds", true, { page == Page.MISC }, description = "Adds artificial sounds to the actions") + val anonymizeLog by setting("Anonymize", false, { page == Page.MISC }, description = "Censors all coordinates in HUD and Chat") + val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.MISC }, description = "Choose action when bot is out of materials or tools") + val usingProxy by setting("Proxy", false, { page == Page.MISC && disableMode == DisableMode.LOGOUT }, description = "Enable this if you are using a proxy to call the given command") + val proxyCommand by setting("Proxy Command", "/dc", { page == Page.MISC && disableMode == DisableMode.LOGOUT && usingProxy }, description = "Command to be sent to log out") + + private enum class Page { + BEHAVIOR, MINING, PLACING, STORAGE_MANAGEMENT, RENDER, MISC + } + + enum class DebugLevel { + OFF, IMPORTANT, VERBOSE + } + + enum class DisableMode { + NONE, ANTI_AFK, LOGOUT + } + + var defaultFillerMat: Block + get() = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK + set(value) { + fillerMatSaved.value = value.registryName.toString() + } + + var defaultTool: Item + get() = Item.getByNameOrId(tool.value) ?: Items.GOLDEN_APPLE + set(value) { + tool.value = value.registryName.toString() + } + + var defaultFood: Item + get() = Item.getByNameOrId(food.value) ?: Items.GOLDEN_APPLE + set(value) { + food.value = value.registryName.toString() + } + + private val defaultIgnoreBlocks = linkedSetOf( + "minecraft:standing_sign", + "minecraft:wall_sign", + "minecraft:standing_banner", + "minecraft:wall_banner", + "minecraft:bedrock", + "minecraft:end_portal", + "minecraft:end_portal_frame", + "minecraft:portal", + "minecraft:piston_extension", + "minecraft:barrier" + ).also { defaultIgnoreBlocks -> defaultIgnoreBlocks.addAll(shulkerList.map { it.localizedName }) } + + private val defaultEjectList = linkedSetOf( + "minecraft:grass", + "minecraft:dirt", + "minecraft:netherrack", + "minecraft:stone", + "minecraft:cobblestone" + ) + + val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) + val fillerMaterials = setting(CollectionSetting("Eject List", defaultEjectList)) + private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) + private val food = setting("FoodItem", "minecraft:golden_apple", { false }) + private val tool = setting("ToolItem", "minecraft:diamond_pickaxe", { false }) + +// override fun isActive() = BuildToolsManager.isActive() +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt new file mode 100644 index 000000000..a0136b663 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -0,0 +1,210 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.activity.activities.highlevel.BuildStructure +import com.lambda.client.commons.extension.floorToInt +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.module.modules.client.BuildTools.defaultFillerMat +import com.lambda.client.module.modules.client.BuildTools.maxReach +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.threads.runSafe +import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks +import net.minecraft.util.math.BlockPos + +object HighwayTools : Module( + name = "HighwayTools", + description = "Be the grief a step a head.", + category = Category.MISC, + alias = arrayOf("HT", "HWT") +) { + private val structure by setting("Structure", Structure.HIGHWAY, description = "Choose the structure") + private val width by setting("Width", 6, 1..50, 1, description = "Sets the width of blueprint", unit = " blocks") + private val height by setting("Height", 4, 2..10, 1, { clearSpace }, description = "Sets height of blueprint", unit = " blocks") + private val backfill by setting("Backfill", false, { structure == Structure.TUNNEL }, description = "Fills the tunnel behind you") + private val clearSpace by setting("Clear Space", true, { structure == Structure.HIGHWAY }, description = "Clears out the tunnel if necessary") + private val cleanFloor by setting("Clean Floor", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") + private val cleanRightWall by setting("Clean Right Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the right wall") + private val cleanLeftWall by setting("Clean Left Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the left wall") + private val cleanRoof by setting("Clean Roof", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") + private val cleanCorner by setting("Clean Corner", false, { structure == Structure.TUNNEL && !cornerBlock && !backfill && width > 2 }, description = "Cleans up the tunnels corner") + private val cornerBlock by setting("Corner Block", false, { structure == Structure.HIGHWAY || (structure == Structure.TUNNEL && !backfill && width > 2) }, description = "If activated will break the corner in tunnel or place a corner while paving") + private val railing by setting("Railing", true, { structure == Structure.HIGHWAY }, description = "Adds a railing/rim/border to the highway") + private val railingHeight by setting("Railing Height", 1, 1..4, 1, { structure == Structure.HIGHWAY && railing }, description = "Sets height of railing", unit = " blocks") + + enum class Structure { + HIGHWAY, TUNNEL + } + + private var originDirection = Direction.NORTH + private var originOrthogonalDirection = Direction.NORTH + private var originPosition = BlockPos.ORIGIN + var distance = 0 // 0 means infinite + + private var ownedBuildStructure: BuildStructure? = null + + private var material: Block + get() = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN + set(value) { + materialSaved.value = value.registryName.toString() + } + + init { + onEnable { + runSafe { + originPosition = player.flooredPosition.down() + originDirection = Direction.fromEntity(player) + originOrthogonalDirection = originDirection.clockwise(if (originDirection.isDiagonal) 1 else 2) + + printEnable() + + BuildStructure( + generateHighway(), + direction = originDirection, + offsetMove = BlockPos(originDirection.directionVec), + maximumRepeats = 0 + ).let { + ownedBuildStructure = it + ActivityManager.addSubActivities(it) + } + } + } + + onDisable { + runSafe { + ownedBuildStructure?.let { + with(it) { + success() + } + } + } + } + } + + private fun generateHighway(): HashMap { + val blueprint = hashMapOf() + + for (x in -maxReach.floorToInt() * 5..maxReach.floorToInt() * 5) { + val thisPos = originPosition.add(originDirection.directionVec.multiply(x)) + if (clearSpace) generateClear(blueprint, thisPos) + if (structure == Structure.TUNNEL) { + if (cleanFloor) generateFloor(blueprint, thisPos) + if (cleanRightWall || cleanLeftWall) generateWalls(blueprint, thisPos) + if (cleanRoof) generateRoof(blueprint, thisPos) + if (cleanCorner && !cornerBlock && width > 2) generateCorner(blueprint, thisPos) + } else { + generateBase(blueprint, thisPos) + } + } + + if (structure == Structure.TUNNEL && (!cleanFloor || backfill)) { + if (originDirection.isDiagonal) { + for (x in 0..maxReach.floorToInt()) { + val pos = originPosition.add(originDirection.directionVec.multiply(x)) + blueprint[pos] = fillerState() + blueprint[pos.add(originDirection.clockwise(7).directionVec)] = fillerState() + } + } else { + for (x in 0..maxReach.floorToInt()) { + blueprint[originPosition.add(originDirection.directionVec.multiply(x))] = fillerState() + } + } + } + + return blueprint + } + + private fun generateClear(blueprint: HashMap, basePos: BlockPos) { + for (w in 0 until width) { + for (h in 0 until height) { + val x = w - width / 2 + val pos = basePos.add(originOrthogonalDirection.directionVec.multiply(x)).up(h) + + if (structure == Structure.HIGHWAY && h == 0 && isRail(w)) { + continue + } + + if (structure == Structure.HIGHWAY) { + blueprint[pos] = Blocks.AIR.defaultState + } else { + if (!(isRail(w) && h == 0 && !cornerBlock && width > 2)) blueprint[pos.up()] = Blocks.AIR.defaultState + } + } + } + } + + private fun generateBase(blueprint: HashMap, basePos: BlockPos) { + for (w in 0 until width) { + val x = w - width / 2 + val pos = basePos.add(originOrthogonalDirection.directionVec.multiply(x)) + + if (structure == Structure.HIGHWAY && isRail(w)) { + if (!cornerBlock && width > 2 && originDirection.isDiagonal) blueprint[pos] = fillerState() // support block + val startHeight = if (cornerBlock && width > 2) 0 else 1 + for (y in startHeight..railingHeight) { + blueprint[pos.up(y)] = material.defaultState + } + } else { + blueprint[pos] = material.defaultState + } + } + } + + private fun generateFloor(blueprint: HashMap, basePos: BlockPos) { + val wid = if (cornerBlock && width > 2) { + width + } else { + width - 2 + } + for (w in 0 until wid) { + val x = w - wid / 2 + val pos = basePos.add(originOrthogonalDirection.directionVec.multiply(x)) + blueprint[pos] = fillerState() + } + } + + private fun generateWalls(blueprint: HashMap, basePos: BlockPos) { + val cb = if (!cornerBlock && width > 2) { + 1 + } else { + 0 + } + for (h in cb until height) { + if (cleanRightWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(width - width / 2)).up(h + 1)] = fillerState() + if (cleanLeftWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(-1 - width / 2)).up(h + 1)] = fillerState() + } + } + + private fun generateRoof(blueprint: HashMap, basePos: BlockPos) { + for (w in 0 until width) { + val x = w - width / 2 + val pos = basePos.add(originOrthogonalDirection.directionVec.multiply(x)) + blueprint[pos.up(height + 1)] = fillerState() + } + } + + private fun generateCorner(blueprint: HashMap, basePos: BlockPos) { + blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(-1 - width / 2 + 1)).up()] = fillerState() + blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(width - width / 2 - 1)).up()] = fillerState() + } + + private fun isRail(w: Int) = railing && w !in 1 until width - 1 + + private fun SafeClientEvent.printEnable() { + + } + + fun printSettings() { + + } + + private fun fillerState() = defaultFillerMat.defaultState + + private val materialSaved = setting("Material", "minecraft:obsidian", { false }) +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 3be6e7e1f..c584ca504 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,8 +4,8 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.* -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.interaction.BreakBlockWithTool +import com.lambda.client.activity.activities.interaction.PlaceBlockWithItem import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand @@ -22,7 +22,6 @@ import com.lambda.client.util.items.block import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item -import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockShulkerBox @@ -117,8 +116,8 @@ object TestActivityManager : Module( val origin = player.flooredPosition ActivityManager.addSubActivities( - PlaceBlock(origin, Blocks.OBSIDIAN.defaultState), - BreakBlock(origin) + PlaceBlockWithItem(origin, Blocks.OBSIDIAN.defaultState), + BreakBlockWithTool(origin) ) } false @@ -172,20 +171,6 @@ object TestActivityManager : Module( false }) - private val cnrsgt by setting("Build", false, consumer = { _, _-> - runSafe { - ActivityManager.addSubActivities( - BuildHighway( - player.flooredPosition, - Direction.fromEntity(player), - Blocks.OBSIDIAN - ) - ) - } - - false - }) - val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> ActivityManager.addSubActivities(ReachXPLevel(30)) false diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index b3d032d8f..41687ded0 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,8 +1,7 @@ package com.lambda.client.module.modules.player -import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.BreakBlockWithTool import com.lambda.client.activity.activities.storage.OpenShulkerFromSlot -import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities @@ -12,18 +11,17 @@ import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockShulkerBox -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.inventory.ClickType import net.minecraft.item.ItemShulkerBox +import net.minecraftforge.fml.common.gameevent.TickEvent object InventoryManagerTwo : Module( name = "InventoryManagerTwo", description = "Manages your inventory automatically", category = Category.PLAYER ) { - private val placedShulkerBoxes = mutableListOf() + private val placedShulkerBoxes = ArrayDeque(mutableListOf()) init { safeListener { @@ -39,23 +37,69 @@ object InventoryManagerTwo : Module( ActivityManager.addSubActivities(openShulkerFromSlot) it.cancel() + +// val cloned = ArrayDeque(placedShulkerBoxes) +// +// cloned.forEachIndexed { index, openShulker -> +// if (index == 0) return@forEachIndexed +// placedShulkerBoxes.remove(openShulker) +// +// val currentBlock = world.getBlockState(openShulker.containerPos).block +// +// if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@forEachIndexed +// +// ActivityManager.addSubActivities( +// BreakBlock(openShulker.containerPos, collectDrops = true) +// ) +// } + +// if (placedShulkerBoxes.size > 1) { +// val previous = placedShulkerBoxes.removeFirst() +// +// val currentBlock = world.getBlockState(previous.containerPos).block +// +// if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener +// +// ActivityManager.addSubActivities( +// BreakBlock(previous.containerPos, collectDrops = true) +// ) +// } } } - safeListener { - if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener + safeListener { + if (placedShulkerBoxes.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener - placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> - placedShulkerBoxes.remove(openShulkerFromSlot) + val cloned = ArrayDeque(placedShulkerBoxes) - val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block + cloned.forEachIndexed { index, openShulker -> + if (index == 0) return@forEachIndexed + placedShulkerBoxes.remove(openShulker) - if (!(currentBlock is BlockShulkerBox || currentBlock !is BlockEnderChest)) return@safeListener + val currentBlock = world.getBlockState(openShulker.containerPos).block + + if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@forEachIndexed ActivityManager.addSubActivities( - BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) + BreakBlockWithTool(openShulker.containerPos, collectDrops = true) ) } } + +// safeListener { +// if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener +// +// placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> +// placedShulkerBoxes.remove(openShulkerFromSlot) +// +// val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block +// +// if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener +// +// ActivityManager.addSubActivities( +// BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) +// ) +// } +// } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/graphics/ESPRenderer.kt b/src/main/kotlin/com/lambda/client/util/graphics/ESPRenderer.kt index 78a9e767a..c4545ce79 100644 --- a/src/main/kotlin/com/lambda/client/util/graphics/ESPRenderer.kt +++ b/src/main/kotlin/com/lambda/client/util/graphics/ESPRenderer.kt @@ -4,6 +4,8 @@ import com.lambda.client.util.EntityUtils import com.lambda.client.util.EntityUtils.getInterpolatedAmount import com.lambda.client.util.Wrapper import com.lambda.client.util.color.ColorHolder +import net.minecraft.block.state.IBlockState +import net.minecraft.client.multiplayer.WorldClient import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.culling.Frustum import net.minecraft.client.renderer.culling.ICamera @@ -50,6 +52,10 @@ class ESPRenderer { add(AxisAlignedBB(pos), color, sides) } + fun add(pos: BlockPos, state: IBlockState, world: WorldClient, color: ColorHolder, sides: Int) { + add(state.getSelectedBoundingBox(world, pos), color, sides) + } + fun add(box: AxisAlignedBB, color: ColorHolder) { add(box, color, GeometryMasks.Quad.ALL) } From afc3ac7cadfcd0509fa5421f083ff525a813b394 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 09:49:11 +0100 Subject: [PATCH 043/104] Module is now Activity --- .../com/lambda/client/activity/Activity.kt | 47 ++++++++++--------- .../activities/highlevel/BuildBlock.kt | 37 ++++++++++++--- .../activities/highlevel/BuildStructure.kt | 8 ++-- .../activities/interaction/PlaceBlock.kt | 19 ++++---- .../inventory/AcquireItemInActiveHand.kt | 3 +- .../storage/ExtractItemFromShulkerBox.kt | 12 ++--- .../activities/types/AttemptActivity.kt | 2 +- .../activities/types/RenderAABBActivity.kt | 3 +- .../elements/misc/ActivityManagerHud.kt | 6 +-- .../manager/managers/ActivityManager.kt | 25 +++++----- .../lambda/client/module/AbstractModule.kt | 2 +- 11 files changed, 97 insertions(+), 67 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 569b94804..153f055d8 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -29,16 +29,12 @@ import org.apache.commons.lang3.time.DurationFormatUtils import java.util.concurrent.ConcurrentLinkedDeque import kotlin.collections.ArrayDeque -abstract class Activity { +abstract class Activity(private val isRoot: Boolean = false) { val subActivities = ConcurrentLinkedDeque() var activityStatus = ActivityStatus.UNINITIALIZED private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 - val name get() = this::class.simpleName ?: "Activity" - val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L - val currentActivity: Activity get() = subActivities.firstOrNull { it.activityStatus != ActivityStatus.PENDING } - ?.currentActivity ?: subActivities.firstOrNull()?.currentActivity ?: this open fun SafeClientEvent.onInitialize() {} @@ -59,6 +55,27 @@ abstract class Activity { secondaryColor: ColorHolder ) {} + val activityName get() = this::class.simpleName ?: "Activity" + + val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L + + val currentActivity: Activity get() = + subActivities.firstOrNull { it.activityStatus != ActivityStatus.PENDING }?.currentActivity + ?: subActivities.firstOrNull()?.currentActivity + ?: this + + val allSubActivities: List get() = run { + val activities = mutableListOf() + + if (!isRoot) activities.add(this) + + activities.addAll(subActivities.flatMap { it.allSubActivities }) + + activities + } + + val hasNoSubActivities get() = subActivities.isEmpty() + fun SafeClientEvent.updateActivity() { when (activityStatus) { ActivityStatus.UNINITIALIZED -> { @@ -66,7 +83,7 @@ abstract class Activity { } ActivityStatus.PENDING, ActivityStatus.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) - && noSubActivities() + && hasNoSubActivities && this@Activity !is EndlessActivity && this@Activity !is DelayedActivity ) success() @@ -133,7 +150,7 @@ abstract class Activity { if (checkAttempt(activity, exception)) return if (onFailure(exception)) return - MessageSendHelper.sendErrorMessage("Exception in $name: ${exception.message}") + MessageSendHelper.sendErrorMessage("Exception in $activityName: ${exception.message}") ActivityManager.reset() } @@ -142,7 +159,7 @@ abstract class Activity { if (onChildFailure(childActivities, childException)) return true if (onFailure(childException)) return true - MessageSendHelper.sendErrorMessage("${childActivities.joinToString { it.name }}: ${childException.message}") + MessageSendHelper.sendErrorMessage("${childActivities.joinToString { it.activityName }}: ${childException.message}") if (owner == ActivityManager) return false @@ -175,20 +192,6 @@ abstract class Activity { addSubActivities(activities.toList()) } - fun getAllSubActivities(): MutableList { - val activities = mutableListOf() - - if (this !is ActivityManager) { - activities.add(this) - } - - activities.addAll(subActivities.flatMap { it.getAllSubActivities() }) - - return activities - } - - fun noSubActivities() = subActivities.isEmpty() - enum class ActivityStatus { UNINITIALIZED, RUNNING, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 5eb91a87d..351297451 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -3,14 +3,13 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.activity.activities.travel.BreakGoal -import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.item +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.threads.runSafe import com.lambda.client.util.world.isReplaceable import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks @@ -20,8 +19,34 @@ class BuildBlock( private val blockPos: BlockPos, private val targetState: IBlockState, override val maxAttempts: Int = 3, - override var usedAttempts: Int = 0 -) : AttemptActivity, Activity() { + override var usedAttempts: Int = 0, + override val toRender: MutableSet = mutableSetOf() +) : AttemptActivity, RenderAABBActivity, Activity() { + init { + runSafe { + val currentState = world.getBlockState(blockPos) + + when { + /* is in desired state */ + currentState.block == targetState.block -> success() + /* block needs to be placed */ + targetState.block != Blocks.AIR && currentState.isReplaceable -> { + toRender.add(RenderAABBActivity.Companion.RenderBlockPos( + blockPos, + ColorHolder(35, 188, 254) + )) + } + /* only option left is breaking the block */ + else -> { + toRender.add(RenderAABBActivity.Companion.RenderBlockPos( + blockPos, + ColorHolder(222, 0, 0) + )) + } + } + } + } + override fun SafeClientEvent.onInitialize() { val currentState = world.getBlockState(blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 951634eb2..2ede8a201 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,6 +1,8 @@ package com.lambda.client.activity.activities.highlevel +import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent @@ -24,16 +26,12 @@ class BuildStructure( private var currentOffset = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - toRender.clear() +// addSubActivities(CustomGoal(GoalNear())) structure.asSequence().sortedBy { player.distanceTo(it.key) }.forEach { (pos, state) -> val offsetPos = pos.add(currentOffset) if (isInPadding(offsetPos)) return@forEach - if (state.block != Blocks.AIR) toRender.add( - RenderAABBActivity.Companion.RenderBlockPos(offsetPos, ColorHolder(255, 255, 255, 50)) - ) - addSubActivities( BuildBlock(offsetPos, state) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 41fdc5894..9e97b2f48 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -19,21 +19,21 @@ import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.toPlacePacket import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks import net.minecraft.inventory.EntityEquipmentSlot import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import java.lang.Exception class PlaceBlock( private val blockPos: BlockPos, private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks private val doPending: Boolean = false, override var rotation: Vec2f = Vec2f.ZERO, - override val timeout: Long = 200L, + override val timeout: Long = 300L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -49,7 +49,7 @@ class PlaceBlock( return } - if (player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).item.block != targetState.block) { + if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { addSubActivities(AcquireItemInActiveHand(targetState.block.item)) return } @@ -66,16 +66,18 @@ class PlaceBlock( rotation = getRotationTo(it.hitVec) // connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) - playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) + if (playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) != EnumActionResult.SUCCESS) { + failedWith(ProcessRightClickException()) + return + } + player.swingArm(EnumHand.MAIN_HAND) if (placedAtBlock in blockBlacklist) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - if (doPending) { - addSubActivities(Wait(45L)) - } + if (doPending) addSubActivities(Wait(45L)) } ?: run { addSubActivities(PlaceGoal(blockPos)) // failedWith(NoNeighbourException(blockPos)) @@ -109,4 +111,5 @@ class PlaceBlock( } class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") + class ProcessRightClickException : Exception("Processing right click failed") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index cb49b52e8..da8c66429 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -8,6 +8,7 @@ import com.lambda.client.util.items.hotbarSlots import net.minecraft.inventory.EntityEquipmentSlot import net.minecraft.item.Item import net.minecraft.item.ItemStack +import net.minecraft.util.EnumHand import java.lang.Exception class AcquireItemInActiveHand( @@ -38,7 +39,7 @@ class AcquireItemInActiveHand( } override fun SafeClientEvent.onSuccess() { - val currentItem = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND).item + val currentItem = player.getHeldItem(EnumHand.MAIN_HAND).item if (currentItem != item) { failedWith(Exception("Failed to move item ${item.registryName} to hotbar (current item: ${currentItem.registryName})")) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 2a69deaf6..7929acd80 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -42,12 +42,12 @@ class ExtractItemFromShulkerBox( return } - if (owner is BreakDownEnderChests) return - - addSubActivities( - BreakDownEnderChests(maximumRepeats = 64), - AcquireItemInActiveHand(Blocks.OBSIDIAN.item) - ) +// if (owner is BreakDownEnderChests) return +// +// addSubActivities( +// BreakDownEnderChests(maximumRepeats = 64), +// AcquireItemInActiveHand(Blocks.OBSIDIAN.item) +// ) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 76863383e..33d66a1c1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -18,7 +18,7 @@ interface AttemptActivity { failedWith(MaxAttemptsExceededException(usedAttempts, causeException)) } else { usedAttempts++ - MessageSendHelper.sendErrorMessage("$name caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") + MessageSendHelper.sendErrorMessage("$activityName caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") subActivities.clear() initialize() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt index 9bae2ccbe..721e6611c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt @@ -18,7 +18,8 @@ interface RenderAABBActivity { fun SafeClientEvent.checkRender() { normalizedRender.clear() - ActivityManager.getAllSubActivities() + ActivityManager + .allSubActivities .filterIsInstance() .forEach { activity -> activity.toRender.forEach { compound -> diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index 1343c3e8c..b48b77a04 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -16,7 +16,7 @@ internal object ActivityManagerHud: LabelHud( private var startTime = 0L override fun SafeClientEvent.updateText() { - if (ActivityManager.noSubActivities()) { + if (ActivityManager.hasNoSubActivities) { startTime = 0L return } @@ -26,9 +26,9 @@ internal object ActivityManagerHud: LabelHud( displayText.add("Runtime:", primaryColor) displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), secondaryColor) displayText.add("Amount:", primaryColor) - displayText.add(ActivityManager.getAllSubActivities().size.toString(), secondaryColor) + displayText.add(ActivityManager.allSubActivities.size.toString(), secondaryColor) displayText.add("Current:", primaryColor) - displayText.addLine(ActivityManager.currentActivity.name, secondaryColor) + displayText.addLine(ActivityManager.currentActivity.activityName, secondaryColor) ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 4319a239e..c042ba420 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -3,49 +3,48 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.LambdaEventBus -import com.lambda.client.event.LambdaEventBus.subscribedListeners -import com.lambda.client.event.LambdaEventBus.subscribedListenersAsync import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager -import com.lambda.client.manager.managers.ActivityManager.updateTypesOnTick import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent -object ActivityManager : Manager, Activity() { +object ActivityManager : Manager, Activity(true) { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 private var lastActivity: Activity = this init { safeListener { event -> - if (noSubActivities() || event.phase != TickEvent.Phase.START) return@safeListener + if (hasNoSubActivities || event.phase != TickEvent.Phase.START) return@safeListener + + val allActivities = allSubActivities val currentActivity = currentActivity - getAllSubActivities().filter { it.activityStatus == ActivityStatus.RUNNING - || it.activityStatus == ActivityStatus.PENDING }.forEach { - with(it) { - updateTypesOnTick(it) - } - } +// allActivities.filter { it.activityStatus == ActivityStatus.RUNNING +// || it.activityStatus == ActivityStatus.PENDING }.forEach { +// with(it) { +// updateTypesOnTick(it) +// } +// } with(currentActivity) { if (activityStatus == ActivityStatus.RUNNING || activityStatus == ActivityStatus.PENDING) updateTypesOnTick(currentActivity) } - repeat(100) { + repeat(allActivities.size * 2) { updateCurrentActivity() } } safeListener { - if (noSubActivities()) return@safeListener + if (hasNoSubActivities) return@safeListener renderer.aFilled = BuildTools.aFilled renderer.aOutline = BuildTools.aOutline diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index 6270d42d8..3ca15e112 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -29,7 +29,7 @@ abstract class AbstractModule( val alwaysEnabled: Boolean = false, val enabledByDefault: Boolean = false, private val config: NameableConfig -) : Nameable, Alias, SettingRegister by config as NameableConfig { +) : Nameable, Alias, SettingRegister by config as NameableConfig, Activity() { val bind = BindSetting("Bind", Bind(), { !alwaysEnabled }).also(::addSetting) private val enabled = BooleanSetting("Enabled", false, { false }).also(::addSetting) From db873878a7d391f8157e373a64297d5623570ea6 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 09:49:58 +0100 Subject: [PATCH 044/104] Formatting refactor --- .../client/activity/activities/example/ListenAndWait.kt | 1 - .../client/activity/activities/example/ProbablyFailing.kt | 1 - .../activity/activities/highlevel/BreakDownEnderChests.kt | 2 +- .../client/activity/activities/highlevel/BuildStructure.kt | 4 ---- .../client/activity/activities/highlevel/ReachXPLevel.kt | 2 +- .../client/activity/activities/interaction/BreakBlock.kt | 5 ++--- .../client/activity/activities/interaction/PlaceBlock.kt | 2 -- .../activity/activities/inventory/AcquireItemInActiveHand.kt | 2 -- .../activity/activities/inventory/InventoryTransaction.kt | 1 - .../activity/activities/storage/ExtractItemFromShulkerBox.kt | 1 - .../client/activity/activities/travel/PickUpEntityItem.kt | 2 +- .../client/activity/activities/types/RotatingActivity.kt | 1 - .../client/activity/activities/types/TimeoutActivity.kt | 3 +-- 13 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt index 4cf0a3fa8..4359a4e06 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt @@ -8,7 +8,6 @@ import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent -import java.lang.Exception class ListenAndWait( private val message: String, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt index 967f356ae..44bdac2a8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.example import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import java.lang.Exception import kotlin.random.Random class ProbablyFailing : Activity() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 6115f73f4..67c186667 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -1,11 +1,11 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox +import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 2ede8a201..71835cff2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,18 +1,14 @@ package com.lambda.client.activity.activities.highlevel -import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.multiply import net.minecraft.block.state.IBlockState -import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos class BuildStructure( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt index a186c6f89..d46a375d5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt @@ -1,10 +1,10 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopWhileActivity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor +import com.lambda.client.activity.activities.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index fafa0d105..97d277774 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,11 +1,11 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.color.ColorHolder @@ -24,7 +24,6 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* -import kotlin.Exception import kotlin.math.ceil class BreakBlock( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 9e97b2f48..83a4ff1b5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -20,8 +20,6 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import net.minecraft.block.state.IBlockState -import net.minecraft.init.Blocks -import net.minecraft.inventory.EntityEquipmentSlot import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index da8c66429..37fa2f1c1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -5,11 +5,9 @@ import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots -import net.minecraft.inventory.EntityEquipmentSlot import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.util.EnumHand -import java.lang.Exception class AcquireItemInActiveHand( private val item: Item, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index f610bfada..d9f481c39 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -1,6 +1,5 @@ package com.lambda.client.activity.activities.inventory -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.TimeoutActivity diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 7929acd80..e53db4d44 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.interaction.BreakBlockWithTool import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 78580b9c6..05311ff68 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -2,8 +2,8 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.inventory.DumpSlot +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt index 98eb9b5f5..60ec171e5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.types import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.PlayerPacketManager import com.lambda.client.util.math.Vec2f diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index ea2c4e312..3cc5ba4f7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.types import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.text.MessageSendHelper interface TimeoutActivity { val timeout: Long @@ -28,6 +27,6 @@ interface TimeoutActivity { } } - class TimeoutException(age: Long, timeout: Long): Exception("Exceeded maximum age ($age) of $timeout ms") + class TimeoutException(age: Long, timeout: Long) : Exception("Exceeded maximum age ($age) of $timeout ms") } } \ No newline at end of file From ffaeb79c5e3ae61cc509545e9e60c09b9a7bac76 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 09:52:19 +0100 Subject: [PATCH 045/104] Not yet --- src/main/kotlin/com/lambda/client/activity/Activity.kt | 5 ++++- src/main/kotlin/com/lambda/client/module/AbstractModule.kt | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 153f055d8..77f5c2411 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -81,13 +81,16 @@ abstract class Activity(private val isRoot: Boolean = false) { ActivityStatus.UNINITIALIZED -> { initialize() } - ActivityStatus.PENDING, ActivityStatus.RUNNING -> { + ActivityStatus.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) && hasNoSubActivities && this@Activity !is EndlessActivity && this@Activity !is DelayedActivity ) success() } + ActivityStatus.PENDING -> { + // + } ActivityStatus.FAILURE -> { // } diff --git a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt index 3ca15e112..6270d42d8 100644 --- a/src/main/kotlin/com/lambda/client/module/AbstractModule.kt +++ b/src/main/kotlin/com/lambda/client/module/AbstractModule.kt @@ -29,7 +29,7 @@ abstract class AbstractModule( val alwaysEnabled: Boolean = false, val enabledByDefault: Boolean = false, private val config: NameableConfig -) : Nameable, Alias, SettingRegister by config as NameableConfig, Activity() { +) : Nameable, Alias, SettingRegister by config as NameableConfig { val bind = BindSetting("Bind", Bind(), { !alwaysEnabled }).also(::addSetting) private val enabled = BooleanSetting("Enabled", false, { false }).also(::addSetting) From 49ea2cf253a6e98639827dfdd795ee75627ad511 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 10:10:28 +0100 Subject: [PATCH 046/104] Fix PlaceBlock timeout --- .../activities/interaction/PlaceBlock.kt | 4 ++-- .../interaction/PlaceBlockWithItem.kt | 20 ------------------- .../activities/storage/PlaceContainer.kt | 12 ++++++----- .../modules/misc/TestActivityManager.kt | 8 +++----- 4 files changed, 12 insertions(+), 32 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 83a4ff1b5..ea53b33e3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -31,7 +31,7 @@ class PlaceBlock( private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks private val doPending: Boolean = false, override var rotation: Vec2f = Vec2f.ZERO, - override val timeout: Long = 300L, + override val timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -103,7 +103,7 @@ class PlaceBlock( when (childActivity) { is Wait -> if (doPending) owner.activityStatus = ActivityStatus.PENDING else -> { -// activityStatus = ActivityStatus.UNINITIALIZED + activityStatus = ActivityStatus.UNINITIALIZED } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt deleted file mode 100644 index bd0b6670b..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlockWithItem.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.item -import net.minecraft.block.state.IBlockState -import net.minecraft.util.math.BlockPos - -class PlaceBlockWithItem( - private val blockPos: BlockPos, - private val targetState: IBlockState -) : Activity() { - override fun SafeClientEvent.onInitialize() { - addSubActivities( - AcquireItemInActiveHand(targetState.block.item), - PlaceBlock(blockPos, targetState) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index 032936c28..844467566 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -17,9 +17,11 @@ class PlaceContainer( var containerPos: BlockPos = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - containerPos = getContainerPos(targetState) ?: run { - failedWith(NoContainerPlacePositionFoundException()) - return + if (containerPos == BlockPos.ORIGIN) { + containerPos = getContainerPos(targetState) ?: run { + failedWith(NoContainerPlacePositionFoundException()) + return + } } addSubActivities( @@ -27,8 +29,8 @@ class PlaceContainer( ) } - override fun SafeClientEvent.onChildFailure(childActivity: ArrayDeque, childException: Exception): Boolean { - if (childActivity.firstOrNull() !is PlaceBlock) return false + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childActivities.firstOrNull() !is PlaceBlock) return false if (childException !is PlaceBlock.NoNeighbourException) return false checkAttempt(this@PlaceContainer, NoContainerPlacePositionFoundException()) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index c584ca504..f36810ee0 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,9 +4,7 @@ import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.* -import com.lambda.client.activity.activities.interaction.BreakBlockWithTool -import com.lambda.client.activity.activities.interaction.PlaceBlockWithItem -import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity +import com.lambda.client.activity.activities.interaction.* import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox @@ -116,8 +114,8 @@ object TestActivityManager : Module( val origin = player.flooredPosition ActivityManager.addSubActivities( - PlaceBlockWithItem(origin, Blocks.OBSIDIAN.defaultState), - BreakBlockWithTool(origin) + PlaceBlock(origin, Blocks.OBSIDIAN.defaultState), + BreakBlock(origin) ) } false From ea28a28de31401bbf524b7b101d5e8e7402460a0 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 11:20:32 +0100 Subject: [PATCH 047/104] Tweaks for structure building --- .../activities/highlevel/BuildBlock.kt | 2 +- .../activities/highlevel/BuildStructure.kt | 12 +++++++++- .../activities/interaction/PlaceBlock.kt | 7 +++++- .../storage/ExtractItemFromShulkerBox.kt | 13 +++++++---- .../activity/activities/travel/PlaceGoal.kt | 23 ++++++++----------- .../activities/types/TimeoutActivity.kt | 2 +- .../manager/managers/ActivityManager.kt | 11 ++++----- .../module/modules/misc/HighwayTools.kt | 15 ++++-------- 8 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 351297451..7d1d1fbd1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -16,7 +16,7 @@ import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos class BuildBlock( - private val blockPos: BlockPos, + val blockPos: BlockPos, private val targetState: IBlockState, override val maxAttempts: Int = 3, override var usedAttempts: Int = 0, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 71835cff2..b3a2f2551 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -22,11 +22,11 @@ class BuildStructure( private var currentOffset = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { -// addSubActivities(CustomGoal(GoalNear())) structure.asSequence().sortedBy { player.distanceTo(it.key) }.forEach { (pos, state) -> val offsetPos = pos.add(currentOffset) if (isInPadding(offsetPos)) return@forEach + if (world.getBlockState(offsetPos).block == state.block) return@forEach addSubActivities( BuildBlock(offsetPos, state) @@ -36,6 +36,16 @@ class BuildStructure( override fun SafeClientEvent.onSuccess() { currentOffset = currentOffset.add(offsetMove) +// structure.keys.asSequence().sortedBy { player.distanceTo(it.add(currentOffset)) }.firstOrNull()?.let { +// addSubActivities(CustomGoal(GoalNear(it.add(currentOffset), 2))) +// } + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + val sorted = subActivities.filterIsInstance().sortedBy { player.distanceTo(it.blockPos) } + + subActivities.clear() + subActivities.addAll(sorted) } private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index ea53b33e3..cbf5648fc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -101,7 +101,12 @@ class PlaceBlock( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { - is Wait -> if (doPending) owner.activityStatus = ActivityStatus.PENDING + is Wait -> { + if (doPending) { + activityStatus = ActivityStatus.PENDING + owner.activityStatus = ActivityStatus.PENDING + } + } else -> { activityStatus = ActivityStatus.UNINITIALIZED } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index e53db4d44..779b5c548 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,9 +1,11 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.interaction.BreakBlockWithTool import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory @@ -36,12 +38,13 @@ class ExtractItemFromShulkerBox( } if (candidates.isEmpty()) { - if (item != Blocks.OBSIDIAN.item) { - failedWith(NoShulkerBoxFoundExtractException(item)) - return - } + failedWith(NoShulkerBoxFoundExtractException(item)) +// if (item != Blocks.OBSIDIAN.item) { +// failedWith(NoShulkerBoxFoundExtractException(item)) +// return +// } -// if (owner is BreakDownEnderChests) return +// if (owner?.owner !is PlaceBlock) return // // addSubActivities( // BreakDownEnderChests(maximumRepeats = 64), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt index c1624ba96..afba38713 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -19,7 +19,9 @@ class PlaceGoal( override val timeout: Long = 60000L ) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (!isInBlockAABB(blockPos) && GoalNear(blockPos, 4).isInGoal(player.flooredPosition)) success() + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.5f)?.let { + success() + } } init { @@ -31,22 +33,15 @@ class PlaceGoal( return@safeListener } - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.95f)?.let { + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.5f)?.let { success() } ?: run { - getNeighbour(blockPos, attempts = 1, range = 4.95f)?.let { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 2)) + getNeighbour(blockPos, attempts = 1, range = 256f)?.let { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 1)) } ?: run { - val nearGoal = GoalNear(blockPos, 3) - - if (!nearGoal.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(nearGoal) - return@safeListener - } - -// activityStatus = ActivityStatus.PENDING + // ToDo: Scaffolding! -// failedWith(NoPathToPlaceFound()) + failedWith(NoPathToPlaceFound()) } } } @@ -56,5 +51,5 @@ class PlaceGoal( return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) } - class NoPathToPlaceFound : Exception("No path to place position found") + class NoPathToPlaceFound : Exception("No path to place position found (scaffolding not yet implemented)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index 3cc5ba4f7..dd08247df 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -27,6 +27,6 @@ interface TimeoutActivity { } } - class TimeoutException(age: Long, timeout: Long) : Exception("Exceeded maximum age ($age) of $timeout ms") + class TimeoutException(age: Long, timeout: Long) : Exception("Exceeded maximum age ($age/$timeout)ms") } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index c042ba420..86fd4550a 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -26,12 +26,11 @@ object ActivityManager : Manager, Activity(true) { val currentActivity = currentActivity -// allActivities.filter { it.activityStatus == ActivityStatus.RUNNING -// || it.activityStatus == ActivityStatus.PENDING }.forEach { -// with(it) { -// updateTypesOnTick(it) -// } -// } + allActivities.filter { it.activityStatus == ActivityStatus.PENDING }.forEach { + with(it) { + updateTypesOnTick(it) + } + } with(currentActivity) { if (activityStatus == ActivityStatus.RUNNING diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index a0136b663..afe95b8d4 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -77,22 +77,17 @@ object HighwayTools : Module( } onDisable { - runSafe { - ownedBuildStructure?.let { - with(it) { - success() - } - } - } + ActivityManager.reset() } } private fun generateHighway(): HashMap { val blueprint = hashMapOf() - for (x in -maxReach.floorToInt() * 5..maxReach.floorToInt() * 5) { + for (x in -width..width) { val thisPos = originPosition.add(originDirection.directionVec.multiply(x)) if (clearSpace) generateClear(blueprint, thisPos) + if (structure == Structure.TUNNEL) { if (cleanFloor) generateFloor(blueprint, thisPos) if (cleanRightWall || cleanLeftWall) generateWalls(blueprint, thisPos) @@ -105,13 +100,13 @@ object HighwayTools : Module( if (structure == Structure.TUNNEL && (!cleanFloor || backfill)) { if (originDirection.isDiagonal) { - for (x in 0..maxReach.floorToInt()) { + for (x in 0..width) { val pos = originPosition.add(originDirection.directionVec.multiply(x)) blueprint[pos] = fillerState() blueprint[pos.add(originDirection.clockwise(7).directionVec)] = fillerState() } } else { - for (x in 0..maxReach.floorToInt()) { + for (x in 0..width) { blueprint[originPosition.add(originDirection.directionVec.multiply(x))] = fillerState() } } From 2eac4ae570da5e8c13c78aaf2bbe37f57bb0e1ab Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 10 Jan 2023 11:37:31 +0100 Subject: [PATCH 048/104] Bring back ignored blocks --- .../client/activity/activities/highlevel/BuildBlock.kt | 6 ++++++ .../client/activity/activities/highlevel/BuildStructure.kt | 3 ++- .../com/lambda/client/module/modules/client/BuildTools.kt | 3 +++ .../com/lambda/client/module/modules/misc/HighwayTools.kt | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 7d1d1fbd1..e2c1e63ec 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -8,6 +8,7 @@ import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools.ignoredBlocks import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.threads.runSafe import com.lambda.client.util.world.isReplaceable @@ -18,6 +19,7 @@ import net.minecraft.util.math.BlockPos class BuildBlock( val blockPos: BlockPos, private val targetState: IBlockState, + private val respectIgnore: Boolean = false, override val maxAttempts: Int = 3, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -36,6 +38,8 @@ class BuildBlock( ColorHolder(35, 188, 254) )) } + /* should be ignored */ + respectIgnore && currentState.block in ignoredBlocks -> success() /* only option left is breaking the block */ else -> { toRender.add(RenderAABBActivity.Companion.RenderBlockPos( @@ -59,6 +63,8 @@ class BuildBlock( PlaceBlock(blockPos, targetState, doPending = true) ) } + /* should be ignored */ + respectIgnore && currentState.block in ignoredBlocks -> success() /* only option left is breaking the block */ else -> { addSubActivities( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index b3a2f2551..aadeb3018 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -15,6 +15,7 @@ class BuildStructure( private val structure: Map, private val direction: Direction = Direction.NORTH, private val offsetMove: BlockPos = BlockPos.ORIGIN, + private val respectIgnore: Boolean = false, override val toRender: MutableSet = mutableSetOf(), override val maximumRepeats: Int = 1, override var repeated: Int = 0, @@ -29,7 +30,7 @@ class BuildStructure( if (world.getBlockState(offsetPos).block == state.block) return@forEach addSubActivities( - BuildBlock(offsetPos, state) + BuildBlock(offsetPos, state, respectIgnore) ) } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 7f4adad7d..4a36aec55 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -96,6 +96,9 @@ object BuildTools : Module( NONE, ANTI_AFK, LOGOUT } + val ignoredBlocks: List + get() = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } + var defaultFillerMat: Block get() = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK set(value) { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index afe95b8d4..65c9b5cb1 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -68,7 +68,8 @@ object HighwayTools : Module( generateHighway(), direction = originDirection, offsetMove = BlockPos(originDirection.directionVec), - maximumRepeats = 0 + maximumRepeats = 0, + respectIgnore = true ).let { ownedBuildStructure = it ActivityManager.addSubActivities(it) From 756f31892883702d671e22bb2736ebdfc677c5e7 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 13 Jan 2023 01:05:52 +0100 Subject: [PATCH 049/104] Added working HighwayTools prototype --- .../com/lambda/client/activity/Activity.kt | 41 ++++--- .../highlevel/BreakDownEnderChests.kt | 24 ++-- .../activities/highlevel/BuildBlock.kt | 109 ++++++++++++------ .../activities/highlevel/BuildStructure.kt | 32 +++-- .../activities/interaction/BreakBlock.kt | 72 ++++++++---- .../interaction/BreakBlockWithTool.kt | 20 ---- .../activities/interaction/PlaceBlock.kt | 26 +++-- .../inventory/AcquireItemInActiveHand.kt | 23 ++++ .../inventory/SwapOrSwitchToSlot.kt | 2 +- .../activities/inventory/SwapToBestTool.kt | 3 +- .../activities/inventory/SwapWithSlot.kt | 4 +- .../storage/ExtractItemFromShulkerBox.kt | 20 +--- .../storage/PullItemsFromContainer.kt | 47 ++++++-- .../storage/StoreItemToShulkerBox.kt | 4 +- .../activity/activities/travel/BreakGoal.kt | 21 +++- .../activities/travel/PickUpEntityItem.kt | 5 +- .../activity/activities/travel/PlaceGoal.kt | 14 ++- .../activities/types/AttemptActivity.kt | 3 +- .../types/RenderOverlayTextActivity.kt | 4 + .../activities/types/TimeoutActivity.kt | 2 +- .../elements/misc/ActivityManagerHud.kt | 18 +-- .../manager/managers/ActivityManager.kt | 21 +--- .../module/modules/client/BuildTools.kt | 4 +- .../module/modules/misc/HighwayTools.kt | 5 +- .../modules/misc/TestActivityManager.kt | 14 --- .../modules/player/InventoryManagerTwo.kt | 4 +- .../com/lambda/client/util/world/Interact.kt | 9 ++ 27 files changed, 345 insertions(+), 206 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 77f5c2411..11e678660 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity +import akka.actor.dsl.Creators.Act import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed @@ -55,14 +56,17 @@ abstract class Activity(private val isRoot: Boolean = false) { secondaryColor: ColorHolder ) {} - val activityName get() = this::class.simpleName ?: "Activity" + open fun SafeClientEvent.getCurrentActivity(): Activity { + subActivities.firstOrNull()?.let { + with(it) { + return getCurrentActivity() + } + } ?: return this@Activity + } - val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L + val activityName get() = this.javaClass.simpleName ?: "Activity" - val currentActivity: Activity get() = - subActivities.firstOrNull { it.activityStatus != ActivityStatus.PENDING }?.currentActivity - ?: subActivities.firstOrNull()?.currentActivity - ?: this + val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L val allSubActivities: List get() = run { val activities = mutableListOf() @@ -88,12 +92,7 @@ abstract class Activity(private val isRoot: Boolean = false) { && this@Activity !is DelayedActivity ) success() } - ActivityStatus.PENDING -> { - // - } - ActivityStatus.FAILURE -> { - // - } + ActivityStatus.PENDING, ActivityStatus.FAILURE -> { } } } @@ -162,9 +161,11 @@ abstract class Activity(private val isRoot: Boolean = false) { if (onChildFailure(childActivities, childException)) return true if (onFailure(childException)) return true - MessageSendHelper.sendErrorMessage("${childActivities.joinToString { it.activityName }}: ${childException.message}") - if (owner == ActivityManager) return false + if (owner.isRoot) { + MessageSendHelper.sendErrorMessage("Traceback: ${childException.javaClass.simpleName}: ${childException.message}\n ${childActivities.joinToString(separator = "\n ") { it.toString() }}") + return false + } childActivities.add(this@Activity) with(owner) { @@ -196,8 +197,8 @@ abstract class Activity(private val isRoot: Boolean = false) { } enum class ActivityStatus { - UNINITIALIZED, RUNNING, + UNINITIALIZED, PENDING, FAILURE } @@ -259,6 +260,14 @@ abstract class Activity(private val isRoot: Boolean = false) { } override fun toString(): String { - return "Name: ${javaClass.simpleName} State: $activityStatus SubActivities: $subActivities" + val properties = this::class.java.declaredFields.joinToString(separator = ", ", prefix = ", ") { + it.isAccessible = true + val name = it.name + val value = it.get(this) + "$name=$value" + } + +// return "$activityName: [State=$activityStatus, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}$properties]" + return "$activityName: [State=$activityStatus, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}]" } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 67c186667..0099e472e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -7,9 +7,8 @@ import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.inventorySlots -import com.lambda.client.util.items.item +import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.util.items.* import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments @@ -20,10 +19,19 @@ class BreakDownEnderChests( override var repeated: Int = 0 ) : RepeatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (player.inventorySlots.countEmpty() < 2) { - addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item) - ) + val freeSlots = player.allSlots.filter { slot -> + InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) || slot.stack.isEmpty + } + + if (freeSlots.isEmpty()) { + if (player.allSlots.countItem(Blocks.OBSIDIAN.item) > 0) { + addSubActivities( + StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + ) + return + } + + failedWith(NoSpaceLeftInInventoryException()) return } @@ -49,4 +57,6 @@ class BreakDownEnderChests( ) ) } + + class NoSpaceLeftInInventoryException : Exception("No space left in inventory") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index e2c1e63ec..d51d1d780 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -3,18 +3,22 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.SwapToBestTool -import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.ignoredBlocks import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.threads.runSafe -import com.lambda.client.util.world.isReplaceable +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getMiningSide +import com.lambda.client.util.world.getNeighbour +import com.lambda.client.util.world.isPlaceable import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent class BuildBlock( val blockPos: BlockPos, @@ -24,56 +28,91 @@ class BuildBlock( override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() ) : AttemptActivity, RenderAABBActivity, Activity() { - init { - runSafe { - val currentState = world.getBlockState(blockPos) + var currentAction = Action.UNINIT + enum class Action(val color: ColorHolder) { + BREAK(ColorHolder(222, 0, 0)), + PLACE(ColorHolder(35, 188, 254)), + WRONG_POS_BREAK(ColorHolder(112, 0, 0)), + WRONG_POS_PLACE(ColorHolder(20, 108, 145)), + INVALID_BREAK(ColorHolder(46, 0, 0)), + INVALID_PLACE(ColorHolder(11, 55, 74)), + UNINIT(ColorHolder(11, 11, 11)); - when { - /* is in desired state */ - currentState.block == targetState.block -> success() - /* block needs to be placed */ - targetState.block != Blocks.AIR && currentState.isReplaceable -> { - toRender.add(RenderAABBActivity.Companion.RenderBlockPos( - blockPos, - ColorHolder(35, 188, 254) - )) - } - /* should be ignored */ - respectIgnore && currentState.block in ignoredBlocks -> success() - /* only option left is breaking the block */ - else -> { - toRender.add(RenderAABBActivity.Companion.RenderBlockPos( - blockPos, - ColorHolder(222, 0, 0) - )) - } + fun addToRenderer(activity: BuildBlock) { + with(activity) { + toRender.add(RenderAABBActivity.Companion.RenderBlockPos( + blockPos, + color + )) } } } + init { + runSafe { updateState() } + + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + updateState() + } + } + override fun SafeClientEvent.onInitialize() { + updateState(true) + } + + private fun SafeClientEvent.updateState(addActivities: Boolean = false) { val currentState = world.getBlockState(blockPos) when { /* is in desired state */ currentState.block == targetState.block -> success() /* block needs to be placed */ - targetState.block != Blocks.AIR && currentState.isReplaceable -> { - addSubActivities( - PlaceBlock(blockPos, targetState, doPending = true) - ) + targetState.block != Blocks.AIR && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) ?: AxisAlignedBB(blockPos)) -> { + if (addActivities) { + addSubActivities( + PlaceBlock(blockPos, targetState, doPending = true) + ) + } else { + if (getNeighbour(blockPos, 1, BuildTools.maxReach, true) != null) { + currentAction = Action.PLACE + } else { + getNeighbour(blockPos, 1, 256f, false)?.let { + currentAction = Action.WRONG_POS_PLACE + } ?: run { + currentAction = Action.INVALID_PLACE + } + } + } } /* should be ignored */ respectIgnore && currentState.block in ignoredBlocks -> success() /* only option left is breaking the block */ else -> { - addSubActivities( - SwapToBestTool(blockPos), - BreakGoal(blockPos), - BreakBlock(blockPos), - PlaceBlock(blockPos, targetState) - ) + if (addActivities) { + addSubActivities( + BreakBlock(blockPos, doPending = true) + ) + } else { + getMiningSide(blockPos, BuildTools.maxReach)?.let { + currentAction = Action.BREAK + } ?: run { + getMiningSide(blockPos)?.let { + currentAction = Action.WRONG_POS_BREAK + } ?: run { + currentAction = Action.INVALID_BREAK + } + } + } } } + + toRender.clear() + currentAction.addToRenderer(this@BuildBlock) + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + activityStatus = ActivityStatus.UNINITIALIZED } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index aadeb3018..ce6a2f473 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -3,6 +3,9 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RepeatingActivity +import com.lambda.client.commons.extension.ceilToInt +import com.lambda.client.commons.extension.floorToInt +import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction @@ -29,9 +32,11 @@ class BuildStructure( if (isInPadding(offsetPos)) return@forEach if (world.getBlockState(offsetPos).block == state.block) return@forEach - addSubActivities( - BuildBlock(offsetPos, state, respectIgnore) - ) + val activity = BuildBlock(offsetPos, state, respectIgnore) + + addSubActivities(activity) + + LambdaEventBus.subscribe(activity) } } @@ -42,11 +47,22 @@ class BuildStructure( // } } - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - val sorted = subActivities.filterIsInstance().sortedBy { player.distanceTo(it.blockPos) } - - subActivities.clear() - subActivities.addAll(sorted) + override fun SafeClientEvent.getCurrentActivity(): Activity { + subActivities + .filterIsInstance() + .sortedWith( + compareBy { + it.activityStatus.ordinal + }.thenBy { + it.currentAction.ordinal + }.thenBy { + player.distanceTo(it.blockPos) + } + ).firstOrNull()?.let { + with(it) { + return getCurrentActivity() + } + } ?: return this@BuildStructure } private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 97d277774..682336ea5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,15 +1,21 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.SwapToBestTool +import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block +import com.lambda.client.util.items.item import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener @@ -31,6 +37,7 @@ class BreakBlock( private val miningSpeedFactor: Float = 1.0f, private val collectDrops: Boolean = false, private val minCollectAmount: Int = 1, + private val doPending: Boolean = false, override var timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, @@ -54,6 +61,11 @@ class BreakBlock( return } + if (player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE) { // ToDo: get optimal tool + addSubActivities(AcquireItemInActiveHand(Items.DIAMOND_PICKAXE)) + return + } + initState = currentState drop = currentState.block.getItemDropped(currentState, Random(), 0) @@ -61,36 +73,46 @@ class BreakBlock( ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() timeout = ticksNeeded * 50L + 2000L + + if (!(doPending && (ticksNeeded == 1 || player.capabilities.isCreativeMode))) return + + getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> + rotation = getRotationTo(getHitVec(blockPos, side)) + + playerController.onPlayerDamageBlock(blockPos, side) + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) + + if (BuildTools.breakDelay == 0) { + owner.activityStatus = ActivityStatus.PENDING + } else { + addSubActivities(Wait(BuildTools.placeDelay * 50L)) + } + } } init { safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener - getMiningSide(blockPos)?.let { side -> + getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) playerController.onPlayerDamageBlock(blockPos, side) mc.effectRenderer.addBlockHitEffects(blockPos, side) player.swingArm(EnumHand.MAIN_HAND) -// if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { -// playerController.onPlayerDestroyBlock(blockPos) -// player.swingArm(EnumHand.MAIN_HAND) -// } else { -// playerController.onPlayerDamageBlock(blockPos, side) -// player.swingArm(EnumHand.MAIN_HAND) -// // cancel onPlayerDestroy NoGhostBlocks -// -//// if (ticksNeeded * 50L < System.currentTimeMillis() - creationTime) { -//// connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockPos, side)) -//// player.swingArm(EnumHand.MAIN_HAND) -//// } else { -//// player.swingArm(EnumHand.MAIN_HAND) -//// } -// } + if (doPending && (ticksNeeded == 1 || player.capabilities.isCreativeMode)) { + if (BuildTools.breakDelay == 0) { + owner.activityStatus = ActivityStatus.PENDING + } else { + addSubActivities(Wait(BuildTools.placeDelay * 50L - 5L)) + } + } } ?: run { - failedWith(ExceptionNoSurfaceExposed()) + if (subActivities.filterIsInstance().isEmpty()) { + addSubActivities(BreakGoal(blockPos)) + } } } @@ -116,15 +138,23 @@ class BreakBlock( } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is PickUpDrops) return + when (childActivity) { + is PickUpDrops -> { + success() + } + is Wait -> { + if (!doPending) return - success() + owner.activityStatus = ActivityStatus.PENDING + } + is AcquireItemInActiveHand -> { + activityStatus = ActivityStatus.UNINITIALIZED + } + } } override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() return false } - - class ExceptionNoSurfaceExposed : Exception("No block surface exposed to player") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt deleted file mode 100644 index 6194ae2dc..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlockWithTool.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.lambda.client.activity.activities.interaction - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.SwapToBestTool -import com.lambda.client.event.SafeClientEvent -import net.minecraft.util.math.BlockPos - -class BreakBlockWithTool( - private val blockPos: BlockPos, - private val miningSpeedFactor: Float = 1.0f, - private val collectDrops: Boolean = false, - private val minCollectAmount: Int = 1 -) : Activity() { - override fun SafeClientEvent.onInitialize() { - addSubActivities( - SwapToBestTool(blockPos), - BreakBlock(blockPos, miningSpeedFactor, collectDrops, minCollectAmount) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index cbf5648fc..14690b1de 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -10,6 +10,7 @@ import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.items.blockBlacklist @@ -19,11 +20,14 @@ import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour +import com.lambda.client.util.world.isPlaceable import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumHand +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class PlaceBlock( @@ -47,12 +51,17 @@ class PlaceBlock( return } + if (!world.isPlaceable(blockPos, AxisAlignedBB(blockPos))) { + addSubActivities(BreakBlock(blockPos)) + return + } + if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { addSubActivities(AcquireItemInActiveHand(targetState.block.item)) return } - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.95f)?.let { + getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = BuildTools.maxReach)?.let { val placedAtBlock = world.getBlockState(it.pos).block renderActivity.color = ColorHolder(11, 66, 89) @@ -75,7 +84,13 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - if (doPending) addSubActivities(Wait(45L)) + if (doPending) { + if (BuildTools.placeDelay == 0) { + owner.activityStatus = ActivityStatus.PENDING + } else { + addSubActivities(Wait(BuildTools.placeDelay * 50L)) + } + } } ?: run { addSubActivities(PlaceGoal(blockPos)) // failedWith(NoNeighbourException(blockPos)) @@ -88,12 +103,6 @@ class PlaceBlock( && it.packet.blockPosition == blockPos && it.packet.blockState.block == targetState.block // TODO: Calculate correct resulting state of placed block to enable rotation checks ) { - if (doPending) { - with(owner) { - success() - } - } - success() } } @@ -103,7 +112,6 @@ class PlaceBlock( when (childActivity) { is Wait -> { if (doPending) { - activityStatus = ActivityStatus.PENDING owner.activityStatus = ActivityStatus.PENDING } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 37fa2f1c1..d9115939b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -1,10 +1,14 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.items.item +import net.minecraft.init.Blocks import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.util.EnumHand @@ -44,5 +48,24 @@ class AcquireItemInActiveHand( } } + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is ExtractItemFromShulkerBox.NoShulkerBoxFoundExtractException) return false + + if (childException.item == Blocks.OBSIDIAN.item) { + addSubActivities(BreakDownEnderChests(maximumRepeats = 64)) + return true + } + +// addSubActivities(ExtractItemFromEnderChest(item, 1, predicateItem, predicateSlot)) // ToDo: Add this + + return false + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is BreakDownEnderChests) return + + activityStatus = ActivityStatus.UNINITIALIZED + } + class NoItemFoundException(item: Item) : Exception("No ${item.registryName} found in inventory (shulkers are disabled)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt index e800e3070..2e27ffbbc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt @@ -22,7 +22,7 @@ class SwapOrSwitchToSlot( ?: return addSubActivities( - SwapWithSlot(slot, slotTo), + SwapWithSlot(slot, slotTo.hotbarSlot), SwitchToHotbarSlot(slotTo) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt index eda53622f..a030bf1dd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.inventorySlots import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments @@ -9,7 +10,7 @@ import net.minecraft.util.math.BlockPos class SwapToBestTool(private val blockPos: BlockPos) : Activity() { override fun SafeClientEvent.onInitialize() { - player.inventorySlots.asReversed().maxByOrNull { + player.allSlots.asReversed().maxByOrNull { val stack = it.stack if (stack.isEmpty) { 0.0f diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index 30cf6ea3d..44783ae83 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -8,9 +8,9 @@ import net.minecraft.inventory.Slot class SwapWithSlot( private val slotFrom: Slot, - private val slotTo: HotbarSlot + private val hotbarSlotTo: Int ) : Activity() { override fun SafeClientEvent.onInitialize() { - addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, slotTo.hotbarSlot, ClickType.SWAP)) + addSubActivities(InventoryTransaction(player.openContainer.windowId, slotFrom.slotNumber, hotbarSlotTo, ClickType.SWAP)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 779b5c548..b4062e352 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -2,10 +2,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests -import com.lambda.client.activity.activities.interaction.BreakBlockWithTool -import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.interaction.* import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory @@ -39,17 +36,6 @@ class ExtractItemFromShulkerBox( if (candidates.isEmpty()) { failedWith(NoShulkerBoxFoundExtractException(item)) -// if (item != Blocks.OBSIDIAN.item) { -// failedWith(NoShulkerBoxFoundExtractException(item)) -// return -// } - -// if (owner?.owner !is PlaceBlock) return -// -// addSubActivities( -// BreakDownEnderChests(maximumRepeats = 64), -// AcquireItemInActiveHand(Blocks.OBSIDIAN.item) -// ) return } @@ -68,10 +54,10 @@ class ExtractItemFromShulkerBox( OpenContainer(childActivity.containerPos), PullItemsFromContainer(item, amount, predicateItem), CloseContainer(), - BreakBlockWithTool(childActivity.containerPos, collectDrops = true), + BreakBlock(childActivity.containerPos, collectDrops = true), AcquireItemInActiveHand(item, predicateItem, predicateSlot) ) } - class NoShulkerBoxFoundExtractException(item: Item) : Exception("No shulker box was found containing ${item.registryName}") + class NoShulkerBoxFoundExtractException(val item: Item) : Exception("No shulker box was found containing ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 4ed34ca1e..4098e0fe4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -2,26 +2,57 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot +import com.lambda.client.activity.activities.inventory.SwapWithSlot import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.getSlots import net.minecraft.item.Item import net.minecraft.item.ItemStack -class PullItemsFromContainer( +class PullItemsFromContainer( // ToDo: fix take for full inv private val item: Item, private val amount: Int, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { - val maxEmpty = player.inventorySlots.countEmpty() - 1 + val toMoveSlots = player + .openContainer + .inventorySlots + .filter { slot -> + slot.stack.item == item && predicateItem(slot.stack) + } - val take = if (amount > 0) amount.coerceAtMost(maxEmpty) else maxEmpty + if (toMoveSlots.isEmpty()) { + success() + return + } + + val remainingSlots = if (amount == 0) toMoveSlots else toMoveSlots.take(amount) + + val playerInventory = player.openContainer.getSlots(27 .. 62) - player.openContainer.inventorySlots.filter { slot -> - slot.stack.item == item && predicateItem(slot.stack) - }.take(take).forEach { - addSubActivities(QuickMoveSlot(it)) + remainingSlots.forEach { fromSlot -> + if (playerInventory.countEmpty() > 0) { + addSubActivities(QuickMoveSlot(fromSlot)) + return@forEach + } + + playerInventory.firstOrNull { slot -> + InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) + }?.let { + val firstHotbarSlot = player.openContainer.inventorySlots[54].slotNumber + + addSubActivities( + SwapWithSlot(it, firstHotbarSlot), + SwapWithSlot(fromSlot, firstHotbarSlot) + ) + } ?: run { + failedWith(NoSpaceLeftInInventoryException()) + } } } + + class NoSpaceLeftInInventoryException : Exception("No space left in inventory") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 8e615c46f..5a4011e02 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlockWithTool +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot @@ -57,7 +57,7 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes OpenContainer(childActivity.containerPos), PushItemsToContainer(item, amount, predicateItem), CloseContainer(), - BreakBlockWithTool(childActivity.containerPos, collectDrops = true) + BreakBlock(childActivity.containerPos, collectDrops = true) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt index ae7311c49..80c0b1be3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt @@ -5,10 +5,13 @@ import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getMiningSide import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent @@ -31,18 +34,24 @@ class BreakGoal( return@safeListener } - val nearGoal = GoalNear(blockPos, 3) + getMiningSide(blockPos, BuildTools.maxReach)?.let { + success() + } ?: run { + val goalNear = GoalNear(blockPos, 3) - if (!nearGoal.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(nearGoal) - return@safeListener - } + if (!goalNear.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) + return@safeListener + } - success() + failedWith(NoPathToBreakFound()) + } } } private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos): Boolean { return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) } + + class NoPathToBreakFound : Exception("No path to break position found (scaffolding not yet implemented)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 05311ff68..07d68d086 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -7,6 +7,7 @@ import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.player.InventoryManager import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem @@ -26,9 +27,7 @@ class PickUpEntityItem( return@safeListener } - val emptySlots = player.inventory.mainInventory.filter { it.isEmpty } - - if (emptySlots.isNotEmpty()) { + if (player.inventorySlots.countEmpty() > 0) { BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) return@safeListener } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt index afba38713..670e87b24 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -5,7 +5,9 @@ import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener @@ -37,6 +39,13 @@ class PlaceGoal( success() } ?: run { getNeighbour(blockPos, attempts = 1, range = 256f)?.let { + val goalNear = GoalNear(blockPos, 3) + + if (!goalNear.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) + return@safeListener + } + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 1)) } ?: run { // ToDo: Scaffolding! @@ -47,9 +56,8 @@ class PlaceGoal( } } - private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos): Boolean { - return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) - } + private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos) = + !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) class NoPathToPlaceFound : Exception("No path to place position found (scaffolding not yet implemented)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 33d66a1c1..6d4bfe4cf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity.activities.types +import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.text.MessageSendHelper @@ -18,7 +19,7 @@ interface AttemptActivity { failedWith(MaxAttemptsExceededException(usedAttempts, causeException)) } else { usedAttempts++ - MessageSendHelper.sendErrorMessage("$activityName caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") + LambdaMod.LOG.warn("$activityName caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") subActivities.clear() initialize() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt new file mode 100644 index 000000000..82b1984bb --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt @@ -0,0 +1,4 @@ +package com.lambda.client.activity.activities.types + +interface RenderOverlayTextActivity { +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index dd08247df..b475e7045 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -27,6 +27,6 @@ interface TimeoutActivity { } } - class TimeoutException(age: Long, timeout: Long) : Exception("Exceeded maximum age ($age/$timeout)ms") + class TimeoutException(age: Long, timeout: Long) : Exception("Exceeded maximum age ${age}ms / ${timeout}ms") } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt index b48b77a04..39978c837 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt @@ -23,14 +23,16 @@ internal object ActivityManagerHud: LabelHud( if (startTime == 0L) startTime = System.currentTimeMillis() - displayText.add("Runtime:", primaryColor) - displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), secondaryColor) - displayText.add("Amount:", primaryColor) - displayText.add(ActivityManager.allSubActivities.size.toString(), secondaryColor) - displayText.add("Current:", primaryColor) - displayText.addLine(ActivityManager.currentActivity.activityName, secondaryColor) - - ActivityManager.appendInfo(displayText, primaryColor, secondaryColor) + with(ActivityManager) { + displayText.add("Runtime:", primaryColor) + displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), secondaryColor) + displayText.add("Amount:", primaryColor) + displayText.add(ActivityManager.allSubActivities.size.toString(), secondaryColor) + displayText.add("Current:", primaryColor) + displayText.addLine(getCurrentActivity().activityName, secondaryColor) + + appendInfo(displayText, primaryColor, secondaryColor) + } val sync = ListenerManager.listenerMap.keys.filterIsInstance() val async = ListenerManager.asyncListenerMap.keys.filterIsInstance() diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 86fd4550a..1ab39f00c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -24,7 +24,7 @@ object ActivityManager : Manager, Activity(true) { val allActivities = allSubActivities - val currentActivity = currentActivity + val currentActivity = getCurrentActivity() allActivities.filter { it.activityStatus == ActivityStatus.PENDING }.forEach { with(it) { @@ -34,7 +34,8 @@ object ActivityManager : Manager, Activity(true) { with(currentActivity) { if (activityStatus == ActivityStatus.RUNNING - || activityStatus == ActivityStatus.PENDING) updateTypesOnTick(currentActivity) + || activityStatus == ActivityStatus.PENDING + ) updateTypesOnTick(currentActivity) } repeat(allActivities.size * 2) { @@ -58,32 +59,18 @@ object ActivityManager : Manager, Activity(true) { } private fun SafeClientEvent.updateCurrentActivity() { - val currentActivity = currentActivity + val currentActivity = getCurrentActivity() with(currentActivity) { BaritoneUtils.settings?.allowPlace?.value = false BaritoneUtils.settings?.allowBreak?.value = false BaritoneUtils.settings?.allowInventory?.value = false -// if (currentActivity != lastActivity) { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) { -//// if (lastActivity !is ActivityManager) { -// LambdaEventBus.unsubscribe(lastActivity) -// ListenerManager.unregister(lastActivity) -// } -// -// LambdaEventBus.subscribe(currentActivity) -// BaritoneUtils.primary?.pathingBehavior?.cancelEverything() -// -// lastActivity = currentActivity -// } - updateActivity() } } fun reset() { -// if (lastActivity !is ActivityManager && lastActivity.activityStatus != ActivityStatus.PENDING) ListenerManager.listenerMap.keys.filterIsInstance().forEach { if (it is ActivityManager) return@forEach LambdaEventBus.unsubscribe(it) diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 4a36aec55..2c4462d32 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -31,14 +31,14 @@ object BuildTools : Module( // }) /* mining */ - val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.MINING }, description = "Sets the delay ticks between break tasks", unit = " ticks") + val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.MINING }, description = "Sets the delay ticks between break tasks", unit = " ticks") val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.MINING }, description = "Factor to manipulate calculated mining speed") val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") val packetFlood by setting("Packet Flood", false, { page == Page.MINING }, description = "Exploit for faster packet breaks. Sends START and STOP packet on same tick") /* placing */ - val placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.PLACING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") + val placeDelay by setting("Place Delay", 1, 0..20, 1, { page == Page.PLACING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") val illegalPlacements by setting("Illegal Placements", false, { page == Page.PLACING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 65c9b5cb1..0c1efbf01 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -37,6 +37,7 @@ object HighwayTools : Module( private val cornerBlock by setting("Corner Block", false, { structure == Structure.HIGHWAY || (structure == Structure.TUNNEL && !backfill && width > 2) }, description = "If activated will break the corner in tunnel or place a corner while paving") private val railing by setting("Railing", true, { structure == Structure.HIGHWAY }, description = "Adds a railing/rim/border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { structure == Structure.HIGHWAY && railing }, description = "Sets height of railing", unit = " blocks") + private val offset by setting("Offset", 0, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") enum class Structure { HIGHWAY, TUNNEL @@ -67,7 +68,7 @@ object HighwayTools : Module( BuildStructure( generateHighway(), direction = originDirection, - offsetMove = BlockPos(originDirection.directionVec), + offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), maximumRepeats = 0, respectIgnore = true ).let { @@ -85,7 +86,7 @@ object HighwayTools : Module( private fun generateHighway(): HashMap { val blueprint = hashMapOf() - for (x in -width..width) { + for (x in -5..5) { val thisPos = originPosition.add(originDirection.directionVec.multiply(x)) if (clearSpace) generateClear(blueprint, thisPos) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index f36810ee0..6be32c388 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -107,20 +107,6 @@ object TestActivityManager : Module( false }) - private val ctiectiectie by setting("Place break obby", false, consumer = { _, _-> - runSafe { -// val origin = player.flooredPosition.add(Direction.fromEntity(player).directionVec) - - val origin = player.flooredPosition - - ActivityManager.addSubActivities( - PlaceBlock(origin, Blocks.OBSIDIAN.defaultState), - BreakBlock(origin) - ) - } - false - }) - private val citectie by setting("Clear out", false, consumer = { _, _-> runSafe { val structure = mutableMapOf() diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 41687ded0..cad289ba6 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,6 +1,6 @@ package com.lambda.client.module.modules.player -import com.lambda.client.activity.activities.interaction.BreakBlockWithTool +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.storage.OpenShulkerFromSlot import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager @@ -81,7 +81,7 @@ object InventoryManagerTwo : Module( if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@forEachIndexed ActivityManager.addSubActivities( - BreakBlockWithTool(openShulker.containerPos, collectDrops = true) + BreakBlock(openShulker.containerPos, collectDrops = true) ) } } diff --git a/src/main/kotlin/com/lambda/client/util/world/Interact.kt b/src/main/kotlin/com/lambda/client/util/world/Interact.kt index c5d7ad657..d1a8c384e 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Interact.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Interact.kt @@ -144,6 +144,15 @@ fun SafeClientEvent.getMiningSide(pos: BlockPos): EnumFacing? { .minByOrNull { eyePos.squareDistanceTo(getHitVec(pos, it)) } } +fun SafeClientEvent.getMiningSide(pos: BlockPos, range: Float): EnumFacing? { + val eyePos = player.getPositionEyes(1.0f) + + return getVisibleSides(pos) + .filter { !world.getBlockState(pos.offset(it)).isFullBox } + .filter { eyePos.distanceTo(getHitVec(pos, it)) < range } + .minByOrNull { eyePos.squareDistanceTo(getHitVec(pos, it)) } +} + fun SafeClientEvent.getClosestVisibleSide(pos: BlockPos): EnumFacing? { val eyePos = player.getPositionEyes(1.0f) From 29b255a80fba1de0bb8a5a61064abf50f5d39787 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 13 Jan 2023 02:17:28 +0100 Subject: [PATCH 050/104] Commands and cleanup --- .../com/lambda/client/activity/Activity.kt | 74 +++++++------- .../highlevel/BreakDownEnderChests.kt | 4 +- .../activities/highlevel/BuildBlock.kt | 4 +- .../activities/highlevel/BuildStructure.kt | 2 - .../activities/interaction/BreakBlock.kt | 2 - .../activities/interaction/PlaceBlock.kt | 1 - .../inventory/AcquireItemInActiveHand.kt | 4 +- .../activities/inventory/SwapToBestTool.kt | 1 - .../activities/inventory/SwapWithSlot.kt | 1 - .../storage/ExtractItemFromShulkerBox.kt | 7 +- .../storage/PullItemsFromContainer.kt | 3 +- .../activity/activities/travel/BreakGoal.kt | 1 - .../activity/activities/travel/PlaceGoal.kt | 2 - .../activities/types/AttemptActivity.kt | 1 - .../types/RenderOverlayTextActivity.kt | 3 +- .../command/commands/BuildToolsCommand.kt | 78 +++++++++++++++ .../command/commands/HighwayToolsCommand.kt | 31 ++++++ .../manager/managers/ActivityManager.kt | 20 ++-- .../module/modules/client/BuildTools.kt | 97 +++++++++---------- .../module/modules/misc/HighwayTools.kt | 4 +- 20 files changed, 212 insertions(+), 128 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt create mode 100644 src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 11e678660..138f3ccc4 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,6 +1,5 @@ package com.lambda.client.activity -import akka.actor.dsl.Creators.Act import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed @@ -13,22 +12,14 @@ import com.lambda.client.activity.activities.types.TimeoutActivity.Companion.che import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent -import com.lambda.client.gui.hudgui.elements.misc.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper -import com.lambda.client.util.text.capitalize -import net.minecraft.entity.Entity -import net.minecraft.item.ItemBlock -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils import java.util.concurrent.ConcurrentLinkedDeque -import kotlin.collections.ArrayDeque abstract class Activity(private val isRoot: Boolean = false) { val subActivities = ConcurrentLinkedDeque() @@ -68,15 +59,16 @@ abstract class Activity(private val isRoot: Boolean = false) { val age get() = if (creationTime != 0L) System.currentTimeMillis() - creationTime else 0L - val allSubActivities: List get() = run { - val activities = mutableListOf() + val allSubActivities: List + get() = run { + val activities = mutableListOf() - if (!isRoot) activities.add(this) + if (!isRoot) activities.add(this) - activities.addAll(subActivities.flatMap { it.allSubActivities }) + activities.addAll(subActivities.flatMap { it.allSubActivities }) - activities - } + activities + } val hasNoSubActivities get() = subActivities.isEmpty() @@ -220,34 +212,34 @@ abstract class Activity(private val isRoot: Boolean = false) { textComponent.add("Runtime", primaryColor) textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), secondaryColor) } - this::class.java.declaredFields.forEachIndexed { index, field -> - field.isAccessible = true - val name = field.name - val value = field.get(this) - -// if (index.mod(6) == 0) { -// textComponent.addLine("", primaryColor) -// repeat(depth) { -// textComponent.add(" ") +// this::class.java.declaredFields.forEachIndexed { index, field -> +// field.isAccessible = true +// val name = field.name +// val value = field.get(this) +// +//// if (index.mod(6) == 0) { +//// textComponent.addLine("", primaryColor) +//// repeat(depth) { +//// textComponent.add(" ") +//// } +//// } +// +// value?.let { +// if (!ActivityManagerHud.anonymize +// || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) +// ) { +// textComponent.add(name.capitalize(), primaryColor) +// when (value) { +// is ItemBlock -> { +// textComponent.add(value.block.localizedName, secondaryColor) +// } +// else -> { +// textComponent.add(value.toString(), secondaryColor) +// } +// } // } // } - - value?.let { - if (!ActivityManagerHud.anonymize - || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) - ) { - textComponent.add(name.capitalize(), primaryColor) - when (value) { - is ItemBlock -> { - textComponent.add(value.block.localizedName, secondaryColor) - } - else -> { - textComponent.add(value.toString(), secondaryColor) - } - } - } - } - } +// } } addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 0099e472e..be2fc12a7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -8,7 +8,9 @@ import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.player.InventoryManager -import com.lambda.client.util.items.* +import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.countItem +import com.lambda.client.util.items.item import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index d51d1d780..6d60a01bb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -29,6 +29,7 @@ class BuildBlock( override val toRender: MutableSet = mutableSetOf() ) : AttemptActivity, RenderAABBActivity, Activity() { var currentAction = Action.UNINIT + enum class Action(val color: ColorHolder) { BREAK(ColorHolder(222, 0, 0)), PLACE(ColorHolder(35, 188, 254)), @@ -69,7 +70,8 @@ class BuildBlock( /* is in desired state */ currentState.block == targetState.block -> success() /* block needs to be placed */ - targetState.block != Blocks.AIR && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) ?: AxisAlignedBB(blockPos)) -> { + targetState.block != Blocks.AIR && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) + ?: AxisAlignedBB(blockPos)) -> { if (addActivities) { addSubActivities( PlaceBlock(blockPos, targetState, doPending = true) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index ce6a2f473..4886b05a0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -3,8 +3,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RepeatingActivity -import com.lambda.client.commons.extension.ceilToInt -import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 682336ea5..56e2dcc9a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.SwapToBestTool import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.AttemptActivity @@ -15,7 +14,6 @@ import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block -import com.lambda.client.util.items.item import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 14690b1de..5af73a2d4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -22,7 +22,6 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.state.IBlockState -import net.minecraft.init.Blocks import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index d9115939b..8c42f3469 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.item @@ -52,7 +52,7 @@ class AcquireItemInActiveHand( if (childException !is ExtractItemFromShulkerBox.NoShulkerBoxFoundExtractException) return false if (childException.item == Blocks.OBSIDIAN.item) { - addSubActivities(BreakDownEnderChests(maximumRepeats = 64)) + addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) return true } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt index a030bf1dd..45aed5f8b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.inventorySlots import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Enchantments import net.minecraft.util.math.BlockPos diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt index 44783ae83..9a0bdb2b8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.HotbarSlot import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index b4062e352..202a07f4a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,16 +1,15 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests -import com.lambda.client.activity.activities.interaction.* +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.CloseContainer +import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.block -import com.lambda.client.util.items.item -import net.minecraft.init.Blocks import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 4098e0fe4..2aba361f1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -5,7 +5,6 @@ import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.activity.activities.inventory.SwapWithSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.player.InventoryManager -import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots import net.minecraft.item.Item @@ -31,7 +30,7 @@ class PullItemsFromContainer( // ToDo: fix take for full inv val remainingSlots = if (amount == 0) toMoveSlots else toMoveSlots.take(amount) - val playerInventory = player.openContainer.getSlots(27 .. 62) + val playerInventory = player.openContainer.getSlots(27..62) remainingSlots.forEach { fromSlot -> if (playerInventory.countEmpty() > 0) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt index 80c0b1be3..21e05beb7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt @@ -5,7 +5,6 @@ import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt index 670e87b24..d699915c4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -5,9 +5,7 @@ import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index 6d4bfe4cf..c391f7381 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.types import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.text.MessageSendHelper interface AttemptActivity { val maxAttempts: Int diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt index 82b1984bb..29d89633b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt @@ -1,4 +1,3 @@ package com.lambda.client.activity.activities.types -interface RenderOverlayTextActivity { -} \ No newline at end of file +interface RenderOverlayTextActivity \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt new file mode 100644 index 000000000..a0686c269 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt @@ -0,0 +1,78 @@ +package com.lambda.client.command.commands + +import com.lambda.client.command.ClientCommand +import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.util.text.MessageSendHelper + +object BuildToolsCommand : ClientCommand( + name = "buildtools", + alias = arrayOf("bt", "build"), + description = "Customize settings of BuildTools" +) { + init { + literal("ignore") { + literal("add", "new", "+") { + block("block") { blockArg -> + execute("Adds a block to ignore list") { + val added = BuildTools.ignoreBlocks.add(blockArg.value.registryName.toString()) + if (added) { + MessageSendHelper.sendChatMessage("Added &7${blockArg.value.localizedName}&r to ignore list.") + } else { + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is already ignored.") + } + } + } + } + + literal("remove", "rem", "-", "del") { + block("block") { blockArg -> + execute("Removes a block from ignore list") { + val removed = BuildTools.ignoreBlocks.remove(blockArg.value.registryName.toString()) + if (removed) { + MessageSendHelper.sendChatMessage("Removed &7${blockArg.value.localizedName}&r from ignore list.") + } else { + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is not yet ignored.") + } + } + } + } + } + + literal("eject") { + literal("add", "new", "+") { + block("block") { blockArg -> + execute("Adds a block to eject list") { + val added = BuildTools.ejectList.add(blockArg.value.registryName.toString()) + if (added) { + MessageSendHelper.sendChatMessage("Added &7${blockArg.value.localizedName}&r to eject list.") + } else { + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is already in eject list.") + } + } + } + } + + literal("remove", "rem", "-", "del") { + block("block") { blockArg -> + execute("Removes a block from eject list") { + val removed = BuildTools.ejectList.remove(blockArg.value.registryName.toString()) + if (removed) { + MessageSendHelper.sendChatMessage("Removed &7${blockArg.value.localizedName}&r from eject list.") + } else { + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is not yet in the eject list.") + } + } + } + } + } + + literal("food") { + item("item") { itemArg -> + execute("Sets the food item") { + BuildTools.defaultFood = itemArg.value + MessageSendHelper.sendChatMessage("Set food item to &7${itemArg.value.registryName}&r.") + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt new file mode 100644 index 000000000..374972aaf --- /dev/null +++ b/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt @@ -0,0 +1,31 @@ +package com.lambda.client.command.commands + +import com.lambda.client.command.ClientCommand +import com.lambda.client.module.modules.misc.HighwayTools +import com.lambda.client.util.text.MessageSendHelper + +object HighwayToolsCommand : ClientCommand( + name = "highwaytools", + alias = arrayOf("ht", "hwt", "high"), + description = "Customize settings of HighwayTools." +) { + init { + literal("material", "mat") { + block("block") { blockArg -> + execute("Sets a block as main material") { + HighwayTools.material = blockArg.value + MessageSendHelper.sendChatMessage("Set your building material to &7${blockArg.value.localizedName}&r.") + } + } + } + + literal("distance") { + int("distance") { distanceArg -> + execute("Sets the distance between the player and the highway") { + HighwayTools.distance = distanceArg.value + MessageSendHelper.sendChatMessage("Set your distance to &7${distanceArg.value}&r.") + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 1ab39f00c..134352274 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -39,7 +39,13 @@ object ActivityManager : Manager, Activity(true) { } repeat(allActivities.size * 2) { - updateCurrentActivity() + with(getCurrentActivity()) { + BaritoneUtils.settings?.allowPlace?.value = false + BaritoneUtils.settings?.allowBreak?.value = false + BaritoneUtils.settings?.allowInventory?.value = false + + updateActivity() + } } } @@ -58,18 +64,6 @@ object ActivityManager : Manager, Activity(true) { } } - private fun SafeClientEvent.updateCurrentActivity() { - val currentActivity = getCurrentActivity() - - with(currentActivity) { - BaritoneUtils.settings?.allowPlace?.value = false - BaritoneUtils.settings?.allowBreak?.value = false - BaritoneUtils.settings?.allowInventory?.value = false - - updateActivity() - } - } - fun reset() { ListenerManager.listenerMap.keys.filterIsInstance().forEach { if (it is ActivityManager) return@forEach diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 2c4462d32..cee24e6b1 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -17,75 +17,76 @@ object BuildTools : Module( showOnArray = false, alwaysEnabled = true ) { - private val page by setting("Page", Page.BEHAVIOR, description = "Switch between setting pages") + private val page by setting("Page", Page.BUILDING, description = "Switch between setting pages") /* behavior */ - val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") - val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") - val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") - val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") - val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag", unit = " ticks") + val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BUILDING }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") +// val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") +// val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") +// val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") +// val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag", unit = " ticks") // private val clearQueue by setting("Clear build queue", false, { page == Page.BEHAVIOR }, consumer = { _, it -> // if (it) BuildToolsManager.resetAll() // false // }) /* mining */ - val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.MINING }, description = "Sets the delay ticks between break tasks", unit = " ticks") - val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.MINING }, description = "Factor to manipulate calculated mining speed") - val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") - val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") - val packetFlood by setting("Packet Flood", false, { page == Page.MINING }, description = "Exploit for faster packet breaks. Sends START and STOP packet on same tick") + val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") +// val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.MINING }, description = "Factor to manipulate calculated mining speed") +// val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") +// val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") +// val packetFlood by setting("Packet Flood", false, { page == Page.MINING }, description = "Exploit for faster packet breaks. Sends START and STOP packet on same tick") /* placing */ - val placeDelay by setting("Place Delay", 1, 0..20, 1, { page == Page.PLACING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") - val illegalPlacements by setting("Illegal Placements", false, { page == Page.PLACING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") - val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") - val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") + val placeDelay by setting("Place Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") + val breakDownCycles by setting("Break Down", 64, 1..200, 1, { page == Page.BUILDING }, description = "", unit = " ender chests") + val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") +// val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") +// val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") /* storage management */ - val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") - val searchEChest by setting("Search Ender Chest", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Allow access to your ender chest") - val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers") - val grindObsidian by setting("Grind Obsidian", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Destroy Ender Chests to obtain Obsidian") - val pickupRadius by setting("Pickup radius", 8, 1..50, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the radius for pickup", unit = " blocks") - val fastFill by setting("Fast Fill", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Moves as many item stacks to inventory as possible") - val keepFreeSlots by setting("Free Slots", 1, 0..30, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many inventory slots are untouched on refill", unit = " slots") - val lockSlotHotkey by setting("Lock Slot Hotkey", Bind(), { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the hotkey for locking a slot") - val manageFood by setting("Manage Food", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") - val manageTools by setting("Manage Tools", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") - val leastTools by setting("Least Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT && manageTools && storageManagement }, description = "How many tools are saved") - val leastEnder by setting("Least Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many ender chests are saved") - val leastFood by setting("Least Food", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && manageFood && storageManagement }, description = "How many food items are saved") - val preferEnderChests by setting("Prefer Ender Chests", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Prevent using raw material shulkers") +// val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") +// val searchEChest by setting("Search Ender Chest", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Allow access to your ender chest") +// val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers") +// val grindObsidian by setting("Grind Obsidian", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Destroy Ender Chests to obtain Obsidian") +// val pickupRadius by setting("Pickup radius", 8, 1..50, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the radius for pickup", unit = " blocks") +// val fastFill by setting("Fast Fill", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Moves as many item stacks to inventory as possible") +// val keepFreeSlots by setting("Free Slots", 1, 0..30, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many inventory slots are untouched on refill", unit = " slots") +// val lockSlotHotkey by setting("Lock Slot Hotkey", Bind(), { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the hotkey for locking a slot") +// val manageFood by setting("Manage Food", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") +// val manageTools by setting("Manage Tools", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") +// val leastTools by setting("Least Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT && manageTools && storageManagement }, description = "How many tools are saved") +// val leastEnder by setting("Least Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many ender chests are saved") +// val leastFood by setting("Least Food", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && manageFood && storageManagement }, description = "How many food items are saved") +// val preferEnderChests by setting("Prefer Ender Chests", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Prevent using raw material shulkers") /* render */ - val info by setting("Show Info", true, { page == Page.RENDER }, description = "Prints session stats in chat") - val goalRender by setting("Baritone Goal", false, { page == Page.RENDER }, description = "Renders the baritone goal") - val showCurrentPos by setting("Current Pos", false, { page == Page.RENDER }, description = "Renders the current position") +// val info by setting("Show Info", true, { page == Page.RENDER }, description = "Prints session stats in chat") +// val goalRender by setting("Baritone Goal", false, { page == Page.RENDER }, description = "Renders the baritone goal") +// val showCurrentPos by setting("Current Pos", false, { page == Page.RENDER }, description = "Renders the current position") val filled by setting("Filled", true, { page == Page.RENDER }, description = "Renders colored task surfaces") val outline by setting("Outline", true, { page == Page.RENDER }, description = "Renders colored task outlines") - val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") - val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") - val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") - val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") - val distScaleFactor by setting("Distance Scale Factor", 0.05f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) - val minDistScale by setting("Min Distance Scale", 0.35f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) +// val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") +// val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") +// val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") +// val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") +// val distScaleFactor by setting("Distance Scale Factor", 0.05f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) +// val minDistScale by setting("Min Distance Scale", 0.35f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.RENDER }, description = "Sets the opacity") val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.RENDER }, description = "Sets the opacity") val thickness by setting("Thickness", 2.0f, 0.25f..4.0f, 0.25f, { outline && page == Page.RENDER }, description = "Sets thickness of outline") /* misc */ - val disableWarnings by setting("Disable Warnings", false, { page == Page.MISC }, description = "DANGEROUS: Disable warnings on enable") - val debugLevel by setting("Debug Level", DebugLevel.IMPORTANT, { page == Page.MISC }, description = "Sets the debug log depth level") - val fakeSounds by setting("Fake Sounds", true, { page == Page.MISC }, description = "Adds artificial sounds to the actions") - val anonymizeLog by setting("Anonymize", false, { page == Page.MISC }, description = "Censors all coordinates in HUD and Chat") - val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.MISC }, description = "Choose action when bot is out of materials or tools") - val usingProxy by setting("Proxy", false, { page == Page.MISC && disableMode == DisableMode.LOGOUT }, description = "Enable this if you are using a proxy to call the given command") - val proxyCommand by setting("Proxy Command", "/dc", { page == Page.MISC && disableMode == DisableMode.LOGOUT && usingProxy }, description = "Command to be sent to log out") +// val disableWarnings by setting("Disable Warnings", false, { page == Page.MISC }, description = "DANGEROUS: Disable warnings on enable") +// val debugLevel by setting("Debug Level", DebugLevel.IMPORTANT, { page == Page.MISC }, description = "Sets the debug log depth level") +// val fakeSounds by setting("Fake Sounds", true, { page == Page.MISC }, description = "Adds artificial sounds to the actions") +// val anonymizeLog by setting("Anonymize", false, { page == Page.MISC }, description = "Censors all coordinates in HUD and Chat") +// val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.MISC }, description = "Choose action when bot is out of materials or tools") +// val usingProxy by setting("Proxy", false, { page == Page.MISC && disableMode == DisableMode.LOGOUT }, description = "Enable this if you are using a proxy to call the given command") +// val proxyCommand by setting("Proxy Command", "/dc", { page == Page.MISC && disableMode == DisableMode.LOGOUT && usingProxy }, description = "Command to be sent to log out") private enum class Page { - BEHAVIOR, MINING, PLACING, STORAGE_MANAGEMENT, RENDER, MISC + BUILDING, RENDER } enum class DebugLevel { @@ -139,10 +140,8 @@ object BuildTools : Module( ) val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) - val fillerMaterials = setting(CollectionSetting("Eject List", defaultEjectList)) + val ejectList = setting(CollectionSetting("Eject List", defaultEjectList)) private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) private val food = setting("FoodItem", "minecraft:golden_apple", { false }) private val tool = setting("ToolItem", "minecraft:diamond_pickaxe", { false }) - -// override fun isActive() = BuildToolsManager.isActive() } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 0c1efbf01..ee2515799 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -50,7 +50,7 @@ object HighwayTools : Module( private var ownedBuildStructure: BuildStructure? = null - private var material: Block + var material: Block get() = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN set(value) { materialSaved.value = value.registryName.toString() @@ -69,7 +69,7 @@ object HighwayTools : Module( generateHighway(), direction = originDirection, offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), - maximumRepeats = 0, + maximumRepeats = distance, respectIgnore = true ).let { ownedBuildStructure = it From d0b37d3e7422fb8c35d19ce8f870405bcd5c86f9 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sat, 14 Jan 2023 05:27:53 +0100 Subject: [PATCH 051/104] BuildBlock context system and rainbow highway --- .../com/lambda/client/activity/Activity.kt | 22 +++--- .../highlevel/BreakDownEnderChests.kt | 4 +- .../activities/highlevel/BuildBlock.kt | 66 ++++++++--------- .../activities/highlevel/BuildStructure.kt | 34 ++++++++- .../activities/interaction/BreakBlock.kt | 73 +++++++++++++++---- .../activities/interaction/PlaceBlock.kt | 28 +++++-- .../inventory/AcquireItemInActiveHand.kt | 9 ++- .../storage/PullItemsFromContainer.kt | 4 +- .../activities/travel/PickUpEntityItem.kt | 12 +-- .../activities/types/LoopWhileActivity.kt | 2 +- .../activities/types/RepeatingActivity.kt | 2 +- .../manager/managers/ActivityManager.kt | 7 +- .../module/modules/client/BuildTools.kt | 2 + .../module/modules/misc/HighwayTools.kt | 26 ++++++- 14 files changed, 200 insertions(+), 91 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 138f3ccc4..1a02230c9 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentLinkedDeque abstract class Activity(private val isRoot: Boolean = false) { val subActivities = ConcurrentLinkedDeque() - var activityStatus = ActivityStatus.UNINITIALIZED + var status = Status.UNINITIALIZED private var creationTime = 0L var owner: Activity = ActivityManager var depth = 0 @@ -73,18 +73,18 @@ abstract class Activity(private val isRoot: Boolean = false) { val hasNoSubActivities get() = subActivities.isEmpty() fun SafeClientEvent.updateActivity() { - when (activityStatus) { - ActivityStatus.UNINITIALIZED -> { + when (status) { + Status.UNINITIALIZED -> { initialize() } - ActivityStatus.RUNNING -> { + Status.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) && hasNoSubActivities && this@Activity !is EndlessActivity && this@Activity !is DelayedActivity ) success() } - ActivityStatus.PENDING, ActivityStatus.FAILURE -> { } + Status.PENDING, Status.FAILURE -> { } } } @@ -98,7 +98,7 @@ abstract class Activity(private val isRoot: Boolean = false) { fun SafeClientEvent.initialize() { val activity = this@Activity - activityStatus = ActivityStatus.RUNNING + status = Status.RUNNING creationTime = System.currentTimeMillis() onInitialize() @@ -188,7 +188,7 @@ abstract class Activity(private val isRoot: Boolean = false) { addSubActivities(activities.toList()) } - enum class ActivityStatus { + enum class Status { RUNNING, UNINITIALIZED, PENDING, @@ -203,12 +203,13 @@ abstract class Activity(private val isRoot: Boolean = false) { ListenerManager.asyncListenerMap[this@Activity]?.let { textComponent.add("ASYNC", secondaryColor) } + textComponent.add("Name", primaryColor) textComponent.add("${javaClass.simpleName} ", secondaryColor) textComponent.add("State", primaryColor) - textComponent.add(activityStatus.name, secondaryColor) + textComponent.add(status.name, secondaryColor) - if (activityStatus == ActivityStatus.RUNNING) { + if (status == Status.RUNNING) { textComponent.add("Runtime", primaryColor) textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), secondaryColor) } @@ -243,6 +244,7 @@ abstract class Activity(private val isRoot: Boolean = false) { } addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") +// subActivities.filter { !(it is BuildBlock && it.activityStatus == ActivityStatus.UNINITIALIZED) }.forEach { subActivities.forEach { repeat(depth) { textComponent.add(" ") @@ -260,6 +262,6 @@ abstract class Activity(private val isRoot: Boolean = false) { } // return "$activityName: [State=$activityStatus, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}$properties]" - return "$activityName: [State=$activityStatus, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}]" + return "$activityName: [State=$status, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}]" } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index be2fc12a7..1d1a30e6e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -7,7 +7,7 @@ import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countItem import com.lambda.client.util.items.item @@ -22,7 +22,7 @@ class BreakDownEnderChests( ) : RepeatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { val freeSlots = player.allSlots.filter { slot -> - InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) || slot.stack.isEmpty + BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) || slot.stack.isEmpty } if (freeSlots.isEmpty()) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 6d60a01bb..45ec2183a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -11,9 +11,7 @@ import com.lambda.client.module.modules.client.BuildTools.ignoredBlocks import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getMiningSide -import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.* import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.AxisAlignedBB @@ -28,7 +26,14 @@ class BuildBlock( override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() ) : AttemptActivity, RenderAABBActivity, Activity() { - var currentAction = Action.UNINIT + var action = Action.UNINIT + var context = Context.NONE + + enum class Context(val color: ColorHolder) { + RESTOCK(ColorHolder()), + LIQUID(ColorHolder()), + NONE(ColorHolder()) + } enum class Action(val color: ColorHolder) { BREAK(ColorHolder(222, 0, 0)), @@ -50,41 +55,40 @@ class BuildBlock( } init { - runSafe { updateState() } + runSafe { updateAction() } safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - updateState() + updateAction() } } override fun SafeClientEvent.onInitialize() { - updateState(true) + updateAction(true) } - private fun SafeClientEvent.updateState(addActivities: Boolean = false) { + private fun SafeClientEvent.updateAction(addActivities: Boolean = false) { + val owner = owner + + if (owner !is BuildStructure) return + val currentState = world.getBlockState(blockPos) when { /* is in desired state */ - currentState.block == targetState.block -> success() + currentState == targetState -> success() /* block needs to be placed */ - targetState.block != Blocks.AIR && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) - ?: AxisAlignedBB(blockPos)) -> { + currentState.isLiquid || + (targetState != Blocks.AIR.defaultState && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) + ?: AxisAlignedBB(blockPos))) -> { if (addActivities) { addSubActivities( - PlaceBlock(blockPos, targetState, doPending = true) + PlaceBlock(blockPos, targetState, BuildTools.doPending) ) } else { - if (getNeighbour(blockPos, 1, BuildTools.maxReach, true) != null) { - currentAction = Action.PLACE - } else { - getNeighbour(blockPos, 1, 256f, false)?.let { - currentAction = Action.WRONG_POS_PLACE - } ?: run { - currentAction = Action.INVALID_PLACE - } + action = when { + getNeighbour(blockPos, 1, BuildTools.maxReach, true) != null -> Action.PLACE + getNeighbour(blockPos, 1, 256f, false) != null -> Action.WRONG_POS_PLACE + else -> Action.INVALID_PLACE } } } @@ -94,27 +98,23 @@ class BuildBlock( else -> { if (addActivities) { addSubActivities( - BreakBlock(blockPos, doPending = true) + BreakBlock(blockPos, BuildTools.doPending) ) } else { - getMiningSide(blockPos, BuildTools.maxReach)?.let { - currentAction = Action.BREAK - } ?: run { - getMiningSide(blockPos)?.let { - currentAction = Action.WRONG_POS_BREAK - } ?: run { - currentAction = Action.INVALID_BREAK - } + action = when { + getMiningSide(blockPos, BuildTools.maxReach) != null -> Action.BREAK + getMiningSide(blockPos) != null -> Action.WRONG_POS_BREAK + else -> Action.INVALID_BREAK } } } } toRender.clear() - currentAction.addToRenderer(this@BuildBlock) + action.addToRenderer(this@BuildBlock) } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - activityStatus = ActivityStatus.UNINITIALIZED + status = Status.UNINITIALIZED } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 4886b05a0..c1dae5471 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -24,11 +24,11 @@ class BuildStructure( private var currentOffset = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - structure.asSequence().sortedBy { player.distanceTo(it.key) }.forEach { (pos, state) -> + structure.forEach { (pos, state) -> val offsetPos = pos.add(currentOffset) if (isInPadding(offsetPos)) return@forEach - if (world.getBlockState(offsetPos).block == state.block) return@forEach + if (world.getBlockState(offsetPos) == state) return@forEach val activity = BuildBlock(offsetPos, state, respectIgnore) @@ -47,12 +47,15 @@ class BuildStructure( override fun SafeClientEvent.getCurrentActivity(): Activity { subActivities + .asSequence() .filterIsInstance() .sortedWith( compareBy { - it.activityStatus.ordinal + it.status }.thenBy { - it.currentAction.ordinal + it.context + }.thenBy { + it.action }.thenBy { player.distanceTo(it.blockPos) } @@ -63,6 +66,29 @@ class BuildStructure( } ?: return this@BuildStructure } +// init { +// safeListener { event -> +// if (event.phase != TickEvent.Phase.START) return@safeListener +// +// structure.forEach { (pos, state) -> +// val offsetPos = pos.add(currentOffset) +// +// if (isInPadding(offsetPos)) return@forEach +// +// val blockState = world.getBlockState(offsetPos) +// +// if (blockState == state) return@forEach +// if (!blockState.isLiquid) return@forEach +// +// val activity = BuildBlock(offsetPos, state, respectIgnore) +// +// addSubActivities(activity) +// +// LambdaEventBus.subscribe(activity) +// } +// } +// } + private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) private fun isBehindPos(origin: BlockPos, check: BlockPos): Boolean { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 56e2dcc9a..f62fd757d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.highlevel.BuildBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops @@ -12,6 +13,7 @@ import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -19,23 +21,26 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide +import com.lambda.client.util.world.isLiquid import net.minecraft.block.material.Material import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* +import kotlin.collections.ArrayDeque import kotlin.math.ceil class BreakBlock( private val blockPos: BlockPos, - private val miningSpeedFactor: Float = 1.0f, + private val doPending: Boolean = false, private val collectDrops: Boolean = false, + private val miningSpeedFactor: Float = 1.0f, private val minCollectAmount: Int = 1, - private val doPending: Boolean = false, override var timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, @@ -60,10 +65,36 @@ class BreakBlock( } if (player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE) { // ToDo: get optimal tool + val owner = owner + + if (owner is BuildBlock) { + owner.context = BuildBlock.Context.RESTOCK + } + addSubActivities(AcquireItemInActiveHand(Items.DIAMOND_PICKAXE)) return } + var needToHandleLiquid = false + + EnumFacing.values().forEach { + if (it == EnumFacing.DOWN) return@forEach + + val neighbour = blockPos.offset(it) + if (world.getBlockState(neighbour).isLiquid) { + val owner = owner + + if (owner is BuildBlock) { + owner.context = BuildBlock.Context.LIQUID + } + + addSubActivities(PlaceBlock(neighbour, BuildTools.defaultFillerMat.defaultState)) + needToHandleLiquid = true + } + } + + if (needToHandleLiquid) return + initState = currentState drop = currentState.block.getItemDropped(currentState, Random(), 0) @@ -72,7 +103,7 @@ class BreakBlock( ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() timeout = ticksNeeded * 50L + 2000L - if (!(doPending && (ticksNeeded == 1 || player.capabilities.isCreativeMode))) return + if (!(ticksNeeded == 1 || player.capabilities.isCreativeMode)) return getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) @@ -82,9 +113,9 @@ class BreakBlock( player.swingArm(EnumHand.MAIN_HAND) if (BuildTools.breakDelay == 0) { - owner.activityStatus = ActivityStatus.PENDING + setBuildBlockOnPending() } else { - addSubActivities(Wait(BuildTools.placeDelay * 50L)) + addSubActivities(Wait(BuildTools.placeDelay * 50L - 5L)) } } } @@ -92,6 +123,7 @@ class BreakBlock( init { safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener + if (owner.status == Status.PENDING) return@safeListener getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) @@ -102,13 +134,13 @@ class BreakBlock( if (doPending && (ticksNeeded == 1 || player.capabilities.isCreativeMode)) { if (BuildTools.breakDelay == 0) { - owner.activityStatus = ActivityStatus.PENDING + owner.status = Status.PENDING } else { addSubActivities(Wait(BuildTools.placeDelay * 50L - 5L)) } } } ?: run { - if (subActivities.filterIsInstance().isEmpty()) { + if (autoPathing && subActivities.filterIsInstance().isEmpty()) { addSubActivities(BreakGoal(blockPos)) } } @@ -119,7 +151,7 @@ class BreakBlock( && it.packet.blockPosition == blockPos && it.packet.blockState.block == Blocks.AIR ) { - if (!collectDrops) { + if (!collectDrops || !autoPathing) { success() return@safeListener } @@ -140,19 +172,30 @@ class BreakBlock( is PickUpDrops -> { success() } - is Wait -> { - if (!doPending) return - - owner.activityStatus = ActivityStatus.PENDING - } - is AcquireItemInActiveHand -> { - activityStatus = ActivityStatus.UNINITIALIZED + is Wait -> setBuildBlockOnPending() + is AcquireItemInActiveHand, is PlaceBlock -> { + status = Status.UNINITIALIZED } } } + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is BreakGoal.NoPathToBreakFound) return false + + if (owner !is BuildBlock) return false + + owner.status = Status.UNINITIALIZED + return true + } + override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() return false } + + private fun setBuildBlockOnPending() { + if (!doPending || owner !is BuildBlock) return + + owner.status = Status.PENDING + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 5af73a2d4..68ad13016 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -11,6 +11,7 @@ import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.items.blockBlacklist @@ -21,7 +22,9 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable +import net.minecraft.block.BlockColored import net.minecraft.block.state.IBlockState +import net.minecraft.item.EnumDyeColor import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult @@ -45,7 +48,7 @@ class PlaceBlock( ).also { toRender.add(it) } override fun SafeClientEvent.onInitialize() { - if (world.getBlockState(blockPos).block == targetState.block) { + if (world.getBlockState(blockPos) == targetState) { success() return } @@ -55,7 +58,18 @@ class PlaceBlock( return } - if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { + if (targetState.block is BlockColored) { + targetState.properties.entries.firstOrNull { it.key == BlockColored.COLOR }?.let { entry -> + val meta = (entry.value as EnumDyeColor).metadata + + if (player.getHeldItem(EnumHand.MAIN_HAND).metadata != meta) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item, predicateItem = { + it.metadata == meta + })) + return + } + } + } else if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { addSubActivities(AcquireItemInActiveHand(targetState.block.item)) return } @@ -85,13 +99,13 @@ class PlaceBlock( if (doPending) { if (BuildTools.placeDelay == 0) { - owner.activityStatus = ActivityStatus.PENDING + owner.status = Status.PENDING } else { addSubActivities(Wait(BuildTools.placeDelay * 50L)) } } } ?: run { - addSubActivities(PlaceGoal(blockPos)) + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) // failedWith(NoNeighbourException(blockPos)) } } @@ -100,7 +114,7 @@ class PlaceBlock( safeListener { if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos - && it.packet.blockState.block == targetState.block // TODO: Calculate correct resulting state of placed block to enable rotation checks + && it.packet.blockState == targetState ) { success() } @@ -111,11 +125,11 @@ class PlaceBlock( when (childActivity) { is Wait -> { if (doPending) { - owner.activityStatus = ActivityStatus.PENDING + owner.status = Status.PENDING } } else -> { - activityStatus = ActivityStatus.UNINITIALIZED + status = Status.UNINITIALIZED } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 8c42f3469..99efc4979 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.allSlots @@ -18,8 +19,10 @@ class AcquireItemInActiveHand( private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, private val useShulkerBoxes: Boolean = true, - private val useEnderChest: Boolean = false -) : Activity() { + private val useEnderChest: Boolean = false, + override val maxAttempts: Int = 3, + override var usedAttempts: Int = 0 +) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) @@ -64,7 +67,7 @@ class AcquireItemInActiveHand( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { if (childActivity !is BreakDownEnderChests) return - activityStatus = ActivityStatus.UNINITIALIZED + status = Status.UNINITIALIZED } class NoItemFoundException(item: Item) : Exception("No ${item.registryName} found in inventory (shulkers are disabled)") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 2aba361f1..32526b568 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.activity.activities.inventory.SwapWithSlot import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots import net.minecraft.item.Item @@ -39,7 +39,7 @@ class PullItemsFromContainer( // ToDo: fix take for full inv } playerInventory.firstOrNull { slot -> - InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) + BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { val firstHotbarSlot = player.openContainer.inventorySlots[54].slotNumber diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 07d68d086..01a7f1d00 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -5,7 +5,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.DumpSlot import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.player.InventoryManager +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots @@ -15,7 +15,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class PickUpEntityItem( private val entityItem: EntityItem, - override val timeout: Long = 10000L + override val timeout: Long = 20000L ) : TimeoutActivity, Activity() { init { safeListener { event -> @@ -27,13 +27,15 @@ class PickUpEntityItem( return@safeListener } - if (player.inventorySlots.countEmpty() > 0) { + if (player.openContainer.inventorySlots.countEmpty() > 0) { BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) return@safeListener } - player.inventorySlots.firstOrNull { slot -> - InventoryManager.ejectList.contains(slot.stack.item.registryName.toString()) + if (subActivities.filterIsInstance().isNotEmpty()) return@safeListener + + player.openContainer.inventorySlots.firstOrNull() { slot -> + BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt index 6fd477821..d7551c0e3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt @@ -15,7 +15,7 @@ interface LoopWhileActivity { if (!loopWhile()) return currentLoops++ - activityStatus = Activity.ActivityStatus.UNINITIALIZED + status = Activity.Status.UNINITIALIZED owner.subActivities.add(activity) // LambdaMod.LOG.info("Looping $name ($currentLoops)") } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt index 2a0fbe5b4..b7b211ff5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt @@ -14,7 +14,7 @@ interface RepeatingActivity { with(activity) { if (repeated++ >= maximumRepeats && maximumRepeats != 0) return - activityStatus = Activity.ActivityStatus.UNINITIALIZED + status = Activity.Status.UNINITIALIZED owner.subActivities.add(activity) // LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 134352274..a7715388c 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -4,7 +4,6 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager -import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager import com.lambda.client.module.modules.client.BuildTools @@ -26,15 +25,15 @@ object ActivityManager : Manager, Activity(true) { val currentActivity = getCurrentActivity() - allActivities.filter { it.activityStatus == ActivityStatus.PENDING }.forEach { + allActivities.filter { it.status == Status.PENDING }.forEach { with(it) { updateTypesOnTick(it) } } with(currentActivity) { - if (activityStatus == ActivityStatus.RUNNING - || activityStatus == ActivityStatus.PENDING + if (status == Status.RUNNING + || status == Status.PENDING ) updateTypesOnTick(currentActivity) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index cee24e6b1..17052521a 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -21,6 +21,7 @@ object BuildTools : Module( /* behavior */ val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BUILDING }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") + val autoPathing by setting("Auto Pathing", true, { page == Page.BUILDING }, description = "Automatically pathfind to the next block") // val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") // val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") // val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") @@ -41,6 +42,7 @@ object BuildTools : Module( val placeDelay by setting("Place Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") val breakDownCycles by setting("Break Down", 64, 1..200, 1, { page == Page.BUILDING }, description = "", unit = " ender chests") val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") + val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") // val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index ee2515799..fc801d5c0 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -1,21 +1,21 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.highlevel.BuildStructure -import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.client.BuildTools.defaultFillerMat -import com.lambda.client.module.modules.client.BuildTools.maxReach import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe import net.minecraft.block.Block +import net.minecraft.block.BlockColored import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.item.EnumDyeColor import net.minecraft.util.math.BlockPos object HighwayTools : Module( @@ -38,6 +38,7 @@ object HighwayTools : Module( private val railing by setting("Railing", true, { structure == Structure.HIGHWAY }, description = "Adds a railing/rim/border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { structure == Structure.HIGHWAY && railing }, description = "Sets height of railing", unit = " blocks") private val offset by setting("Offset", 0, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") + private val rainbowMode by setting("Rainbow Mode", false, description = "Rainbow mode for the structure") enum class Structure { HIGHWAY, TUNNEL @@ -145,10 +146,10 @@ object HighwayTools : Module( if (!cornerBlock && width > 2 && originDirection.isDiagonal) blueprint[pos] = fillerState() // support block val startHeight = if (cornerBlock && width > 2) 0 else 1 for (y in startHeight..railingHeight) { - blueprint[pos.up(y)] = material.defaultState + blueprint[pos.up(y)] = if (rainbowMode) getRainbowBlockState(pos.up(y)) else material.defaultState } } else { - blueprint[pos] = material.defaultState + blueprint[pos] = if (rainbowMode) getRainbowBlockState(pos) else material.defaultState } } } @@ -201,6 +202,23 @@ object HighwayTools : Module( } + private fun getRainbowBlockState(pos: BlockPos): IBlockState { + val rainbowColors = listOf( + EnumDyeColor.PURPLE, + EnumDyeColor.BLUE, + EnumDyeColor.CYAN, + EnumDyeColor.LIME, + EnumDyeColor.YELLOW, + EnumDyeColor.ORANGE, + EnumDyeColor.RED + ) + + return Blocks.CONCRETE.defaultState.withProperty( + BlockColored.COLOR, + rainbowColors[(originPosition.subtract(pos).z + width / 2).mod(rainbowColors.size)] + ) + } + private fun fillerState() = defaultFillerMat.defaultState private val materialSaved = setting("Material", "minecraft:obsidian", { false }) From c433670aa20374f41528f970ebb58b8e6c3a1f50 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 26 Jan 2023 02:07:44 +0100 Subject: [PATCH 052/104] Stash dump --- src/main/kotlin/com/lambda/client/activity/Activity.kt | 2 +- .../client/activity/activities/highlevel/BuildBlock.kt | 9 ++++++++- .../activity/activities/highlevel/BuildStructure.kt | 2 +- .../activity/activities/interaction/BreakBlock.kt | 10 ++++++++-- .../activity/activities/interaction/PlaceBlock.kt | 8 +++++--- .../client/activity/activities/travel/PickUpDrops.kt | 4 +++- .../activity/activities/travel/PickUpEntityItem.kt | 2 +- .../lambda/client/manager/managers/ActivityManager.kt | 10 ++++------ .../lambda/client/module/modules/client/BuildTools.kt | 1 + 9 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 1a02230c9..fbc37396f 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -21,7 +21,7 @@ import com.lambda.client.util.text.MessageSendHelper import org.apache.commons.lang3.time.DurationFormatUtils import java.util.concurrent.ConcurrentLinkedDeque -abstract class Activity(private val isRoot: Boolean = false) { +abstract class Activity(val isRoot: Boolean = false) { val subActivities = ConcurrentLinkedDeque() var status = Status.UNINITIALIZED private var creationTime = 0L diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 45ec2183a..72da6389e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -82,7 +82,7 @@ class BuildBlock( ?: AxisAlignedBB(blockPos))) -> { if (addActivities) { addSubActivities( - PlaceBlock(blockPos, targetState, BuildTools.doPending) + PlaceBlock(blockPos, if (currentState.isLiquid) BuildTools.defaultFillerMat.defaultState else targetState, BuildTools.doPending) ) } else { action = when { @@ -117,4 +117,11 @@ class BuildBlock( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { status = Status.UNINITIALIZED } + + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is BreakBlock.NoExposedSideFound) return false + + status = Status.UNINITIALIZED + return true + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index c1dae5471..0e8d64480 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -57,7 +57,7 @@ class BuildStructure( }.thenBy { it.action }.thenBy { - player.distanceTo(it.blockPos) + player.getPositionEyes(1f).distanceTo(it.blockPos) } ).firstOrNull()?.let { with(it) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index f62fd757d..fcda1a4cb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -140,8 +140,12 @@ class BreakBlock( } } } ?: run { - if (autoPathing && subActivities.filterIsInstance().isEmpty()) { - addSubActivities(BreakGoal(blockPos)) + getMiningSide(blockPos)?.let { + if (autoPathing && subActivities.filterIsInstance().isEmpty()) { + addSubActivities(BreakGoal(blockPos)) + } + } ?: run { + failedWith(NoExposedSideFound()) } } } @@ -198,4 +202,6 @@ class BreakBlock( owner.status = Status.PENDING } + + class NoExposedSideFound : Exception("No exposed side found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 68ad13016..c464a3b8b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -86,8 +86,10 @@ class PlaceBlock( rotation = getRotationTo(it.hitVec) // connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) - if (playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) != EnumActionResult.SUCCESS) { - failedWith(ProcessRightClickException()) + val result = playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) + + if (result != EnumActionResult.SUCCESS) { + failedWith(ProcessRightClickException(result)) return } @@ -135,5 +137,5 @@ class PlaceBlock( } class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") - class ProcessRightClickException : Exception("Processing right click failed") + class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index ac71224b2..78da30946 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -15,7 +15,9 @@ class PickUpDrops( ) : Activity() { override fun SafeClientEvent.onInitialize() { val drops = world.loadedEntityList.filterIsInstance().filter { - it.item.item == item && player.distanceTo(it.positionVector) < maxRange && predicate(it.item) + it.item.item == item + && player.distanceTo(it.positionVector) < maxRange + && predicate(it.item) } if (drops.isEmpty() || drops.sumOf { it.item.count } < minAmount) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 01a7f1d00..26b3c93f6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -34,7 +34,7 @@ class PickUpEntityItem( if (subActivities.filterIsInstance().isNotEmpty()) return@safeListener - player.openContainer.inventorySlots.firstOrNull() { slot -> + player.inventorySlots.firstOrNull() { slot -> BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index a7715388c..a2c49eaad 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -7,6 +7,7 @@ import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener @@ -15,7 +16,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity(true) { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 - private var lastActivity: Activity = this init { safeListener { event -> @@ -37,7 +37,7 @@ object ActivityManager : Manager, Activity(true) { ) updateTypesOnTick(currentActivity) } - repeat(allActivities.size * 2) { + repeat(executionCountPerTick) { with(getCurrentActivity()) { BaritoneUtils.settings?.allowPlace?.value = false BaritoneUtils.settings?.allowBreak?.value = false @@ -65,18 +65,16 @@ object ActivityManager : Manager, Activity(true) { fun reset() { ListenerManager.listenerMap.keys.filterIsInstance().forEach { - if (it is ActivityManager) return@forEach + if (it.isRoot) return@forEach LambdaEventBus.unsubscribe(it) ListenerManager.unregister(it) } ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { - if (it is ActivityManager) return@forEach + if (it.isRoot) return@forEach LambdaEventBus.unsubscribe(it) ListenerManager.unregister(it) } BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() - - lastActivity = ActivityManager } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 17052521a..976c00feb 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -43,6 +43,7 @@ object BuildTools : Module( val breakDownCycles by setting("Break Down", 64, 1..200, 1, { page == Page.BUILDING }, description = "", unit = " ender chests") val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") + val executionCountPerTick by setting("Executions Per Tick", 100, 0..200, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") // val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") From b4b44ac7124ee61fd464c6cbbe97c24b785a0416 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 30 Jan 2023 05:40:57 +0100 Subject: [PATCH 053/104] Support EnumFacing blocks, fixed item dump --- .../com/lambda/client/activity/Activity.kt | 84 ++++++++------ .../highlevel/BreakDownEnderChests.kt | 7 +- .../activities/highlevel/BuildBlock.kt | 4 +- .../activities/interaction/BreakBlock.kt | 3 +- .../activities/interaction/PlaceBlock.kt | 106 ++++++++++++++---- .../activity/activities/interaction/Rotate.kt | 19 ++++ .../activities/storage/PlaceContainer.kt | 13 ++- .../activities/travel/PickUpEntityItem.kt | 2 +- .../command/commands/BuildToolsCommand.kt | 12 ++ .../{misc => client}/ActivityManagerHud.kt | 19 ++-- .../module/modules/client/BuildTools.kt | 3 +- .../client/module/modules/misc/BlockData.kt | 5 + .../module/modules/misc/HighwayTools.kt | 43 +++---- .../modules/misc/TestActivityManager.kt | 26 +++++ .../module/modules/player/PacketLogger.kt | 2 +- .../com/lambda/client/util/world/Check.kt | 8 +- .../com/lambda/client/util/world/Interact.kt | 4 +- 17 files changed, 252 insertions(+), 108 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt rename src/main/kotlin/com/lambda/client/gui/hudgui/elements/{misc => client}/ActivityManagerHud.kt (79%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index fbc37396f..64247c8ed 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -12,12 +12,18 @@ import com.lambda.client.activity.activities.types.TimeoutActivity.Companion.che import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.entity.Entity +import net.minecraft.item.ItemBlock +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils import java.util.concurrent.ConcurrentLinkedDeque @@ -154,7 +160,7 @@ abstract class Activity(val isRoot: Boolean = false) { if (onFailure(childException)) return true - if (owner.isRoot) { + if (this@Activity is ActivityManager) { MessageSendHelper.sendErrorMessage("Traceback: ${childException.javaClass.simpleName}: ${childException.message}\n ${childActivities.joinToString(separator = "\n ") { it.toString() }}") return false } @@ -195,53 +201,57 @@ abstract class Activity(val isRoot: Boolean = false) { FAILURE } - fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { + fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder, details: Boolean) { if (this !is ActivityManager) { ListenerManager.listenerMap[this@Activity]?.let { - textComponent.add("SYNC", secondaryColor) + textComponent.add("SYNC", primaryColor) } ListenerManager.asyncListenerMap[this@Activity]?.let { - textComponent.add("ASYNC", secondaryColor) + textComponent.add("ASYNC", primaryColor) } - textComponent.add("Name", primaryColor) - textComponent.add("${javaClass.simpleName} ", secondaryColor) - textComponent.add("State", primaryColor) - textComponent.add(status.name, secondaryColor) + textComponent.add("Name", secondaryColor) + textComponent.add("${javaClass.simpleName} ", primaryColor) + textComponent.add("State", secondaryColor) + textComponent.add(status.name, primaryColor) if (status == Status.RUNNING) { - textComponent.add("Runtime", primaryColor) - textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), secondaryColor) + textComponent.add("Runtime", secondaryColor) + textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), primaryColor) } -// this::class.java.declaredFields.forEachIndexed { index, field -> -// field.isAccessible = true -// val name = field.name -// val value = field.get(this) -// -//// if (index.mod(6) == 0) { -//// textComponent.addLine("", primaryColor) -//// repeat(depth) { -//// textComponent.add(" ") -//// } -//// } -// -// value?.let { -// if (!ActivityManagerHud.anonymize -// || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) -// ) { -// textComponent.add(name.capitalize(), primaryColor) -// when (value) { -// is ItemBlock -> { -// textComponent.add(value.block.localizedName, secondaryColor) -// } -// else -> { -// textComponent.add(value.toString(), secondaryColor) -// } + + if (details) { + this::class.java.declaredFields.forEachIndexed { index, field -> + field.isAccessible = true + val name = field.name + val value = field.get(this) + +// if (index.mod(6) == 0) { +// textComponent.addLine("", primaryColor) +// repeat(depth) { +// textComponent.add(" ") // } // } -// } -// } + + value?.let { + if (!ActivityManagerHud.anonymize + || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) + ) { + textComponent.add(name.capitalize(), primaryColor) + when (value) { + is ItemBlock -> { + textComponent.add(value.block.localizedName, secondaryColor) + } + else -> { + textComponent.add(value.toString(), secondaryColor) + } + } + } + } + } + } } + addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") // subActivities.filter { !(it is BuildBlock && it.activityStatus == ActivityStatus.UNINITIALIZED) }.forEach { @@ -249,7 +259,7 @@ abstract class Activity(val isRoot: Boolean = false) { repeat(depth) { textComponent.add(" ") } - it.appendInfo(textComponent, primaryColor, secondaryColor) + it.appendInfo(textComponent, primaryColor, secondaryColor, details) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 1d1a30e6e..1ebf54365 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -8,9 +8,10 @@ import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countItem +import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item +import net.minecraft.block.BlockHorizontal import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments @@ -21,12 +22,12 @@ class BreakDownEnderChests( override var repeated: Int = 0 ) : RepeatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { - val freeSlots = player.allSlots.filter { slot -> + val freeSlots = player.inventorySlots.filter { slot -> BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) || slot.stack.isEmpty } if (freeSlots.isEmpty()) { - if (player.allSlots.countItem(Blocks.OBSIDIAN.item) > 0) { + if (player.inventorySlots.countItem(Blocks.OBSIDIAN.item) > 0) { addSubActivities( StoreItemToShulkerBox(Blocks.OBSIDIAN.item) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 72da6389e..17e7c5020 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -81,8 +81,10 @@ class BuildBlock( (targetState != Blocks.AIR.defaultState && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) ?: AxisAlignedBB(blockPos))) -> { if (addActivities) { + val trueTarget = if (currentState.isLiquid) BuildTools.defaultFillerMat.defaultState else targetState + addSubActivities( - PlaceBlock(blockPos, if (currentState.isLiquid) BuildTools.defaultFillerMat.defaultState else targetState, BuildTools.doPending) + PlaceBlock(blockPos, trueTarget, BuildTools.doPending) ) } else { action = when { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index fcda1a4cb..25b53c8f0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -42,7 +42,7 @@ class BreakBlock( private val miningSpeedFactor: Float = 1.0f, private val minCollectAmount: Int = 1, override var timeout: Long = 200L, - override val maxAttempts: Int = 8, + override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), override var rotation: Vec2f = Vec2f.ZERO @@ -124,6 +124,7 @@ class BreakBlock( safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener if (owner.status == Status.PENDING) return@safeListener + if (subActivities.isNotEmpty()) return@safeListener getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> rotation = getRotationTo(getHitVec(blockPos, side)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index c464a3b8b..ce181ecb8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -12,6 +12,7 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing +import com.lambda.client.module.modules.client.BuildTools.directionForce import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.items.blockBlacklist @@ -23,22 +24,25 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.BlockColored +import net.minecraft.block.properties.PropertyDirection import net.minecraft.block.state.IBlockState import net.minecraft.item.EnumDyeColor import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult +import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand -import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class PlaceBlock( private val blockPos: BlockPos, - private val targetState: IBlockState, // TODO: Calculate correct resulting state of placed block to enable rotation checks + private val targetState: IBlockState, private val doPending: Boolean = false, + private val ignoreDirection: Boolean = false, + private val ignoreProperties: Boolean = false, override var rotation: Vec2f = Vec2f.ZERO, override val timeout: Long = 200L, - override val maxAttempts: Int = 8, + override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { @@ -47,45 +51,75 @@ class PlaceBlock( ColorHolder(35, 188, 254) ).also { toRender.add(it) } + private var spoofedDirection = false + override fun SafeClientEvent.onInitialize() { if (world.getBlockState(blockPos) == targetState) { success() return } - if (!world.isPlaceable(blockPos, AxisAlignedBB(blockPos))) { - addSubActivities(BreakBlock(blockPos)) + if (ignoreProperties && world.getBlockState(blockPos).block == targetState.block) { + success() return } - if (targetState.block is BlockColored) { - targetState.properties.entries.firstOrNull { it.key == BlockColored.COLOR }?.let { entry -> - val meta = (entry.value as EnumDyeColor).metadata + if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { + if (world.worldBorder.contains(blockPos) + && !world.isOutsideBuildHeight(blockPos)) { + addSubActivities(BreakBlock(blockPos)) + } else { + failedWith(BlockOutsideOfWorldException(blockPos)) + } - if (player.getHeldItem(EnumHand.MAIN_HAND).metadata != meta) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item, predicateItem = { - it.metadata == meta - })) - return - } + return + } + + targetState.properties.entries.firstOrNull { it.key is PropertyDirection }?.let { entry -> + val direction = (entry.value as EnumFacing).opposite + + if (directionForce + && !ignoreDirection + && !spoofedDirection + && player.horizontalFacing != direction + ) { + addSubActivities(Rotate(Vec2f(direction.horizontalAngle, player.rotationPitch))) + return } - } else if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { + } + + targetState.properties.entries.firstOrNull { it.key == BlockColored.COLOR }?.let { entry -> + val meta = (entry.value as EnumDyeColor).metadata + + if (player.getHeldItem(EnumHand.MAIN_HAND).metadata != meta) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item, predicateItem = { + it.metadata == meta + })) + return + } + } + + if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { addSubActivities(AcquireItemInActiveHand(targetState.block.item)) return } - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = BuildTools.maxReach)?.let { - val placedAtBlock = world.getBlockState(it.pos).block + getNeighbour( + blockPos, + attempts = BuildTools.placementSearch, + visibleSideCheck = BuildTools.illegalPlacements, + range = BuildTools.maxReach + )?.let { + val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist renderActivity.color = ColorHolder(11, 66, 89) - if (placedAtBlock in blockBlacklist) { + if (isBlacklisted) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } rotation = getRotationTo(it.hitVec) -// connection.sendPacket(it.toPlacePacket(EnumHand.MAIN_HAND)) val result = playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) if (result != EnumActionResult.SUCCESS) { @@ -95,7 +129,7 @@ class PlaceBlock( player.swingArm(EnumHand.MAIN_HAND) - if (placedAtBlock in blockBlacklist) { + if (isBlacklisted) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } @@ -107,8 +141,16 @@ class PlaceBlock( } } } ?: run { - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) -// failedWith(NoNeighbourException(blockPos)) + getNeighbour( + blockPos, + attempts = BuildTools.placementSearch, + visibleSideCheck = false, + range = 256f + )?.let { + if (autoPathing) addSubActivities(PlaceGoal(it.pos)) + } ?: run { + failedWith(NoNeighbourException(blockPos)) + } } } @@ -116,9 +158,19 @@ class PlaceBlock( safeListener { if (it.packet is SPacketBlockChange && it.packet.blockPosition == blockPos - && it.packet.blockState == targetState + && subActivities.isEmpty() ) { - success() + when { + it.packet.blockState == targetState -> { + success() + } + ignoreProperties && it.packet.blockState.block == targetState.block -> { + success() + } + else -> { + failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) + } + } } } } @@ -130,6 +182,10 @@ class PlaceBlock( owner.status = Status.PENDING } } + is Rotate -> { + spoofedDirection = true + status = Status.UNINITIALIZED + } else -> { status = Status.UNINITIALIZED } @@ -138,4 +194,6 @@ class PlaceBlock( class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") + class UnexpectedBlockStateException(blockPos: BlockPos, expected: IBlockState, actual: IBlockState) : Exception("Unexpected block state at (${blockPos.asString()}) expected $expected but got $actual") + class BlockOutsideOfWorldException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt new file mode 100644 index 000000000..940241c4f --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt @@ -0,0 +1,19 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.safeListener +import net.minecraftforge.fml.common.gameevent.TickEvent + +class Rotate( + override var rotation: Vec2f +) : RotatingActivity, Activity() { + init { + safeListener { + if (it.phase != TickEvent.Phase.END) return@safeListener + + success() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index 844467566..c4aee0fd5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -24,16 +24,19 @@ class PlaceContainer( } } - addSubActivities( - PlaceBlock(containerPos, targetState) - ) + addSubActivities(PlaceBlock( + containerPos, + targetState, + ignoreDirection = true, + ignoreProperties = true + )) } override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { if (childActivities.firstOrNull() !is PlaceBlock) return false - if (childException !is PlaceBlock.NoNeighbourException) return false - checkAttempt(this@PlaceContainer, NoContainerPlacePositionFoundException()) + checkAttempt(this@PlaceContainer, childException) + containerPos = BlockPos.ORIGIN return true } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 26b3c93f6..79a030084 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -27,7 +27,7 @@ class PickUpEntityItem( return@safeListener } - if (player.openContainer.inventorySlots.countEmpty() > 0) { + if (player.inventorySlots.countEmpty() > 0) { BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalBlock(entityItem.position)) return@safeListener } diff --git a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt index a0686c269..e6462887f 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt @@ -36,6 +36,10 @@ object BuildToolsCommand : ClientCommand( } } } + + execute("Lists all ignored blocks") { + MessageSendHelper.sendChatMessage("Ignored blocks: ${BuildTools.ignoreBlocks.joinToString(", ")}") + } } literal("eject") { @@ -64,6 +68,10 @@ object BuildToolsCommand : ClientCommand( } } } + + execute("Lists all blocks in eject list") { + MessageSendHelper.sendChatMessage("Eject list: ${BuildTools.ejectList.joinToString(", ")}") + } } literal("food") { @@ -73,6 +81,10 @@ object BuildToolsCommand : ClientCommand( MessageSendHelper.sendChatMessage("Set food item to &7${itemArg.value.registryName}&r.") } } + + execute("Shows the food item") { + MessageSendHelper.sendChatMessage("Food item: &7${BuildTools.defaultFood.registryName}&r") + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt similarity index 79% rename from src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt rename to src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt index 39978c837..8f9d9a43d 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt @@ -1,4 +1,4 @@ -package com.lambda.client.gui.hudgui.elements.misc +package com.lambda.client.gui.hudgui.elements.client import com.lambda.client.activity.Activity import com.lambda.client.event.ListenerManager @@ -13,6 +13,7 @@ internal object ActivityManagerHud: LabelHud( description = "Display current activities." ) { val anonymize by setting("Anonymize", false) + private val details by setting("Details", false) private var startTime = 0L override fun SafeClientEvent.updateText() { @@ -24,14 +25,14 @@ internal object ActivityManagerHud: LabelHud( if (startTime == 0L) startTime = System.currentTimeMillis() with(ActivityManager) { - displayText.add("Runtime:", primaryColor) - displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), secondaryColor) - displayText.add("Amount:", primaryColor) - displayText.add(ActivityManager.allSubActivities.size.toString(), secondaryColor) - displayText.add("Current:", primaryColor) - displayText.addLine(getCurrentActivity().activityName, secondaryColor) - - appendInfo(displayText, primaryColor, secondaryColor) + displayText.add("Runtime", secondaryColor) + displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), primaryColor) + displayText.add("Amount", secondaryColor) + displayText.add(ActivityManager.allSubActivities.size.toString(), primaryColor) + displayText.add("Current", secondaryColor) + displayText.addLine(getCurrentActivity().activityName, primaryColor) + + appendInfo(displayText, primaryColor, secondaryColor, details) } val sync = ListenerManager.listenerMap.keys.filterIsInstance() diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 976c00feb..057240f76 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -45,7 +45,8 @@ object BuildTools : Module( val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") val executionCountPerTick by setting("Executions Per Tick", 100, 0..200, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") -// val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.PLACING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") + val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BUILDING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") + val directionForce by setting("Block Direction Exploit", true, { page == Page.BUILDING }, description = "EXPLOIT: Forces the direction of the block to be placed") /* storage management */ // val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt index b375a1acb..99a452cbf 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt @@ -34,6 +34,11 @@ object BlockData : Module( val tag = NBTTagCompound().apply { tileEntity.writeToNBT(this) } MessageSendHelper.sendChatMessage("""$chatName &6Block Tags:$tag""".trimIndent()) } + + if (blockState.properties.isNotEmpty()) { + val properties = blockState.properties.entries.joinToString(", ") { "${it.key}=${it.value}" } + MessageSendHelper.sendChatMessage("""$chatName &6Block Properties: $properties""".trimIndent()) + } } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index fc801d5c0..8968834e9 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -26,24 +26,27 @@ object HighwayTools : Module( ) { private val structure by setting("Structure", Structure.HIGHWAY, description = "Choose the structure") private val width by setting("Width", 6, 1..50, 1, description = "Sets the width of blueprint", unit = " blocks") - private val height by setting("Height", 4, 2..10, 1, { clearSpace }, description = "Sets height of blueprint", unit = " blocks") + private val height by setting("Height", 4, 2..10, 1, description = "Sets height of blueprint", unit = " blocks") + private val offset by setting("Offset", 0, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") + private val rainbowMode by setting("Rainbow Mode", false, description = "Rainbow highway uwu") + private val backfill by setting("Backfill", false, { structure == Structure.TUNNEL }, description = "Fills the tunnel behind you") - private val clearSpace by setting("Clear Space", true, { structure == Structure.HIGHWAY }, description = "Clears out the tunnel if necessary") - private val cleanFloor by setting("Clean Floor", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") - private val cleanRightWall by setting("Clean Right Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the right wall") - private val cleanLeftWall by setting("Clean Left Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the left wall") - private val cleanRoof by setting("Clean Roof", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") - private val cleanCorner by setting("Clean Corner", false, { structure == Structure.TUNNEL && !cornerBlock && !backfill && width > 2 }, description = "Cleans up the tunnels corner") + private val fillFloor by setting("Fill Floor", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") + private val fillRightWall by setting("Fill Right Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the right wall") + private val fillLeftWall by setting("Fill Left Wall", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the left wall") + private val fillRoof by setting("Fill Roof", false, { structure == Structure.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") + private val fillCorner by setting("Fill Corner", false, { structure == Structure.TUNNEL && !cornerBlock && !backfill && width > 2 }, description = "Cleans up the tunnels corner") private val cornerBlock by setting("Corner Block", false, { structure == Structure.HIGHWAY || (structure == Structure.TUNNEL && !backfill && width > 2) }, description = "If activated will break the corner in tunnel or place a corner while paving") - private val railing by setting("Railing", true, { structure == Structure.HIGHWAY }, description = "Adds a railing/rim/border to the highway") - private val railingHeight by setting("Railing Height", 1, 1..4, 1, { structure == Structure.HIGHWAY && railing }, description = "Sets height of railing", unit = " blocks") - private val offset by setting("Offset", 0, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") - private val rainbowMode by setting("Rainbow Mode", false, description = "Rainbow mode for the structure") + private val railingHeight by setting("Railing Height", 1, 0..4, 1, { structure == Structure.HIGHWAY }, description = "Sets height of railing", unit = " blocks") enum class Structure { HIGHWAY, TUNNEL } + private enum class Pages { + GENERAL, CLEAN_UP, MATERIALS + } + private var originDirection = Direction.NORTH private var originOrthogonalDirection = Direction.NORTH private var originPosition = BlockPos.ORIGIN @@ -89,19 +92,19 @@ object HighwayTools : Module( for (x in -5..5) { val thisPos = originPosition.add(originDirection.directionVec.multiply(x)) - if (clearSpace) generateClear(blueprint, thisPos) + generateClear(blueprint, thisPos) if (structure == Structure.TUNNEL) { - if (cleanFloor) generateFloor(blueprint, thisPos) - if (cleanRightWall || cleanLeftWall) generateWalls(blueprint, thisPos) - if (cleanRoof) generateRoof(blueprint, thisPos) - if (cleanCorner && !cornerBlock && width > 2) generateCorner(blueprint, thisPos) + if (fillFloor) generateFloor(blueprint, thisPos) + if (fillRightWall || fillLeftWall) generateWalls(blueprint, thisPos) + if (fillRoof) generateRoof(blueprint, thisPos) + if (fillCorner && !cornerBlock && width > 2) generateCorner(blueprint, thisPos) } else { generateBase(blueprint, thisPos) } } - if (structure == Structure.TUNNEL && (!cleanFloor || backfill)) { + if (structure == Structure.TUNNEL && (!fillFloor || backfill)) { if (originDirection.isDiagonal) { for (x in 0..width) { val pos = originPosition.add(originDirection.directionVec.multiply(x)) @@ -174,8 +177,8 @@ object HighwayTools : Module( 0 } for (h in cb until height) { - if (cleanRightWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(width - width / 2)).up(h + 1)] = fillerState() - if (cleanLeftWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(-1 - width / 2)).up(h + 1)] = fillerState() + if (fillRightWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(width - width / 2)).up(h + 1)] = fillerState() + if (fillLeftWall) blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(-1 - width / 2)).up(h + 1)] = fillerState() } } @@ -192,7 +195,7 @@ object HighwayTools : Module( blueprint[basePos.add(originOrthogonalDirection.directionVec.multiply(width - width / 2 - 1)).up()] = fillerState() } - private fun isRail(w: Int) = railing && w !in 1 until width - 1 + private fun isRail(w: Int) = railingHeight > 0 && w !in 1 until width - 1 private fun SafeClientEvent.printEnable() { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 6be32c388..91753f511 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -8,8 +8,11 @@ import com.lambda.client.activity.activities.interaction.* import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.commons.extension.next import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category @@ -21,13 +24,16 @@ import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe +import net.minecraft.block.BlockHorizontal import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items +import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos object TestActivityManager : Module( @@ -63,6 +69,26 @@ object TestActivityManager : Module( false }) + private val eticiettie by setting("Direction shenanigans", false, consumer = { _, _-> + runSafe { + var currentDirection = player.horizontalFacing + var position = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) + + repeat(4) { + val targetState = Blocks.MAGENTA_GLAZED_TERRACOTTA.defaultState.withProperty(BlockHorizontal.FACING, currentDirection) + + ActivityManager.addSubActivities( + PlaceBlock(position, targetState) + ) + + currentDirection = currentDirection.rotateY() + position = position.add(currentDirection.directionVec) + } + } + + false + }) + private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> ActivityManager.addSubActivities( AcquireItemInActiveHand( diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt b/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt index 2a3d15395..aab031e72 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/PacketLogger.kt @@ -202,7 +202,7 @@ object PacketLogger : Module( is SPacketBlockChange -> { logServer(packet) { "blockPosition" to packet.blockPosition - "block" to packet.blockState.block.localizedName + "blockState" to packet.blockState } } is SPacketCamera -> { diff --git a/src/main/kotlin/com/lambda/client/util/world/Check.kt b/src/main/kotlin/com/lambda/client/util/world/Check.kt index 96b5c7d6c..1294daa31 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Check.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Check.kt @@ -106,6 +106,8 @@ fun SafeClientEvent.hasNeighbour(pos: BlockPos): Boolean { * * @return true playing is not colliding with [pos] and there is block below it */ -fun World.isPlaceable(pos: BlockPos, targetBoundingBox: AxisAlignedBB, ignoreSelfCollide: Boolean = false) = - this.getBlockState(pos).isReplaceable - && this.checkNoEntityCollision(targetBoundingBox, if (ignoreSelfCollide) Wrapper.player else null) \ No newline at end of file +fun World.isPlaceable(pos: BlockPos, resultingBoundingBox: AxisAlignedBB, ignoreSelfCollide: Boolean = false) = + getBlockState(pos).isReplaceable + && checkNoEntityCollision(resultingBoundingBox, if (ignoreSelfCollide) Wrapper.player else null) + && worldBorder.contains(pos) + && !isOutsideBuildHeight(pos) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/world/Interact.kt b/src/main/kotlin/com/lambda/client/util/world/Interact.kt index d1a8c384e..723a28492 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Interact.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Interact.kt @@ -84,7 +84,7 @@ private fun SafeClientEvent.getNeighbour( sides: Array, toIgnore: HashSet> ): PlaceInfo? { - if (!world.isPlaceable(pos)) return null + if (!world.isPlaceable(pos, AxisAlignedBB(pos))) return null sides.forEach { side -> checkNeighbour(eyePos, pos, side, range, visibleSideCheck, true, toIgnore)?.let { @@ -99,7 +99,7 @@ private fun SafeClientEvent.getNeighbour( sides.forEach { posSide -> val newPos = pos.offset(posSide) - if (!world.isPlaceable(newPos)) return@forEach + if (!world.isPlaceable(newPos, AxisAlignedBB(newPos))) return@forEach if (eyePos.distanceTo(newPos.toVec3dCenter()) > range + 1) return@forEach getNeighbour(eyePos, newPos, attempts - 1, range, visibleSideCheck, sides, toIgnore)?.let { From 52e691c9a39cd20dfa8bc620bb34adce2059f476 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:45:34 -0800 Subject: [PATCH 054/104] Schematica API --- build.gradle | 10 ++++++ .../schematic/LambdaSchematicaHelper.java | 26 ++++++++++++++ .../java/com/lambda/schematic/Schematic.java | 26 ++++++++++++++ .../lambda/schematic/SchematicAdapter.java | 35 +++++++++++++++++++ .../lunatrius/core/util/math/MBlockPos.java | 24 +++++++++++++ .../lunatrius/schematica/Schematica.java | 7 ++++ .../lunatrius/schematica/api/ISchematic.java | 11 ++++++ .../client/world/SchematicWorld.java | 12 +++++++ .../schematica/proxy/ClientProxy.java | 7 ++++ .../schematica/proxy/CommonProxy.java | 5 +++ 10 files changed, 163 insertions(+) create mode 100644 src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java create mode 100644 src/main/java/com/lambda/schematic/Schematic.java create mode 100644 src/main/java/com/lambda/schematic/SchematicAdapter.java create mode 100644 src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java create mode 100644 src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java diff --git a/build.gradle b/build.gradle index 9d7dfe2be..060d4a188 100644 --- a/build.gradle +++ b/build.gradle @@ -120,6 +120,16 @@ dependencies { implementation configurations.jarLibs } +sourceSets { + schematica_api { + compileClasspath += main.compileClasspath + } + + main { + compileClasspath += schematica_api.output + } +} + mixin { defaultObfuscationEnv 'searge' sourceSets { diff --git a/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java b/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java new file mode 100644 index 000000000..e460e8395 --- /dev/null +++ b/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java @@ -0,0 +1,26 @@ +package com.lambda.schematic; + +import com.github.lunatrius.schematica.Schematica; +import com.github.lunatrius.schematica.proxy.ClientProxy; +import net.minecraft.util.Tuple; +import net.minecraft.util.math.BlockPos; + +import java.util.Optional; + +public class LambdaSchematicaHelper { + + public static boolean isSchematicaPresent() { + try { + Class.forName(Schematica.class.getName()); + return true; + } catch (ClassNotFoundException | NoClassDefFoundError ex) { + return false; + } + } + + public static Optional> getOpenSchematic() { + return Optional.ofNullable(ClientProxy.schematic) + .map(world -> new Tuple<>(new SchematicAdapter(world), world.position)); + } + +} diff --git a/src/main/java/com/lambda/schematic/Schematic.java b/src/main/java/com/lambda/schematic/Schematic.java new file mode 100644 index 000000000..499d27930 --- /dev/null +++ b/src/main/java/com/lambda/schematic/Schematic.java @@ -0,0 +1,26 @@ +package com.lambda.schematic; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public interface Schematic { + default IBlockState desiredState(int x, int y, int z) { + return desiredState(new BlockPos(x, y, z)); + } + + IBlockState desiredState(BlockPos pos); + + default boolean inSchematic(BlockPos pos) { + return inSchematic(pos.getX(), pos.getY(), pos.getZ()); + } + + default boolean inSchematic(int x, int y, int z) { + return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ(); + } + + int widthX(); + + int heightY(); + + int lengthZ(); +} \ No newline at end of file diff --git a/src/main/java/com/lambda/schematic/SchematicAdapter.java b/src/main/java/com/lambda/schematic/SchematicAdapter.java new file mode 100644 index 000000000..b2bcef1a8 --- /dev/null +++ b/src/main/java/com/lambda/schematic/SchematicAdapter.java @@ -0,0 +1,35 @@ +package com.lambda.schematic; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + + +public final class SchematicAdapter implements Schematic { + + private final SchematicWorld schematic; + + public SchematicAdapter(SchematicWorld schematicWorld) { + this.schematic = schematicWorld; + } + + @Override + public IBlockState desiredState(BlockPos pos) { + return schematic.getSchematic().getBlockState(pos); + } + + @Override + public int widthX() { + return schematic.getSchematic().getWidth(); + } + + @Override + public int heightY() { + return schematic.getSchematic().getHeight(); + } + + @Override + public int lengthZ() { + return schematic.getSchematic().getLength(); + } +} \ No newline at end of file diff --git a/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java new file mode 100644 index 000000000..5fe69bcf0 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java @@ -0,0 +1,24 @@ +package com.github.lunatrius.core.util.math; + +import net.minecraft.util.math.BlockPos; + +public class MBlockPos extends BlockPos { + MBlockPos() { + super(0, 0, 0); + } + + @Override + public int getX() { + return 0; + } + + @Override + public int getY() { + return 0; + } + + @Override + public int getZ() { + return 0; + } +} \ No newline at end of file diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java new file mode 100644 index 000000000..eec4da7be --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java @@ -0,0 +1,7 @@ +package com.github.lunatrius.schematica; + +import com.github.lunatrius.schematica.proxy.CommonProxy; + +public class Schematica { + public static CommonProxy proxy; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java new file mode 100644 index 000000000..071f752a2 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java @@ -0,0 +1,11 @@ +package com.github.lunatrius.schematica.api; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public interface ISchematic { + IBlockState getBlockState(BlockPos blockPos); + int getWidth(); + int getHeight(); + int getLength(); +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java new file mode 100644 index 000000000..860bd2ad6 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java @@ -0,0 +1,12 @@ +package com.github.lunatrius.schematica.client.world; + +import com.github.lunatrius.core.util.math.MBlockPos; +import com.github.lunatrius.schematica.api.ISchematic; + +public class SchematicWorld { + public final MBlockPos position = null; + + public ISchematic getSchematic() { + return null; + } +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java new file mode 100644 index 000000000..79a55132e --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java @@ -0,0 +1,7 @@ +package com.github.lunatrius.schematica.proxy; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; + +public class ClientProxy extends CommonProxy { + public static SchematicWorld schematic; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java new file mode 100644 index 000000000..e400c815a --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java @@ -0,0 +1,5 @@ +package com.github.lunatrius.schematica.proxy; + +public abstract class CommonProxy { + +} From 5f0b980cf2e25897479e7bacdb2cfe1fd2775312 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 27 Jan 2023 21:51:54 -0800 Subject: [PATCH 055/104] Build schematic activity BuildStructure seems to be broken somewhat but I checked the structure is created and looks correct --- .../schematic/LambdaSchematicaHelper.java | 26 --------- .../java/com/lambda/schematic/Schematic.java | 26 --------- .../lambda/schematic/SchematicAdapter.java | 35 ------------ .../modules/misc/TestActivityManager.kt | 56 +++++++++++++++++-- .../util/schematic/LambdaSchematicaHelper.kt | 23 ++++++++ .../lambda/client/util/schematic/Schematic.kt | 20 +++++++ .../client/util/schematic/SchematicAdapter.kt | 35 ++++++++++++ .../com/lambda/client/util/world/Check.kt | 7 +-- 8 files changed, 132 insertions(+), 96 deletions(-) delete mode 100644 src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java delete mode 100644 src/main/java/com/lambda/schematic/Schematic.java delete mode 100644 src/main/java/com/lambda/schematic/SchematicAdapter.java create mode 100644 src/main/kotlin/com/lambda/client/util/schematic/LambdaSchematicaHelper.kt create mode 100644 src/main/kotlin/com/lambda/client/util/schematic/Schematic.kt create mode 100644 src/main/kotlin/com/lambda/client/util/schematic/SchematicAdapter.kt diff --git a/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java b/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java deleted file mode 100644 index e460e8395..000000000 --- a/src/main/java/com/lambda/schematic/LambdaSchematicaHelper.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.lambda.schematic; - -import com.github.lunatrius.schematica.Schematica; -import com.github.lunatrius.schematica.proxy.ClientProxy; -import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; - -import java.util.Optional; - -public class LambdaSchematicaHelper { - - public static boolean isSchematicaPresent() { - try { - Class.forName(Schematica.class.getName()); - return true; - } catch (ClassNotFoundException | NoClassDefFoundError ex) { - return false; - } - } - - public static Optional> getOpenSchematic() { - return Optional.ofNullable(ClientProxy.schematic) - .map(world -> new Tuple<>(new SchematicAdapter(world), world.position)); - } - -} diff --git a/src/main/java/com/lambda/schematic/Schematic.java b/src/main/java/com/lambda/schematic/Schematic.java deleted file mode 100644 index 499d27930..000000000 --- a/src/main/java/com/lambda/schematic/Schematic.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.lambda.schematic; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; - -public interface Schematic { - default IBlockState desiredState(int x, int y, int z) { - return desiredState(new BlockPos(x, y, z)); - } - - IBlockState desiredState(BlockPos pos); - - default boolean inSchematic(BlockPos pos) { - return inSchematic(pos.getX(), pos.getY(), pos.getZ()); - } - - default boolean inSchematic(int x, int y, int z) { - return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ(); - } - - int widthX(); - - int heightY(); - - int lengthZ(); -} \ No newline at end of file diff --git a/src/main/java/com/lambda/schematic/SchematicAdapter.java b/src/main/java/com/lambda/schematic/SchematicAdapter.java deleted file mode 100644 index b2bcef1a8..000000000 --- a/src/main/java/com/lambda/schematic/SchematicAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.lambda.schematic; - -import com.github.lunatrius.schematica.client.world.SchematicWorld; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; - - -public final class SchematicAdapter implements Schematic { - - private final SchematicWorld schematic; - - public SchematicAdapter(SchematicWorld schematicWorld) { - this.schematic = schematicWorld; - } - - @Override - public IBlockState desiredState(BlockPos pos) { - return schematic.getSchematic().getBlockState(pos); - } - - @Override - public int widthX() { - return schematic.getSchematic().getWidth(); - } - - @Override - public int heightY() { - return schematic.getSchematic().getHeight(); - } - - @Override - public int lengthZ() { - return schematic.getSchematic().getLength(); - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 91753f511..e1bb419c2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -3,10 +3,13 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly -import com.lambda.client.activity.activities.highlevel.* -import com.lambda.client.activity.activities.interaction.* -import com.lambda.client.activity.activities.inventory.DumpInventory +import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests +import com.lambda.client.activity.activities.highlevel.BuildStructure +import com.lambda.client.activity.activities.highlevel.ReachXPLevel +import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox @@ -24,7 +27,8 @@ import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item import com.lambda.client.util.math.VectorUtils -import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.schematic.LambdaSchematicaHelper +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockHorizontal import net.minecraft.block.BlockShulkerBox @@ -38,7 +42,7 @@ import net.minecraft.util.math.BlockPos object TestActivityManager : Module( name = "TestActivityManager", - description = "", + description = "a", category = Category.MISC ) { private val a by setting("Get any Dia Pickaxe", false, consumer = { _, _-> @@ -148,6 +152,48 @@ object TestActivityManager : Module( false }) + private val schematicBuild by setting("Build Schematic", false, consumer = { _, _ -> + runSafe { + schematicBuildActivity(true) + } + false + }) + + private val schematicBuildSkipAir by setting("Build Schematic (Skip Air)", false, consumer = { _, _ -> + runSafe { + schematicBuildActivity(false) + } + false + }) + + private fun schematicBuildActivity(buildAir: Boolean) { + if (LambdaSchematicaHelper.isSchematicaPresent) { + LambdaSchematicaHelper.loadedSchematic?.let { schematic -> + val structure = mutableMapOf() + for (y in schematic.getOrigin().y..schematic.getOrigin().y + schematic.heightY()) { + for (x in schematic.getOrigin().x..schematic.getOrigin().x + schematic.widthX()) { + for (z in schematic.getOrigin().z..schematic.getOrigin().z + schematic.lengthZ()) { + val blockPos = BlockPos(x, y, z) + if (!schematic.inSchematic(blockPos)) continue // probably not necessary to check + val desiredBlockState = schematic.desiredState(blockPos) + if (desiredBlockState.block == Blocks.AIR && buildAir) continue + structure[blockPos] = desiredBlockState + } + } + } + // potentially beeg log +// LambdaMod.LOG.info("Building structure $structure") + ActivityManager.addSubActivities( + BuildStructure(structure) + ) + } ?: run { + MessageSendHelper.sendChatMessage("No schematic is loaded") + } + } else { + MessageSendHelper.sendChatMessage("Schematica is not present") + } + } + private val ctirsgn by setting("Throw", false, consumer = { _, _-> runSafe { ActivityManager.addSubActivities( diff --git a/src/main/kotlin/com/lambda/client/util/schematic/LambdaSchematicaHelper.kt b/src/main/kotlin/com/lambda/client/util/schematic/LambdaSchematicaHelper.kt new file mode 100644 index 000000000..0fce63ca9 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/util/schematic/LambdaSchematicaHelper.kt @@ -0,0 +1,23 @@ +package com.lambda.client.util.schematic + +import com.github.lunatrius.schematica.Schematica +import com.github.lunatrius.schematica.proxy.ClientProxy + +object LambdaSchematicaHelper { + val isSchematicaPresent: Boolean + get() = try { + Class.forName(Schematica::class.java.name) + true + } catch (ex: ClassNotFoundException) { + false + } catch (ex: NoClassDefFoundError) { + false + } + + val loadedSchematic: Schematic? + get() { + return ClientProxy.schematic?.let { + SchematicAdapter(it) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/schematic/Schematic.kt b/src/main/kotlin/com/lambda/client/util/schematic/Schematic.kt new file mode 100644 index 000000000..5d1d56774 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/util/schematic/Schematic.kt @@ -0,0 +1,20 @@ +package com.lambda.client.util.schematic + +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +interface Schematic { + fun desiredState(x: Int, y: Int, z: Int): IBlockState { + return desiredState(BlockPos(x, y, z)) + } + + fun desiredState(pos: BlockPos): IBlockState + + fun inSchematic(pos: BlockPos): Boolean + fun inSchematic(x: Int, y: Int, z: Int): Boolean + + fun widthX(): Int + fun heightY(): Int + fun lengthZ(): Int + fun getOrigin(): BlockPos +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/schematic/SchematicAdapter.kt b/src/main/kotlin/com/lambda/client/util/schematic/SchematicAdapter.kt new file mode 100644 index 000000000..527d2e8b5 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/util/schematic/SchematicAdapter.kt @@ -0,0 +1,35 @@ +package com.lambda.client.util.schematic + +import com.github.lunatrius.schematica.client.world.SchematicWorld +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class SchematicAdapter(private val schematic: SchematicWorld) : Schematic { + override fun desiredState(pos: BlockPos): IBlockState { + return schematic.schematic.getBlockState(BlockPos(pos.x - getOrigin().x, pos.y - getOrigin().y, pos.z - getOrigin().z)) + } + + override fun widthX(): Int { + return schematic.schematic.width + } + + override fun heightY(): Int { + return schematic.schematic.height + } + + override fun lengthZ(): Int { + return schematic.schematic.length + } + + override fun getOrigin(): BlockPos { + return schematic.position + } + + override fun inSchematic(pos: BlockPos): Boolean { + return inSchematic(pos.x, pos.y, pos.z) + } + + override fun inSchematic(x: Int, y: Int, z: Int): Boolean { + return x >= schematic.position.x && x < schematic.position.x + widthX() && y >= schematic.position.y && y < schematic.position.y + heightY() && z >= schematic.position.z && z < schematic.position.z + lengthZ() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/util/world/Check.kt b/src/main/kotlin/com/lambda/client/util/world/Check.kt index 1294daa31..4c9f54e90 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Check.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Check.kt @@ -3,7 +3,6 @@ package com.lambda.client.util.world import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.Wrapper import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.util.EnumFacing import net.minecraft.util.math.AxisAlignedBB @@ -106,8 +105,8 @@ fun SafeClientEvent.hasNeighbour(pos: BlockPos): Boolean { * * @return true playing is not colliding with [pos] and there is block below it */ -fun World.isPlaceable(pos: BlockPos, resultingBoundingBox: AxisAlignedBB, ignoreSelfCollide: Boolean = false) = - getBlockState(pos).isReplaceable - && checkNoEntityCollision(resultingBoundingBox, if (ignoreSelfCollide) Wrapper.player else null) +fun World.isPlaceable(pos: BlockPos, targetBoundingBox: AxisAlignedBB = AxisAlignedBB(pos), ignoreSelfCollide: Boolean = false) = + this.getBlockState(pos).isReplaceable + && checkNoEntityCollision(targetBoundingBox, if (ignoreSelfCollide) Wrapper.player else null) && worldBorder.contains(pos) && !isOutsideBuildHeight(pos) \ No newline at end of file From 0a3ed434ba4f573e5056657aa53caa5380d4fa3e Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 27 Jan 2023 21:55:46 -0800 Subject: [PATCH 056/104] rename --- .../client/module/modules/misc/TestActivityManager.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index e1bb419c2..914398dcb 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -154,19 +154,19 @@ object TestActivityManager : Module( private val schematicBuild by setting("Build Schematic", false, consumer = { _, _ -> runSafe { - schematicBuildActivity(true) + schematicBuildActivity(false) } false }) private val schematicBuildSkipAir by setting("Build Schematic (Skip Air)", false, consumer = { _, _ -> runSafe { - schematicBuildActivity(false) + schematicBuildActivity(true) } false }) - private fun schematicBuildActivity(buildAir: Boolean) { + private fun schematicBuildActivity(skipAir: Boolean) { if (LambdaSchematicaHelper.isSchematicaPresent) { LambdaSchematicaHelper.loadedSchematic?.let { schematic -> val structure = mutableMapOf() @@ -176,7 +176,7 @@ object TestActivityManager : Module( val blockPos = BlockPos(x, y, z) if (!schematic.inSchematic(blockPos)) continue // probably not necessary to check val desiredBlockState = schematic.desiredState(blockPos) - if (desiredBlockState.block == Blocks.AIR && buildAir) continue + if (desiredBlockState.block == Blocks.AIR && skipAir) continue structure[blockPos] = desiredBlockState } } From 90dd2f81318eaa7be44d9c501819051c0cb9f14b Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 30 Jan 2023 07:42:09 +0100 Subject: [PATCH 057/104] Add SchematicBuilder module --- .../activities/highlevel/BuildSchematic.kt | 48 +++++++++++++++++ .../activities/highlevel/BuildStructure.kt | 29 +--------- .../activities/interaction/PlaceBlock.kt | 2 +- .../module/modules/misc/HighwayTools.kt | 1 + .../module/modules/misc/SchematicBuilder.kt | 53 +++++++++++++++++++ .../modules/misc/TestActivityManager.kt | 42 --------------- 6 files changed, 105 insertions(+), 70 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt new file mode 100644 index 000000000..fa5763794 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt @@ -0,0 +1,48 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.util.math.Direction +import com.lambda.client.util.schematic.LambdaSchematicaHelper +import com.lambda.client.util.schematic.Schematic +import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos + +class BuildSchematic( + private val schematic: Schematic, + private val direction: Direction = Direction.NORTH, + private val offsetMove: BlockPos = BlockPos.ORIGIN, +) : Activity() { + override fun SafeClientEvent.onInitialize() { + if (!LambdaSchematicaHelper.isSchematicaPresent) { + failedWith(SchematicNotPresentException()) + return + } + + val structure = mutableMapOf() + + for (y in schematic.getOrigin().y..schematic.getOrigin().y + schematic.heightY()) { + for (x in schematic.getOrigin().x..schematic.getOrigin().x + schematic.widthX()) { + for (z in schematic.getOrigin().z..schematic.getOrigin().z + schematic.lengthZ()) { + val blockPos = BlockPos(x, y, z) + if (!schematic.inSchematic(blockPos)) continue + structure[blockPos] = schematic.desiredState(blockPos) + } + } + } + + MessageSendHelper.sendChatMessage("$activityName Building ${structure.size} blocks") + + ActivityManager.addSubActivities( + BuildStructure( + structure, + direction, + offsetMove + ) + ) + } + + private class SchematicNotPresentException : Exception("Schematica is not present") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 0e8d64480..792574ae7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -16,6 +16,7 @@ class BuildStructure( private val structure: Map, private val direction: Direction = Direction.NORTH, private val offsetMove: BlockPos = BlockPos.ORIGIN, + private val doPadding: Boolean = false, private val respectIgnore: Boolean = false, override val toRender: MutableSet = mutableSetOf(), override val maximumRepeats: Int = 1, @@ -27,7 +28,7 @@ class BuildStructure( structure.forEach { (pos, state) -> val offsetPos = pos.add(currentOffset) - if (isInPadding(offsetPos)) return@forEach + if (doPadding && isInPadding(offsetPos)) return@forEach if (world.getBlockState(offsetPos) == state) return@forEach val activity = BuildBlock(offsetPos, state, respectIgnore) @@ -40,9 +41,6 @@ class BuildStructure( override fun SafeClientEvent.onSuccess() { currentOffset = currentOffset.add(offsetMove) -// structure.keys.asSequence().sortedBy { player.distanceTo(it.add(currentOffset)) }.firstOrNull()?.let { -// addSubActivities(CustomGoal(GoalNear(it.add(currentOffset), 2))) -// } } override fun SafeClientEvent.getCurrentActivity(): Activity { @@ -66,29 +64,6 @@ class BuildStructure( } ?: return this@BuildStructure } -// init { -// safeListener { event -> -// if (event.phase != TickEvent.Phase.START) return@safeListener -// -// structure.forEach { (pos, state) -> -// val offsetPos = pos.add(currentOffset) -// -// if (isInPadding(offsetPos)) return@forEach -// -// val blockState = world.getBlockState(offsetPos) -// -// if (blockState == state) return@forEach -// if (!blockState.isLiquid) return@forEach -// -// val activity = BuildBlock(offsetPos, state, respectIgnore) -// -// addSubActivities(activity) -// -// LambdaEventBus.subscribe(activity) -// } -// } -// } - private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) private fun isBehindPos(origin: BlockPos, check: BlockPos): Boolean { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index ce181ecb8..770d0154e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -147,7 +147,7 @@ class PlaceBlock( visibleSideCheck = false, range = 256f )?.let { - if (autoPathing) addSubActivities(PlaceGoal(it.pos)) + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) } ?: run { failedWith(NoNeighbourException(blockPos)) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 8968834e9..262d8c48b 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -74,6 +74,7 @@ object HighwayTools : Module( direction = originDirection, offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), maximumRepeats = distance, + doPadding = true, respectIgnore = true ).let { ownedBuildStructure = it diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt new file mode 100644 index 000000000..faa3935e6 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -0,0 +1,53 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.activity.activities.highlevel.BuildSchematic +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.schematic.LambdaSchematicaHelper +import com.lambda.client.util.threads.runSafe +import net.minecraft.util.math.BlockPos + +object SchematicBuilder : Module( + name = "SchematicBuilder", + description = "Build schematics", + category = Category.MISC, + alias = arrayOf("sb") +) { + private val offset by setting("Offset", 0, -10..10, 1) + + private var ownedBuildStructure: BuildSchematic? = null + + init { + onEnable { + runSafe { + LambdaSchematicaHelper.loadedSchematic?.let { schematic -> + val direction = Direction.fromEntity(player) + + BuildSchematic( + schematic, + direction, + BlockPos(direction.directionVec.multiply(offset)) + ).let { + ownedBuildStructure = it + ActivityManager.addSubActivities(it) + } + } + } + } + + onDisable { + ownedBuildStructure?.let { + with(it) { + runSafe { + success() + } + } + } + ActivityManager.reset() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 914398dcb..8e448cd0b 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -152,48 +152,6 @@ object TestActivityManager : Module( false }) - private val schematicBuild by setting("Build Schematic", false, consumer = { _, _ -> - runSafe { - schematicBuildActivity(false) - } - false - }) - - private val schematicBuildSkipAir by setting("Build Schematic (Skip Air)", false, consumer = { _, _ -> - runSafe { - schematicBuildActivity(true) - } - false - }) - - private fun schematicBuildActivity(skipAir: Boolean) { - if (LambdaSchematicaHelper.isSchematicaPresent) { - LambdaSchematicaHelper.loadedSchematic?.let { schematic -> - val structure = mutableMapOf() - for (y in schematic.getOrigin().y..schematic.getOrigin().y + schematic.heightY()) { - for (x in schematic.getOrigin().x..schematic.getOrigin().x + schematic.widthX()) { - for (z in schematic.getOrigin().z..schematic.getOrigin().z + schematic.lengthZ()) { - val blockPos = BlockPos(x, y, z) - if (!schematic.inSchematic(blockPos)) continue // probably not necessary to check - val desiredBlockState = schematic.desiredState(blockPos) - if (desiredBlockState.block == Blocks.AIR && skipAir) continue - structure[blockPos] = desiredBlockState - } - } - } - // potentially beeg log -// LambdaMod.LOG.info("Building structure $structure") - ActivityManager.addSubActivities( - BuildStructure(structure) - ) - } ?: run { - MessageSendHelper.sendChatMessage("No schematic is loaded") - } - } else { - MessageSendHelper.sendChatMessage("Schematica is not present") - } - } - private val ctirsgn by setting("Throw", false, consumer = { _, _-> runSafe { ActivityManager.addSubActivities( From a0053f8ead7d932245d06caa51fd100a24d8f7d0 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 31 Jan 2023 08:00:49 +0100 Subject: [PATCH 058/104] Creative mode support and fixes --- .../activities/highlevel/BuildBlock.kt | 4 +-- .../activities/highlevel/BuildSchematic.kt | 22 +++++++++++++-- .../activities/interaction/BreakBlock.kt | 4 ++- .../activities/interaction/PlaceBlock.kt | 28 +++++++++++++++---- .../inventory/AcquireItemInActiveHand.kt | 5 ++-- .../inventory/CreativeInventoryAction.kt | 26 +++++++++++++++++ .../module/modules/misc/SchematicBuilder.kt | 2 ++ 7 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 17e7c5020..0cedd0bf5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -67,9 +67,9 @@ class BuildBlock( } private fun SafeClientEvent.updateAction(addActivities: Boolean = false) { - val owner = owner +// val owner = owner - if (owner !is BuildStructure) return +// if (owner !is BuildStructure) return val currentState = world.getBlockState(blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt index fa5763794..e4b66c546 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.util.math.Direction import com.lambda.client.util.schematic.LambdaSchematicaHelper import com.lambda.client.util.schematic.Schematic @@ -12,6 +11,7 @@ import net.minecraft.util.math.BlockPos class BuildSchematic( private val schematic: Schematic, + private val inLayers: Boolean = true, private val direction: Direction = Direction.NORTH, private val offsetMove: BlockPos = BlockPos.ORIGIN, ) : Activity() { @@ -24,18 +24,34 @@ class BuildSchematic( val structure = mutableMapOf() for (y in schematic.getOrigin().y..schematic.getOrigin().y + schematic.heightY()) { + val layerStructure = mutableMapOf() + for (x in schematic.getOrigin().x..schematic.getOrigin().x + schematic.widthX()) { for (z in schematic.getOrigin().z..schematic.getOrigin().z + schematic.lengthZ()) { val blockPos = BlockPos(x, y, z) if (!schematic.inSchematic(blockPos)) continue - structure[blockPos] = schematic.desiredState(blockPos) + layerStructure[blockPos] = schematic.desiredState(blockPos) } } + + structure.putAll(layerStructure) + + if (!inLayers) continue + + addSubActivities( + BuildStructure( + layerStructure, + direction, + offsetMove + ) + ) } MessageSendHelper.sendChatMessage("$activityName Building ${structure.size} blocks") - ActivityManager.addSubActivities( + if (inLayers) return + + addSubActivities( BuildStructure( structure, direction, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 25b53c8f0..128ef4505 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -64,7 +64,9 @@ class BreakBlock( return } - if (player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE) { // ToDo: get optimal tool + if (!player.capabilities.isCreativeMode + && player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE + ) { // ToDo: get optimal tool val owner = owner if (owner is BuildBlock) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 770d0154e..0e2123154 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.CreativeInventoryAction import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RenderAABBActivity @@ -27,6 +28,8 @@ import net.minecraft.block.BlockColored import net.minecraft.block.properties.PropertyDirection import net.minecraft.block.state.IBlockState import net.minecraft.item.EnumDyeColor +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.CPacketCreativeInventoryAction import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult @@ -42,7 +45,7 @@ class PlaceBlock( private val ignoreProperties: Boolean = false, override var rotation: Vec2f = Vec2f.ZERO, override val timeout: Long = 200L, - override val maxAttempts: Int = 5, + override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { @@ -92,15 +95,29 @@ class PlaceBlock( val meta = (entry.value as EnumDyeColor).metadata if (player.getHeldItem(EnumHand.MAIN_HAND).metadata != meta) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item, predicateItem = { - it.metadata == meta - })) + if (!player.capabilities.isCreativeMode) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = meta, predicateItem = { + it.metadata == meta + })) + return + } + + val stack = ItemStack(targetState.block.item, 1, meta) + + addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) return } } if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item)) + if (!player.capabilities.isCreativeMode) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item)) + return + } + + val stack = ItemStack(targetState.block.item) + + addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) return } @@ -187,6 +204,7 @@ class PlaceBlock( status = Status.UNINITIALIZED } else -> { + spoofedDirection = false status = Status.UNINITIALIZED } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 99efc4979..1e1c43dbf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -18,6 +18,7 @@ class AcquireItemInActiveHand( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, + private val metadata: Int? = null, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false, override val maxAttempts: Int = 3, @@ -37,7 +38,7 @@ class AcquireItemInActiveHand( if (useShulkerBoxes) { addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) } else { - failedWith(NoItemFoundException(item)) + failedWith(NoItemFoundException(item, metadata)) } } } @@ -70,5 +71,5 @@ class AcquireItemInActiveHand( status = Status.UNINITIALIZED } - class NoItemFoundException(item: Item) : Exception("No ${item.registryName} found in inventory (shulkers are disabled)") + class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${ metadata?.let { ":$it" } ?: "" } found in inventory (shulkers are disabled)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt new file mode 100644 index 000000000..05864e20b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt @@ -0,0 +1,26 @@ +package com.lambda.client.activity.activities.inventory + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.threads.safeListener +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.CPacketCreativeInventoryAction +import net.minecraft.network.play.server.SPacketSetSlot +import net.minecraft.util.EnumHand + +class CreativeInventoryAction( + private val slot: Int, + private val stack: ItemStack +) : Activity() { + override fun SafeClientEvent.onInitialize() { + player.setHeldItem(EnumHand.MAIN_HAND, stack) + connection.sendPacket(CPacketCreativeInventoryAction(slot, stack)) + } + + init { + safeListener { + if (it.packet is SPacketSetSlot) success() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt index faa3935e6..f16af9f24 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -18,6 +18,7 @@ object SchematicBuilder : Module( alias = arrayOf("sb") ) { private val offset by setting("Offset", 0, -10..10, 1) + private val inLayers by setting("In Layers", true) private var ownedBuildStructure: BuildSchematic? = null @@ -29,6 +30,7 @@ object SchematicBuilder : Module( BuildSchematic( schematic, + inLayers, direction, BlockPos(direction.directionVec.multiply(offset)) ).let { From 14f13bbdb9c65da6f3a1a0e7341dec39776c6bc9 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 2 Feb 2023 06:09:53 +0100 Subject: [PATCH 059/104] Added HalfBlock placements --- .../activities/interaction/PlaceBlock.kt | 76 +++++++++++++------ .../inventory/CreativeInventoryAction.kt | 6 +- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 0e2123154..0d712b2ac 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -24,12 +24,12 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable -import net.minecraft.block.BlockColored +import net.minecraft.block.BlockGlazedTerracotta +import net.minecraft.block.BlockSlab +import net.minecraft.block.BlockSlab.EnumBlockHalf import net.minecraft.block.properties.PropertyDirection import net.minecraft.block.state.IBlockState -import net.minecraft.item.EnumDyeColor import net.minecraft.item.ItemStack -import net.minecraft.network.play.client.CPacketCreativeInventoryAction import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult @@ -57,16 +57,19 @@ class PlaceBlock( private var spoofedDirection = false override fun SafeClientEvent.onInitialize() { + /* check if is done */ if (world.getBlockState(blockPos) == targetState) { success() return } + /* less strict done check */ if (ignoreProperties && world.getBlockState(blockPos).block == targetState.block) { success() return } + /* check if block is placeable */ if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { if (world.worldBorder.contains(blockPos) && !world.isOutsideBuildHeight(blockPos)) { @@ -78,8 +81,14 @@ class PlaceBlock( return } + /* rotate block to right direction */ targetState.properties.entries.firstOrNull { it.key is PropertyDirection }?.let { entry -> - val direction = (entry.value as EnumFacing).opposite + var direction = entry.value as EnumFacing + + direction = when (targetState) { // ToDo: Exhaust all block types + is BlockGlazedTerracotta -> direction.opposite + else -> direction + } if (directionForce && !ignoreDirection @@ -91,31 +100,31 @@ class PlaceBlock( } } - targetState.properties.entries.firstOrNull { it.key == BlockColored.COLOR }?.let { entry -> - val meta = (entry.value as EnumDyeColor).metadata - - if (player.getHeldItem(EnumHand.MAIN_HAND).metadata != meta) { - if (!player.capabilities.isCreativeMode) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = meta, predicateItem = { - it.metadata == meta - })) - return - } + /* half slab placement adjustments */ + var half: EnumBlockHalf? = null + val allowedSides = EnumFacing.VALUES.toMutableList() - val stack = ItemStack(targetState.block.item, 1, meta) + targetState.properties.entries.firstOrNull { it.key == BlockSlab.HALF }?.let { entry -> + half = entry.value as EnumBlockHalf - addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) - return + when (half) { + EnumBlockHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) + EnumBlockHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) + else -> {} } } - if (player.getHeldItem(EnumHand.MAIN_HAND).item.block != targetState.block) { + /* check if item has required metadata (declares the type) */ + val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) + val meta = targetState.block.getMetaFromState(targetState) + + if (heldItem.item.block != targetState.block || meta != heldItem.metadata) { if (!player.capabilities.isCreativeMode) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item)) + addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = meta)) return } - val stack = ItemStack(targetState.block.item) + val stack = ItemStack(targetState.block.item, 1, meta) addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) return @@ -125,8 +134,28 @@ class PlaceBlock( blockPos, attempts = BuildTools.placementSearch, visibleSideCheck = BuildTools.illegalPlacements, - range = BuildTools.maxReach + range = BuildTools.maxReach, + sides = allowedSides.toTypedArray() )?.let { + var hitVec = it.hitVec + + half?.let { half -> + if (it.side in EnumFacing.HORIZONTALS) { + hitVec = when (half) { + EnumBlockHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) + else -> hitVec.add(0.0, 0.1, 0.0) + } + } + } + + /* last check for placement state */ + val resultingState = targetState.block.getStateForPlacement(world, it.pos, it.side, hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), meta, player, EnumHand.MAIN_HAND) + + if (resultingState != targetState && !spoofedDirection) { + failedWith(PlacementStateException(resultingState, targetState)) + return + } + val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist renderActivity.color = ColorHolder(11, 66, 89) @@ -135,9 +164,9 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } - rotation = getRotationTo(it.hitVec) + rotation = getRotationTo(hitVec) - val result = playerController.processRightClickBlock(player, world, it.pos, it.side, it.hitVec, EnumHand.MAIN_HAND) + val result = playerController.processRightClickBlock(player, world, it.pos, it.side, hitVec, EnumHand.MAIN_HAND) if (result != EnumActionResult.SUCCESS) { failedWith(ProcessRightClickException(result)) @@ -212,6 +241,7 @@ class PlaceBlock( class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") + class PlacementStateException(placementState: IBlockState, targetState: IBlockState) : Exception("Placement state $placementState does not match target state $targetState") class UnexpectedBlockStateException(blockPos: BlockPos, expected: IBlockState, actual: IBlockState) : Exception("Unexpected block state at (${blockPos.asString()}) expected $expected but got $actual") class BlockOutsideOfWorldException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt index 05864e20b..174d9cc57 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.threads.safeListener @@ -11,8 +12,9 @@ import net.minecraft.util.EnumHand class CreativeInventoryAction( private val slot: Int, - private val stack: ItemStack -) : Activity() { + private val stack: ItemStack, + override val timeout: Long = 600L +) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.setHeldItem(EnumHand.MAIN_HAND, stack) connection.sendPacket(CPacketCreativeInventoryAction(slot, stack)) From b2d174961ef0271f24311794e054314f9808187d Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 2 Feb 2023 07:20:07 +0100 Subject: [PATCH 060/104] Fix block meta data and block rotations --- .../activities/interaction/PlaceBlock.kt | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 0d712b2ac..628caca3f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -24,7 +24,12 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable +import net.minecraft.block.BlockEndPortalFrame +import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockGlazedTerracotta +import net.minecraft.block.BlockPumpkin +import net.minecraft.block.BlockRedstoneComparator +import net.minecraft.block.BlockRedstoneDiode import net.minecraft.block.BlockSlab import net.minecraft.block.BlockSlab.EnumBlockHalf import net.minecraft.block.properties.PropertyDirection @@ -85,8 +90,13 @@ class PlaceBlock( targetState.properties.entries.firstOrNull { it.key is PropertyDirection }?.let { entry -> var direction = entry.value as EnumFacing - direction = when (targetState) { // ToDo: Exhaust all block types - is BlockGlazedTerracotta -> direction.opposite + direction = when (targetState.block) { + is BlockEnderChest, + is BlockEndPortalFrame, + is BlockGlazedTerracotta, + is BlockPumpkin, + is BlockRedstoneComparator, + is BlockRedstoneDiode -> direction.opposite else -> direction } @@ -116,16 +126,16 @@ class PlaceBlock( /* check if item has required metadata (declares the type) */ val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) - val meta = targetState.block.getMetaFromState(targetState) - if (heldItem.item.block != targetState.block || meta != heldItem.metadata) { + @Suppress("DEPRECATION") + val stack = targetState.block.getItem(world, blockPos, targetState) + + if (heldItem.item.block != targetState.block || stack.metadata != heldItem.metadata) { if (!player.capabilities.isCreativeMode) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = meta)) + addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = stack.metadata)) return } - val stack = ItemStack(targetState.block.item, 1, meta) - addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) return } @@ -149,7 +159,15 @@ class PlaceBlock( } /* last check for placement state */ - val resultingState = targetState.block.getStateForPlacement(world, it.pos, it.side, hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), meta, player, EnumHand.MAIN_HAND) + val resultingState = targetState.block.getStateForPlacement( + world, + it.pos, + it.side, + hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), + stack.metadata, + player, + EnumHand.MAIN_HAND + ) if (resultingState != targetState && !spoofedDirection) { failedWith(PlacementStateException(resultingState, targetState)) From 74ea5969e12c16540b35643d2b4ae2a6735c5361 Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 2 Feb 2023 08:03:18 +0100 Subject: [PATCH 061/104] Add TrapDoors and Strairs support --- .../activities/interaction/PlaceBlock.kt | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 628caca3f..b7e983b68 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -24,17 +24,21 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable +import net.minecraft.block.BlockButton +import net.minecraft.block.BlockDoor.EnumDoorHalf import net.minecraft.block.BlockEndPortalFrame import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockGlazedTerracotta +import net.minecraft.block.BlockPistonBase import net.minecraft.block.BlockPumpkin import net.minecraft.block.BlockRedstoneComparator import net.minecraft.block.BlockRedstoneDiode import net.minecraft.block.BlockSlab import net.minecraft.block.BlockSlab.EnumBlockHalf +import net.minecraft.block.BlockStairs +import net.minecraft.block.BlockTrapDoor import net.minecraft.block.properties.PropertyDirection import net.minecraft.block.state.IBlockState -import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult @@ -91,6 +95,7 @@ class PlaceBlock( var direction = entry.value as EnumFacing direction = when (targetState.block) { + is BlockPistonBase, is BlockEnderChest, is BlockEndPortalFrame, is BlockGlazedTerracotta, @@ -111,19 +116,41 @@ class PlaceBlock( } /* half slab placement adjustments */ - var half: EnumBlockHalf? = null + var blockHalf: EnumBlockHalf? = null + var doorHalf: BlockTrapDoor.DoorHalf? = null + var stairsHalf: BlockStairs.EnumHalf? = null val allowedSides = EnumFacing.VALUES.toMutableList() targetState.properties.entries.firstOrNull { it.key == BlockSlab.HALF }?.let { entry -> - half = entry.value as EnumBlockHalf + blockHalf = entry.value as EnumBlockHalf - when (half) { + when (blockHalf) { EnumBlockHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) EnumBlockHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) else -> {} } } + targetState.properties.entries.firstOrNull { it.key == BlockTrapDoor.HALF }?.let { entry -> + doorHalf = entry.value as BlockTrapDoor.DoorHalf + + when (doorHalf) { + BlockTrapDoor.DoorHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) + BlockTrapDoor.DoorHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) + else -> {} + } + } + + targetState.properties.entries.firstOrNull { it.key == BlockStairs.HALF }?.let { entry -> + stairsHalf = entry.value as BlockStairs.EnumHalf + + when (stairsHalf) { + BlockStairs.EnumHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) + BlockStairs.EnumHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) + else -> {} + } + } + /* check if item has required metadata (declares the type) */ val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) @@ -149,7 +176,7 @@ class PlaceBlock( )?.let { var hitVec = it.hitVec - half?.let { half -> + blockHalf?.let { half -> if (it.side in EnumFacing.HORIZONTALS) { hitVec = when (half) { EnumBlockHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) @@ -158,6 +185,24 @@ class PlaceBlock( } } + doorHalf?.let { half -> + if (it.side in EnumFacing.HORIZONTALS) { + hitVec = when (half) { + BlockTrapDoor.DoorHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) + else -> hitVec.add(0.0, 0.1, 0.0) + } + } + } + + stairsHalf?.let { half -> + if (it.side in EnumFacing.HORIZONTALS) { + hitVec = when (half) { + BlockStairs.EnumHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) + else -> hitVec.add(0.0, 0.1, 0.0) + } + } + } + /* last check for placement state */ val resultingState = targetState.block.getStateForPlacement( world, From cdb03b56a93ffb503eff45252d03b8500da2909c Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 2 Feb 2023 08:47:34 +0100 Subject: [PATCH 062/104] Added Button support --- .../activities/interaction/PlaceBlock.kt | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index b7e983b68..5a760de8b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -25,7 +25,6 @@ import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.BlockButton -import net.minecraft.block.BlockDoor.EnumDoorHalf import net.minecraft.block.BlockEndPortalFrame import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockGlazedTerracotta @@ -79,6 +78,11 @@ class PlaceBlock( } /* check if block is placeable */ +// if (!targetState.block.canPlaceBlockOnSide(world, blockPos, EnumFacing.UP)) { +// failedWith(BlockNotPlaceableException(blockPos)) +// return +// } + if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { if (world.worldBorder.contains(blockPos) && !world.isOutsideBuildHeight(blockPos)) { @@ -90,20 +94,25 @@ class PlaceBlock( return } + var direction = EnumFacing.UP + /* rotate block to right direction */ targetState.properties.entries.firstOrNull { it.key is PropertyDirection }?.let { entry -> - var direction = entry.value as EnumFacing - - direction = when (targetState.block) { - is BlockPistonBase, - is BlockEnderChest, - is BlockEndPortalFrame, - is BlockGlazedTerracotta, - is BlockPumpkin, - is BlockRedstoneComparator, - is BlockRedstoneDiode -> direction.opposite - else -> direction - } + direction = entry.value as EnumFacing + + if (targetState.block is BlockButton) return@let + + val blocksToOppositeDirection = listOf( + BlockPistonBase::class, + BlockEnderChest::class, + BlockEndPortalFrame::class, + BlockGlazedTerracotta::class, + BlockPumpkin::class, + BlockRedstoneComparator::class, + BlockRedstoneDiode::class + ) + + if (targetState.block::class in blocksToOppositeDirection) direction = direction.opposite if (directionForce && !ignoreDirection @@ -151,6 +160,11 @@ class PlaceBlock( } } + if (targetState.block is BlockButton) { + allowedSides.clear() + allowedSides.add(direction.opposite) + } + /* check if item has required metadata (declares the type) */ val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) @@ -203,21 +217,24 @@ class PlaceBlock( } } - /* last check for placement state */ - val resultingState = targetState.block.getStateForPlacement( - world, - it.pos, - it.side, - hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), - stack.metadata, - player, - EnumHand.MAIN_HAND - ) - - if (resultingState != targetState && !spoofedDirection) { - failedWith(PlacementStateException(resultingState, targetState)) - return - } +// /* last check for placement state */ ToDo: this has currently too low accuracy +// val resultingState = targetState.block.getStateForPlacement( +// world, +// it.pos, +// it.side, +// hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), +// stack.metadata, +// player, +// EnumHand.MAIN_HAND +// ) +// +// if (resultingState != targetState +// && !spoofedDirection +// && targetState.block !is BlockButton +// ) { +// failedWith(PlacementStateException(resultingState, targetState)) +// return +// } val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist From 72f392b8a4b0a645f040ea82c7271ba8b32b3d4d Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 16 Feb 2023 06:44:05 +0100 Subject: [PATCH 063/104] State properties rewrite and render fix --- .../activities/highlevel/BuildBlock.kt | 1 + .../activities/interaction/PlaceBlock.kt | 214 ++++++++---------- .../inventory/AcquireItemInActiveHand.kt | 9 + .../storage/ExtractItemFromShulkerBox.kt | 1 + .../activities/storage/PlaceContainer.kt | 1 - .../manager/managers/ActivityManager.kt | 8 +- .../module/modules/client/BuildTools.kt | 9 +- .../client/module/modules/misc/BlockData.kt | 4 + .../modules/misc/TestActivityManager.kt | 25 ++ 9 files changed, 150 insertions(+), 122 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt index 0cedd0bf5..d69ca90a9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt @@ -35,6 +35,7 @@ class BuildBlock( NONE(ColorHolder()) } + // ToDo: Update actions inside PlaceBlock and BreakBlock enum class Action(val color: ColorHolder) { BREAK(ColorHolder(222, 0, 0)), PLACE(ColorHolder(35, 188, 254)), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 5a760de8b..f4a9a722e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.CreativeInventoryAction import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RenderAABBActivity @@ -14,6 +13,7 @@ import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.client.BuildTools.directionForce +import com.lambda.client.module.modules.client.BuildTools.placeStrictness import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.items.blockBlacklist @@ -24,32 +24,21 @@ import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable -import net.minecraft.block.BlockButton -import net.minecraft.block.BlockEndPortalFrame -import net.minecraft.block.BlockEnderChest -import net.minecraft.block.BlockGlazedTerracotta -import net.minecraft.block.BlockPistonBase -import net.minecraft.block.BlockPumpkin -import net.minecraft.block.BlockRedstoneComparator -import net.minecraft.block.BlockRedstoneDiode -import net.minecraft.block.BlockSlab -import net.minecraft.block.BlockSlab.EnumBlockHalf -import net.minecraft.block.BlockStairs -import net.minecraft.block.BlockTrapDoor -import net.minecraft.block.properties.PropertyDirection +import net.minecraft.block.* import net.minecraft.block.state.IBlockState +import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos class PlaceBlock( private val blockPos: BlockPos, private val targetState: IBlockState, private val doPending: Boolean = false, - private val ignoreDirection: Boolean = false, private val ignoreProperties: Boolean = false, override var rotation: Vec2f = Vec2f.ZERO, override val timeout: Long = 200L, @@ -64,6 +53,20 @@ class PlaceBlock( private var spoofedDirection = false + private enum class PlacementOffset { + TOP, NONE, BOTTOM + } + + private val blocksToOppositeDirection = listOf( + BlockPistonBase::class, + BlockEnderChest::class, + BlockEndPortalFrame::class, + BlockGlazedTerracotta::class, + BlockPumpkin::class, + BlockRedstoneComparator::class, + BlockRedstoneDiode::class + ) + override fun SafeClientEvent.onInitialize() { /* check if is done */ if (world.getBlockState(blockPos) == targetState) { @@ -94,28 +97,29 @@ class PlaceBlock( return } - var direction = EnumFacing.UP + val allowedSides = EnumFacing.VALUES.toMutableList() + var placementOffset = PlacementOffset.NONE + +// var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() /* rotate block to right direction */ - targetState.properties.entries.firstOrNull { it.key is PropertyDirection }?.let { entry -> - direction = entry.value as EnumFacing - - if (targetState.block is BlockButton) return@let - - val blocksToOppositeDirection = listOf( - BlockPistonBase::class, - BlockEnderChest::class, - BlockEndPortalFrame::class, - BlockGlazedTerracotta::class, - BlockPumpkin::class, - BlockRedstoneComparator::class, - BlockRedstoneDiode::class - ) + targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> + var direction = entry.value as EnumFacing + + if (targetState.block is BlockButton) { + allowedSides.clear() + allowedSides.add(direction.opposite) + return@let + } + +// BlockDirectional +// BlockHorizontal +// BlockTorch +// BlockLever if (targetState.block::class in blocksToOppositeDirection) direction = direction.opposite if (directionForce - && !ignoreDirection && !spoofedDirection && player.horizontalFacing != direction ) { @@ -124,118 +128,97 @@ class PlaceBlock( } } - /* half slab placement adjustments */ - var blockHalf: EnumBlockHalf? = null - var doorHalf: BlockTrapDoor.DoorHalf? = null - var stairsHalf: BlockStairs.EnumHalf? = null - val allowedSides = EnumFacing.VALUES.toMutableList() - - targetState.properties.entries.firstOrNull { it.key == BlockSlab.HALF }?.let { entry -> - blockHalf = entry.value as EnumBlockHalf - - when (blockHalf) { - EnumBlockHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) - EnumBlockHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) - else -> {} + targetState.properties.entries.firstOrNull { it.key.name == "half" }?.let { entry -> + val half = entry.value as IStringSerializable + placementOffset = when (half.name) { + "top" -> { + allowedSides.remove(EnumFacing.DOWN) + PlacementOffset.TOP + } + else -> { + allowedSides.remove(EnumFacing.UP) + PlacementOffset.BOTTOM + } } } - targetState.properties.entries.firstOrNull { it.key == BlockTrapDoor.HALF }?.let { entry -> - doorHalf = entry.value as BlockTrapDoor.DoorHalf + targetState.properties.entries.firstOrNull { it.key.name == "axis" }?.let { entry -> + val axis = entry.value as IStringSerializable - when (doorHalf) { - BlockTrapDoor.DoorHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) - BlockTrapDoor.DoorHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) + when (axis.name) { + "x" -> allowedSides.removeIf { it.axis != EnumFacing.Axis.X } + "y" -> allowedSides.removeIf { it.axis != EnumFacing.Axis.Y } + "z" -> allowedSides.removeIf { it.axis != EnumFacing.Axis.Z } else -> {} } } - targetState.properties.entries.firstOrNull { it.key == BlockStairs.HALF }?.let { entry -> - stairsHalf = entry.value as BlockStairs.EnumHalf - - when (stairsHalf) { - BlockStairs.EnumHalf.BOTTOM -> allowedSides.remove(EnumFacing.UP) - BlockStairs.EnumHalf.TOP -> allowedSides.remove(EnumFacing.DOWN) + targetState.properties.entries.firstOrNull { it.key.name == "variant" }?.let { entry -> + when (entry.value) { + BlockQuartz.EnumType.LINES_X -> allowedSides.removeIf { it.axis != EnumFacing.Axis.X } + BlockQuartz.EnumType.LINES_Y -> allowedSides.removeIf { it.axis != EnumFacing.Axis.Y } + BlockQuartz.EnumType.LINES_Z -> allowedSides.removeIf { it.axis != EnumFacing.Axis.Z } else -> {} } } - if (targetState.block is BlockButton) { - allowedSides.clear() - allowedSides.add(direction.opposite) - } - /* check if item has required metadata (declares the type) */ val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) - @Suppress("DEPRECATION") - val stack = targetState.block.getItem(world, blockPos, targetState) + if (!ignoreProperties) { + val stack = if (targetState.block is BlockShulkerBox) { + ItemStack(targetState.block, 1, targetState.block.getMetaFromState(targetState)) + } else { + @Suppress("DEPRECATION") + targetState.block.getItem(world, blockPos, targetState) + } - if (heldItem.item.block != targetState.block || stack.metadata != heldItem.metadata) { - if (!player.capabilities.isCreativeMode) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item, metadata = stack.metadata)) + if (heldItem.item.block != targetState.block || stack.metadata != heldItem.metadata) { + addSubActivities(AcquireItemInActiveHand( + targetState.block.item, + metadata = stack.metadata + )) + return + } + } else { + if (heldItem.item.block != targetState.block) { + addSubActivities(AcquireItemInActiveHand(targetState.block.item)) return } - - addSubActivities(CreativeInventoryAction(36 + player.inventory.currentItem, stack)) - return } getNeighbour( blockPos, attempts = BuildTools.placementSearch, - visibleSideCheck = BuildTools.illegalPlacements, + visibleSideCheck = placeStrictness != BuildTools.PlacementStrictness.ANY, range = BuildTools.maxReach, sides = allowedSides.toTypedArray() )?.let { - var hitVec = it.hitVec - - blockHalf?.let { half -> - if (it.side in EnumFacing.HORIZONTALS) { - hitVec = when (half) { - EnumBlockHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) - else -> hitVec.add(0.0, 0.1, 0.0) - } - } + val hitVec = when (placementOffset) { + PlacementOffset.TOP -> it.hitVec.add(0.0, 0.1, 0.0) + PlacementOffset.BOTTOM -> it.hitVec.add(0.0, -0.1, 0.0) + else -> it.hitVec } - doorHalf?.let { half -> - if (it.side in EnumFacing.HORIZONTALS) { - hitVec = when (half) { - BlockTrapDoor.DoorHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) - else -> hitVec.add(0.0, 0.1, 0.0) - } - } - } + /* last check for placement state */ + val resultingState = targetState.block.getStateForPlacement( + world, + it.pos, + it.side, + hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), + heldItem.metadata, + player, + EnumHand.MAIN_HAND + ) - stairsHalf?.let { half -> - if (it.side in EnumFacing.HORIZONTALS) { - hitVec = when (half) { - BlockStairs.EnumHalf.BOTTOM -> hitVec.add(0.0, -0.1, 0.0) - else -> hitVec.add(0.0, 0.1, 0.0) - } - } + if (resultingState != targetState + && !spoofedDirection + && targetState.block !is BlockButton // ToDo: find out why buttons don't work with this + ) { + failedWith(PlacementStateException(resultingState, targetState)) + return } -// /* last check for placement state */ ToDo: this has currently too low accuracy -// val resultingState = targetState.block.getStateForPlacement( -// world, -// it.pos, -// it.side, -// hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), -// stack.metadata, -// player, -// EnumHand.MAIN_HAND -// ) -// -// if (resultingState != targetState -// && !spoofedDirection -// && targetState.block !is BlockButton -// ) { -// failedWith(PlacementStateException(resultingState, targetState)) -// return -// } - val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist renderActivity.color = ColorHolder(11, 66, 89) @@ -304,14 +287,14 @@ class PlaceBlock( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is Wait -> { - if (doPending) { - owner.status = Status.PENDING - } + if (doPending) owner.status = Status.PENDING } + is Rotate -> { spoofedDirection = true status = Status.UNINITIALIZED } + else -> { spoofedDirection = false status = Status.UNINITIALIZED @@ -320,6 +303,7 @@ class PlaceBlock( } class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") + class BlockNotPlaceableException(targetState: IBlockState) : Exception("Block $targetState is not placeable") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") class PlacementStateException(placementState: IBlockState, targetState: IBlockState) : Exception("Placement state $placementState does not match target state $targetState") class UnexpectedBlockStateException(blockPos: BlockPos, expected: IBlockState, actual: IBlockState) : Exception("Unexpected block state at (${blockPos.asString()}) expected $expected but got $actual") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 1e1c43dbf..e2448231d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -6,6 +6,7 @@ import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.module.modules.client.BuildTools.pickBlock import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.item @@ -30,6 +31,14 @@ class AcquireItemInActiveHand( }?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { + if (pickBlock && player.capabilities.isCreativeMode) { + addSubActivities(CreativeInventoryAction( + 36 + player.inventory.currentItem, + ItemStack(item, 1, metadata ?: 0) + )) + return + } + player.allSlots.firstOrNull { slot -> slot.stack.item == item && predicateItem(slot.stack) }?.let { slotFrom -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 202a07f4a..5d53c75be 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -25,6 +25,7 @@ class ExtractItemFromShulkerBox( val candidates = mutableMapOf() + // ToDo: move to acquire item in active hand player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> val count = inventory.count { it.item == item && predicateItem(it) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index c4aee0fd5..8e71cbe60 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -27,7 +27,6 @@ class PlaceContainer( addSubActivities(PlaceBlock( containerPos, targetState, - ignoreDirection = true, ignoreProperties = true )) } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index a2c49eaad..454b486a4 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -2,6 +2,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.RenderAABBActivity +import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent @@ -23,18 +24,16 @@ object ActivityManager : Manager, Activity(true) { val allActivities = allSubActivities - val currentActivity = getCurrentActivity() - allActivities.filter { it.status == Status.PENDING }.forEach { with(it) { updateTypesOnTick(it) } } - with(currentActivity) { + with(getCurrentActivity()) { if (status == Status.RUNNING || status == Status.PENDING - ) updateTypesOnTick(currentActivity) + ) updateTypesOnTick(this) } repeat(executionCountPerTick) { @@ -44,6 +43,7 @@ object ActivityManager : Manager, Activity(true) { BaritoneUtils.settings?.allowInventory?.value = false updateActivity() + checkRender() } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 057240f76..f41ae0374 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -3,7 +3,6 @@ package com.lambda.client.module.modules.client import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting -import com.lambda.client.util.Bind import com.lambda.client.util.items.shulkerList import net.minecraft.block.Block import net.minecraft.init.Blocks @@ -41,7 +40,9 @@ object BuildTools : Module( /* placing */ val placeDelay by setting("Place Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between placement tasks", unit = " ticks") val breakDownCycles by setting("Break Down", 64, 1..200, 1, { page == Page.BUILDING }, description = "", unit = " ender chests") - val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") + val pickBlock by setting("Pick Block Creative", true, { page == Page.BUILDING }, description = "Use pick block to place blocks when in creative mode") + val placeStrictness by setting("Placement Strictness", PlacementStrictness.DIRECTION, { page == Page.BUILDING }, description = "ANY: Allow all exposed surfaces. DIRECTION: Only allow surfaces in the direction of the player. VISIBLE: Only allow surfaces that are visible to the player.") +// val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") val executionCountPerTick by setting("Executions Per Tick", 100, 0..200, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") @@ -101,6 +102,10 @@ object BuildTools : Module( NONE, ANTI_AFK, LOGOUT } + enum class PlacementStrictness { + ANY, DIRECTION, VISIBLE + } + val ignoredBlocks: List get() = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt index 99a452cbf..ba7ef56bc 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/BlockData.kt @@ -39,6 +39,10 @@ object BlockData : Module( val properties = blockState.properties.entries.joinToString(", ") { "${it.key}=${it.value}" } MessageSendHelper.sendChatMessage("""$chatName &6Block Properties: $properties""".trimIndent()) } + + blockState.block.getValidRotations(world, blockPos)?.let { rotations -> + MessageSendHelper.sendChatMessage("""$chatName &6Block Valid Rotations: ${rotations.joinToString()}""".trimIndent()) + } } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 8e448cd0b..e34c24190 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -7,6 +7,8 @@ import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.highlevel.ReachXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.DumpInventory @@ -26,11 +28,15 @@ import com.lambda.client.util.items.block import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item +import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.schematic.LambdaSchematicaHelper import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe +import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal +import net.minecraft.block.BlockLog +import net.minecraft.block.BlockQuartz import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper @@ -93,6 +99,25 @@ object TestActivityManager : Module( false }) + private val ctiectictiectie by setting("Button", false, consumer = { _, _-> + runSafe { + val currentDirection = player.horizontalFacing + +// val targetState = Blocks.QUARTZ_BLOCK.defaultState +// .withProperty(BlockQuartz.VARIANT, BlockQuartz.EnumType.LINES_X) + + val targetState = Blocks.WOODEN_BUTTON.defaultState + .withProperty(BlockDirectional.FACING, EnumFacing.NORTH) + + ActivityManager.addSubActivities(PlaceBlock( + player.flooredPosition.add(currentDirection.directionVec.multiply(2)), + targetState + )) + } + + false + }) + private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> ActivityManager.addSubActivities( AcquireItemInActiveHand( From c1e2df106274d58ac43f952a72f4bd8960932960 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 19 Feb 2023 21:55:19 +0100 Subject: [PATCH 064/104] Better UP and BOTTOM place. Fix absent Schematica crash --- .../activities/interaction/PlaceBlock.kt | 60 +++++++++---------- .../inventory/AcquireItemInActiveHand.kt | 13 ++-- .../inventory/CreativeInventoryAction.kt | 5 +- .../module/modules/misc/SchematicBuilder.kt | 8 +++ .../modules/misc/TestActivityManager.kt | 3 + 5 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index f4a9a722e..4980d58f9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -34,6 +34,7 @@ import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d class PlaceBlock( private val blockPos: BlockPos, @@ -53,8 +54,10 @@ class PlaceBlock( private var spoofedDirection = false - private enum class PlacementOffset { - TOP, NONE, BOTTOM + private enum class PlacementOffset(val offset: Vec3d) { + UPPER(Vec3d(0.0, 0.1, 0.0)), + CENTER(Vec3d.ZERO), + LOWER(Vec3d(0.0, -0.1, 0.0)) } private val blocksToOppositeDirection = listOf( @@ -98,11 +101,10 @@ class PlaceBlock( } val allowedSides = EnumFacing.VALUES.toMutableList() - var placementOffset = PlacementOffset.NONE + var placementOffset = PlacementOffset.CENTER // var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() - /* rotate block to right direction */ targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> var direction = entry.value as EnumFacing @@ -119,6 +121,7 @@ class PlaceBlock( if (targetState.block::class in blocksToOppositeDirection) direction = direction.opposite + /* rotate block to right direction if possible */ if (directionForce && !spoofedDirection && player.horizontalFacing != direction @@ -133,11 +136,11 @@ class PlaceBlock( placementOffset = when (half.name) { "top" -> { allowedSides.remove(EnumFacing.DOWN) - PlacementOffset.TOP + PlacementOffset.UPPER } else -> { allowedSides.remove(EnumFacing.UP) - PlacementOffset.BOTTOM + PlacementOffset.LOWER } } } @@ -153,6 +156,7 @@ class PlaceBlock( } } + /* quartz is special snowflake */ targetState.properties.entries.firstOrNull { it.key.name == "variant" }?.let { entry -> when (entry.value) { BlockQuartz.EnumType.LINES_X -> allowedSides.removeIf { it.axis != EnumFacing.Axis.X } @@ -194,30 +198,26 @@ class PlaceBlock( range = BuildTools.maxReach, sides = allowedSides.toTypedArray() )?.let { - val hitVec = when (placementOffset) { - PlacementOffset.TOP -> it.hitVec.add(0.0, 0.1, 0.0) - PlacementOffset.BOTTOM -> it.hitVec.add(0.0, -0.1, 0.0) - else -> it.hitVec - } - - /* last check for placement state */ - val resultingState = targetState.block.getStateForPlacement( - world, - it.pos, - it.side, - hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), - heldItem.metadata, - player, - EnumHand.MAIN_HAND - ) - - if (resultingState != targetState - && !spoofedDirection - && targetState.block !is BlockButton // ToDo: find out why buttons don't work with this - ) { - failedWith(PlacementStateException(resultingState, targetState)) - return - } + val hitVec = it.hitVec.add(placementOffset.offset) + +// /* last check for placement state */ +// val resultingState = targetState.block.getStateForPlacement( +// world, +// it.pos, +// it.side, +// hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat(), +// heldItem.metadata, +// player, +// EnumHand.MAIN_HAND +// ) +// +// if (resultingState != targetState +// && !spoofedDirection +// && targetState.block !is BlockButton // ToDo: find out why buttons don't work with this +// ) { +// failedWith(PlacementStateException(resultingState, targetState)) +// return +// } val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index e2448231d..ddc87cfef 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -7,9 +7,7 @@ import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock -import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.hotbarSlots -import com.lambda.client.util.items.item +import com.lambda.client.util.items.* import net.minecraft.init.Blocks import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -19,7 +17,7 @@ class AcquireItemInActiveHand( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, - private val metadata: Int? = null, + private val metadata: Int = 0, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false, override val maxAttempts: Int = 3, @@ -27,20 +25,19 @@ class AcquireItemInActiveHand( ) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) + slot.stack.item == item && predicateItem(slot.stack) && metadata == slot.stack.metadata }?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { if (pickBlock && player.capabilities.isCreativeMode) { addSubActivities(CreativeInventoryAction( - 36 + player.inventory.currentItem, - ItemStack(item, 1, metadata ?: 0) + ItemStack(item, 1, metadata) )) return } player.allSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) + slot.stack.item == item && predicateItem(slot.stack) && metadata == slot.stack.metadata }?.let { slotFrom -> addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) } ?: run { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt index 174d9cc57..c07894dbf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt @@ -4,20 +4,21 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.items.toHotbarSlotOrNull import com.lambda.client.util.threads.safeListener +import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketCreativeInventoryAction import net.minecraft.network.play.server.SPacketSetSlot import net.minecraft.util.EnumHand class CreativeInventoryAction( - private val slot: Int, private val stack: ItemStack, override val timeout: Long = 600L ) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.setHeldItem(EnumHand.MAIN_HAND, stack) - connection.sendPacket(CPacketCreativeInventoryAction(slot, stack)) + connection.sendPacket(CPacketCreativeInventoryAction(36 + player.inventory.currentItem, stack)) } init { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt index f16af9f24..56cbd61a3 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -8,6 +8,8 @@ import com.lambda.client.module.Module import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.schematic.LambdaSchematicaHelper +import com.lambda.client.util.schematic.LambdaSchematicaHelper.isSchematicaPresent +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe import net.minecraft.util.math.BlockPos @@ -25,6 +27,12 @@ object SchematicBuilder : Module( init { onEnable { runSafe { + if (!isSchematicaPresent) { + MessageSendHelper.sendErrorMessage("$chatName Schematica is not loaded / installed!") + disable() + return@runSafe + } + LambdaSchematicaHelper.loadedSchematic?.let { schematic -> val direction = Direction.fromEntity(player) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index e34c24190..a1d56c2d8 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -36,7 +36,10 @@ import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal import net.minecraft.block.BlockLog +import net.minecraft.block.BlockPistonBase +import net.minecraft.block.BlockPurpurSlab import net.minecraft.block.BlockQuartz +import net.minecraft.block.BlockRotatedPillar import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper From d98d40304074ac05c2f271b92df2144972e1bfc1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 20 Feb 2023 01:15:38 +0100 Subject: [PATCH 065/104] Fix ItemBlockSpecials --- .../activities/interaction/PlaceBlock.kt | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 4980d58f9..e92f2f5bc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -26,6 +26,7 @@ import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.* import net.minecraft.block.state.IBlockState +import net.minecraft.item.ItemBlockSpecial import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange @@ -35,6 +36,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.asm.transformers.ItemBlockSpecialTransformer class PlaceBlock( private val blockPos: BlockPos, @@ -65,9 +67,7 @@ class PlaceBlock( BlockEnderChest::class, BlockEndPortalFrame::class, BlockGlazedTerracotta::class, - BlockPumpkin::class, - BlockRedstoneComparator::class, - BlockRedstoneDiode::class + BlockPumpkin::class ) override fun SafeClientEvent.onInitialize() { @@ -168,27 +168,21 @@ class PlaceBlock( /* check if item has required metadata (declares the type) */ val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) - - if (!ignoreProperties) { - val stack = if (targetState.block is BlockShulkerBox) { - ItemStack(targetState.block, 1, targetState.block.getMetaFromState(targetState)) - } else { - @Suppress("DEPRECATION") - targetState.block.getItem(world, blockPos, targetState) - } - - if (heldItem.item.block != targetState.block || stack.metadata != heldItem.metadata) { - addSubActivities(AcquireItemInActiveHand( - targetState.block.item, - metadata = stack.metadata - )) - return - } + val stack = if (targetState.block is BlockShulkerBox) { + ItemStack(targetState.block, 1, targetState.block.getMetaFromState(targetState)) } else { - if (heldItem.item.block != targetState.block) { - addSubActivities(AcquireItemInActiveHand(targetState.block.item)) - return - } + @Suppress("DEPRECATION") + targetState.block.getItem(world, blockPos, targetState) + } + + if (heldItem.item != stack.item + || (!ignoreProperties && stack.metadata != heldItem.metadata) + ) { + addSubActivities(AcquireItemInActiveHand( + stack.item, + metadata = stack.metadata + )) + return } getNeighbour( From a70cdbaa2cf4ebcd8c0f6ebf0546290e664c2a5f Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 20 Feb 2023 02:15:24 +0100 Subject: [PATCH 066/104] Fix optimal stack calcultion --- .../activities/interaction/PlaceBlock.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index e92f2f5bc..f353acc1b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -15,9 +15,7 @@ import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.client.BuildTools.directionForce import com.lambda.client.module.modules.client.BuildTools.placeStrictness import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.block import com.lambda.client.util.items.blockBlacklist -import com.lambda.client.util.items.item import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f @@ -26,7 +24,6 @@ import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.* import net.minecraft.block.state.IBlockState -import net.minecraft.item.ItemBlockSpecial import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.server.SPacketBlockChange @@ -36,7 +33,6 @@ import net.minecraft.util.EnumHand import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import net.minecraftforge.fml.common.asm.transformers.ItemBlockSpecialTransformer class PlaceBlock( private val blockPos: BlockPos, @@ -67,7 +63,8 @@ class PlaceBlock( BlockEnderChest::class, BlockEndPortalFrame::class, BlockGlazedTerracotta::class, - BlockPumpkin::class + BlockPumpkin::class, + BlockRedstoneDiode::class, ) override fun SafeClientEvent.onInitialize() { @@ -167,20 +164,20 @@ class PlaceBlock( } /* check if item has required metadata (declares the type) */ - val heldItem = player.getHeldItem(EnumHand.MAIN_HAND) - val stack = if (targetState.block is BlockShulkerBox) { + val heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND) + val optimalStack = if (targetState.block is BlockShulkerBox) { ItemStack(targetState.block, 1, targetState.block.getMetaFromState(targetState)) } else { @Suppress("DEPRECATION") targetState.block.getItem(world, blockPos, targetState) } - if (heldItem.item != stack.item - || (!ignoreProperties && stack.metadata != heldItem.metadata) + if (heldItemStack.item != optimalStack.item + || (!ignoreProperties && optimalStack.metadata != heldItemStack.metadata) ) { addSubActivities(AcquireItemInActiveHand( - stack.item, - metadata = stack.metadata + optimalStack.item, + metadata = optimalStack.metadata )) return } From 11e5ce720ad1a8127e9d701e8d2c36f29109122f Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 20 Feb 2023 07:00:39 +0100 Subject: [PATCH 067/104] Place and Break rewrite and improved concurrent building --- .../com/lambda/client/activity/Activity.kt | 6 +- .../highlevel/BreakDownEnderChests.kt | 1 - .../activities/highlevel/BuildBlock.kt | 130 --------- .../activities/highlevel/BuildStructure.kt | 54 ++-- .../highlevel/SurroundWithObsidian.kt | 17 +- .../activities/interaction/BreakBlock.kt | 250 ++++++++-------- .../activities/interaction/OpenContainer.kt | 2 +- .../activities/interaction/PlaceBlock.kt | 268 ++++++++++-------- .../activity/activities/interaction/Rotate.kt | 2 +- .../interaction/UseThrowableOnEntity.kt | 2 +- .../inventory/AcquireItemInActiveHand.kt | 14 +- .../inventory/CreativeInventoryAction.kt | 2 - .../activities/storage/PlaceContainer.kt | 1 + .../activities/travel/PickUpEntityItem.kt | 2 +- .../activities/types/BuildActivity.kt | 28 ++ .../activities/types/RotatingActivity.kt | 8 +- .../elements/client/ActivityManagerHud.kt | 20 +- .../manager/managers/ActivityManager.kt | 20 +- .../module/modules/client/BuildTools.kt | 2 +- .../module/modules/misc/HighwayTools.kt | 7 +- 20 files changed, 415 insertions(+), 421 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 64247c8ed..e5b483ed6 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -19,6 +19,7 @@ import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent import com.lambda.client.util.text.MessageSendHelper +import com.lambda.client.util.text.capitalize import net.minecraft.entity.Entity import net.minecraft.item.ItemBlock import net.minecraft.util.math.AxisAlignedBB @@ -90,7 +91,6 @@ abstract class Activity(val isRoot: Boolean = false) { && this@Activity !is DelayedActivity ) success() } - Status.PENDING, Status.FAILURE -> { } } } @@ -196,9 +196,7 @@ abstract class Activity(val isRoot: Boolean = false) { enum class Status { RUNNING, - UNINITIALIZED, - PENDING, - FAILURE + UNINITIALIZED } fun appendInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder, details: Boolean) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 1ebf54365..94b14a400 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -11,7 +11,6 @@ import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countItem import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item -import net.minecraft.block.BlockHorizontal import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt deleted file mode 100644 index d69ca90a9..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildBlock.kt +++ /dev/null @@ -1,130 +0,0 @@ -package com.lambda.client.activity.activities.highlevel - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.module.modules.client.BuildTools.ignoredBlocks -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.threads.runSafe -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.* -import net.minecraft.block.state.IBlockState -import net.minecraft.init.Blocks -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent - -class BuildBlock( - val blockPos: BlockPos, - private val targetState: IBlockState, - private val respectIgnore: Boolean = false, - override val maxAttempts: Int = 3, - override var usedAttempts: Int = 0, - override val toRender: MutableSet = mutableSetOf() -) : AttemptActivity, RenderAABBActivity, Activity() { - var action = Action.UNINIT - var context = Context.NONE - - enum class Context(val color: ColorHolder) { - RESTOCK(ColorHolder()), - LIQUID(ColorHolder()), - NONE(ColorHolder()) - } - - // ToDo: Update actions inside PlaceBlock and BreakBlock - enum class Action(val color: ColorHolder) { - BREAK(ColorHolder(222, 0, 0)), - PLACE(ColorHolder(35, 188, 254)), - WRONG_POS_BREAK(ColorHolder(112, 0, 0)), - WRONG_POS_PLACE(ColorHolder(20, 108, 145)), - INVALID_BREAK(ColorHolder(46, 0, 0)), - INVALID_PLACE(ColorHolder(11, 55, 74)), - UNINIT(ColorHolder(11, 11, 11)); - - fun addToRenderer(activity: BuildBlock) { - with(activity) { - toRender.add(RenderAABBActivity.Companion.RenderBlockPos( - blockPos, - color - )) - } - } - } - - init { - runSafe { updateAction() } - - safeListener { - updateAction() - } - } - - override fun SafeClientEvent.onInitialize() { - updateAction(true) - } - - private fun SafeClientEvent.updateAction(addActivities: Boolean = false) { -// val owner = owner - -// if (owner !is BuildStructure) return - - val currentState = world.getBlockState(blockPos) - - when { - /* is in desired state */ - currentState == targetState -> success() - /* block needs to be placed */ - currentState.isLiquid || - (targetState != Blocks.AIR.defaultState && world.isPlaceable(blockPos, targetState.getCollisionBoundingBox(world, blockPos) - ?: AxisAlignedBB(blockPos))) -> { - if (addActivities) { - val trueTarget = if (currentState.isLiquid) BuildTools.defaultFillerMat.defaultState else targetState - - addSubActivities( - PlaceBlock(blockPos, trueTarget, BuildTools.doPending) - ) - } else { - action = when { - getNeighbour(blockPos, 1, BuildTools.maxReach, true) != null -> Action.PLACE - getNeighbour(blockPos, 1, 256f, false) != null -> Action.WRONG_POS_PLACE - else -> Action.INVALID_PLACE - } - } - } - /* should be ignored */ - respectIgnore && currentState.block in ignoredBlocks -> success() - /* only option left is breaking the block */ - else -> { - if (addActivities) { - addSubActivities( - BreakBlock(blockPos, BuildTools.doPending) - ) - } else { - action = when { - getMiningSide(blockPos, BuildTools.maxReach) != null -> Action.BREAK - getMiningSide(blockPos) != null -> Action.WRONG_POS_BREAK - else -> Action.INVALID_BREAK - } - } - } - } - - toRender.clear() - action.addToRenderer(this@BuildBlock) - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - status = Status.UNINITIALIZED - } - - override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { - if (childException !is BreakBlock.NoExposedSideFound) return false - - status = Status.UNINITIALIZED - return true - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 792574ae7..cbae9d145 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -1,15 +1,19 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RenderAABBActivity +import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction -import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.multiply +import jdk.nashorn.internal.ir.annotations.Ignore import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos class BuildStructure( @@ -17,26 +21,41 @@ class BuildStructure( private val direction: Direction = Direction.NORTH, private val offsetMove: BlockPos = BlockPos.ORIGIN, private val doPadding: Boolean = false, - private val respectIgnore: Boolean = false, - override val toRender: MutableSet = mutableSetOf(), override val maximumRepeats: Int = 1, override var repeated: Int = 0, -) : RepeatingActivity, RenderAABBActivity, Activity() { +) : RepeatingActivity, Activity() { private var currentOffset = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - structure.forEach { (pos, state) -> - val offsetPos = pos.add(currentOffset) + val activities = mutableListOf() - if (doPadding && isInPadding(offsetPos)) return@forEach - if (world.getBlockState(offsetPos) == state) return@forEach + structure.forEach { (pos, targetState) -> + val blockPos = pos.add(currentOffset) + val currentState = world.getBlockState(blockPos) - val activity = BuildBlock(offsetPos, state, respectIgnore) - - addSubActivities(activity) + when { + /* is in padding */ + doPadding && isInPadding(blockPos) -> return@forEach + /* is in desired state */ + currentState == targetState -> return@forEach + /* block needs to be placed */ + targetState != Blocks.AIR.defaultState -> { + activities.add(PlaceBlock( + blockPos, targetState + )) + } + /* only option left is breaking the block */ + else -> { + activities.add(BreakBlock(blockPos)) + } + } + } - LambdaEventBus.subscribe(activity) + activities.forEach { + LambdaEventBus.subscribe(it) } + + addSubActivities(activities) } override fun SafeClientEvent.onSuccess() { @@ -46,16 +65,15 @@ class BuildStructure( override fun SafeClientEvent.getCurrentActivity(): Activity { subActivities .asSequence() - .filterIsInstance() .sortedWith( - compareBy { + compareBy { it.status }.thenBy { - it.context + if (it is BuildActivity) it.context else 0 }.thenBy { - it.action + if (it is BuildActivity) it.action else 0 }.thenBy { - player.getPositionEyes(1f).distanceTo(it.blockPos) + if (it is BuildActivity) player.getPositionEyes(1f).distanceTo(it.hitVec) else 0.0 } ).firstOrNull()?.let { with(it) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt index 39909fae1..58b4e3c14 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt @@ -2,9 +2,9 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.LoopWhileActivity -import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition +import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos @@ -16,12 +16,17 @@ class SurroundWithObsidian( override var currentLoops: Int = 0 ) : LoopWhileActivity, Activity() { override fun SafeClientEvent.onInitialize() { + val material = Blocks.OBSIDIAN.defaultState + + val structure = mutableMapOf( + originPos.north() to material, + originPos.south() to material, + originPos.east() to material, + originPos.west() to material, + ) + addSubActivities( - BuildBlock(originPos.north(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(originPos.south(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(originPos.east(), Blocks.SLIME_BLOCK.defaultState), - BuildBlock(originPos.west(), Blocks.SLIME_BLOCK.defaultState), - Wait(10L) + BuildStructure(structure) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 128ef4505..e79fa6e85 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -1,210 +1,236 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BuildBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.activity.activities.types.RotatingActivity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.types.* import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.block import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid -import net.minecraft.block.material.Material import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item +import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent +import java.nio.channels.AcceptPendingException import java.util.* -import kotlin.collections.ArrayDeque import kotlin.math.ceil class BreakBlock( private val blockPos: BlockPos, - private val doPending: Boolean = false, private val collectDrops: Boolean = false, - private val miningSpeedFactor: Float = 1.0f, private val minCollectAmount: Int = 1, override var timeout: Long = 200L, override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), - override var rotation: Vec2f = Vec2f.ZERO -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, Activity() { + override var rotation: Vec2f? = null, + override var context: BuildActivity.BuildContext = BuildActivity.BuildContext.NONE, + override var action: BuildActivity.BuildAction = BuildActivity.BuildAction.UNINIT, + override var hitVec: Vec3d = Vec3d.ZERO +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, Activity() { + private var side: EnumFacing? = null private var ticksNeeded = 0 private var initState = Blocks.AIR.defaultState private var drop: Item = Items.AIR private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( - blockPos, - ColorHolder(222, 0, 0) + blockPos, action.color ).also { toRender.add(it) } - override fun SafeClientEvent.onInitialize() { - val currentState = world.getBlockState(blockPos) + init { + runSafe { updateState() } - if (currentState.material == Material.AIR) { - success() - return + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + updateState() + + if (status != Status.RUNNING + || context == BuildActivity.BuildContext.PENDING + || subActivities.isNotEmpty() + ) return@safeListener + + when (action) { + BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { + side?.let { side -> + checkBreak(side) + } + } + BuildActivity.BuildAction.WRONG_POS_BREAK -> { + if (autoPathing) { + addSubActivities(BreakGoal(blockPos)) + } + } + else -> { + // ToDo: break nearby blocks + failedWith(NoExposedSideFound()) + } + } } - if (!player.capabilities.isCreativeMode - && player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE - ) { // ToDo: get optimal tool - val owner = owner + safeListener { + if (it.packet !is SPacketBlockChange + || it.packet.blockPosition != blockPos + || it.packet.blockState.block != Blocks.AIR + ) return@safeListener - if (owner is BuildBlock) { - owner.context = BuildBlock.Context.RESTOCK + if (!collectDrops || !autoPathing) { + ActivityManagerHud.totalBlocksBroken++ + success() + return@safeListener } - addSubActivities(AcquireItemInActiveHand(Items.DIAMOND_PICKAXE)) - return + renderActivity.color = ColorHolder(252, 3, 207) + + if (drop.block == Blocks.AIR) return@safeListener + + addSubActivities( + PickUpDrops(drop, minAmount = minCollectAmount) + ) } + } - var needToHandleLiquid = false + override fun SafeClientEvent.onInitialize() { + updateState() - EnumFacing.values().forEach { - if (it == EnumFacing.DOWN) return@forEach + side?.let { + checkBreak(it) + } + } - val neighbour = blockPos.offset(it) - if (world.getBlockState(neighbour).isLiquid) { - val owner = owner + private fun SafeClientEvent.updateState() { + val currentState = world.getBlockState(blockPos) - if (owner is BuildBlock) { - owner.context = BuildBlock.Context.LIQUID - } + if (world.isAirBlock(blockPos) || currentState.block in BuildTools.ignoredBlocks) { + ActivityManagerHud.totalBlocksBroken++ + success() + return + } - addSubActivities(PlaceBlock(neighbour, BuildTools.defaultFillerMat.defaultState)) - needToHandleLiquid = true + getMiningSide(blockPos, BuildTools.maxReach)?.let { + action = BuildActivity.BuildAction.BREAK + hitVec = getHitVec(blockPos, it) + side = it + rotation = getRotationTo(getHitVec(blockPos, it)) + } ?: run { + getMiningSide(blockPos)?.let { + action = BuildActivity.BuildAction.WRONG_POS_BREAK + hitVec = getHitVec(blockPos, it) + } ?: run { + action = BuildActivity.BuildAction.INVALID_BREAK + hitVec = Vec3d.ZERO } + playerController.resetBlockRemoving() + side = null + rotation = null } - if (needToHandleLiquid) return + renderActivity.color = action.color + } + + private fun SafeClientEvent.checkBreak(side: EnumFacing) { + val currentState = world.getBlockState(blockPos) initState = currentState drop = currentState.block.getItemDropped(currentState, Random(), 0) - renderActivity.color = ColorHolder(240, 222, 60) + if (!player.capabilities.isCreativeMode +// && currentState.block.isToolEffective("pickaxe", currentState) + && player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE + ) { // ToDo: get optimal tool + context = BuildActivity.BuildContext.RESTOCK - ticksNeeded = ceil((1 / currentState.getPlayerRelativeBlockHardness(player, world, blockPos)) * miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 2000L + addSubActivities(AcquireItemInActiveHand(Items.DIAMOND_PICKAXE)) + return + } - if (!(ticksNeeded == 1 || player.capabilities.isCreativeMode)) return + ticksNeeded = ceil((1 / currentState + .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() + timeout = ticksNeeded * 50L + 2000L - getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> - rotation = getRotationTo(getHitVec(blockPos, side)) + var needToHandleLiquid = false - playerController.onPlayerDamageBlock(blockPos, side) - mc.effectRenderer.addBlockHitEffects(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) + EnumFacing.values() + .filter { it != EnumFacing.UP } + .map { blockPos.offset(it) } + .filter { world.getBlockState(it).isLiquid } + .forEach { + val placeActivity = PlaceBlock(it, BuildTools.defaultFillerMat.defaultState) + placeActivity.context = BuildActivity.BuildContext.LIQUID - if (BuildTools.breakDelay == 0) { - setBuildBlockOnPending() - } else { - addSubActivities(Wait(BuildTools.placeDelay * 50L - 5L)) + addSubActivities(placeActivity) + needToHandleLiquid = true } - } - } - - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - if (owner.status == Status.PENDING) return@safeListener - if (subActivities.isNotEmpty()) return@safeListener - getMiningSide(blockPos, BuildTools.maxReach)?.let { side -> - rotation = getRotationTo(getHitVec(blockPos, side)) + if (needToHandleLiquid) return - playerController.onPlayerDamageBlock(blockPos, side) - mc.effectRenderer.addBlockHitEffects(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) + doBreak(side) + } - if (doPending && (ticksNeeded == 1 || player.capabilities.isCreativeMode)) { - if (BuildTools.breakDelay == 0) { - owner.status = Status.PENDING - } else { - addSubActivities(Wait(BuildTools.placeDelay * 50L - 5L)) - } - } - } ?: run { - getMiningSide(blockPos)?.let { - if (autoPathing && subActivities.filterIsInstance().isEmpty()) { - addSubActivities(BreakGoal(blockPos)) - } - } ?: run { - failedWith(NoExposedSideFound()) - } - } + private fun SafeClientEvent.doBreak(side: EnumFacing) { + val isCreative = player.capabilities.isCreativeMode + + val successDamage = if (player.capabilities.isCreativeMode) { + connection.sendPacket(CPacketPlayerDigging( + CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side + )) + playerController.onPlayerDestroyBlock(blockPos) + } else { + action = BuildActivity.BuildAction.BREAKING + renderActivity.color = action.color + playerController.onPlayerDamageBlock(blockPos, side) } - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && it.packet.blockState.block == Blocks.AIR - ) { - if (!collectDrops || !autoPathing) { - success() - return@safeListener - } + if (!successDamage) { + failedWith(BlockBreakingException()) + return + } - renderActivity.color = ColorHolder(252, 3, 207) + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) - if (drop.block == Blocks.AIR) return@safeListener + if (BuildTools.breakDelay != 0) addSubActivities(Wait(BuildTools.breakDelay * 50L - 5L)) - addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount) - ) - } - } + if (ticksNeeded == 1 || isCreative) context = BuildActivity.BuildContext.PENDING } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is PickUpDrops -> { + ActivityManagerHud.totalBlocksBroken++ success() } - is Wait -> setBuildBlockOnPending() +// is Wait -> setBuildBlockOnPending() is AcquireItemInActiveHand, is PlaceBlock -> { status = Status.UNINITIALIZED } } } - override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { - if (childException !is BreakGoal.NoPathToBreakFound) return false - - if (owner !is BuildBlock) return false - - owner.status = Status.UNINITIALIZED - return true - } - override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() return false } - private fun setBuildBlockOnPending() { - if (!doPending || owner !is BuildBlock) return - - owner.status = Status.PENDING - } - class NoExposedSideFound : Exception("No exposed side found") + class BlockBreakingException : Exception("Block breaking failed") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 27bbb5411..8be88029c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -19,7 +19,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( private val containerPos: BlockPos, - override var rotation: Vec2f = Vec2f.ZERO, + override var rotation: Vec2f? = null, override val timeout: Long = 1000L, override val maxAttempts: Int = 3, override var usedAttempts: Int = 0, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index f353acc1b..53543a8fa 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -3,13 +3,10 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.activity.activities.types.RotatingActivity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.activities.types.* import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent +import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.client.BuildTools.directionForce @@ -19,39 +16,45 @@ import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.PlaceInfo import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isPlaceable import net.minecraft.block.* import net.minecraft.block.state.IBlockState import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.gameevent.TickEvent class PlaceBlock( private val blockPos: BlockPos, private val targetState: IBlockState, - private val doPending: Boolean = false, private val ignoreProperties: Boolean = false, - override var rotation: Vec2f = Vec2f.ZERO, + private val ignoreFacing: Boolean = false, + override var rotation: Vec2f? = null, override val timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, - override val toRender: MutableSet = mutableSetOf() -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, Activity() { + override val toRender: MutableSet = mutableSetOf(), + override var context: BuildActivity.BuildContext = BuildActivity.BuildContext.NONE, + override var action: BuildActivity.BuildAction = BuildActivity.BuildAction.UNINIT, + override var hitVec: Vec3d = Vec3d.ZERO +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, Activity() { + private var placeInfo: PlaceInfo? = null + private var spoofedDirection = false + private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( blockPos, - ColorHolder(35, 188, 254) + action.color ).also { toRender.add(it) } - private var spoofedDirection = false - private enum class PlacementOffset(val offset: Vec3d) { UPPER(Vec3d(0.0, 0.1, 0.0)), CENTER(Vec3d.ZERO), @@ -67,33 +70,49 @@ class PlaceBlock( BlockRedstoneDiode::class, ) - override fun SafeClientEvent.onInitialize() { - /* check if is done */ - if (world.getBlockState(blockPos) == targetState) { - success() - return - } + init { + runSafe { updateState() } - /* less strict done check */ - if (ignoreProperties && world.getBlockState(blockPos).block == targetState.block) { - success() - return - } + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener - /* check if block is placeable */ -// if (!targetState.block.canPlaceBlockOnSide(world, blockPos, EnumFacing.UP)) { -// failedWith(BlockNotPlaceableException(blockPos)) -// return -// } + updateState() - if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { - if (world.worldBorder.contains(blockPos) - && !world.isOutsideBuildHeight(blockPos)) { - addSubActivities(BreakBlock(blockPos)) - } else { - failedWith(BlockOutsideOfWorldException(blockPos)) + if (status != Status.RUNNING + || context == BuildActivity.BuildContext.PENDING + || subActivities.isNotEmpty() + ) return@safeListener + + when (action) { + BuildActivity.BuildAction.PLACE -> { + placeInfo?.let { placeInfo -> + checkPlace(placeInfo) + } + } + BuildActivity.BuildAction.WRONG_POS_PLACE -> { + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) + } + else -> { + // ToDo: place neighbours + failedWith(NoNeighbourException(blockPos)) + } } + } + } + override fun SafeClientEvent.onInitialize() { + updateState() + + placeInfo?.let { + checkPlace(it) + } + } + + private fun SafeClientEvent.updateState() { + val blockState = world.getBlockState(blockPos) + if (blockState == targetState || (ignoreProperties && blockState.block == targetState.block)) { + ActivityManagerHud.totalBlocksPlaced++ + success() return } @@ -103,28 +122,11 @@ class PlaceBlock( // var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> - var direction = entry.value as EnumFacing + val direction = entry.value as EnumFacing if (targetState.block is BlockButton) { allowedSides.clear() allowedSides.add(direction.opposite) - return@let - } - -// BlockDirectional -// BlockHorizontal -// BlockTorch -// BlockLever - - if (targetState.block::class in blocksToOppositeDirection) direction = direction.opposite - - /* rotate block to right direction if possible */ - if (directionForce - && !spoofedDirection - && player.horizontalFacing != direction - ) { - addSubActivities(Rotate(Vec2f(direction.horizontalAngle, player.rotationPitch))) - return } } @@ -163,6 +165,55 @@ class PlaceBlock( } } + getNeighbour( + blockPos, + attempts = BuildTools.placementSearch, + visibleSideCheck = placeStrictness != BuildTools.PlacementStrictness.ANY, + range = BuildTools.maxReach, + sides = allowedSides.toTypedArray() + )?.let { + placeInfo = it + action = BuildActivity.BuildAction.PLACE + hitVec = it.hitVec.add(placementOffset.offset) + rotation = getRotationTo(hitVec) + } ?: run { + getNeighbour( + blockPos, + attempts = BuildTools.placementSearch, + visibleSideCheck = false, + range = 256f, + sides = allowedSides.toTypedArray() + )?.let { + action = BuildActivity.BuildAction.WRONG_POS_PLACE + hitVec = it.hitVec.add(placementOffset.offset) + } ?: run { + action = BuildActivity.BuildAction.INVALID_PLACE + hitVec = Vec3d.ZERO + } + placeInfo = null + rotation = null + } + + renderActivity.color = action.color + } + + private fun SafeClientEvent.checkPlace(placeInfo: PlaceInfo) { +// if (!targetState.block.canPlaceBlockOnSide(world, blockPos, EnumFacing.UP)) { +// failedWith(BlockNotPlaceableException(blockPos)) +// return +// } + + /* check if block is placeable */ + if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { + if (world.worldBorder.contains(blockPos) + && !world.isOutsideBuildHeight(blockPos)) { + addSubActivities(BreakBlock(blockPos)) + } else { + failedWith(BlockOutsideOfWorldException(blockPos)) + } + return + } + /* check if item has required metadata (declares the type) */ val heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND) val optimalStack = if (targetState.block is BlockShulkerBox) { @@ -175,6 +226,8 @@ class PlaceBlock( if (heldItemStack.item != optimalStack.item || (!ignoreProperties && optimalStack.metadata != heldItemStack.metadata) ) { + context = BuildActivity.BuildContext.RESTOCK + addSubActivities(AcquireItemInActiveHand( optimalStack.item, metadata = optimalStack.metadata @@ -182,16 +235,27 @@ class PlaceBlock( return } - getNeighbour( - blockPos, - attempts = BuildTools.placementSearch, - visibleSideCheck = placeStrictness != BuildTools.PlacementStrictness.ANY, - range = BuildTools.maxReach, - sides = allowedSides.toTypedArray() - )?.let { - val hitVec = it.hitVec.add(placementOffset.offset) + targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> + var direction = entry.value as EnumFacing + +// BlockDirectional +// BlockHorizontal +// BlockTorch +// BlockLever + + if (targetState.block::class in blocksToOppositeDirection) direction = direction.opposite + + /* rotate block to right direction if possible */ + if (directionForce + && !spoofedDirection + && player.horizontalFacing != direction + ) { + addSubActivities(Rotate(Vec2f(direction.horizontalAngle, player.rotationPitch))) + return + } + } -// /* last check for placement state */ + /* last check for placement state */ // val resultingState = targetState.block.getStateForPlacement( // world, // it.pos, @@ -210,76 +274,41 @@ class PlaceBlock( // return // } - val isBlacklisted = world.getBlockState(it.pos).block in blockBlacklist + doPlace(placeInfo) + } - renderActivity.color = ColorHolder(11, 66, 89) + private fun SafeClientEvent.doPlace(placeInfo: PlaceInfo) { + val isBlacklisted = world.getBlockState(placeInfo.pos).block in blockBlacklist - if (isBlacklisted) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) - } + renderActivity.color = ColorHolder(11, 66, 89) - rotation = getRotationTo(hitVec) + if (isBlacklisted) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } - val result = playerController.processRightClickBlock(player, world, it.pos, it.side, hitVec, EnumHand.MAIN_HAND) + val result = playerController.processRightClickBlock(player, world, placeInfo.pos, placeInfo.side, hitVec, EnumHand.MAIN_HAND) - if (result != EnumActionResult.SUCCESS) { - failedWith(ProcessRightClickException(result)) - return - } - - player.swingArm(EnumHand.MAIN_HAND) + if (result != EnumActionResult.SUCCESS) { + failedWith(ProcessRightClickException(result)) + return + } - if (isBlacklisted) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) - } + player.swingArm(EnumHand.MAIN_HAND) - if (doPending) { - if (BuildTools.placeDelay == 0) { - owner.status = Status.PENDING - } else { - addSubActivities(Wait(BuildTools.placeDelay * 50L)) - } - } - } ?: run { - getNeighbour( - blockPos, - attempts = BuildTools.placementSearch, - visibleSideCheck = false, - range = 256f - )?.let { - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) - } ?: run { - failedWith(NoNeighbourException(blockPos)) - } + if (isBlacklisted) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - } - init { - safeListener { - if (it.packet is SPacketBlockChange - && it.packet.blockPosition == blockPos - && subActivities.isEmpty() - ) { - when { - it.packet.blockState == targetState -> { - success() - } - ignoreProperties && it.packet.blockState.block == targetState.block -> { - success() - } - else -> { - failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) - } - } - } - } + if (BuildTools.placeDelay != 0) addSubActivities(Wait(BuildTools.placeDelay * 50L)) + + context = BuildActivity.BuildContext.PENDING } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { - is Wait -> { - if (doPending) owner.status = Status.PENDING - } +// is Wait -> { +// if (doPending) owner.status = Status.PENDING +// } is Rotate -> { spoofedDirection = true @@ -296,7 +325,6 @@ class PlaceBlock( class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") class BlockNotPlaceableException(targetState: IBlockState) : Exception("Block $targetState is not placeable") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") - class PlacementStateException(placementState: IBlockState, targetState: IBlockState) : Exception("Placement state $placementState does not match target state $targetState") class UnexpectedBlockStateException(blockPos: BlockPos, expected: IBlockState, actual: IBlockState) : Exception("Unexpected block state at (${blockPos.asString()}) expected $expected but got $actual") class BlockOutsideOfWorldException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt index 940241c4f..9f37af903 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt @@ -7,7 +7,7 @@ import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent class Rotate( - override var rotation: Vec2f + override var rotation: Vec2f? = null, ) : RotatingActivity, Activity() { init { safeListener { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt index 817974be9..7273fec74 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -15,7 +15,7 @@ class UseThrowableOnEntity( private val targetEntity: Entity, private val amount: Int = 1, private val useHand: EnumHand = EnumHand.MAIN_HAND, - override var rotation: Vec2f = Vec2f.ZERO, + override var rotation: Vec2f? = null, ) : RotatingActivity, Activity() { private var used = 0 diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index ddc87cfef..cc8673a7a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -7,7 +7,9 @@ import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock -import com.lambda.client.util.items.* +import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.items.item import net.minecraft.init.Blocks import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -17,7 +19,7 @@ class AcquireItemInActiveHand( private val item: Item, private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, - private val metadata: Int = 0, + private var metadata: Int? = null, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false, override val maxAttempts: Int = 3, @@ -25,19 +27,19 @@ class AcquireItemInActiveHand( ) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { player.hotbarSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) && metadata == slot.stack.metadata + slot.stack.item == item && predicateItem(slot.stack) && (metadata == null || metadata == slot.stack.metadata) }?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { if (pickBlock && player.capabilities.isCreativeMode) { addSubActivities(CreativeInventoryAction( - ItemStack(item, 1, metadata) + ItemStack(item, 1, metadata ?: 0) )) return } player.allSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) && metadata == slot.stack.metadata + slot.stack.item == item && predicateItem(slot.stack) && (metadata == null || metadata == slot.stack.metadata) }?.let { slotFrom -> addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) } ?: run { @@ -77,5 +79,5 @@ class AcquireItemInActiveHand( status = Status.UNINITIALIZED } - class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${ metadata?.let { ":$it" } ?: "" } found in inventory (shulkers are disabled)") + class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${metadata?.let { ":$it" } ?: ""} found in inventory (shulkers are disabled)") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt index c07894dbf..dc073259c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt @@ -4,9 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.items.toHotbarSlotOrNull import com.lambda.client.util.threads.safeListener -import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketCreativeInventoryAction import net.minecraft.network.play.server.SPacketSetSlot diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index 8e71cbe60..d382730e3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 79a030084..eacec6396 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -34,7 +34,7 @@ class PickUpEntityItem( if (subActivities.filterIsInstance().isNotEmpty()) return@safeListener - player.inventorySlots.firstOrNull() { slot -> + player.inventorySlots.firstOrNull { slot -> BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt new file mode 100644 index 000000000..cae3f9b07 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -0,0 +1,28 @@ +package com.lambda.client.activity.activities.types + +import com.lambda.client.util.color.ColorHolder +import net.minecraft.util.math.Vec3d + +interface BuildActivity { + var context: BuildContext + var action: BuildAction + var hitVec: Vec3d + + enum class BuildContext(val color: ColorHolder) { + RESTOCK(ColorHolder()), + LIQUID(ColorHolder()), + NONE(ColorHolder()), + PENDING(ColorHolder()) + } + + enum class BuildAction(val color: ColorHolder) { + BREAKING(ColorHolder(240, 222, 60)), + BREAK(ColorHolder(222, 0, 0)), + PLACE(ColorHolder(35, 188, 254)), + WRONG_POS_BREAK(ColorHolder(112, 0, 0)), + WRONG_POS_PLACE(ColorHolder(20, 108, 145)), + INVALID_BREAK(ColorHolder(46, 0, 0)), + INVALID_PLACE(ColorHolder(11, 55, 74)), + UNINIT(ColorHolder(11, 11, 11)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt index 60ec171e5..e93cce7c4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt @@ -5,15 +5,17 @@ import com.lambda.client.manager.managers.PlayerPacketManager import com.lambda.client.util.math.Vec2f interface RotatingActivity { - var rotation: Vec2f + var rotation: Vec2f? companion object { fun checkRotating(activity: Activity) { if (activity !is RotatingActivity) return with(activity) { - PlayerPacketManager.sendPlayerPacket { - rotate(rotation) + rotation?.let { + PlayerPacketManager.sendPlayerPacket { + rotate(it) + } } } } diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt index 8f9d9a43d..c97f08122 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt @@ -24,13 +24,24 @@ internal object ActivityManagerHud: LabelHud( if (startTime == 0L) startTime = System.currentTimeMillis() + val runTimeMS = System.currentTimeMillis() - startTime + val runTimeS = (runTimeMS + 1) / 1000.0 + with(ActivityManager) { displayText.add("Runtime", secondaryColor) - displayText.addLine(DurationFormatUtils.formatDuration(System.currentTimeMillis() - startTime, "HH:mm:ss,SSS"), primaryColor) + displayText.addLine(DurationFormatUtils.formatDuration(runTimeMS, "HH:mm:ss,SSS"), primaryColor) displayText.add("Amount", secondaryColor) displayText.add(ActivityManager.allSubActivities.size.toString(), primaryColor) displayText.add("Current", secondaryColor) - displayText.addLine(getCurrentActivity().activityName, primaryColor) + displayText.add(getCurrentActivity().activityName, primaryColor) + displayText.add("Total Placed", secondaryColor) + displayText.add(totalBlocksPlaced.toString(), primaryColor) + displayText.add("Total Broken", secondaryColor) + displayText.add(totalBlocksBroken.toString(), primaryColor) + displayText.add("Place/s", secondaryColor) + displayText.add("%.2f".format(totalBlocksPlaced / runTimeS), primaryColor) + displayText.add("Break/s", secondaryColor) + displayText.addLine("%.2f".format(totalBlocksBroken / runTimeS), primaryColor) appendInfo(displayText, primaryColor, secondaryColor, details) } @@ -45,4 +56,9 @@ internal object ActivityManagerHud: LabelHud( if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.map { it::class.simpleName }}") } } + + // STATS? + + var totalBlocksPlaced = 0 + var totalBlocksBroken = 0 } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 454b486a4..993ce854e 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,6 +1,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.event.LambdaEventBus @@ -24,17 +25,16 @@ object ActivityManager : Manager, Activity(true) { val allActivities = allSubActivities - allActivities.filter { it.status == Status.PENDING }.forEach { - with(it) { - updateTypesOnTick(it) + allActivities + .filter { it.status == Status.RUNNING } + .forEach { + if (it is BuildActivity && it.context == BuildActivity.BuildContext.PENDING) { + return@forEach + } + with(it) { + updateTypesOnTick(it) + } } - } - - with(getCurrentActivity()) { - if (status == Status.RUNNING - || status == Status.PENDING - ) updateTypesOnTick(this) - } repeat(executionCountPerTick) { with(getCurrentActivity()) { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index f41ae0374..0912156f9 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -32,7 +32,7 @@ object BuildTools : Module( /* mining */ val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") -// val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.MINING }, description = "Factor to manipulate calculated mining speed") + val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.BUILDING }, description = "Factor to manipulate calculated mining speed") // val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") // val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") // val packetFlood by setting("Packet Flood", false, { page == Page.MINING }, description = "Exploit for faster packet breaks. Sends START and STOP packet on same tick") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 262d8c48b..2afc57de0 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -2,6 +2,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category @@ -69,13 +70,15 @@ object HighwayTools : Module( printEnable() + ActivityManagerHud.totalBlocksBroken = 0 + ActivityManagerHud.totalBlocksPlaced = 0 + BuildStructure( generateHighway(), direction = originDirection, offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), maximumRepeats = distance, - doPadding = true, - respectIgnore = true + doPadding = true ).let { ownedBuildStructure = it ActivityManager.addSubActivities(it) From e81fc22aae0e484140926178e6c3a767c0ad00a2 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 20 Feb 2023 08:00:41 +0100 Subject: [PATCH 068/104] Fix block replacement --- .../activities/interaction/BreakBlock.kt | 8 +++--- .../activities/interaction/PlaceBlock.kt | 25 ++++++++++--------- .../activity/activities/interaction/Rotate.kt | 2 +- .../manager/managers/ActivityManager.kt | 5 +--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index e79fa6e85..40cb73ceb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -200,10 +200,10 @@ class BreakBlock( playerController.onPlayerDamageBlock(blockPos, side) } - if (!successDamage) { - failedWith(BlockBreakingException()) - return - } +// if (!successDamage) { +// failedWith(BlockBreakingException()) +// return +// } mc.effectRenderer.addBlockHitEffects(blockPos, side) player.swingArm(EnumHand.MAIN_HAND) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 53543a8fa..73e0f9be4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -121,6 +121,17 @@ class PlaceBlock( // var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() + /* check if block is placeable */ + if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { + if (world.worldBorder.contains(blockPos) + && !world.isOutsideBuildHeight(blockPos)) { + if (subActivities.isEmpty()) addSubActivities(BreakBlock(blockPos)) + } else { + failedWith(BlockOutsideOfWorldException(blockPos)) + } + return + } + targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> val direction = entry.value as EnumFacing @@ -175,7 +186,6 @@ class PlaceBlock( placeInfo = it action = BuildActivity.BuildAction.PLACE hitVec = it.hitVec.add(placementOffset.offset) - rotation = getRotationTo(hitVec) } ?: run { getNeighbour( blockPos, @@ -203,17 +213,6 @@ class PlaceBlock( // return // } - /* check if block is placeable */ - if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { - if (world.worldBorder.contains(blockPos) - && !world.isOutsideBuildHeight(blockPos)) { - addSubActivities(BreakBlock(blockPos)) - } else { - failedWith(BlockOutsideOfWorldException(blockPos)) - } - return - } - /* check if item has required metadata (declares the type) */ val heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND) val optimalStack = if (targetState.block is BlockShulkerBox) { @@ -286,6 +285,8 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } + rotation = getRotationTo(hitVec) + val result = playerController.processRightClickBlock(player, world, placeInfo.pos, placeInfo.side, hitVec, EnumHand.MAIN_HAND) if (result != EnumActionResult.SUCCESS) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt index 9f37af903..d05622f98 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt @@ -7,7 +7,7 @@ import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent class Rotate( - override var rotation: Vec2f? = null, + override var rotation: Vec2f?, ) : RotatingActivity, Activity() { init { safeListener { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 993ce854e..1e888e939 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -26,11 +26,8 @@ object ActivityManager : Manager, Activity(true) { val allActivities = allSubActivities allActivities - .filter { it.status == Status.RUNNING } + .filter { it.status == Status.RUNNING && it.subActivities.isEmpty() } .forEach { - if (it is BuildActivity && it.context == BuildActivity.BuildContext.PENDING) { - return@forEach - } with(it) { updateTypesOnTick(it) } From c5ca532a834aa93b6695872974230d732468343d Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 20 Feb 2023 23:20:01 +0100 Subject: [PATCH 069/104] Fix boxed tasks --- .../activities/highlevel/BuildStructure.kt | 32 ++++++++++++++++--- .../activities/interaction/PlaceBlock.kt | 25 ++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index cbae9d145..4cbb173a6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -7,6 +7,7 @@ import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager.getCurrentActivity import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction @@ -67,13 +68,27 @@ class BuildStructure( .asSequence() .sortedWith( compareBy { - it.status + with(it) { + getCurrentActivity().status + } }.thenBy { - if (it is BuildActivity) it.context else 0 + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + current.context + } else 0 }.thenBy { - if (it is BuildActivity) it.action else 0 + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + current.action + } else 0 }.thenBy { - if (it is BuildActivity) player.getPositionEyes(1f).distanceTo(it.hitVec) else 0.0 + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + player.getPositionEyes(1f).distanceTo(current.hitVec) + } else 0.0 } ).firstOrNull()?.let { with(it) { @@ -82,6 +97,15 @@ class BuildStructure( } ?: return this@BuildStructure } + /* BreakBlocks that are boxed in a PlaceBlock are considered in the sequence */ + private fun SafeClientEvent.deepestBuildActivity(activity: Activity): Activity { + activity.subActivities + .filterIsInstance() + .firstOrNull()?.let { + return deepestBuildActivity(it as Activity) + } ?: return activity + } + private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) private fun isBehindPos(origin: BlockPos, check: BlockPos): Boolean { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 73e0f9be4..0852e2c10 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -5,6 +5,7 @@ import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* import com.lambda.client.activity.activities.utils.Wait +import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools @@ -125,7 +126,12 @@ class PlaceBlock( if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { if (world.worldBorder.contains(blockPos) && !world.isOutsideBuildHeight(blockPos)) { - if (subActivities.isEmpty()) addSubActivities(BreakBlock(blockPos)) + if (subActivities.isNotEmpty()) return + + renderActivity.color = ColorHolder(0, 0, 0, 0) + val breakBlock = BreakBlock(blockPos) + addSubActivities(breakBlock) + LambdaEventBus.subscribe(breakBlock) } else { failedWith(BlockOutsideOfWorldException(blockPos)) } @@ -166,7 +172,7 @@ class PlaceBlock( } } - /* quartz is special snowflake */ + /* quartz is a special snowflake */ targetState.properties.entries.firstOrNull { it.key.name == "variant" }?.let { entry -> when (entry.value) { BlockQuartz.EnumType.LINES_X -> allowedSides.removeIf { it.axis != EnumFacing.Axis.X } @@ -176,6 +182,11 @@ class PlaceBlock( } } +// /* check if block is replaceable */ +// allowedSides.removeIf { +// !targetState.block.canPlaceBlockOnSide(world, blockPos, it.opposite) +// } + getNeighbour( blockPos, attempts = BuildTools.placementSearch, @@ -208,11 +219,6 @@ class PlaceBlock( } private fun SafeClientEvent.checkPlace(placeInfo: PlaceInfo) { -// if (!targetState.block.canPlaceBlockOnSide(world, blockPos, EnumFacing.UP)) { -// failedWith(BlockNotPlaceableException(blockPos)) -// return -// } - /* check if item has required metadata (declares the type) */ val heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND) val optimalStack = if (targetState.block is BlockShulkerBox) { @@ -307,15 +313,10 @@ class PlaceBlock( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { -// is Wait -> { -// if (doPending) owner.status = Status.PENDING -// } - is Rotate -> { spoofedDirection = true status = Status.UNINITIALIZED } - else -> { spoofedDirection = false status = Status.UNINITIALIZED From 23be96eec93b5e99027a49853366587ca327ba68 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 22 Feb 2023 07:06:47 +0100 Subject: [PATCH 070/104] Adding concurrent build actions --- .../com/lambda/client/activity/Activity.kt | 42 ++++++- .../activities/highlevel/BuildStructure.kt | 58 ++++----- .../activities/interaction/BreakBlock.kt | 57 +++++---- .../activities/interaction/PlaceBlock.kt | 2 + .../activities/storage/PlaceContainer.kt | 16 +-- .../activities/types/TimedActivity.kt | 5 + .../elements/client/ActivityManagerHud.kt | 2 +- .../module/modules/client/BuildTools.kt | 3 +- .../module/modules/misc/HighwayTools.kt | 8 +- .../module/modules/misc/SchematicBuilder.kt | 10 +- .../modules/misc/TestActivityManager.kt | 111 ++++++++---------- .../modules/player/InventoryManagerTwo.kt | 37 +++--- 12 files changed, 182 insertions(+), 169 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index e5b483ed6..adada7b75 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt +import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.DelayedActivity import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed import com.lambda.client.activity.activities.types.EndlessActivity @@ -26,10 +27,10 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils -import java.util.concurrent.ConcurrentLinkedDeque +import java.util.concurrent.PriorityBlockingQueue abstract class Activity(val isRoot: Boolean = false) { - val subActivities = ConcurrentLinkedDeque() + open val subActivities = PriorityBlockingQueue(15, compareBy { it.status }) var status = Status.UNINITIALIZED private var creationTime = 0L var owner: Activity = ActivityManager @@ -48,6 +49,8 @@ abstract class Activity(val isRoot: Boolean = false) { open fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean = false + open fun SafeClientEvent.onCancel() {} + open fun addExtraInfo( textComponent: TextComponent, primaryColor: ColorHolder, @@ -155,6 +158,27 @@ abstract class Activity(val isRoot: Boolean = false) { ActivityManager.reset() } + fun SafeClientEvent.cancel() { + val activity = this@Activity + + subActivities.forEach { + with(it) { + cancel() + } + } + + LambdaEventBus.unsubscribe(activity) + ListenerManager.unregister(activity) + + with(owner) { + subActivities.remove(activity) + } + + onCancel() + + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + } + private fun SafeClientEvent.childFailure(childActivities: ArrayDeque, childException: Exception): Boolean { if (onChildFailure(childActivities, childException)) return true @@ -218,6 +242,16 @@ abstract class Activity(val isRoot: Boolean = false) { textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), primaryColor) } + if (this is BuildActivity) { + textComponent.add("Context", secondaryColor) + textComponent.add(context.name, primaryColor) + textComponent.add("Action", secondaryColor) + textComponent.add(action.name, primaryColor) + } + + textComponent.add("Hash", secondaryColor) + textComponent.add(hashCode().toString(), primaryColor) + if (details) { this::class.java.declaredFields.forEachIndexed { index, field -> field.isAccessible = true @@ -253,7 +287,9 @@ abstract class Activity(val isRoot: Boolean = false) { addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") // subActivities.filter { !(it is BuildBlock && it.activityStatus == ActivityStatus.UNINITIALIZED) }.forEach { - subActivities.forEach { + val sortedList = subActivities.toTypedArray().sortedWith(subActivities.comparator()) + + sortedList.forEach { repeat(depth) { textComponent.add(" ") } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 4cbb173a6..2a251f300 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -5,17 +5,18 @@ import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RepeatingActivity +import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent -import com.lambda.client.manager.managers.ActivityManager.getCurrentActivity import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.Wrapper import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply -import jdk.nashorn.internal.ir.annotations.Ignore import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos +import java.util.concurrent.PriorityBlockingQueue class BuildStructure( private val structure: Map, @@ -26,6 +27,7 @@ class BuildStructure( override var repeated: Int = 0, ) : RepeatingActivity, Activity() { private var currentOffset = BlockPos.ORIGIN + override val subActivities = PriorityBlockingQueue(100, buildComparator()) override fun SafeClientEvent.onInitialize() { val activities = mutableListOf() @@ -63,42 +65,28 @@ class BuildStructure( currentOffset = currentOffset.add(offsetMove) } - override fun SafeClientEvent.getCurrentActivity(): Activity { - subActivities - .asSequence() - .sortedWith( - compareBy { - with(it) { - getCurrentActivity().status - } - }.thenBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - current.context - } else 0 - }.thenBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - current.action - } else 0 - }.thenBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - player.getPositionEyes(1f).distanceTo(current.hitVec) - } else 0.0 - } - ).firstOrNull()?.let { - with(it) { - return getCurrentActivity() - } - } ?: return this@BuildStructure + private fun buildComparator() = compareBy { + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + current.context + } else 0 + }.thenBy { + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + current.action + } else 0 + }.thenBy { + val current = deepestBuildActivity(it) + + if (current is BuildActivity) { + Wrapper.player?.getPositionEyes(1f)?.distanceTo(current.hitVec) ?: 0.0 + } else 0.0 } /* BreakBlocks that are boxed in a PlaceBlock are considered in the sequence */ - private fun SafeClientEvent.deepestBuildActivity(activity: Activity): Activity { + private fun deepestBuildActivity(activity: Activity): Activity { activity.subActivities .filterIsInstance() .firstOrNull()?.let { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 40cb73ceb..d89da5229 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -5,7 +5,6 @@ import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.* -import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud @@ -30,7 +29,6 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent -import java.nio.channels.AcceptPendingException import java.util.* import kotlin.math.ceil @@ -46,11 +44,14 @@ class BreakBlock( override var context: BuildActivity.BuildContext = BuildActivity.BuildContext.NONE, override var action: BuildActivity.BuildAction = BuildActivity.BuildAction.UNINIT, override var hitVec: Vec3d = Vec3d.ZERO -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, Activity() { +) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 private var initState = Blocks.AIR.defaultState private var drop: Item = Items.AIR + override var earliestFinish: Long + get() = BuildTools.breakDelay.toLong() + set(_) {} private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( blockPos, action.color @@ -64,10 +65,10 @@ class BreakBlock( updateState() - if (status != Status.RUNNING - || context == BuildActivity.BuildContext.PENDING - || subActivities.isNotEmpty() - ) return@safeListener +// if (status != Status.RUNNING +// || context == BuildActivity.BuildContext.PENDING +// || subActivities.isNotEmpty() +// ) return@safeListener when (action) { BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { @@ -82,7 +83,7 @@ class BreakBlock( } else -> { // ToDo: break nearby blocks - failedWith(NoExposedSideFound()) +// failedWith(NoExposedSideFound()) } } } @@ -93,19 +94,7 @@ class BreakBlock( || it.packet.blockState.block != Blocks.AIR ) return@safeListener - if (!collectDrops || !autoPathing) { - ActivityManagerHud.totalBlocksBroken++ - success() - return@safeListener - } - - renderActivity.color = ColorHolder(252, 3, 207) - - if (drop.block == Blocks.AIR) return@safeListener - - addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount) - ) + finish() } } @@ -117,15 +106,27 @@ class BreakBlock( } } - private fun SafeClientEvent.updateState() { - val currentState = world.getBlockState(blockPos) + override fun SafeClientEvent.onCancel() { + playerController.resetBlockRemoving() + } - if (world.isAirBlock(blockPos) || currentState.block in BuildTools.ignoredBlocks) { + private fun SafeClientEvent.finish() { + if (!collectDrops || !autoPathing) { ActivityManagerHud.totalBlocksBroken++ success() return } + renderActivity.color = ColorHolder(252, 3, 207) + + if (drop.block == Blocks.AIR) return + + addSubActivities( + PickUpDrops(drop, minAmount = minCollectAmount) + ) + } + + private fun SafeClientEvent.updateState() { getMiningSide(blockPos, BuildTools.maxReach)?.let { action = BuildActivity.BuildAction.BREAK hitVec = getHitVec(blockPos, it) @@ -205,12 +206,11 @@ class BreakBlock( // return // } - mc.effectRenderer.addBlockHitEffects(blockPos, side) player.swingArm(EnumHand.MAIN_HAND) - if (BuildTools.breakDelay != 0) addSubActivities(Wait(BuildTools.breakDelay * 50L - 5L)) - - if (ticksNeeded == 1 || isCreative) context = BuildActivity.BuildContext.PENDING + if (ticksNeeded == 1 || isCreative) { + context = BuildActivity.BuildContext.PENDING + } } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { @@ -219,7 +219,6 @@ class BreakBlock( ActivityManagerHud.totalBlocksBroken++ success() } -// is Wait -> setBuildBlockOnPending() is AcquireItemInActiveHand, is PlaceBlock -> { status = Status.UNINITIALIZED } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 0852e2c10..df6a4a351 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -241,6 +241,8 @@ class PlaceBlock( } targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> + if (ignoreProperties || ignoreFacing) return@let + var direction = entry.value as EnumFacing // BlockDirectional diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index d382730e3..dc628e67d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -18,11 +18,9 @@ class PlaceContainer( var containerPos: BlockPos = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - if (containerPos == BlockPos.ORIGIN) { - containerPos = getContainerPos(targetState) ?: run { - failedWith(NoContainerPlacePositionFoundException()) - return - } + containerPos = getContainerPos(targetState) ?: run { + failedWith(NoContainerPlacePositionFoundException()) + return } addSubActivities(PlaceBlock( @@ -32,13 +30,5 @@ class PlaceContainer( )) } - override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { - if (childActivities.firstOrNull() !is PlaceBlock) return false - - checkAttempt(this@PlaceContainer, childException) - containerPos = BlockPos.ORIGIN - return true - } - class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt new file mode 100644 index 000000000..607df2469 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt @@ -0,0 +1,5 @@ +package com.lambda.client.activity.activities.types + +interface TimedActivity { + var earliestFinish: Long +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt index c97f08122..76c18c2c6 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt @@ -33,7 +33,7 @@ internal object ActivityManagerHud: LabelHud( displayText.add("Amount", secondaryColor) displayText.add(ActivityManager.allSubActivities.size.toString(), primaryColor) displayText.add("Current", secondaryColor) - displayText.add(getCurrentActivity().activityName, primaryColor) + displayText.addLine(getCurrentActivity().activityName, primaryColor) displayText.add("Total Placed", secondaryColor) displayText.add(totalBlocksPlaced.toString(), primaryColor) displayText.add("Total Broken", secondaryColor) diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 0912156f9..262b16a0c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -31,7 +31,8 @@ object BuildTools : Module( // }) /* mining */ - val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") + val breakDelay by setting("Break Delay", 50, 0..1000, 5, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ms") + val maxPending by setting("Max Pending", 1, 1..100, 1, { page == Page.BUILDING }, description = "Sets the maximum amount of pending break tasks") val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.BUILDING }, description = "Factor to manipulate calculated mining speed") // val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") // val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 2afc57de0..8fa1db8ae 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -87,7 +87,13 @@ object HighwayTools : Module( } onDisable { - ActivityManager.reset() + runSafe { + ownedBuildStructure?.let { + with(it) { + cancel() + } + } + } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt index 56cbd61a3..876aa7ba1 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -3,6 +3,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.highlevel.BuildSchematic import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.manager.managers.ActivityManager.cancel import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.math.Direction @@ -50,14 +51,13 @@ object SchematicBuilder : Module( } onDisable { - ownedBuildStructure?.let { - with(it) { - runSafe { - success() + runSafe { + ownedBuildStructure?.let { + with(it) { + cancel() } } } - ActivityManager.reset() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index a1d56c2d8..d61e13b05 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -7,6 +7,7 @@ import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.highlevel.ReachXPLevel import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity @@ -54,9 +55,9 @@ object TestActivityManager : Module( description = "a", category = Category.MISC ) { - private val a by setting("Get any Dia Pickaxe", false, consumer = { _, _-> + private val ctiectie by setting("Auto Obby", false, consumer = { _, _-> ActivityManager.addSubActivities( - AcquireItemInActiveHand(Items.DIAMOND_PICKAXE) + BreakDownEnderChests() ) false }) @@ -68,17 +69,54 @@ object TestActivityManager : Module( false }) - private val ctiectie by setting("Auto Obby", false, consumer = { _, _-> + private val etit by setting("Extract Obby", false, consumer = { _, _-> ActivityManager.addSubActivities( - BreakDownEnderChests() + ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item) ) false }) - private val etit by setting("Extract Obby", false, consumer = { _, _-> - ActivityManager.addSubActivities( - ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item) - ) + private val ectiecti by setting("Break Place", false, consumer = { _, _-> + runSafe { + val currentDirection = player.horizontalFacing + val pos = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) + +// val targetState = Blocks.QUARTZ_BLOCK.defaultState +// .withProperty(BlockQuartz.VARIANT, BlockQuartz.EnumType.LINES_X) + + val targetState = Blocks.ENDER_CHEST.defaultState + + ActivityManager.addSubActivities( + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos), + PlaceBlock(pos, targetState), + BreakBlock(pos) + ) + } false }) @@ -121,40 +159,11 @@ object TestActivityManager : Module( false }) - private val b by setting("Get Dia Pickaxe with silktouch", false, consumer = { _, _-> - ActivityManager.addSubActivities( - AcquireItemInActiveHand( - Items.DIAMOND_PICKAXE, - predicateItem = { - EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 - }, - predicateSlot = { - val item = it.item - item != Items.DIAMOND_PICKAXE && item.block !is BlockShulkerBox - } - ) - ) - false - }) - - private val dumpInventoryActivity by setting("Dump Inventory", false, consumer = { _, _-> - ActivityManager.addSubActivities(DumpInventory()) - false - }) - private val po by setting("Pickup Obby", false, consumer = { _, _-> ActivityManager.addSubActivities(PickUpDrops(Blocks.OBSIDIAN.item)) false }) - private val ti by setting("count", false, consumer = { _, _-> - runSafe { - LambdaMod.LOG.info(player.inventorySlots.countEmpty()) - } - - false - }) - private val tiectie by setting("Surround me", false, consumer = { _, _-> runSafe { player.centerPlayer() @@ -180,39 +189,11 @@ object TestActivityManager : Module( false }) - private val ctirsgn by setting("Throw", false, consumer = { _, _-> - runSafe { - ActivityManager.addSubActivities( - UseThrowableOnEntity(player, amount = 64) - ) - } - false - }) - private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> ActivityManager.addSubActivities(SayAnnoyingly("Hello World")) false }) - private val fail by setting("maybe fail", false, consumer = { _, _-> - ActivityManager.addSubActivities(ProbablyFailing()) - false - }) - - private val pullll by setting("Extract", false, consumer = { _, _-> - ActivityManager.addSubActivities( - ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item, amount = 1) - ) - false - }) - - private val pusshhh by setting("Store", false, consumer = { _, _-> - ActivityManager.addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item, amount = 1) - ) - false - }) - val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> ActivityManager.addSubActivities(ReachXPLevel(30)) false diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index cad289ba6..3bff44aa2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -2,6 +2,7 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.storage.OpenShulkerFromSlot +import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities @@ -11,9 +12,12 @@ import com.lambda.client.util.items.item import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockShulkerBox +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.inventory.ClickType import net.minecraft.item.ItemShulkerBox +import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent object InventoryManagerTwo : Module( @@ -22,6 +26,7 @@ object InventoryManagerTwo : Module( category = Category.PLAYER ) { private val placedShulkerBoxes = ArrayDeque(mutableListOf()) + private val currentlyOpen: OpenShulkerFromSlot? = null init { safeListener { @@ -73,7 +78,7 @@ object InventoryManagerTwo : Module( val cloned = ArrayDeque(placedShulkerBoxes) cloned.forEachIndexed { index, openShulker -> - if (index == 0) return@forEachIndexed + if (index == 0 || openShulker.containerPos == BlockPos.ORIGIN) return@forEachIndexed placedShulkerBoxes.remove(openShulker) val currentBlock = world.getBlockState(openShulker.containerPos).block @@ -86,20 +91,20 @@ object InventoryManagerTwo : Module( } } -// safeListener { -// if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener -// -// placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> -// placedShulkerBoxes.remove(openShulkerFromSlot) -// -// val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block -// -// if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener -// -// ActivityManager.addSubActivities( -// BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) -// ) -// } -// } + safeListener { + if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener + + placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> + placedShulkerBoxes.remove(openShulkerFromSlot) + + val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block + + if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener + + ActivityManager.addSubActivities( + BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) + ) + } + } } } \ No newline at end of file From 140dc0f4dfeda1f34fc1ca2bfa0a5b3c70be5f9a Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 24 Feb 2023 05:54:06 +0100 Subject: [PATCH 071/104] Fix build order structure --- .../com/lambda/client/activity/Activity.kt | 6 +- .../activities/highlevel/BuildStructure.kt | 2 - .../activities/highlevel/WorldEater.kt | 35 +++++ .../activities/interaction/BreakBlock.kt | 76 ++++++----- .../activities/interaction/PlaceBlock.kt | 127 ++++++++++-------- .../activities/types/BuildActivity.kt | 4 +- .../manager/managers/ActivityManager.kt | 14 +- .../modules/misc/TestActivityManager.kt | 18 ++- 8 files changed, 178 insertions(+), 104 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index adada7b75..5140955cb 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -57,7 +57,7 @@ abstract class Activity(val isRoot: Boolean = false) { secondaryColor: ColorHolder ) {} - open fun SafeClientEvent.getCurrentActivity(): Activity { + open fun getCurrentActivity(): Activity { subActivities.firstOrNull()?.let { with(it) { return getCurrentActivity() @@ -286,10 +286,8 @@ abstract class Activity(val isRoot: Boolean = false) { addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") -// subActivities.filter { !(it is BuildBlock && it.activityStatus == ActivityStatus.UNINITIALIZED) }.forEach { - val sortedList = subActivities.toTypedArray().sortedWith(subActivities.comparator()) - sortedList.forEach { + subActivities.forEach { repeat(depth) { textComponent.add(" ") } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 2a251f300..81e62e6cc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -5,10 +5,8 @@ import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RepeatingActivity -import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.Wrapper import com.lambda.client.util.math.Direction diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt new file mode 100644 index 000000000..343d987dc --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt @@ -0,0 +1,35 @@ +package com.lambda.client.activity.activities.highlevel + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.block.state.IBlockState +import net.minecraft.init.Blocks +import net.minecraft.util.math.BlockPos + +class WorldEater( + private val pos1: BlockPos, + private val pos2: BlockPos +) : Activity() { + override fun SafeClientEvent.onInitialize() { + val minX = minOf(pos1.x, pos2.x) + val minY = minOf(pos1.y, pos2.y) + val minZ = minOf(pos1.z, pos2.z) + val maxX = maxOf(pos1.x, pos2.x) + val maxY = maxOf(pos1.y, pos2.y) + val maxZ = maxOf(pos1.z, pos2.z) + + (minY..maxY).reversed().forEach { y -> + val structure = mutableMapOf() + + (minX..maxX).forEach { x -> + (minZ..maxZ).forEach { z -> + structure[BlockPos(x, y, z)] = Blocks.AIR.defaultState + } + } + + addSubActivities( + BuildStructure(structure) + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index d89da5229..2431d6766 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -31,6 +31,7 @@ import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil +import kotlin.properties.Delegates class BreakBlock( private val blockPos: BlockPos, @@ -41,19 +42,32 @@ class BreakBlock( override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), override var rotation: Vec2f? = null, - override var context: BuildActivity.BuildContext = BuildActivity.BuildContext.NONE, - override var action: BuildActivity.BuildAction = BuildActivity.BuildAction.UNINIT, override var hitVec: Vec3d = Vec3d.ZERO ) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 private var initState = Blocks.AIR.defaultState private var drop: Item = Items.AIR + + override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, _, new -> + renderContext.color = new.color + if (owner.subActivities.remove(this)) owner.subActivities.add(this) + } + + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, _, new -> + renderAction.color = new.color + if (owner.subActivities.remove(this)) owner.subActivities.add(this) + } + override var earliestFinish: Long get() = BuildTools.breakDelay.toLong() set(_) {} - private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( + private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, context.color + ).also { toRender.add(it) } + + private val renderAction = RenderAABBActivity.Companion.RenderBlockPos( blockPos, action.color ).also { toRender.add(it) } @@ -65,26 +79,10 @@ class BreakBlock( updateState() -// if (status != Status.RUNNING -// || context == BuildActivity.BuildContext.PENDING -// || subActivities.isNotEmpty() -// ) return@safeListener + if (action != BuildActivity.BuildAction.BREAKING) return@safeListener - when (action) { - BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { - side?.let { side -> - checkBreak(side) - } - } - BuildActivity.BuildAction.WRONG_POS_BREAK -> { - if (autoPathing) { - addSubActivities(BreakGoal(blockPos)) - } - } - else -> { - // ToDo: break nearby blocks -// failedWith(NoExposedSideFound()) - } + side?.let { side -> + checkBreak(side) } } @@ -101,8 +99,19 @@ class BreakBlock( override fun SafeClientEvent.onInitialize() { updateState() - side?.let { - checkBreak(it) + when (action) { + BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { + side?.let { side -> + checkBreak(side) + } + } + BuildActivity.BuildAction.WRONG_POS_BREAK -> { + if (autoPathing) addSubActivities(BreakGoal(blockPos)) + } + else -> { + // ToDo: break nearby blocks +// failedWith(NoExposedSideFound()) + } } } @@ -117,7 +126,7 @@ class BreakBlock( return } - renderActivity.color = ColorHolder(252, 3, 207) + renderAction.color = ColorHolder(252, 3, 207) if (drop.block == Blocks.AIR) return @@ -128,7 +137,9 @@ class BreakBlock( private fun SafeClientEvent.updateState() { getMiningSide(blockPos, BuildTools.maxReach)?.let { - action = BuildActivity.BuildAction.BREAK + if (action != BuildActivity.BuildAction.BREAKING) { + action = BuildActivity.BuildAction.BREAK + } hitVec = getHitVec(blockPos, it) side = it rotation = getRotationTo(getHitVec(blockPos, it)) @@ -144,8 +155,6 @@ class BreakBlock( side = null rotation = null } - - renderActivity.color = action.color } private fun SafeClientEvent.checkBreak(side: EnumFacing) { @@ -190,14 +199,15 @@ class BreakBlock( private fun SafeClientEvent.doBreak(side: EnumFacing) { val isCreative = player.capabilities.isCreativeMode - val successDamage = if (player.capabilities.isCreativeMode) { + val successDamage = if (ticksNeeded == 1 || isCreative) { + context = BuildActivity.BuildContext.PENDING connection.sendPacket(CPacketPlayerDigging( CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side )) playerController.onPlayerDestroyBlock(blockPos) } else { action = BuildActivity.BuildAction.BREAKING - renderActivity.color = action.color + renderAction.color = action.color playerController.onPlayerDamageBlock(blockPos, side) } @@ -207,10 +217,6 @@ class BreakBlock( // } player.swingArm(EnumHand.MAIN_HAND) - - if (ticksNeeded == 1 || isCreative) { - context = BuildActivity.BuildContext.PENDING - } } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { @@ -221,6 +227,8 @@ class BreakBlock( } is AcquireItemInActiveHand, is PlaceBlock -> { status = Status.UNINITIALIZED + context = BuildActivity.BuildContext.NONE + updateState() } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index df6a4a351..c993e5812 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -4,15 +4,14 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* -import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.client.BuildTools.directionForce import com.lambda.client.module.modules.client.BuildTools.placeStrictness -import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -21,11 +20,12 @@ import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.PlaceInfo import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.isReplaceable import net.minecraft.block.* import net.minecraft.block.state.IBlockState import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumActionResult import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand @@ -33,6 +33,7 @@ import net.minecraft.util.IStringSerializable import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent +import kotlin.properties.Delegates class PlaceBlock( private val blockPos: BlockPos, @@ -44,16 +45,32 @@ class PlaceBlock( override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), - override var context: BuildActivity.BuildContext = BuildActivity.BuildContext.NONE, - override var action: BuildActivity.BuildAction = BuildActivity.BuildAction.UNINIT, override var hitVec: Vec3d = Vec3d.ZERO -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, Activity() { +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var placeInfo: PlaceInfo? = null + private var breakFirst = false private var spoofedDirection = false - private val renderActivity = RenderAABBActivity.Companion.RenderBlockPos( - blockPos, - action.color + override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, _, new -> + renderContext.color = new.color + if (owner.subActivities.remove(this)) owner.subActivities.add(this) + } + + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, _, new -> + renderAction.color = new.color + if (owner.subActivities.remove(this)) owner.subActivities.add(this) + } + + override var earliestFinish: Long + get() = BuildTools.placeDelay.toLong() + set(_) {} + + private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, context.color + ).also { toRender.add(it) } + + private val renderAction = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, action.color ).also { toRender.add(it) } private enum class PlacementOffset(val offset: Vec3d) { @@ -72,31 +89,30 @@ class PlaceBlock( ) init { - runSafe { updateState() } + runSafe { + if (!world.worldBorder.contains(blockPos) || world.isOutsideBuildHeight(blockPos)) { + // ToDo: add support for placing blocks outside of world border + failedWith(BlockOutsideOfBoundsException(blockPos)) + } + updateState() + } safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener updateState() + } - if (status != Status.RUNNING - || context == BuildActivity.BuildContext.PENDING - || subActivities.isNotEmpty() - ) return@safeListener + safeListener { + if (it.packet !is SPacketBlockChange || it.packet.blockPosition != blockPos) return@safeListener - when (action) { - BuildActivity.BuildAction.PLACE -> { - placeInfo?.let { placeInfo -> - checkPlace(placeInfo) - } - } - BuildActivity.BuildAction.WRONG_POS_PLACE -> { - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) - } - else -> { - // ToDo: place neighbours - failedWith(NoNeighbourException(blockPos)) - } + if (it.packet.blockState == targetState + || (ignoreProperties && it.packet.blockState.block == targetState.block) + ) { + ActivityManagerHud.totalBlocksPlaced++ + success() + } else { + failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) } } } @@ -104,37 +120,33 @@ class PlaceBlock( override fun SafeClientEvent.onInitialize() { updateState() - placeInfo?.let { - checkPlace(it) + when (action) { + BuildActivity.BuildAction.PLACE -> { + placeInfo?.let { placeInfo -> + checkPlace(placeInfo) + } + } + BuildActivity.BuildAction.WRONG_POS_PLACE -> { + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) + } + else -> { + // ToDo: place neighbours +// failedWith(NoNeighbourException(blockPos)) + } } } private fun SafeClientEvent.updateState() { - val blockState = world.getBlockState(blockPos) - if (blockState == targetState || (ignoreProperties && blockState.block == targetState.block)) { - ActivityManagerHud.totalBlocksPlaced++ - success() - return - } - val allowedSides = EnumFacing.VALUES.toMutableList() var placementOffset = PlacementOffset.CENTER // var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() - /* check if block is placeable */ - if (!world.isPlaceable(blockPos, targetState.getSelectedBoundingBox(world, blockPos))) { - if (world.worldBorder.contains(blockPos) - && !world.isOutsideBuildHeight(blockPos)) { - if (subActivities.isNotEmpty()) return - - renderActivity.color = ColorHolder(0, 0, 0, 0) - val breakBlock = BreakBlock(blockPos) - addSubActivities(breakBlock) - LambdaEventBus.subscribe(breakBlock) - } else { - failedWith(BlockOutsideOfWorldException(blockPos)) - } + if (!world.getBlockState(blockPos).isReplaceable && !breakFirst) { + breakFirst = true + val breakBlock = BreakBlock(blockPos) + addSubActivities(breakBlock) + LambdaEventBus.subscribe(breakBlock) return } @@ -194,8 +206,8 @@ class PlaceBlock( range = BuildTools.maxReach, sides = allowedSides.toTypedArray() )?.let { - placeInfo = it action = BuildActivity.BuildAction.PLACE + placeInfo = it hitVec = it.hitVec.add(placementOffset.offset) } ?: run { getNeighbour( @@ -214,8 +226,6 @@ class PlaceBlock( placeInfo = null rotation = null } - - renderActivity.color = action.color } private fun SafeClientEvent.checkPlace(placeInfo: PlaceInfo) { @@ -240,6 +250,13 @@ class PlaceBlock( return } + /* check if no entity collides */ + if (!world.checkNoEntityCollision(targetState.getSelectedBoundingBox(world, blockPos), player)) { + // ToDo: this only handles the case where the player is inside the block + addSubActivities(PlaceGoal(blockPos)) + return + } + targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> if (ignoreProperties || ignoreFacing) return@let @@ -287,8 +304,6 @@ class PlaceBlock( private fun SafeClientEvent.doPlace(placeInfo: PlaceInfo) { val isBlacklisted = world.getBlockState(placeInfo.pos).block in blockBlacklist - renderActivity.color = ColorHolder(11, 66, 89) - if (isBlacklisted) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } @@ -308,8 +323,6 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - if (BuildTools.placeDelay != 0) addSubActivities(Wait(BuildTools.placeDelay * 50L)) - context = BuildActivity.BuildContext.PENDING } @@ -330,5 +343,5 @@ class PlaceBlock( class BlockNotPlaceableException(targetState: IBlockState) : Exception("Block $targetState is not placeable") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") class UnexpectedBlockStateException(blockPos: BlockPos, expected: IBlockState, actual: IBlockState) : Exception("Unexpected block state at (${blockPos.asString()}) expected $expected but got $actual") - class BlockOutsideOfWorldException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") + class BlockOutsideOfBoundsException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt index cae3f9b07..6dba94f0f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -11,8 +11,8 @@ interface BuildActivity { enum class BuildContext(val color: ColorHolder) { RESTOCK(ColorHolder()), LIQUID(ColorHolder()), - NONE(ColorHolder()), - PENDING(ColorHolder()) + NONE(ColorHolder(0, 0, 0, 0)), + PENDING(ColorHolder(11, 11, 175)) } enum class BuildAction(val color: ColorHolder) { diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 1e888e939..742d7b841 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -4,6 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.activities.types.TimedActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent @@ -33,15 +34,26 @@ object ActivityManager : Manager, Activity(true) { } } + var lastActivity: Activity? = null + repeat(executionCountPerTick) { - with(getCurrentActivity()) { + val current = getCurrentActivity() + + with(current) { BaritoneUtils.settings?.allowPlace?.value = false BaritoneUtils.settings?.allowBreak?.value = false BaritoneUtils.settings?.allowInventory?.value = false + // ToDo: Find a working way to guarantee specific age of activity + (lastActivity as? TimedActivity)?.let { + if (age < it.earliestFinish) return@repeat + } + updateActivity() checkRender() } + + lastActivity = current } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index d61e13b05..2456671cd 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -3,10 +3,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly -import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests -import com.lambda.client.activity.activities.highlevel.BuildStructure -import com.lambda.client.activity.activities.highlevel.ReachXPLevel -import com.lambda.client.activity.activities.highlevel.SurroundWithObsidian +import com.lambda.client.activity.activities.highlevel.* import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.interaction.Rotate @@ -120,6 +117,19 @@ object TestActivityManager : Module( false }) + private val ectiectctiectiei by setting("World Eater", false, consumer = { _, _-> + runSafe { + val currentDirection = player.horizontalFacing + val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) + val pos2 = player.flooredPosition.add(currentDirection.directionVec.multiply(10)).down(3) + + ActivityManager.addSubActivities( + WorldEater(pos1, pos2) + ) + } + false + }) + private val eticiettie by setting("Direction shenanigans", false, consumer = { _, _-> runSafe { var currentDirection = player.horizontalFacing From c3f9e9499bd40dd7936253c16c97786b51cd2749 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 26 Feb 2023 05:26:32 +0100 Subject: [PATCH 072/104] Revert to ConcurrentLinkedDeque and fancy break particles --- .../com/lambda/client/activity/Activity.kt | 18 ++-- .../activities/highlevel/BuildStructure.kt | 17 ++-- .../activities/interaction/BreakBlock.kt | 82 ++++++++++--------- .../activities/interaction/OpenContainer.kt | 10 +++ .../activities/interaction/PlaceBlock.kt | 41 ++++++---- .../inventory/AcquireItemInActiveHand.kt | 2 +- .../storage/ExtractItemFromShulkerBox.kt | 7 +- .../storage/PullItemsFromContainer.kt | 32 ++++++-- .../activities/types/BuildActivity.kt | 2 +- .../modules/misc/TestActivityManager.kt | 12 +++ .../com/lambda/client/util/world/PlaceInfo.kt | 2 +- 11 files changed, 147 insertions(+), 78 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 5140955cb..5e7815830 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity +import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.DelayedActivity @@ -27,10 +28,11 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils +import java.util.concurrent.ConcurrentLinkedDeque import java.util.concurrent.PriorityBlockingQueue abstract class Activity(val isRoot: Boolean = false) { - open val subActivities = PriorityBlockingQueue(15, compareBy { it.status }) + val subActivities = ConcurrentLinkedDeque() var status = Status.UNINITIALIZED private var creationTime = 0L var owner: Activity = ActivityManager @@ -205,9 +207,9 @@ abstract class Activity(val isRoot: Boolean = false) { return } - activities.forEach { - it.owner = this - it.depth = depth + 1 + activities.forEach { activity -> + activity.owner = this + activity.depth = depth + 1 } subActivities.addAll(activities) @@ -287,7 +289,13 @@ abstract class Activity(val isRoot: Boolean = false) { addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") - subActivities.forEach { + val acti = if (this is BuildStructure) { + subActivities.sortedWith(buildComparator()) + } else { + subActivities + } + + acti.forEach { repeat(depth) { textComponent.add(" ") } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 81e62e6cc..9bf3bffc5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -8,13 +8,11 @@ import com.lambda.client.activity.activities.types.RepeatingActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.Wrapper import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos -import java.util.concurrent.PriorityBlockingQueue class BuildStructure( private val structure: Map, @@ -25,7 +23,6 @@ class BuildStructure( override var repeated: Int = 0, ) : RepeatingActivity, Activity() { private var currentOffset = BlockPos.ORIGIN - override val subActivities = PriorityBlockingQueue(100, buildComparator()) override fun SafeClientEvent.onInitialize() { val activities = mutableListOf() @@ -63,7 +60,15 @@ class BuildStructure( currentOffset = currentOffset.add(offsetMove) } - private fun buildComparator() = compareBy { + override fun getCurrentActivity(): Activity { + subActivities.sortedWith(buildComparator()).firstOrNull()?.let { + with(it) { + return getCurrentActivity() + } + } ?: return this + } + + fun buildComparator() = compareBy { val current = deepestBuildActivity(it) if (current is BuildActivity) { @@ -79,8 +84,8 @@ class BuildStructure( val current = deepestBuildActivity(it) if (current is BuildActivity) { - Wrapper.player?.getPositionEyes(1f)?.distanceTo(current.hitVec) ?: 0.0 - } else 0.0 + current.distance + } else 1337.0 } /* BreakBlocks that are boxed in a PlaceBlock are considered in the sequence */ diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 2431d6766..f8b8fb06a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -11,9 +11,10 @@ import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.block +import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec @@ -27,7 +28,6 @@ import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil @@ -42,21 +42,20 @@ class BreakBlock( override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), override var rotation: Vec2f? = null, - override var hitVec: Vec3d = Vec3d.ZERO + override var distance: Double = 1337.0, ) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 - private var initState = Blocks.AIR.defaultState private var drop: Item = Items.AIR - override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, _, new -> + override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> + if (old == new) return@observable renderContext.color = new.color - if (owner.subActivities.remove(this)) owner.subActivities.add(this) } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, _, new -> + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, old, new -> + if (old == new) return@observable renderAction.color = new.color - if (owner.subActivities.remove(this)) owner.subActivities.add(this) } override var earliestFinish: Long @@ -72,14 +71,35 @@ class BreakBlock( ).also { toRender.add(it) } init { - runSafe { updateState() } + runSafe { + if (!world.worldBorder.contains(blockPos) || world.isOutsideBuildHeight(blockPos)) { + // ToDo: add support for placing blocks outside of world border + failedWith(BlockOutsideOfBoundsException(blockPos)) + return@runSafe + } + + val currentState = world.getBlockState(blockPos) + + // ToDo: doesn't work for some reason + if (currentState.block in BuildTools.ignoredBlocks) { + success() + return@runSafe + } + + drop = currentState.block.getItemDropped(currentState, Random(), 0) + + updateState() + } safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener updateState() - if (action != BuildActivity.BuildAction.BREAKING) return@safeListener + if (action != BuildActivity.BuildAction.BREAKING + || subActivities.isNotEmpty() + || status == Status.UNINITIALIZED + ) return@safeListener side?.let { side -> checkBreak(side) @@ -120,7 +140,7 @@ class BreakBlock( } private fun SafeClientEvent.finish() { - if (!collectDrops || !autoPathing) { + if (!collectDrops || !autoPathing || drop == Items.AIR) { ActivityManagerHud.totalBlocksBroken++ success() return @@ -128,8 +148,6 @@ class BreakBlock( renderAction.color = ColorHolder(252, 3, 207) - if (drop.block == Blocks.AIR) return - addSubActivities( PickUpDrops(drop, minAmount = minCollectAmount) ) @@ -140,16 +158,16 @@ class BreakBlock( if (action != BuildActivity.BuildAction.BREAKING) { action = BuildActivity.BuildAction.BREAK } - hitVec = getHitVec(blockPos, it) + distance = player.distanceTo(getHitVec(blockPos, it)) side = it rotation = getRotationTo(getHitVec(blockPos, it)) } ?: run { getMiningSide(blockPos)?.let { action = BuildActivity.BuildAction.WRONG_POS_BREAK - hitVec = getHitVec(blockPos, it) + distance = player.distanceTo(getHitVec(blockPos, it)) } ?: run { action = BuildActivity.BuildAction.INVALID_BREAK - hitVec = Vec3d.ZERO + distance = 1337.0 } playerController.resetBlockRemoving() side = null @@ -160,7 +178,6 @@ class BreakBlock( private fun SafeClientEvent.checkBreak(side: EnumFacing) { val currentState = world.getBlockState(blockPos) - initState = currentState drop = currentState.block.getItemDropped(currentState, Random(), 0) if (!player.capabilities.isCreativeMode @@ -193,30 +210,16 @@ class BreakBlock( if (needToHandleLiquid) return - doBreak(side) - } + if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { + if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { + context = BuildActivity.BuildContext.PENDING + } else { + action = BuildActivity.BuildAction.BREAKING + } - private fun SafeClientEvent.doBreak(side: EnumFacing) { - val isCreative = player.capabilities.isCreativeMode - - val successDamage = if (ticksNeeded == 1 || isCreative) { - context = BuildActivity.BuildContext.PENDING - connection.sendPacket(CPacketPlayerDigging( - CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockPos, side - )) - playerController.onPlayerDestroyBlock(blockPos) - } else { - action = BuildActivity.BuildAction.BREAKING - renderAction.color = action.color - playerController.onPlayerDamageBlock(blockPos, side) + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) } - -// if (!successDamage) { -// failedWith(BlockBreakingException()) -// return -// } - - player.swingArm(EnumHand.MAIN_HAND) } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { @@ -240,4 +243,5 @@ class BreakBlock( class NoExposedSideFound : Exception("No exposed side found") class BlockBreakingException : Exception("Block breaking failed") + class BlockOutsideOfBoundsException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 8be88029c..59900b3bf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -11,6 +11,7 @@ import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset +import net.minecraft.block.BlockContainer import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand @@ -25,6 +26,13 @@ class OpenContainer( override var usedAttempts: Int = 0, ) : RotatingActivity, TimeoutActivity, AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { + val currentState = world.getBlockState(containerPos) + + if (currentState.block !is BlockContainer) { + failedWith(BlockNotContainerException(currentState)) + return + } + val diff = player.getPositionEyes(1f).subtract(containerPos.toVec3dCenter()) val normalizedVec = diff.normalize() @@ -62,4 +70,6 @@ class OpenContainer( } } } + + class BlockNotContainerException(blockState: Any) : Exception("Block $blockState is not a container") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index c993e5812..668eb057f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* @@ -16,6 +17,7 @@ import com.lambda.client.util.items.blockBlacklist import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.PlaceInfo @@ -41,24 +43,23 @@ class PlaceBlock( private val ignoreProperties: Boolean = false, private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, + override var distance: Double = 1337.0, override val timeout: Long = 200L, override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, - override val toRender: MutableSet = mutableSetOf(), - override var hitVec: Vec3d = Vec3d.ZERO + override val toRender: MutableSet = mutableSetOf() ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var placeInfo: PlaceInfo? = null - private var breakFirst = false private var spoofedDirection = false - override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, _, new -> + override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> + if (old == new) return@observable renderContext.color = new.color - if (owner.subActivities.remove(this)) owner.subActivities.add(this) } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, _, new -> + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, old, new -> + if (old == new) return@observable renderAction.color = new.color - if (owner.subActivities.remove(this)) owner.subActivities.add(this) } override var earliestFinish: Long @@ -94,6 +95,7 @@ class PlaceBlock( // ToDo: add support for placing blocks outside of world border failedWith(BlockOutsideOfBoundsException(blockPos)) } + updateState() } @@ -142,8 +144,11 @@ class PlaceBlock( // var allowedRotations = targetState.block.getValidRotations(world, blockPos)?.toMutableSet() - if (!world.getBlockState(blockPos).isReplaceable && !breakFirst) { - breakFirst = true + val currentState = world.getBlockState(blockPos) + + if (!currentState.isReplaceable && currentState != targetState + && subActivities.filterIsInstance().isEmpty() + ) { val breakBlock = BreakBlock(blockPos) addSubActivities(breakBlock) LambdaEventBus.subscribe(breakBlock) @@ -207,8 +212,9 @@ class PlaceBlock( sides = allowedSides.toTypedArray() )?.let { action = BuildActivity.BuildAction.PLACE + it.hitVec = it.hitVec.add(placementOffset.offset) + distance = player.distanceTo(it.hitVec) placeInfo = it - hitVec = it.hitVec.add(placementOffset.offset) } ?: run { getNeighbour( blockPos, @@ -218,10 +224,10 @@ class PlaceBlock( sides = allowedSides.toTypedArray() )?.let { action = BuildActivity.BuildAction.WRONG_POS_PLACE - hitVec = it.hitVec.add(placementOffset.offset) + distance = player.distanceTo(it.hitVec.add(placementOffset.offset)) } ?: run { action = BuildActivity.BuildAction.INVALID_PLACE - hitVec = Vec3d.ZERO + distance = 1337.0 } placeInfo = null rotation = null @@ -308,9 +314,16 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) } - rotation = getRotationTo(hitVec) + rotation = getRotationTo(placeInfo.hitVec) - val result = playerController.processRightClickBlock(player, world, placeInfo.pos, placeInfo.side, hitVec, EnumHand.MAIN_HAND) + val result = playerController.processRightClickBlock( + player, + world, + placeInfo.pos, + placeInfo.side, + placeInfo.hitVec, + EnumHand.MAIN_HAND + ) if (result != EnumActionResult.SUCCESS) { failedWith(ProcessRightClickException(result)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index cc8673a7a..c9f65b98a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -44,7 +44,7 @@ class AcquireItemInActiveHand( addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) } ?: run { if (useShulkerBoxes) { - addSubActivities(ExtractItemFromShulkerBox(item, 1, predicateItem, predicateSlot)) + addSubActivities(ExtractItemFromShulkerBox(item, metadata, 1, predicateItem, predicateSlot)) } else { failedWith(NoItemFoundException(item, metadata)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 5d53c75be..2d82659ae 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -16,19 +16,18 @@ import net.minecraft.item.ItemStack class ExtractItemFromShulkerBox( private val item: Item, + private var metadata: Int? = null, private val amount: Int = 0, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { -// if (player.inventorySlots.item) - val candidates = mutableMapOf() // ToDo: move to acquire item in active hand player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> - val count = inventory.count { it.item == item && predicateItem(it) } + val count = inventory.count { it.item == item && predicateItem(it) && (metadata == null || metadata == it.metadata) } if (count > 0) candidates[slot] = count } @@ -52,7 +51,7 @@ class ExtractItemFromShulkerBox( addSubActivities( OpenContainer(childActivity.containerPos), - PullItemsFromContainer(item, amount, predicateItem), + PullItemsFromContainer(item, metadata, amount, predicateItem), CloseContainer(), BreakBlock(childActivity.containerPos, collectDrops = true), AcquireItemInActiveHand(item, predicateItem, predicateSlot) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 32526b568..0dff97dfd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -7,20 +7,39 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots +import net.minecraft.inventory.Container +import net.minecraft.inventory.ContainerChest +import net.minecraft.inventory.ContainerShulkerBox +import net.minecraft.inventory.Slot +import net.minecraft.inventory.SlotShulkerBox import net.minecraft.item.Item import net.minecraft.item.ItemStack class PullItemsFromContainer( // ToDo: fix take for full inv private val item: Item, + private val metadata: Int? = null, private val amount: Int, // 0 = all private val predicateItem: (ItemStack) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { - val toMoveSlots = player - .openContainer - .inventorySlots - .filter { slot -> - slot.stack.item == item && predicateItem(slot.stack) + val containerInventory: List + val playerInventory: List + + when (val container = player.openContainer) { + is ContainerShulkerBox -> { + containerInventory = container.getSlots(0..26) + playerInventory = container.getSlots(27..62) + } + else -> { + failedWith(ContainerNotKnownException(container)) + return + } + } + + val toMoveSlots = containerInventory.filter { slot -> + slot.stack.item == item + && predicateItem(slot.stack) + && (metadata == null || metadata == slot.stack.metadata) } if (toMoveSlots.isEmpty()) { @@ -30,8 +49,6 @@ class PullItemsFromContainer( // ToDo: fix take for full inv val remainingSlots = if (amount == 0) toMoveSlots else toMoveSlots.take(amount) - val playerInventory = player.openContainer.getSlots(27..62) - remainingSlots.forEach { fromSlot -> if (playerInventory.countEmpty() > 0) { addSubActivities(QuickMoveSlot(fromSlot)) @@ -54,4 +71,5 @@ class PullItemsFromContainer( // ToDo: fix take for full inv } class NoSpaceLeftInInventoryException : Exception("No space left in inventory") + class ContainerNotKnownException(val container: Container) : Exception("Container ${container::class.simpleName} not known") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt index 6dba94f0f..8e1696fac 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -6,7 +6,7 @@ import net.minecraft.util.math.Vec3d interface BuildActivity { var context: BuildContext var action: BuildAction - var hitVec: Vec3d + var distance: Double enum class BuildContext(val color: ColorHolder) { RESTOCK(ColorHolder()), diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 2456671cd..4de5ed4b9 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -14,6 +14,7 @@ import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.activity.activities.utils.Wait import com.lambda.client.commons.extension.next import com.lambda.client.manager.managers.ActivityManager @@ -213,4 +214,15 @@ object TestActivityManager : Module( ActivityManager.reset() false }) + + init { + onToggle { + runSafe { + with(ActivityManager.getCurrentActivity()) { + updateActivity() + checkRender() + } + } + } + } } diff --git a/src/main/kotlin/com/lambda/client/util/world/PlaceInfo.kt b/src/main/kotlin/com/lambda/client/util/world/PlaceInfo.kt index 410543712..d57ae9212 100644 --- a/src/main/kotlin/com/lambda/client/util/world/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/client/util/world/PlaceInfo.kt @@ -9,6 +9,6 @@ class PlaceInfo( val side: EnumFacing, val dist: Double, val hitVecOffset: Vec3d, - val hitVec: Vec3d, + var hitVec: Vec3d, val placedPos: BlockPos ) \ No newline at end of file From 8123508afc0b6f6f090aa28a06b7dd5a7de6d393 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 26 Feb 2023 07:51:55 +0100 Subject: [PATCH 073/104] Best tool for mining --- .../com/lambda/client/activity/Activity.kt | 6 +- .../highlevel/{WorldEater.kt => BreakArea.kt} | 25 +++++--- .../activities/interaction/BreakBlock.kt | 46 +++++++++++---- .../activities/interaction/PlaceBlock.kt | 5 +- .../activities/types/BuildActivity.kt | 3 +- .../modules/misc/TestActivityManager.kt | 38 +----------- .../client/module/modules/misc/WorldEater.kt | 59 +++++++++++++++++++ 7 files changed, 121 insertions(+), 61 deletions(-) rename src/main/kotlin/com/lambda/client/activity/activities/highlevel/{WorldEater.kt => BreakArea.kt} (53%) create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 5e7815830..3c23a0903 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -115,8 +115,10 @@ abstract class Activity(val isRoot: Boolean = false) { LambdaEventBus.subscribe(activity) -// with(owner) { -// onChildInitialize(activity) +// if (!owner.isRoot) { +// with(owner) { +// onChildInitialize(activity) +// } // } checkRotating(activity) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt similarity index 53% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt rename to src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt index 343d987dc..5a6b6ba97 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt @@ -1,15 +1,22 @@ package com.lambda.client.activity.activities.highlevel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.color.ColorHolder import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.BlockPos -class WorldEater( +class BreakArea( private val pos1: BlockPos, - private val pos2: BlockPos -) : Activity() { + private val pos2: BlockPos, + private val layerSize: Int = 1, + override val toRender: MutableSet = mutableSetOf( + RenderAABBActivity.Companion.RenderBlockPos(pos1, ColorHolder(255, 0, 255)), + RenderAABBActivity.Companion.RenderBlockPos(pos2, ColorHolder(0, 255, 0)) + ) +) : RenderAABBActivity, Activity() { override fun SafeClientEvent.onInitialize() { val minX = minOf(pos1.x, pos2.x) val minY = minOf(pos1.y, pos2.y) @@ -18,7 +25,9 @@ class WorldEater( val maxY = maxOf(pos1.y, pos2.y) val maxZ = maxOf(pos1.z, pos2.z) - (minY..maxY).reversed().forEach { y -> + val layers = (minY..maxY).reversed() + + layers.forEach { y -> val structure = mutableMapOf() (minX..maxX).forEach { x -> @@ -27,9 +36,11 @@ class WorldEater( } } - addSubActivities( - BuildStructure(structure) - ) + if (y.mod(layerSize) == 0 || y == layers.last) { + addSubActivities( + BuildStructure(structure) + ) + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index f8b8fb06a..0c7ebb470 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -2,6 +2,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.* @@ -11,6 +12,7 @@ import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.allSlots import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f @@ -22,12 +24,13 @@ import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid import net.minecraft.init.Blocks import net.minecraft.init.Items +import net.minecraft.inventory.Slot import net.minecraft.item.Item -import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraftforge.common.ForgeHooks import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil @@ -37,7 +40,7 @@ class BreakBlock( private val blockPos: BlockPos, private val collectDrops: Boolean = false, private val minCollectAmount: Int = 1, - override var timeout: Long = 200L, + override var timeout: Long = 200L, // ToDo: Reset timeouted breaks override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), @@ -53,7 +56,7 @@ class BreakBlock( renderContext.color = new.color } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, old, new -> + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.NONE) { _, old, new -> if (old == new) return@observable renderAction.color = new.color } @@ -86,7 +89,7 @@ class BreakBlock( return@runSafe } - drop = currentState.block.getItemDropped(currentState, Random(), 0) + drop = currentState.block.getItemDropped(currentState, Random(), 0) ?: Items.AIR updateState() } @@ -178,18 +181,40 @@ class BreakBlock( private fun SafeClientEvent.checkBreak(side: EnumFacing) { val currentState = world.getBlockState(blockPos) - drop = currentState.block.getItemDropped(currentState, Random(), 0) + drop = currentState.block.getItemDropped(currentState, Random(), 0) ?: Items.AIR if (!player.capabilities.isCreativeMode -// && currentState.block.isToolEffective("pickaxe", currentState) - && player.getHeldItem(EnumHand.MAIN_HAND).item != Items.DIAMOND_PICKAXE - ) { // ToDo: get optimal tool - context = BuildActivity.BuildContext.RESTOCK + && !ForgeHooks.isToolEffective(world, blockPos, player.heldItemMainhand) + && currentState.block.getHarvestTool(currentState) != null + ) { + val topTools = player + .allSlots + .filter { + ForgeHooks.isToolEffective(world, blockPos, it.stack) + } + + topTools.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { + addSubActivities(SwapOrSwitchToSlot(it)) + } ?: run { + currentState.block.getHarvestTool(currentState)?.let { harvestTool -> + context = BuildActivity.BuildContext.RESTOCK + + // ToDo: add support for lower tools + val item = when (harvestTool) { + "pickaxe" -> Items.DIAMOND_PICKAXE + "axe" -> Items.DIAMOND_AXE + else -> Items.DIAMOND_SHOVEL + } - addSubActivities(AcquireItemInActiveHand(Items.DIAMOND_PICKAXE)) + addSubActivities(AcquireItemInActiveHand(item)) + } + } return } + // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) + // ToDo: 2. ForgeHooks.canHarvestBlock(currentState.block, player, world, blockPos) + ticksNeeded = ceil((1 / currentState .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() timeout = ticksNeeded * 50L + 2000L @@ -231,6 +256,7 @@ class BreakBlock( is AcquireItemInActiveHand, is PlaceBlock -> { status = Status.UNINITIALIZED context = BuildActivity.BuildContext.NONE + action = BuildActivity.BuildAction.NONE updateState() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 668eb057f..ee3b831a0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* @@ -44,7 +43,7 @@ class PlaceBlock( private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, override var distance: Double = 1337.0, - override val timeout: Long = 200L, + override val timeout: Long = 200L, // ToDo: Reset timeouted placements override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -57,7 +56,7 @@ class PlaceBlock( renderContext.color = new.color } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.UNINIT) { _, old, new -> + override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.NONE) { _, old, new -> if (old == new) return@observable renderAction.color = new.color } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt index 8e1696fac..58e3166b7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.types import com.lambda.client.util.color.ColorHolder -import net.minecraft.util.math.Vec3d interface BuildActivity { var context: BuildContext @@ -23,6 +22,6 @@ interface BuildActivity { WRONG_POS_PLACE(ColorHolder(20, 108, 145)), INVALID_BREAK(ColorHolder(46, 0, 0)), INVALID_PLACE(ColorHolder(11, 55, 74)), - UNINIT(ColorHolder(11, 11, 11)) + NONE(ColorHolder(11, 11, 11)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 4de5ed4b9..71057b677 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,50 +1,27 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.LambdaMod -import com.lambda.client.activity.activities.example.ProbablyFailing import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.* import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.interaction.Rotate -import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity -import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.DumpInventory import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox -import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender -import com.lambda.client.activity.activities.utils.Wait -import com.lambda.client.commons.extension.next import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.MovementUtils.centerPlayer -import com.lambda.client.util.items.block -import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.items.item -import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils -import com.lambda.client.util.schematic.LambdaSchematicaHelper -import com.lambda.client.util.text.MessageSendHelper +import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal -import net.minecraft.block.BlockLog -import net.minecraft.block.BlockPistonBase -import net.minecraft.block.BlockPurpurSlab -import net.minecraft.block.BlockQuartz -import net.minecraft.block.BlockRotatedPillar -import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState -import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks -import net.minecraft.init.Enchantments -import net.minecraft.init.Items import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos @@ -118,19 +95,6 @@ object TestActivityManager : Module( false }) - private val ectiectctiectiei by setting("World Eater", false, consumer = { _, _-> - runSafe { - val currentDirection = player.horizontalFacing - val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) - val pos2 = player.flooredPosition.add(currentDirection.directionVec.multiply(10)).down(3) - - ActivityManager.addSubActivities( - WorldEater(pos1, pos2) - ) - } - false - }) - private val eticiettie by setting("Direction shenanigans", false, consumer = { _, _-> runSafe { var currentDirection = player.horizontalFacing diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt new file mode 100644 index 000000000..6e1385826 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -0,0 +1,59 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.activity.activities.highlevel.BreakArea +import com.lambda.client.activity.activities.highlevel.BuildSchematic +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.manager.managers.ActivityManager.cancel +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.schematic.LambdaSchematicaHelper +import com.lambda.client.util.schematic.LambdaSchematicaHelper.isSchematicaPresent +import com.lambda.client.util.text.MessageSendHelper +import com.lambda.client.util.threads.runSafe +import net.minecraft.util.math.BlockPos + +object WorldEater : Module( + name = "WorldEater", + description = "Easy perimeter building", + category = Category.MISC, + alias = arrayOf("we") +) { + private val size by setting("Size", 10, 1..100, 1) + private val depth by setting("Depth", 3, 1..100, 1) + private val layerSize by setting("Layers size", 1, 1..6, 1) + + private var ownedBuildStructure: BreakArea? = null + + init { + onEnable { + runSafe { + val currentDirection = player.horizontalFacing + val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) + val pos2 = player.flooredPosition.add( + currentDirection.directionVec.multiply(size) + ).add( + currentDirection.rotateY().directionVec.multiply(size) + ).down(depth) + + BreakArea(pos1, pos2, layerSize).let { + ownedBuildStructure = it + ActivityManager.addSubActivities(it) + } + } + } + + onDisable { + runSafe { + ownedBuildStructure?.let { + with(it) { + cancel() + } + } + } + } + } +} \ No newline at end of file From f209f00130b84e1587f0625e56ec54922478505b Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 26 Feb 2023 22:15:08 +0100 Subject: [PATCH 074/104] Smol fixes --- .../com/lambda/client/activity/Activity.kt | 6 ++--- .../activities/highlevel/BreakArea.kt | 3 +++ .../activities/interaction/BreakBlock.kt | 26 ++++++++----------- .../activities/interaction/PlaceBlock.kt | 13 +++++++--- .../module/modules/client/BuildTools.kt | 10 +++---- .../module/modules/misc/HighwayTools.kt | 2 +- .../client/module/modules/misc/WorldEater.kt | 3 +++ 7 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 3c23a0903..87223f016 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -165,15 +165,15 @@ abstract class Activity(val isRoot: Boolean = false) { fun SafeClientEvent.cancel() { val activity = this@Activity + LambdaEventBus.unsubscribe(activity) + ListenerManager.unregister(activity) + subActivities.forEach { with(it) { cancel() } } - LambdaEventBus.unsubscribe(activity) - ListenerManager.unregister(activity) - with(owner) { subActivities.remove(activity) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt index 5a6b6ba97..5425095d7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt @@ -6,12 +6,15 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.color.ColorHolder import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos class BreakArea( private val pos1: BlockPos, private val pos2: BlockPos, private val layerSize: Int = 1, + private val sliceSize: Int = 1, + private val sliceDirection: EnumFacing = EnumFacing.NORTH, override val toRender: MutableSet = mutableSetOf( RenderAABBActivity.Companion.RenderBlockPos(pos1, ColorHolder(255, 0, 255)), RenderAABBActivity.Companion.RenderBlockPos(pos2, ColorHolder(0, 255, 0)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 0c7ebb470..9a7a9aa78 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -9,6 +9,7 @@ import com.lambda.client.activity.activities.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud +import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder @@ -24,7 +25,6 @@ import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid import net.minecraft.init.Blocks import net.minecraft.init.Items -import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing @@ -183,20 +183,15 @@ class BreakBlock( drop = currentState.block.getItemDropped(currentState, Random(), 0) ?: Items.AIR - if (!player.capabilities.isCreativeMode - && !ForgeHooks.isToolEffective(world, blockPos, player.heldItemMainhand) - && currentState.block.getHarvestTool(currentState) != null - ) { - val topTools = player - .allSlots - .filter { + currentState.block.getHarvestTool(currentState)?.let { harvestTool -> + if (!player.capabilities.isCreativeMode + && !ForgeHooks.isToolEffective(world, blockPos, player.heldItemMainhand) + ) { + player.allSlots.filter { ForgeHooks.isToolEffective(world, blockPos, it.stack) - } - - topTools.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { - addSubActivities(SwapOrSwitchToSlot(it)) - } ?: run { - currentState.block.getHarvestTool(currentState)?.let { harvestTool -> + }.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { + addSubActivities(SwapOrSwitchToSlot(it)) + } ?: run { context = BuildActivity.BuildContext.RESTOCK // ToDo: add support for lower tools @@ -208,8 +203,8 @@ class BreakBlock( addSubActivities(AcquireItemInActiveHand(item)) } + return } - return } // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) @@ -234,6 +229,7 @@ class BreakBlock( } if (needToHandleLiquid) return + playerController.blockHitDelay = 0 if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index ee3b831a0..d3e1b1b74 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity.activities.interaction +import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal @@ -50,6 +51,7 @@ class PlaceBlock( ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var placeInfo: PlaceInfo? = null private var spoofedDirection = false + private var breakFirst = false override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> if (old == new) return@observable @@ -105,14 +107,16 @@ class PlaceBlock( } safeListener { - if (it.packet !is SPacketBlockChange || it.packet.blockPosition != blockPos) return@safeListener + if (it.packet !is SPacketBlockChange + || it.packet.blockPosition != blockPos + ) return@safeListener if (it.packet.blockState == targetState || (ignoreProperties && it.packet.blockState.block == targetState.block) ) { ActivityManagerHud.totalBlocksPlaced++ success() - } else { + } else if (!breakFirst) { failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) } } @@ -146,11 +150,12 @@ class PlaceBlock( val currentState = world.getBlockState(blockPos) if (!currentState.isReplaceable && currentState != targetState - && subActivities.filterIsInstance().isEmpty() + && !breakFirst ) { val breakBlock = BreakBlock(blockPos) addSubActivities(breakBlock) LambdaEventBus.subscribe(breakBlock) + breakFirst = true return } @@ -303,6 +308,8 @@ class PlaceBlock( // return // } + breakFirst = false + doPlace(placeInfo) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 262b16a0c..27d3748be 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -31,8 +31,8 @@ object BuildTools : Module( // }) /* mining */ - val breakDelay by setting("Break Delay", 50, 0..1000, 5, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ms") - val maxPending by setting("Max Pending", 1, 1..100, 1, { page == Page.BUILDING }, description = "Sets the maximum amount of pending break tasks") + val breakDelay by setting("Break Delay", 1, 0..20, 5, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") +// val maxPending by setting("Max Pending", 1, 1..100, 1, { page == Page.BUILDING }, description = "Sets the maximum amount of pending break tasks") val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.BUILDING }, description = "Factor to manipulate calculated mining speed") // val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") // val multiBreak by setting("Multi Break", true, { page == Page.MINING }, description = "Breaks multiple instant breaking blocks intersecting with view vector on the same tick") @@ -44,10 +44,10 @@ object BuildTools : Module( val pickBlock by setting("Pick Block Creative", true, { page == Page.BUILDING }, description = "Use pick block to place blocks when in creative mode") val placeStrictness by setting("Placement Strictness", PlacementStrictness.DIRECTION, { page == Page.BUILDING }, description = "ANY: Allow all exposed surfaces. DIRECTION: Only allow surfaces in the direction of the player. VISIBLE: Only allow surfaces that are visible to the player.") // val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") - val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") - val executionCountPerTick by setting("Executions Per Tick", 100, 0..200, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") +// val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") + val executionCountPerTick by setting("Executions Per Tick", 20, 0..100, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") - val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BUILDING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") + val placementSearch by setting("Place Deep Search", 1, 1..4, 1, { page == Page.BUILDING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") val directionForce by setting("Block Direction Exploit", true, { page == Page.BUILDING }, description = "EXPLOIT: Forces the direction of the block to be placed") /* storage management */ diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 8fa1db8ae..708b43069 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -28,7 +28,7 @@ object HighwayTools : Module( private val structure by setting("Structure", Structure.HIGHWAY, description = "Choose the structure") private val width by setting("Width", 6, 1..50, 1, description = "Sets the width of blueprint", unit = " blocks") private val height by setting("Height", 4, 2..10, 1, description = "Sets height of blueprint", unit = " blocks") - private val offset by setting("Offset", 0, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") + private val offset by setting("Offset", 3, -10..10, 1, description = "Sets the offset of the structure", unit = " blocks") private val rainbowMode by setting("Rainbow Mode", false, description = "Rainbow highway uwu") private val backfill by setting("Backfill", false, { structure == Structure.TUNNEL }, description = "Fills the tunnel behind you") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 6e1385826..eb8f1aee8 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -14,6 +14,7 @@ import com.lambda.client.util.schematic.LambdaSchematicaHelper import com.lambda.client.util.schematic.LambdaSchematicaHelper.isSchematicaPresent import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe +import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos object WorldEater : Module( @@ -25,6 +26,8 @@ object WorldEater : Module( private val size by setting("Size", 10, 1..100, 1) private val depth by setting("Depth", 3, 1..100, 1) private val layerSize by setting("Layers size", 1, 1..6, 1) + private val sliceSize by setting("Slice size", 1, 1..6, 1) + private val sliceDirection by setting("Slice direction", EnumFacing.NORTH) private var ownedBuildStructure: BreakArea? = null From 060f5447135823acc10e71a39839540e16b3b4fd Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 3 Mar 2023 07:04:02 +0100 Subject: [PATCH 075/104] Thread sanitizing and other fixes --- .../com/lambda/client/activity/Activity.kt | 12 +++---- .../activities/highlevel/BuildStructure.kt | 6 +--- .../activities/interaction/BreakBlock.kt | 12 ++++--- .../activities/interaction/OpenContainer.kt | 28 +++++----------- .../activities/interaction/PlaceBlock.kt | 33 ++++++++++++------- .../inventory/CreativeInventoryAction.kt | 11 ++++++- .../inventory/InventoryTransaction.kt | 25 +++++++++----- .../module/modules/client/BuildTools.kt | 6 ++-- 8 files changed, 75 insertions(+), 58 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 87223f016..e400fe8cd 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -28,11 +28,9 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils -import java.util.concurrent.ConcurrentLinkedDeque -import java.util.concurrent.PriorityBlockingQueue abstract class Activity(val isRoot: Boolean = false) { - val subActivities = ConcurrentLinkedDeque() + val subActivities = ArrayDeque() var status = Status.UNINITIALIZED private var creationTime = 0L var owner: Activity = ActivityManager @@ -200,7 +198,7 @@ abstract class Activity(val isRoot: Boolean = false) { return false } - fun Activity.addSubActivities(activities: List) { + fun Activity.addSubActivities(activities: List, subscribe: Boolean = false) { if (activities.isEmpty()) return if (depth > MAX_DEPTH) { @@ -212,14 +210,16 @@ abstract class Activity(val isRoot: Boolean = false) { activities.forEach { activity -> activity.owner = this activity.depth = depth + 1 + if (subscribe) LambdaEventBus.subscribe(activity) } + subActivities.addAll(activities) // LambdaMod.LOG.info("${System.currentTimeMillis()} Added ${activities.size} sub activities to $name") } - fun Activity.addSubActivities(vararg activities: Activity) { - addSubActivities(activities.toList()) + fun Activity.addSubActivities(vararg activities: Activity, subscribe: Boolean = false) { + addSubActivities(activities.toList(), subscribe) } enum class Status { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 9bf3bffc5..86f943b19 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -49,11 +49,7 @@ class BuildStructure( } } - activities.forEach { - LambdaEventBus.subscribe(it) - } - - addSubActivities(activities) + addSubActivities(activities, subscribe = true) } override fun SafeClientEvent.onSuccess() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 9a7a9aa78..199f96b51 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -18,11 +18,11 @@ import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.distanceTo -import com.lambda.client.util.threads.runSafe -import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.threads.* import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid +import kotlinx.coroutines.launch import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item @@ -115,7 +115,11 @@ class BreakBlock( || it.packet.blockState.block != Blocks.AIR ) return@safeListener - finish() + defaultScope.launch { + onMainThreadSafe { + finish() + } + } } } @@ -229,10 +233,10 @@ class BreakBlock( } if (needToHandleLiquid) return - playerController.blockHitDelay = 0 if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { + playerController.blockHitDelay = 0 context = BuildActivity.BuildContext.PENDING } else { action = BuildActivity.BuildAction.BREAKING diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt index 59900b3bf..e37059e96 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt @@ -5,18 +5,22 @@ import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.RotatingActivity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getHitVecOffset +import kotlinx.coroutines.launch import net.minecraft.block.BlockContainer import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock +import net.minecraft.network.play.server.SPacketWindowItems import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent class OpenContainer( private val containerPos: BlockPos, @@ -46,25 +50,11 @@ class OpenContainer( } init { -// safeListener { -// when (it.packet) { -// is SPacketWindowItems -> { -// success() -// LambdaMod.LOG.info(it.packet.itemStacks.size) -// it.packet.itemStacks.forEach { stack -> -// LambdaMod.LOG.info(stack.displayName) -// } -// LambdaMod.LOG.info(player.openContainer.inventorySlots.size) -// player.openContainer.inventorySlots.forEach { slot -> -// LambdaMod.LOG.info(slot.stack.displayName) -// } -// } -// } -// } + safeListener { + if (it.packet !is SPacketWindowItems) return@safeListener - safeListener { - if (it.phase == TickEvent.Phase.END) { - if (player.openContainer.inventorySlots.size == 63) { + defaultScope.launch { + onMainThreadSafe { success() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index d3e1b1b74..cc22bce29 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -18,11 +18,14 @@ import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.PlaceInfo import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isReplaceable +import kotlinx.coroutines.launch import net.minecraft.block.* import net.minecraft.block.state.IBlockState import net.minecraft.item.ItemStack @@ -111,13 +114,18 @@ class PlaceBlock( || it.packet.blockPosition != blockPos ) return@safeListener - if (it.packet.blockState == targetState - || (ignoreProperties && it.packet.blockState.block == targetState.block) - ) { - ActivityManagerHud.totalBlocksPlaced++ - success() - } else if (!breakFirst) { - failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) + defaultScope.launch { + onMainThreadSafe { + if (it.packet.blockState == targetState + || (ignoreProperties && it.packet.blockState.block == targetState.block) + ) { + ActivityManagerHud.totalBlocksPlaced++ + + success() + } else if (!breakFirst) { +// failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) + } + } } } } @@ -149,13 +157,16 @@ class PlaceBlock( val currentState = world.getBlockState(blockPos) - if (!currentState.isReplaceable && currentState != targetState + if (!currentState.isReplaceable + && currentState != targetState + && context != BuildActivity.BuildContext.PENDING && !breakFirst ) { - val breakBlock = BreakBlock(blockPos) - addSubActivities(breakBlock) - LambdaEventBus.subscribe(breakBlock) breakFirst = true + addSubActivities( + BreakBlock(blockPos), + subscribe = true + ) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt index dc073259c..a574b4bee 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt @@ -4,7 +4,10 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.safeListener +import kotlinx.coroutines.launch import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketCreativeInventoryAction import net.minecraft.network.play.server.SPacketSetSlot @@ -21,7 +24,13 @@ class CreativeInventoryAction( init { safeListener { - if (it.packet is SPacketSetSlot) success() + if (it.packet !is SPacketSetSlot) return@safeListener + + defaultScope.launch { + onMainThreadSafe { + success() + } + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt index d9f481c39..2c772c80a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt @@ -5,7 +5,10 @@ import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.safeListener +import kotlinx.coroutines.launch import net.minecraft.inventory.ClickType import net.minecraft.inventory.Container import net.minecraft.item.ItemStack @@ -61,17 +64,21 @@ class InventoryTransaction( || packet.actionNumber != transactionId ) return@safeListener - if (!packet.wasAccepted()) { - failedWith(DeniedException(packet.actionNumber)) - return@safeListener - } + defaultScope.launch { + onMainThreadSafe { + if (!packet.wasAccepted()) { + failedWith(DeniedException(packet.actionNumber)) + return@onMainThreadSafe + } - getContainerOrNull(packet.windowId)?.let { container -> - container.slotClick(slot, mouseButton, type, player) - success() + getContainerOrNull(packet.windowId)?.let { container -> + container.slotClick(slot, mouseButton, type, player) + success() // LambdaMod.LOG.info("Accepted packet: ${it.packet.javaClass.simpleName} $transactionId") - } ?: run { - failedWith(ContainerOutdatedException(packet.windowId)) + } ?: run { + failedWith(ContainerOutdatedException(packet.windowId)) + } + } } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 27d3748be..b40ac4194 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -31,7 +31,7 @@ object BuildTools : Module( // }) /* mining */ - val breakDelay by setting("Break Delay", 1, 0..20, 5, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") + val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") // val maxPending by setting("Max Pending", 1, 1..100, 1, { page == Page.BUILDING }, description = "Sets the maximum amount of pending break tasks") val miningSpeedFactor by setting("Mining Speed Factor", 1.0f, 0.0f..2.0f, 0.01f, { page == Page.BUILDING }, description = "Factor to manipulate calculated mining speed") // val interactionLimit by setting("Interaction Limit", 20, 1..100, 1, { page == Page.MINING }, description = "Set the interaction limit per second", unit = " interactions/s") @@ -149,8 +149,8 @@ object BuildTools : Module( "minecraft:cobblestone" ) - val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) - val ejectList = setting(CollectionSetting("Eject List", defaultEjectList)) + val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, String::class.java, { false })) + val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, String::class.java, { false })) private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) private val food = setting("FoodItem", "minecraft:golden_apple", { false }) private val tool = setting("ToolItem", "minecraft:diamond_pickaxe", { false }) From 2d6d57ba6a093364ac7b915fee8df181650d0e05 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 6 Mar 2023 05:37:48 +0100 Subject: [PATCH 076/104] Optimal tool selection and other optimizations --- .../com/lambda/client/activity/Activity.kt | 16 +- .../highlevel/BreakDownEnderChests.kt | 3 +- .../activities/highlevel/BuildStructure.kt | 1 + .../highlevel/{BreakArea.kt => ClearArea.kt} | 43 +++-- .../activities/interaction/BreakBlock.kt | 165 ++++++++++++------ .../activities/interaction/PlaceBlock.kt | 43 +++-- .../activity/activities/travel/BreakGoal.kt | 13 +- .../activity/activities/travel/PlaceGoal.kt | 42 +++-- .../activities/types/BuildActivity.kt | 8 +- .../manager/managers/ActivityManager.kt | 8 +- .../module/modules/client/BuildTools.kt | 8 +- .../client/module/modules/misc/WorldEater.kt | 81 ++++++--- 12 files changed, 290 insertions(+), 141 deletions(-) rename src/main/kotlin/com/lambda/client/activity/activities/highlevel/{BreakArea.kt => ClearArea.kt} (55%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index e400fe8cd..ef900a52d 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -163,22 +163,24 @@ abstract class Activity(val isRoot: Boolean = false) { fun SafeClientEvent.cancel() { val activity = this@Activity + onCancel() + + BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + LambdaEventBus.unsubscribe(activity) ListenerManager.unregister(activity) - subActivities.forEach { + subActivities.toList().forEach { with(it) { cancel() } } - with(owner) { - subActivities.remove(activity) + if (!owner.isRoot) { + with(owner) { + subActivities.remove(activity) + } } - - onCancel() - - BaritoneUtils.primary?.pathingBehavior?.cancelEverything() } private fun SafeClientEvent.childFailure(childActivities: ArrayDeque, childException: Exception): Boolean { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 94b14a400..1367fd876 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -22,7 +22,8 @@ class BreakDownEnderChests( ) : RepeatingActivity, Activity() { override fun SafeClientEvent.onInitialize() { val freeSlots = player.inventorySlots.filter { slot -> - BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) || slot.stack.isEmpty + BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) + || slot.stack.isEmpty } if (freeSlots.isEmpty()) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 86f943b19..90e0feeb8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -44,6 +44,7 @@ class BuildStructure( } /* only option left is breaking the block */ else -> { +// activities.add(BreakBlock(blockPos, collectDrops = true, minCollectAmount = 64)) activities.add(BreakBlock(blockPos)) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt similarity index 55% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt rename to src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt index 5425095d7..de83e1301 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt @@ -7,32 +7,40 @@ import com.lambda.client.util.color.ColorHolder import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.EnumFacing +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos -class BreakArea( - private val pos1: BlockPos, - private val pos2: BlockPos, +class ClearArea( + pos1: BlockPos, + pos2: BlockPos, private val layerSize: Int = 1, private val sliceSize: Int = 1, private val sliceDirection: EnumFacing = EnumFacing.NORTH, - override val toRender: MutableSet = mutableSetOf( - RenderAABBActivity.Companion.RenderBlockPos(pos1, ColorHolder(255, 0, 255)), - RenderAABBActivity.Companion.RenderBlockPos(pos2, ColorHolder(0, 255, 0)) - ) + override val toRender: MutableSet = mutableSetOf() ) : RenderAABBActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - val minX = minOf(pos1.x, pos2.x) - val minY = minOf(pos1.y, pos2.y) - val minZ = minOf(pos1.z, pos2.z) - val maxX = maxOf(pos1.x, pos2.x) - val maxY = maxOf(pos1.y, pos2.y) - val maxZ = maxOf(pos1.z, pos2.z) + private val minX = minOf(pos1.x, pos2.x) + private val minY = minOf(pos1.y, pos2.y) + private val minZ = minOf(pos1.z, pos2.z) + private val maxX = maxOf(pos1.x, pos2.x) + private val maxY = maxOf(pos1.y, pos2.y) + private val maxZ = maxOf(pos1.z, pos2.z) + + init { + RenderAABBActivity.Companion.RenderAABB( + AxisAlignedBB( + minX.toDouble(), minY.toDouble(), minZ.toDouble(), + (maxX + 1).toDouble(), (maxY + 1).toDouble(), (maxZ + 1).toDouble() + ), + ColorHolder(245, 66, 66) + ).also { toRender.add(it) } + } + override fun SafeClientEvent.onInitialize() { val layers = (minY..maxY).reversed() - layers.forEach { y -> - val structure = mutableMapOf() + val structure = mutableMapOf() + layers.forEach { y -> (minX..maxX).forEach { x -> (minZ..maxZ).forEach { z -> structure[BlockPos(x, y, z)] = Blocks.AIR.defaultState @@ -41,8 +49,9 @@ class BreakArea( if (y.mod(layerSize) == 0 || y == layers.last) { addSubActivities( - BuildStructure(structure) + BuildStructure(structure.toMap()) ) + structure.clear() } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 199f96b51..06086a59e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -13,7 +13,7 @@ import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.items.allSlots +import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f @@ -23,14 +23,17 @@ import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid import kotlinx.coroutines.launch +import net.minecraft.block.state.IBlockState +import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks +import net.minecraft.init.Enchantments import net.minecraft.init.Items import net.minecraft.item.Item +import net.minecraft.item.ItemStack import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraftforge.common.ForgeHooks import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.ceil @@ -40,7 +43,11 @@ class BreakBlock( private val blockPos: BlockPos, private val collectDrops: Boolean = false, private val minCollectAmount: Int = 1, - override var timeout: Long = 200L, // ToDo: Reset timeouted breaks + private val forceSilk: Boolean = false, + private val forceNoSilk: Boolean = false, + private val forceFortune: Boolean = false, + private val forceNoFortune: Boolean = false, + override var timeout: Long = 200L, // ToDo: Reset timeouted breaks blockstates override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), @@ -49,7 +56,7 @@ class BreakBlock( ) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 - private var drop: Item = Items.AIR + private var drops: Item = Items.AIR override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> if (old == new) return@observable @@ -89,8 +96,7 @@ class BreakBlock( return@runSafe } - drop = currentState.block.getItemDropped(currentState, Random(), 0) ?: Items.AIR - + updateDrops(currentState) updateState() } @@ -99,13 +105,17 @@ class BreakBlock( updateState() + if (context != BuildActivity.BuildContext.PENDING + && world.getBlockState(blockPos) == Blocks.AIR.defaultState + ) success() + if (action != BuildActivity.BuildAction.BREAKING || subActivities.isNotEmpty() || status == Status.UNINITIALIZED ) return@safeListener side?.let { side -> - checkBreak(side) + tryBreak(side) } } @@ -129,7 +139,7 @@ class BreakBlock( when (action) { BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { side?.let { side -> - checkBreak(side) + tryBreak(side) } } BuildActivity.BuildAction.WRONG_POS_BREAK -> { @@ -147,16 +157,17 @@ class BreakBlock( } private fun SafeClientEvent.finish() { - if (!collectDrops || !autoPathing || drop == Items.AIR) { + if (!collectDrops || !autoPathing || drops == Items.AIR) { ActivityManagerHud.totalBlocksBroken++ success() return } renderAction.color = ColorHolder(252, 3, 207) + context = BuildActivity.BuildContext.NONE addSubActivities( - PickUpDrops(drop, minAmount = minCollectAmount) + PickUpDrops(drops, minAmount = minCollectAmount) ) } @@ -182,69 +193,117 @@ class BreakBlock( } } - private fun SafeClientEvent.checkBreak(side: EnumFacing) { + private fun SafeClientEvent.tryBreak(side: EnumFacing) { + if (checkLiquids() || !hasOptimalTool()) return + val currentState = world.getBlockState(blockPos) - drop = currentState.block.getItemDropped(currentState, Random(), 0) ?: Items.AIR + // ToDo: add silk touch support + updateDrops(currentState) + + ticksNeeded = ceil((1 / currentState + .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() + timeout = ticksNeeded * 50L + 2000L + + if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { + if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { + playerController.blockHitDelay = 0 + context = BuildActivity.BuildContext.PENDING + } else { + action = BuildActivity.BuildAction.BREAKING + } + + mc.effectRenderer.addBlockHitEffects(blockPos, side) + player.swingArm(EnumHand.MAIN_HAND) + } + } - currentState.block.getHarvestTool(currentState)?.let { harvestTool -> - if (!player.capabilities.isCreativeMode - && !ForgeHooks.isToolEffective(world, blockPos, player.heldItemMainhand) + // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) + // ToDo: 2. ForgeHooks.canHarvestBlock(currentState.block, player, world, blockPos) + private fun SafeClientEvent.hasOptimalTool(): Boolean { + if (player.capabilities.isCreativeMode) return true + + val currentState = world.getBlockState(blockPos) + val currentDestroySpeed = player.heldItemMainhand.getDestroySpeed(currentState) + + player.inventorySlots.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { + if (it.stack.getDestroySpeed(currentState) > currentDestroySpeed +// && it.stack != player.heldItemMainhand +// && (!getSilkDrop || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it.stack) > 0) ) { - player.allSlots.filter { - ForgeHooks.isToolEffective(world, blockPos, it.stack) - }.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { - addSubActivities(SwapOrSwitchToSlot(it)) - } ?: run { - context = BuildActivity.BuildContext.RESTOCK + context = BuildActivity.BuildContext.RESTOCK + + addSubActivities(SwapOrSwitchToSlot(it)) + return false + } + } - // ToDo: add support for lower tools - val item = when (harvestTool) { - "pickaxe" -> Items.DIAMOND_PICKAXE - "axe" -> Items.DIAMOND_AXE - else -> Items.DIAMOND_SHOVEL - } + val availableTools = mutableListOf() + + if (BuildTools.usePickaxe) availableTools.add(Items.DIAMOND_PICKAXE) + if (BuildTools.useShovel) availableTools.add(Items.DIAMOND_SHOVEL) + if (BuildTools.useAxe) availableTools.add(Items.DIAMOND_AXE) + if (BuildTools.useShears) availableTools.add(Items.SHEARS) + if (BuildTools.useSword) availableTools.add(Items.DIAMOND_SWORD) + + availableTools.maxByOrNull { tool -> + tool.getDestroySpeed(ItemStack(tool), currentState) + }?.let { tool -> + val selectedSpeed = tool.getDestroySpeed(ItemStack(tool), currentState) + + if (selectedSpeed > currentDestroySpeed) { + context = BuildActivity.BuildContext.RESTOCK + + addSubActivities(AcquireItemInActiveHand( + tool, +// predicateItem = { +// EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 +// } + )) + return false + } - addSubActivities(AcquireItemInActiveHand(item)) + if (selectedSpeed == 1.0f + && player.heldItemMainhand.isItemStackDamageable + ) { + player.inventorySlots.firstOrNull { !it.stack.isItemStackDamageable }?.let { + context = BuildActivity.BuildContext.RESTOCK + + addSubActivities(SwapOrSwitchToSlot(it)) + return false } - return } } - // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) - // ToDo: 2. ForgeHooks.canHarvestBlock(currentState.block, player, world, blockPos) - - ticksNeeded = ceil((1 / currentState - .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 2000L + return true + } - var needToHandleLiquid = false + private fun SafeClientEvent.checkLiquids(): Boolean { + var foundLiquid = false EnumFacing.values() .filter { it != EnumFacing.UP } .map { blockPos.offset(it) } .filter { world.getBlockState(it).isLiquid } .forEach { - val placeActivity = PlaceBlock(it, BuildTools.defaultFillerMat.defaultState) - placeActivity.context = BuildActivity.BuildContext.LIQUID + // ToDo: Don't add if exists + PlaceBlock(it, BuildTools.defaultFillerMat.defaultState).apply { + context = BuildActivity.BuildContext.LIQUID + addSubActivities(this) + } - addSubActivities(placeActivity) - needToHandleLiquid = true + foundLiquid = true } - if (needToHandleLiquid) return - - if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { - if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { - playerController.blockHitDelay = 0 - context = BuildActivity.BuildContext.PENDING - } else { - action = BuildActivity.BuildAction.BREAKING - } + return foundLiquid + } - mc.effectRenderer.addBlockHitEffects(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) - } + private fun SafeClientEvent.updateDrops(currentState: IBlockState) { + drops = currentState.block.getItemDropped( + currentState, + Random(), + EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.heldItemMainhand) + ) ?: Items.AIR } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { @@ -253,7 +312,7 @@ class BreakBlock( ActivityManagerHud.totalBlocksBroken++ success() } - is AcquireItemInActiveHand, is PlaceBlock -> { + else -> { status = Status.UNINITIALIZED context = BuildActivity.BuildContext.NONE action = BuildActivity.BuildAction.NONE diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index cc22bce29..88af0ef9b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -1,11 +1,9 @@ package com.lambda.client.activity.activities.interaction -import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* -import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud @@ -47,7 +45,7 @@ class PlaceBlock( private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, override var distance: Double = 1337.0, - override val timeout: Long = 200L, // ToDo: Reset timeouted placements + override val timeout: Long = 1000L, // ToDo: Reset timeouted placements blockstates override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -116,9 +114,7 @@ class PlaceBlock( defaultScope.launch { onMainThreadSafe { - if (it.packet.blockState == targetState - || (ignoreProperties && it.packet.blockState.block == targetState.block) - ) { + if (isInDesiredState(it.packet.blockState)) { ActivityManagerHud.totalBlocksPlaced++ success() @@ -157,6 +153,10 @@ class PlaceBlock( val currentState = world.getBlockState(blockPos) + if (context != BuildActivity.BuildContext.PENDING + && isInDesiredState(currentState) + ) success() + if (!currentState.isReplaceable && currentState != targetState && context != BuildActivity.BuildContext.PENDING @@ -214,7 +214,6 @@ class PlaceBlock( } } -// /* check if block is replaceable */ // allowedSides.removeIf { // !targetState.block.canPlaceBlockOnSide(world, blockPos, it.opposite) // } @@ -226,10 +225,19 @@ class PlaceBlock( range = BuildTools.maxReach, sides = allowedSides.toTypedArray() )?.let { - action = BuildActivity.BuildAction.PLACE - it.hitVec = it.hitVec.add(placementOffset.offset) - distance = player.distanceTo(it.hitVec) - placeInfo = it + if (it.placedPos == blockPos) { + action = BuildActivity.BuildAction.PLACE + it.hitVec = it.hitVec.add(placementOffset.offset) + distance = player.distanceTo(it.hitVec) + placeInfo = it + } else { + action = BuildActivity.BuildAction.NEEDS_SUPPORT + + PlaceBlock(it.placedPos, targetState).apply { + context = BuildActivity.BuildContext.SUPPORT + addSubActivities(this) + } + } } ?: run { getNeighbour( blockPos, @@ -356,6 +364,12 @@ class PlaceBlock( context = BuildActivity.BuildContext.PENDING } + private fun isInDesiredState(currentState: IBlockState) = + currentState == targetState + || (ignoreProperties && currentState.block == targetState.block) +// || (ignoreFacing && currentState.block == targetState.block && currentState.properties == targetState.properties) + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is Rotate -> { @@ -369,6 +383,13 @@ class PlaceBlock( } } +// override fun SafeClientEvent.onFailure(exception: Exception): Boolean { +// if (context != BuildActivity.BuildContext.PENDING) return false +// +// world.setBlockState(blockPos, initState) +// return false +// } + class NoNeighbourException(blockPos: BlockPos) : Exception("No neighbour for (${blockPos.asString()}) found") class BlockNotPlaceableException(targetState: IBlockState) : Exception("Block $targetState is not placeable") class ProcessRightClickException(result: EnumActionResult) : Exception("Processing right click failed with result $result") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt index 21e05beb7..dd0e5c1c0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalInverted -import baritone.api.pathing.goals.GoalNear +import baritone.process.BuilderProcess.GoalBreak import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent @@ -20,8 +20,9 @@ class BreakGoal( override val timeout: Long = 60000L ) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (isInBlockAABB(blockPos) - && GoalNear(blockPos, 3).isInGoal(player.flooredPosition)) success() + if (!isInBlockAABB(blockPos.up()) + && getMiningSide(blockPos, BuildTools.maxReach) != null + ) success() } init { @@ -36,10 +37,10 @@ class BreakGoal( getMiningSide(blockPos, BuildTools.maxReach)?.let { success() } ?: run { - val goalNear = GoalNear(blockPos, 3) + val goalBreak = GoalBreak(blockPos) - if (!goalNear.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) + if (!goalBreak.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalBreak) return@safeListener } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt index d699915c4..31ac650be 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -3,9 +3,11 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear +import baritone.process.BuilderProcess import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener @@ -33,23 +35,37 @@ class PlaceGoal( return@safeListener } - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.5f)?.let { + // ToDo: Use original data from PlaceBlock + getNeighbour( + blockPos, + attempts = BuildTools.placementSearch, + visibleSideCheck = BuildTools.placeStrictness != BuildTools.PlacementStrictness.ANY, + range = BuildTools.maxReach + )?.let { success() } ?: run { - getNeighbour(blockPos, attempts = 1, range = 256f)?.let { - val goalNear = GoalNear(blockPos, 3) + val goalAdjacent = BuilderProcess.GoalAdjacent(blockPos, blockPos, true) - if (!goalNear.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) - return@safeListener - } - - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 1)) - } ?: run { - // ToDo: Scaffolding! - - failedWith(NoPathToPlaceFound()) + if (!goalAdjacent.isInGoal(player.flooredPosition)) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalAdjacent) + return@safeListener } + + failedWith(NoPathToPlaceFound()) +// getNeighbour(blockPos, attempts = 1, range = 256f)?.let { +// val goalNear = GoalNear(blockPos, 3) +// +// if (!goalNear.isInGoal(player.flooredPosition)) { +// BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) +// return@safeListener +// } +// +// BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 1)) +// } ?: run { +// // ToDo: Scaffolding! +// +// failedWith(NoPathToPlaceFound()) +// } } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt index 58e3166b7..dd38cc7e8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -10,6 +10,7 @@ interface BuildActivity { enum class BuildContext(val color: ColorHolder) { RESTOCK(ColorHolder()), LIQUID(ColorHolder()), + SUPPORT(ColorHolder()), NONE(ColorHolder(0, 0, 0, 0)), PENDING(ColorHolder(11, 11, 175)) } @@ -18,10 +19,13 @@ interface BuildActivity { BREAKING(ColorHolder(240, 222, 60)), BREAK(ColorHolder(222, 0, 0)), PLACE(ColorHolder(35, 188, 254)), + NEEDS_SUPPORT(ColorHolder(35, 15, 254)), WRONG_POS_BREAK(ColorHolder(112, 0, 0)), WRONG_POS_PLACE(ColorHolder(20, 108, 145)), - INVALID_BREAK(ColorHolder(46, 0, 0)), - INVALID_PLACE(ColorHolder(11, 55, 74)), +// INVALID_BREAK(ColorHolder(46, 0, 0)), +// INVALID_PLACE(ColorHolder(11, 55, 74)), + INVALID_BREAK(ColorHolder(46, 0, 0, 0)), + INVALID_PLACE(ColorHolder(11, 55, 74, 0)), NONE(ColorHolder(11, 11, 11)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 742d7b841..c85fb726f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -36,14 +36,14 @@ object ActivityManager : Manager, Activity(true) { var lastActivity: Activity? = null +// BaritoneUtils.settings?.allowPlace?.value = false +// BaritoneUtils.settings?.allowBreak?.value = false + BaritoneUtils.settings?.allowInventory?.value = false + repeat(executionCountPerTick) { val current = getCurrentActivity() with(current) { - BaritoneUtils.settings?.allowPlace?.value = false - BaritoneUtils.settings?.allowBreak?.value = false - BaritoneUtils.settings?.allowInventory?.value = false - // ToDo: Find a working way to guarantee specific age of activity (lastActivity as? TimedActivity)?.let { if (age < it.earliestFinish) return@repeat diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index b40ac4194..d9da23b1c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -66,6 +66,12 @@ object BuildTools : Module( // val leastFood by setting("Least Food", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && manageFood && storageManagement }, description = "How many food items are saved") // val preferEnderChests by setting("Prefer Ender Chests", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Prevent using raw material shulkers") + val usePickaxe by setting("Force Pickaxe", true, { page == Page.TOOLS }, description = "Use pickaxe to mine blocks") + val useAxe by setting("Force Axe", true, { page == Page.TOOLS }, description = "Use axe to mine blocks") + val useShovel by setting("Force Shovel", true, { page == Page.TOOLS }, description = "Use shovel to mine blocks") + val useSword by setting("Force Sword", true, { page == Page.TOOLS }, description = "Use sword to mine blocks") + val useShears by setting("Force Shears", true, { page == Page.TOOLS }, description = "Use shears to mine blocks") + /* render */ // val info by setting("Show Info", true, { page == Page.RENDER }, description = "Prints session stats in chat") // val goalRender by setting("Baritone Goal", false, { page == Page.RENDER }, description = "Renders the baritone goal") @@ -92,7 +98,7 @@ object BuildTools : Module( // val proxyCommand by setting("Proxy Command", "/dc", { page == Page.MISC && disableMode == DisableMode.LOGOUT && usingProxy }, description = "Command to be sent to log out") private enum class Page { - BUILDING, RENDER + BUILDING, TOOLS, RENDER } enum class DebugLevel { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index eb8f1aee8..a470697bd 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,21 +1,17 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.activity.activities.highlevel.BreakArea -import com.lambda.client.activity.activities.highlevel.BuildSchematic +import com.lambda.client.activity.activities.highlevel.ClearArea import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.ActivityManager.cancel import com.lambda.client.module.Category import com.lambda.client.module.Module -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.math.Direction -import com.lambda.client.util.math.VectorUtils.multiply -import com.lambda.client.util.schematic.LambdaSchematicaHelper -import com.lambda.client.util.schematic.LambdaSchematicaHelper.isSchematicaPresent -import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe +import com.lambda.client.util.threads.safeListener import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.RayTraceResult +import net.minecraftforge.fml.common.gameevent.InputEvent +import org.lwjgl.input.Mouse object WorldEater : Module( name = "WorldEater", @@ -28,26 +24,32 @@ object WorldEater : Module( private val layerSize by setting("Layers size", 1, 1..6, 1) private val sliceSize by setting("Slice size", 1, 1..6, 1) private val sliceDirection by setting("Slice direction", EnumFacing.NORTH) + private val start by setting("Start", false, consumer = { _, _ -> + clearArea() + false + }) - private var ownedBuildStructure: BreakArea? = null + private var ownedBuildStructure: ClearArea? = null + private var firstPos: BlockPos? = null + private var secondPos: BlockPos? = null init { - onEnable { - runSafe { - val currentDirection = player.horizontalFacing - val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) - val pos2 = player.flooredPosition.add( - currentDirection.directionVec.multiply(size) - ).add( - currentDirection.rotateY().directionVec.multiply(size) - ).down(depth) - - BreakArea(pos1, pos2, layerSize).let { - ownedBuildStructure = it - ActivityManager.addSubActivities(it) - } - } - } +// onEnable { +// runSafe { +// val currentDirection = player.horizontalFacing +// val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) +// val pos2 = player.flooredPosition.add( +// currentDirection.directionVec.multiply(size) +// ).add( +// currentDirection.rotateY().directionVec.multiply(size) +// ).down(depth) +// +// BreakArea(pos1, pos2, layerSize).let { +// ownedBuildStructure = it +// ActivityManager.addSubActivities(it) +// } +// } +// } onDisable { runSafe { @@ -58,5 +60,32 @@ object WorldEater : Module( } } } + + safeListener { + mc.objectMouseOver?.let { result -> + if (result.typeOfHit != RayTraceResult.Type.BLOCK) return@safeListener + + when (Mouse.getEventButton()) { + 0 -> firstPos = result.blockPos + 1 -> secondPos = result.blockPos + 2 -> clearArea() + } + } + } + } + + private fun clearArea() { + val first = firstPos ?: return + val second = secondPos ?: return + + ClearArea( + first, + second, + layerSize, + sliceSize, + ).let { + ownedBuildStructure = it + ActivityManager.addSubActivities(it) + } } } \ No newline at end of file From 83ec46cda61881f44a9451e25f16bc5e390204bb Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 7 Mar 2023 18:47:06 +0100 Subject: [PATCH 077/104] Fix attempting activities and skipping ignore blocks --- .../com/lambda/client/activity/Activity.kt | 49 ++++++++++++------- .../activities/interaction/BreakBlock.kt | 24 ++++++--- .../activities/interaction/PlaceBlock.kt | 6 +-- .../activities/storage/PlaceContainer.kt | 2 - .../activities/types/AttemptActivity.kt | 4 +- .../activities/types/LoopWhileActivity.kt | 2 +- .../activities/types/RepeatingActivity.kt | 2 +- .../activities/types/TimeoutActivity.kt | 12 +---- .../command/commands/BuildToolsCommand.kt | 45 +++++++++++++++++ .../manager/managers/ActivityManager.kt | 16 +++--- .../module/modules/client/BuildTools.kt | 12 ++--- 11 files changed, 114 insertions(+), 60 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index ef900a52d..b66e9b536 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -29,11 +29,11 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import org.apache.commons.lang3.time.DurationFormatUtils -abstract class Activity(val isRoot: Boolean = false) { +abstract class Activity { val subActivities = ArrayDeque() var status = Status.UNINITIALIZED private var creationTime = 0L - var owner: Activity = ActivityManager + var owner: Activity? = null var depth = 0 open fun SafeClientEvent.onInitialize() {} @@ -73,7 +73,9 @@ abstract class Activity(val isRoot: Boolean = false) { get() = run { val activities = mutableListOf() - if (!isRoot) activities.add(this) + owner?.let { + activities.add(this) + } activities.addAll(subActivities.flatMap { it.allSubActivities }) @@ -130,9 +132,11 @@ abstract class Activity(val isRoot: Boolean = false) { LambdaEventBus.unsubscribe(activity) ListenerManager.unregister(activity) - with(owner) { - onChildSuccess(activity) - subActivities.remove(activity) + owner?.let { + with(it) { + onChildSuccess(activity) + subActivities.remove(activity) + } } onSuccess() @@ -148,16 +152,23 @@ abstract class Activity(val isRoot: Boolean = false) { fun SafeClientEvent.failedWith(exception: Exception) { val activity = this@Activity - with(owner) { - if (childFailure(ArrayDeque(listOf(activity)), exception)) return + MessageSendHelper.sendErrorMessage("Exception in $activityName: ${exception.message}") + + if (onFailure(exception)) return + + owner?.let { + with(it) { + if (childFailure(ArrayDeque(listOf(activity)), exception)) return + } } if (checkAttempt(activity, exception)) return - if (onFailure(exception)) return - MessageSendHelper.sendErrorMessage("Exception in $activityName: ${exception.message}") + MessageSendHelper.sendErrorMessage("Fatal Exception in $activityName: ${exception.message}") - ActivityManager.reset() + with(ActivityManager) { + cancel() + } } fun SafeClientEvent.cancel() { @@ -167,17 +178,16 @@ abstract class Activity(val isRoot: Boolean = false) { BaritoneUtils.primary?.pathingBehavior?.cancelEverything() - LambdaEventBus.unsubscribe(activity) - ListenerManager.unregister(activity) - subActivities.toList().forEach { with(it) { cancel() } } - if (!owner.isRoot) { - with(owner) { + owner?.let { + with(it) { + LambdaEventBus.unsubscribe(activity) + ListenerManager.unregister(activity) subActivities.remove(activity) } } @@ -194,9 +204,12 @@ abstract class Activity(val isRoot: Boolean = false) { } childActivities.add(this@Activity) - with(owner) { - childFailure(childActivities, childException) + owner?.let { + with(it) { + childFailure(childActivities, childException) + } } + return false } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 06086a59e..23be81d8c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -90,7 +90,6 @@ class BreakBlock( val currentState = world.getBlockState(blockPos) - // ToDo: doesn't work for some reason if (currentState.block in BuildTools.ignoredBlocks) { success() return@runSafe @@ -134,6 +133,15 @@ class BreakBlock( } override fun SafeClientEvent.onInitialize() { + val currentState = world.getBlockState(blockPos) + + if (currentState.block in BuildTools.ignoredBlocks + || currentState.getBlockHardness(world, blockPos) < 0 + ) { + success() + return + } + updateState() when (action) { @@ -282,14 +290,14 @@ class BreakBlock( var foundLiquid = false EnumFacing.values() - .filter { it != EnumFacing.UP } + .filter { it != EnumFacing.DOWN } .map { blockPos.offset(it) } .filter { world.getBlockState(it).isLiquid } - .forEach { + .forEach { pos -> // ToDo: Don't add if exists - PlaceBlock(it, BuildTools.defaultFillerMat.defaultState).apply { - context = BuildActivity.BuildContext.LIQUID - addSubActivities(this) + PlaceBlock(pos, BuildTools.defaultFillerMat.defaultState).also { breakBlock -> + breakBlock.context = BuildActivity.BuildContext.LIQUID + addSubActivities(breakBlock) } foundLiquid = true @@ -323,6 +331,10 @@ class BreakBlock( override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() + context = BuildActivity.BuildContext.NONE + action = BuildActivity.BuildAction.NONE + side = null + rotation = null return false } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index 88af0ef9b..b2615de13 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -233,9 +233,9 @@ class PlaceBlock( } else { action = BuildActivity.BuildAction.NEEDS_SUPPORT - PlaceBlock(it.placedPos, targetState).apply { - context = BuildActivity.BuildContext.SUPPORT - addSubActivities(this) + PlaceBlock(it.placedPos, targetState).also { placeBlock -> + placeBlock.context = BuildActivity.BuildContext.SUPPORT + addSubActivities(placeBlock) } } } ?: run { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index dc628e67d..593c475a6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -1,10 +1,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BuildStructure import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent import net.minecraft.block.state.IBlockState diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt index c391f7381..b5989bb4e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt @@ -19,11 +19,11 @@ interface AttemptActivity { } else { usedAttempts++ LambdaMod.LOG.warn("$activityName caused ${causeException::class.simpleName}: ${causeException.message}. Attempt $usedAttempts of $maxAttempts restarting...") - subActivities.clear() initialize() + return true } } - return true + return false } class MaxAttemptsExceededException(usedAttempts: Int, causeException: Exception) : Exception("Exceeded $usedAttempts attempts caused by ${causeException::class.simpleName}: ${causeException.message}") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt index d7551c0e3..08ca1e53c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt @@ -16,7 +16,7 @@ interface LoopWhileActivity { currentLoops++ status = Activity.Status.UNINITIALIZED - owner.subActivities.add(activity) + owner?.subActivities?.add(activity) // LambdaMod.LOG.info("Looping $name ($currentLoops)") } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt index b7b211ff5..b5337f689 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt @@ -15,7 +15,7 @@ interface RepeatingActivity { if (repeated++ >= maximumRepeats && maximumRepeats != 0) return status = Activity.Status.UNINITIALIZED - owner.subActivities.add(activity) + owner?.subActivities?.add(activity) // LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt index b475e7045..25b207f40 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.activities.types import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.event.SafeClientEvent interface TimeoutActivity { @@ -14,16 +13,7 @@ interface TimeoutActivity { with(activity) { if (age <= timeout) return - if (activity is AttemptActivity) { - checkAttempt(activity, TimeoutException(age, timeout)) -// with(activity) { -// usedAttempts++ -// initialize() -// MessageSendHelper.sendErrorMessage("$name timed out at attempt $usedAttempts of $maxAttempts") -// } - } else { - failedWith(TimeoutException(age, timeout)) - } + failedWith(TimeoutException(age, timeout)) } } diff --git a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt index e6462887f..552231d68 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt @@ -3,6 +3,7 @@ package com.lambda.client.command.commands import com.lambda.client.command.ClientCommand import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.init.Items object BuildToolsCommand : ClientCommand( name = "buildtools", @@ -37,7 +38,26 @@ object BuildToolsCommand : ClientCommand( } } + literal("reset", "clear") { + execute("Resets the ignore list") { + BuildTools.ignoreBlocks.clear() + MessageSendHelper.sendChatMessage("Reset ignore list.") + } + } + + literal("default") { + execute("Adds all default blocks to ignore list") { + BuildTools.ignoreBlocks.addAll(BuildTools.defaultIgnoreBlocks) + MessageSendHelper.sendChatMessage("Added all default blocks to ignore list.") + } + } + execute("Lists all ignored blocks") { + if (BuildTools.ignoreBlocks.isEmpty()) { + MessageSendHelper.sendChatMessage("No blocks are ignored.") + return@execute + } + MessageSendHelper.sendChatMessage("Ignored blocks: ${BuildTools.ignoreBlocks.joinToString(", ")}") } } @@ -69,7 +89,25 @@ object BuildToolsCommand : ClientCommand( } } + literal("reset", "clear") { + execute("Resets the eject list") { + BuildTools.ejectList.clear() + MessageSendHelper.sendChatMessage("Reset eject list.") + } + } + + literal("default") { + execute("Adds all default blocks to eject list") { + BuildTools.ejectList.addAll(BuildTools.defaultEjectList) + MessageSendHelper.sendChatMessage("Added all default blocks to eject list.") + } + } + execute("Lists all blocks in eject list") { + if (BuildTools.ejectList.isEmpty()) { + MessageSendHelper.sendChatMessage("No blocks are in the eject list.") + return@execute + } MessageSendHelper.sendChatMessage("Eject list: ${BuildTools.ejectList.joinToString(", ")}") } } @@ -82,6 +120,13 @@ object BuildToolsCommand : ClientCommand( } } + literal("default") { + execute("Sets the food item to default") { + BuildTools.defaultFood = Items.GOLDEN_APPLE + MessageSendHelper.sendChatMessage("Set food item to default.") + } + } + execute("Shows the food item") { MessageSendHelper.sendChatMessage("Food item: &7${BuildTools.defaultFood.registryName}&r") } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index c85fb726f..51d95821a 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -16,7 +16,7 @@ import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent -object ActivityManager : Manager, Activity(true) { +object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 @@ -74,14 +74,16 @@ object ActivityManager : Manager, Activity(true) { fun reset() { ListenerManager.listenerMap.keys.filterIsInstance().forEach { - if (it.isRoot) return@forEach - LambdaEventBus.unsubscribe(it) - ListenerManager.unregister(it) + it.owner?.let { _ -> + LambdaEventBus.unsubscribe(it) + ListenerManager.unregister(it) + } } ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { - if (it.isRoot) return@forEach - LambdaEventBus.unsubscribe(it) - ListenerManager.unregister(it) + it.owner?.let { _ -> + LambdaEventBus.unsubscribe(it) + ListenerManager.unregister(it) + } } BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index d9da23b1c..8afc08b9d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -134,20 +134,14 @@ object BuildTools : Module( food.value = value.registryName.toString() } - private val defaultIgnoreBlocks = linkedSetOf( + val defaultIgnoreBlocks = linkedSetOf( "minecraft:standing_sign", "minecraft:wall_sign", "minecraft:standing_banner", - "minecraft:wall_banner", - "minecraft:bedrock", - "minecraft:end_portal", - "minecraft:end_portal_frame", - "minecraft:portal", - "minecraft:piston_extension", - "minecraft:barrier" + "minecraft:wall_banner" ).also { defaultIgnoreBlocks -> defaultIgnoreBlocks.addAll(shulkerList.map { it.localizedName }) } - private val defaultEjectList = linkedSetOf( + val defaultEjectList = linkedSetOf( "minecraft:grass", "minecraft:dirt", "minecraft:netherrack", From 6a6d71c5dc36ae12cdab9e6d34d11fb48a87e69e Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 10 Mar 2023 05:22:25 +0100 Subject: [PATCH 078/104] Lots of fixes --- .../highlevel/BreakDownEnderChests.kt | 6 +- .../activities/highlevel/BuildStructure.kt | 78 +++++++++++----- .../activities/highlevel/ClearArea.kt | 2 +- .../activities/interaction/BreakBlock.kt | 56 ++++++++--- .../activities/interaction/PlaceBlock.kt | 34 ++----- .../inventory/AcquireItemInActiveHand.kt | 93 +++++++++++-------- .../storage/ExtractItemFromShulkerBox.kt | 50 +++------- .../activities/storage/OpenShulkerFromSlot.kt | 34 ------- .../activities/storage/PlaceContainer.kt | 22 +++-- .../storage/PullItemsFromContainer.kt | 33 ++++--- .../storage/StoreItemToShulkerBox.kt | 6 +- .../activity/activities/travel/PickUpDrops.kt | 22 +++-- .../activities/travel/PickUpEntityItem.kt | 11 +-- .../activities/types/BuildActivity.kt | 7 +- .../activities/utils/ActivityUtils.kt | 9 +- .../manager/managers/ActivityManager.kt | 16 ++-- .../module/modules/client/BuildTools.kt | 5 +- .../modules/misc/TestActivityManager.kt | 16 +++- .../client/module/modules/misc/WorldEater.kt | 35 ++++--- .../modules/player/InventoryManagerTwo.kt | 34 +++---- 20 files changed, 306 insertions(+), 263 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt index 1367fd876..fb9a81ec0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt @@ -15,6 +15,7 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items +import net.minecraft.item.ItemStack class BreakDownEnderChests( override val maximumRepeats: Int = 0, @@ -38,8 +39,9 @@ class BreakDownEnderChests( return } + // ToDo: Better way to find ender chest addSubActivities( - PlaceContainer(Blocks.ENDER_CHEST.defaultState) + PlaceContainer(ItemStack(Blocks.ENDER_CHEST, 1, 0), onlyItem = true) ) } @@ -49,7 +51,7 @@ class BreakDownEnderChests( addSubActivities( AcquireItemInActiveHand( Items.DIAMOND_PICKAXE, - predicateItem = { + predicateStack = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 } ), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt index 90e0feeb8..93bc5f1ca 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt @@ -5,7 +5,6 @@ import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock import com.lambda.client.activity.activities.types.BuildActivity import com.lambda.client.activity.activities.types.RepeatingActivity -import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction @@ -19,6 +18,7 @@ class BuildStructure( private val direction: Direction = Direction.NORTH, private val offsetMove: BlockPos = BlockPos.ORIGIN, private val doPadding: Boolean = false, + private val collectAll: Boolean = false, override val maximumRepeats: Int = 1, override var repeated: Int = 0, ) : RepeatingActivity, Activity() { @@ -28,35 +28,67 @@ class BuildStructure( val activities = mutableListOf() structure.forEach { (pos, targetState) -> - val blockPos = pos.add(currentOffset) - val currentState = world.getBlockState(blockPos) - - when { - /* is in padding */ - doPadding && isInPadding(blockPos) -> return@forEach - /* is in desired state */ - currentState == targetState -> return@forEach - /* block needs to be placed */ - targetState != Blocks.AIR.defaultState -> { - activities.add(PlaceBlock( - blockPos, targetState - )) - } - /* only option left is breaking the block */ - else -> { -// activities.add(BreakBlock(blockPos, collectDrops = true, minCollectAmount = 64)) - activities.add(BreakBlock(blockPos)) - } - } + getBuildActivity(pos.add(currentOffset), targetState)?.let { activities.add(it) } } addSubActivities(activities, subscribe = true) - } - override fun SafeClientEvent.onSuccess() { currentOffset = currentOffset.add(offsetMove) } + init { +// safeListener { +// if (subActivities.isEmpty() || status == Status.UNINITIALIZED) return@safeListener +// success() +// } + +// /* Listen for any block changes like falling sand */ +// safeListener { event -> +// if (event.packet !is SPacketBlockChange) return@safeListener +// +// val blockPos = event.packet.blockPosition +// +// structure[blockPos]?.let { targetState -> +// val isContained = allSubActivities.none { +// when (it) { +// is BreakBlock -> it.blockPos == blockPos +// is PlaceBlock -> it.blockPos == blockPos +// else -> false +// } +// } +// +// if (isContained) return@safeListener +// +// getBuildActivity(blockPos, targetState)?.let { +// addSubActivities(listOf(it), subscribe = true) +// } +// } +// } + } + + private fun SafeClientEvent.getBuildActivity(blockPos: BlockPos, targetState: IBlockState): Activity? { + val currentState = world.getBlockState(blockPos) + + when { + /* is in padding */ + doPadding && isInPadding(blockPos) -> return null + /* is in desired state */ + currentState == targetState -> return null + /* block needs to be placed */ + targetState != Blocks.AIR.defaultState -> { + return PlaceBlock( + blockPos, targetState + ) + } + /* only option left is breaking the block */ + else -> { + return BreakBlock( + blockPos, collectDrops = collectAll, minCollectAmount = 64 + ) + } + } + } + override fun getCurrentActivity(): Activity { subActivities.sortedWith(buildComparator()).firstOrNull()?.let { with(it) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt index de83e1301..0714a9746 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt @@ -49,7 +49,7 @@ class ClearArea( if (y.mod(layerSize) == 0 || y == layers.last) { addSubActivities( - BuildStructure(structure.toMap()) + BuildStructure(structure.toMap(), collectAll = true) ) structure.clear() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt index 23be81d8c..c7f3ca55f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt @@ -12,7 +12,9 @@ import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing -import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.items.block +import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -40,7 +42,7 @@ import kotlin.math.ceil import kotlin.properties.Delegates class BreakBlock( - private val blockPos: BlockPos, + val blockPos: BlockPos, private val collectDrops: Boolean = false, private val minCollectAmount: Int = 1, private val forceSilk: Boolean = false, @@ -95,6 +97,8 @@ class BreakBlock( return@runSafe } + if (currentState.isLiquid) addLiquidFill(blockPos) + updateDrops(currentState) updateState() } @@ -102,11 +106,12 @@ class BreakBlock( safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener - updateState() - if (context != BuildActivity.BuildContext.PENDING - && world.getBlockState(blockPos) == Blocks.AIR.defaultState - ) success() + && action != BuildActivity.BuildAction.BREAKING + && world.isAirBlock(blockPos) + ) finish() + + updateState() if (action != BuildActivity.BuildAction.BREAKING || subActivities.isNotEmpty() @@ -171,8 +176,9 @@ class BreakBlock( return } - renderAction.color = ColorHolder(252, 3, 207) - context = BuildActivity.BuildContext.NONE + if (context == BuildActivity.BuildContext.PICKUP) return + + context = BuildActivity.BuildContext.PICKUP addSubActivities( PickUpDrops(drops, minAmount = minCollectAmount) @@ -181,6 +187,15 @@ class BreakBlock( private fun SafeClientEvent.updateState() { getMiningSide(blockPos, BuildTools.maxReach)?.let { + /* prevent breaking the block the player is standing on */ + if (player.flooredPosition.down() == blockPos + && !world.getBlockState(blockPos.down()).isSideSolid(world, blockPos.down(), EnumFacing.UP) + ) { + action = BuildActivity.BuildAction.WRONG_POS_BREAK + distance = player.distanceTo(getHitVec(blockPos, it)) + return + } + if (action != BuildActivity.BuildAction.BREAKING) { action = BuildActivity.BuildAction.BREAK } @@ -232,6 +247,9 @@ class BreakBlock( if (player.capabilities.isCreativeMode) return true val currentState = world.getBlockState(blockPos) + + if (world.isAirBlock(blockPos)) return false + val currentDestroySpeed = player.heldItemMainhand.getDestroySpeed(currentState) player.inventorySlots.maxByOrNull { it.stack.getDestroySpeed(currentState) }?.let { @@ -294,11 +312,7 @@ class BreakBlock( .map { blockPos.offset(it) } .filter { world.getBlockState(it).isLiquid } .forEach { pos -> - // ToDo: Don't add if exists - PlaceBlock(pos, BuildTools.defaultFillerMat.defaultState).also { breakBlock -> - breakBlock.context = BuildActivity.BuildContext.LIQUID - addSubActivities(breakBlock) - } + addLiquidFill(pos) foundLiquid = true } @@ -314,6 +328,21 @@ class BreakBlock( ) ?: Items.AIR } + private fun SafeClientEvent.addLiquidFill(liquidPos: BlockPos) { + context = BuildActivity.BuildContext.LIQUID + + val available = player.inventorySlots + .filterByStack { BuildTools.ejectList.value.contains(it.item.block.registryName.toString()) } + .maxByOrNull { it.stack.count }?.stack?.item?.block ?: Blocks.AIR + + if (available == Blocks.AIR) { + failedWith(NoFillerMaterialFoundException()) + return + } + + addSubActivities(PlaceBlock(liquidPos, available.defaultState)) + } + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is PickUpDrops -> { @@ -341,4 +370,5 @@ class BreakBlock( class NoExposedSideFound : Exception("No exposed side found") class BlockBreakingException : Exception("Block breaking failed") class BlockOutsideOfBoundsException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") + class NoFillerMaterialFoundException: Exception("No filler material in inventory found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt index b2615de13..045e54e75 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt @@ -39,7 +39,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import kotlin.properties.Delegates class PlaceBlock( - private val blockPos: BlockPos, + val blockPos: BlockPos, private val targetState: IBlockState, private val ignoreProperties: Boolean = false, private val ignoreFacing: Boolean = false, @@ -52,7 +52,6 @@ class PlaceBlock( ) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { private var placeInfo: PlaceInfo? = null private var spoofedDirection = false - private var breakFirst = false override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> if (old == new) return@observable @@ -118,7 +117,7 @@ class PlaceBlock( ActivityManagerHud.totalBlocksPlaced++ success() - } else if (!breakFirst) { + } else { // failedWith(UnexpectedBlockStateException(blockPos, targetState, it.packet.blockState)) } } @@ -135,12 +134,8 @@ class PlaceBlock( checkPlace(placeInfo) } } - BuildActivity.BuildAction.WRONG_POS_PLACE -> { - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) - } else -> { - // ToDo: place neighbours -// failedWith(NoNeighbourException(blockPos)) + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) } } } @@ -158,11 +153,10 @@ class PlaceBlock( ) success() if (!currentState.isReplaceable - && currentState != targetState + && !isInDesiredState(currentState) && context != BuildActivity.BuildContext.PENDING - && !breakFirst + && subActivities.filterIsInstance().isEmpty() ) { - breakFirst = true addSubActivities( BreakBlock(blockPos), subscribe = true @@ -274,7 +268,7 @@ class PlaceBlock( addSubActivities(AcquireItemInActiveHand( optimalStack.item, - metadata = optimalStack.metadata + predicateStack = { optimalStack.metadata == it.metadata } )) return } @@ -282,7 +276,7 @@ class PlaceBlock( /* check if no entity collides */ if (!world.checkNoEntityCollision(targetState.getSelectedBoundingBox(world, blockPos), player)) { // ToDo: this only handles the case where the player is inside the block - addSubActivities(PlaceGoal(blockPos)) + if (autoPathing) addSubActivities(PlaceGoal(blockPos)) return } @@ -327,8 +321,6 @@ class PlaceBlock( // return // } - breakFirst = false - doPlace(placeInfo) } @@ -371,16 +363,8 @@ class PlaceBlock( override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - when (childActivity) { - is Rotate -> { - spoofedDirection = true - status = Status.UNINITIALIZED - } - else -> { - spoofedDirection = false - status = Status.UNINITIALIZED - } - } + spoofedDirection = childActivity is Rotate + status = Status.UNINITIALIZED } // override fun SafeClientEvent.onFailure(exception: Exception): Boolean { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index c9f65b98a..03c2035ec 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -4,6 +4,8 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.activity.activities.types.AttemptActivity +import com.lambda.client.activity.activities.utils.getShulkerInventory +import com.lambda.client.activity.activities.utils.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock @@ -11,66 +13,82 @@ import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.item import net.minecraft.init.Blocks +import net.minecraft.inventory.Slot import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack -import net.minecraft.util.EnumHand class AcquireItemInActiveHand( private val item: Item, - private val predicateItem: (ItemStack) -> Boolean = { true }, + private val predicateStack: (ItemStack) -> Boolean = { true }, private val predicateSlot: (ItemStack) -> Boolean = { true }, private var metadata: Int? = null, + private val amount: Int = 1, private val useShulkerBoxes: Boolean = true, private val useEnderChest: Boolean = false, override val maxAttempts: Int = 3, override var usedAttempts: Int = 0 ) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.hotbarSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) && (metadata == null || metadata == slot.stack.metadata) - }?.let { hotbarSlot -> - addSubActivities(SwitchToHotbarSlot(hotbarSlot)) - } ?: run { - if (pickBlock && player.capabilities.isCreativeMode) { - addSubActivities(CreativeInventoryAction( - ItemStack(item, 1, metadata ?: 0) + player.hotbarSlots.firstOrNull(slotFilterFunction(item, metadata, predicateStack))?.let { + addSubActivities(SwitchToHotbarSlot(it)) + return + } + + if (pickBlock && player.capabilities.isCreativeMode) { + addSubActivities(CreativeInventoryAction( + ItemStack(item, 1, metadata ?: 0) + )) + return + } + + player.allSlots.firstOrNull(slotFilterFunction(item, metadata, predicateStack))?.let { slotFrom -> + addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + return + } + + if (useShulkerBoxes && item !is ItemShulkerBox) { + val candidates = mutableMapOf() + + player.allSlots.forEach { slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val count = inventory.count { + item == it.item + && predicateStack(it) + && (metadata == null || metadata == it.metadata) + } + + if (count > 0) candidates[slot] = count + } + } + + candidates.minByOrNull { it.value }?.key?.let { slot -> + addSubActivities(ExtractItemFromShulkerBox( + slot.stack, item, predicateStack, predicateSlot, metadata, 1 )) return } + } - player.allSlots.firstOrNull { slot -> - slot.stack.item == item && predicateItem(slot.stack) && (metadata == null || metadata == slot.stack.metadata) - }?.let { slotFrom -> - addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) - } ?: run { - if (useShulkerBoxes) { - addSubActivities(ExtractItemFromShulkerBox(item, metadata, 1, predicateItem, predicateSlot)) - } else { - failedWith(NoItemFoundException(item, metadata)) - } - } + if (item == Blocks.OBSIDIAN.item) { + addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) + return } - } - override fun SafeClientEvent.onSuccess() { - val currentItem = player.getHeldItem(EnumHand.MAIN_HAND).item +// if (useEnderChest) { +// addSubActivities(ExtractItemFromEnderChest(item, 1, predicateItem, predicateSlot)) // ToDo: Add this +// return +// } - if (currentItem != item) { - failedWith(Exception("Failed to move item ${item.registryName} to hotbar (current item: ${currentItem.registryName})")) - } + failedWith(NoItemFoundException(item, metadata)) } - override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { - if (childException !is ExtractItemFromShulkerBox.NoShulkerBoxFoundExtractException) return false + override fun SafeClientEvent.onSuccess() { + val currentItemStack = player.heldItemMainhand - if (childException.item == Blocks.OBSIDIAN.item) { - addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) - return true + if (currentItemStack.item != item) { + failedWith(FailedToMoveItemException(item, metadata, currentItemStack)) } - -// addSubActivities(ExtractItemFromEnderChest(item, 1, predicateItem, predicateSlot)) // ToDo: Add this - - return false } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { @@ -79,5 +97,6 @@ class AcquireItemInActiveHand( status = Status.UNINITIALIZED } - class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${metadata?.let { ":$it" } ?: ""} found in inventory (shulkers are disabled)") + class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${metadata?.let { ":$it" } ?: ""} found in inventory") + class FailedToMoveItemException(item: Item, metadata: Int?, currentStack: ItemStack) : Exception("Failed to move ${item.registryName}${metadata?.let { ":$it" } ?: ""} to hotbar (current item: ${currentStack.item.registryName})") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 2d82659ae..cb70ec3ab 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -5,58 +5,36 @@ import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.utils.getShulkerInventory +import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.block -import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack class ExtractItemFromShulkerBox( + private val shulkerBoxStack: ItemStack, private val item: Item, + private val predicateStack: (ItemStack) -> Boolean = { true }, + private val predicateSlot: (ItemStack) -> Boolean = { true }, private var metadata: Int? = null, - private val amount: Int = 0, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true } + private val amount: Int = 0 // 0 = all ) : Activity() { - override fun SafeClientEvent.onInitialize() { - val candidates = mutableMapOf() - - // ToDo: move to acquire item in active hand - player.allSlots.forEach { slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - val count = inventory.count { it.item == item && predicateItem(it) && (metadata == null || metadata == it.metadata) } - - if (count > 0) candidates[slot] = count - } - } - - if (candidates.isEmpty()) { - failedWith(NoShulkerBoxFoundExtractException(item)) - return - } + private val stack = shulkerBoxStack.copy() - candidates.minBy { it.value }.key.let { slot -> - addSubActivities( - SwapOrSwitchToSlot(slot), - PlaceContainer(slot.stack.item.block.defaultState) - ) - } + override fun SafeClientEvent.onInitialize() { + addSubActivities( + PlaceContainer(stack, open = true) + ) } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { if (childActivity !is PlaceContainer) return addSubActivities( - OpenContainer(childActivity.containerPos), - PullItemsFromContainer(item, metadata, amount, predicateItem), + PullItemsFromContainer(item, predicateStack, metadata, amount), CloseContainer(), - BreakBlock(childActivity.containerPos, collectDrops = true), - AcquireItemInActiveHand(item, predicateItem, predicateSlot) + BreakBlock(childActivity.containerPos), + PickUpDrops(stack.item), // BreakBlock doesn't collect drops + AcquireItemInActiveHand(item, predicateStack, predicateSlot) ) } - - class NoShulkerBoxFoundExtractException(val item: Item) : Exception("No shulker box was found containing ${item.registryName}") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt deleted file mode 100644 index 1178e146a..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/OpenShulkerFromSlot.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.block -import net.minecraft.inventory.Slot -import net.minecraft.util.math.BlockPos - -class OpenShulkerFromSlot( - private val slot: Slot -) : Activity() { - var containerPos: BlockPos = BlockPos.ORIGIN - - override fun SafeClientEvent.onInitialize() { - val targetState = slot.stack.item.block.defaultState - - addSubActivities( - SwapOrSwitchToSlot(slot), - PlaceContainer(targetState) - ) - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is PlaceContainer) return - - containerPos = childActivity.containerPos - - addSubActivities( - OpenContainer(containerPos) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt index 593c475a6..84f313e3a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt @@ -1,31 +1,39 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.OpenContainer import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.types.AttemptActivity import com.lambda.client.activity.activities.utils.getContainerPos import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.block import net.minecraft.block.state.IBlockState +import net.minecraft.item.Item +import net.minecraft.item.ItemStack import net.minecraft.util.math.BlockPos class PlaceContainer( - private val targetState: IBlockState, + private val targetStack: ItemStack, + private val onlyItem: Boolean = false, + private val open: Boolean = false, override val maxAttempts: Int = 5, override var usedAttempts: Int = 0 ) : AttemptActivity, Activity() { var containerPos: BlockPos = BlockPos.ORIGIN override fun SafeClientEvent.onInitialize() { - containerPos = getContainerPos(targetState) ?: run { + containerPos = getContainerPos() ?: run { failedWith(NoContainerPlacePositionFoundException()) return } - addSubActivities(PlaceBlock( - containerPos, - targetState, - ignoreProperties = true - )) + addSubActivities( + AcquireItemInActiveHand(targetStack.item, { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) }), + PlaceBlock(containerPos, targetStack.item.block.defaultState, ignoreProperties = true) + ) + + if (open) addSubActivities(OpenContainer(containerPos)) } class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt index 0dff97dfd..e0464bac2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt @@ -3,23 +3,22 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.QuickMoveSlot import com.lambda.client.activity.activities.inventory.SwapWithSlot +import com.lambda.client.activity.activities.utils.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.getSlots import net.minecraft.inventory.Container -import net.minecraft.inventory.ContainerChest import net.minecraft.inventory.ContainerShulkerBox import net.minecraft.inventory.Slot -import net.minecraft.inventory.SlotShulkerBox import net.minecraft.item.Item import net.minecraft.item.ItemStack class PullItemsFromContainer( // ToDo: fix take for full inv private val item: Item, + private val predicateStack: (ItemStack) -> Boolean = { true }, private val metadata: Int? = null, private val amount: Int, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { val containerInventory: List @@ -36,40 +35,48 @@ class PullItemsFromContainer( // ToDo: fix take for full inv } } - val toMoveSlots = containerInventory.filter { slot -> - slot.stack.item == item - && predicateItem(slot.stack) - && (metadata == null || metadata == slot.stack.metadata) - } + val toMoveSlots = containerInventory.filter(slotFilterFunction(item, metadata, predicateStack)) if (toMoveSlots.isEmpty()) { - success() + failedWith(NoItemFoundException()) return } val remainingSlots = if (amount == 0) toMoveSlots else toMoveSlots.take(amount) + if (remainingSlots.isEmpty()) { + failedWith(NoSpaceLeftInInventoryException()) + return + } + remainingSlots.forEach { fromSlot -> if (playerInventory.countEmpty() > 0) { addSubActivities(QuickMoveSlot(fromSlot)) return@forEach } - playerInventory.firstOrNull { slot -> + val ejectableSlots = playerInventory.filter { slot -> BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) - }?.let { + } + + if (ejectableSlots.isEmpty()) { + failedWith(NoSpaceLeftInInventoryException()) + return@forEach + } + + ejectableSlots.firstOrNull()?.let { + // ToDo: Use proper slot reference val firstHotbarSlot = player.openContainer.inventorySlots[54].slotNumber addSubActivities( SwapWithSlot(it, firstHotbarSlot), SwapWithSlot(fromSlot, firstHotbarSlot) ) - } ?: run { - failedWith(NoSpaceLeftInInventoryException()) } } } class NoSpaceLeftInInventoryException : Exception("No space left in inventory") + class NoItemFoundException : Exception("No item found") class ContainerNotKnownException(val container: Container) : Exception("Container ${container::class.simpleName} not known") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 5a4011e02..9fa585fdf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -4,11 +4,9 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.CloseContainer import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot import com.lambda.client.activity.activities.utils.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.block import com.lambda.client.util.items.countItem import net.minecraft.inventory.Slot import net.minecraft.item.Item @@ -44,8 +42,7 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes candidates.maxBy { it.value }.key.let { slot -> addSubActivities( - SwapOrSwitchToSlot(slot), - PlaceContainer(slot.stack.item.block.defaultState) + PlaceContainer(slot.stack.copy(), open = true) ) } } @@ -54,7 +51,6 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes if (childActivity !is PlaceContainer) return addSubActivities( - OpenContainer(childActivity.containerPos), PushItemsToContainer(item, amount, predicateItem), CloseContainer(), BreakBlock(childActivity.containerPos, collectDrops = true) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 78da30946..4d9dd8d26 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem @@ -9,23 +10,30 @@ import net.minecraft.item.ItemStack class PickUpDrops( private val item: Item, + private val itemStack: ItemStack = ItemStack.EMPTY, private val predicate: (ItemStack) -> Boolean = { true }, private val maxRange: Float = 10.0f, private val minAmount: Int = 1, -) : Activity() { - override fun SafeClientEvent.onInitialize() { - val drops = world.loadedEntityList.filterIsInstance().filter { - it.item.item == item - && player.distanceTo(it.positionVector) < maxRange + override var currentLoops: Int = 0, +) : LoopWhileActivity, Activity() { + private val SafeClientEvent.drops get() = + world.loadedEntityList.filterIsInstance().filter { + player.distanceTo(it.positionVector) < maxRange + && it.item.item == item && predicate(it.item) + && if (itemStack != ItemStack.EMPTY) ItemStack.areItemStacksEqual(it.item, itemStack) else true } + override val loopWhile: SafeClientEvent.() -> Boolean = { + drops.isNotEmpty() + } + + override fun SafeClientEvent.onInitialize() { if (drops.isEmpty() || drops.sumOf { it.item.count } < minAmount) { success() - return } - drops.sortedBy { drop -> player.distanceTo(drop.positionVector) }.forEach { drop -> + drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> addSubActivities(PickUpEntityItem(drop)) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index eacec6396..1f5c9d8bc 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -22,7 +22,6 @@ class PickUpEntityItem( if (event.phase != TickEvent.Phase.START) return@safeListener if (!world.loadedEntityList.contains(entityItem)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(null) success() return@safeListener } @@ -38,15 +37,11 @@ class PickUpEntityItem( BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) }?.let { slot -> addSubActivities(DumpSlot(slot)) + return@safeListener } - } - } - override fun SafeClientEvent.onFailure(exception: Exception): Boolean { - if (exception !is TimeoutActivity.Companion.TimeoutException) return false - - onFailure(InventoryFullException()) - return true + onFailure(InventoryFullException()) + } } class InventoryFullException : Exception("No empty slots or items to dump!") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt index dd38cc7e8..8be389483 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt @@ -11,6 +11,7 @@ interface BuildActivity { RESTOCK(ColorHolder()), LIQUID(ColorHolder()), SUPPORT(ColorHolder()), + PICKUP(ColorHolder(252, 3, 207)), NONE(ColorHolder(0, 0, 0, 0)), PENDING(ColorHolder(11, 11, 175)) } @@ -20,10 +21,8 @@ interface BuildActivity { BREAK(ColorHolder(222, 0, 0)), PLACE(ColorHolder(35, 188, 254)), NEEDS_SUPPORT(ColorHolder(35, 15, 254)), - WRONG_POS_BREAK(ColorHolder(112, 0, 0)), - WRONG_POS_PLACE(ColorHolder(20, 108, 145)), -// INVALID_BREAK(ColorHolder(46, 0, 0)), -// INVALID_PLACE(ColorHolder(11, 55, 74)), + WRONG_POS_BREAK(ColorHolder(112, 0, 0, 0)), + WRONG_POS_PLACE(ColorHolder(20, 108, 145, 0)), INVALID_BREAK(ColorHolder(46, 0, 0, 0)), INVALID_PLACE(ColorHolder(11, 55, 74, 0)), NONE(ColorHolder(11, 11, 11)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt index e2ef14534..d6897ec5d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt @@ -7,8 +7,9 @@ import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.world.getVisibleSides import com.lambda.client.util.world.isPlaceable import com.lambda.client.util.world.isReplaceable -import net.minecraft.block.state.IBlockState import net.minecraft.inventory.ItemStackHelper +import net.minecraft.inventory.Slot +import net.minecraft.item.Item import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing @@ -31,7 +32,7 @@ fun getShulkerInventory(stack: ItemStack): NonNullList? { return shulkerInventory } -fun SafeClientEvent.getContainerPos(targetState: IBlockState): BlockPos? { +fun SafeClientEvent.getContainerPos(): BlockPos? { return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() .filter { pos -> // world.isPlaceable(pos, targetState.getSelectedBoundingBox(world, pos)) // TODO: Calculate correct resulting state of placed block to enable rotation checks @@ -56,4 +57,8 @@ fun SafeClientEvent.secureScore(pos: BlockPos): Int { if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ return safe +} + +val slotFilterFunction = { item: Item, metadata: Int?, predicateStack: (ItemStack) -> Boolean -> + { slot: Slot -> slot.stack.item == item && predicateStack(slot.stack) && (metadata == null || metadata == slot.stack.metadata) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 51d95821a..9674c7c5f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -11,7 +11,10 @@ import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.manager.Manager import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick +import com.lambda.client.module.modules.client.BuildTools.tickDelay import com.lambda.client.util.BaritoneUtils +import com.lambda.client.util.TickTimer +import com.lambda.client.util.TimeUnit import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent @@ -19,14 +22,15 @@ import net.minecraftforge.fml.common.gameevent.TickEvent object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() const val MAX_DEPTH = 25 + private val tickTimer = TickTimer(TimeUnit.TICKS) init { safeListener { event -> - if (hasNoSubActivities || event.phase != TickEvent.Phase.START) return@safeListener + if (hasNoSubActivities + || event.phase != TickEvent.Phase.START + ) return@safeListener - val allActivities = allSubActivities - - allActivities + allSubActivities .filter { it.status == Status.RUNNING && it.subActivities.isEmpty() } .forEach { with(it) { @@ -34,10 +38,10 @@ object ActivityManager : Manager, Activity() { } } + if (!tickTimer.tick(tickDelay * 1L)) return@safeListener + var lastActivity: Activity? = null -// BaritoneUtils.settings?.allowPlace?.value = false -// BaritoneUtils.settings?.allowBreak?.value = false BaritoneUtils.settings?.allowInventory?.value = false repeat(executionCountPerTick) { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 8afc08b9d..e2450b0e2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -1,5 +1,7 @@ package com.lambda.client.module.modules.client +import com.lambda.client.activity.Activity +import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting @@ -29,6 +31,7 @@ object BuildTools : Module( // if (it) BuildToolsManager.resetAll() // false // }) + val tickDelay by setting("Tick Delay", 0, 0..200, 1, { page == Page.BUILDING }) /* mining */ val breakDelay by setting("Break Delay", 1, 0..20, 1, { page == Page.BUILDING }, description = "Sets the delay ticks between break tasks", unit = " ticks") @@ -45,7 +48,7 @@ object BuildTools : Module( val placeStrictness by setting("Placement Strictness", PlacementStrictness.DIRECTION, { page == Page.BUILDING }, description = "ANY: Allow all exposed surfaces. DIRECTION: Only allow surfaces in the direction of the player. VISIBLE: Only allow surfaces that are visible to the player.") // val illegalPlacements by setting("Illegal Placements", false, { page == Page.BUILDING }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") // val doPending by setting("Do Pending", true, { page == Page.BUILDING }, description = "Do not wait for server to confirm action") - val executionCountPerTick by setting("Executions Per Tick", 20, 0..100, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") + val executionCountPerTick by setting("Executions Per Tick", ActivityManager.MAX_DEPTH, 0..ActivityManager.MAX_DEPTH * 2, 1, { page == Page.BUILDING }, description = "How many tasks to execute per tick") // val scaffold by setting("Scaffold", true, { page == Page.PLACING }, description = "Tries to bridge / scaffold when stuck placing") val placementSearch by setting("Place Deep Search", 1, 1..4, 1, { page == Page.BUILDING }, description = "EXPERIMENTAL: Attempts to find a support block for placing against", unit = " blocks") val directionForce by setting("Block Direction Exploit", true, { page == Page.BUILDING }, description = "EXPLOIT: Forces the direction of the block to be placed") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 71057b677..1c947460a 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -4,6 +4,7 @@ import com.lambda.client.activity.activities.example.SayAnnoyingly import com.lambda.client.activity.activities.highlevel.* import com.lambda.client.activity.activities.interaction.BreakBlock import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops @@ -22,6 +23,7 @@ import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos @@ -44,9 +46,9 @@ object TestActivityManager : Module( false }) - private val etit by setting("Extract Obby", false, consumer = { _, _-> + private val etit by setting("Acquire Obby", false, consumer = { _, _-> ActivityManager.addSubActivities( - ExtractItemFromShulkerBox(Blocks.OBSIDIAN.item) + AcquireItemInActiveHand(Blocks.OBSIDIAN.item) ) false }) @@ -139,6 +141,16 @@ object TestActivityManager : Module( false }) + private val ctiectiectiectieciec by setting("Pickup Dropped", false, consumer = { _, _-> + runSafe { + val stack = player.heldItemMainhand.copy() + + ActivityManager.addSubActivities(PickUpDrops(stack.item, stack)) + } + + false + }) + private val tiectie by setting("Surround me", false, consumer = { _, _-> runSafe { player.centerPlayer() diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index a470697bd..dcbaf9b75 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -3,8 +3,11 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.highlevel.ClearArea import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.manager.managers.ActivityManager.owner import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.safeListener import net.minecraft.util.EnumFacing @@ -34,22 +37,17 @@ object WorldEater : Module( private var secondPos: BlockPos? = null init { -// onEnable { -// runSafe { -// val currentDirection = player.horizontalFacing -// val pos1 = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) -// val pos2 = player.flooredPosition.add( -// currentDirection.directionVec.multiply(size) -// ).add( -// currentDirection.rotateY().directionVec.multiply(size) -// ).down(depth) -// -// BreakArea(pos1, pos2, layerSize).let { -// ownedBuildStructure = it -// ActivityManager.addSubActivities(it) -// } -// } -// } + onEnable { + runSafe { + val currentDirection = player.horizontalFacing + firstPos = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) + secondPos = player.flooredPosition.add( + currentDirection.directionVec.multiply(size) + ).add( + currentDirection.rotateY().directionVec.multiply(size) + ).down(depth) + } + } onDisable { runSafe { @@ -58,6 +56,7 @@ object WorldEater : Module( cancel() } } + ownedBuildStructure = null } } @@ -68,7 +67,7 @@ object WorldEater : Module( when (Mouse.getEventButton()) { 0 -> firstPos = result.blockPos 1 -> secondPos = result.blockPos - 2 -> clearArea() +// 2 -> if (ownedBuildStructure == null) clearArea() } } } @@ -83,7 +82,7 @@ object WorldEater : Module( second, layerSize, sliceSize, - ).let { + ).also { ownedBuildStructure = it ActivityManager.addSubActivities(it) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 3bff44aa2..9798f6c3d 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,7 +1,7 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.storage.OpenShulkerFromSlot +import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager @@ -25,8 +25,8 @@ object InventoryManagerTwo : Module( description = "Manages your inventory automatically", category = Category.PLAYER ) { - private val placedShulkerBoxes = ArrayDeque(mutableListOf()) - private val currentlyOpen: OpenShulkerFromSlot? = null + private val placedContainer = ArrayDeque(mutableListOf()) + private val currentlyOpen: PlaceContainer? = null init { safeListener { @@ -35,11 +35,7 @@ object InventoryManagerTwo : Module( player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener - val openShulkerFromSlot = OpenShulkerFromSlot(slot) - - placedShulkerBoxes.add(openShulkerFromSlot) - - ActivityManager.addSubActivities(openShulkerFromSlot) + ActivityManager.addSubActivities(PlaceContainer(slot.stack.copy(), open = true)) it.cancel() @@ -73,20 +69,20 @@ object InventoryManagerTwo : Module( } safeListener { - if (placedShulkerBoxes.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener + if (placedContainer.isEmpty() || it.phase != TickEvent.Phase.START) return@safeListener - val cloned = ArrayDeque(placedShulkerBoxes) + val cloned = ArrayDeque(placedContainer) - cloned.forEachIndexed { index, openShulker -> - if (index == 0 || openShulker.containerPos == BlockPos.ORIGIN) return@forEachIndexed - placedShulkerBoxes.remove(openShulker) + cloned.forEachIndexed { index, placeContainer -> + if (index == 0 || placeContainer.containerPos == BlockPos.ORIGIN) return@forEachIndexed + placedContainer.remove(placeContainer) - val currentBlock = world.getBlockState(openShulker.containerPos).block + val currentBlock = world.getBlockState(placeContainer.containerPos).block if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@forEachIndexed ActivityManager.addSubActivities( - BreakBlock(openShulker.containerPos, collectDrops = true) + BreakBlock(placeContainer.containerPos, collectDrops = true) ) } } @@ -94,15 +90,15 @@ object InventoryManagerTwo : Module( safeListener { if (!(it.screen is GuiShulkerBox || it.screen is GuiChest)) return@safeListener - placedShulkerBoxes.firstOrNull()?.let { openShulkerFromSlot -> - placedShulkerBoxes.remove(openShulkerFromSlot) + placedContainer.firstOrNull()?.let { placeContainer -> + placedContainer.remove(placeContainer) - val currentBlock = world.getBlockState(openShulkerFromSlot.containerPos).block + val currentBlock = world.getBlockState(placeContainer.containerPos).block if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener ActivityManager.addSubActivities( - BreakBlock(openShulkerFromSlot.containerPos, collectDrops = true) + BreakBlock(placeContainer.containerPos, collectDrops = true) ) } } From 1ea6db198e13c497290d168945d360964ce48a0b Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 12 Mar 2023 03:15:50 +0100 Subject: [PATCH 079/104] Clean up --- .../com/lambda/client/activity/Activity.kt | 22 +++-- .../lambda/client/activity/ActivityUtils.kt | 27 +++++++ .../BuildSchematic.kt | 3 +- .../{highlevel => construction}/ClearArea.kt | 5 +- .../SurroundWithObsidian.kt | 5 +- .../core}/BreakBlock.kt | 5 +- .../core}/BuildStructure.kt | 8 +- .../core}/PlaceBlock.kt | 6 +- .../activities/example/ListenAndWait.kt | 34 -------- .../activities/example/ProbablyFailing.kt | 15 ---- .../activities/example/SayAnnoyingly.kt | 12 --- .../activities/example/SayVeryAnnoyingly.kt | 12 --- .../activity/activities/example/WaitAndSay.kt | 16 ---- .../activity/activities/interaction/Rotate.kt | 2 +- .../interaction/UseThrowableOnEntity.kt | 6 +- .../crafting}/ReachXPLevel.kt | 4 +- .../inventory/AcquireItemInActiveHand.kt | 11 ++- .../activities/inventory/DumpInventory.kt | 15 ---- .../activity/activities/inventory/DumpSlot.kt | 1 + .../activities/inventory/SwapToBestTool.kt | 32 -------- .../activities/inventory/TakeOffArmor.kt | 1 + .../{ => core}/CreativeInventoryAction.kt | 4 +- .../{ => core}/InventoryTransaction.kt | 6 +- .../inventory/{ => core}/QuickMoveSlot.kt | 2 +- .../inventory/{ => core}/SwapHotbarSlots.kt | 2 +- .../{ => core}/SwapOrSwitchToSlot.kt | 2 +- .../inventory/{ => core}/SwapWithSlot.kt | 2 +- .../{ => core}/SwitchToHotbarSlot.kt | 2 +- .../BreakDownEnderChests.kt | 9 +-- .../storage/ExtractItemFromShulkerBox.kt | 5 +- .../activities/storage/PlaceContainer.kt | 40 --------- .../storage/StoreItemToShulkerBox.kt | 7 +- .../core}/CloseContainer.kt | 2 +- .../core}/OpenContainer.kt | 8 +- .../activities/storage/core/PlaceContainer.kt | 71 ++++++++++++++++ .../{ => core}/PullItemsFromContainer.kt | 8 +- .../{ => core}/PushItemsToContainer.kt | 4 +- .../activity/activities/travel/BreakGoal.kt | 2 +- .../activity/activities/travel/CustomGoal.kt | 2 +- .../activity/activities/travel/PickUpDrops.kt | 2 +- .../activities/travel/PickUpEntityItem.kt | 3 +- .../activity/activities/travel/PlaceGoal.kt | 2 +- .../activities/types/ConcurrentActivity.kt | 31 ------- .../activities/types/EndlessActivity.kt | 3 - .../types/RenderOverlayTextActivity.kt | 3 - .../activities/utils/ActivityUtils.kt | 64 --------------- .../activities/utils/VoxelShapeUtils.kt | 2 - .../client/activity/activities/utils/Wait.kt | 13 --- .../{activities => }/types/AttemptActivity.kt | 2 +- .../{activities => }/types/BuildActivity.kt | 8 +- .../{activities => }/types/DelayedActivity.kt | 2 +- .../types/LoopWhileActivity.kt | 2 +- .../types/RenderAABBActivity.kt | 2 +- .../types/RenderOverlayTextActivity.kt | 3 + .../types/RepeatingActivity.kt | 4 +- .../types/RotatingActivity.kt | 2 +- .../{activities => }/types/TimedActivity.kt | 2 +- .../{activities => }/types/TimeoutActivity.kt | 2 +- .../manager/managers/ActivityManager.kt | 8 +- .../module/modules/misc/HighwayTools.kt | 2 +- .../module/modules/misc/SchematicBuilder.kt | 3 +- .../modules/misc/TestActivityManager.kt | 81 ++----------------- .../client/module/modules/misc/WorldEater.kt | 3 +- .../modules/player/InventoryManagerTwo.kt | 2 +- 64 files changed, 206 insertions(+), 465 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => construction}/BuildSchematic.kt (93%) rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => construction}/ClearArea.kt (90%) rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => construction}/SurroundWithObsidian.kt (82%) rename src/main/kotlin/com/lambda/client/activity/activities/{interaction => construction/core}/BreakBlock.kt (98%) rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => construction/core}/BuildStructure.kt (93%) rename src/main/kotlin/com/lambda/client/activity/activities/{interaction => construction/core}/PlaceBlock.kt (98%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => interaction/crafting}/ReachXPLevel.kt (86%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/CreativeInventoryAction.kt (90%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/InventoryTransaction.kt (94%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/QuickMoveSlot.kt (94%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/SwapHotbarSlots.kt (88%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/SwapOrSwitchToSlot.kt (94%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/SwapWithSlot.kt (88%) rename src/main/kotlin/com/lambda/client/activity/activities/inventory/{ => core}/SwitchToHotbarSlot.kt (87%) rename src/main/kotlin/com/lambda/client/activity/activities/{highlevel => storage}/BreakDownEnderChests.kt (86%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt rename src/main/kotlin/com/lambda/client/activity/activities/{interaction => storage/core}/CloseContainer.kt (79%) rename src/main/kotlin/com/lambda/client/activity/activities/{interaction => storage/core}/OpenContainer.kt (90%) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ => core}/PullItemsFromContainer.kt (91%) rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ => core}/PushItemsToContainer.kt (91%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/AttemptActivity.kt (95%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/BuildActivity.kt (82%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/DelayedActivity.kt (89%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/LoopWhileActivity.kt (92%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/RenderAABBActivity.kt (97%) create mode 100644 src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/RepeatingActivity.kt (84%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/RotatingActivity.kt (91%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/TimedActivity.kt (52%) rename src/main/kotlin/com/lambda/client/activity/{activities => }/types/TimeoutActivity.kt (91%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index b66e9b536..f3b2b902f 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,16 +1,15 @@ package com.lambda.client.activity -import com.lambda.client.activity.activities.highlevel.BuildStructure -import com.lambda.client.activity.activities.types.AttemptActivity.Companion.checkAttempt -import com.lambda.client.activity.activities.types.BuildActivity -import com.lambda.client.activity.activities.types.DelayedActivity -import com.lambda.client.activity.activities.types.DelayedActivity.Companion.checkDelayed -import com.lambda.client.activity.activities.types.EndlessActivity -import com.lambda.client.activity.activities.types.LoopWhileActivity.Companion.checkLoopingUntil -import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender -import com.lambda.client.activity.activities.types.RepeatingActivity.Companion.checkRepeat -import com.lambda.client.activity.activities.types.RotatingActivity.Companion.checkRotating -import com.lambda.client.activity.activities.types.TimeoutActivity.Companion.checkTimeout +import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.activity.types.AttemptActivity.Companion.checkAttempt +import com.lambda.client.activity.types.BuildActivity +import com.lambda.client.activity.types.DelayedActivity +import com.lambda.client.activity.types.DelayedActivity.Companion.checkDelayed +import com.lambda.client.activity.types.LoopWhileActivity.Companion.checkLoopingUntil +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.RepeatingActivity.Companion.checkRepeat +import com.lambda.client.activity.types.RotatingActivity.Companion.checkRotating +import com.lambda.client.activity.types.TimeoutActivity.Companion.checkTimeout import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent @@ -92,7 +91,6 @@ abstract class Activity { Status.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) && hasNoSubActivities - && this@Activity !is EndlessActivity && this@Activity !is DelayedActivity ) success() } diff --git a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt new file mode 100644 index 000000000..90305ee86 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt @@ -0,0 +1,27 @@ +package com.lambda.client.activity + +import net.minecraft.inventory.ItemStackHelper +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox +import net.minecraft.item.ItemStack +import net.minecraft.util.NonNullList + +fun getShulkerInventory(stack: ItemStack): NonNullList? { + if (stack.item !is ItemShulkerBox) return null + + val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) + + stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { + if (it.hasKey("Items", 9)) { + ItemStackHelper.loadAllItems(it, shulkerInventory) + return shulkerInventory + } + } + + return shulkerInventory +} + +val slotFilterFunction = { item: Item, metadata: Int?, predicateStack: (ItemStack) -> Boolean -> + { slot: Slot -> item == slot.stack.item && predicateStack(slot.stack) && (metadata == null || metadata == slot.stack.metadata) } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/BuildSchematic.kt similarity index 93% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/BuildSchematic.kt index e4b66c546..9afe02dc7 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildSchematic.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/BuildSchematic.kt @@ -1,6 +1,7 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.construction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.construction.core.BuildStructure import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.Direction import com.lambda.client.util.schematic.LambdaSchematicaHelper diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt similarity index 90% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 0714a9746..838290502 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -1,7 +1,8 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.construction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RenderAABBActivity +import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.color.ColorHolder import net.minecraft.block.state.IBlockState diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/SurroundWithObsidian.kt similarity index 82% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/SurroundWithObsidian.kt index 58b4e3c14..74fa08abf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/SurroundWithObsidian.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/SurroundWithObsidian.kt @@ -1,7 +1,8 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.construction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopWhileActivity +import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import net.minecraft.block.state.IBlockState diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt similarity index 98% rename from src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index c7f3ca55f..3edbee4ab 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -1,11 +1,12 @@ -package com.lambda.client.activity.activities.interaction +package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.activities.types.* +import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt similarity index 93% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 93bc5f1ca..e5da6c24e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -1,10 +1,8 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.types.BuildActivity -import com.lambda.client.activity.activities.types.RepeatingActivity +import com.lambda.client.activity.types.BuildActivity +import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt similarity index 98% rename from src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt rename to src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 045e54e75..d3506582a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -1,9 +1,11 @@ -package com.lambda.client.activity.activities.interaction +package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.activities.types.* +import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud @@ -274,7 +276,7 @@ class PlaceBlock( } /* check if no entity collides */ - if (!world.checkNoEntityCollision(targetState.getSelectedBoundingBox(world, blockPos), player)) { + if (!world.checkNoEntityCollision(targetState.getSelectedBoundingBox(world, blockPos), null)) { // ToDo: this only handles the case where the player is inside the block if (autoPathing) addSubActivities(PlaceGoal(blockPos)) return diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt deleted file mode 100644 index 4359a4e06..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ListenAndWait.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.lambda.client.activity.activities.example - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.graphics.font.TextComponent -import com.lambda.client.util.text.MessageSendHelper -import com.lambda.client.util.threads.safeListener -import net.minecraftforge.fml.common.gameevent.TickEvent - -class ListenAndWait( - private val message: String, - override val timeout: Long -) : TimeoutActivity, Activity() { - init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - MessageSendHelper.sendChatMessage(message) - } - } - - override fun SafeClientEvent.onFailure(exception: Exception) = - if (exception is TimeoutActivity.Companion.TimeoutException) { - success() - true - } else false - - override fun addExtraInfo(textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder) { - textComponent.add("Age", primaryColor) - textComponent.add(age.toString(), secondaryColor) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt deleted file mode 100644 index 44bdac2a8..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/ProbablyFailing.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.lambda.client.activity.activities.example - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import kotlin.random.Random - -class ProbablyFailing : Activity() { - override fun SafeClientEvent.onInitialize() { - if (Random.nextBoolean()) { - success() - } else { - failedWith(Exception("Randomly failed")) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt deleted file mode 100644 index fbe48b267..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayAnnoyingly.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lambda.client.activity.activities.example - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent - -class SayAnnoyingly(private val message: String) : Activity() { - override fun SafeClientEvent.onInitialize() { - message.split(" ").forEach { - addSubActivities(SayVeryAnnoyingly(it)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt deleted file mode 100644 index 429eab227..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/SayVeryAnnoyingly.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.lambda.client.activity.activities.example - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent - -class SayVeryAnnoyingly(private val message: String) : Activity() { - override fun SafeClientEvent.onInitialize() { - message.forEach { - addSubActivities(ListenAndWait(it.toString(), 250)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt b/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt deleted file mode 100644 index f76025ad8..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/example/WaitAndSay.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.lambda.client.activity.activities.example - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.DelayedActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.text.MessageSendHelper - -class WaitAndSay( - private val message: String, - override val delay: Long = 1000L -) : DelayedActivity, Activity() { - override fun SafeClientEvent.onDelayedActivity() { - MessageSendHelper.sendChatMessage(message) - success() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt index d05622f98..1b313cfff 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/Rotate.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt index 7273fec74..0b1d6acd8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/UseThrowableOnEntity.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.RotatingActivity +import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.RotationUtils.getRotationToEntity import com.lambda.client.util.math.Vec2f @@ -13,7 +13,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent class UseThrowableOnEntity( private val targetEntity: Entity, - private val amount: Int = 1, + private val uses: Int = 1, private val useHand: EnumHand = EnumHand.MAIN_HAND, override var rotation: Vec2f? = null, ) : RotatingActivity, Activity() { @@ -33,7 +33,7 @@ class UseThrowableOnEntity( used++ - if (used == amount) success() + if (used == uses) success() } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt similarity index 86% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt rename to src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt index d46a375d5..3d77a9fc8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt @@ -1,10 +1,10 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.interaction.crafting import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor -import com.lambda.client.activity.activities.types.LoopWhileActivity +import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 03c2035ec..9eacc0655 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -1,11 +1,14 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.highlevel.BreakDownEnderChests +import com.lambda.client.activity.activities.inventory.core.CreativeInventoryAction +import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot +import com.lambda.client.activity.activities.storage.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.utils.getShulkerInventory -import com.lambda.client.activity.activities.utils.slotFilterFunction +import com.lambda.client.activity.types.AttemptActivity +import com.lambda.client.activity.getShulkerInventory +import com.lambda.client.activity.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt deleted file mode 100644 index 39249c8d7..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpInventory.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.lambda.client.activity.activities.inventory - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.allSlots - -class DumpInventory : Activity() { - override fun SafeClientEvent.onInitialize() { - player.allSlots - .filter { it.hasStack } - .forEach { - addSubActivities(DumpSlot(it)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt index a27bb4aec..1ecfe1182 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/DumpSlot.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.core.InventoryTransaction import com.lambda.client.event.SafeClientEvent import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt deleted file mode 100644 index 45aed5f8b..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapToBestTool.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.lambda.client.activity.activities.inventory - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.allSlots -import net.minecraft.enchantment.EnchantmentHelper -import net.minecraft.init.Enchantments -import net.minecraft.util.math.BlockPos - -class SwapToBestTool(private val blockPos: BlockPos) : Activity() { - override fun SafeClientEvent.onInitialize() { - player.allSlots.asReversed().maxByOrNull { - val stack = it.stack - if (stack.isEmpty) { - 0.0f - } else { - var speed = stack.getDestroySpeed(world.getBlockState(blockPos)) - - if (speed > 1.0f) { - val efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack) - if (efficiency > 0) { - speed += efficiency * efficiency + 1.0f - } - } - - speed - } - }?.let { bestSlot -> - addSubActivities(SwapOrSwitchToSlot(bestSlot)) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt index 1796c80e9..952ddb8d4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/TakeOffArmor.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.inventory import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.armorSlots import com.lambda.client.util.items.offhandSlot diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/CreativeInventoryAction.kt similarity index 90% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/CreativeInventoryAction.kt index a574b4bee..d20503eaa 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/CreativeInventoryAction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/CreativeInventoryAction.kt @@ -1,7 +1,7 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.threads.defaultScope diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/InventoryTransaction.kt similarity index 94% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/InventoryTransaction.kt index 2c772c80a..a47f3993e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/InventoryTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/InventoryTransaction.kt @@ -1,8 +1,8 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.AttemptActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.threads.defaultScope diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/QuickMoveSlot.kt similarity index 94% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/QuickMoveSlot.kt index 75cf2246a..7a6c76b55 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/QuickMoveSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/QuickMoveSlot.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapHotbarSlots.kt similarity index 88% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapHotbarSlots.kt index 819dff237..ad91cc47c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapHotbarSlots.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapHotbarSlots.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt similarity index 94% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt index 2e27ffbbc..c60f8e6a6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapWithSlot.kt similarity index 88% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapWithSlot.kt index 9a0bdb2b8..daec5636e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwapWithSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapWithSlot.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwitchToHotbarSlot.kt similarity index 87% rename from src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt rename to src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwitchToHotbarSlot.kt index c69dcf124..a6dbc89ad 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/SwitchToHotbarSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwitchToHotbarSlot.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.inventory +package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt similarity index 86% rename from src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt index fb9a81ec0..660d13a88 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/highlevel/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt @@ -1,11 +1,10 @@ -package com.lambda.client.activity.activities.highlevel +package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.PlaceContainer -import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox -import com.lambda.client.activity.activities.types.RepeatingActivity +import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countItem diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index cb70ec3ab..5d06e7eed 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -1,10 +1,9 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.OpenContainer +import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.storage.core.CloseContainer import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent import net.minecraft.item.Item diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt deleted file mode 100644 index 84f313e3a..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PlaceContainer.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.interaction.PlaceBlock -import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.utils.getContainerPos -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.block -import net.minecraft.block.state.IBlockState -import net.minecraft.item.Item -import net.minecraft.item.ItemStack -import net.minecraft.util.math.BlockPos - -class PlaceContainer( - private val targetStack: ItemStack, - private val onlyItem: Boolean = false, - private val open: Boolean = false, - override val maxAttempts: Int = 5, - override var usedAttempts: Int = 0 -) : AttemptActivity, Activity() { - var containerPos: BlockPos = BlockPos.ORIGIN - - override fun SafeClientEvent.onInitialize() { - containerPos = getContainerPos() ?: run { - failedWith(NoContainerPlacePositionFoundException()) - return - } - - addSubActivities( - AcquireItemInActiveHand(targetStack.item, { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) }), - PlaceBlock(containerPos, targetStack.item.block.defaultState, ignoreProperties = true) - ) - - if (open) addSubActivities(OpenContainer(containerPos)) - } - - class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 9fa585fdf..04b7e7e2a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -1,10 +1,9 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.CloseContainer -import com.lambda.client.activity.activities.interaction.OpenContainer -import com.lambda.client.activity.activities.utils.getShulkerInventory +import com.lambda.client.activity.activities.construction.core.BreakBlock +import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countItem diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/CloseContainer.kt similarity index 79% rename from src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/CloseContainer.kt index 50a9c9adc..fdd575505 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/CloseContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/CloseContainer.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.interaction +package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/OpenContainer.kt similarity index 90% rename from src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/OpenContainer.kt index e37059e96..54b032e11 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/OpenContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/OpenContainer.kt @@ -1,9 +1,9 @@ -package com.lambda.client.activity.activities.interaction +package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.AttemptActivity -import com.lambda.client.activity.activities.types.RotatingActivity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.AttemptActivity +import com.lambda.client.activity.types.RotatingActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.util.math.RotationUtils.getRotationTo diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt new file mode 100644 index 000000000..695112dcf --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt @@ -0,0 +1,71 @@ +package com.lambda.client.activity.activities.storage.core + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.construction.core.PlaceBlock +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.types.AttemptActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.items.block +import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.world.getVisibleSides +import com.lambda.client.util.world.isPlaceable +import com.lambda.client.util.world.isReplaceable +import net.minecraft.item.ItemStack +import net.minecraft.util.EnumFacing +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos + +class PlaceContainer( + private val targetStack: ItemStack, + private val onlyItem: Boolean = false, + private val open: Boolean = false, + override val maxAttempts: Int = 5, + override var usedAttempts: Int = 0 +) : AttemptActivity, Activity() { + var containerPos: BlockPos = BlockPos.ORIGIN + + override fun SafeClientEvent.onInitialize() { + containerPos = getContainerPos() ?: run { + failedWith(NoContainerPlacePositionFoundException()) + return + } + + addSubActivities( + AcquireItemInActiveHand(targetStack.item, { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) }), + PlaceBlock(containerPos, targetStack.item.block.defaultState, ignoreProperties = true) + ) + + if (open) addSubActivities(OpenContainer(containerPos)) + } + + private fun SafeClientEvent.getContainerPos(): BlockPos? { + return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() + .filter { pos -> +// world.isPlaceable(pos, targetState.getSelectedBoundingBox(world, pos)) // TODO: Calculate correct resulting state of placed block to enable rotation checks + world.isPlaceable(pos, AxisAlignedBB(pos)) + && !world.getBlockState(pos.down()).isReplaceable + && world.isAirBlock(pos.up()) + && getVisibleSides(pos.down()).contains(EnumFacing.UP) + && pos.y >= player.flooredPosition.y + }.sortedWith( + compareByDescending { + secureScore(it) + }.thenBy { + player.positionVector.distanceTo(it.toVec3dCenter()) + } + ).firstOrNull() + } + + private fun SafeClientEvent.secureScore(pos: BlockPos): Int { + var safe = 0 + if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ + if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ + return safe + } + + class NoContainerPlacePositionFoundException : Exception("No position to place a container was found") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt index e0464bac2..8a42ade08 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt @@ -1,9 +1,9 @@ -package com.lambda.client.activity.activities.storage +package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.QuickMoveSlot -import com.lambda.client.activity.activities.inventory.SwapWithSlot -import com.lambda.client.activity.activities.utils.slotFilterFunction +import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot +import com.lambda.client.activity.activities.inventory.core.SwapWithSlot +import com.lambda.client.activity.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt index b9590360c..316372e35 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/PushItemsToContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt @@ -1,7 +1,7 @@ -package com.lambda.client.activity.activities.storage +package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.QuickMoveSlot +import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.getSlots import net.minecraft.item.Item diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt index dd0e5c1c0..495493310 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt @@ -4,7 +4,7 @@ import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalInverted import baritone.process.BuilderProcess.GoalBreak import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index e57f23a49..0821aa08d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.Goal import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt index 4d9dd8d26..362ed9b9a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt @@ -1,7 +1,7 @@ package com.lambda.client.activity.activities.travel import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.LoopWhileActivity +import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.entity.item.EntityItem diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt index 1f5c9d8bc..9b0ef6c43 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt @@ -3,8 +3,7 @@ package com.lambda.client.activity.activities.travel import baritone.api.pathing.goals.GoalBlock import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.DumpSlot -import com.lambda.client.activity.activities.types.TimeoutActivity -import com.lambda.client.event.SafeClientEvent +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.items.countEmpty diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt index 31ac650be..03bce9651 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt @@ -5,7 +5,7 @@ import baritone.api.pathing.goals.GoalInverted import baritone.api.pathing.goals.GoalNear import baritone.process.BuilderProcess import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.TimeoutActivity +import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.BaritoneUtils diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt deleted file mode 100644 index 5c79a98b2..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/ConcurrentActivity.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.lambda.client.activity.activities.types - -import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent - -interface ConcurrentActivity { - val maxInstancesPerTick: Int - var currentInstances: Int - val root: Activity - - companion object { - fun SafeClientEvent.doConcurrent(activity: Activity): Boolean { - if (activity !is ConcurrentActivity) return false - - with(activity) { - if (currentInstances >= maxInstancesPerTick) return false - currentInstances++ -// root.refresh(activity.owner.owner) - root.addSubActivities(activity) - } - return true - } - - fun SafeClientEvent.checkConcurrent(activity: Activity): Boolean { - if (activity !is ConcurrentActivity) return false - - activity.currentInstances = 0 - return true - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt deleted file mode 100644 index eb5495828..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/EndlessActivity.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.lambda.client.activity.activities.types - -interface EndlessActivity \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt deleted file mode 100644 index 29d89633b..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderOverlayTextActivity.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.lambda.client.activity.activities.types - -interface RenderOverlayTextActivity \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt deleted file mode 100644 index d6897ec5d..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/ActivityUtils.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.lambda.client.activity.activities.utils - -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.math.VectorUtils -import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import com.lambda.client.util.world.getVisibleSides -import com.lambda.client.util.world.isPlaceable -import com.lambda.client.util.world.isReplaceable -import net.minecraft.inventory.ItemStackHelper -import net.minecraft.inventory.Slot -import net.minecraft.item.Item -import net.minecraft.item.ItemShulkerBox -import net.minecraft.item.ItemStack -import net.minecraft.util.EnumFacing -import net.minecraft.util.NonNullList -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos - -fun getShulkerInventory(stack: ItemStack): NonNullList? { - if (stack.item !is ItemShulkerBox) return null - - val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) - - stack.tagCompound?.getCompoundTag("BlockEntityTag")?.let { - if (it.hasKey("Items", 9)) { - ItemStackHelper.loadAllItems(it, shulkerInventory) - return shulkerInventory - } - } - - return shulkerInventory -} - -fun SafeClientEvent.getContainerPos(): BlockPos? { - return VectorUtils.getBlockPosInSphere(player.positionVector, 4.25f).asSequence() - .filter { pos -> -// world.isPlaceable(pos, targetState.getSelectedBoundingBox(world, pos)) // TODO: Calculate correct resulting state of placed block to enable rotation checks - world.isPlaceable(pos, AxisAlignedBB(pos)) - && !world.getBlockState(pos.down()).isReplaceable - && world.isAirBlock(pos.up()) - && getVisibleSides(pos.down()).contains(EnumFacing.UP) - && pos.y >= player.flooredPosition.y - }.sortedWith( - compareByDescending { - secureScore(it) - }.thenBy { - player.positionVector.distanceTo(it.toVec3dCenter()) - } - ).firstOrNull() -} - -fun SafeClientEvent.secureScore(pos: BlockPos): Int { - var safe = 0 - if (!world.getBlockState(pos.down().north()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().east()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().south()).isReplaceable) safe++ - if (!world.getBlockState(pos.down().west()).isReplaceable) safe++ - return safe -} - -val slotFilterFunction = { item: Item, metadata: Int?, predicateStack: (ItemStack) -> Boolean -> - { slot: Slot -> slot.stack.item == item && predicateStack(slot.stack) && (metadata == null || metadata == slot.stack.metadata) } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt deleted file mode 100644 index f33b95ead..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/VoxelShapeUtils.kt +++ /dev/null @@ -1,2 +0,0 @@ -package com.lambda.client.activity.activities.utils - diff --git a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt b/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt deleted file mode 100644 index 1fcd8159d..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/utils/Wait.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.lambda.client.activity.activities.utils - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.DelayedActivity -import com.lambda.client.event.SafeClientEvent - -class Wait( - override val delay: Long -) : DelayedActivity, Activity() { - override fun SafeClientEvent.onDelayedActivity() { - success() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/AttemptActivity.kt similarity index 95% rename from src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/AttemptActivity.kt index b5989bb4e..bfad7aaff 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/AttemptActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/AttemptActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt similarity index 82% rename from src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt index 8be389483..18a62c662 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.util.color.ColorHolder @@ -8,9 +8,9 @@ interface BuildActivity { var distance: Double enum class BuildContext(val color: ColorHolder) { - RESTOCK(ColorHolder()), - LIQUID(ColorHolder()), - SUPPORT(ColorHolder()), + RESTOCK(ColorHolder(3, 252, 169)), + LIQUID(ColorHolder(114, 27, 255)), + SUPPORT(ColorHolder(16, 74, 94)), PICKUP(ColorHolder(252, 3, 207)), NONE(ColorHolder(0, 0, 0, 0)), PENDING(ColorHolder(11, 11, 175)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/DelayedActivity.kt similarity index 89% rename from src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/DelayedActivity.kt index 9245cf76f..3845a2f88 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/DelayedActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/DelayedActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt similarity index 92% rename from src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt index 08ca1e53c..fdd1e5026 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/LoopWhileActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt similarity index 97% rename from src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt index 721e6611c..1a383b9bd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RenderAABBActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager diff --git a/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt new file mode 100644 index 000000000..b5aef815c --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt @@ -0,0 +1,3 @@ +package com.lambda.client.activity.types + +interface RenderOverlayTextActivity \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt similarity index 84% rename from src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt index b5337f689..0eda1691b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RepeatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent @@ -8,7 +8,7 @@ interface RepeatingActivity { var repeated: Int companion object { - fun SafeClientEvent.checkRepeat(activity: Activity) { + fun checkRepeat(activity: Activity) { if (activity !is RepeatingActivity) return with(activity) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RotatingActivity.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/RotatingActivity.kt index e93cce7c4..1152b59bd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/RotatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RotatingActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.activity.Activity import com.lambda.client.manager.managers.PlayerPacketManager diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/TimedActivity.kt similarity index 52% rename from src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/TimedActivity.kt index 607df2469..d1fe6ae32 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimedActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/TimedActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types interface TimedActivity { var earliestFinish: Long diff --git a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/TimeoutActivity.kt similarity index 91% rename from src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt rename to src/main/kotlin/com/lambda/client/activity/types/TimeoutActivity.kt index 25b207f40..c48ed9848 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/types/TimeoutActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/TimeoutActivity.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.types +package com.lambda.client.activity.types import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 9674c7c5f..d93ddcee3 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,10 +1,10 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.types.BuildActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity -import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender -import com.lambda.client.activity.activities.types.TimedActivity +import com.lambda.client.activity.types.BuildActivity +import com.lambda.client.activity.types.RenderAABBActivity +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.TimedActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.events.RenderWorldEvent diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 708b43069..66218faa2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -1,6 +1,6 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.activity.activities.highlevel.BuildStructure +import com.lambda.client.activity.activities.construction.core.BuildStructure import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt index 876aa7ba1..fd966b197 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -1,9 +1,8 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.activity.activities.highlevel.BuildSchematic +import com.lambda.client.activity.activities.construction.BuildSchematic import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.ActivityManager.cancel import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.math.Direction diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 1c947460a..f50954d41 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,14 +1,13 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.activity.activities.example.SayAnnoyingly -import com.lambda.client.activity.activities.highlevel.* -import com.lambda.client.activity.activities.interaction.BreakBlock -import com.lambda.client.activity.activities.interaction.PlaceBlock +import com.lambda.client.activity.activities.construction.SurroundWithObsidian +import com.lambda.client.activity.activities.construction.core.PlaceBlock +import com.lambda.client.activity.activities.interaction.crafting.ReachXPLevel import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.storage.BreakDownEnderChests import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category @@ -16,16 +15,12 @@ import com.lambda.client.module.Module import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.MovementUtils.centerPlayer import com.lambda.client.util.items.item -import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal -import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks -import net.minecraft.item.ItemStack import net.minecraft.util.EnumFacing -import net.minecraft.util.math.BlockPos object TestActivityManager : Module( name = "TestActivityManager", @@ -53,50 +48,6 @@ object TestActivityManager : Module( false }) - private val ectiecti by setting("Break Place", false, consumer = { _, _-> - runSafe { - val currentDirection = player.horizontalFacing - val pos = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) - -// val targetState = Blocks.QUARTZ_BLOCK.defaultState -// .withProperty(BlockQuartz.VARIANT, BlockQuartz.EnumType.LINES_X) - - val targetState = Blocks.ENDER_CHEST.defaultState - - ActivityManager.addSubActivities( - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos), - PlaceBlock(pos, targetState), - BreakBlock(pos) - ) - } - false - }) - private val eticiettie by setting("Direction shenanigans", false, consumer = { _, _-> runSafe { var currentDirection = player.horizontalFacing @@ -151,7 +102,7 @@ object TestActivityManager : Module( false }) - private val tiectie by setting("Surround me", false, consumer = { _, _-> + private val tiectie by setting("Surround", false, consumer = { _, _-> runSafe { player.centerPlayer() ActivityManager.addSubActivities( @@ -161,26 +112,6 @@ object TestActivityManager : Module( false }) - private val citectie by setting("Clear out", false, consumer = { _, _-> - runSafe { - val structure = mutableMapOf() - - VectorUtils.getBlockPosInSphere(player.positionVector, 3.0f).forEach { - if (it.up() != player.flooredPosition) structure[it] = Blocks.AIR.defaultState - } - - ActivityManager.addSubActivities( - BuildStructure(structure) - ) - } - false - }) - - private val sayHelloWorld by setting("Hello World", false, consumer = { _, _-> - ActivityManager.addSubActivities(SayAnnoyingly("Hello World")) - false - }) - val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> ActivityManager.addSubActivities(ReachXPLevel(30)) false diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index dcbaf9b75..0d8195cfe 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,9 +1,8 @@ package com.lambda.client.module.modules.misc -import com.lambda.client.activity.activities.highlevel.ClearArea +import com.lambda.client.activity.activities.construction.ClearArea import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities -import com.lambda.client.manager.managers.ActivityManager.owner import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.EntityUtils.flooredPosition diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index 9798f6c3d..e3fa41735 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,6 +1,6 @@ package com.lambda.client.module.modules.player -import com.lambda.client.activity.activities.interaction.BreakBlock +import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.storage.PlaceContainer import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent From 20cf1373827669da9d7f71313a918590c5d84071 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 12 Mar 2023 03:59:00 +0100 Subject: [PATCH 080/104] Multi module support --- .../com/lambda/client/activity/Activity.kt | 28 +++++++++++++------ .../activities/construction/ClearArea.kt | 3 +- .../construction/core/BreakBlock.kt | 1 - .../construction/core/PlaceBlock.kt | 1 - .../storage/ExtractItemFromShulkerBox.kt | 2 ++ .../storage/StoreItemToShulkerBox.kt | 2 ++ .../activity/types/LoopWhileActivity.kt | 2 +- .../activity/types/RepeatingActivity.kt | 3 +- .../manager/managers/ActivityManager.kt | 9 ++++-- .../module/modules/misc/HighwayTools.kt | 3 +- .../module/modules/misc/SchematicBuilder.kt | 2 +- .../modules/misc/TestActivityManager.kt | 18 ++++++------ .../client/module/modules/misc/WorldEater.kt | 4 ++- .../modules/player/InventoryManagerTwo.kt | 8 +++--- 14 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index f3b2b902f..b82690fae 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -16,6 +16,7 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH +import com.lambda.client.module.AbstractModule import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.font.TextComponent @@ -32,7 +33,8 @@ abstract class Activity { val subActivities = ArrayDeque() var status = Status.UNINITIALIZED private var creationTime = 0L - var owner: Activity? = null + var parent: Activity? = null + var owner: AbstractModule? = null var depth = 0 open fun SafeClientEvent.onInitialize() {} @@ -72,7 +74,7 @@ abstract class Activity { get() = run { val activities = mutableListOf() - owner?.let { + parent?.let { activities.add(this) } @@ -130,7 +132,7 @@ abstract class Activity { LambdaEventBus.unsubscribe(activity) ListenerManager.unregister(activity) - owner?.let { + parent?.let { with(it) { onChildSuccess(activity) subActivities.remove(activity) @@ -154,7 +156,7 @@ abstract class Activity { if (onFailure(exception)) return - owner?.let { + parent?.let { with(it) { if (childFailure(ArrayDeque(listOf(activity)), exception)) return } @@ -182,7 +184,7 @@ abstract class Activity { } } - owner?.let { + parent?.let { with(it) { LambdaEventBus.unsubscribe(activity) ListenerManager.unregister(activity) @@ -202,7 +204,7 @@ abstract class Activity { } childActivities.add(this@Activity) - owner?.let { + parent?.let { with(it) { childFailure(childActivities, childException) } @@ -211,7 +213,7 @@ abstract class Activity { return false } - fun Activity.addSubActivities(activities: List, subscribe: Boolean = false) { + fun Activity.addSubActivities(activities: List, subscribe: Boolean = false, module: AbstractModule? = null) { if (activities.isEmpty()) return if (depth > MAX_DEPTH) { @@ -221,7 +223,8 @@ abstract class Activity { } activities.forEach { activity -> - activity.owner = this + activity.parent = this + activity.owner = module activity.depth = depth + 1 if (subscribe) LambdaEventBus.subscribe(activity) } @@ -235,6 +238,10 @@ abstract class Activity { addSubActivities(activities.toList(), subscribe) } + fun AbstractModule.addSubActivities(vararg activities: Activity, subscribe: Boolean = false) { + addSubActivities(activities.toList(), subscribe, this) + } + enum class Status { RUNNING, UNINITIALIZED @@ -249,6 +256,11 @@ abstract class Activity { textComponent.add("ASYNC", primaryColor) } + owner?.let { + textComponent.add("Module", secondaryColor) + textComponent.add(it.name, primaryColor) + } + textComponent.add("Name", secondaryColor) textComponent.add("${javaClass.simpleName} ", primaryColor) textComponent.add("State", secondaryColor) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 838290502..70515946d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -17,6 +17,7 @@ class ClearArea( private val layerSize: Int = 1, private val sliceSize: Int = 1, private val sliceDirection: EnumFacing = EnumFacing.NORTH, + private val collectAll: Boolean = false, override val toRender: MutableSet = mutableSetOf() ) : RenderAABBActivity, Activity() { private val minX = minOf(pos1.x, pos2.x) @@ -50,7 +51,7 @@ class ClearArea( if (y.mod(layerSize) == 0 || y == layers.last) { addSubActivities( - BuildStructure(structure.toMap(), collectAll = true) + BuildStructure(structure.toMap(), collectAll = collectAll) ) structure.clear() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 3edbee4ab..158b58052 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -5,7 +5,6 @@ import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.activities.types.* import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index d3506582a..999a5aeaa 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -4,7 +4,6 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.travel.PlaceGoal -import com.lambda.client.activity.activities.types.* import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 5d06e7eed..47bea9618 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -4,6 +4,8 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.activities.storage.core.PullItemsFromContainer import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent import net.minecraft.item.Item diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 04b7e7e2a..ddb9b3856 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -3,6 +3,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.activities.storage.core.PushItemsToContainer import com.lambda.client.activity.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots diff --git a/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt index fdd1e5026..21c03d4f1 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/LoopWhileActivity.kt @@ -16,7 +16,7 @@ interface LoopWhileActivity { currentLoops++ status = Activity.Status.UNINITIALIZED - owner?.subActivities?.add(activity) + parent?.subActivities?.add(activity) // LambdaMod.LOG.info("Looping $name ($currentLoops)") } } diff --git a/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt index 0eda1691b..8f6298850 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt @@ -1,7 +1,6 @@ package com.lambda.client.activity.types import com.lambda.client.activity.Activity -import com.lambda.client.event.SafeClientEvent interface RepeatingActivity { val maximumRepeats: Int @@ -15,7 +14,7 @@ interface RepeatingActivity { if (repeated++ >= maximumRepeats && maximumRepeats != 0) return status = Activity.Status.UNINITIALIZED - owner?.subActivities?.add(activity) + parent?.subActivities?.add(activity) // LambdaMod.LOG.info("Looping $name [$currentLoops/${if (maxLoops == 0) "∞" else maxLoops}] ") } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index d93ddcee3..33b0e9638 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,7 +1,6 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.activity.types.TimedActivity @@ -76,15 +75,19 @@ object ActivityManager : Manager, Activity() { } } + override fun getCurrentActivity(): Activity { + return subActivities.maxByOrNull { it.owner?.modulePriority ?: 0 }?.getCurrentActivity() ?: this + } + fun reset() { ListenerManager.listenerMap.keys.filterIsInstance().forEach { - it.owner?.let { _ -> + it.parent?.let { _ -> LambdaEventBus.unsubscribe(it) ListenerManager.unregister(it) } } ListenerManager.asyncListenerMap.keys.filterIsInstance().forEach { - it.owner?.let { _ -> + it.parent?.let { _ -> LambdaEventBus.unsubscribe(it) ListenerManager.unregister(it) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 66218faa2..9fa30376f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -3,7 +3,6 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.core.BuildStructure import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud -import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module @@ -81,7 +80,7 @@ object HighwayTools : Module( doPadding = true ).let { ownedBuildStructure = it - ActivityManager.addSubActivities(it) + addSubActivities(it) } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt index fd966b197..a55085989 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/SchematicBuilder.kt @@ -43,7 +43,7 @@ object SchematicBuilder : Module( BlockPos(direction.directionVec.multiply(offset)) ).let { ownedBuildStructure = it - ActivityManager.addSubActivities(it) + addSubActivities(it) } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index f50954d41..39ab1eb6f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -28,21 +28,21 @@ object TestActivityManager : Module( category = Category.MISC ) { private val ctiectie by setting("Auto Obby", false, consumer = { _, _-> - ActivityManager.addSubActivities( + addSubActivities( BreakDownEnderChests() ) false }) private val tie by setting("Store Obby", false, consumer = { _, _-> - ActivityManager.addSubActivities( + addSubActivities( StoreItemToShulkerBox(Blocks.OBSIDIAN.item) ) false }) private val etit by setting("Acquire Obby", false, consumer = { _, _-> - ActivityManager.addSubActivities( + addSubActivities( AcquireItemInActiveHand(Blocks.OBSIDIAN.item) ) false @@ -56,7 +56,7 @@ object TestActivityManager : Module( repeat(4) { val targetState = Blocks.MAGENTA_GLAZED_TERRACOTTA.defaultState.withProperty(BlockHorizontal.FACING, currentDirection) - ActivityManager.addSubActivities( + addSubActivities( PlaceBlock(position, targetState) ) @@ -78,7 +78,7 @@ object TestActivityManager : Module( val targetState = Blocks.WOODEN_BUTTON.defaultState .withProperty(BlockDirectional.FACING, EnumFacing.NORTH) - ActivityManager.addSubActivities(PlaceBlock( + addSubActivities(PlaceBlock( player.flooredPosition.add(currentDirection.directionVec.multiply(2)), targetState )) @@ -88,7 +88,7 @@ object TestActivityManager : Module( }) private val po by setting("Pickup Obby", false, consumer = { _, _-> - ActivityManager.addSubActivities(PickUpDrops(Blocks.OBSIDIAN.item)) + addSubActivities(PickUpDrops(Blocks.OBSIDIAN.item)) false }) @@ -96,7 +96,7 @@ object TestActivityManager : Module( runSafe { val stack = player.heldItemMainhand.copy() - ActivityManager.addSubActivities(PickUpDrops(stack.item, stack)) + addSubActivities(PickUpDrops(stack.item, stack)) } false @@ -105,7 +105,7 @@ object TestActivityManager : Module( private val tiectie by setting("Surround", false, consumer = { _, _-> runSafe { player.centerPlayer() - ActivityManager.addSubActivities( + addSubActivities( SurroundWithObsidian(player.flooredPosition) ) } @@ -113,7 +113,7 @@ object TestActivityManager : Module( }) val raiseXPLevel by setting("Reach level 30", false, consumer = { _, _-> - ActivityManager.addSubActivities(ReachXPLevel(30)) + addSubActivities(ReachXPLevel(30)) false }) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 0d8195cfe..4c89306f3 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -26,6 +26,7 @@ object WorldEater : Module( private val layerSize by setting("Layers size", 1, 1..6, 1) private val sliceSize by setting("Slice size", 1, 1..6, 1) private val sliceDirection by setting("Slice direction", EnumFacing.NORTH) + private val collectAll by setting("Collect all", false) private val start by setting("Start", false, consumer = { _, _ -> clearArea() false @@ -81,9 +82,10 @@ object WorldEater : Module( second, layerSize, sliceSize, + collectAll = collectAll ).also { ownedBuildStructure = it - ActivityManager.addSubActivities(it) + addSubActivities(it) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index e3fa41735..f85b52f3e 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -1,7 +1,7 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.construction.core.BreakBlock -import com.lambda.client.activity.activities.storage.PlaceContainer +import com.lambda.client.activity.activities.storage.core.PlaceContainer import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager @@ -35,7 +35,7 @@ object InventoryManagerTwo : Module( player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener - ActivityManager.addSubActivities(PlaceContainer(slot.stack.copy(), open = true)) + addSubActivities(PlaceContainer(slot.stack.copy(), open = true)) it.cancel() @@ -81,7 +81,7 @@ object InventoryManagerTwo : Module( if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@forEachIndexed - ActivityManager.addSubActivities( + addSubActivities( BreakBlock(placeContainer.containerPos, collectDrops = true) ) } @@ -97,7 +97,7 @@ object InventoryManagerTwo : Module( if (!(currentBlock is BlockShulkerBox || currentBlock is BlockEnderChest)) return@safeListener - ActivityManager.addSubActivities( + addSubActivities( BreakBlock(placeContainer.containerPos, collectDrops = true) ) } From 40590f881232c8b14da0f55a72c95b1c4fa2c79b Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 12 Mar 2023 21:30:35 +0100 Subject: [PATCH 081/104] Fix build --- .../com/lambda/client/module/modules/client/BuildTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index e2450b0e2..c5c976511 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -152,8 +152,8 @@ object BuildTools : Module( "minecraft:cobblestone" ) - val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, String::class.java, { false })) - val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, String::class.java, { false })) + val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) + val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, { false })) private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) private val food = setting("FoodItem", "minecraft:golden_apple", { false }) private val tool = setting("ToolItem", "minecraft:diamond_pickaxe", { false }) From 4dbaeb69b201a01e76db9f0a144e2a9336dec8c4 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 13 Mar 2023 03:26:55 +0100 Subject: [PATCH 082/104] Fix no autopathing --- .../construction/core/BreakBlock.kt | 2 +- .../construction/core/BuildStructure.kt | 21 +++++++++++++++++++ .../construction/core/PlaceBlock.kt | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 158b58052..3f12af7b4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -49,7 +49,7 @@ class BreakBlock( private val forceNoSilk: Boolean = false, private val forceFortune: Boolean = false, private val forceNoFortune: Boolean = false, - override var timeout: Long = 200L, // ToDo: Reset timeouted breaks blockstates + override var timeout: Long = if (autoPathing) Long.MAX_VALUE else 200L, // ToDo: Reset timeouted breaks blockstates override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index e5da6c24e..0376570c6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -132,4 +132,25 @@ class BuildStructure( return ((b.x - a.x) * (check.z - a.z) - (b.z - a.z) * (check.x - a.x)) > 0 } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + when (childActivity) { + is PlaceBlock -> { + val blockPos = childActivity.blockPos + val targetState = structure[blockPos] ?: return + + getBuildActivity(blockPos, targetState)?.let { + addSubActivities(it, subscribe = true) + } + } + is BreakBlock -> { + val blockPos = childActivity.blockPos + val targetState = structure[blockPos] ?: return + + getBuildActivity(blockPos, targetState)?.let { + addSubActivities(it, subscribe = true) + } + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 999a5aeaa..86f8ee62b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -46,7 +46,7 @@ class PlaceBlock( private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, override var distance: Double = 1337.0, - override val timeout: Long = 1000L, // ToDo: Reset timeouted placements blockstates + override val timeout: Long = if (autoPathing) Long.MAX_VALUE else 1000L, // ToDo: Reset timeouted placements blockstates override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() From 37d72b67a8242de14b560ba41f88fc7108f392e1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 17 Mar 2023 00:45:04 +0100 Subject: [PATCH 083/104] Elevate path finding into BuildStructure --- .../activities/construction/ClearArea.kt | 2 + .../construction/core/BreakBlock.kt | 12 +-- .../construction/core/BuildStructure.kt | 97 +++++++++++++------ .../construction/core/PlaceBlock.kt | 16 +-- .../activity/activities/travel/BreakGoal.kt | 57 ----------- .../activity/activities/travel/PlaceGoal.kt | 77 --------------- 6 files changed, 80 insertions(+), 181 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 70515946d..8cf9dd0d9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -43,6 +43,8 @@ class ClearArea( val structure = mutableMapOf() layers.forEach { y -> + if (y !in 0..world.actualHeight) return@forEach + (minX..maxX).forEach { x -> (minZ..maxZ).forEach { z -> structure[BlockPos(x, y, z)] = Blocks.AIR.defaultState diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 3f12af7b4..0d085889d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.travel.BreakGoal import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent @@ -11,7 +10,6 @@ import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.items.block import com.lambda.client.util.items.filterByStack @@ -49,7 +47,7 @@ class BreakBlock( private val forceNoSilk: Boolean = false, private val forceFortune: Boolean = false, private val forceNoFortune: Boolean = false, - override var timeout: Long = if (autoPathing) Long.MAX_VALUE else 200L, // ToDo: Reset timeouted breaks blockstates + override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted breaks blockstates override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf(), @@ -113,7 +111,7 @@ class BreakBlock( updateState() - if (action != BuildActivity.BuildAction.BREAKING + if (!(action == BuildActivity.BuildAction.BREAKING || action == BuildActivity.BuildAction.BREAK) || subActivities.isNotEmpty() || status == Status.UNINITIALIZED ) return@safeListener @@ -155,9 +153,6 @@ class BreakBlock( tryBreak(side) } } - BuildActivity.BuildAction.WRONG_POS_BREAK -> { - if (autoPathing) addSubActivities(BreakGoal(blockPos)) - } else -> { // ToDo: break nearby blocks // failedWith(NoExposedSideFound()) @@ -170,7 +165,8 @@ class BreakBlock( } private fun SafeClientEvent.finish() { - if (!collectDrops || !autoPathing || drops == Items.AIR) { +// if (!collectDrops || !autoPathing || drops == Items.AIR) { + if (!collectDrops || drops == Items.AIR) { ActivityManagerHud.totalBlocksBroken++ success() return diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 0376570c6..dfdc14788 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -1,15 +1,26 @@ package com.lambda.client.activity.activities.construction.core +import baritone.api.pathing.goals.Goal +import baritone.api.pathing.goals.GoalBlock +import baritone.api.pathing.goals.GoalInverted +import baritone.process.BuilderProcess import com.lambda.client.activity.Activity import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.module.modules.client.BuildTools.autoPathing +import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.threads.safeListener import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent class BuildStructure( private val structure: Map, @@ -21,6 +32,7 @@ class BuildStructure( override var repeated: Int = 0, ) : RepeatingActivity, Activity() { private var currentOffset = BlockPos.ORIGIN + private var lastGoal: Goal? = null override fun SafeClientEvent.onInitialize() { val activities = mutableListOf() @@ -35,33 +47,59 @@ class BuildStructure( } init { -// safeListener { -// if (subActivities.isEmpty() || status == Status.UNINITIALIZED) return@safeListener -// success() -// } - -// /* Listen for any block changes like falling sand */ -// safeListener { event -> -// if (event.packet !is SPacketBlockChange) return@safeListener -// -// val blockPos = event.packet.blockPosition -// -// structure[blockPos]?.let { targetState -> -// val isContained = allSubActivities.none { -// when (it) { -// is BreakBlock -> it.blockPos == blockPos -// is PlaceBlock -> it.blockPos == blockPos -// else -> false -// } -// } -// -// if (isContained) return@safeListener -// -// getBuildActivity(blockPos, targetState)?.let { -// addSubActivities(listOf(it), subscribe = true) -// } -// } -// } + safeListener { + if (it.phase != TickEvent.Phase.END) return@safeListener + + if (subActivities.isEmpty()) success() + + if (!autoPathing) return@safeListener + + when (val activity = getCurrentActivity()) { + is PlaceBlock -> { + val blockPos = activity.blockPos + + lastGoal = if (isInBlockAABB(blockPos)) { + GoalInverted(GoalBlock(blockPos)) + } else { + BuilderProcess.GoalAdjacent(blockPos, blockPos, true) + } + } + is BreakBlock -> { + val blockPos = activity.blockPos + + lastGoal = if (isInBlockAABB(blockPos.up())) { + GoalInverted(GoalBlock(blockPos.up())) + } else { + BuilderProcess.GoalBreak(blockPos) + } + } + } + + lastGoal?.let { goal -> + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) + } + } + + /* Listen for any block changes like falling sand */ + safeListener { event -> + if (event.packet !is SPacketBlockChange) return@safeListener + + val blockPos = event.packet.blockPosition + + structure[blockPos]?.let { targetState -> + if (allSubActivities.any { + when (it) { + is BreakBlock -> it.blockPos == blockPos + is PlaceBlock -> it.blockPos == blockPos + else -> false + } + }) return@safeListener + + getBuildActivity(blockPos, targetState)?.let { + addSubActivities(listOf(it), subscribe = true) + } + } + } } private fun SafeClientEvent.getBuildActivity(blockPos: BlockPos, targetState: IBlockState): Activity? { @@ -78,6 +116,8 @@ class BuildStructure( blockPos, targetState ) } + /* block is not breakable */ + currentState.getBlockHardness(world, blockPos) < 0 -> return null /* only option left is breaking the block */ else -> { return BreakBlock( @@ -153,4 +193,7 @@ class BuildStructure( } } } + + private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos) = + !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 86f8ee62b..faaa9e4b4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -3,7 +3,6 @@ package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.travel.PlaceGoal import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent @@ -46,7 +45,7 @@ class PlaceBlock( private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, override var distance: Double = 1337.0, - override val timeout: Long = if (autoPathing) Long.MAX_VALUE else 1000L, // ToDo: Reset timeouted placements blockstates + override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted placements blockstates override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, override val toRender: MutableSet = mutableSetOf() @@ -135,9 +134,7 @@ class PlaceBlock( checkPlace(placeInfo) } } - else -> { - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) - } + else -> {} } } @@ -274,13 +271,6 @@ class PlaceBlock( return } - /* check if no entity collides */ - if (!world.checkNoEntityCollision(targetState.getSelectedBoundingBox(world, blockPos), null)) { - // ToDo: this only handles the case where the player is inside the block - if (autoPathing) addSubActivities(PlaceGoal(blockPos)) - return - } - targetState.properties.entries.firstOrNull { it.key.name == "facing" }?.let { entry -> if (ignoreProperties || ignoreFacing) return@let @@ -326,6 +316,8 @@ class PlaceBlock( } private fun SafeClientEvent.doPlace(placeInfo: PlaceInfo) { + timeout = 1000L + val isBlacklisted = world.getBlockState(placeInfo.pos).block in blockBlacklist if (isBlacklisted) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt deleted file mode 100644 index 495493310..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/BreakGoal.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.lambda.client.activity.activities.travel - -import baritone.api.pathing.goals.GoalBlock -import baritone.api.pathing.goals.GoalInverted -import baritone.process.BuilderProcess.GoalBreak -import com.lambda.client.activity.Activity -import com.lambda.client.activity.types.TimeoutActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.util.BaritoneUtils -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getMiningSide -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent - -class BreakGoal( - private val blockPos: BlockPos, - override val timeout: Long = 60000L -) : TimeoutActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - if (!isInBlockAABB(blockPos.up()) - && getMiningSide(blockPos, BuildTools.maxReach) != null - ) success() - } - - init { - safeListener { event -> - if (event.phase != TickEvent.Phase.START) return@safeListener - - if (isInBlockAABB(blockPos.up())) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalInverted(GoalBlock(blockPos.up()))) - return@safeListener - } - - getMiningSide(blockPos, BuildTools.maxReach)?.let { - success() - } ?: run { - val goalBreak = GoalBreak(blockPos) - - if (!goalBreak.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalBreak) - return@safeListener - } - - failedWith(NoPathToBreakFound()) - } - } - } - - private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos): Boolean { - return !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) - } - - class NoPathToBreakFound : Exception("No path to break position found (scaffolding not yet implemented)") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt deleted file mode 100644 index 03bce9651..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PlaceGoal.kt +++ /dev/null @@ -1,77 +0,0 @@ -package com.lambda.client.activity.activities.travel - -import baritone.api.pathing.goals.GoalBlock -import baritone.api.pathing.goals.GoalInverted -import baritone.api.pathing.goals.GoalNear -import baritone.process.BuilderProcess -import com.lambda.client.activity.Activity -import com.lambda.client.activity.types.TimeoutActivity -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.util.BaritoneUtils -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.threads.safeListener -import com.lambda.client.util.world.getNeighbour -import net.minecraft.util.math.AxisAlignedBB -import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent - -class PlaceGoal( - private val blockPos: BlockPos, - override val timeout: Long = 60000L -) : TimeoutActivity, Activity() { - override fun SafeClientEvent.onInitialize() { - getNeighbour(blockPos, attempts = 1, visibleSideCheck = true, range = 4.5f)?.let { - success() - } - } - - init { - safeListener { event -> - if (event.phase != TickEvent.Phase.START) return@safeListener - - if (isInBlockAABB(blockPos)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalInverted(GoalBlock(blockPos))) - return@safeListener - } - - // ToDo: Use original data from PlaceBlock - getNeighbour( - blockPos, - attempts = BuildTools.placementSearch, - visibleSideCheck = BuildTools.placeStrictness != BuildTools.PlacementStrictness.ANY, - range = BuildTools.maxReach - )?.let { - success() - } ?: run { - val goalAdjacent = BuilderProcess.GoalAdjacent(blockPos, blockPos, true) - - if (!goalAdjacent.isInGoal(player.flooredPosition)) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalAdjacent) - return@safeListener - } - - failedWith(NoPathToPlaceFound()) -// getNeighbour(blockPos, attempts = 1, range = 256f)?.let { -// val goalNear = GoalNear(blockPos, 3) -// -// if (!goalNear.isInGoal(player.flooredPosition)) { -// BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goalNear) -// return@safeListener -// } -// -// BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalNear(blockPos.offset(it.side), 1)) -// } ?: run { -// // ToDo: Scaffolding! -// -// failedWith(NoPathToPlaceFound()) -// } - } - } - } - - private fun SafeClientEvent.isInBlockAABB(blockPos: BlockPos) = - !world.checkNoEntityCollision(AxisAlignedBB(blockPos), null) - - class NoPathToPlaceFound : Exception("No path to place position found (scaffolding not yet implemented)") -} \ No newline at end of file From d35a7d40d18eb653ba2afd262d63fcf2cd94ae97 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 26 Mar 2023 07:58:11 +0200 Subject: [PATCH 084/104] Rewrote priority system for BuildStructure --- .../com/lambda/client/activity/Activity.kt | 27 ++- .../construction/core/BreakBlock.kt | 229 ++++++++++-------- .../construction/core/BuildStructure.kt | 165 +++++++------ .../construction/core/PlaceBlock.kt | 78 +++--- .../client/activity/types/BuildActivity.kt | 33 ++- .../client/event/listener/ListenerImpl.kt | 4 +- 6 files changed, 302 insertions(+), 234 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index b82690fae..54487e3b5 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -6,6 +6,7 @@ import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.DelayedActivity import com.lambda.client.activity.types.DelayedActivity.Companion.checkDelayed import com.lambda.client.activity.types.LoopWhileActivity.Companion.checkLoopingUntil +import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender import com.lambda.client.activity.types.RepeatingActivity.Companion.checkRepeat import com.lambda.client.activity.types.RotatingActivity.Companion.checkRotating @@ -132,6 +133,10 @@ abstract class Activity { LambdaEventBus.unsubscribe(activity) ListenerManager.unregister(activity) + if (activity is RenderAABBActivity) { + activity.toRender.clear() + } + parent?.let { with(it) { onChildSuccess(activity) @@ -263,6 +268,16 @@ abstract class Activity { textComponent.add("Name", secondaryColor) textComponent.add("${javaClass.simpleName} ", primaryColor) + + if (this is BuildActivity) { + textComponent.add("Context", secondaryColor) + textComponent.add(context.name, primaryColor) + textComponent.add("Availability", secondaryColor) + textComponent.add(availability.name, primaryColor) + textComponent.add("Type", secondaryColor) + textComponent.add(type.name, primaryColor) + } + textComponent.add("State", secondaryColor) textComponent.add(status.name, primaryColor) @@ -271,13 +286,6 @@ abstract class Activity { textComponent.add(DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS"), primaryColor) } - if (this is BuildActivity) { - textComponent.add("Context", secondaryColor) - textComponent.add(context.name, primaryColor) - textComponent.add("Action", secondaryColor) - textComponent.add(action.name, primaryColor) - } - textComponent.add("Hash", secondaryColor) textComponent.add(hashCode().toString(), primaryColor) @@ -317,7 +325,10 @@ abstract class Activity { textComponent.addLine("") val acti = if (this is BuildStructure) { - subActivities.sortedWith(buildComparator()) + subActivities + .filterIsInstance() + .sortedWith(buildComparator()) + .filterIsInstance() } else { subActivities } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 0d085889d..ad44d0589 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -11,8 +11,6 @@ import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.items.block -import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo @@ -23,7 +21,6 @@ import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid import kotlinx.coroutines.launch -import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments @@ -58,28 +55,37 @@ class BreakBlock( private var ticksNeeded = 0 private var drops: Item = Items.AIR - override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> + override var context: BuildActivity.Context by Delegates.observable(BuildActivity.Context.NONE) { _, old, new -> if (old == new) return@observable renderContext.color = new.color } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.NONE) { _, old, new -> + override var availability: BuildActivity.Availability by Delegates.observable(BuildActivity.Availability.NONE) { _, old, new -> if (old == new) return@observable - renderAction.color = new.color + renderAvailability.color = new.color } - override var earliestFinish: Long - get() = BuildTools.breakDelay.toLong() - set(_) {} + override var type: BuildActivity.Type by Delegates.observable(BuildActivity.Type.BREAK_BLOCK) { _, old, new -> + if (old == new) return@observable + renderType.color = new.color + } private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( blockPos, context.color ).also { toRender.add(it) } - private val renderAction = RenderAABBActivity.Companion.RenderBlockPos( - blockPos, action.color + private val renderAvailability = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, availability.color ).also { toRender.add(it) } + private val renderType = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, type.color + ).also { toRender.add(it) } + + override var earliestFinish: Long + get() = BuildTools.breakDelay.toLong() + set(_) {} + init { runSafe { if (!world.worldBorder.contains(blockPos) || world.isOutsideBuildHeight(blockPos)) { @@ -88,37 +94,24 @@ class BreakBlock( return@runSafe } - val currentState = world.getBlockState(blockPos) - - if (currentState.block in BuildTools.ignoredBlocks) { - success() - return@runSafe - } - - if (currentState.isLiquid) addLiquidFill(blockPos) - - updateDrops(currentState) - updateState() + updateState() // ToDo: check if needed } safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener - if (context != BuildActivity.BuildContext.PENDING - && action != BuildActivity.BuildAction.BREAKING - && world.isAirBlock(blockPos) - ) finish() - updateState() - if (!(action == BuildActivity.BuildAction.BREAKING || action == BuildActivity.BuildAction.BREAK) - || subActivities.isNotEmpty() + if (world.isAirBlock(blockPos)) { + finish() + return@safeListener + } + + if (subActivities.isNotEmpty() || status == Status.UNINITIALIZED ) return@safeListener - side?.let { side -> - tryBreak(side) - } + resolveAvailability() } safeListener { @@ -146,22 +139,11 @@ class BreakBlock( } updateState() - - when (action) { - BuildActivity.BuildAction.BREAKING, BuildActivity.BuildAction.BREAK -> { - side?.let { side -> - tryBreak(side) - } - } - else -> { - // ToDo: break nearby blocks -// failedWith(NoExposedSideFound()) - } - } + resolveAvailability() } override fun SafeClientEvent.onCancel() { - playerController.resetBlockRemoving() + if (context == BuildActivity.Context.IN_PROGRESS) playerController.resetBlockRemoving() } private fun SafeClientEvent.finish() { @@ -172,9 +154,9 @@ class BreakBlock( return } - if (context == BuildActivity.BuildContext.PICKUP) return + if (context == BuildActivity.Context.PICKUP) return - context = BuildActivity.BuildContext.PICKUP + context = BuildActivity.Context.PICKUP addSubActivities( PickUpDrops(drops, minAmount = minCollectAmount) @@ -182,59 +164,81 @@ class BreakBlock( } private fun SafeClientEvent.updateState() { + if (checkLiquids()) return + + updateProperties() + getMiningSide(blockPos, BuildTools.maxReach)?.let { + val hitVec = getHitVec(blockPos, it) + /* prevent breaking the block the player is standing on */ if (player.flooredPosition.down() == blockPos && !world.getBlockState(blockPos.down()).isSideSolid(world, blockPos.down(), EnumFacing.UP) ) { - action = BuildActivity.BuildAction.WRONG_POS_BREAK - distance = player.distanceTo(getHitVec(blockPos, it)) + availability = BuildActivity.Availability.BLOCKED_BY_PLAYER + distance = player.distanceTo(hitVec) return } + availability = BuildActivity.Availability.VALID + distance = player.distanceTo(hitVec) + side = it + rotation = getRotationTo(hitVec) + return + } - if (action != BuildActivity.BuildAction.BREAKING) { - action = BuildActivity.BuildAction.BREAK - } + getMiningSide(blockPos)?.let { + availability = BuildActivity.Availability.NOT_IN_RANGE distance = player.distanceTo(getHitVec(blockPos, it)) - side = it - rotation = getRotationTo(getHitVec(blockPos, it)) } ?: run { - getMiningSide(blockPos)?.let { - action = BuildActivity.BuildAction.WRONG_POS_BREAK - distance = player.distanceTo(getHitVec(blockPos, it)) - } ?: run { - action = BuildActivity.BuildAction.INVALID_BREAK - distance = 1337.0 - } - playerController.resetBlockRemoving() - side = null - rotation = null + availability = BuildActivity.Availability.NOT_EXPOSED + distance = 1337.0 } - } - private fun SafeClientEvent.tryBreak(side: EnumFacing) { - if (checkLiquids() || !hasOptimalTool()) return + playerController.resetBlockRemoving() + side = null + rotation = null + } - val currentState = world.getBlockState(blockPos) + private fun SafeClientEvent.resolveAvailability() { + when (availability) { + BuildActivity.Availability.VALID -> { + tryBreak() + } + BuildActivity.Availability.BLOCKED_BY_PLAYER, + BuildActivity.Availability.NOT_IN_RANGE -> { + // Wait for player move + } + BuildActivity.Availability.WRONG_ITEM_SELECTED -> { +// acquireOptimalTool() + } + BuildActivity.Availability.NOT_EXPOSED, + BuildActivity.Availability.NEEDS_LIQUID_HANDLING -> { + // Wait for other tasks to finish + } + else -> { + // Other cases should not happen + } + } + } - // ToDo: add silk touch support - updateDrops(currentState) + private fun SafeClientEvent.tryBreak() { + if (!hasOptimalTool()) return - ticksNeeded = ceil((1 / currentState - .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 2000L + side?.let { + if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, it)) { + if ((ticksNeeded == 1 && player.onGround) || player.capabilities.isCreativeMode) { + playerController.blockHitDelay = 0 + context = BuildActivity.Context.PENDING + } else { + context = BuildActivity.Context.IN_PROGRESS + } - if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, side)) { - if (ticksNeeded == 1 || player.capabilities.isCreativeMode) { - playerController.blockHitDelay = 0 - context = BuildActivity.BuildContext.PENDING - } else { - action = BuildActivity.BuildAction.BREAKING + mc.effectRenderer.addBlockHitEffects(blockPos, it) + player.swingArm(EnumHand.MAIN_HAND) } - - mc.effectRenderer.addBlockHitEffects(blockPos, side) - player.swingArm(EnumHand.MAIN_HAND) } + + } // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) @@ -253,7 +257,7 @@ class BreakBlock( // && it.stack != player.heldItemMainhand // && (!getSilkDrop || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it.stack) > 0) ) { - context = BuildActivity.BuildContext.RESTOCK + context = BuildActivity.Context.RESTOCK addSubActivities(SwapOrSwitchToSlot(it)) return false @@ -274,7 +278,7 @@ class BreakBlock( val selectedSpeed = tool.getDestroySpeed(ItemStack(tool), currentState) if (selectedSpeed > currentDestroySpeed) { - context = BuildActivity.BuildContext.RESTOCK + context = BuildActivity.Context.RESTOCK addSubActivities(AcquireItemInActiveHand( tool, @@ -289,7 +293,7 @@ class BreakBlock( && player.heldItemMainhand.isItemStackDamageable ) { player.inventorySlots.firstOrNull { !it.stack.isItemStackDamageable }?.let { - context = BuildActivity.BuildContext.RESTOCK + context = BuildActivity.Context.RESTOCK addSubActivities(SwapOrSwitchToSlot(it)) return false @@ -303,20 +307,52 @@ class BreakBlock( private fun SafeClientEvent.checkLiquids(): Boolean { var foundLiquid = false + if (world.getBlockState(blockPos).isLiquid) { + (parent as? BuildStructure)?.let { + with(it) { + addLiquidFill(blockPos) + } + } + availability = BuildActivity.Availability.NEEDS_LIQUID_HANDLING + + return true + } + EnumFacing.values() .filter { it != EnumFacing.DOWN } .map { blockPos.offset(it) } .filter { world.getBlockState(it).isLiquid } .forEach { pos -> - addLiquidFill(pos) + (parent as? BuildStructure)?.let { + with(it) { + addLiquidFill(pos) + } + } foundLiquid = true } + if (foundLiquid) { + availability = BuildActivity.Availability.NEEDS_LIQUID_HANDLING + } + return foundLiquid } - private fun SafeClientEvent.updateDrops(currentState: IBlockState) { + private fun SafeClientEvent.updateProperties() { + val currentState = world.getBlockState(blockPos) + + if (currentState.block in BuildTools.ignoredBlocks) { + success() + return + } + + ticksNeeded = ceil((1 / currentState + .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() + + timeout = ticksNeeded * 50L + 2000L + + // ToDo: add silk touch support drops = currentState.block.getItemDropped( currentState, Random(), @@ -324,21 +360,6 @@ class BreakBlock( ) ?: Items.AIR } - private fun SafeClientEvent.addLiquidFill(liquidPos: BlockPos) { - context = BuildActivity.BuildContext.LIQUID - - val available = player.inventorySlots - .filterByStack { BuildTools.ejectList.value.contains(it.item.block.registryName.toString()) } - .maxByOrNull { it.stack.count }?.stack?.item?.block ?: Blocks.AIR - - if (available == Blocks.AIR) { - failedWith(NoFillerMaterialFoundException()) - return - } - - addSubActivities(PlaceBlock(liquidPos, available.defaultState)) - } - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is PickUpDrops -> { @@ -347,8 +368,6 @@ class BreakBlock( } else -> { status = Status.UNINITIALIZED - context = BuildActivity.BuildContext.NONE - action = BuildActivity.BuildAction.NONE updateState() } } @@ -356,8 +375,6 @@ class BreakBlock( override fun SafeClientEvent.onFailure(exception: Exception): Boolean { playerController.resetBlockRemoving() - context = BuildActivity.BuildContext.NONE - action = BuildActivity.BuildAction.NONE side = null rotation = null return false diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index dfdc14788..9e39c0ba4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -6,20 +6,25 @@ import baritone.api.pathing.goals.GoalInverted import baritone.process.BuilderProcess import com.lambda.client.activity.Activity import com.lambda.client.activity.types.BuildActivity +import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.event.events.PacketEvent +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.items.block +import com.lambda.client.util.items.filterByStack +import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.safeListener import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks -import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos +import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.fml.common.gameevent.TickEvent class BuildStructure( @@ -30,19 +35,20 @@ class BuildStructure( private val collectAll: Boolean = false, override val maximumRepeats: Int = 1, override var repeated: Int = 0, -) : RepeatingActivity, Activity() { + override val toRender: MutableSet = mutableSetOf() +) : RepeatingActivity, RenderAABBActivity, Activity() { private var currentOffset = BlockPos.ORIGIN private var lastGoal: Goal? = null - override fun SafeClientEvent.onInitialize() { - val activities = mutableListOf() + private val renderCurrent = RenderAABBActivity.Companion.RenderAABB( + AxisAlignedBB(BlockPos.ORIGIN), ColorHolder(255, 255, 255) + ).also { toRender.add(it) } + override fun SafeClientEvent.onInitialize() { structure.forEach { (pos, targetState) -> - getBuildActivity(pos.add(currentOffset), targetState)?.let { activities.add(it) } + createBuildActivity(pos.add(currentOffset), targetState) } - addSubActivities(activities, subscribe = true) - currentOffset = currentOffset.add(offsetMove) } @@ -52,12 +58,14 @@ class BuildStructure( if (subActivities.isEmpty()) success() - if (!autoPathing) return@safeListener - when (val activity = getCurrentActivity()) { is PlaceBlock -> { val blockPos = activity.blockPos + renderCurrent.renderAABB = AxisAlignedBB(blockPos).grow(0.1) + + if (!autoPathing) return@safeListener + lastGoal = if (isInBlockAABB(blockPos)) { GoalInverted(GoalBlock(blockPos)) } else { @@ -67,6 +75,10 @@ class BuildStructure( is BreakBlock -> { val blockPos = activity.blockPos + renderCurrent.renderAABB = AxisAlignedBB(blockPos).grow(0.1) + + if (!autoPathing) return@safeListener + lastGoal = if (isInBlockAABB(blockPos.up())) { GoalInverted(GoalBlock(blockPos.up())) } else { @@ -80,11 +92,11 @@ class BuildStructure( } } - /* Listen for any block changes like falling sand */ - safeListener { event -> - if (event.packet !is SPacketBlockChange) return@safeListener +// safeListener { } - val blockPos = event.packet.blockPosition + /* Listen for any block changes like falling sand */ + safeListener { event -> + val blockPos = event.pos structure[blockPos]?.let { targetState -> if (allSubActivities.any { @@ -95,73 +107,58 @@ class BuildStructure( } }) return@safeListener - getBuildActivity(blockPos, targetState)?.let { - addSubActivities(listOf(it), subscribe = true) - } + createBuildActivity(blockPos, targetState) } } } - private fun SafeClientEvent.getBuildActivity(blockPos: BlockPos, targetState: IBlockState): Activity? { + private fun SafeClientEvent.createBuildActivity(blockPos: BlockPos, targetState: IBlockState) { val currentState = world.getBlockState(blockPos) - when { - /* is in padding */ - doPadding && isInPadding(blockPos) -> return null - /* is in desired state */ - currentState == targetState -> return null - /* block needs to be placed */ - targetState != Blocks.AIR.defaultState -> { - return PlaceBlock( - blockPos, targetState - ) - } - /* block is not breakable */ - currentState.getBlockHardness(world, blockPos) < 0 -> return null - /* only option left is breaking the block */ - else -> { - return BreakBlock( - blockPos, collectDrops = collectAll, minCollectAmount = 64 - ) - } + /* is in padding */ + if (doPadding && isInPadding(blockPos)) return + + /* is in desired state */ + if (currentState == targetState) return + + /* block needs to be placed */ + if (targetState != Blocks.AIR.defaultState) { + addSubActivities(PlaceBlock( + blockPos, targetState + ), subscribe = true) + return } + + /* block is not breakable */ + if (currentState.getBlockHardness(world, blockPos) < 0) return + + /* only option left is breaking the block */ + addSubActivities(BreakBlock( + blockPos, collectDrops = collectAll, minCollectAmount = 64 + ), subscribe = true) } override fun getCurrentActivity(): Activity { - subActivities.sortedWith(buildComparator()).firstOrNull()?.let { - with(it) { - return getCurrentActivity() - } + subActivities + .filterIsInstance() + .sortedWith(buildComparator()) + .firstOrNull()?.let { buildActivity -> + (buildActivity as? Activity)?.let { + with (it) { + return getCurrentActivity() + } + } } ?: return this } - fun buildComparator() = compareBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - current.context - } else 0 + fun buildComparator() = compareBy { + it.context }.thenBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - current.action - } else 0 + it.availability }.thenBy { - val current = deepestBuildActivity(it) - - if (current is BuildActivity) { - current.distance - } else 1337.0 - } - - /* BreakBlocks that are boxed in a PlaceBlock are considered in the sequence */ - private fun deepestBuildActivity(activity: Activity): Activity { - activity.subActivities - .filterIsInstance() - .firstOrNull()?.let { - return deepestBuildActivity(it as Activity) - } ?: return activity + it.type + }.thenBy { + it.distance } private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) @@ -173,23 +170,47 @@ class BuildStructure( return ((b.x - a.x) * (check.z - a.z) - (b.z - a.z) * (check.x - a.x)) > 0 } + fun SafeClientEvent.addLiquidFill(liquidPos: BlockPos) { + var exists = false + + subActivities + .filterIsInstance() + .filter { it.blockPos == liquidPos }.forEach { + it.type = BuildActivity.Type.LIQUID_FILL + exists = true + } + + if (exists) return + + val available = player.inventorySlots + .filterByStack { BuildTools.ejectList.value.contains(it.item.block.registryName.toString()) } + .maxByOrNull { it.stack.count }?.stack?.item?.block ?: Blocks.AIR + + if (available == Blocks.AIR) { + failedWith(BreakBlock.NoFillerMaterialFoundException()) + return + } + + val activity = PlaceBlock(liquidPos, available.defaultState) + + activity.type = BuildActivity.Type.LIQUID_FILL + + addSubActivities(activity) + } + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is PlaceBlock -> { val blockPos = childActivity.blockPos val targetState = structure[blockPos] ?: return - getBuildActivity(blockPos, targetState)?.let { - addSubActivities(it, subscribe = true) - } + createBuildActivity(blockPos, targetState) } is BreakBlock -> { val blockPos = childActivity.blockPos val targetState = structure[blockPos] ?: return - getBuildActivity(blockPos, targetState)?.let { - addSubActivities(it, subscribe = true) - } + createBuildActivity(blockPos, targetState) } } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index faaa9e4b4..0ef8a50f1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -8,7 +8,6 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.client.BuildTools.directionForce import com.lambda.client.module.modules.client.BuildTools.placeStrictness import com.lambda.client.util.items.blockBlacklist @@ -53,28 +52,37 @@ class PlaceBlock( private var placeInfo: PlaceInfo? = null private var spoofedDirection = false - override var context: BuildActivity.BuildContext by Delegates.observable(BuildActivity.BuildContext.NONE) { _, old, new -> + override var context: BuildActivity.Context by Delegates.observable(BuildActivity.Context.NONE) { _, old, new -> if (old == new) return@observable renderContext.color = new.color } - override var action: BuildActivity.BuildAction by Delegates.observable(BuildActivity.BuildAction.NONE) { _, old, new -> + override var availability: BuildActivity.Availability by Delegates.observable(BuildActivity.Availability.NONE) { _, old, new -> if (old == new) return@observable - renderAction.color = new.color + renderAvailability.color = new.color } - override var earliestFinish: Long - get() = BuildTools.placeDelay.toLong() - set(_) {} + override var type: BuildActivity.Type by Delegates.observable(BuildActivity.Type.PLACE_BLOCK) { _, old, new -> + if (old == new) return@observable + renderType.color = new.color + } private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( blockPos, context.color ).also { toRender.add(it) } - private val renderAction = RenderAABBActivity.Companion.RenderBlockPos( - blockPos, action.color + private val renderAvailability = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, availability.color ).also { toRender.add(it) } + private val renderType = RenderAABBActivity.Companion.RenderBlockPos( + blockPos, type.color + ).also { toRender.add(it) } + + override var earliestFinish: Long + get() = BuildTools.placeDelay.toLong() + set(_) {} + private enum class PlacementOffset(val offset: Vec3d) { UPPER(Vec3d(0.0, 0.1, 0.0)), CENTER(Vec3d.ZERO), @@ -128,13 +136,13 @@ class PlaceBlock( override fun SafeClientEvent.onInitialize() { updateState() - when (action) { - BuildActivity.BuildAction.PLACE -> { - placeInfo?.let { placeInfo -> - checkPlace(placeInfo) - } - } - else -> {} + if (availability != BuildActivity.Availability.VALID) { + status = Status.UNINITIALIZED + return + } + + placeInfo?.let { placeInfo -> + checkPlace(placeInfo) } } @@ -146,19 +154,23 @@ class PlaceBlock( val currentState = world.getBlockState(blockPos) - if (context != BuildActivity.BuildContext.PENDING + if (context != BuildActivity.Context.PENDING && isInDesiredState(currentState) ) success() if (!currentState.isReplaceable && !isInDesiredState(currentState) - && context != BuildActivity.BuildContext.PENDING + && context != BuildActivity.Context.PENDING && subActivities.filterIsInstance().isEmpty() ) { - addSubActivities( - BreakBlock(blockPos), - subscribe = true - ) + (parent as? BuildStructure)?.let { + with (it) { + addSubActivities( + BreakBlock(blockPos), + subscribe = true + ) + } + } return } @@ -218,17 +230,17 @@ class PlaceBlock( sides = allowedSides.toTypedArray() )?.let { if (it.placedPos == blockPos) { - action = BuildActivity.BuildAction.PLACE + availability = BuildActivity.Availability.VALID it.hitVec = it.hitVec.add(placementOffset.offset) distance = player.distanceTo(it.hitVec) placeInfo = it } else { - action = BuildActivity.BuildAction.NEEDS_SUPPORT - - PlaceBlock(it.placedPos, targetState).also { placeBlock -> - placeBlock.context = BuildActivity.BuildContext.SUPPORT - addSubActivities(placeBlock) - } +// action = BuildActivity.BuildAction.NEEDS_SUPPORT +// +// PlaceBlock(it.placedPos, targetState).also { placeBlock -> +// placeBlock.context = BuildActivity.BuildContext.SUPPORT +// addSubActivities(placeBlock) +// } } } ?: run { getNeighbour( @@ -238,10 +250,10 @@ class PlaceBlock( range = 256f, sides = allowedSides.toTypedArray() )?.let { - action = BuildActivity.BuildAction.WRONG_POS_PLACE + availability = BuildActivity.Availability.NOT_IN_RANGE distance = player.distanceTo(it.hitVec.add(placementOffset.offset)) } ?: run { - action = BuildActivity.BuildAction.INVALID_PLACE + availability = BuildActivity.Availability.NOT_VISIBLE distance = 1337.0 } placeInfo = null @@ -262,7 +274,7 @@ class PlaceBlock( if (heldItemStack.item != optimalStack.item || (!ignoreProperties && optimalStack.metadata != heldItemStack.metadata) ) { - context = BuildActivity.BuildContext.RESTOCK + context = BuildActivity.Context.RESTOCK addSubActivities(AcquireItemInActiveHand( optimalStack.item, @@ -346,7 +358,7 @@ class PlaceBlock( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - context = BuildActivity.BuildContext.PENDING + context = BuildActivity.Context.PENDING } private fun isInDesiredState(currentState: IBlockState) = diff --git a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt index 18a62c662..25ac3787b 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt @@ -3,28 +3,35 @@ package com.lambda.client.activity.types import com.lambda.client.util.color.ColorHolder interface BuildActivity { - var context: BuildContext - var action: BuildAction + var context: Context + var availability: Availability + var type: Type var distance: Double - enum class BuildContext(val color: ColorHolder) { + enum class Context(val color: ColorHolder) { + IN_PROGRESS(ColorHolder(240, 222, 60)), RESTOCK(ColorHolder(3, 252, 169)), - LIQUID(ColorHolder(114, 27, 255)), - SUPPORT(ColorHolder(16, 74, 94)), PICKUP(ColorHolder(252, 3, 207)), NONE(ColorHolder(0, 0, 0, 0)), PENDING(ColorHolder(11, 11, 175)) } - enum class BuildAction(val color: ColorHolder) { - BREAKING(ColorHolder(240, 222, 60)), - BREAK(ColorHolder(222, 0, 0)), - PLACE(ColorHolder(35, 188, 254)), + enum class Availability(val color: ColorHolder) { + VALID(ColorHolder(222, 0, 0)), + WRONG_ITEM_SELECTED(ColorHolder(3, 252, 169)), + BLOCKED_BY_PLAYER(ColorHolder(252, 3, 207)), + NOT_IN_RANGE(ColorHolder(252, 3, 207)), + NOT_REPLACEABLE(ColorHolder(46, 0, 0, 0)), + NOT_EXPOSED(ColorHolder(46, 0, 0, 0)), NEEDS_SUPPORT(ColorHolder(35, 15, 254)), - WRONG_POS_BREAK(ColorHolder(112, 0, 0, 0)), - WRONG_POS_PLACE(ColorHolder(20, 108, 145, 0)), - INVALID_BREAK(ColorHolder(46, 0, 0, 0)), - INVALID_PLACE(ColorHolder(11, 55, 74, 0)), + NOT_VISIBLE(ColorHolder(46, 0, 0, 0)), + NEEDS_LIQUID_HANDLING(ColorHolder(114, 27, 255)), NONE(ColorHolder(11, 11, 11)) } + + enum class Type(val color: ColorHolder) { + LIQUID_FILL(ColorHolder(114, 27, 255)), + BREAK_BLOCK(ColorHolder(255, 0, 0, 0)), + PLACE_BLOCK(ColorHolder(0, 255, 0, 0)), + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/event/listener/ListenerImpl.kt b/src/main/kotlin/com/lambda/client/event/listener/ListenerImpl.kt index e0aede6da..861e0a646 100644 --- a/src/main/kotlin/com/lambda/client/event/listener/ListenerImpl.kt +++ b/src/main/kotlin/com/lambda/client/event/listener/ListenerImpl.kt @@ -22,7 +22,7 @@ inline fun Any.asyncListener(noinline function: suspend (T) -> /** * Create and register a new async listener for this object - * Must be used with Kotlinx Coroutine and a implementation of [IAsyncEventBus] + * Must be used with Kotlinx Coroutine and an implementation of [IAsyncEventBus] * * @param T type of the target event * @param clazz class of the target event @@ -57,7 +57,7 @@ fun Any.listener(priority: Int = DEFAULT_PRIORITY, clazz: Class, fu /** * Implementation of [AbstractListener] with suspend block - * Must be used with Kotlinx Coroutine and a implementation of [IAsyncEventBus] + * Must be used with Kotlinx Coroutine and an implementation of [IAsyncEventBus] */ class AsyncListener( owner: Any, From 16daa9643183fa409a6a81ee2d356e462d37404e Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 27 Mar 2023 07:34:25 +0200 Subject: [PATCH 085/104] Added overlay debug renderer and fix breaking bushes --- .../com/lambda/client/activity/Activity.kt | 6 +-- .../activities/construction/ClearArea.kt | 4 +- .../construction/core/BreakBlock.kt | 45 +++++++++++++----- .../construction/core/BuildStructure.kt | 19 ++++++-- .../construction/core/PlaceBlock.kt | 47 ++++++++++++++----- .../client/activity/types/BuildActivity.kt | 17 +++---- .../activity/types/RenderAABBActivity.kt | 6 +-- .../types/RenderOverlayTextActivity.kt | 36 +++++++++++++- .../manager/managers/ActivityManager.kt | 40 ++++++++++++++-- .../module/modules/client/BuildTools.kt | 4 +- .../modules/misc/TestActivityManager.kt | 4 +- 11 files changed, 175 insertions(+), 53 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 54487e3b5..92e7b85b5 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -7,7 +7,7 @@ import com.lambda.client.activity.types.DelayedActivity import com.lambda.client.activity.types.DelayedActivity.Companion.checkDelayed import com.lambda.client.activity.types.LoopWhileActivity.Companion.checkLoopingUntil import com.lambda.client.activity.types.RenderAABBActivity -import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.activity.types.RepeatingActivity.Companion.checkRepeat import com.lambda.client.activity.types.RotatingActivity.Companion.checkRotating import com.lambda.client.activity.types.TimeoutActivity.Companion.checkTimeout @@ -104,7 +104,7 @@ abstract class Activity { checkTimeout(activity) checkDelayed(activity) checkRotating(activity) - checkRender() + checkAABBRender() } fun SafeClientEvent.initialize() { @@ -134,7 +134,7 @@ abstract class Activity { ListenerManager.unregister(activity) if (activity is RenderAABBActivity) { - activity.toRender.clear() + activity.aabbCompounds.clear() } parent?.let { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 8cf9dd0d9..d49819540 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -18,7 +18,7 @@ class ClearArea( private val sliceSize: Int = 1, private val sliceDirection: EnumFacing = EnumFacing.NORTH, private val collectAll: Boolean = false, - override val toRender: MutableSet = mutableSetOf() + override val aabbCompounds: MutableSet = mutableSetOf() ) : RenderAABBActivity, Activity() { private val minX = minOf(pos1.x, pos2.x) private val minY = minOf(pos1.y, pos2.y) @@ -34,7 +34,7 @@ class ClearArea( (maxX + 1).toDouble(), (maxY + 1).toDouble(), (maxZ + 1).toDouble() ), ColorHolder(245, 66, 66) - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } } override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index ad44d0589..c022ebd20 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -16,6 +16,7 @@ import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.* import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide @@ -47,40 +48,62 @@ class BreakBlock( override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted breaks blockstates override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, - override val toRender: MutableSet = mutableSetOf(), + override val aabbCompounds: MutableSet = mutableSetOf(), + override val overlayTexts: MutableSet = mutableSetOf(), override var rotation: Vec2f? = null, override var distance: Double = 1337.0, -) : TimeoutActivity, AttemptActivity, RotatingActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { +) : BuildActivity, TimeoutActivity, AttemptActivity, RotatingActivity, TimedActivity, RenderAABBActivity, RenderOverlayTextActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 private var drops: Item = Items.AIR override var context: BuildActivity.Context by Delegates.observable(BuildActivity.Context.NONE) { _, old, new -> if (old == new) return@observable - renderContext.color = new.color + renderContextAABB.color = new.color + + renderContextOverlay.text = new.name + renderContextOverlay.color = new.color } override var availability: BuildActivity.Availability by Delegates.observable(BuildActivity.Availability.NONE) { _, old, new -> if (old == new) return@observable - renderAvailability.color = new.color + renderAvailabilityAABB.color = new.color + + renderAvailabilityOverlay.text = new.name + renderAvailabilityOverlay.color = new.color } override var type: BuildActivity.Type by Delegates.observable(BuildActivity.Type.BREAK_BLOCK) { _, old, new -> if (old == new) return@observable - renderType.color = new.color + renderTypeAABB.color = new.color + + renderTypeOverlay.text = new.name + renderTypeOverlay.color = new.color } - private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( + private val renderContextAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, context.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } - private val renderAvailability = RenderAABBActivity.Companion.RenderBlockPos( + private val renderContextOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + context.name, context.color, blockPos.toVec3dCenter(), 0 + ).also { overlayTexts.add(it) } + + private val renderAvailabilityAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, availability.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } + + private val renderAvailabilityOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + availability.name, availability.color, blockPos.toVec3dCenter(), 1 + ).also { overlayTexts.add(it) } - private val renderType = RenderAABBActivity.Companion.RenderBlockPos( + private val renderTypeAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, type.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } + + private val renderTypeOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + type.name, type.color, blockPos.toVec3dCenter(), 2 + ).also { overlayTexts.add(it) } override var earliestFinish: Long get() = BuildTools.breakDelay.toLong() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 9e39c0ba4..a7386c1db 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,6 +7,7 @@ import baritone.process.BuilderProcess import com.lambda.client.activity.Activity import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity +import com.lambda.client.activity.types.RenderOverlayTextActivity import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools @@ -20,6 +21,7 @@ import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.safeListener +import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.math.AxisAlignedBB @@ -33,16 +35,17 @@ class BuildStructure( private val offsetMove: BlockPos = BlockPos.ORIGIN, private val doPadding: Boolean = false, private val collectAll: Boolean = false, + private val breakBushes: Boolean = false, override val maximumRepeats: Int = 1, override var repeated: Int = 0, - override val toRender: MutableSet = mutableSetOf() + override val aabbCompounds: MutableSet = mutableSetOf() ) : RepeatingActivity, RenderAABBActivity, Activity() { private var currentOffset = BlockPos.ORIGIN private var lastGoal: Goal? = null - private val renderCurrent = RenderAABBActivity.Companion.RenderAABB( + private val renderAABB = RenderAABBActivity.Companion.RenderAABB( AxisAlignedBB(BlockPos.ORIGIN), ColorHolder(255, 255, 255) - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } override fun SafeClientEvent.onInitialize() { structure.forEach { (pos, targetState) -> @@ -62,7 +65,7 @@ class BuildStructure( is PlaceBlock -> { val blockPos = activity.blockPos - renderCurrent.renderAABB = AxisAlignedBB(blockPos).grow(0.1) + renderAABB.renderAABB = AxisAlignedBB(blockPos).grow(0.1) if (!autoPathing) return@safeListener @@ -75,7 +78,7 @@ class BuildStructure( is BreakBlock -> { val blockPos = activity.blockPos - renderCurrent.renderAABB = AxisAlignedBB(blockPos).grow(0.1) + renderAABB.renderAABB = AxisAlignedBB(blockPos).grow(0.1) if (!autoPathing) return@safeListener @@ -132,6 +135,12 @@ class BuildStructure( /* block is not breakable */ if (currentState.getBlockHardness(world, blockPos) < 0) return + /* block is auto breakable like lilypad or tall grass */ + if (!breakBushes && currentState.block is BlockBush) return + + /* block should be ignored */ + if (currentState.block in BuildTools.ignoredBlocks) return + /* only option left is breaking the block */ addSubActivities(BreakBlock( blockPos, collectDrops = collectAll, minCollectAmount = 64 diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 0ef8a50f1..fe61c5b45 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -15,6 +15,7 @@ import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.defaultScope import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.runSafe @@ -47,37 +48,59 @@ class PlaceBlock( override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted placements blockstates override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, - override val toRender: MutableSet = mutableSetOf() -) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, BuildActivity, TimedActivity, Activity() { + override val aabbCompounds: MutableSet = mutableSetOf(), + override val overlayTexts: MutableSet = mutableSetOf(), +) : RotatingActivity, TimeoutActivity, AttemptActivity, RenderAABBActivity, RenderOverlayTextActivity, BuildActivity, TimedActivity, Activity() { private var placeInfo: PlaceInfo? = null private var spoofedDirection = false override var context: BuildActivity.Context by Delegates.observable(BuildActivity.Context.NONE) { _, old, new -> if (old == new) return@observable - renderContext.color = new.color + renderContextAABB.color = new.color + + renderContextOverlay.text = new.name + renderContextOverlay.color = new.color } override var availability: BuildActivity.Availability by Delegates.observable(BuildActivity.Availability.NONE) { _, old, new -> if (old == new) return@observable - renderAvailability.color = new.color + renderAvailabilityAABB.color = new.color + + renderAvailabilityOverlay.text = new.name + renderAvailabilityOverlay.color = new.color } - override var type: BuildActivity.Type by Delegates.observable(BuildActivity.Type.PLACE_BLOCK) { _, old, new -> + override var type: BuildActivity.Type by Delegates.observable(BuildActivity.Type.BREAK_BLOCK) { _, old, new -> if (old == new) return@observable - renderType.color = new.color + renderTypeAABB.color = new.color + + renderTypeOverlay.text = new.name + renderTypeOverlay.color = new.color } - private val renderContext = RenderAABBActivity.Companion.RenderBlockPos( + private val renderContextAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, context.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } - private val renderAvailability = RenderAABBActivity.Companion.RenderBlockPos( + private val renderContextOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + context.name, context.color, blockPos.toVec3dCenter(), 0 + ).also { overlayTexts.add(it) } + + private val renderAvailabilityAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, availability.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } + + private val renderAvailabilityOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + availability.name, availability.color, blockPos.toVec3dCenter(), 1 + ).also { overlayTexts.add(it) } - private val renderType = RenderAABBActivity.Companion.RenderBlockPos( + private val renderTypeAABB = RenderAABBActivity.Companion.RenderBlockPos( blockPos, type.color - ).also { toRender.add(it) } + ).also { aabbCompounds.add(it) } + + private val renderTypeOverlay = RenderOverlayTextActivity.Companion.RenderOverlayText( + type.name, type.color, blockPos.toVec3dCenter(), 2 + ).also { overlayTexts.add(it) } override var earliestFinish: Long get() = BuildTools.placeDelay.toLong() diff --git a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt index 25ac3787b..458a5a481 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt @@ -17,21 +17,22 @@ interface BuildActivity { } enum class Availability(val color: ColorHolder) { - VALID(ColorHolder(222, 0, 0)), + VALID(ColorHolder(0, 255, 0, 0)), WRONG_ITEM_SELECTED(ColorHolder(3, 252, 169)), BLOCKED_BY_PLAYER(ColorHolder(252, 3, 207)), NOT_IN_RANGE(ColorHolder(252, 3, 207)), - NOT_REPLACEABLE(ColorHolder(46, 0, 0, 0)), - NOT_EXPOSED(ColorHolder(46, 0, 0, 0)), - NEEDS_SUPPORT(ColorHolder(35, 15, 254)), - NOT_VISIBLE(ColorHolder(46, 0, 0, 0)), - NEEDS_LIQUID_HANDLING(ColorHolder(114, 27, 255)), + NOT_REPLACEABLE(ColorHolder(46, 0, 0, 30)), + NOT_EXPOSED(ColorHolder(46, 0, 0, 30)), + NEEDS_SUPPORT(ColorHolder(46, 0, 0, 30)), + NOT_VISIBLE(ColorHolder(46, 0, 0, 30)), + NEEDS_LIQUID_HANDLING(ColorHolder(50, 12, 112)), NONE(ColorHolder(11, 11, 11)) } enum class Type(val color: ColorHolder) { LIQUID_FILL(ColorHolder(114, 27, 255)), - BREAK_BLOCK(ColorHolder(255, 0, 0, 0)), - PLACE_BLOCK(ColorHolder(0, 255, 0, 0)), + BREAK_BLOCK(ColorHolder(222, 0, 0)), + IS_SUPPORT(ColorHolder(0, 166, 0)), + PLACE_BLOCK(ColorHolder(35, 188, 254)), } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt index 1a383b9bd..77d67ee1e 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt @@ -10,19 +10,19 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos interface RenderAABBActivity { - val toRender: MutableSet + val aabbCompounds: MutableSet companion object { val normalizedRender: MutableSet = mutableSetOf() - fun SafeClientEvent.checkRender() { + fun SafeClientEvent.checkAABBRender() { normalizedRender.clear() ActivityManager .allSubActivities .filterIsInstance() .forEach { activity -> - activity.toRender.forEach { compound -> + activity.aabbCompounds.forEach { compound -> when (compound) { is RenderAABB -> normalizedRender.add(compound) is RenderBlockPos -> { diff --git a/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt index b5aef815c..e5db5e58c 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt @@ -1,3 +1,37 @@ package com.lambda.client.activity.types -interface RenderOverlayTextActivity \ No newline at end of file +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.util.color.ColorHolder +import net.minecraft.util.math.Vec3d + +interface RenderOverlayTextActivity { + val overlayTexts: MutableSet + + companion object { + val normalizedRender: MutableSet = mutableSetOf() + + fun SafeClientEvent.checkOverlayRender() { + normalizedRender.clear() + + ActivityManager + .allSubActivities + .filterIsInstance() + .forEach { activity -> + activity.overlayTexts.forEach { compound -> + normalizedRender.add(compound) + } + } + } + + interface RenderOverlayTextCompound + + data class RenderOverlayText( + var text: String, + var color: ColorHolder = ColorHolder(255, 255, 255), + var origin: Vec3d, + var index: Int = 0, + var scale: Float = 1f, + ) : RenderOverlayTextCompound + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 33b0e9638..a0486907f 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -2,21 +2,31 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.types.RenderAABBActivity -import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender +import com.lambda.client.activity.types.RenderOverlayTextActivity +import com.lambda.client.activity.types.RenderOverlayTextActivity.Companion.checkOverlayRender import com.lambda.client.activity.types.TimedActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager +import com.lambda.client.event.events.RenderOverlayEvent import com.lambda.client.event.events.RenderWorldEvent +import com.lambda.client.event.listener.listener import com.lambda.client.manager.Manager import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick +import com.lambda.client.module.modules.client.BuildTools.textScale import com.lambda.client.module.modules.client.BuildTools.tickDelay import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.TickTimer import com.lambda.client.util.TimeUnit import com.lambda.client.util.graphics.ESPRenderer +import com.lambda.client.util.graphics.GlStateUtils +import com.lambda.client.util.graphics.ProjectionUtils +import com.lambda.client.util.graphics.font.FontRenderAdapter +import com.lambda.client.util.math.VectorUtils.toVec3dCenter import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.opengl.GL11 object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() @@ -53,15 +63,16 @@ object ActivityManager : Manager, Activity() { } updateActivity() - checkRender() + checkOverlayRender() + checkAABBRender() } lastActivity = current } } - safeListener { - if (hasNoSubActivities) return@safeListener + listener { + if (hasNoSubActivities) return@listener renderer.aFilled = BuildTools.aFilled renderer.aOutline = BuildTools.aOutline @@ -73,6 +84,27 @@ object ActivityManager : Manager, Activity() { renderer.render(true) } + + listener { + if (hasNoSubActivities) return@listener + + GlStateUtils.rescaleActual() + + RenderOverlayTextActivity.normalizedRender.forEach { renderText -> + GL11.glPushMatrix() + val screenPos = ProjectionUtils.toScreenPos(renderText.origin) + GL11.glTranslated(screenPos.x, screenPos.y, 0.0) + GL11.glScalef(textScale * 2.0f, textScale * 2.0f, 1.0f) + + val halfWidth = FontRenderAdapter.getStringWidth(renderText.text) / -2.0f + val lineHeight = FontRenderAdapter.getFontHeight() + 2.0f + val yLift = lineHeight * 3 / 2 + + FontRenderAdapter.drawString(renderText.text, halfWidth, lineHeight * renderText.index - yLift, color = renderText.color) + + GL11.glPopMatrix() + } + } } override fun getCurrentActivity(): Activity { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index c5c976511..41c4bb63c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -83,8 +83,8 @@ object BuildTools : Module( val outline by setting("Outline", true, { page == Page.RENDER }, description = "Renders colored task outlines") // val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") // val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") -// val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") -// val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") + private val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") + val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") // val distScaleFactor by setting("Distance Scale Factor", 0.05f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) // val minDistScale by setting("Min Distance Scale", 0.35f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.RENDER }, description = "Sets the opacity") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 39ab1eb6f..560c1fe2e 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -7,7 +7,7 @@ import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.BreakDownEnderChests import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.travel.PickUpDrops -import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkRender +import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category @@ -127,7 +127,7 @@ object TestActivityManager : Module( runSafe { with(ActivityManager.getCurrentActivity()) { updateActivity() - checkRender() + checkAABBRender() } } } From 9d691941e4bda0ee4b73abbcc25c1b5f408b4fca Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 5 May 2023 19:04:51 +0200 Subject: [PATCH 086/104] Add render settings and graffiti module --- .../activities/construction/Graffiti.kt | 31 +++++++ .../construction/core/BuildStructure.kt | 1 - .../activities/interaction/AttachItemFrame.kt | 82 +++++++++++++++++++ .../activities/interaction/AttachMap.kt | 58 +++++++++++++ .../types/RenderOverlayTextActivity.kt | 16 +++- .../manager/managers/ActivityManager.kt | 4 + .../module/modules/client/BuildTools.kt | 4 +- .../modules/misc/TestActivityManager.kt | 8 ++ .../client/module/modules/misc/WorldEater.kt | 17 +--- 9 files changed, 202 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt new file mode 100644 index 000000000..5ef799930 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt @@ -0,0 +1,31 @@ +package com.lambda.client.activity.activities.construction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.interaction.AttachItemFrame +import com.lambda.client.activity.activities.interaction.AttachMap +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.world.isReplaceable +import net.minecraft.entity.item.EntityItemFrame +import net.minecraft.util.EnumFacing + +class Graffiti : Activity() { + override fun SafeClientEvent.onInitialize() { + VectorUtils.getBlockPosInSphere(player.positionVector, 5.0f) + .filter { world.getBlockState(it).isReplaceable } + .forEach { + addSubActivities( + AttachItemFrame(player.heldItemMainhand, it, player.horizontalFacing.opposite) + ) + } + + world.loadedEntityList + .filterIsInstance() + .forEach { + addSubActivities( + AttachMap(it, player.heldItemMainhand) + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index a7386c1db..66115e37e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,7 +7,6 @@ import baritone.process.BuilderProcess import com.lambda.client.activity.Activity import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity -import com.lambda.client.activity.types.RenderOverlayTextActivity import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt new file mode 100644 index 000000000..1203add8b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt @@ -0,0 +1,82 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.LambdaMod +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot +import com.lambda.client.activity.types.RotatingActivity +import com.lambda.client.activity.types.TimeoutActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe +import com.lambda.client.util.threads.safeListener +import com.lambda.client.util.world.getHitVec +import kotlinx.coroutines.launch +import net.minecraft.item.ItemStack +import net.minecraft.network.play.server.SPacketSpawnObject +import net.minecraft.util.EnumFacing +import net.minecraft.util.EnumHand +import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent + +class AttachItemFrame( + private val itemFrame: ItemStack, + private val placePos: BlockPos, + private val facing: EnumFacing, + override var rotation: Vec2f? = null, + override var timeout: Long = 1000L +) : RotatingActivity, TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + rotation = getRotationTo(getHitVec(placePos, facing)) + + player.inventorySlots.firstOrNull { + ItemStack.areItemStacksEqual(it.stack, itemFrame) + }?.let { + addSubActivities( + SwapOrSwitchToSlot(it) + ) + } + } + + init { + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + + LambdaMod.LOG.info(playerController.processRightClickBlock( + player, + world, + placePos, + facing, + getHitVec(placePos, facing), + EnumHand.MAIN_HAND + )) + } + + safeListener { + if (it.packet !is SPacketSpawnObject) return@safeListener + if (it.packet.type != 71) return@safeListener + + defaultScope.launch { + onMainThreadSafe { + success() + } + } + } + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is SwapOrSwitchToSlot) return + + LambdaMod.LOG.info(playerController.processRightClickBlock( + player, + world, + placePos, + facing, + getHitVec(placePos, facing), + EnumHand.MAIN_HAND + )) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt new file mode 100644 index 000000000..4b24eaf1a --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -0,0 +1,58 @@ +package com.lambda.client.activity.activities.interaction + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot +import com.lambda.client.activity.types.RotatingActivity +import com.lambda.client.activity.types.TimeoutActivity +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.math.RotationUtils.getRotationToEntity +import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe +import com.lambda.client.util.threads.safeListener +import kotlinx.coroutines.launch +import net.minecraft.entity.item.EntityItemFrame +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.CPacketUseEntity +import net.minecraft.network.play.server.SPacketSpawnObject +import net.minecraft.util.EnumHand + +class AttachMap( + private val itemFrame: EntityItemFrame, + private val map: ItemStack, + override var rotation: Vec2f? = null, + override var timeout: Long = 1000L +) : RotatingActivity, TimeoutActivity, Activity() { + override fun SafeClientEvent.onInitialize() { + rotation = getRotationToEntity(itemFrame) + + player.inventorySlots.firstOrNull { + ItemStack.areItemStacksEqual(it.stack, map) + }?.let { + addSubActivities( + SwapOrSwitchToSlot(it) + ) + } + } + + init { + safeListener { + if (it.packet !is SPacketSpawnObject) return@safeListener + if (it.packet.entityID != itemFrame.entityId) return@safeListener + + defaultScope.launch { + onMainThreadSafe { + success() + } + } + } + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is SwapOrSwitchToSlot) return + + connection.sendPacket(CPacketUseEntity(itemFrame, EnumHand.MAIN_HAND)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt index e5db5e58c..7ef642f38 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderOverlayTextActivity.kt @@ -2,7 +2,11 @@ package com.lambda.client.activity.types import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager +import com.lambda.client.module.modules.client.BuildTools.maxDebugAmount +import com.lambda.client.module.modules.client.BuildTools.maxDebugRange +import com.lambda.client.module.modules.client.BuildTools.showDebugRender import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.util.math.Vec3d interface RenderOverlayTextActivity { @@ -12,15 +16,21 @@ interface RenderOverlayTextActivity { val normalizedRender: MutableSet = mutableSetOf() fun SafeClientEvent.checkOverlayRender() { + if (!showDebugRender) return + normalizedRender.clear() ActivityManager .allSubActivities .filterIsInstance() .forEach { activity -> - activity.overlayTexts.forEach { compound -> - normalizedRender.add(compound) - } + activity.overlayTexts + .sortedBy { player.distanceTo(it.origin) } + .filter { player.distanceTo(it.origin) < maxDebugRange } + .take(maxDebugAmount) + .forEach { compound -> + normalizedRender.add(compound) + } } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index a0486907f..5aa49030d 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -16,6 +16,7 @@ import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick import com.lambda.client.module.modules.client.BuildTools.textScale import com.lambda.client.module.modules.client.BuildTools.tickDelay +import com.lambda.client.module.modules.player.AutoEat import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.TickTimer import com.lambda.client.util.TimeUnit @@ -39,6 +40,9 @@ object ActivityManager : Manager, Activity() { || event.phase != TickEvent.Phase.START ) return@safeListener + /* life support systems */ + if (AutoEat.eating) return@safeListener + allSubActivities .filter { it.status == Status.RUNNING && it.subActivities.isEmpty() } .forEach { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 41c4bb63c..0d6b5348a 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -83,7 +83,9 @@ object BuildTools : Module( val outline by setting("Outline", true, { page == Page.RENDER }, description = "Renders colored task outlines") // val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") // val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") - private val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") + val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") + val maxDebugRange by setting("Max Debug Range", 8, 0..256, 1, { page == Page.RENDER && showDebugRender }, description = "Max distance to render debug info", unit = " blocks") + val maxDebugAmount by setting("Max Debug Amount", 20, 0..256, 1, { page == Page.RENDER && showDebugRender }, description = "Max amount of debug info to render") val textScale by setting("Text Scale", 1.0f, 0.0f..4.0f, 0.25f, { page == Page.RENDER && showDebugRender }, description = "Scale of debug text") // val distScaleFactor by setting("Distance Scale Factor", 0.05f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) // val minDistScale by setting("Min Distance Scale", 0.35f, 0.0f..1.0f, 0.05f, { page == Page.RENDER && showDebugRender }) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 560c1fe2e..a5282fa16 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -1,5 +1,6 @@ package com.lambda.client.module.modules.misc +import com.lambda.client.activity.activities.construction.Graffiti import com.lambda.client.activity.activities.construction.SurroundWithObsidian import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.interaction.crafting.ReachXPLevel @@ -48,6 +49,13 @@ object TestActivityManager : Module( false }) + private val ectiectietit by setting("Graffiti", false, consumer = { _, _-> + addSubActivities( + Graffiti() + ) + false + }) + private val eticiettie by setting("Direction shenanigans", false, consumer = { _, _-> runSafe { var currentDirection = player.horizontalFacing diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 4c89306f3..ffb7a5e56 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -39,9 +39,10 @@ object WorldEater : Module( init { onEnable { runSafe { + val origin = player.flooredPosition val currentDirection = player.horizontalFacing - firstPos = player.flooredPosition.add(currentDirection.directionVec.multiply(2)) - secondPos = player.flooredPosition.add( + firstPos = origin.add(currentDirection.directionVec) + secondPos = origin.add( currentDirection.directionVec.multiply(size) ).add( currentDirection.rotateY().directionVec.multiply(size) @@ -59,18 +60,6 @@ object WorldEater : Module( ownedBuildStructure = null } } - - safeListener { - mc.objectMouseOver?.let { result -> - if (result.typeOfHit != RayTraceResult.Type.BLOCK) return@safeListener - - when (Mouse.getEventButton()) { - 0 -> firstPos = result.blockPos - 1 -> secondPos = result.blockPos -// 2 -> if (ownedBuildStructure == null) clearArea() - } - } - } } private fun clearArea() { From 077e869150ad52f4c7ca577a1e451f386dbd3ebf Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 5 May 2023 22:04:24 +0200 Subject: [PATCH 087/104] Fix Graffiti logic --- .../activities/construction/Graffiti.kt | 38 ++++++++++++++----- .../activities/interaction/AttachItemFrame.kt | 32 +++------------- .../activities/interaction/AttachMap.kt | 15 ++++---- .../client/module/modules/misc/Graffiti.kt | 30 +++++++++++++++ 4 files changed, 72 insertions(+), 43 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt index 5ef799930..3afdc4798 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt @@ -3,28 +3,48 @@ package com.lambda.client.activity.activities.construction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.AttachItemFrame import com.lambda.client.activity.activities.interaction.AttachMap +import com.lambda.client.activity.types.LoopWhileActivity +import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.misc.Graffiti import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.VectorUtils +import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.world.getNeighbour import com.lambda.client.util.world.isReplaceable import net.minecraft.entity.item.EntityItemFrame import net.minecraft.util.EnumFacing -class Graffiti : Activity() { +class Graffiti( + private val mapID: Int, + override val loopWhile: SafeClientEvent.() -> Boolean = { Graffiti.isEnabled }, + override var currentLoops: Int = 0 +) : LoopWhileActivity, Activity() { override fun SafeClientEvent.onInitialize() { - VectorUtils.getBlockPosInSphere(player.positionVector, 5.0f) - .filter { world.getBlockState(it).isReplaceable } - .forEach { + val range = 4.95f + + // 1. Check for missing maps in item frames + world.loadedEntityList + .filterIsInstance() + .minByOrNull { player.distanceTo(it.positionVector) } + ?.let { + if (player.distanceTo(it.positionVector) > range) return + addSubActivities( - AttachItemFrame(player.heldItemMainhand, it, player.horizontalFacing.opposite) + AttachMap(it, mapID) ) + return } - world.loadedEntityList - .filterIsInstance() - .forEach { + // 2. Check for surface to place item frames on and place it + VectorUtils.getBlockPosInSphere(player.positionVector, range) + .mapNotNull { getNeighbour(it, 1, range, true, EnumFacing.HORIZONTALS) } + .minByOrNull { player.distanceTo(it.hitVec) } + ?.let { + if (player.distanceTo(it.hitVec) > range) return + addSubActivities( - AttachMap(it, player.heldItemMainhand) + AttachItemFrame(it.pos, it.side) ) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt index 1203add8b..b0c0ed683 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt @@ -2,12 +2,11 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.defaultScope @@ -15,15 +14,13 @@ import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import kotlinx.coroutines.launch -import net.minecraft.item.ItemStack +import net.minecraft.init.Items import net.minecraft.network.play.server.SPacketSpawnObject import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraftforge.fml.common.gameevent.TickEvent class AttachItemFrame( - private val itemFrame: ItemStack, private val placePos: BlockPos, private val facing: EnumFacing, override var rotation: Vec2f? = null, @@ -32,29 +29,12 @@ class AttachItemFrame( override fun SafeClientEvent.onInitialize() { rotation = getRotationTo(getHitVec(placePos, facing)) - player.inventorySlots.firstOrNull { - ItemStack.areItemStacksEqual(it.stack, itemFrame) - }?.let { - addSubActivities( - SwapOrSwitchToSlot(it) - ) - } + addSubActivities( + AcquireItemInActiveHand(Items.ITEM_FRAME) + ) } init { - safeListener { - if (it.phase != TickEvent.Phase.START) return@safeListener - - LambdaMod.LOG.info(playerController.processRightClickBlock( - player, - world, - placePos, - facing, - getHitVec(placePos, facing), - EnumHand.MAIN_HAND - )) - } - safeListener { if (it.packet !is SPacketSpawnObject) return@safeListener if (it.packet.type != 71) return@safeListener @@ -68,7 +48,7 @@ class AttachItemFrame( } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is SwapOrSwitchToSlot) return + if (childActivity !is AcquireItemInActiveHand) return LambdaMod.LOG.info(playerController.processRightClickBlock( player, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index 4b24eaf1a..a7f29a359 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -1,11 +1,13 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.util.items.HotbarSlot import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.RotationUtils.getRotationToEntity import com.lambda.client.util.math.Vec2f @@ -14,6 +16,7 @@ import com.lambda.client.util.threads.onMainThreadSafe import com.lambda.client.util.threads.safeListener import kotlinx.coroutines.launch import net.minecraft.entity.item.EntityItemFrame +import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketUseEntity import net.minecraft.network.play.server.SPacketSpawnObject @@ -21,20 +24,16 @@ import net.minecraft.util.EnumHand class AttachMap( private val itemFrame: EntityItemFrame, - private val map: ItemStack, + private val mapID: Int, override var rotation: Vec2f? = null, override var timeout: Long = 1000L ) : RotatingActivity, TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { rotation = getRotationToEntity(itemFrame) - player.inventorySlots.firstOrNull { - ItemStack.areItemStacksEqual(it.stack, map) - }?.let { - addSubActivities( - SwapOrSwitchToSlot(it) - ) - } + addSubActivities( + AcquireItemInActiveHand(Items.MAP, predicateStack = { it.itemDamage == mapID }), + ) } init { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt new file mode 100644 index 000000000..ef24a7dac --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt @@ -0,0 +1,30 @@ +package com.lambda.client.module.modules.misc + +import com.lambda.client.activity.activities.construction.Graffiti +import com.lambda.client.manager.managers.ActivityManager.addSubActivities +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import com.lambda.client.util.threads.runSafe + +object Graffiti : Module( + name = "Graffiti", + description = "Spams item frames and maps", + category = Category.MISC +) { + private val mapID by setting("Map ID", 0, 0..65535, 1) + private val ownedActivity = Graffiti() + + init { + onEnable { + addSubActivities(ownedActivity) + } + + onDisable { + runSafe { + with(ownedActivity) { + cancel() + } + } + } + } +} \ No newline at end of file From 0d7987ecebdcd8432b866d16f20d9a70974284ef Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 29 May 2023 03:12:34 +0200 Subject: [PATCH 088/104] Graffiti, StorageManagement, BlockPos setting and auto crafting --- .../construction/core/BuildStructure.kt | 2 + .../activities/interaction/AttachMap.kt | 2 +- .../interaction/crafting/CraftShulkerBox.kt | 19 +++++ .../interaction/crafting/CraftSimpleRecipe.kt | 18 ++++ .../activities/storage/ReplenishInventory.kt | 6 ++ .../activities/storage/StoreItemsToStash.kt | 63 ++++++++++++++ .../activity/activities/travel/CustomGoal.kt | 2 +- .../command/commands/BuildToolsCommand.kt | 23 +++++ .../command/commands/WorldEaterCommand.kt | 83 +++++++++++++++++++ .../manager/managers/ActivityManager.kt | 16 ++++ .../module/modules/client/BuildTools.kt | 10 ++- .../client/module/modules/misc/Graffiti.kt | 15 ++-- .../modules/misc/TestActivityManager.kt | 2 +- .../client/module/modules/misc/WorldEater.kt | 52 +++++++----- .../setting/settings/SettingRegister.kt | 10 +++ .../settings/impl/other/BlockPosSetting.kt | 11 +++ 16 files changed, 301 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt create mode 100644 src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt create mode 100644 src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 66115e37e..89d488485 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -19,6 +19,7 @@ import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState @@ -109,6 +110,7 @@ class BuildStructure( } }) return@safeListener + MessageSendHelper.sendWarningMessage("Block changed at $blockPos") createBuildActivity(blockPos, targetState) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index a7f29a359..e87f22814 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -50,7 +50,7 @@ class AttachMap( } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is SwapOrSwitchToSlot) return + if (childActivity !is AcquireItemInActiveHand) return connection.sendPacket(CPacketUseEntity(itemFrame, EnumHand.MAIN_HAND)) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt new file mode 100644 index 000000000..ec2831541 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt @@ -0,0 +1,19 @@ +package com.lambda.client.activity.activities.interaction.crafting + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.inventory.core.InventoryTransaction +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.item +import net.minecraft.init.Blocks +import net.minecraft.init.Items + +class CraftShulkerBox : Activity() { + override fun SafeClientEvent.onInitialize() { + addSubActivities( + AcquireItemInActiveHand(Items.SHULKER_SHELL), + AcquireItemInActiveHand(Blocks.CHEST.item), +// InventoryTransaction(0, ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt new file mode 100644 index 000000000..b6acf9c03 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt @@ -0,0 +1,18 @@ +package com.lambda.client.activity.activities.interaction.crafting + +import com.lambda.client.activity.Activity +import com.lambda.client.event.SafeClientEvent +import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox + +class CraftSimpleRecipe(val item: Item) : Activity() { + override fun SafeClientEvent.onInitialize() { + when(item) { + is ItemShulkerBox -> { + addSubActivities( + + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt new file mode 100644 index 000000000..377e2a6a3 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt @@ -0,0 +1,6 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity + +class ReplenishInventory : Activity() { +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt new file mode 100644 index 000000000..48493258d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt @@ -0,0 +1,63 @@ +package com.lambda.client.activity.activities.storage + +import baritone.api.pathing.goals.GoalGetToBlock +import baritone.api.pathing.goals.GoalNear +import baritone.api.pathing.goals.GoalXZ +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.OpenContainer +import com.lambda.client.activity.activities.storage.core.PushItemsToContainer +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.util.EntityUtils.flooredPosition +import com.lambda.client.util.math.VectorUtils.distanceTo +import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos + +class StoreItemsToStash(val items: List) : Activity() { + private var originalPosition: BlockPos = BlockPos.ORIGIN + + override fun SafeClientEvent.onInitialize() { + originalPosition = player.flooredPosition + + addSubActivities( + CustomGoal(GoalNear(BuildTools.storagePos1.value, 10), timeout = 999999L) + ) + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + when (childActivity) { + is CustomGoal -> { + if (childActivity.goal !is GoalNear) return + + val chestsInArea = world.loadedTileEntityList.filter { + BlockPos.getAllInBox(BuildTools.storagePos1.value, BuildTools.storagePos2.value).contains(it.pos) + } + + val useChest = chestsInArea.minByOrNull { chest -> + player.distanceTo(chest.pos) + } ?: return failedWith(NoChestFoundException()) + + addSubActivities( + CustomGoal(GoalGetToBlock(useChest.pos)), + OpenContainer(useChest.pos) + ) + + items.forEach { + addSubActivities(PushItemsToContainer(it, 0), ) + } + + addSubActivities(CloseContainer()) + + // replenish items + + addSubActivities( + CustomGoal(GoalXZ(originalPosition.x, originalPosition.z), timeout = 999999L) + ) + } + } + } + + class NoChestFoundException : Exception("No chest found in area!") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index 0821aa08d..766f7808b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -10,7 +10,7 @@ import com.lambda.client.util.threads.safeListener import net.minecraftforge.fml.common.gameevent.TickEvent class CustomGoal( - private val goal: Goal, + val goal: Goal, override val timeout: Long = 100000L ) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { diff --git a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt index 552231d68..279f0a4fd 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt @@ -131,5 +131,28 @@ object BuildToolsCommand : ClientCommand( MessageSendHelper.sendChatMessage("Food item: &7${BuildTools.defaultFood.registryName}&r") } } + + literal("storage") { + literal("add", "new", "+") { + blockPos("pos1") { pos1 -> + blockPos("pos2") { pos2 -> + execute("Sets storage area") { + BuildTools.storagePos1.value = pos1.value + BuildTools.storagePos2.value = pos2.value + MessageSendHelper.sendChatMessage("Added storage area (${pos1.value}x${pos2.value}). Use &7${prefix}buildtools storage remove&r to remove it.") +// BuildTools.storageAreas.add(it.args[0].value to it.args[1].value) +// MessageSendHelper.sendChatMessage("Added storage area with id ${BuildTools.storageAreas.size - 1}.") + } + } + } + } + literal("remove", "rem", "-") { + int("id") { + execute("Not yet implemented") { + MessageSendHelper.sendChatMessage("Not yet implemented.") + } + } + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt new file mode 100644 index 000000000..80b5c08c6 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -0,0 +1,83 @@ +package com.lambda.client.command.commands + +import com.lambda.client.command.ClientCommand +import com.lambda.client.command.commands.BuildToolsCommand.blockPos +import com.lambda.client.command.commands.BuildToolsCommand.execute +import com.lambda.client.command.commands.BuildToolsCommand.int +import com.lambda.client.command.commands.BuildToolsCommand.literal +import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.module.modules.misc.WorldEater +import com.lambda.client.util.math.CoordinateConverter.asString +import com.lambda.client.util.text.MessageSendHelper + +object WorldEaterCommand : ClientCommand( + name = "worldeater", + alias = arrayOf("we"), + description = "World eater command" +) { + init { + literal("start") { + execute("Start world eater") { + WorldEater.startClearingArea() + } + } + + literal("pickup") { + literal("add", "new", "+") { + item("item") { itemArg -> + execute("Add item to pickup list") { + val added = WorldEater.collectables.add(itemArg.value.registryName.toString()) + if (added) { + MessageSendHelper.sendChatMessage("Added &7${itemArg.value.registryName}&r to pickup list.") + } else { + MessageSendHelper.sendChatMessage("&7${itemArg.value.registryName}&r is already on the pickup list.") + } + } + } + } + + literal("remove") { + item("item") { itemArg -> + execute("Remove item from pickup list") { + val removed = WorldEater.collectables.remove(itemArg.value.registryName.toString()) + if (removed) { + MessageSendHelper.sendChatMessage("Removed &7${itemArg.value.registryName}&r from pickup list.") + } else { + MessageSendHelper.sendChatMessage("&7${itemArg.value.registryName}&r is not on the pickup list.") + } + } + } + } + } + + literal("area") { + literal("add", "new", "+") { + blockPos("pos1") { pos1 -> + blockPos("pos2") { pos2 -> + execute("Sets excavating area") { + WorldEater.pos1.value = pos1.value + WorldEater.pos2.value = pos2.value + MessageSendHelper.sendChatMessage("Added excavating area (${pos1.value}x${pos2.value}).") +// BuildTools.storageAreas.add(it.args[0].value to it.args[1].value) +// MessageSendHelper.sendChatMessage("Added storage area with id ${BuildTools.storageAreas.size - 1}.") + } + } + } + } + literal("remove", "rem", "-") { + int("id") { + execute("Not yet implemented") { + MessageSendHelper.sendChatMessage("Not yet implemented.") + } + } + } + } + + execute("General setting info") { + MessageSendHelper.sendChatMessage("World eater settings:") + MessageSendHelper.sendChatMessage(" &7${WorldEater.collectables.size}&r items on pickup list.") + MessageSendHelper.sendChatMessage(" &7${WorldEater.pos1.value.asString()}&r is position 1.") + MessageSendHelper.sendChatMessage(" &7${WorldEater.pos2.value.asString()}&r is position 2.") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 5aa49030d..7e13048cb 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,6 +1,8 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.inventory.DumpSlot +import com.lambda.client.activity.activities.storage.StoreItemsToStash import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.activity.types.RenderOverlayTextActivity @@ -24,8 +26,14 @@ import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.graphics.GlStateUtils import com.lambda.client.util.graphics.ProjectionUtils import com.lambda.client.util.graphics.font.FontRenderAdapter +import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.item +import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener +import net.minecraft.init.Blocks import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.GL11 @@ -43,6 +51,14 @@ object ActivityManager : Manager, Activity() { /* life support systems */ if (AutoEat.eating) return@safeListener + if (BuildTools.storageManagement + && subActivities.filterIsInstance().isEmpty() + && player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots + ) { + MessageSendHelper.sendChatMessage("Inventory full, storing items to stash at ${BuildTools.storagePos1.value.asString()}") + addSubActivities(StoreItemsToStash(listOf(Blocks.STONE.item, Blocks.DIRT.item))) + } + allSubActivities .filter { it.status == Status.RUNNING && it.subActivities.isEmpty() } .forEach { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 0d6b5348a..76e7dedef 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -10,6 +10,7 @@ import net.minecraft.block.Block import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos object BuildTools : Module( name = "BuildTools", @@ -54,13 +55,15 @@ object BuildTools : Module( val directionForce by setting("Block Direction Exploit", true, { page == Page.BUILDING }, description = "EXPLOIT: Forces the direction of the block to be placed") /* storage management */ -// val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") + val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") + val storagePos1 = setting("Storage Pos 1", BlockPos.ORIGIN) + val storagePos2 = setting("Storage Pos 2", BlockPos.ORIGIN) // val searchEChest by setting("Search Ender Chest", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Allow access to your ender chest") // val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers") // val grindObsidian by setting("Grind Obsidian", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Destroy Ender Chests to obtain Obsidian") // val pickupRadius by setting("Pickup radius", 8, 1..50, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the radius for pickup", unit = " blocks") // val fastFill by setting("Fast Fill", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Moves as many item stacks to inventory as possible") -// val keepFreeSlots by setting("Free Slots", 1, 0..30, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many inventory slots are untouched on refill", unit = " slots") + val keepFreeSlots by setting("Free Slots", 1, 0..30, 1, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "How many inventory slots are untouched on refill", unit = " slots") // val lockSlotHotkey by setting("Lock Slot Hotkey", Bind(), { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Sets the hotkey for locking a slot") // val manageFood by setting("Manage Food", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") // val manageTools by setting("Manage Tools", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to manage food") @@ -69,6 +72,7 @@ object BuildTools : Module( // val leastFood by setting("Least Food", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT && manageFood && storageManagement }, description = "How many food items are saved") // val preferEnderChests by setting("Prefer Ender Chests", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Prevent using raw material shulkers") + /* tools */ val usePickaxe by setting("Force Pickaxe", true, { page == Page.TOOLS }, description = "Use pickaxe to mine blocks") val useAxe by setting("Force Axe", true, { page == Page.TOOLS }, description = "Use axe to mine blocks") val useShovel by setting("Force Shovel", true, { page == Page.TOOLS }, description = "Use shovel to mine blocks") @@ -103,7 +107,7 @@ object BuildTools : Module( // val proxyCommand by setting("Proxy Command", "/dc", { page == Page.MISC && disableMode == DisableMode.LOGOUT && usingProxy }, description = "Command to be sent to log out") private enum class Page { - BUILDING, TOOLS, RENDER + BUILDING, STORAGE_MANAGEMENT, TOOLS, RENDER } enum class DebugLevel { diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt index ef24a7dac..6294fdbdb 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/Graffiti.kt @@ -11,18 +11,23 @@ object Graffiti : Module( description = "Spams item frames and maps", category = Category.MISC ) { - private val mapID by setting("Map ID", 0, 0..65535, 1) - private val ownedActivity = Graffiti() + private val mapID = setting("Map ID", 0, 0..65535, 1) + private var ownedActivity: Graffiti? = null init { onEnable { - addSubActivities(ownedActivity) + Graffiti(mapID.value).let { + ownedActivity = it + addSubActivities(it) + } } onDisable { runSafe { - with(ownedActivity) { - cancel() + ownedActivity?.let { + with(it) { + cancel() + } } } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index a5282fa16..aeecc0802 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -51,7 +51,7 @@ object TestActivityManager : Module( private val ectiectietit by setting("Graffiti", false, consumer = { _, _-> addSubActivities( - Graffiti() + Graffiti(100) ) false }) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index ffb7a5e56..5c6b4005f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,19 +1,16 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.ClearArea -import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.client.setting.settings.impl.collection.CollectionSetting import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.runSafe -import com.lambda.client.util.threads.safeListener +import net.minecraft.item.Item import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.RayTraceResult -import net.minecraftforge.fml.common.gameevent.InputEvent -import org.lwjgl.input.Mouse object WorldEater : Module( name = "WorldEater", @@ -28,25 +25,36 @@ object WorldEater : Module( private val sliceDirection by setting("Slice direction", EnumFacing.NORTH) private val collectAll by setting("Collect all", false) private val start by setting("Start", false, consumer = { _, _ -> - clearArea() + runSafe { + val origin = player.flooredPosition + val currentDirection = player.horizontalFacing + val firstPos = origin.add(currentDirection.directionVec) + val secondPos = origin.add( + currentDirection.directionVec.multiply(size) + ).add( + currentDirection.rotateY().directionVec.multiply(size) + ).down(depth) + + startClearingArea(firstPos, secondPos) + } false }) + val collectables = setting(CollectionSetting("Pick up items", linkedSetOf("minecraft:dirt", "minecraft:cobblestone"))) + val pos1 = setting("Pos1", BlockPos.ORIGIN) + val pos2 = setting("Pos2", BlockPos.ORIGIN) + + val stashes = setting(CollectionSetting("Stashes", linkedSetOf())) + val dropOff = setting(CollectionSetting("Drop off", linkedSetOf())) + + val pickUp: List + get() = collectables.value.mapNotNull { Item.getByNameOrId(it) } private var ownedBuildStructure: ClearArea? = null - private var firstPos: BlockPos? = null - private var secondPos: BlockPos? = null init { onEnable { runSafe { - val origin = player.flooredPosition - val currentDirection = player.horizontalFacing - firstPos = origin.add(currentDirection.directionVec) - secondPos = origin.add( - currentDirection.directionVec.multiply(size) - ).add( - currentDirection.rotateY().directionVec.multiply(size) - ).down(depth) + startClearingArea() } } @@ -62,13 +70,13 @@ object WorldEater : Module( } } - private fun clearArea() { - val first = firstPos ?: return - val second = secondPos ?: return - + fun startClearingArea( + pos1: BlockPos = this.pos1.value, + pos2: BlockPos = this.pos2.value + ) { ClearArea( - first, - second, + pos1, + pos2, layerSize, sliceSize, collectAll = collectAll diff --git a/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt b/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt index fa781204c..41440743d 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt @@ -4,12 +4,14 @@ import com.lambda.client.setting.settings.impl.number.DoubleSetting import com.lambda.client.setting.settings.impl.number.FloatSetting import com.lambda.client.setting.settings.impl.number.IntegerSetting import com.lambda.client.setting.settings.impl.other.BindSetting +import com.lambda.client.setting.settings.impl.other.BlockPosSetting import com.lambda.client.setting.settings.impl.other.ColorSetting import com.lambda.client.setting.settings.impl.primitive.BooleanSetting import com.lambda.client.setting.settings.impl.primitive.EnumSetting import com.lambda.client.setting.settings.impl.primitive.StringSetting import com.lambda.client.util.Bind import com.lambda.client.util.color.ColorHolder +import net.minecraft.util.math.BlockPos import java.util.function.BooleanSupplier /** @@ -75,6 +77,14 @@ interface SettingRegister { description: String = "" ) = setting(ColorSetting(name, value, hasAlpha, visibility, description)) + /** BlockPos Setting */ + fun T.setting( + name: String, + value: BlockPos, + visibility: () -> Boolean = { true }, + description: String = "" + ) = setting(BlockPosSetting(name, value, visibility, description)) + /** Boolean Setting */ fun T.setting( name: String, diff --git a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt new file mode 100644 index 000000000..48fa11857 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt @@ -0,0 +1,11 @@ +package com.lambda.client.setting.settings.impl.other + +import com.lambda.client.setting.settings.MutableSetting +import net.minecraft.util.math.BlockPos + +class BlockPosSetting( + name: String, + value: BlockPos, + visibility: () -> Boolean = { true }, + description: String = "" +) : MutableSetting(name, value, visibility, { _, input -> input }, description, unit = "") \ No newline at end of file From d47d22e0c9636a006b12106ab7c77db3ea247d7e Mon Sep 17 00:00:00 2001 From: Constructor Date: Sat, 3 Jun 2023 02:52:56 +0200 Subject: [PATCH 089/104] Quality of life settings for WorldEater --- .../activities/construction/ClearArea.kt | 32 +++-- .../command/commands/WorldEaterCommand.kt | 118 +++++++++++++--- .../client/module/modules/misc/WorldEater.kt | 128 ++++++++++++------ .../serializables/BlockPosSerializer.kt | 18 +++ .../setting/serializables/BlockSerializer.kt | 16 +++ .../setting/serializables/ItemSerializer.kt | 16 +++ .../setting/settings/AbstractSetting.kt | 13 +- .../impl/collection/CollectionSetting.kt | 6 +- 8 files changed, 267 insertions(+), 80 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/setting/serializables/BlockPosSerializer.kt create mode 100644 src/main/kotlin/com/lambda/client/setting/serializables/BlockSerializer.kt create mode 100644 src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index d49819540..cfc4a508d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -1,10 +1,15 @@ package com.lambda.client.activity.activities.construction +import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks import net.minecraft.util.EnumFacing @@ -12,41 +17,42 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class ClearArea( - pos1: BlockPos, - pos2: BlockPos, + private val area: WorldEater.Area, private val layerSize: Int = 1, private val sliceSize: Int = 1, private val sliceDirection: EnumFacing = EnumFacing.NORTH, private val collectAll: Boolean = false, override val aabbCompounds: MutableSet = mutableSetOf() ) : RenderAABBActivity, Activity() { - private val minX = minOf(pos1.x, pos2.x) - private val minY = minOf(pos1.y, pos2.y) - private val minZ = minOf(pos1.z, pos2.z) - private val maxX = maxOf(pos1.x, pos2.x) - private val maxY = maxOf(pos1.y, pos2.y) - private val maxZ = maxOf(pos1.z, pos2.z) init { RenderAABBActivity.Companion.RenderAABB( AxisAlignedBB( - minX.toDouble(), minY.toDouble(), minZ.toDouble(), - (maxX + 1).toDouble(), (maxY + 1).toDouble(), (maxZ + 1).toDouble() + area.minX.toDouble(), area.minY.toDouble(), area.minZ.toDouble(), + (area.maxX + 1).toDouble(), (area.maxY + 1).toDouble(), (area.maxZ + 1).toDouble() ), ColorHolder(245, 66, 66) ).also { aabbCompounds.add(it) } } override fun SafeClientEvent.onInitialize() { - val layers = (minY..maxY).reversed() + with(area) { + if (!playerInArea) { + MessageSendHelper.sendWarningMessage("You are not in the area!") + addSubActivities(CustomGoal(GoalXZ(center.x, center.z))) + return@onInitialize + } + } + + val layers = (area.minY..area.maxY).reversed() val structure = mutableMapOf() layers.forEach { y -> if (y !in 0..world.actualHeight) return@forEach - (minX..maxX).forEach { x -> - (minZ..maxZ).forEach { z -> + (area.minX..area.maxX).forEach { x -> + (area.minZ..area.maxZ).forEach { z -> structure[BlockPos(x, y, z)] = Blocks.AIR.defaultState } } diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt index 80b5c08c6..261ae2cd7 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -1,14 +1,11 @@ package com.lambda.client.command.commands import com.lambda.client.command.ClientCommand -import com.lambda.client.command.commands.BuildToolsCommand.blockPos -import com.lambda.client.command.commands.BuildToolsCommand.execute -import com.lambda.client.command.commands.BuildToolsCommand.int -import com.lambda.client.command.commands.BuildToolsCommand.literal -import com.lambda.client.module.modules.client.BuildTools +import com.lambda.client.command.CommandManager import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.item.Item object WorldEaterCommand : ClientCommand( name = "worldeater", @@ -17,8 +14,10 @@ object WorldEaterCommand : ClientCommand( ) { init { literal("start") { - execute("Start world eater") { - WorldEater.startClearingArea() + executeSafe("Start world eater") { + with(WorldEater) { + clearAllAreas() + } } } @@ -26,7 +25,7 @@ object WorldEaterCommand : ClientCommand( literal("add", "new", "+") { item("item") { itemArg -> execute("Add item to pickup list") { - val added = WorldEater.collectables.add(itemArg.value.registryName.toString()) + val added = WorldEater.collectables.add(itemArg.value) if (added) { MessageSendHelper.sendChatMessage("Added &7${itemArg.value.registryName}&r to pickup list.") } else { @@ -39,7 +38,7 @@ object WorldEaterCommand : ClientCommand( literal("remove") { item("item") { itemArg -> execute("Remove item from pickup list") { - val removed = WorldEater.collectables.remove(itemArg.value.registryName.toString()) + val removed = WorldEater.collectables.remove(itemArg.value) if (removed) { MessageSendHelper.sendChatMessage("Removed &7${itemArg.value.registryName}&r from pickup list.") } else { @@ -50,34 +49,109 @@ object WorldEaterCommand : ClientCommand( } } - literal("area") { + literal("quarry") { + literal("add", "new", "+") { + blockPos("pos1") { pos1 -> + blockPos("pos2") { pos2 -> + execute("Adds excavating area") { + val area = WorldEater.Area(pos1.value, pos2.value) + + WorldEater.quarries.value.add(area) + MessageSendHelper.sendChatMessage("Added excavating area $area") + } + } + } + } + literal("remove", "rem", "-") { + int("id") { id -> + execute("Removes excavating area") { + val removed = WorldEater.quarries.value.removeAt(id.value) + MessageSendHelper.sendChatMessage("Removed excavating area $removed") + } + } + } + execute("Shows all quarries") { + MessageSendHelper.sendChatMessage("Quarries:") + WorldEater.quarries.forEachIndexed { index, volume -> + MessageSendHelper.sendChatMessage(" &7$index&r: $volume") + } + } + } + + literal("stash") { + literal("add", "new", "+") { + blockPos("pos1") { pos1 -> + blockPos("pos2") { pos2 -> + greedy("items") { + execute("Adds stash area") { + val safeArgs = CommandManager.tryParseArgument(args.joinToString(" ")) ?: return@execute + + val items = safeArgs.mapNotNull { Item.getByNameOrId(it) } + val stash = WorldEater.Stash(WorldEater.Area(pos1.value, pos2.value), items) + + WorldEater.stashes.value.add(stash) + MessageSendHelper.sendChatMessage("Added stash $stash") + } + } + } + } + } + literal("remove", "rem", "-") { + int("id") { id -> + execute("Removes excavating area") { + val removed = WorldEater.quarries.value.removeAt(id.value) + MessageSendHelper.sendChatMessage("Removed excavating area $removed") + } + } + } + execute("Shows all stashes") { + MessageSendHelper.sendChatMessage("Stashes:") + WorldEater.stashes.forEachIndexed { index, stash -> + MessageSendHelper.sendChatMessage(" &7$index&r: $stash") + } + } + } + + literal("dropOff") { literal("add", "new", "+") { blockPos("pos1") { pos1 -> blockPos("pos2") { pos2 -> - execute("Sets excavating area") { - WorldEater.pos1.value = pos1.value - WorldEater.pos2.value = pos2.value - MessageSendHelper.sendChatMessage("Added excavating area (${pos1.value}x${pos2.value}).") -// BuildTools.storageAreas.add(it.args[0].value to it.args[1].value) -// MessageSendHelper.sendChatMessage("Added storage area with id ${BuildTools.storageAreas.size - 1}.") + greedy("items") { + execute("Adds drop off area") { + val safeArgs = CommandManager.tryParseArgument(args.joinToString(" ")) ?: return@execute + + val items = safeArgs.mapNotNull { Item.getByNameOrId(it) } + val dropOff = WorldEater.DropOff(WorldEater.Area(pos1.value, pos2.value), items) + + WorldEater.dropOff.value.add(dropOff) + MessageSendHelper.sendChatMessage("Added drop-off area $dropOff") + } } } } } literal("remove", "rem", "-") { - int("id") { - execute("Not yet implemented") { - MessageSendHelper.sendChatMessage("Not yet implemented.") + int("id") { id -> + execute("Removes excavating area") { + val removed = WorldEater.dropOff.value.removeAt(id.value) + MessageSendHelper.sendChatMessage("Removed drop-off area $removed") } } } + execute("Shows all drop-off areas") { + MessageSendHelper.sendChatMessage("Stashes:") + WorldEater.dropOff.forEachIndexed { index, dropOff -> + MessageSendHelper.sendChatMessage(" &7$index&r: $dropOff") + } + } } execute("General setting info") { MessageSendHelper.sendChatMessage("World eater settings:") - MessageSendHelper.sendChatMessage(" &7${WorldEater.collectables.size}&r items on pickup list.") - MessageSendHelper.sendChatMessage(" &7${WorldEater.pos1.value.asString()}&r is position 1.") - MessageSendHelper.sendChatMessage(" &7${WorldEater.pos2.value.asString()}&r is position 2.") + MessageSendHelper.sendChatMessage(" &7Pickup&r: ${WorldEater.collectables.value.joinToString { it.registryName.toString() }}") + MessageSendHelper.sendChatMessage(" &7Quarries&r: ${WorldEater.quarries.value.joinToString()}") + MessageSendHelper.sendChatMessage(" &7Stashes&r: ${WorldEater.stashes.value.joinToString()}") + MessageSendHelper.sendChatMessage(" &7Drop-off&r: ${WorldEater.dropOff.value.joinToString()}") } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 5c6b4005f..a51883f2f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,88 +1,130 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.ClearArea +import com.lambda.client.command.CommandManager.prefix +import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.math.VectorUtils.multiply +import com.lambda.client.util.items.item +import com.lambda.client.util.math.CoordinateConverter.asString +import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe +import net.minecraft.init.Blocks import net.minecraft.item.Item import net.minecraft.util.EnumFacing import net.minecraft.util.math.BlockPos object WorldEater : Module( name = "WorldEater", - description = "Easy perimeter building", + description = "Full auto excavation", category = Category.MISC, alias = arrayOf("we") ) { - private val size by setting("Size", 10, 1..100, 1) - private val depth by setting("Depth", 3, 1..100, 1) private val layerSize by setting("Layers size", 1, 1..6, 1) private val sliceSize by setting("Slice size", 1, 1..6, 1) private val sliceDirection by setting("Slice direction", EnumFacing.NORTH) private val collectAll by setting("Collect all", false) - private val start by setting("Start", false, consumer = { _, _ -> - runSafe { - val origin = player.flooredPosition - val currentDirection = player.horizontalFacing - val firstPos = origin.add(currentDirection.directionVec) - val secondPos = origin.add( - currentDirection.directionVec.multiply(size) - ).add( - currentDirection.rotateY().directionVec.multiply(size) - ).down(depth) - startClearingArea(firstPos, secondPos) - } - false - }) - val collectables = setting(CollectionSetting("Pick up items", linkedSetOf("minecraft:dirt", "minecraft:cobblestone"))) - val pos1 = setting("Pos1", BlockPos.ORIGIN) - val pos2 = setting("Pos2", BlockPos.ORIGIN) - - val stashes = setting(CollectionSetting("Stashes", linkedSetOf())) - val dropOff = setting(CollectionSetting("Drop off", linkedSetOf())) + private val defaultPickupItems = linkedSetOf( + Blocks.DIRT.item, + Blocks.GRASS.item, + Blocks.STONE.item, + Blocks.COBBLESTONE.item, + Blocks.GRAVEL.item, + Blocks.SAND.item, + Blocks.SANDSTONE.item, + Blocks.RED_SANDSTONE.item, + Blocks.CLAY.item + ) - val pickUp: List - get() = collectables.value.mapNotNull { Item.getByNameOrId(it) } + val collectables = setting(CollectionSetting("Pick up items", defaultPickupItems, entryType = Item::class.java)) + val quarries = setting(CollectionSetting("Quarries", mutableListOf(), entryType = Area::class.java)) + val stashes = setting(CollectionSetting("Stashes", mutableListOf(), entryType = Stash::class.java)) + val dropOff = setting(CollectionSetting("Drop offs", mutableListOf(), entryType = DropOff::class.java)) - private var ownedBuildStructure: ClearArea? = null + private var ownedActivity: ClearArea? = null init { onEnable { + if (quarries.value.isEmpty()) { + MessageSendHelper.sendChatMessage("No quarries set yet. Use &7${prefix}we quarry add&r to add one.") + disable() + return@onEnable + } + runSafe { - startClearingArea() + clearAllAreas() } } onDisable { runSafe { - ownedBuildStructure?.let { + ownedActivity?.let { with(it) { cancel() } } - ownedBuildStructure = null + ownedActivity = null } } } - fun startClearingArea( - pos1: BlockPos = this.pos1.value, - pos2: BlockPos = this.pos2.value - ) { - ClearArea( - pos1, - pos2, - layerSize, - sliceSize, - collectAll = collectAll - ).also { - ownedBuildStructure = it - addSubActivities(it) + fun SafeClientEvent.clearAllAreas() { + quarries.value.minByOrNull { player.distanceTo(it.pos1) }?.let { area -> + MessageSendHelper.sendChatMessage("Start excavating closest area: $area") + ClearArea( + area, + layerSize, + sliceSize, + sliceDirection, + collectAll = collectAll + ).also { + ownedActivity = it + addSubActivities(it) + } } } + + data class DropOff(val area: Area, val items: List) { + override fun toString() = "($area)\n${items.joinToString { + " &7${it.registryName.toString()}\n" + }}" + } + data class Stash(val area: Area, val items: List) { + override fun toString() = "($area)\n${items.joinToString { + " &7${it.registryName.toString()}\n" + }}" + } + + data class Area(val pos1: BlockPos, val pos2: BlockPos) { + val center: BlockPos + get() = BlockPos( + (pos1.x + pos2.x) / 2, + (pos1.y + pos2.y) / 2, + (pos1.z + pos2.z) / 2 + ) + + val SafeClientEvent.playerInArea: Boolean + get() = player.flooredPosition.x in minX..maxX + && player.flooredPosition.z in minZ..maxZ + + val minX: Int + get() = minOf(pos1.x, pos2.x) + val minY: Int + get() = minOf(pos1.y, pos2.y) + val minZ: Int + get() = minOf(pos1.z, pos2.z) + val maxX: Int + get() = maxOf(pos1.x, pos2.x) + val maxY: Int + get() = maxOf(pos1.y, pos2.y) + val maxZ: Int + get() = maxOf(pos1.z, pos2.z) + + override fun toString() = "(${pos1.asString()})x(${pos2.asString()})" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/BlockPosSerializer.kt b/src/main/kotlin/com/lambda/client/setting/serializables/BlockPosSerializer.kt new file mode 100644 index 000000000..963f88fff --- /dev/null +++ b/src/main/kotlin/com/lambda/client/setting/serializables/BlockPosSerializer.kt @@ -0,0 +1,18 @@ +package com.lambda.client.setting.serializables + +import com.google.gson.JsonDeserializer +import com.google.gson.JsonSerializer +import com.google.gson.* +import java.lang.reflect.Type +import net.minecraft.util.math.BlockPos + +object BlockPosSerializer : JsonSerializer, JsonDeserializer { + override fun serialize(src: BlockPos, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { + return JsonPrimitive(src.toLong()) + } + + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): BlockPos { + val longValue = json.asJsonPrimitive.asLong + return BlockPos.fromLong(longValue) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/BlockSerializer.kt b/src/main/kotlin/com/lambda/client/setting/serializables/BlockSerializer.kt new file mode 100644 index 000000000..186bda634 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/setting/serializables/BlockSerializer.kt @@ -0,0 +1,16 @@ +package com.lambda.client.setting.serializables + +import com.google.gson.* +import java.lang.reflect.Type +import net.minecraft.block.Block + +object BlockSerializer : JsonSerializer, JsonDeserializer { + override fun serialize(src: Block, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { + return JsonPrimitive(src.registryName.toString()) + } + + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Block? { + val stringValue = json.asJsonPrimitive.asString + return Block.getBlockFromName(stringValue) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt b/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt new file mode 100644 index 000000000..5224cb6af --- /dev/null +++ b/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt @@ -0,0 +1,16 @@ +package com.lambda.client.setting.serializables + +import com.google.gson.* +import net.minecraft.item.Item +import java.lang.reflect.Type + +object ItemSerializer : JsonSerializer, JsonDeserializer { + override fun serialize(src: Item, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { + return JsonPrimitive(src.registryName.toString()) + } + + override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Item? { + val stringValue = json.asJsonPrimitive.asString + return Item.getByNameOrId(stringValue) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt index 2867e07ab..bb35c422a 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt @@ -5,6 +5,12 @@ import com.google.gson.GsonBuilder import com.google.gson.JsonElement import com.google.gson.JsonParser import com.lambda.client.commons.interfaces.Nameable +import com.lambda.client.setting.serializables.BlockPosSerializer +import com.lambda.client.setting.serializables.BlockSerializer +import com.lambda.client.setting.serializables.ItemSerializer +import net.minecraft.block.Block +import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos import kotlin.reflect.KProperty abstract class AbstractSetting : Nameable { @@ -47,7 +53,12 @@ abstract class AbstractSetting : Nameable { value.hashCode() protected companion object { - val gson: Gson = GsonBuilder().setPrettyPrinting().create() + val gson: Gson = GsonBuilder() + .registerTypeAdapter(BlockPos::class.java, BlockPosSerializer) + .registerTypeAdapter(Block::class.java, BlockSerializer) + .registerTypeAdapter(Item::class.java, ItemSerializer) + .setPrettyPrinting() + .create() val parser = JsonParser() } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/settings/impl/collection/CollectionSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/impl/collection/CollectionSetting.kt index ce1afaf80..c09ea6cdc 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/impl/collection/CollectionSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/impl/collection/CollectionSetting.kt @@ -2,6 +2,7 @@ package com.lambda.client.setting.settings.impl.collection import com.google.gson.JsonElement import com.google.gson.reflect.TypeToken +import com.lambda.client.LambdaMod import com.lambda.client.setting.settings.ImmutableSetting class CollectionSetting>( @@ -51,7 +52,10 @@ class CollectionSetting>( override fun read(jsonElement: JsonElement?) { jsonElement?.asJsonArray?.let { - val cacheArray = gson.fromJson>(it, TypeToken.getArray(entryType ?: value.first().javaClass).type) + LambdaMod.LOG.info("Reading collection setting $name $it") + val cacheArray = gson.fromJson>( + it, TypeToken.getArray(entryType ?: value.first().javaClass).type + ) synchronized(lockObject) { value.clear() value.addAll(cacheArray) From b91b1f8f7700ed573b354997b81b19fcb8312af2 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 5 Jun 2023 17:31:06 +0200 Subject: [PATCH 090/104] Fix rebase fail --- src/main/kotlin/com/lambda/client/util/world/Interact.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/util/world/Interact.kt b/src/main/kotlin/com/lambda/client/util/world/Interact.kt index 723a28492..6d5e43107 100644 --- a/src/main/kotlin/com/lambda/client/util/world/Interact.kt +++ b/src/main/kotlin/com/lambda/client/util/world/Interact.kt @@ -92,10 +92,7 @@ private fun SafeClientEvent.getNeighbour( } } - if (attempts > 1) { - for (side in sides) { - val newPos = pos.offset(side) - if (!world.isPlaceable(newPos, AxisAlignedBB(newPos))) continue + if (attempts < 2) return null sides.forEach { posSide -> val newPos = pos.offset(posSide) From 775a5c208e9241d15d2ddcf66634a6797996a9ea Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 5 Jun 2023 21:55:19 +0200 Subject: [PATCH 091/104] HWT start command --- .../command/commands/HighwayToolsCommand.kt | 8 ++++ .../module/modules/misc/HighwayTools.kt | 43 +++++++++++-------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt index 374972aaf..572c698e0 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/HighwayToolsCommand.kt @@ -27,5 +27,13 @@ object HighwayToolsCommand : ClientCommand( } } } + + literal("start") { + executeSafe("Starts the highway") { + with(HighwayTools) { + start() + } + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index 9fa30376f..f56d721f5 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -7,6 +7,7 @@ import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.client.BuildTools.defaultFillerMat +import com.lambda.client.module.modules.misc.HighwayTools.printEnable import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply @@ -63,25 +64,7 @@ object HighwayTools : Module( init { onEnable { runSafe { - originPosition = player.flooredPosition.down() - originDirection = Direction.fromEntity(player) - originOrthogonalDirection = originDirection.clockwise(if (originDirection.isDiagonal) 1 else 2) - - printEnable() - - ActivityManagerHud.totalBlocksBroken = 0 - ActivityManagerHud.totalBlocksPlaced = 0 - - BuildStructure( - generateHighway(), - direction = originDirection, - offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), - maximumRepeats = distance, - doPadding = true - ).let { - ownedBuildStructure = it - addSubActivities(it) - } + start() } } @@ -96,6 +79,28 @@ object HighwayTools : Module( } } + fun SafeClientEvent.start() { + originPosition = player.flooredPosition.down() + originDirection = Direction.fromEntity(player) + originOrthogonalDirection = originDirection.clockwise(if (originDirection.isDiagonal) 1 else 2) + + printEnable() + + ActivityManagerHud.totalBlocksBroken = 0 + ActivityManagerHud.totalBlocksPlaced = 0 + + BuildStructure( + generateHighway(), + direction = originDirection, + offsetMove = BlockPos(originDirection.directionVec.multiply(offset)), + maximumRepeats = distance, + doPadding = true + ).let { + ownedBuildStructure = it + addSubActivities(it) + } + } + private fun generateHighway(): HashMap { val blueprint = hashMapOf() From 0d892f3b9209965eb0d38753e7f9c523e5bd903d Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 5 Jun 2023 15:19:33 -0700 Subject: [PATCH 092/104] fix item serializer --- .../setting/serializables/ItemSerializer.kt | 16 --------- .../serializables/ItemTypeAdapterFactory.kt | 34 +++++++++++++++++++ .../setting/settings/AbstractSetting.kt | 5 ++- 3 files changed, 36 insertions(+), 19 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt create mode 100644 src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt b/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt deleted file mode 100644 index 5224cb6af..000000000 --- a/src/main/kotlin/com/lambda/client/setting/serializables/ItemSerializer.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.lambda.client.setting.serializables - -import com.google.gson.* -import net.minecraft.item.Item -import java.lang.reflect.Type - -object ItemSerializer : JsonSerializer, JsonDeserializer { - override fun serialize(src: Item, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { - return JsonPrimitive(src.registryName.toString()) - } - - override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Item? { - val stringValue = json.asJsonPrimitive.asString - return Item.getByNameOrId(stringValue) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt b/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt new file mode 100644 index 000000000..af98a58ac --- /dev/null +++ b/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt @@ -0,0 +1,34 @@ +package com.lambda.client.setting.serializables + +import com.google.gson.Gson +import com.google.gson.JsonObject +import com.google.gson.TypeAdapter +import com.google.gson.TypeAdapterFactory +import com.google.gson.reflect.TypeToken +import com.google.gson.stream.JsonReader +import net.minecraft.item.Item + +object ItemTypeAdapterFactory : TypeAdapterFactory { + override fun create(gson: Gson, type: TypeToken): TypeAdapter? { + if (!Item::class.java.isAssignableFrom(type?.rawType)) return null + val jsonObjectAdapter = gson.getAdapter(JsonObject::class.java) + + return object : TypeAdapter() { + override fun write(out: com.google.gson.stream.JsonWriter, value: Item?) { + if (value == null) { + out.nullValue() + return + } + val jsonObject = JsonObject() + jsonObject.addProperty("name", value.registryName.toString()) + jsonObjectAdapter.write(out, jsonObject) + } + + override fun read(reader: JsonReader): Item? { + val jsonObject = jsonObjectAdapter.read(reader) + val name = jsonObject.get("name").asString + return Item.getByNameOrId(name) + } + } as TypeAdapter + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt index bb35c422a..81d00ec5e 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/AbstractSetting.kt @@ -7,9 +7,8 @@ import com.google.gson.JsonParser import com.lambda.client.commons.interfaces.Nameable import com.lambda.client.setting.serializables.BlockPosSerializer import com.lambda.client.setting.serializables.BlockSerializer -import com.lambda.client.setting.serializables.ItemSerializer +import com.lambda.client.setting.serializables.ItemTypeAdapterFactory import net.minecraft.block.Block -import net.minecraft.item.Item import net.minecraft.util.math.BlockPos import kotlin.reflect.KProperty @@ -56,7 +55,7 @@ abstract class AbstractSetting : Nameable { val gson: Gson = GsonBuilder() .registerTypeAdapter(BlockPos::class.java, BlockPosSerializer) .registerTypeAdapter(Block::class.java, BlockSerializer) - .registerTypeAdapter(Item::class.java, ItemSerializer) + .registerTypeAdapterFactory(ItemTypeAdapterFactory) .setPrettyPrinting() .create() val parser = JsonParser() From f5837b8697f0aa8fcba7672a1ae5444aeae64e63 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:37:44 -0700 Subject: [PATCH 093/104] fix activities aabb messing up rendering scaling --- .../kotlin/com/lambda/client/manager/managers/ActivityManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 7e13048cb..d2028d2e1 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -124,6 +124,7 @@ object ActivityManager : Manager, Activity() { GL11.glPopMatrix() } + GlStateUtils.rescaleMc() } } From 85fcdf1676b7bd38e2b3de9f73bc14e4698e63c3 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:03:03 -0700 Subject: [PATCH 094/104] fix possible break conflicts with baritone goals. fix repeating activities listeners being unsubscribed --- .../com/lambda/client/activity/Activity.kt | 3 +- .../activities/construction/ClearArea.kt | 6 +- .../construction/core/BreakBlock.kt | 16 +++-- .../construction/core/BuildStructure.kt | 63 +++++++++++++++++-- .../activity/types/RepeatingActivity.kt | 6 +- 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 92e7b85b5..6f889a3c6 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -8,6 +8,7 @@ import com.lambda.client.activity.types.DelayedActivity.Companion.checkDelayed import com.lambda.client.activity.types.LoopWhileActivity.Companion.checkLoopingUntil import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender +import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.activity.types.RepeatingActivity.Companion.checkRepeat import com.lambda.client.activity.types.RotatingActivity.Companion.checkRotating import com.lambda.client.activity.types.TimeoutActivity.Companion.checkTimeout @@ -131,7 +132,7 @@ abstract class Activity { val activity = this@Activity LambdaEventBus.unsubscribe(activity) - ListenerManager.unregister(activity) + if (activity !is RepeatingActivity) ListenerManager.unregister(activity) if (activity is RenderAABBActivity) { activity.aabbCompounds.clear() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index cfc4a508d..8cccfaba2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -8,7 +8,6 @@ import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.color.ColorHolder -import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks @@ -38,8 +37,9 @@ class ClearArea( override fun SafeClientEvent.onInitialize() { with(area) { if (!playerInArea) { - MessageSendHelper.sendWarningMessage("You are not in the area!") + MessageSendHelper.sendWarningMessage("Pathing to area") addSubActivities(CustomGoal(GoalXZ(center.x, center.z))) + status = Status.UNINITIALIZED return@onInitialize } } @@ -59,7 +59,7 @@ class ClearArea( if (y.mod(layerSize) == 0 || y == layers.last) { addSubActivities( - BuildStructure(structure.toMap(), collectAll = collectAll) + BuildStructure(structure.toMap(), collectAll = collectAll, allowBreakDescend = true) ) structure.clear() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index c022ebd20..3d7a9a6c4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity.activities.construction.core +import baritone.api.BaritoneAPI import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot @@ -8,6 +9,7 @@ import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud +import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.mixin.extension.blockHitDelay import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition @@ -17,7 +19,10 @@ import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.Vec2f import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.toVec3dCenter -import com.lambda.client.util.threads.* +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.onMainThreadSafe +import com.lambda.client.util.threads.runSafe +import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getHitVec import com.lambda.client.util.world.getMiningSide import com.lambda.client.util.world.isLiquid @@ -223,7 +228,7 @@ class BreakBlock( } private fun SafeClientEvent.resolveAvailability() { - when (availability) { + when (availability) { BuildActivity.Availability.VALID -> { tryBreak() } @@ -245,9 +250,14 @@ class BreakBlock( } private fun SafeClientEvent.tryBreak() { + if (ActivityManager.getCurrentActivity() != this@BreakBlock) return if (!hasOptimalTool()) return side?.let { + // if baritone break/place is on while we're breaking it ourselves, we'll get stuck in a loop + // todo: option to use baritone break/place instead of ours + BaritoneAPI.getSettings().allowBreak.value = false + BaritoneAPI.getSettings().allowPlace.value = false if (!world.isAirBlock(blockPos) && playerController.onPlayerDamageBlock(blockPos, it)) { if ((ticksNeeded == 1 && player.onGround) || player.capabilities.isCreativeMode) { playerController.blockHitDelay = 0 @@ -260,8 +270,6 @@ class BreakBlock( player.swingArm(EnumHand.MAIN_HAND) } } - - } // ToDo: 1. currentState.material.isToolNotRequired (if drop is needed it should check if tool has sufficient harvest level) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 89d488485..f8f520d41 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -3,12 +3,16 @@ package com.lambda.client.activity.activities.construction.core import baritone.api.pathing.goals.Goal import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalInverted -import baritone.process.BuilderProcess +import baritone.api.pathing.goals.GoalXZ +import baritone.process.BuilderProcess.GoalAdjacent +import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity +import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.util.BaritoneUtils @@ -18,12 +22,15 @@ import com.lambda.client.util.items.block import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction +import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks +import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.network.play.server.SPacketMultiBlockChange import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraftforge.event.world.BlockEvent @@ -36,6 +43,7 @@ class BuildStructure( private val doPadding: Boolean = false, private val collectAll: Boolean = false, private val breakBushes: Boolean = false, + private val allowBreakDescend: Boolean = false, override val maximumRepeats: Int = 1, override var repeated: Int = 0, override val aabbCompounds: MutableSet = mutableSetOf() @@ -55,11 +63,29 @@ class BuildStructure( currentOffset = currentOffset.add(offsetMove) } + private fun SafeClientEvent.withinRangeOfStructure(): Boolean { + return nearestStructureBlock()?.let { it.add(currentOffset).distanceTo(player.position) <= 5 } ?: true + } + + private fun SafeClientEvent.nearestStructureBlock(): BlockPos? { + return structure.keys.minBy { it.add(currentOffset).distanceTo(player.position) } + } + init { safeListener { if (it.phase != TickEvent.Phase.END) return@safeListener - if (subActivities.isEmpty()) success() + if (subActivities.isEmpty() && !BaritoneUtils.isPathing) { + // todo: offset pathing like this might not make sense for all structures. we aren't guaranteed to be at a specific position relative to the structure + // we could path to the middle of the structure regardless of shape, but that will be inefficient. also structures are not guaranteed to be small/within render distance + if (autoPathing && !withinRangeOfStructure()) { + LambdaMod.LOG.info("Structure out of range, pathing by offset") + // todo: improve stop/start stutter pathing + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalXZ(player.posX.floorToInt() + (offsetMove.x * 5), player.posZ.floorToInt() + (offsetMove.z * 5))) + return@safeListener + } + success() + } when (val activity = getCurrentActivity()) { is PlaceBlock -> { @@ -72,7 +98,7 @@ class BuildStructure( lastGoal = if (isInBlockAABB(blockPos)) { GoalInverted(GoalBlock(blockPos)) } else { - BuilderProcess.GoalAdjacent(blockPos, blockPos, true) + GoalAdjacent(blockPos, blockPos, true) } } is BreakBlock -> { @@ -82,10 +108,10 @@ class BuildStructure( if (!autoPathing) return@safeListener - lastGoal = if (isInBlockAABB(blockPos.up())) { + lastGoal = if (!allowBreakDescend && isInBlockAABB(blockPos.up())) { GoalInverted(GoalBlock(blockPos.up())) } else { - BuilderProcess.GoalBreak(blockPos) + GoalAdjacent(blockPos, blockPos, true) } } } @@ -114,6 +140,31 @@ class BuildStructure( createBuildActivity(blockPos, targetState) } } + + safeListener { + if (it.packet is SPacketBlockChange) { + handleBlockUpdate(it.packet.blockPosition, it.packet.blockState) + } else if (it.packet is SPacketMultiBlockChange) { + it.packet.changedBlocks.forEach { blockData -> + handleBlockUpdate(blockData.pos, blockData.blockState) + } + } + } + } + + private fun SafeClientEvent.handleBlockUpdate(blockPos: BlockPos, blockState: IBlockState) { + // todo: capture baritone placing support blocks and update structure + structure[blockPos]?.let { targetState -> + if (allSubActivities.any { + when (it) { + is BreakBlock -> it.blockPos == blockPos && targetState == blockState + is PlaceBlock -> it.blockPos == blockPos && targetState == blockState + else -> false + } + }) return + MessageSendHelper.sendWarningMessage("Block changed at $blockPos") + createBuildActivity(blockPos, targetState) + } } private fun SafeClientEvent.createBuildActivity(blockPos: BlockPos, targetState: IBlockState) { @@ -169,6 +220,8 @@ class BuildStructure( it.type }.thenBy { it.distance + }.thenBy { + it.hashCode() } private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt index 8f6298850..c2d46b0a3 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RepeatingActivity.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.types import com.lambda.client.activity.Activity +import com.lambda.client.event.ListenerManager interface RepeatingActivity { val maximumRepeats: Int @@ -11,7 +12,10 @@ interface RepeatingActivity { if (activity !is RepeatingActivity) return with(activity) { - if (repeated++ >= maximumRepeats && maximumRepeats != 0) return + if (repeated++ >= maximumRepeats && maximumRepeats != 0) { + ListenerManager.unregister(activity) + return + } status = Activity.Status.UNINITIALIZED parent?.subActivities?.add(activity) From 92e9aa826757cb5174cd0b53552a6f558064209e Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 16 Jul 2023 04:32:20 +0200 Subject: [PATCH 095/104] Add StashTransaction sketch --- .../lambda/client/activity/ActivityUtils.kt | 44 ++++++- .../activities/construction/ClearArea.kt | 10 +- .../construction/core/BreakBlock.kt | 2 +- .../construction/core/BuildStructure.kt | 6 +- .../inventory/AcquireItemInActiveHand.kt | 28 +++-- .../storage/ExtractItemFromShulkerBox.kt | 15 +-- .../activities/storage/ReplenishInventory.kt | 6 - .../activities/storage/StashTransaction.kt | 87 +++++++++++++ .../storage/StoreItemToShulkerBox.kt | 19 ++- .../activities/storage/StoreItemsToStash.kt | 63 ---------- ...omContainer.kt => ContainerTransaction.kt} | 64 +++++----- .../storage/core/PushItemsToContainer.kt | 45 ------- .../command/commands/BuildToolsCommand.kt | 29 +---- .../command/commands/WorldEaterCommand.kt | 47 ++++--- .../manager/managers/ActivityManager.kt | 119 +++++++++++++++--- .../module/modules/client/BuildTools.kt | 4 +- .../client/module/modules/misc/WorldEater.kt | 23 ++-- 17 files changed, 359 insertions(+), 252 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/core/{PullItemsFromContainer.kt => ContainerTransaction.kt} (52%) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt diff --git a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt index 90305ee86..53a8f3d9b 100644 --- a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt @@ -1,8 +1,8 @@ package com.lambda.client.activity -import net.minecraft.inventory.ItemStackHelper -import net.minecraft.inventory.Slot -import net.minecraft.item.Item +import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.util.items.getSlots +import net.minecraft.inventory.* import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack import net.minecraft.util.NonNullList @@ -22,6 +22,38 @@ fun getShulkerInventory(stack: ItemStack): NonNullList? { return shulkerInventory } -val slotFilterFunction = { item: Item, metadata: Int?, predicateStack: (ItemStack) -> Boolean -> - { slot: Slot -> item == slot.stack.item && predicateStack(slot.stack) && (metadata == null || metadata == slot.stack.metadata) } -} \ No newline at end of file +val slotFilterFunction = { + order: ContainerTransaction.Order -> { + slot: Slot -> if (order.containedInShulker) { + slot.stack.item is ItemShulkerBox + && getShulkerInventory(slot.stack)?.any { + it.item == order.item + && order.predicateStack(it) + && (order.metadata == null || order.metadata == it.metadata) + } == true + } else order.item == slot.stack.item + && order.predicateStack(slot.stack) + && (order.metadata == null || order.metadata == slot.stack.metadata) + } +} + +/** + * Get the slots of a container. + * The first list contains the container slots, the second list contains the player slots. + */ +val Container.seperatedSlots: Pair, List> + get() = when(this) { + is ContainerShulkerBox -> { + getSlots(0..26) to getSlots(27..62) + } + is ContainerChest -> { + if (inventory.size == 62) { + getSlots(0..26) to getSlots(27..62) + } else { + getSlots(0..53) to getSlots(54..89) + } + } + else -> { + throw ContainerTransaction.ContainerNotKnownException(this) + } + } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 8cccfaba2..5168161bd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity.activities.construction +import baritone.api.pathing.goals.GoalTwoBlocks import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BuildStructure @@ -37,7 +38,7 @@ class ClearArea( override fun SafeClientEvent.onInitialize() { with(area) { if (!playerInArea) { - MessageSendHelper.sendWarningMessage("Pathing to area") + MessageSendHelper.sendWarningMessage("You are not in the area $area! Moving now...") addSubActivities(CustomGoal(GoalXZ(center.x, center.z))) status = Status.UNINITIALIZED return@onInitialize @@ -45,7 +46,6 @@ class ClearArea( } val layers = (area.minY..area.maxY).reversed() - val structure = mutableMapOf() layers.forEach { y -> @@ -65,4 +65,10 @@ class ClearArea( } } } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is CustomGoal) return + + status = Status.UNINITIALIZED + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 3d7a9a6c4..32447ef71 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -349,7 +349,7 @@ class BreakBlock( return true } - EnumFacing.values() + EnumFacing.entries .filter { it != EnumFacing.DOWN } .map { blockPos.offset(it) } .filter { world.getBlockState(it).isLiquid } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index f8f520d41..894c0509d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -68,7 +68,7 @@ class BuildStructure( } private fun SafeClientEvent.nearestStructureBlock(): BlockPos? { - return structure.keys.minBy { it.add(currentOffset).distanceTo(player.position) } + return structure.keys.minByOrNull { it.add(currentOffset).distanceTo(player.position) } } init { @@ -136,7 +136,7 @@ class BuildStructure( } }) return@safeListener - MessageSendHelper.sendWarningMessage("Block changed at $blockPos") +// MessageSendHelper.sendWarningMessage("Block changed at $blockPos") createBuildActivity(blockPos, targetState) } } @@ -162,7 +162,7 @@ class BuildStructure( else -> false } }) return - MessageSendHelper.sendWarningMessage("Block changed at $blockPos") +// MessageSendHelper.sendWarningMessage("Block changed at $blockPos") createBuildActivity(blockPos, targetState) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 9eacc0655..b4bc3b673 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -6,6 +6,7 @@ import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot import com.lambda.client.activity.activities.storage.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox +import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.activity.getShulkerInventory import com.lambda.client.activity.slotFilterFunction @@ -33,7 +34,16 @@ class AcquireItemInActiveHand( override var usedAttempts: Int = 0 ) : AttemptActivity, Activity() { override fun SafeClientEvent.onInitialize() { - player.hotbarSlots.firstOrNull(slotFilterFunction(item, metadata, predicateStack))?.let { + val order = ContainerTransaction.Order( + ContainerTransaction.Action.PUSH, + item, + amount, + predicateStack, + metadata, + predicateSlot + ) + + player.hotbarSlots.firstOrNull(slotFilterFunction(order))?.let { addSubActivities(SwitchToHotbarSlot(it)) return } @@ -45,20 +55,20 @@ class AcquireItemInActiveHand( return } - player.allSlots.firstOrNull(slotFilterFunction(item, metadata, predicateStack))?.let { slotFrom -> - addSubActivities(SwapOrSwitchToSlot(slotFrom, predicateSlot)) + player.allSlots.firstOrNull(slotFilterFunction(order))?.let { slotFrom -> + addSubActivities(SwapOrSwitchToSlot(slotFrom, order.predicateSlot)) return } - if (useShulkerBoxes && item !is ItemShulkerBox) { + if (useShulkerBoxes && order.item !is ItemShulkerBox) { val candidates = mutableMapOf() player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> val count = inventory.count { - item == it.item - && predicateStack(it) - && (metadata == null || metadata == it.metadata) + order.item == it.item + && order.predicateStack(it) + && (order.metadata == null || order.metadata == it.metadata) } if (count > 0) candidates[slot] = count @@ -67,13 +77,13 @@ class AcquireItemInActiveHand( candidates.minByOrNull { it.value }?.key?.let { slot -> addSubActivities(ExtractItemFromShulkerBox( - slot.stack, item, predicateStack, predicateSlot, metadata, 1 + slot.stack, order )) return } } - if (item == Blocks.OBSIDIAN.item) { + if (order.item == Blocks.OBSIDIAN.item) { addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt index 47bea9618..c3592a576 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt @@ -5,19 +5,14 @@ import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.CloseContainer import com.lambda.client.activity.activities.storage.core.PlaceContainer -import com.lambda.client.activity.activities.storage.core.PullItemsFromContainer +import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.activities.travel.PickUpDrops import com.lambda.client.event.SafeClientEvent -import net.minecraft.item.Item import net.minecraft.item.ItemStack class ExtractItemFromShulkerBox( - private val shulkerBoxStack: ItemStack, - private val item: Item, - private val predicateStack: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true }, - private var metadata: Int? = null, - private val amount: Int = 0 // 0 = all + shulkerBoxStack: ItemStack, + private val order: ContainerTransaction.Order ) : Activity() { private val stack = shulkerBoxStack.copy() @@ -31,11 +26,11 @@ class ExtractItemFromShulkerBox( if (childActivity !is PlaceContainer) return addSubActivities( - PullItemsFromContainer(item, predicateStack, metadata, amount), + ContainerTransaction(order), CloseContainer(), BreakBlock(childActivity.containerPos), PickUpDrops(stack.item), // BreakBlock doesn't collect drops - AcquireItemInActiveHand(item, predicateStack, predicateSlot) + AcquireItemInActiveHand(order.item, order.predicateStack, order.predicateSlot) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt deleted file mode 100644 index 377e2a6a3..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ReplenishInventory.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity - -class ReplenishInventory : Activity() { -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt new file mode 100644 index 000000000..59a57ffac --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt @@ -0,0 +1,87 @@ +package com.lambda.client.activity.activities.storage + +import baritone.api.pathing.goals.GoalGetToBlock +import baritone.api.pathing.goals.GoalNear +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.OpenContainer +import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.module.modules.misc.WorldEater +import com.lambda.client.util.math.VectorUtils.distanceTo +import net.minecraft.tileentity.TileEntity + +/** + * [StashTransaction] is an [Activity] that allows you to pull or push items from a [WorldEater.Stash]. + * @param stash The [WorldEater.Stash] to pull or push items from. + * @param orders The orders to pull or push items. + */ +class StashTransaction( + private val stash: WorldEater.Stash, + private val orders: List +) : Activity() { + private val orderQueue = ArrayDeque(orders) + private val containerQueue = ArrayDeque() + + override fun SafeClientEvent.onInitialize() { + if (orderQueue.isEmpty()) { + success() + return + } + + //TODO: Use cached chests to instantly find the closest needed container (maybe even shared cache?) + + addSubActivities( + CustomGoal(GoalNear(stash.area.center, stash.area.maxWidth), timeout = 999999L) + ) + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + when (childActivity) { + is CustomGoal -> { + if (childActivity.goal !is GoalNear) return + + val stashContainer = world.loadedTileEntityList.filter { + stash.area.containedBlockPositions.contains(it.pos) + } + + if (stashContainer.isEmpty()) { + failedWith(NoContainerFoundInStashException()) + return + } + + containerQueue.addAll( + stashContainer.sortedBy { player.distanceTo(it.pos) } + ) + + executeOrdersOnContainer(containerQueue.removeFirst()) + } + is CloseContainer -> { + if (orderQueue.isEmpty()) { + success() + return + } + + executeOrdersOnContainer(containerQueue.removeFirst()) + } + } + } + + private fun executeOrdersOnContainer(container: TileEntity) { + addSubActivities( + CustomGoal(GoalGetToBlock(container.pos)), + OpenContainer(container.pos) + ) + + addSubActivities(orders.sortedBy { it.action }.map { + ContainerTransaction(it) + }) + + orderQueue.clear() // TODO: Remove this when order feedback is implemented + + addSubActivities(CloseContainer()) + } + + class NoContainerFoundInStashException : Exception("No chest found in area!") +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index ddb9b3856..7c5bcf5ee 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -3,8 +3,8 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.activities.storage.core.PlaceContainer -import com.lambda.client.activity.activities.storage.core.PushItemsToContainer import com.lambda.client.activity.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots @@ -14,9 +14,9 @@ import net.minecraft.item.Item import net.minecraft.item.ItemStack class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes - private val item: Item, + val item: Item, private val amount: Int = 0, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true } + private val predicateStack: (ItemStack) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { val candidates = mutableMapOf() @@ -28,8 +28,8 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes player.allSlots.forEach { slot -> getShulkerInventory(slot.stack)?.let { inventory -> - if (inventory.all { (it.item == item && predicateItem(it)) || it.isEmpty }) { - val count = inventory.count { it.item == item && predicateItem(it) } + if (inventory.all { (it.item == item && predicateStack(it)) || it.isEmpty }) { + val count = inventory.count { it.item == item && predicateStack(it) } if (count < 27) candidates[slot] = count } @@ -52,7 +52,14 @@ class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes if (childActivity !is PlaceContainer) return addSubActivities( - PushItemsToContainer(item, amount, predicateItem), + ContainerTransaction( + ContainerTransaction.Order( + ContainerTransaction.Action.PUSH, + item, + amount, + predicateStack + ) + ), CloseContainer(), BreakBlock(childActivity.containerPos, collectDrops = true) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt deleted file mode 100644 index 48493258d..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemsToStash.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import baritone.api.pathing.goals.GoalGetToBlock -import baritone.api.pathing.goals.GoalNear -import baritone.api.pathing.goals.GoalXZ -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.OpenContainer -import com.lambda.client.activity.activities.storage.core.PushItemsToContainer -import com.lambda.client.activity.activities.travel.CustomGoal -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.client.BuildTools -import com.lambda.client.util.EntityUtils.flooredPosition -import com.lambda.client.util.math.VectorUtils.distanceTo -import net.minecraft.item.Item -import net.minecraft.util.math.BlockPos - -class StoreItemsToStash(val items: List) : Activity() { - private var originalPosition: BlockPos = BlockPos.ORIGIN - - override fun SafeClientEvent.onInitialize() { - originalPosition = player.flooredPosition - - addSubActivities( - CustomGoal(GoalNear(BuildTools.storagePos1.value, 10), timeout = 999999L) - ) - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - when (childActivity) { - is CustomGoal -> { - if (childActivity.goal !is GoalNear) return - - val chestsInArea = world.loadedTileEntityList.filter { - BlockPos.getAllInBox(BuildTools.storagePos1.value, BuildTools.storagePos2.value).contains(it.pos) - } - - val useChest = chestsInArea.minByOrNull { chest -> - player.distanceTo(chest.pos) - } ?: return failedWith(NoChestFoundException()) - - addSubActivities( - CustomGoal(GoalGetToBlock(useChest.pos)), - OpenContainer(useChest.pos) - ) - - items.forEach { - addSubActivities(PushItemsToContainer(it, 0), ) - } - - addSubActivities(CloseContainer()) - - // replenish items - - addSubActivities( - CustomGoal(GoalXZ(originalPosition.x, originalPosition.z), timeout = 999999L) - ) - } - } - } - - class NoChestFoundException : Exception("No chest found in area!") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt similarity index 52% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt index 8a42ade08..80a7ac35d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PullItemsFromContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt @@ -3,59 +3,65 @@ package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.activity.activities.inventory.core.SwapWithSlot +import com.lambda.client.activity.seperatedSlots import com.lambda.client.activity.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.getSlots +import com.lambda.client.util.items.hotbarSlots import net.minecraft.inventory.Container -import net.minecraft.inventory.ContainerShulkerBox import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack -class PullItemsFromContainer( // ToDo: fix take for full inv - private val item: Item, - private val predicateStack: (ItemStack) -> Boolean = { true }, - private val metadata: Int? = null, - private val amount: Int, // 0 = all +class ContainerTransaction( + private val order: Order ) : Activity() { + + enum class Action { + PULL, PUSH + } + + data class Order( + val action: Action, + val item: Item, + val slotAmount: Int = 0, // 0 = all + val predicateStack: (ItemStack) -> Boolean = { true }, + val metadata: Int? = null, + val predicateSlot: (ItemStack) -> Boolean = { true }, + val containedInShulker: Boolean = false + ) + override fun SafeClientEvent.onInitialize() { - val containerInventory: List - val playerInventory: List + val seperatedSlots = player.openContainer.seperatedSlots - when (val container = player.openContainer) { - is ContainerShulkerBox -> { - containerInventory = container.getSlots(0..26) - playerInventory = container.getSlots(27..62) - } - else -> { - failedWith(ContainerNotKnownException(container)) - return - } + val (fromSlots, toSlots) = if (order.action == Action.PULL) { + seperatedSlots.let { (first, second) -> Pair(first, second) } + } else { + seperatedSlots.let { (first, second) -> Pair(second, first) } } - val toMoveSlots = containerInventory.filter(slotFilterFunction(item, metadata, predicateStack)) + val toMoveSlots = fromSlots.filter(slotFilterFunction(order)) if (toMoveSlots.isEmpty()) { failedWith(NoItemFoundException()) return } - val remainingSlots = if (amount == 0) toMoveSlots else toMoveSlots.take(amount) - - if (remainingSlots.isEmpty()) { - failedWith(NoSpaceLeftInInventoryException()) + if (toMoveSlots.size < order.slotAmount) { + failedWith(NotEnoughSlotsException()) return } + val remainingSlots = if (order.slotAmount == 0) toMoveSlots else toMoveSlots.take(order.slotAmount) + remainingSlots.forEach { fromSlot -> - if (playerInventory.countEmpty() > 0) { + if (toSlots.countEmpty() > 0) { addSubActivities(QuickMoveSlot(fromSlot)) return@forEach } - val ejectableSlots = playerInventory.filter { slot -> + val ejectableSlots = toSlots.filter { slot -> BuildTools.ejectList.contains(slot.stack.item.registryName.toString()) } @@ -65,12 +71,11 @@ class PullItemsFromContainer( // ToDo: fix take for full inv } ejectableSlots.firstOrNull()?.let { - // ToDo: Use proper slot reference - val firstHotbarSlot = player.openContainer.inventorySlots[54].slotNumber + val firstHotbarSlot = player.hotbarSlots.first() addSubActivities( - SwapWithSlot(it, firstHotbarSlot), - SwapWithSlot(fromSlot, firstHotbarSlot) + SwapWithSlot(it, firstHotbarSlot.hotbarSlot), + SwapWithSlot(fromSlot, firstHotbarSlot.hotbarSlot) ) } } @@ -78,5 +83,6 @@ class PullItemsFromContainer( // ToDo: fix take for full inv class NoSpaceLeftInInventoryException : Exception("No space left in inventory") class NoItemFoundException : Exception("No item found") + class NotEnoughSlotsException : Exception("Not enough slots") class ContainerNotKnownException(val container: Container) : Exception("Container ${container::class.simpleName} not known") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt deleted file mode 100644 index 316372e35..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PushItemsToContainer.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.lambda.client.activity.activities.storage.core - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.getSlots -import net.minecraft.item.Item -import net.minecraft.item.ItemStack - -class PushItemsToContainer( - private val item: Item, - private val amount: Int = 0, // 0 = all - private val predicateItem: (ItemStack) -> Boolean = { true }, -) : Activity() { - override fun SafeClientEvent.onInitialize() { - val openContainer = player.openContainer - - if (openContainer.inventorySlots.size != 63) return - - var candidateSlots = openContainer.getSlots(27..62).filter { slot -> - slot.stack.item == item && predicateItem(slot.stack) - } - - if (amount != 0) candidateSlots = candidateSlots.take(amount) - - candidateSlots.forEach { - addSubActivities(QuickMoveSlot(it)) - } - -// if (subActivities.isEmpty()) { -// failedWith(NoItemFoundPushException(item)) -// } - } - - override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { - if (childException !is QuickMoveSlot.ExceptionSlotNotEmpty) return false - - success() - return true - } - - class NotShulkerBoxException : Exception("No shulker box open") - -// class NoItemFoundPushException(item: Item) : Exception("No item found to push to container: ${item.registryName}") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt index 279f0a4fd..45ad09756 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/BuildToolsCommand.kt @@ -15,8 +15,7 @@ object BuildToolsCommand : ClientCommand( literal("add", "new", "+") { block("block") { blockArg -> execute("Adds a block to ignore list") { - val added = BuildTools.ignoreBlocks.add(blockArg.value.registryName.toString()) - if (added) { + if (BuildTools.ignoreBlocks.add(blockArg.value.registryName.toString())) { MessageSendHelper.sendChatMessage("Added &7${blockArg.value.localizedName}&r to ignore list.") } else { MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is already ignored.") @@ -28,8 +27,7 @@ object BuildToolsCommand : ClientCommand( literal("remove", "rem", "-", "del") { block("block") { blockArg -> execute("Removes a block from ignore list") { - val removed = BuildTools.ignoreBlocks.remove(blockArg.value.registryName.toString()) - if (removed) { + if (BuildTools.ignoreBlocks.remove(blockArg.value.registryName.toString())) { MessageSendHelper.sendChatMessage("Removed &7${blockArg.value.localizedName}&r from ignore list.") } else { MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is not yet ignored.") @@ -131,28 +129,5 @@ object BuildToolsCommand : ClientCommand( MessageSendHelper.sendChatMessage("Food item: &7${BuildTools.defaultFood.registryName}&r") } } - - literal("storage") { - literal("add", "new", "+") { - blockPos("pos1") { pos1 -> - blockPos("pos2") { pos2 -> - execute("Sets storage area") { - BuildTools.storagePos1.value = pos1.value - BuildTools.storagePos2.value = pos2.value - MessageSendHelper.sendChatMessage("Added storage area (${pos1.value}x${pos2.value}). Use &7${prefix}buildtools storage remove&r to remove it.") -// BuildTools.storageAreas.add(it.args[0].value to it.args[1].value) -// MessageSendHelper.sendChatMessage("Added storage area with id ${BuildTools.storageAreas.size - 1}.") - } - } - } - } - literal("remove", "rem", "-") { - int("id") { - execute("Not yet implemented") { - MessageSendHelper.sendChatMessage("Not yet implemented.") - } - } - } - } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt index 261ae2cd7..aaa9c0a72 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -3,7 +3,6 @@ package com.lambda.client.command.commands import com.lambda.client.command.ClientCommand import com.lambda.client.command.CommandManager import com.lambda.client.module.modules.misc.WorldEater -import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.text.MessageSendHelper import net.minecraft.item.Item @@ -21,12 +20,21 @@ object WorldEaterCommand : ClientCommand( } } + literal("stop") { + executeSafe("Stop world eater") { + WorldEater.ownedActivity?.let { + with(it) { + cancel() + } + } + } + } + literal("pickup") { literal("add", "new", "+") { item("item") { itemArg -> execute("Add item to pickup list") { - val added = WorldEater.collectables.add(itemArg.value) - if (added) { + if (WorldEater.collectables.add(itemArg.value)) { MessageSendHelper.sendChatMessage("Added &7${itemArg.value.registryName}&r to pickup list.") } else { MessageSendHelper.sendChatMessage("&7${itemArg.value.registryName}&r is already on the pickup list.") @@ -38,8 +46,7 @@ object WorldEaterCommand : ClientCommand( literal("remove") { item("item") { itemArg -> execute("Remove item from pickup list") { - val removed = WorldEater.collectables.remove(itemArg.value) - if (removed) { + if (WorldEater.collectables.remove(itemArg.value)) { MessageSendHelper.sendChatMessage("Removed &7${itemArg.value.registryName}&r from pickup list.") } else { MessageSendHelper.sendChatMessage("&7${itemArg.value.registryName}&r is not on the pickup list.") @@ -98,9 +105,9 @@ object WorldEaterCommand : ClientCommand( } literal("remove", "rem", "-") { int("id") { id -> - execute("Removes excavating area") { - val removed = WorldEater.quarries.value.removeAt(id.value) - MessageSendHelper.sendChatMessage("Removed excavating area $removed") + execute("Removes stash area") { + val removed = WorldEater.stashes.value.removeAt(id.value) + MessageSendHelper.sendChatMessage("Removed stash area $removed") } } } @@ -121,7 +128,7 @@ object WorldEaterCommand : ClientCommand( val safeArgs = CommandManager.tryParseArgument(args.joinToString(" ")) ?: return@execute val items = safeArgs.mapNotNull { Item.getByNameOrId(it) } - val dropOff = WorldEater.DropOff(WorldEater.Area(pos1.value, pos2.value), items) + val dropOff = WorldEater.Stash(WorldEater.Area(pos1.value, pos2.value), items) WorldEater.dropOff.value.add(dropOff) MessageSendHelper.sendChatMessage("Added drop-off area $dropOff") @@ -147,11 +154,23 @@ object WorldEaterCommand : ClientCommand( } execute("General setting info") { - MessageSendHelper.sendChatMessage("World eater settings:") - MessageSendHelper.sendChatMessage(" &7Pickup&r: ${WorldEater.collectables.value.joinToString { it.registryName.toString() }}") - MessageSendHelper.sendChatMessage(" &7Quarries&r: ${WorldEater.quarries.value.joinToString()}") - MessageSendHelper.sendChatMessage(" &7Stashes&r: ${WorldEater.stashes.value.joinToString()}") - MessageSendHelper.sendChatMessage(" &7Drop-off&r: ${WorldEater.dropOff.value.joinToString()}") + val string = "WorldEater settings:\n" + + "&7Pickup&r:\n" + + "${WorldEater.collectables.value.joinToString("\n") { + " &7+&r ${it.registryName.toString()}" + }}\n" + + "&7Quarries&r: ${ + if (WorldEater.quarries.value.isEmpty()) "None" + else WorldEater.quarries.value.joinToString() + }\n&7Stashes&r: ${ + if (WorldEater.stashes.value.isEmpty()) "None" + else WorldEater.stashes.value.joinToString() + }\n&7Drop-off&r: ${ + if (WorldEater.dropOff.value.isEmpty()) "None" + else WorldEater.dropOff.value.joinToString() + }" + + MessageSendHelper.sendChatMessage(string) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index d2028d2e1..78d872165 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,8 +1,9 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.inventory.DumpSlot -import com.lambda.client.activity.activities.storage.StoreItemsToStash +import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox +import com.lambda.client.activity.activities.storage.StashTransaction +import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.activity.types.RenderOverlayTextActivity @@ -10,6 +11,7 @@ import com.lambda.client.activity.types.RenderOverlayTextActivity.Companion.chec import com.lambda.client.activity.types.TimedActivity import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager +import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderOverlayEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.event.listener.listener @@ -18,6 +20,7 @@ import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick import com.lambda.client.module.modules.client.BuildTools.textScale import com.lambda.client.module.modules.client.BuildTools.tickDelay +import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.module.modules.player.AutoEat import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.TickTimer @@ -26,16 +29,19 @@ import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.graphics.GlStateUtils import com.lambda.client.util.graphics.ProjectionUtils import com.lambda.client.util.graphics.font.FontRenderAdapter +import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countEmpty +import com.lambda.client.util.items.countItem import com.lambda.client.util.items.inventorySlots -import com.lambda.client.util.items.item import com.lambda.client.util.math.CoordinateConverter.asString -import com.lambda.client.util.math.VectorUtils.toVec3dCenter +import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener -import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.Item import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.GL11 +import java.util.Optional object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() @@ -51,13 +57,7 @@ object ActivityManager : Manager, Activity() { /* life support systems */ if (AutoEat.eating) return@safeListener - if (BuildTools.storageManagement - && subActivities.filterIsInstance().isEmpty() - && player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots - ) { - MessageSendHelper.sendChatMessage("Inventory full, storing items to stash at ${BuildTools.storagePos1.value.asString()}") - addSubActivities(StoreItemsToStash(listOf(Blocks.STONE.item, Blocks.DIRT.item))) - } + if (BuildTools.storageManagement) maintainInventory() allSubActivities .filter { it.status == Status.RUNNING && it.subActivities.isEmpty() } @@ -98,9 +98,10 @@ object ActivityManager : Manager, Activity() { renderer.aOutline = BuildTools.aOutline renderer.thickness = BuildTools.thickness - RenderAABBActivity.normalizedRender.forEach { renderAABB -> - renderer.add(renderAABB.renderAABB, renderAABB.color) - } + RenderAABBActivity.normalizedRender + .forEach { renderAABB -> + renderer.add(renderAABB.renderAABB, renderAABB.color) + } renderer.render(true) } @@ -120,7 +121,12 @@ object ActivityManager : Manager, Activity() { val lineHeight = FontRenderAdapter.getFontHeight() + 2.0f val yLift = lineHeight * 3 / 2 - FontRenderAdapter.drawString(renderText.text, halfWidth, lineHeight * renderText.index - yLift, color = renderText.color) + FontRenderAdapter.drawString( + renderText.text, + halfWidth, + lineHeight * renderText.index - yLift, + color = renderText.color + ) GL11.glPopMatrix() } @@ -128,9 +134,8 @@ object ActivityManager : Manager, Activity() { } } - override fun getCurrentActivity(): Activity { - return subActivities.maxByOrNull { it.owner?.modulePriority ?: 0 }?.getCurrentActivity() ?: this - } + override fun getCurrentActivity() = + subActivities.maxByOrNull { it.owner?.modulePriority ?: 0 }?.getCurrentActivity() ?: this fun reset() { ListenerManager.listenerMap.keys.filterIsInstance().forEach { @@ -148,4 +153,80 @@ object ActivityManager : Manager, Activity() { BaritoneUtils.primary?.pathingBehavior?.cancelEverything() subActivities.clear() } + + private fun SafeClientEvent.maintainInventory() { + val stashOrders = mutableListOf>() + + if (subActivities.filterIsInstance().isEmpty() + && player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots + ) { + val itemsToStore = WorldEater.collectables.filter { + player.inventorySlots.countItem(it) > 0 + } + + if (itemsToStore.isNotEmpty()) { + val storeActivities = itemsToStore.map { + StoreItemToShulkerBox(it, 0) + } + + MessageSendHelper.sendChatMessage("Compressing ${ + storeActivities.joinToString { "${it.item.registryName}" } + } to shulker boxes.") + + addSubActivities(storeActivities) + } else if (subActivities.filterIsInstance().isEmpty()) { + stashOrders.addAll(itemsToStore.map { itemToStore -> + val optimalStash = WorldEater.dropOff + .filter { it.items.contains(itemToStore) } + .minBy { player.distanceTo(it.area.center) } + + MessageSendHelper.sendChatMessage("Inventory full. Storing ${ + itemToStore.registryName + } to stash at ${optimalStash.area.center}.") + + optimalStash to ContainerTransaction.Order( + ContainerTransaction.Action.PUSH, + itemToStore + ) + }) + } + } + + if (subActivities.filterIsInstance().isNotEmpty()) return + + if (BuildTools.usePickaxe) checkItem(Items.DIAMOND_PICKAXE).ifPresent { stashOrders.add(it) } + if (BuildTools.useShovel) checkItem(Items.DIAMOND_SHOVEL).ifPresent { stashOrders.add(it) } + if (BuildTools.useAxe) checkItem(Items.DIAMOND_AXE).ifPresent { stashOrders.add(it) } + if (BuildTools.useSword) checkItem(Items.DIAMOND_SWORD).ifPresent { stashOrders.add(it) } + if (BuildTools.useShears) checkItem(Items.SHEARS).ifPresent { stashOrders.add(it) } + + checkItem(Items.GOLDEN_APPLE).ifPresent { stashOrders.add(it) } + + if (stashOrders.isNotEmpty()) { + stashOrders.groupBy { it.first }.map { group -> + StashTransaction(group.key, group.value.map { it.second }) + }.forEach { + addSubActivities(it) + } + } + } + + private fun SafeClientEvent.checkItem(item: Item): Optional> { + if (player.allSlots.countItem(item) >= BuildTools.minToolAmount) return Optional.empty() + + val optimalStash = WorldEater.stashes + .filter { it.items.contains(item) } + .minBy { player.distanceTo(it.area.center) } + + MessageSendHelper.sendChatMessage("Missing ${ + item.registryName + }. Fetching from stash at ${optimalStash.area.center.asString()}.") + + return Optional.of( + optimalStash to ContainerTransaction.Order( + ContainerTransaction.Action.PULL, + item + ) + ) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 76e7dedef..dc012a66f 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -56,8 +56,6 @@ object BuildTools : Module( /* storage management */ val storageManagement by setting("Manage Storage", true, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets") - val storagePos1 = setting("Storage Pos 1", BlockPos.ORIGIN) - val storagePos2 = setting("Storage Pos 2", BlockPos.ORIGIN) // val searchEChest by setting("Search Ender Chest", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Allow access to your ender chest") // val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers") // val grindObsidian by setting("Grind Obsidian", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Destroy Ender Chests to obtain Obsidian") @@ -78,6 +76,7 @@ object BuildTools : Module( val useShovel by setting("Force Shovel", true, { page == Page.TOOLS }, description = "Use shovel to mine blocks") val useSword by setting("Force Sword", true, { page == Page.TOOLS }, description = "Use sword to mine blocks") val useShears by setting("Force Shears", true, { page == Page.TOOLS }, description = "Use shears to mine blocks") + val minToolAmount by setting("Min Tool Amount", 1, 0..10, 1, { page == Page.TOOLS }, description = "How many tools are saved") /* render */ // val info by setting("Show Info", true, { page == Page.RENDER }, description = "Prints session stats in chat") @@ -85,6 +84,7 @@ object BuildTools : Module( // val showCurrentPos by setting("Current Pos", false, { page == Page.RENDER }, description = "Renders the current position") val filled by setting("Filled", true, { page == Page.RENDER }, description = "Renders colored task surfaces") val outline by setting("Outline", true, { page == Page.RENDER }, description = "Renders colored task outlines") + val maxDistance by setting("Max Distance", 24, 0..256, 1, { page == Page.RENDER }, description = "Max distance to render tasks", unit = " blocks") // val popUp by setting("Pop up", true, { page == Page.RENDER }, description = "Funny render effect") // val popUpSpeed by setting("Pop up speed", 150, 0..500, 1, { page == Page.RENDER && popUp }, description = "Sets speed of the pop up effect", unit = "ms") val showDebugRender by setting("Debug Render", false, { page == Page.RENDER }, description = "Render debug info on tasks") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index a51883f2f..fef8fb426 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -41,12 +41,14 @@ object WorldEater : Module( Blocks.CLAY.item ) + val tools = setting(CollectionSetting("Tools", mutableListOf(), entryType = Item::class.java)) + val collectables = setting(CollectionSetting("Pick up items", defaultPickupItems, entryType = Item::class.java)) val quarries = setting(CollectionSetting("Quarries", mutableListOf(), entryType = Area::class.java)) val stashes = setting(CollectionSetting("Stashes", mutableListOf(), entryType = Stash::class.java)) - val dropOff = setting(CollectionSetting("Drop offs", mutableListOf(), entryType = DropOff::class.java)) + val dropOff = setting(CollectionSetting("Drop offs", mutableListOf(), entryType = Stash::class.java)) - private var ownedActivity: ClearArea? = null + var ownedActivity: ClearArea? = null init { onEnable { @@ -89,14 +91,9 @@ object WorldEater : Module( } } - data class DropOff(val area: Area, val items: List) { - override fun toString() = "($area)\n${items.joinToString { - " &7${it.registryName.toString()}\n" - }}" - } data class Stash(val area: Area, val items: List) { - override fun toString() = "($area)\n${items.joinToString { - " &7${it.registryName.toString()}\n" + override fun toString() = "$area\n ${items.joinToString("\n ") { + "&7+&r ${it.registryName.toString()}" }}" } @@ -112,6 +109,12 @@ object WorldEater : Module( get() = player.flooredPosition.x in minX..maxX && player.flooredPosition.z in minZ..maxZ + val containedBlockPositions: Set + get() = BlockPos.getAllInBox(pos1, pos2).toSet() + + val maxWidth: Int + get() = maxOf(maxX - minX + 1, maxZ - minZ + 1) + val minX: Int get() = minOf(pos1.x, pos2.x) val minY: Int @@ -125,6 +128,6 @@ object WorldEater : Module( val maxZ: Int get() = maxOf(pos1.z, pos2.z) - override fun toString() = "(${pos1.asString()})x(${pos2.asString()})" + override fun toString() = "(${pos1.asString()}x${pos2.asString()})" } } \ No newline at end of file From 292c68c2381949c94e72efe04bec129e794487ba Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sat, 15 Jul 2023 23:23:31 -0700 Subject: [PATCH 096/104] fixes, optimizations, and crash preventions --- .../com/lambda/client/activity/Activity.kt | 5 +++- .../construction/core/BuildStructure.kt | 3 +-- .../elements/client/ActivityManagerHud.kt | 4 ++-- .../lambda/client/gui/rgui/WindowComponent.kt | 4 ++-- .../manager/managers/ActivityManager.kt | 8 +++---- .../module/modules/client/BuildTools.kt | 23 ++++++++++++++----- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 6f889a3c6..832a756c1 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -334,12 +334,15 @@ abstract class Activity { subActivities } - acti.forEach { + acti.take(25).forEach { repeat(depth) { textComponent.add(" ") } it.appendInfo(textComponent, primaryColor, secondaryColor, details) } + if (acti.size > 25) { + textComponent.addLine("And ${acti.size - 25} more...", primaryColor) + } } override fun toString(): String { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 894c0509d..711c281cf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -24,7 +24,6 @@ import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.multiply -import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState @@ -78,7 +77,7 @@ class BuildStructure( if (subActivities.isEmpty() && !BaritoneUtils.isPathing) { // todo: offset pathing like this might not make sense for all structures. we aren't guaranteed to be at a specific position relative to the structure // we could path to the middle of the structure regardless of shape, but that will be inefficient. also structures are not guaranteed to be small/within render distance - if (autoPathing && !withinRangeOfStructure()) { + if (autoPathing && !withinRangeOfStructure() && offsetMove != BlockPos.ORIGIN) { LambdaMod.LOG.info("Structure out of range, pathing by offset") // todo: improve stop/start stutter pathing BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalXZ(player.posX.floorToInt() + (offsetMove.x * 5), player.posZ.floorToInt() + (offsetMove.z * 5))) diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt index 76c18c2c6..457029816 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt @@ -52,8 +52,8 @@ internal object ActivityManagerHud: LabelHud( if (sync.isNotEmpty() || async.isNotEmpty()) { displayText.addLine("") displayText.addLine("Subscribers:") - if (sync.isNotEmpty()) displayText.addLine("SYNC ${sync.map { it::class.simpleName }}") - if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.map { it::class.simpleName }}") + if (sync.isNotEmpty()) displayText.addLine("SYNC ${sync.take(100).map { it::class.simpleName }}${if (sync.size > 100) "..." else ""}") + if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.take(100).map { it::class.simpleName }}${if (async.size > 100) "..." else ""}") } } diff --git a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt index f2d10d173..9c32031a4 100644 --- a/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt +++ b/src/main/kotlin/com/lambda/client/gui/rgui/WindowComponent.kt @@ -132,8 +132,8 @@ open class WindowComponent( onResize() } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) { - posX = roundOnGrid(preDragPos.x + draggedDist.x).coerceIn(.0f, mc.displayWidth - width) - posY = roundOnGrid(preDragPos.y + draggedDist.y).coerceIn(.0f, mc.displayHeight - height) + posX = roundOnGrid(preDragPos.x + draggedDist.x).coerceIn(.0f, max(mc.displayWidth - width, 0.01f)) + posY = roundOnGrid(preDragPos.y + draggedDist.y).coerceIn(.0f, max(mc.displayHeight - height, 0.01f)) onReposition() } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 78d872165..28a6a2f20 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,8 +1,8 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.storage.StashTransaction +import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender @@ -41,7 +41,7 @@ import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.GL11 -import java.util.Optional +import java.util.* object ActivityManager : Manager, Activity() { private val renderer = ESPRenderer() @@ -216,8 +216,8 @@ object ActivityManager : Manager, Activity() { val optimalStash = WorldEater.stashes .filter { it.items.contains(item) } - .minBy { player.distanceTo(it.area.center) } - + .minByOrNull { player.distanceTo(it.area.center) } + optimalStash ?: return Optional.empty() MessageSendHelper.sendChatMessage("Missing ${ item.registryName }. Fetching from stash at ${optimalStash.area.center.asString()}.") diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index dc012a66f..badb58110 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -1,16 +1,17 @@ package com.lambda.client.module.modules.client -import com.lambda.client.activity.Activity import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting import com.lambda.client.util.items.shulkerList +import com.lambda.client.util.threads.safeListener import net.minecraft.block.Block import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item -import net.minecraft.util.math.BlockPos +import net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent object BuildTools : Module( name = "BuildTools", @@ -122,9 +123,6 @@ object BuildTools : Module( ANY, DIRECTION, VISIBLE } - val ignoredBlocks: List - get() = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } - var defaultFillerMat: Block get() = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK set(value) { @@ -148,7 +146,7 @@ object BuildTools : Module( "minecraft:wall_sign", "minecraft:standing_banner", "minecraft:wall_banner" - ).also { defaultIgnoreBlocks -> defaultIgnoreBlocks.addAll(shulkerList.map { it.localizedName }) } + ).also { defaultIgnoreBlocks -> defaultIgnoreBlocks.addAll(shulkerList.map { it.registryName.toString() }) } val defaultEjectList = linkedSetOf( "minecraft:grass", @@ -159,6 +157,19 @@ object BuildTools : Module( ) val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) + var ignoredBlocks: List = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } + init { + ignoreBlocks.editListeners.add { ignoredBlocks = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } } + + safeListener { + if (it.phase != TickEvent.Phase.START) return@safeListener + if (ignoreBlocks.size != ignoredBlocks.size) { + ignoreBlocks.filter { Block.getBlockFromName(it) == null }.forEach { ignoreBlocks.remove(it) } + ignoredBlocks = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } + } + } + } + val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, { false })) private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) private val food = setting("FoodItem", "minecraft:golden_apple", { false }) From dddb2baf5aa70f761fc1bcb5a71764d4c147ea1e Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 16 Jul 2023 16:34:09 +0200 Subject: [PATCH 097/104] Fix break reset --- .../activity/activities/construction/core/BreakBlock.kt | 3 +++ .../activity/activities/construction/core/BuildStructure.kt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 32447ef71..d6130b6bb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -157,6 +157,9 @@ class BreakBlock( } override fun SafeClientEvent.onInitialize() { + context = BuildActivity.Context.NONE + availability = BuildActivity.Availability.NONE + val currentState = world.getBlockState(blockPos) if (currentState.block in BuildTools.ignoredBlocks diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 711c281cf..cb5c33aa9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -186,13 +186,13 @@ class BuildStructure( /* block is not breakable */ if (currentState.getBlockHardness(world, blockPos) < 0) return - /* block is auto breakable like lilypad or tall grass */ + /* block is auto breakable like lily-pad or tall grass */ if (!breakBushes && currentState.block is BlockBush) return /* block should be ignored */ if (currentState.block in BuildTools.ignoredBlocks) return - /* only option left is breaking the block */ + /* the only option left is breaking the block */ addSubActivities(BreakBlock( blockPos, collectDrops = collectAll, minCollectAmount = 64 ), subscribe = true) From c0bd83599b34e820b7751ccff64dd84fe3d308b1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Sun, 6 Aug 2023 21:13:06 +0200 Subject: [PATCH 098/104] Improved inventory action data propagation --- .../lambda/client/activity/ActivityUtils.kt | 15 --- .../activities/construction/ClearArea.kt | 8 +- .../construction/core/BreakBlock.kt | 39 ++++--- .../construction/core/BuildStructure.kt | 5 +- .../construction/core/PlaceBlock.kt | 4 +- .../activities/interaction/AttachItemFrame.kt | 3 +- .../activities/interaction/AttachMap.kt | 3 +- .../interaction/crafting/CraftShulkerBox.kt | 5 +- .../interaction/crafting/ReachXPLevel.kt | 3 +- .../inventory/AcquireItemInActiveHand.kt | 110 +++++++++--------- .../inventory/core/SwapOrSwitchToSlot.kt | 15 +-- .../activity/activities/storage/Action.kt | 5 + .../activity/activities/storage/Area.kt | 39 +++++++ .../storage/BreakDownEnderChests.kt | 8 +- ...ox.kt => ExtractItemFromContainerStack.kt} | 25 ++-- .../activity/activities/storage/ItemInfo.kt | 34 ++++++ .../activity/activities/storage/Order.kt | 3 + .../activity/activities/storage/Stash.kt | 15 +++ .../activities/storage/StashTransaction.kt | 11 +- .../storage/StoreItemToEnderChest.kt | 10 ++ .../storage/StoreItemToShulkerBox.kt | 45 +++---- .../storage/core/ContainerTransaction.kt | 37 +++--- .../activities/storage/core/PlaceContainer.kt | 5 +- .../{PickUpDrops.kt => CollectDrops.kt} | 5 +- ...ckUpEntityItem.kt => CollectEntityItem.kt} | 2 +- .../command/commands/WorldEaterCommand.kt | 11 +- .../manager/managers/ActivityManager.kt | 55 ++++----- .../module/modules/client/BuildTools.kt | 4 +- .../module/modules/misc/HighwayTools.kt | 5 +- .../modules/misc/TestActivityManager.kt | 11 +- .../client/module/modules/misc/WorldEater.kt | 45 +------ .../client/module/modules/movement/Parkour.kt | 1 - .../serializables/ItemTypeAdapterFactory.kt | 2 + .../setting/settings/ImmutableSetting.kt | 2 +- .../client/setting/settings/MutableSetting.kt | 2 +- .../setting/settings/SettingRegister.kt | 21 +++- .../settings/impl/other/BindSetting.kt | 2 +- .../settings/impl/other/BlockPosSetting.kt | 11 -- .../settings/impl/other/ColorSetting.kt | 2 +- 39 files changed, 336 insertions(+), 292 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ExtractItemFromShulkerBox.kt => ExtractItemFromContainerStack.kt} (56%) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt rename src/main/kotlin/com/lambda/client/activity/activities/travel/{PickUpDrops.kt => CollectDrops.kt} (93%) rename src/main/kotlin/com/lambda/client/activity/activities/travel/{PickUpEntityItem.kt => CollectEntityItem.kt} (98%) delete mode 100644 src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt diff --git a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt index 53a8f3d9b..6e0bf5b49 100644 --- a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt @@ -22,21 +22,6 @@ fun getShulkerInventory(stack: ItemStack): NonNullList? { return shulkerInventory } -val slotFilterFunction = { - order: ContainerTransaction.Order -> { - slot: Slot -> if (order.containedInShulker) { - slot.stack.item is ItemShulkerBox - && getShulkerInventory(slot.stack)?.any { - it.item == order.item - && order.predicateStack(it) - && (order.metadata == null || order.metadata == it.metadata) - } == true - } else order.item == slot.stack.item - && order.predicateStack(slot.stack) - && (order.metadata == null || order.metadata == slot.stack.metadata) - } -} - /** * Get the slots of a container. * The first list contains the container slots, the second list contains the player slots. diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 5168161bd..570d4e8b4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -4,10 +4,12 @@ import baritone.api.pathing.goals.GoalTwoBlocks import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.activity.activities.storage.Area import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.misc.WorldEater +import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.text.MessageSendHelper import net.minecraft.block.state.IBlockState @@ -17,7 +19,7 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class ClearArea( - private val area: WorldEater.Area, + private val area: Area, private val layerSize: Int = 1, private val sliceSize: Int = 1, private val sliceDirection: EnumFacing = EnumFacing.NORTH, @@ -37,8 +39,8 @@ class ClearArea( override fun SafeClientEvent.onInitialize() { with(area) { - if (!playerInArea) { - MessageSendHelper.sendWarningMessage("You are not in the area $area! Moving now...") + if (player.flooredPosition !in area.containedBlocks) { + MessageSendHelper.sendWarningMessage("Player is not in the area $area! Moving now...") addSubActivities(CustomGoal(GoalXZ(center.x, center.z))) status = Status.UNINITIALIZED return@onInitialize diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index d6130b6bb..26dedd64e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -4,7 +4,8 @@ import baritone.api.BaritoneAPI import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent @@ -50,6 +51,7 @@ class BreakBlock( private val forceNoSilk: Boolean = false, private val forceFortune: Boolean = false, private val forceNoFortune: Boolean = false, + private val ignoreIgnored: Boolean = false, override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted breaks blockstates override val maxAttempts: Int = 5, override var usedAttempts: Int = 0, @@ -162,13 +164,20 @@ class BreakBlock( val currentState = world.getBlockState(blockPos) - if (currentState.block in BuildTools.ignoredBlocks + if (!ignoreIgnored && currentState.block in BuildTools.ignoredBlocks || currentState.getBlockHardness(world, blockPos) < 0 ) { success() return } + // ToDo: add silk touch support + drops = currentState.block.getItemDropped( + currentState, + Random(), + EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.heldItemMainhand) + ) ?: Items.AIR + updateState() resolveAvailability() } @@ -190,7 +199,7 @@ class BreakBlock( context = BuildActivity.Context.PICKUP addSubActivities( - PickUpDrops(drops, minAmount = minCollectAmount) + CollectDrops(drops, minAmount = minCollectAmount) ) } @@ -315,10 +324,15 @@ class BreakBlock( context = BuildActivity.Context.RESTOCK addSubActivities(AcquireItemInActiveHand( - tool, -// predicateItem = { -// EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 -// } + ItemInfo(tool, predicate = { + when { + forceSilk -> EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 + forceNoSilk -> EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 + forceFortune -> EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, it) > 0 + forceNoFortune -> EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, it) == 0 + else -> true + } + }), )) return false } @@ -376,7 +390,7 @@ class BreakBlock( private fun SafeClientEvent.updateProperties() { val currentState = world.getBlockState(blockPos) - if (currentState.block in BuildTools.ignoredBlocks) { + if (!ignoreIgnored && currentState.block in BuildTools.ignoredBlocks) { success() return } @@ -385,18 +399,11 @@ class BreakBlock( .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() timeout = ticksNeeded * 50L + 2000L - - // ToDo: add silk touch support - drops = currentState.block.getItemDropped( - currentState, - Random(), - EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.heldItemMainhand) - ) ?: Items.AIR } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { - is PickUpDrops -> { + is CollectDrops -> { ActivityManagerHud.totalBlocksBroken++ success() } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index cb5c33aa9..d8ea03d24 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -211,6 +211,9 @@ class BuildStructure( } ?: return this } + /** + * Find out more about task sorting [here](https://docs.google.com/spreadsheets/d/1oZWV4qNu3Gao-7w3X_v5pjzRcXWjDhURMCKU25IIKEE/edit?usp=sharing) + */ fun buildComparator() = compareBy { it.context }.thenBy { @@ -219,8 +222,6 @@ class BuildStructure( it.type }.thenBy { it.distance - }.thenBy { - it.hashCode() } private fun SafeClientEvent.isInPadding(blockPos: BlockPos) = isBehindPos(player.flooredPosition, blockPos) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index fe61c5b45..51cab26cb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent @@ -300,8 +301,7 @@ class PlaceBlock( context = BuildActivity.Context.RESTOCK addSubActivities(AcquireItemInActiveHand( - optimalStack.item, - predicateStack = { optimalStack.metadata == it.metadata } + ItemInfo(optimalStack.item, metadata = optimalStack.metadata) )) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt index b0c0ed683..00969fc56 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent @@ -30,7 +31,7 @@ class AttachItemFrame( rotation = getRotationTo(getHitVec(placePos, facing)) addSubActivities( - AcquireItemInActiveHand(Items.ITEM_FRAME) + AcquireItemInActiveHand(ItemInfo(Items.ITEM_FRAME)) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index e87f22814..608130933 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent @@ -32,7 +33,7 @@ class AttachMap( rotation = getRotationToEntity(itemFrame) addSubActivities( - AcquireItemInActiveHand(Items.MAP, predicateStack = { it.itemDamage == mapID }), + AcquireItemInActiveHand(ItemInfo(Items.MAP, predicate = { it.itemDamage == mapID })), ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt index ec2831541..791d15e90 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.interaction.crafting import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.InventoryTransaction +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item import net.minecraft.init.Blocks @@ -11,8 +12,8 @@ import net.minecraft.init.Items class CraftShulkerBox : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( - AcquireItemInActiveHand(Items.SHULKER_SHELL), - AcquireItemInActiveHand(Blocks.CHEST.item), + AcquireItemInActiveHand(ItemInfo(Items.SHULKER_SHELL)), + AcquireItemInActiveHand(ItemInfo(Blocks.CHEST.item)), // InventoryTransaction(0, ) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt index 3d77a9fc8..052c42280 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt @@ -4,6 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items @@ -18,7 +19,7 @@ class ReachXPLevel( override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), - AcquireItemInActiveHand(Items.EXPERIENCE_BOTTLE), + AcquireItemInActiveHand(ItemInfo(Items.EXPERIENCE_BOTTLE)), UseThrowableOnEntity(player) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index b4bc3b673..89a37d057 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -4,12 +4,9 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.CreativeInventoryAction import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot -import com.lambda.client.activity.activities.storage.BreakDownEnderChests -import com.lambda.client.activity.activities.storage.ExtractItemFromShulkerBox -import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.* import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.activity.getShulkerInventory -import com.lambda.client.activity.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock @@ -17,90 +14,83 @@ import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.item import net.minecraft.init.Blocks -import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemShulkerBox import net.minecraft.item.ItemStack +/** + * [AcquireItemInActiveHand] is an [Activity] that attempts to acquire an [Item] in the player's active hand. + * It will attempt to acquire the item in the following order: + * 1. Switch to the hotbar slot that contains the item + * 2. Swap the item with an item in the hotbar + */ class AcquireItemInActiveHand( - private val item: Item, - private val predicateStack: (ItemStack) -> Boolean = { true }, - private val predicateSlot: (ItemStack) -> Boolean = { true }, - private var metadata: Int? = null, - private val amount: Int = 1, - private val useShulkerBoxes: Boolean = true, - private val useEnderChest: Boolean = false, - override val maxAttempts: Int = 3, - override var usedAttempts: Int = 0 + private val itemInfo: ItemInfo, + private val searchShulkerBoxes: Boolean = true, + private val searchEnderChest: Boolean = true, ) : AttemptActivity, Activity() { + override val maxAttempts = 3 + override var usedAttempts = 0 + override fun SafeClientEvent.onInitialize() { - val order = ContainerTransaction.Order( - ContainerTransaction.Action.PUSH, - item, - amount, - predicateStack, - metadata, - predicateSlot - ) - - player.hotbarSlots.firstOrNull(slotFilterFunction(order))?.let { + // If the item is already in the player's hand, we're done + if (itemInfo.stackFilter(player.heldItemMainhand)) { + success() + return + } + + // If the item is in the hotbar, switch to it + player.hotbarSlots.firstOrNull(itemInfo.slotFilter)?.let { addSubActivities(SwitchToHotbarSlot(it)) return } + // If we are in game mode creative, we can just use the creative inventory (if item not yet in hotbar) if (pickBlock && player.capabilities.isCreativeMode) { - addSubActivities(CreativeInventoryAction( - ItemStack(item, 1, metadata ?: 0) - )) + addSubActivities(CreativeInventoryAction(itemInfo.optimalStack)) return } - player.allSlots.firstOrNull(slotFilterFunction(order))?.let { slotFrom -> - addSubActivities(SwapOrSwitchToSlot(slotFrom, order.predicateSlot)) + // If the item is in the inventory, swap it with next best slot in hotbar + player.allSlots.firstOrNull(itemInfo.slotFilter)?.let { slotFrom -> + addSubActivities(SwapOrSwitchToSlot(slotFrom)) return } - if (useShulkerBoxes && order.item !is ItemShulkerBox) { - val candidates = mutableMapOf() - - player.allSlots.forEach { slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - val count = inventory.count { - order.item == it.item - && order.predicateStack(it) - && (order.metadata == null || order.metadata == it.metadata) - } - - if (count > 0) candidates[slot] = count - } - } - - candidates.minByOrNull { it.value }?.key?.let { slot -> - addSubActivities(ExtractItemFromShulkerBox( - slot.stack, order - )) + // If the item is in a shulker box, extract it + if (searchShulkerBoxes && itemInfo.item !is ItemShulkerBox) { + selectOptimalShulker()?.let { slot -> + addSubActivities(ExtractItemFromContainerStack(slot.stack, itemInfo)) return } } - if (order.item == Blocks.OBSIDIAN.item) { + // If the item is obsidian, break down ender chests + if (itemInfo.item == Blocks.OBSIDIAN.item) { addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) return } -// if (useEnderChest) { -// addSubActivities(ExtractItemFromEnderChest(item, 1, predicateItem, predicateSlot)) // ToDo: Add this +// // If the item is contained in the ender chest, extract it +// if (searchEnderChest) { +// // TODO: Check cached ender chest inventory if item is in there directly or in a shulker box +// player.allSlots.firstOrNull { it.stack.item == Blocks.ENDER_CHEST.item }?.let { slot -> +// addSubActivities(ExtractItemFromContainerStack(slot.stack, itemInfo)) +// return +// } +// +// addSubActivities(AcquireItemInActiveHand(ItemInfo(Blocks.ENDER_CHEST.item), searchEnderChest = false)) // return // } - failedWith(NoItemFoundException(item, metadata)) + failedWith(NoItemFoundException(itemInfo)) } override fun SafeClientEvent.onSuccess() { val currentItemStack = player.heldItemMainhand - if (currentItemStack.item != item) { - failedWith(FailedToMoveItemException(item, metadata, currentItemStack)) + if (!itemInfo.stackFilter(currentItemStack)) { + failedWith(FailedToMoveItemException(itemInfo, currentItemStack)) } } @@ -110,6 +100,14 @@ class AcquireItemInActiveHand( status = Status.UNINITIALIZED } - class NoItemFoundException(item: Item, metadata: Int?) : Exception("No ${item.registryName}${metadata?.let { ":$it" } ?: ""} found in inventory") - class FailedToMoveItemException(item: Item, metadata: Int?, currentStack: ItemStack) : Exception("Failed to move ${item.registryName}${metadata?.let { ":$it" } ?: ""} to hotbar (current item: ${currentStack.item.registryName})") + private fun SafeClientEvent.selectOptimalShulker() = player.allSlots.mapNotNull { slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val count = inventory.count(itemInfo.stackFilter) + + if (count > 0) slot to count else null + } + }.minByOrNull { it.second }?.first + + class NoItemFoundException(itemInfo: ItemInfo) : Exception("No $itemInfo found in inventory") + class FailedToMoveItemException(itemInfo: ItemInfo, currentStack: ItemStack) : Exception("Failed to move $itemInfo} to hotbar (current item: ${currentStack.item.registryName})") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt index c60f8e6a6..b8d9b1a8f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/core/SwapOrSwitchToSlot.kt @@ -2,27 +2,22 @@ package com.lambda.client.activity.activities.inventory.core import com.lambda.client.activity.Activity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.firstEmpty import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.items.toHotbarSlotOrNull import net.minecraft.inventory.Slot -import net.minecraft.item.ItemStack class SwapOrSwitchToSlot( - private val slot: Slot, - private val predicateSlot: (ItemStack) -> Boolean = { true } + private val slotFrom: Slot, + private val hotbarFilter: (Slot) -> Boolean = { true } ) : Activity() { override fun SafeClientEvent.onInitialize() { - slot.toHotbarSlotOrNull()?.let { hotbarSlot -> + slotFrom.toHotbarSlotOrNull()?.let { hotbarSlot -> addSubActivities(SwitchToHotbarSlot(hotbarSlot)) } ?: run { - val hotbarSlots = player.hotbarSlots - val slotTo = hotbarSlots.firstEmpty() - ?: hotbarSlots.firstOrNull { predicateSlot(it.stack) } - ?: return + val slotTo = player.hotbarSlots.firstOrNull { hotbarFilter(it.slot) } ?: return addSubActivities( - SwapWithSlot(slot, slotTo.hotbarSlot), + SwapWithSlot(slotFrom, slotTo.hotbarSlot), SwitchToHotbarSlot(slotTo) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt new file mode 100644 index 000000000..fccbe4d09 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt @@ -0,0 +1,5 @@ +package com.lambda.client.activity.activities.storage + +enum class Action { + PULL, PUSH +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt new file mode 100644 index 000000000..4f2e9f472 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt @@ -0,0 +1,39 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.util.math.CoordinateConverter.asString +import net.minecraft.util.math.BlockPos + +/** + * [Area] is a data class that represents an area in the world. + * @param pos1 The first position of the area. + * @param pos2 The second position of the area. + */ +data class Area(val pos1: BlockPos, val pos2: BlockPos) { + val center: BlockPos + get() = BlockPos( + (pos1.x + pos2.x) / 2, + (pos1.y + pos2.y) / 2, + (pos1.z + pos2.z) / 2 + ) + + val containedBlocks: Set + get() = BlockPos.getAllInBox(pos1, pos2).toSet() + + val maxWidth: Int + get() = maxOf(maxX - minX + 1, maxZ - minZ + 1) + + val minX: Int + get() = minOf(pos1.x, pos2.x) + val minY: Int + get() = minOf(pos1.y, pos2.y) + val minZ: Int + get() = minOf(pos1.z, pos2.z) + val maxX: Int + get() = maxOf(pos1.x, pos2.x) + val maxY: Int + get() = maxOf(pos1.y, pos2.y) + val maxZ: Int + get() = maxOf(pos1.z, pos2.z) + + override fun toString() = "Area(${center.asString()})" +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt index 660d13a88..87142b228 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt @@ -29,7 +29,7 @@ class BreakDownEnderChests( if (freeSlots.isEmpty()) { if (player.inventorySlots.countItem(Blocks.OBSIDIAN.item) > 0) { addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + StoreItemToShulkerBox(ItemInfo(Blocks.OBSIDIAN.item, 0)) ) return } @@ -48,12 +48,12 @@ class BreakDownEnderChests( if (childActivity !is PlaceContainer) return addSubActivities( - AcquireItemInActiveHand( + AcquireItemInActiveHand(ItemInfo( Items.DIAMOND_PICKAXE, - predicateStack = { + predicate = { EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 } - ), + )), BreakBlock( childActivity.containerPos, collectDrops = true, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt similarity index 56% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt index c3592a576..d9a6785c4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt @@ -6,19 +6,20 @@ import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.CloseContainer import com.lambda.client.activity.activities.storage.core.PlaceContainer import com.lambda.client.activity.activities.storage.core.ContainerTransaction -import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.event.SafeClientEvent +import net.minecraft.init.Blocks import net.minecraft.item.ItemStack -class ExtractItemFromShulkerBox( - shulkerBoxStack: ItemStack, - private val order: ContainerTransaction.Order +class ExtractItemFromContainerStack( + containerStack: ItemStack, + private val itemInfo: ItemInfo ) : Activity() { - private val stack = shulkerBoxStack.copy() + private val containerStack = containerStack.copy() override fun SafeClientEvent.onInitialize() { addSubActivities( - PlaceContainer(stack, open = true) + PlaceContainer(containerStack, open = true) ) } @@ -26,11 +27,15 @@ class ExtractItemFromShulkerBox( if (childActivity !is PlaceContainer) return addSubActivities( - ContainerTransaction(order), + ContainerTransaction(Order(Action.PULL, itemInfo)), CloseContainer(), - BreakBlock(childActivity.containerPos), - PickUpDrops(stack.item), // BreakBlock doesn't collect drops - AcquireItemInActiveHand(order.item, order.predicateStack, order.predicateSlot) + BreakBlock( + childActivity.containerPos, + forceSilk = containerStack.item == Blocks.ENDER_CHEST, + ignoreIgnored = true + ), + CollectDrops(containerStack.item), + AcquireItemInActiveHand(itemInfo) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt new file mode 100644 index 000000000..4791d6097 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt @@ -0,0 +1,34 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.getShulkerInventory +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox +import net.minecraft.item.ItemStack + +data class ItemInfo( + val item: Item, + val number: Int = 1, // 0 = all + val predicate: (ItemStack) -> Boolean = { true }, + val metadata: Int? = null, + val containedInShulker: Boolean = false +) { + val optimalStack: ItemStack + get() = ItemStack(item, number, metadata ?: 0) + + val slotFilter = { slot: Slot -> + if (containedInShulker) { + slot.stack.item is ItemShulkerBox && getShulkerInventory(slot.stack)?.any { + stackFilter(it) + } == true + } else stackFilter(slot.stack) + } + + val stackFilter = { stack: ItemStack -> + item == stack.item + && predicate(stack) + && (metadata == null || metadata == stack.metadata) + } + + override fun toString() = "ItemInfo(item=$item, number=$number, metadata=$metadata, containedInShulker=$containedInShulker)" +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt new file mode 100644 index 000000000..673db3020 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt @@ -0,0 +1,3 @@ +package com.lambda.client.activity.activities.storage + +data class Order(val action: Action, val itemInfo: ItemInfo) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt new file mode 100644 index 000000000..037648d36 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt @@ -0,0 +1,15 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.util.math.CoordinateConverter.asString +import net.minecraft.item.Item + +/** + * [Stash] is a data class that represents a stash of [Item]s. + * @param area The area that the stash is located in. + * @param items The items that are in the stash. + */ +data class Stash(val area: Area, val items: List) { + override fun toString() = "Stash(${items.joinToString { + it.registryName.toString().split(":").last() + }})@(${area.center.asString()})" +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt index 59a57ffac..32d252a24 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt @@ -8,18 +8,17 @@ import com.lambda.client.activity.activities.storage.core.OpenContainer import com.lambda.client.activity.activities.storage.core.ContainerTransaction import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.math.VectorUtils.distanceTo import net.minecraft.tileentity.TileEntity /** - * [StashTransaction] is an [Activity] that allows you to pull or push items from a [WorldEater.Stash]. - * @param stash The [WorldEater.Stash] to pull or push items from. + * [StashTransaction] is an [Activity] that allows you to pull or push items from a [Stash]. + * @param stash The [Stash] to pull or push items from. * @param orders The orders to pull or push items. */ class StashTransaction( - private val stash: WorldEater.Stash, - private val orders: List + private val orders: List, + private val stash: Stash ) : Activity() { private val orderQueue = ArrayDeque(orders) private val containerQueue = ArrayDeque() @@ -43,7 +42,7 @@ class StashTransaction( if (childActivity.goal !is GoalNear) return val stashContainer = world.loadedTileEntityList.filter { - stash.area.containedBlockPositions.contains(it.pos) + stash.area.containedBlocks.contains(it.pos) } if (stashContainer.isEmpty()) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt new file mode 100644 index 000000000..05d613d17 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt @@ -0,0 +1,10 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import net.minecraft.item.ItemStack + +class StoreItemToEnderChest( + containerStack: ItemStack, + private val itemInfo: ItemInfo +) : Activity() { +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 7c5bcf5ee..054a10ba6 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -14,54 +14,43 @@ import net.minecraft.item.Item import net.minecraft.item.ItemStack class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes - val item: Item, - private val amount: Int = 0, // 0 = all - private val predicateStack: (ItemStack) -> Boolean = { true } + private val itemInfo: ItemInfo ) : Activity() { override fun SafeClientEvent.onInitialize() { - val candidates = mutableMapOf() - - if (player.allSlots.countItem(item) == 0) { + if (player.allSlots.countItem(itemInfo.item) == 0) { success() return } - player.allSlots.forEach { slot -> + player.allSlots.mapNotNull { slot -> getShulkerInventory(slot.stack)?.let { inventory -> - if (inventory.all { (it.item == item && predicateStack(it)) || it.isEmpty }) { - val count = inventory.count { it.item == item && predicateStack(it) } + if (inventory.all { itemInfo.stackFilter(it) || it.isEmpty }) { + val count = inventory.count { itemInfo.stackFilter(it) } - if (count < 27) candidates[slot] = count - } + if (count < 27) slot to count else null + } else null } - } - - if (candidates.isEmpty()) { - failedWith(NoShulkerBoxFoundStoreException(item)) - return - } - - candidates.maxBy { it.value }.key.let { slot -> + }.maxByOrNull { it.second }?.first?.let { slot -> addSubActivities( PlaceContainer(slot.stack.copy(), open = true) ) + return } + + failedWith(NoShulkerBoxFoundStoreException(itemInfo.item)) } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { if (childActivity !is PlaceContainer) return addSubActivities( - ContainerTransaction( - ContainerTransaction.Order( - ContainerTransaction.Action.PUSH, - item, - amount, - predicateStack - ) - ), + ContainerTransaction(Order(Action.PUSH, itemInfo)), CloseContainer(), - BreakBlock(childActivity.containerPos, collectDrops = true) + BreakBlock( + childActivity.containerPos, + collectDrops = true, + ignoreIgnored = true + ) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt index 80a7ac35d..bbe116aa4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt @@ -3,35 +3,20 @@ package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.activity.activities.inventory.core.SwapWithSlot +import com.lambda.client.activity.activities.storage.Action +import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.Order import com.lambda.client.activity.seperatedSlots -import com.lambda.client.activity.slotFilterFunction import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.items.countEmpty import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.inventory.Container -import net.minecraft.inventory.Slot -import net.minecraft.item.Item -import net.minecraft.item.ItemStack class ContainerTransaction( private val order: Order ) : Activity() { - - enum class Action { - PULL, PUSH - } - - data class Order( - val action: Action, - val item: Item, - val slotAmount: Int = 0, // 0 = all - val predicateStack: (ItemStack) -> Boolean = { true }, - val metadata: Int? = null, - val predicateSlot: (ItemStack) -> Boolean = { true }, - val containedInShulker: Boolean = false - ) - override fun SafeClientEvent.onInitialize() { val seperatedSlots = player.openContainer.seperatedSlots @@ -41,19 +26,19 @@ class ContainerTransaction( seperatedSlots.let { (first, second) -> Pair(second, first) } } - val toMoveSlots = fromSlots.filter(slotFilterFunction(order)) + val toMoveSlots = fromSlots.filter(order.itemInfo.slotFilter) if (toMoveSlots.isEmpty()) { failedWith(NoItemFoundException()) return } - if (toMoveSlots.size < order.slotAmount) { + if (toMoveSlots.size < order.itemInfo.number) { failedWith(NotEnoughSlotsException()) return } - val remainingSlots = if (order.slotAmount == 0) toMoveSlots else toMoveSlots.take(order.slotAmount) + val remainingSlots = if (order.itemInfo.number == 0) toMoveSlots else toMoveSlots.take(order.itemInfo.number) remainingSlots.forEach { fromSlot -> if (toSlots.countEmpty() > 0) { @@ -81,6 +66,14 @@ class ContainerTransaction( } } + override fun SafeClientEvent.onChildFailure(childActivities: ArrayDeque, childException: Exception): Boolean { + if (childException !is QuickMoveSlot.ExceptionSlotNotEmpty) return false + + MessageSendHelper.sendWarningMessage("Quick move failed, container full") + success() + return true + } + class NoSpaceLeftInInventoryException : Exception("No space left in inventory") class NoItemFoundException : Exception("No item found") class NotEnoughSlotsException : Exception("Not enough slots") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt index 695112dcf..72c7923b4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt @@ -3,6 +3,7 @@ package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition @@ -33,7 +34,9 @@ class PlaceContainer( } addSubActivities( - AcquireItemInActiveHand(targetStack.item, { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) }), + AcquireItemInActiveHand(ItemInfo( + targetStack.item, predicate = { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) } + )), PlaceBlock(containerPos, targetStack.item.block.defaultState, ignoreProperties = true) ) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt similarity index 93% rename from src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt rename to src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt index 362ed9b9a..3b41ad2e5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt @@ -8,7 +8,7 @@ import net.minecraft.entity.item.EntityItem import net.minecraft.item.Item import net.minecraft.item.ItemStack -class PickUpDrops( +class CollectDrops( private val item: Item, private val itemStack: ItemStack = ItemStack.EMPTY, private val predicate: (ItemStack) -> Boolean = { true }, @@ -31,10 +31,11 @@ class PickUpDrops( override fun SafeClientEvent.onInitialize() { if (drops.isEmpty() || drops.sumOf { it.item.count } < minAmount) { success() + return } drops.minByOrNull { drop -> player.distanceTo(drop.positionVector) }?.let { drop -> - addSubActivities(PickUpEntityItem(drop)) + addSubActivities(CollectEntityItem(drop)) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectEntityItem.kt similarity index 98% rename from src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt rename to src/main/kotlin/com/lambda/client/activity/activities/travel/CollectEntityItem.kt index 9b0ef6c43..e8a017bd8 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/PickUpEntityItem.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectEntityItem.kt @@ -12,7 +12,7 @@ import com.lambda.client.util.threads.safeListener import net.minecraft.entity.item.EntityItem import net.minecraftforge.fml.common.gameevent.TickEvent -class PickUpEntityItem( +class CollectEntityItem( private val entityItem: EntityItem, override val timeout: Long = 20000L ) : TimeoutActivity, Activity() { diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt index aaa9c0a72..7968579d9 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -1,7 +1,10 @@ package com.lambda.client.command.commands +import com.lambda.client.activity.activities.storage.Area +import com.lambda.client.activity.activities.storage.Stash import com.lambda.client.command.ClientCommand import com.lambda.client.command.CommandManager +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.text.MessageSendHelper import net.minecraft.item.Item @@ -61,9 +64,9 @@ object WorldEaterCommand : ClientCommand( blockPos("pos1") { pos1 -> blockPos("pos2") { pos2 -> execute("Adds excavating area") { - val area = WorldEater.Area(pos1.value, pos2.value) + val area = Area(pos1.value, pos2.value) - WorldEater.quarries.value.add(area) + WorldEater.quarries.add(area) MessageSendHelper.sendChatMessage("Added excavating area $area") } } @@ -94,7 +97,7 @@ object WorldEaterCommand : ClientCommand( val safeArgs = CommandManager.tryParseArgument(args.joinToString(" ")) ?: return@execute val items = safeArgs.mapNotNull { Item.getByNameOrId(it) } - val stash = WorldEater.Stash(WorldEater.Area(pos1.value, pos2.value), items) + val stash = Stash(Area(pos1.value, pos2.value), items) WorldEater.stashes.value.add(stash) MessageSendHelper.sendChatMessage("Added stash $stash") @@ -128,7 +131,7 @@ object WorldEaterCommand : ClientCommand( val safeArgs = CommandManager.tryParseArgument(args.joinToString(" ")) ?: return@execute val items = safeArgs.mapNotNull { Item.getByNameOrId(it) } - val dropOff = WorldEater.Stash(WorldEater.Area(pos1.value, pos2.value), items) + val dropOff = Stash(Area(pos1.value, pos2.value), items) WorldEater.dropOff.value.add(dropOff) MessageSendHelper.sendChatMessage("Added drop-off area $dropOff") diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 28a6a2f20..51144694b 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -1,9 +1,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.storage.StashTransaction -import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox -import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.* import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.activity.types.RenderOverlayTextActivity @@ -155,7 +153,7 @@ object ActivityManager : Manager, Activity() { } private fun SafeClientEvent.maintainInventory() { - val stashOrders = mutableListOf>() + val stashOrders = mutableListOf>() if (subActivities.filterIsInstance().isEmpty() && player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots @@ -165,29 +163,20 @@ object ActivityManager : Manager, Activity() { } if (itemsToStore.isNotEmpty()) { - val storeActivities = itemsToStore.map { - StoreItemToShulkerBox(it, 0) - } - MessageSendHelper.sendChatMessage("Compressing ${ - storeActivities.joinToString { "${it.item.registryName}" } + itemsToStore.joinToString { "${it.registryName}" } } to shulker boxes.") - addSubActivities(storeActivities) + addSubActivities(itemsToStore.map { + StoreItemToShulkerBox(ItemInfo(it, 0)) + }) } else if (subActivities.filterIsInstance().isEmpty()) { - stashOrders.addAll(itemsToStore.map { itemToStore -> - val optimalStash = WorldEater.dropOff + stashOrders.addAll(itemsToStore.mapNotNull { itemToStore -> + WorldEater.dropOff .filter { it.items.contains(itemToStore) } - .minBy { player.distanceTo(it.area.center) } - - MessageSendHelper.sendChatMessage("Inventory full. Storing ${ - itemToStore.registryName - } to stash at ${optimalStash.area.center}.") - - optimalStash to ContainerTransaction.Order( - ContainerTransaction.Action.PUSH, - itemToStore - ) + .minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> + stash to Order(Action.PUSH, ItemInfo(itemToStore, number = 0)) + } }) } } @@ -203,30 +192,28 @@ object ActivityManager : Manager, Activity() { checkItem(Items.GOLDEN_APPLE).ifPresent { stashOrders.add(it) } if (stashOrders.isNotEmpty()) { - stashOrders.groupBy { it.first }.map { group -> - StashTransaction(group.key, group.value.map { it.second }) - }.forEach { - addSubActivities(it) - } + addSubActivities(stashOrders.groupBy { it.first }.map { group -> + StashTransaction(group.value.map { it.second }, group.key) + }) + MessageSendHelper.sendChatMessage("Inventory full. Storing ${ + stashOrders.joinToString(" ") { "${it.second.itemInfo.item.registryName} -> ${it.first.area.center}" } + }") } } - private fun SafeClientEvent.checkItem(item: Item): Optional> { + private fun SafeClientEvent.checkItem(item: Item): Optional> { if (player.allSlots.countItem(item) >= BuildTools.minToolAmount) return Optional.empty() val optimalStash = WorldEater.stashes .filter { it.items.contains(item) } - .minByOrNull { player.distanceTo(it.area.center) } - optimalStash ?: return Optional.empty() + .minByOrNull { player.distanceTo(it.area.center) } ?: return Optional.empty() + MessageSendHelper.sendChatMessage("Missing ${ item.registryName }. Fetching from stash at ${optimalStash.area.center.asString()}.") return Optional.of( - optimalStash to ContainerTransaction.Order( - ContainerTransaction.Action.PULL, - item - ) + optimalStash to Order(Action.PULL, ItemInfo(item)) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index badb58110..cb25748d2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -4,6 +4,7 @@ import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting +import com.lambda.client.util.items.item import com.lambda.client.util.items.shulkerList import com.lambda.client.util.threads.safeListener import net.minecraft.block.Block @@ -11,7 +12,6 @@ import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraftforge.fml.common.gameevent.TickEvent -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent object BuildTools : Module( name = "BuildTools", @@ -161,7 +161,7 @@ object BuildTools : Module( init { ignoreBlocks.editListeners.add { ignoredBlocks = ignoreBlocks.mapNotNull { Block.getBlockFromName(it) } } - safeListener { + safeListener { if (it.phase != TickEvent.Phase.START) return@safeListener if (ignoreBlocks.size != ignoredBlocks.size) { ignoreBlocks.filter { Block.getBlockFromName(it) == null }.forEach { ignoreBlocks.remove(it) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt index f56d721f5..4c032775c 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/HighwayTools.kt @@ -6,8 +6,7 @@ import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module -import com.lambda.client.module.modules.client.BuildTools.defaultFillerMat -import com.lambda.client.module.modules.misc.HighwayTools.printEnable +import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.multiply @@ -236,7 +235,7 @@ object HighwayTools : Module( ) } - private fun fillerState() = defaultFillerMat.defaultState + private fun fillerState() = Blocks.NETHERRACK.defaultState private val materialSaved = setting("Material", "minecraft:obsidian", { false }) } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index aeecc0802..f1c2a5e27 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -6,8 +6,9 @@ import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.interaction.crafting.ReachXPLevel import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.BreakDownEnderChests +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox -import com.lambda.client.activity.activities.travel.PickUpDrops +import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities @@ -37,14 +38,14 @@ object TestActivityManager : Module( private val tie by setting("Store Obby", false, consumer = { _, _-> addSubActivities( - StoreItemToShulkerBox(Blocks.OBSIDIAN.item) + StoreItemToShulkerBox(ItemInfo(Blocks.OBSIDIAN.item, 0)) ) false }) private val etit by setting("Acquire Obby", false, consumer = { _, _-> addSubActivities( - AcquireItemInActiveHand(Blocks.OBSIDIAN.item) + AcquireItemInActiveHand(ItemInfo(Blocks.OBSIDIAN.item)) ) false }) @@ -96,7 +97,7 @@ object TestActivityManager : Module( }) private val po by setting("Pickup Obby", false, consumer = { _, _-> - addSubActivities(PickUpDrops(Blocks.OBSIDIAN.item)) + addSubActivities(CollectDrops(Blocks.OBSIDIAN.item)) false }) @@ -104,7 +105,7 @@ object TestActivityManager : Module( runSafe { val stack = player.heldItemMainhand.copy() - addSubActivities(PickUpDrops(stack.item, stack)) + addSubActivities(CollectDrops(stack.item, stack)) } false diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index fef8fb426..a32b763cb 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,22 +1,21 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.ClearArea +import com.lambda.client.activity.activities.storage.Area +import com.lambda.client.activity.activities.storage.Stash import com.lambda.client.command.CommandManager.prefix import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting -import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.items.item -import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe import net.minecraft.init.Blocks import net.minecraft.item.Item import net.minecraft.util.EnumFacing -import net.minecraft.util.math.BlockPos object WorldEater : Module( name = "WorldEater", @@ -90,44 +89,4 @@ object WorldEater : Module( } } } - - data class Stash(val area: Area, val items: List) { - override fun toString() = "$area\n ${items.joinToString("\n ") { - "&7+&r ${it.registryName.toString()}" - }}" - } - - data class Area(val pos1: BlockPos, val pos2: BlockPos) { - val center: BlockPos - get() = BlockPos( - (pos1.x + pos2.x) / 2, - (pos1.y + pos2.y) / 2, - (pos1.z + pos2.z) / 2 - ) - - val SafeClientEvent.playerInArea: Boolean - get() = player.flooredPosition.x in minX..maxX - && player.flooredPosition.z in minZ..maxZ - - val containedBlockPositions: Set - get() = BlockPos.getAllInBox(pos1, pos2).toSet() - - val maxWidth: Int - get() = maxOf(maxX - minX + 1, maxZ - minZ + 1) - - val minX: Int - get() = minOf(pos1.x, pos2.x) - val minY: Int - get() = minOf(pos1.y, pos2.y) - val minZ: Int - get() = minOf(pos1.z, pos2.z) - val maxX: Int - get() = maxOf(pos1.x, pos2.x) - val maxY: Int - get() = maxOf(pos1.y, pos2.y) - val maxZ: Int - get() = maxOf(pos1.z, pos2.z) - - override fun toString() = "(${pos1.asString()}x${pos2.asString()})" - } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/movement/Parkour.kt b/src/main/kotlin/com/lambda/client/module/modules/movement/Parkour.kt index 07ea8bb58..915d2cfdf 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/movement/Parkour.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/movement/Parkour.kt @@ -5,7 +5,6 @@ import com.lambda.client.event.listener.listener import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.client.GuiColors -import com.lambda.client.module.modules.render.Search.setting import com.lambda.client.util.Wrapper import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.graphics.GeometryMasks diff --git a/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt b/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt index af98a58ac..ff895cd8d 100644 --- a/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt +++ b/src/main/kotlin/com/lambda/client/setting/serializables/ItemTypeAdapterFactory.kt @@ -10,9 +10,11 @@ import net.minecraft.item.Item object ItemTypeAdapterFactory : TypeAdapterFactory { override fun create(gson: Gson, type: TypeToken): TypeAdapter? { + @Suppress("UNNECESSARY_SAFE_CALL") if (!Item::class.java.isAssignableFrom(type?.rawType)) return null val jsonObjectAdapter = gson.getAdapter(JsonObject::class.java) + @Suppress("UNCHECKED_CAST") return object : TypeAdapter() { override fun write(out: com.google.gson.stream.JsonWriter, value: Item?) { if (value == null) { diff --git a/src/main/kotlin/com/lambda/client/setting/settings/ImmutableSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/ImmutableSetting.kt index 9ad33535b..2239182e5 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/ImmutableSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/ImmutableSetting.kt @@ -15,7 +15,7 @@ abstract class ImmutableSetting( override val visibility: () -> Boolean, val consumer: (prev: T, input: T) -> T, override val description: String, - override val unit: String + override val unit: String = "" ) : AbstractSetting() { override val value: T = valueIn override val valueClass: Class = valueIn.javaClass diff --git a/src/main/kotlin/com/lambda/client/setting/settings/MutableSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/MutableSetting.kt index 05ee5b3d8..a8cf950af 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/MutableSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/MutableSetting.kt @@ -18,7 +18,7 @@ open class MutableSetting( override val visibility: () -> Boolean, consumer: (prev: T, input: T) -> T, override val description: String, - override val unit: String + override val unit: String = "" ) : AbstractSetting() { override val defaultValue = valueIn diff --git a/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt b/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt index 41440743d..061f96720 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/SettingRegister.kt @@ -4,13 +4,14 @@ import com.lambda.client.setting.settings.impl.number.DoubleSetting import com.lambda.client.setting.settings.impl.number.FloatSetting import com.lambda.client.setting.settings.impl.number.IntegerSetting import com.lambda.client.setting.settings.impl.other.BindSetting -import com.lambda.client.setting.settings.impl.other.BlockPosSetting import com.lambda.client.setting.settings.impl.other.ColorSetting import com.lambda.client.setting.settings.impl.primitive.BooleanSetting import com.lambda.client.setting.settings.impl.primitive.EnumSetting import com.lambda.client.setting.settings.impl.primitive.StringSetting import com.lambda.client.util.Bind import com.lambda.client.util.color.ColorHolder +import net.minecraft.block.Block +import net.minecraft.item.Item import net.minecraft.util.math.BlockPos import java.util.function.BooleanSupplier @@ -83,7 +84,23 @@ interface SettingRegister { value: BlockPos, visibility: () -> Boolean = { true }, description: String = "" - ) = setting(BlockPosSetting(name, value, visibility, description)) + ) = setting(MutableSetting(name, value, visibility, { _, input -> input }, description, unit = "")) + + /** Item Setting */ + fun T.setting( + name: String, + value : Item, + visibility: () -> Boolean = { true }, + description: String = "" + ) = setting(MutableSetting(name, value, visibility, { _, input -> input }, description, unit = "")) + + /** Block Setting */ + fun T.setting( + name: String, + value : Block, + visibility: () -> Boolean = { true }, + description: String = "" + ) = setting(MutableSetting(name, value, visibility, { _, input -> input }, description, unit = "")) /** Boolean Setting */ fun T.setting( diff --git a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BindSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BindSetting.kt index 23e224f27..1d82b415a 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BindSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BindSetting.kt @@ -12,7 +12,7 @@ class BindSetting( value: Bind, visibility: () -> Boolean = { true }, description: String = "" -) : ImmutableSetting(name, value, visibility, { _, input -> input }, description, unit = "") { +) : ImmutableSetting(name, value, visibility, { _, input -> input }, description) { override val defaultValue: Bind = Bind(TreeSet(value.modifierKeys), value.key, null) diff --git a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt deleted file mode 100644 index 48fa11857..000000000 --- a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/BlockPosSetting.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.lambda.client.setting.settings.impl.other - -import com.lambda.client.setting.settings.MutableSetting -import net.minecraft.util.math.BlockPos - -class BlockPosSetting( - name: String, - value: BlockPos, - visibility: () -> Boolean = { true }, - description: String = "" -) : MutableSetting(name, value, visibility, { _, input -> input }, description, unit = "") \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/ColorSetting.kt b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/ColorSetting.kt index 3feb506e4..f424b2a33 100644 --- a/src/main/kotlin/com/lambda/client/setting/settings/impl/other/ColorSetting.kt +++ b/src/main/kotlin/com/lambda/client/setting/settings/impl/other/ColorSetting.kt @@ -9,4 +9,4 @@ class ColorSetting( val hasAlpha: Boolean = true, visibility: () -> Boolean = { true }, description: String = "" -) : MutableSetting(name, value, visibility, { _, input -> if (!hasAlpha) input.apply { a = 255 } else input }, description, unit = "") \ No newline at end of file +) : MutableSetting(name, value, visibility, { _, input -> if (!hasAlpha) input.apply { a = 255 } else input }, description) \ No newline at end of file From a11a23c4ce8cbccb8e2a494cbf201a4f908da7a9 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 7 Aug 2023 04:06:58 +0200 Subject: [PATCH 099/104] Make pathfinding actually kinda work --- .../com/lambda/client/activity/Activity.kt | 2 +- .../construction/core/BreakBlock.kt | 16 ++++-- .../construction/core/BuildStructure.kt | 50 ++++++++++++++++--- .../construction/core/PlaceBlock.kt | 4 ++ .../storage/core/ContainerTransaction.kt | 1 - .../client/activity/types/BuildActivity.kt | 1 + .../module/modules/client/BuildTools.kt | 5 +- 7 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 832a756c1..c4ec88af0 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -149,7 +149,7 @@ abstract class Activity { checkRepeat(activity) checkLoopingUntil(activity) - BaritoneUtils.primary?.pathingBehavior?.cancelEverything() +// BaritoneUtils.primary?.pathingBehavior?.cancelEverything() // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") // MessageSendHelper.sendRawChatMessage("$name took ${age}ms") diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 26dedd64e..e89e6637c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -53,12 +53,13 @@ class BreakBlock( private val forceNoFortune: Boolean = false, private val ignoreIgnored: Boolean = false, override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted breaks blockstates - override val maxAttempts: Int = 5, + override val maxAttempts: Int = 20, override var usedAttempts: Int = 0, override val aabbCompounds: MutableSet = mutableSetOf(), override val overlayTexts: MutableSet = mutableSetOf(), override var rotation: Vec2f? = null, override var distance: Double = 1337.0, + override var exposedSides: Int = 0, ) : BuildActivity, TimeoutActivity, AttemptActivity, RotatingActivity, TimedActivity, RenderAABBActivity, RenderOverlayTextActivity, Activity() { private var side: EnumFacing? = null private var ticksNeeded = 0 @@ -208,8 +209,8 @@ class BreakBlock( updateProperties() - getMiningSide(blockPos, BuildTools.maxReach)?.let { - val hitVec = getHitVec(blockPos, it) + getMiningSide(blockPos, BuildTools.maxReach)?.let { miningSide -> + val hitVec = getHitVec(blockPos, miningSide) /* prevent breaking the block the player is standing on */ if (player.flooredPosition.down() == blockPos @@ -217,11 +218,13 @@ class BreakBlock( ) { availability = BuildActivity.Availability.BLOCKED_BY_PLAYER distance = player.distanceTo(hitVec) + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } return } availability = BuildActivity.Availability.VALID distance = player.distanceTo(hitVec) - side = it + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } + side = miningSide rotation = getRotationTo(hitVec) return } @@ -229,9 +232,11 @@ class BreakBlock( getMiningSide(blockPos)?.let { availability = BuildActivity.Availability.NOT_IN_RANGE distance = player.distanceTo(getHitVec(blockPos, it)) + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } } ?: run { availability = BuildActivity.Availability.NOT_EXPOSED distance = 1337.0 + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } } playerController.resetBlockRemoving() @@ -247,6 +252,7 @@ class BreakBlock( BuildActivity.Availability.BLOCKED_BY_PLAYER, BuildActivity.Availability.NOT_IN_RANGE -> { // Wait for player move + timeout = Long.MAX_VALUE // ToDo: find a better way to do this } BuildActivity.Availability.WRONG_ITEM_SELECTED -> { // acquireOptimalTool() @@ -398,7 +404,7 @@ class BreakBlock( ticksNeeded = ceil((1 / currentState .getPlayerRelativeBlockHardness(player, world, blockPos)) * BuildTools.miningSpeedFactor).toInt() - timeout = ticksNeeded * 50L + 2000L + timeout = ticksNeeded * 50L + 100L } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index d8ea03d24..33c3677bb 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,6 +7,7 @@ import baritone.api.pathing.goals.GoalXZ import baritone.process.BuilderProcess.GoalAdjacent import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.travel.CollectEntityItem import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity @@ -15,6 +16,7 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing +import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.color.ColorHolder @@ -23,10 +25,12 @@ import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.math.VectorUtils.manhattanDistanceTo import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState +import net.minecraft.entity.item.EntityItem import net.minecraft.init.Blocks import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.network.play.server.SPacketMultiBlockChange @@ -34,6 +38,8 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import kotlin.properties.Delegates +import kotlin.reflect.KProperty class BuildStructure( private val structure: Map, @@ -48,7 +54,10 @@ class BuildStructure( override val aabbCompounds: MutableSet = mutableSetOf() ) : RepeatingActivity, RenderAABBActivity, Activity() { private var currentOffset = BlockPos.ORIGIN - private var lastGoal: Goal? = null + private var lastGoal: Goal? by Delegates.observable(null) { _, old, new -> + if (old != new) lastGoalSet = System.currentTimeMillis() + } + private var lastGoalSet: Long = 0L private val renderAABB = RenderAABBActivity.Companion.RenderAABB( AxisAlignedBB(BlockPos.ORIGIN), ColorHolder(255, 255, 255) @@ -71,8 +80,8 @@ class BuildStructure( } init { - safeListener { - if (it.phase != TickEvent.Phase.END) return@safeListener + safeListener { event -> + if (event.phase != TickEvent.Phase.END) return@safeListener if (subActivities.isEmpty() && !BaritoneUtils.isPathing) { // todo: offset pathing like this might not make sense for all structures. we aren't guaranteed to be at a specific position relative to the structure @@ -86,7 +95,33 @@ class BuildStructure( success() } - when (val activity = getCurrentActivity()) { + val activity = getCurrentActivity() + + // no forced moving on other activities + if (!activity.hasNoSubActivities) return@safeListener + + // pathing cool-down + if (System.currentTimeMillis() - lastGoalSet < BuildTools.pathingRecomputeTimeout) { + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(lastGoal) + return@safeListener + } + + val itemsInRange = world.loadedEntityList + .filterIsInstance() + .filter { player.manhattanDistanceTo(it.position) <= 5 && it.item.item in WorldEater.collectables } + + // collect drops + if (collectAll && itemsInRange.sumOf { it.item.count } > BuildTools.pickupMinimumItemAmount) { + itemsInRange.groupBy { it.item.item }.maxByOrNull { it.value.size }?.let { largestGroup -> + largestGroup.value.minByOrNull { player.manhattanDistanceTo(it.position) }?.let { + lastGoal = GoalBlock(it.position) + return@safeListener + } + } + } + + // move to next activity + when (activity) { is PlaceBlock -> { val blockPos = activity.blockPos @@ -194,7 +229,8 @@ class BuildStructure( /* the only option left is breaking the block */ addSubActivities(BreakBlock( - blockPos, collectDrops = collectAll, minCollectAmount = 64 +// blockPos, collectDrops = collectAll, minCollectAmount = 64 + blockPos ), subscribe = true) } @@ -220,6 +256,8 @@ class BuildStructure( it.availability }.thenBy { it.type + }.thenByDescending { + it.exposedSides }.thenBy { it.distance } @@ -246,7 +284,7 @@ class BuildStructure( if (exists) return val available = player.inventorySlots - .filterByStack { BuildTools.ejectList.value.contains(it.item.block.registryName.toString()) } + .filterByStack { BuildTools.ejectList.contains(it.item.block.registryName.toString()) } .maxByOrNull { it.stack.count }?.stack?.item?.block ?: Blocks.AIR if (available == Blocks.AIR) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 51cab26cb..48cbd3a07 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -46,6 +46,7 @@ class PlaceBlock( private val ignoreFacing: Boolean = false, override var rotation: Vec2f? = null, override var distance: Double = 1337.0, + override var exposedSides: Int = 0, override var timeout: Long = Long.MAX_VALUE, // ToDo: Reset timeouted placements blockstates override val maxAttempts: Int = 8, override var usedAttempts: Int = 0, @@ -257,6 +258,7 @@ class PlaceBlock( availability = BuildActivity.Availability.VALID it.hitVec = it.hitVec.add(placementOffset.offset) distance = player.distanceTo(it.hitVec) + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } placeInfo = it } else { // action = BuildActivity.BuildAction.NEEDS_SUPPORT @@ -276,9 +278,11 @@ class PlaceBlock( )?.let { availability = BuildActivity.Availability.NOT_IN_RANGE distance = player.distanceTo(it.hitVec.add(placementOffset.offset)) + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } } ?: run { availability = BuildActivity.Availability.NOT_VISIBLE distance = 1337.0 + exposedSides = EnumFacing.HORIZONTALS.count { world.isAirBlock(blockPos.offset(it)) } } placeInfo = null rotation = null diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt index bbe116aa4..ca919e8ce 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt @@ -4,7 +4,6 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.activity.activities.inventory.core.SwapWithSlot import com.lambda.client.activity.activities.storage.Action -import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.activities.storage.Order import com.lambda.client.activity.seperatedSlots import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt index 458a5a481..1a4793632 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/BuildActivity.kt @@ -6,6 +6,7 @@ interface BuildActivity { var context: Context var availability: Availability var type: Type + var exposedSides: Int var distance: Double enum class Context(val color: ColorHolder) { diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index cb25748d2..973fa84ee 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -4,7 +4,6 @@ import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.setting.settings.impl.collection.CollectionSetting -import com.lambda.client.util.items.item import com.lambda.client.util.items.shulkerList import com.lambda.client.util.threads.safeListener import net.minecraft.block.Block @@ -25,7 +24,9 @@ object BuildTools : Module( /* behavior */ val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BUILDING }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") val autoPathing by setting("Auto Pathing", true, { page == Page.BUILDING }, description = "Automatically pathfind to the next block") -// val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") + val pathingRecomputeTimeout by setting("Pathing Recompute Timeout", 200, 0..1000, 20, { page == Page.BUILDING }, description = "Timeout for recomputing the path", unit = " ms") + val pickupMinimumItemAmount by setting("Pickup Minimum Item Amount", 32, 1..64, 1, { page == Page.BUILDING }, description = "Minimum amount of items to pick up", unit = " items") + // val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") // val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") // val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") // val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag", unit = " ticks") From 431b8632d853bd49b9fdfa7bc40bcdf846f3611c Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 7 Aug 2023 06:52:14 +0200 Subject: [PATCH 100/104] Fixing pathing bugs and more efficient item collecting --- .../construction/core/BuildStructure.kt | 38 ++++++------ .../activity/activities/storage/ItemInfo.kt | 2 +- .../storage/core/ContainerTransaction.kt | 2 +- .../manager/managers/ActivityManager.kt | 59 +++++++++++++------ .../module/modules/client/BuildTools.kt | 5 +- .../client/module/modules/misc/WorldEater.kt | 6 +- 6 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 33c3677bb..8ccfb319e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,13 +7,13 @@ import baritone.api.pathing.goals.GoalXZ import baritone.process.BuilderProcess.GoalAdjacent import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.travel.CollectEntityItem import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.commons.extension.floorToInt import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent +import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.autoPathing import com.lambda.client.module.modules.misc.WorldEater @@ -25,7 +25,6 @@ import com.lambda.client.util.items.filterByStack import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.Direction import com.lambda.client.util.math.VectorUtils.distanceTo -import com.lambda.client.util.math.VectorUtils.manhattanDistanceTo import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.threads.safeListener import net.minecraft.block.BlockBush @@ -39,7 +38,6 @@ import net.minecraft.util.math.BlockPos import net.minecraftforge.event.world.BlockEvent import net.minecraftforge.fml.common.gameevent.TickEvent import kotlin.properties.Delegates -import kotlin.reflect.KProperty class BuildStructure( private val structure: Map, @@ -54,7 +52,7 @@ class BuildStructure( override val aabbCompounds: MutableSet = mutableSetOf() ) : RepeatingActivity, RenderAABBActivity, Activity() { private var currentOffset = BlockPos.ORIGIN - private var lastGoal: Goal? by Delegates.observable(null) { _, old, new -> + private var currentGoal: Goal? by Delegates.observable(null) { _, old, new -> if (old != new) lastGoalSet = System.currentTimeMillis() } private var lastGoalSet: Long = 0L @@ -95,28 +93,34 @@ class BuildStructure( success() } - val activity = getCurrentActivity() + val activity = ActivityManager.getCurrentActivity() // no forced moving on other activities - if (!activity.hasNoSubActivities) return@safeListener + if (activity is PlaceBlock && activity.context != BuildActivity.Context.NONE) return@safeListener + if (activity is BreakBlock && activity.context != BuildActivity.Context.NONE) return@safeListener + if (!activity.hasNoSubActivities || activity !in subActivities) return@safeListener // pathing cool-down if (System.currentTimeMillis() - lastGoalSet < BuildTools.pathingRecomputeTimeout) { - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(lastGoal) + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(currentGoal) return@safeListener } val itemsInRange = world.loadedEntityList .filterIsInstance() - .filter { player.manhattanDistanceTo(it.position) <= 5 && it.item.item in WorldEater.collectables } + .filter { + player.distanceTo(it.position) <= BuildTools.collectRange + && it.item.item in WorldEater.collectables + } // collect drops - if (collectAll && itemsInRange.sumOf { it.item.count } > BuildTools.pickupMinimumItemAmount) { - itemsInRange.groupBy { it.item.item }.maxByOrNull { it.value.size }?.let { largestGroup -> - largestGroup.value.minByOrNull { player.manhattanDistanceTo(it.position) }?.let { - lastGoal = GoalBlock(it.position) - return@safeListener - } + if (collectAll + && autoPathing + && (itemsInRange.maxOfOrNull { it.item.count } ?: 0) > BuildTools.minimumStackSize + ) { + itemsInRange.maxByOrNull { it.item.count / player.distanceTo(it.position) }?.let { largestStack -> + currentGoal = GoalBlock(largestStack.position) + return@safeListener } } @@ -129,7 +133,7 @@ class BuildStructure( if (!autoPathing) return@safeListener - lastGoal = if (isInBlockAABB(blockPos)) { + currentGoal = if (isInBlockAABB(blockPos)) { GoalInverted(GoalBlock(blockPos)) } else { GoalAdjacent(blockPos, blockPos, true) @@ -142,7 +146,7 @@ class BuildStructure( if (!autoPathing) return@safeListener - lastGoal = if (!allowBreakDescend && isInBlockAABB(blockPos.up())) { + currentGoal = if (!allowBreakDescend && isInBlockAABB(blockPos.up())) { GoalInverted(GoalBlock(blockPos.up())) } else { GoalAdjacent(blockPos, blockPos, true) @@ -150,7 +154,7 @@ class BuildStructure( } } - lastGoal?.let { goal -> + currentGoal?.let { goal -> BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) } } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt index 4791d6097..9f72a89a5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt @@ -11,7 +11,7 @@ data class ItemInfo( val number: Int = 1, // 0 = all val predicate: (ItemStack) -> Boolean = { true }, val metadata: Int? = null, - val containedInShulker: Boolean = false + var containedInShulker: Boolean = false ) { val optimalStack: ItemStack get() = ItemStack(item, number, metadata ?: 0) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt index ca919e8ce..1be15c499 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt @@ -74,7 +74,7 @@ class ContainerTransaction( } class NoSpaceLeftInInventoryException : Exception("No space left in inventory") - class NoItemFoundException : Exception("No item found") + class NoItemFoundException : Exception("No item to move found") class NotEnoughSlotsException : Exception("Not enough slots") class ContainerNotKnownException(val container: Container) : Exception("Container ${container::class.simpleName} not known") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 51144694b..453b78b09 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -2,6 +2,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.storage.* +import com.lambda.client.activity.getShulkerInventory import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.activity.types.RenderOverlayTextActivity @@ -37,6 +38,7 @@ import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener import net.minecraft.init.Items import net.minecraft.item.Item +import net.minecraft.item.ItemShulkerBox import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.GL11 import java.util.* @@ -153,36 +155,45 @@ object ActivityManager : Manager, Activity() { } private fun SafeClientEvent.maintainInventory() { + if (subActivities.filterIsInstance().isNotEmpty() + || allSubActivities.filterIsInstance().isNotEmpty() + || subActivities.filterIsInstance().isNotEmpty() + ) return + val stashOrders = mutableListOf>() - if (subActivities.filterIsInstance().isEmpty() - && player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots - ) { + if (player.allSlots.none { slot -> getShulkerInventory(slot.stack)?.all { it.isEmpty } == true }) { + MessageSendHelper.sendChatMessage("No empty shulker boxes found, requesting new ones.") + + val fullShulkerItem = player.allSlots + .filter { slot -> getShulkerInventory(slot.stack)?.none { it.isEmpty } == true } + .mapNotNull { slot -> getShulkerInventory(slot.stack)?.firstOrNull()?.item } + + stashOrders.addAll(fullShulkerItem.mapNotNull { itemShulkerToStore -> + WorldEater.dropOff + .filter { it.items.contains(itemShulkerToStore) } + .minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> + stash to Order(Action.PUSH, ItemInfo(itemShulkerToStore, number = 0, containedInShulker = true)) + } + }) + } + + if (player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots) { val itemsToStore = WorldEater.collectables.filter { player.inventorySlots.countItem(it) > 0 } if (itemsToStore.isNotEmpty()) { MessageSendHelper.sendChatMessage("Compressing ${ - itemsToStore.joinToString { "${it.registryName}" } + itemsToStore.joinToString { "${it.registryName?.path}" } } to shulker boxes.") addSubActivities(itemsToStore.map { StoreItemToShulkerBox(ItemInfo(it, 0)) }) - } else if (subActivities.filterIsInstance().isEmpty()) { - stashOrders.addAll(itemsToStore.mapNotNull { itemToStore -> - WorldEater.dropOff - .filter { it.items.contains(itemToStore) } - .minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> - stash to Order(Action.PUSH, ItemInfo(itemToStore, number = 0)) - } - }) } } - if (subActivities.filterIsInstance().isNotEmpty()) return - if (BuildTools.usePickaxe) checkItem(Items.DIAMOND_PICKAXE).ifPresent { stashOrders.add(it) } if (BuildTools.useShovel) checkItem(Items.DIAMOND_SHOVEL).ifPresent { stashOrders.add(it) } if (BuildTools.useAxe) checkItem(Items.DIAMOND_AXE).ifPresent { stashOrders.add(it) } @@ -193,16 +204,28 @@ object ActivityManager : Manager, Activity() { if (stashOrders.isNotEmpty()) { addSubActivities(stashOrders.groupBy { it.first }.map { group -> + MessageSendHelper.sendChatMessage("Orders for stash at (${ + group.key.area.center.asString() + }): ${ + stashOrders.joinToString { + "${ + it.second.action.name + }:${ + it.second.itemInfo.item.registryName.toString().split(":")[1] + }" + } + }") + StashTransaction(group.value.map { it.second }, group.key) }) - MessageSendHelper.sendChatMessage("Inventory full. Storing ${ - stashOrders.joinToString(" ") { "${it.second.itemInfo.item.registryName} -> ${it.first.area.center}" } - }") } } private fun SafeClientEvent.checkItem(item: Item): Optional> { - if (player.allSlots.countItem(item) >= BuildTools.minToolAmount) return Optional.empty() + if (player.allSlots.countItem(item) + player.allSlots.sumOf { slot -> + getShulkerInventory(slot.stack)?.filter { it.item == item }?.sumOf { it.count } ?: 0 + // ToDo: Add ender chest support + } >= BuildTools.minToolAmount) return Optional.empty() val optimalStash = WorldEater.stashes .filter { it.items.contains(item) } diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 973fa84ee..68e8489f3 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -25,8 +25,9 @@ object BuildTools : Module( val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BUILDING }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") val autoPathing by setting("Auto Pathing", true, { page == Page.BUILDING }, description = "Automatically pathfind to the next block") val pathingRecomputeTimeout by setting("Pathing Recompute Timeout", 200, 0..1000, 20, { page == Page.BUILDING }, description = "Timeout for recomputing the path", unit = " ms") - val pickupMinimumItemAmount by setting("Pickup Minimum Item Amount", 32, 1..64, 1, { page == Page.BUILDING }, description = "Minimum amount of items to pick up", unit = " items") - // val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") + val collectRange by setting("Collect Range", 8, 1..50, 1, { page == Page.BUILDING }, description = "Sets the range of the pickup", unit = " blocks") + val minimumStackSize by setting("Minimum Stack Size To Collect", 32, 1..64, 1, { page == Page.BUILDING }, description = "Minimum amount of items to pick up", unit = " items") +// val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") // val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") // val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") // val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag", unit = " ticks") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index a32b763cb..16f430ca0 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -5,6 +5,7 @@ import com.lambda.client.activity.activities.storage.Area import com.lambda.client.activity.activities.storage.Stash import com.lambda.client.command.CommandManager.prefix import com.lambda.client.event.SafeClientEvent +import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.addSubActivities import com.lambda.client.module.Category import com.lambda.client.module.Module @@ -14,6 +15,7 @@ import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.runSafe import net.minecraft.init.Blocks +import net.minecraft.init.Items import net.minecraft.item.Item import net.minecraft.util.EnumFacing @@ -37,7 +39,8 @@ object WorldEater : Module( Blocks.SAND.item, Blocks.SANDSTONE.item, Blocks.RED_SANDSTONE.item, - Blocks.CLAY.item + Blocks.CLAY.item, + Items.COAL, ) val tools = setting(CollectionSetting("Tools", mutableListOf(), entryType = Item::class.java)) @@ -64,6 +67,7 @@ object WorldEater : Module( onDisable { runSafe { + ActivityManager.reset() // ToDo: Should also cancel the maintain inventory activity ownedActivity?.let { with(it) { cancel() From 0dcae9ea07b94656a5ed04c8d806c928fe5366ee Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 7 Aug 2023 15:57:19 +0200 Subject: [PATCH 101/104] Mob repelling, WorldEater HUD, qol --- .../com/lambda/client/activity/Activity.kt | 5 ++-- .../construction/core/BuildStructure.kt | 17 +++--------- .../command/commands/WorldEaterCommand.kt | 21 +++------------ .../gui/hudgui/elements/misc/WorldEaterHud.kt | 27 +++++++++++++++++++ .../manager/managers/ActivityManager.kt | 3 +++ .../client/module/modules/misc/WorldEater.kt | 20 ++++++++++++++ 6 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/WorldEaterHud.kt diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index c4ec88af0..5ab92ebe7 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -1,5 +1,6 @@ package com.lambda.client.activity +import com.lambda.client.LambdaMod import com.lambda.client.activity.activities.construction.core.BuildStructure import com.lambda.client.activity.types.AttemptActivity.Companion.checkAttempt import com.lambda.client.activity.types.BuildActivity @@ -158,7 +159,7 @@ abstract class Activity { fun SafeClientEvent.failedWith(exception: Exception) { val activity = this@Activity - MessageSendHelper.sendErrorMessage("Exception in $activityName: ${exception.message}") + LambdaMod.LOG.warn("Exception in $activityName: ${exception.message}") if (onFailure(exception)) return @@ -205,7 +206,7 @@ abstract class Activity { if (onFailure(childException)) return true if (this@Activity is ActivityManager) { - MessageSendHelper.sendErrorMessage("Traceback: ${childException.javaClass.simpleName}: ${childException.message}\n ${childActivities.joinToString(separator = "\n ") { it.toString() }}") + LambdaMod.LOG.warn("Traceback: ${childException.javaClass.simpleName}: ${childException.message}\n ${childActivities.joinToString(separator = "\n ") { it.toString() }}") return false } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 8ccfb319e..2cdca36d1 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,6 +7,7 @@ import baritone.api.pathing.goals.GoalXZ import baritone.process.BuilderProcess.GoalAdjacent import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity @@ -98,6 +99,7 @@ class BuildStructure( // no forced moving on other activities if (activity is PlaceBlock && activity.context != BuildActivity.Context.NONE) return@safeListener if (activity is BreakBlock && activity.context != BuildActivity.Context.NONE) return@safeListener + if (ActivityManager.allSubActivities.filterIsInstance().isNotEmpty()) return@safeListener if (!activity.hasNoSubActivities || activity !in subActivities) return@safeListener // pathing cool-down @@ -163,20 +165,7 @@ class BuildStructure( /* Listen for any block changes like falling sand */ safeListener { event -> - val blockPos = event.pos - - structure[blockPos]?.let { targetState -> - if (allSubActivities.any { - when (it) { - is BreakBlock -> it.blockPos == blockPos - is PlaceBlock -> it.blockPos == blockPos - else -> false - } - }) return@safeListener - -// MessageSendHelper.sendWarningMessage("Block changed at $blockPos") - createBuildActivity(blockPos, targetState) - } + handleBlockUpdate(event.pos, event.state) } safeListener { diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt index 7968579d9..350ae5c9b 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -6,6 +6,7 @@ import com.lambda.client.command.ClientCommand import com.lambda.client.command.CommandManager import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.misc.WorldEater +import com.lambda.client.module.modules.misc.WorldEater.info import com.lambda.client.util.text.MessageSendHelper import net.minecraft.item.Item @@ -156,24 +157,8 @@ object WorldEaterCommand : ClientCommand( } } - execute("General setting info") { - val string = "WorldEater settings:\n" + - "&7Pickup&r:\n" + - "${WorldEater.collectables.value.joinToString("\n") { - " &7+&r ${it.registryName.toString()}" - }}\n" + - "&7Quarries&r: ${ - if (WorldEater.quarries.value.isEmpty()) "None" - else WorldEater.quarries.value.joinToString() - }\n&7Stashes&r: ${ - if (WorldEater.stashes.value.isEmpty()) "None" - else WorldEater.stashes.value.joinToString() - }\n&7Drop-off&r: ${ - if (WorldEater.dropOff.value.isEmpty()) "None" - else WorldEater.dropOff.value.joinToString() - }" - - MessageSendHelper.sendChatMessage(string) + executeSafe("General setting info") { + MessageSendHelper.sendChatMessage(info()) } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/WorldEaterHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/WorldEaterHud.kt new file mode 100644 index 000000000..5543db972 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/misc/WorldEaterHud.kt @@ -0,0 +1,27 @@ +package com.lambda.client.gui.hudgui.elements.misc + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.construction.core.BuildStructure +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.LabelHud +import com.lambda.client.module.modules.misc.WorldEater + +internal object WorldEaterHud : LabelHud( + name = "WorldEater", + category = Category.MISC, + description = "Statistics about the world eater." +) { + override fun SafeClientEvent.updateText() { + if (WorldEater.ownedActivity == null) { + displayText.addLine("Not running", primaryColor) + return + } + + with(WorldEater) { + displayText.add("Progress", secondaryColor) + displayText.addLine("${"%.3f".format(quarries.value.sumOf { it.containedBlocks.count { pos -> world.isAirBlock(pos) } }.toFloat() / quarries.value.sumOf { it.containedBlocks.size } * 100)}%", primaryColor) + displayText.add("Layers left", secondaryColor) + displayText.addLine("${ownedActivity?.subActivities?.filterIsInstance()?.count { it.status == Activity.Status.UNINITIALIZED }}", primaryColor) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index 453b78b09..cc141caaf 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -19,6 +19,7 @@ import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.executionCountPerTick import com.lambda.client.module.modules.client.BuildTools.textScale import com.lambda.client.module.modules.client.BuildTools.tickDelay +import com.lambda.client.module.modules.combat.KillAura import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.module.modules.player.AutoEat import com.lambda.client.util.BaritoneUtils @@ -56,6 +57,8 @@ object ActivityManager : Manager, Activity() { /* life support systems */ if (AutoEat.eating) return@safeListener + if (KillAura.isActive()) return@safeListener + if (!player.onGround) return@safeListener if (BuildTools.storageManagement) maintainInventory() diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 16f430ca0..0a9a930ac 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -1,6 +1,7 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.ClearArea +import com.lambda.client.activity.activities.construction.core.BuildStructure import com.lambda.client.activity.activities.storage.Area import com.lambda.client.activity.activities.storage.Stash import com.lambda.client.command.CommandManager.prefix @@ -40,6 +41,8 @@ object WorldEater : Module( Blocks.SANDSTONE.item, Blocks.RED_SANDSTONE.item, Blocks.CLAY.item, + Blocks.IRON_ORE.item, + Blocks.GOLD_ORE.item, Items.COAL, ) @@ -93,4 +96,21 @@ object WorldEater : Module( } } } + + fun SafeClientEvent.info() = "WorldEater:\n&7Progress&r:${ + "%.3f".format(quarries.value.sumOf { it.containedBlocks.count { pos -> world.isAirBlock(pos) } }.toFloat() / quarries.value.sumOf { it.containedBlocks.size } * 100) + }% with ${ + ownedActivity?.subActivities?.filterIsInstance()?.size + } layers left.\n&7Pickup&r:${collectables.value.joinToString { + "${it.registryName?.path}" + }}\n&7Quarries&r: ${ + if (quarries.value.isEmpty()) "None" + else quarries.value.joinToString { "${quarries.indexOf(it) + 1}: $it" } + }\n&7Stashes&r: ${ + if (stashes.value.isEmpty()) "None" + else stashes.value.joinToString { "${stashes.indexOf(it) + 1}: $it" } + }\n&7Drop-off&r: ${ + if (dropOff.value.isEmpty()) "None" + else dropOff.value.joinToString { "${dropOff.indexOf(it) + 1}: $it" } + }" } \ No newline at end of file From fd33de3d45bfb3da4eaaca407bef7266d2974c6c Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 7 Aug 2023 21:47:37 +0200 Subject: [PATCH 102/104] Cleanup --- .../com/lambda/client/activity/Activity.kt | 5 +++- .../lambda/client/activity/ActivityUtils.kt | 4 ++- .../activities/construction/ClearArea.kt | 2 -- .../activities/construction/Graffiti.kt | 3 -- .../construction/core/BreakBlock.kt | 9 ++++-- .../construction/core/BuildStructure.kt | 30 +++++++++---------- .../construction/core/PlaceBlock.kt | 3 +- .../activities/interaction/AttachMap.kt | 4 --- .../interaction/crafting/CraftShulkerBox.kt | 1 - .../interaction/crafting/CraftSimpleRecipe.kt | 2 +- .../inventory/AcquireItemInActiveHand.kt | 6 ++-- .../storage/ExtractItemFromContainerStack.kt | 2 +- .../activity/activities/storage/Stash.kt | 8 +++-- .../activities/storage/StashTransaction.kt | 3 +- .../storage/StoreItemToEnderChest.kt | 3 +- .../storage/StoreItemToShulkerBox.kt | 2 -- .../activities/travel/CollectDrops.kt | 15 +++++----- .../activity/types/RenderAABBActivity.kt | 1 + 18 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index 5ab92ebe7..ddee1d1a3 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -59,7 +59,8 @@ abstract class Activity { textComponent: TextComponent, primaryColor: ColorHolder, secondaryColor: ColorHolder - ) {} + ) { + } open fun getCurrentActivity(): Activity { subActivities.firstOrNull()?.let { @@ -93,6 +94,7 @@ abstract class Activity { Status.UNINITIALIZED -> { initialize() } + Status.RUNNING -> { if (!ListenerManager.listenerMap.containsKey(this@Activity) && hasNoSubActivities @@ -313,6 +315,7 @@ abstract class Activity { is ItemBlock -> { textComponent.add(value.block.localizedName, secondaryColor) } + else -> { textComponent.add(value.toString(), secondaryColor) } diff --git a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt index 6e0bf5b49..4149bb952 100644 --- a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt @@ -27,10 +27,11 @@ fun getShulkerInventory(stack: ItemStack): NonNullList? { * The first list contains the container slots, the second list contains the player slots. */ val Container.seperatedSlots: Pair, List> - get() = when(this) { + get() = when (this) { is ContainerShulkerBox -> { getSlots(0..26) to getSlots(27..62) } + is ContainerChest -> { if (inventory.size == 62) { getSlots(0..26) to getSlots(27..62) @@ -38,6 +39,7 @@ val Container.seperatedSlots: Pair, List> getSlots(0..53) to getSlots(54..89) } } + else -> { throw ContainerTransaction.ContainerNotKnownException(this) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index 570d4e8b4..ea6c12300 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -1,6 +1,5 @@ package com.lambda.client.activity.activities.construction -import baritone.api.pathing.goals.GoalTwoBlocks import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BuildStructure @@ -8,7 +7,6 @@ import com.lambda.client.activity.activities.storage.Area import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent -import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.text.MessageSendHelper diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt index 3afdc4798..f1f716b29 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/Graffiti.kt @@ -4,14 +4,11 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.AttachItemFrame import com.lambda.client.activity.activities.interaction.AttachMap import com.lambda.client.activity.types.LoopWhileActivity -import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.misc.Graffiti -import com.lambda.client.util.math.RotationUtils.getRotationTo import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.world.getNeighbour -import com.lambda.client.util.world.isReplaceable import net.minecraft.entity.item.EntityItemFrame import net.minecraft.util.EnumFacing diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index e89e6637c..2d270c428 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -245,22 +245,26 @@ class BreakBlock( } private fun SafeClientEvent.resolveAvailability() { - when (availability) { + when (availability) { BuildActivity.Availability.VALID -> { tryBreak() } + BuildActivity.Availability.BLOCKED_BY_PLAYER, BuildActivity.Availability.NOT_IN_RANGE -> { // Wait for player move timeout = Long.MAX_VALUE // ToDo: find a better way to do this } + BuildActivity.Availability.WRONG_ITEM_SELECTED -> { // acquireOptimalTool() } + BuildActivity.Availability.NOT_EXPOSED, BuildActivity.Availability.NEEDS_LIQUID_HANDLING -> { // Wait for other tasks to finish } + else -> { // Other cases should not happen } @@ -413,6 +417,7 @@ class BreakBlock( ActivityManagerHud.totalBlocksBroken++ success() } + else -> { status = Status.UNINITIALIZED updateState() @@ -430,5 +435,5 @@ class BreakBlock( class NoExposedSideFound : Exception("No exposed side found") class BlockBreakingException : Exception("Block breaking failed") class BlockOutsideOfBoundsException(blockPos: BlockPos) : Exception("Block at (${blockPos.asString()}) is outside of world") - class NoFillerMaterialFoundException: Exception("No filler material in inventory found") + class NoFillerMaterialFoundException : Exception("No filler material in inventory found") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 2cdca36d1..38a93554e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -7,7 +7,6 @@ import baritone.api.pathing.goals.GoalXZ import baritone.process.BuilderProcess.GoalAdjacent import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.BuildActivity import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RepeatingActivity @@ -88,7 +87,9 @@ class BuildStructure( if (autoPathing && !withinRangeOfStructure() && offsetMove != BlockPos.ORIGIN) { LambdaMod.LOG.info("Structure out of range, pathing by offset") // todo: improve stop/start stutter pathing - BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(GoalXZ(player.posX.floorToInt() + (offsetMove.x * 5), player.posZ.floorToInt() + (offsetMove.z * 5))) + BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath( + GoalXZ(player.posX.floorToInt() + (offsetMove.x * 5), player.posZ.floorToInt() + (offsetMove.z * 5)) + ) return@safeListener } success() @@ -96,11 +97,8 @@ class BuildStructure( val activity = ActivityManager.getCurrentActivity() - // no forced moving on other activities - if (activity is PlaceBlock && activity.context != BuildActivity.Context.NONE) return@safeListener - if (activity is BreakBlock && activity.context != BuildActivity.Context.NONE) return@safeListener - if (ActivityManager.allSubActivities.filterIsInstance().isNotEmpty()) return@safeListener - if (!activity.hasNoSubActivities || activity !in subActivities) return@safeListener + // no forced moving on other activities than native build activity + if (activity !is BuildActivity || !activity.hasNoSubActivities) return@safeListener // pathing cool-down if (System.currentTimeMillis() - lastGoalSet < BuildTools.pathingRecomputeTimeout) { @@ -141,6 +139,7 @@ class BuildStructure( GoalAdjacent(blockPos, blockPos, true) } } + is BreakBlock -> { val blockPos = activity.blockPos @@ -183,12 +182,12 @@ class BuildStructure( // todo: capture baritone placing support blocks and update structure structure[blockPos]?.let { targetState -> if (allSubActivities.any { - when (it) { - is BreakBlock -> it.blockPos == blockPos && targetState == blockState - is PlaceBlock -> it.blockPos == blockPos && targetState == blockState - else -> false - } - }) return + when (it) { + is BreakBlock -> it.blockPos == blockPos && targetState == blockState + is PlaceBlock -> it.blockPos == blockPos && targetState == blockState + else -> false + } + }) return // MessageSendHelper.sendWarningMessage("Block changed at $blockPos") createBuildActivity(blockPos, targetState) } @@ -233,11 +232,11 @@ class BuildStructure( .sortedWith(buildComparator()) .firstOrNull()?.let { buildActivity -> (buildActivity as? Activity)?.let { - with (it) { + with(it) { return getCurrentActivity() } } - } ?: return this + } ?: return this } /** @@ -300,6 +299,7 @@ class BuildStructure( createBuildActivity(blockPos, targetState) } + is BreakBlock -> { val blockPos = childActivity.blockPos val targetState = structure[blockPos] ?: return diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 48cbd3a07..f4964811c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -189,7 +189,7 @@ class PlaceBlock( && subActivities.filterIsInstance().isEmpty() ) { (parent as? BuildStructure)?.let { - with (it) { + with(it) { addSubActivities( BreakBlock(blockPos), subscribe = true @@ -215,6 +215,7 @@ class PlaceBlock( allowedSides.remove(EnumFacing.DOWN) PlacementOffset.UPPER } + else -> { allowedSides.remove(EnumFacing.UP) PlacementOffset.LOWER diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index 608130933..d47a5f933 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -2,14 +2,11 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent -import com.lambda.client.util.items.HotbarSlot -import com.lambda.client.util.items.inventorySlots import com.lambda.client.util.math.RotationUtils.getRotationToEntity import com.lambda.client.util.math.Vec2f import com.lambda.client.util.threads.defaultScope @@ -18,7 +15,6 @@ import com.lambda.client.util.threads.safeListener import kotlinx.coroutines.launch import net.minecraft.entity.item.EntityItemFrame import net.minecraft.init.Items -import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketUseEntity import net.minecraft.network.play.server.SPacketSpawnObject import net.minecraft.util.EnumHand diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt index 791d15e90..ece95710c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt @@ -2,7 +2,6 @@ package com.lambda.client.activity.activities.interaction.crafting import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.inventory.core.InventoryTransaction import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt index b6acf9c03..8a92d0bff 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftSimpleRecipe.kt @@ -7,7 +7,7 @@ import net.minecraft.item.ItemShulkerBox class CraftSimpleRecipe(val item: Item) : Activity() { override fun SafeClientEvent.onInitialize() { - when(item) { + when (item) { is ItemShulkerBox -> { addSubActivities( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 89a37d057..2fc9bb101 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -4,9 +4,11 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.CreativeInventoryAction import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot -import com.lambda.client.activity.activities.storage.* -import com.lambda.client.activity.types.AttemptActivity +import com.lambda.client.activity.activities.storage.BreakDownEnderChests +import com.lambda.client.activity.activities.storage.ExtractItemFromContainerStack +import com.lambda.client.activity.activities.storage.ItemInfo import com.lambda.client.activity.getShulkerInventory +import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.client.BuildTools.pickBlock diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt index d9a6785c4..18573806c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt @@ -4,8 +4,8 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.PlaceContainer import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.core.PlaceContainer import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Blocks diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt index 037648d36..deaf1a6c0 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt @@ -9,7 +9,9 @@ import net.minecraft.item.Item * @param items The items that are in the stash. */ data class Stash(val area: Area, val items: List) { - override fun toString() = "Stash(${items.joinToString { - it.registryName.toString().split(":").last() - }})@(${area.center.asString()})" + override fun toString() = "Stash(${ + items.joinToString { + it.registryName.toString().split(":").last() + } + })@(${area.center.asString()})" } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt index 32d252a24..0673091e4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt @@ -4,8 +4,8 @@ import baritone.api.pathing.goals.GoalGetToBlock import baritone.api.pathing.goals.GoalNear import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.OpenContainer import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.core.OpenContainer import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.math.VectorUtils.distanceTo @@ -56,6 +56,7 @@ class StashTransaction( executeOrdersOnContainer(containerQueue.removeFirst()) } + is CloseContainer -> { if (orderQueue.isEmpty()) { success() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt index 05d613d17..ac935c739 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt @@ -6,5 +6,4 @@ import net.minecraft.item.ItemStack class StoreItemToEnderChest( containerStack: ItemStack, private val itemInfo: ItemInfo -) : Activity() { -} \ No newline at end of file +) : Activity() \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt index 054a10ba6..0d1604f3e 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt @@ -9,9 +9,7 @@ import com.lambda.client.activity.getShulkerInventory import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots import com.lambda.client.util.items.countItem -import net.minecraft.inventory.Slot import net.minecraft.item.Item -import net.minecraft.item.ItemStack class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes private val itemInfo: ItemInfo diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt index 3b41ad2e5..202c9d446 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CollectDrops.kt @@ -16,13 +16,14 @@ class CollectDrops( private val minAmount: Int = 1, override var currentLoops: Int = 0, ) : LoopWhileActivity, Activity() { - private val SafeClientEvent.drops get() = - world.loadedEntityList.filterIsInstance().filter { - player.distanceTo(it.positionVector) < maxRange - && it.item.item == item - && predicate(it.item) - && if (itemStack != ItemStack.EMPTY) ItemStack.areItemStacksEqual(it.item, itemStack) else true - } + private val SafeClientEvent.drops + get() = + world.loadedEntityList.filterIsInstance().filter { + player.distanceTo(it.positionVector) < maxRange + && it.item.item == item + && predicate(it.item) + && if (itemStack != ItemStack.EMPTY) ItemStack.areItemStacksEqual(it.item, itemStack) else true + } override val loopWhile: SafeClientEvent.() -> Boolean = { drops.isNotEmpty() diff --git a/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt index 77d67ee1e..341ddc13e 100644 --- a/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt +++ b/src/main/kotlin/com/lambda/client/activity/types/RenderAABBActivity.kt @@ -30,6 +30,7 @@ interface RenderAABBActivity { normalizedRender.add(toRenderAABB()) } } + is RenderEntity -> { with(compound) { normalizedRender.add(toRenderAABB()) From 856f5f44214e345857e8a4fd470d24945311a4dd Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 9 Aug 2023 04:17:05 +0200 Subject: [PATCH 103/104] First minimum viable product of WorldEater --- .../com/lambda/client/activity/Activity.kt | 64 ++++++------- .../lambda/client/activity/ActivityUtils.kt | 4 +- .../activities/construction/ClearArea.kt | 19 ++-- .../construction/core/BreakBlock.kt | 2 +- .../construction/core/BuildStructure.kt | 16 +++- .../construction/core/PlaceBlock.kt | 2 +- .../activities/interaction/AttachItemFrame.kt | 2 +- .../activities/interaction/AttachMap.kt | 2 +- .../interaction/crafting/CraftShulkerBox.kt | 2 +- .../interaction/crafting/ReachXPLevel.kt | 2 +- .../inventory/AcquireItemInActiveHand.kt | 12 +-- .../activity/activities/storage/Action.kt | 5 - .../storage/BreakDownEnderChests.kt | 6 +- .../storage/ExtractItemFromContainerStack.kt | 41 -------- .../activity/activities/storage/Order.kt | 3 - .../activities/storage/ShulkerTransaction.kt | 55 +++++++++++ .../activities/storage/StashTransaction.kt | 94 +++++++++---------- .../storage/StoreItemToEnderChest.kt | 1 + .../storage/StoreItemToShulkerBox.kt | 56 ----------- ...ction.kt => ContainerWindowTransaction.kt} | 24 +++-- .../activities/storage/core/PlaceContainer.kt | 8 +- .../activities/storage/types/Action.kt | 74 +++++++++++++++ .../activities/storage/{ => types}/Area.kt | 16 +++- .../storage/{ => types}/ItemInfo.kt | 9 +- .../activities/storage/{ => types}/Stash.kt | 7 +- .../activity/activities/travel/CustomGoal.kt | 6 +- .../command/commands/WorldEaterCommand.kt | 5 +- .../elements/client/ActivityManagerHud.kt | 5 +- .../manager/managers/ActivityManager.kt | 94 ++++++++----------- .../module/modules/client/BuildTools.kt | 4 +- .../modules/misc/TestActivityManager.kt | 39 +++++++- .../client/module/modules/misc/WorldEater.kt | 4 +- 32 files changed, 379 insertions(+), 304 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/core/{ContainerTransaction.kt => ContainerWindowTransaction.kt} (81%) create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ => types}/Area.kt (66%) rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ => types}/ItemInfo.kt (74%) rename src/main/kotlin/com/lambda/client/activity/activities/storage/{ => types}/Stash.kt (70%) diff --git a/src/main/kotlin/com/lambda/client/activity/Activity.kt b/src/main/kotlin/com/lambda/client/activity/Activity.kt index ddee1d1a3..9f6de57d2 100644 --- a/src/main/kotlin/com/lambda/client/activity/Activity.kt +++ b/src/main/kotlin/com/lambda/client/activity/Activity.kt @@ -17,6 +17,7 @@ import com.lambda.client.event.LambdaEventBus import com.lambda.client.event.ListenerManager import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud +import com.lambda.client.gui.hudgui.elements.client.ActivityManagerHud.maxEntries import com.lambda.client.manager.managers.ActivityManager import com.lambda.client.manager.managers.ActivityManager.MAX_DEPTH import com.lambda.client.module.AbstractModule @@ -152,7 +153,7 @@ abstract class Activity { checkRepeat(activity) checkLoopingUntil(activity) -// BaritoneUtils.primary?.pathingBehavior?.cancelEverything() + if (this@Activity !is BuildActivity) BaritoneUtils.primary?.pathingBehavior?.cancelEverything() // LambdaMod.LOG.info("${System.currentTimeMillis()} Finalized $name after ${System.currentTimeMillis() - creationTime}ms") // MessageSendHelper.sendRawChatMessage("$name took ${age}ms") @@ -294,32 +295,22 @@ abstract class Activity { textComponent.add(hashCode().toString(), primaryColor) if (details) { - this::class.java.declaredFields.forEachIndexed { index, field -> + this::class.java.declaredFields.forEach { field -> field.isAccessible = true val name = field.name - val value = field.get(this) - -// if (index.mod(6) == 0) { -// textComponent.addLine("", primaryColor) -// repeat(depth) { -// textComponent.add(" ") -// } -// } - - value?.let { - if (!ActivityManagerHud.anonymize - || !(value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB) - ) { - textComponent.add(name.capitalize(), primaryColor) - when (value) { - is ItemBlock -> { - textComponent.add(value.block.localizedName, secondaryColor) - } - - else -> { - textComponent.add(value.toString(), secondaryColor) - } - } + val value = field.get(this) ?: return@forEach + + if (ActivityManagerHud.anonymize && (value is BlockPos || value is Vec3d || value is Entity || value is AxisAlignedBB)) return@forEach + + textComponent.add(name.capitalize(), primaryColor) + + when (value) { + is ItemBlock -> { + textComponent.add(value.block.localizedName, secondaryColor) + } + + else -> { + textComponent.add(value.toString(), secondaryColor) } } } @@ -329,7 +320,7 @@ abstract class Activity { addExtraInfo(textComponent, primaryColor, secondaryColor) textComponent.addLine("") - val acti = if (this is BuildStructure) { + val activities = if (this is BuildStructure) { subActivities .filterIsInstance() .sortedWith(buildComparator()) @@ -338,24 +329,27 @@ abstract class Activity { subActivities } - acti.take(25).forEach { + activities.take(maxEntries).forEach { repeat(depth) { textComponent.add(" ") } it.appendInfo(textComponent, primaryColor, secondaryColor, details) } - if (acti.size > 25) { - textComponent.addLine("And ${acti.size - 25} more...", primaryColor) + if (activities.size > maxEntries) { + repeat(depth) { + textComponent.add(" ") + } + textComponent.addLine("And ${activities.size - maxEntries} more...", primaryColor) } } override fun toString(): String { - val properties = this::class.java.declaredFields.joinToString(separator = ", ", prefix = ", ") { - it.isAccessible = true - val name = it.name - val value = it.get(this) - "$name=$value" - } +// val properties = this::class.java.declaredFields.joinToString(separator = ", ", prefix = ", ") { +// it.isAccessible = true +// val name = it.name +// val value = it.get(this) +// "$name=$value" +// } // return "$activityName: [State=$activityStatus, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}$properties]" return "$activityName: [State=$status, Runtime=${DurationFormatUtils.formatDuration(age, "HH:mm:ss,SSS")}, SubActivities=${subActivities.size}]" diff --git a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt index 4149bb952..c3fa5e638 100644 --- a/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt +++ b/src/main/kotlin/com/lambda/client/activity/ActivityUtils.kt @@ -1,6 +1,6 @@ package com.lambda.client.activity -import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.core.ContainerWindowTransaction import com.lambda.client.util.items.getSlots import net.minecraft.inventory.* import net.minecraft.item.ItemShulkerBox @@ -41,6 +41,6 @@ val Container.seperatedSlots: Pair, List> } else -> { - throw ContainerTransaction.ContainerNotKnownException(this) + throw ContainerWindowTransaction.ContainerNotKnownException(this) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt index ea6c12300..ca4afa9ad 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/ClearArea.kt @@ -1,14 +1,16 @@ package com.lambda.client.activity.activities.construction +import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BuildStructure -import com.lambda.client.activity.activities.storage.Area +import com.lambda.client.activity.activities.storage.types.Area import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.text.MessageSendHelper import net.minecraft.block.state.IBlockState import net.minecraft.init.Blocks @@ -36,13 +38,14 @@ class ClearArea( } override fun SafeClientEvent.onInitialize() { - with(area) { - if (player.flooredPosition !in area.containedBlocks) { - MessageSendHelper.sendWarningMessage("Player is not in the area $area! Moving now...") - addSubActivities(CustomGoal(GoalXZ(center.x, center.z))) - status = Status.UNINITIALIZED - return@onInitialize - } + if (player.flooredPosition !in area.containedBlocks) { + val highestNonAirBlock = world.getTopSolidOrLiquidBlock(area.center) + + MessageSendHelper.sendWarningMessage("Player is not in the area $area! Moving to closest position (${highestNonAirBlock.asString()})...") + addSubActivities(CustomGoal(GoalBlock(highestNonAirBlock), + inGoal = { blockPos -> area.containedBlocks.contains(blockPos) }, timeout = 999999L)) + status = Status.UNINITIALIZED + return } val layers = (area.minY..area.maxY).reversed() diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index 2d270c428..d83e8eb24 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -4,7 +4,7 @@ import baritone.api.BaritoneAPI import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt index 38a93554e..50272b728 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BuildStructure.kt @@ -31,6 +31,7 @@ import net.minecraft.block.BlockBush import net.minecraft.block.state.IBlockState import net.minecraft.entity.item.EntityItem import net.minecraft.init.Blocks +import net.minecraft.item.ItemShulkerBox import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.network.play.server.SPacketMultiBlockChange import net.minecraft.util.math.AxisAlignedBB @@ -67,6 +68,8 @@ class BuildStructure( } currentOffset = currentOffset.add(offsetMove) + + if (subActivities.isEmpty()) success() } private fun SafeClientEvent.withinRangeOfStructure(): Boolean { @@ -98,7 +101,7 @@ class BuildStructure( val activity = ActivityManager.getCurrentActivity() // no forced moving on other activities than native build activity - if (activity !is BuildActivity || !activity.hasNoSubActivities) return@safeListener + if (activity !is BuildActivity || !activity.hasNoSubActivities || activity.context != BuildActivity.Context.NONE) return@safeListener // pathing cool-down if (System.currentTimeMillis() - lastGoalSet < BuildTools.pathingRecomputeTimeout) { @@ -106,6 +109,14 @@ class BuildStructure( return@safeListener } + // collect all shulker boxes just to be sure + world.loadedEntityList.filterIsInstance().firstOrNull { + it.item.item is ItemShulkerBox + }?.let { + currentGoal = GoalBlock(it.position) + return@safeListener + } + val itemsInRange = world.loadedEntityList .filterIsInstance() .filter { @@ -114,8 +125,7 @@ class BuildStructure( } // collect drops - if (collectAll - && autoPathing + if (collectAll && autoPathing && (itemsInRange.maxOfOrNull { it.item.count } ?: 0) > BuildTools.minimumStackSize ) { itemsInRange.maxByOrNull { it.item.count / player.distanceTo(it.position) }?.let { largestStack -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index f4964811c..23a33c6fa 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt index 00969fc56..6845caa12 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index d47a5f933..a955054bf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt index ece95710c..69dfa2584 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.interaction.crafting import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.item import net.minecraft.init.Blocks diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt index 052c42280..5d7edc037 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 2fc9bb101..657c537c5 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -5,8 +5,10 @@ import com.lambda.client.activity.activities.inventory.core.CreativeInventoryAct import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot import com.lambda.client.activity.activities.storage.BreakDownEnderChests -import com.lambda.client.activity.activities.storage.ExtractItemFromContainerStack -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.ShulkerTransaction +import com.lambda.client.activity.activities.storage.types.ContainerAction +import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.ShulkerOrder import com.lambda.client.activity.getShulkerInventory import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent @@ -61,10 +63,8 @@ class AcquireItemInActiveHand( // If the item is in a shulker box, extract it if (searchShulkerBoxes && itemInfo.item !is ItemShulkerBox) { - selectOptimalShulker()?.let { slot -> - addSubActivities(ExtractItemFromContainerStack(slot.stack, itemInfo)) - return - } + addSubActivities(ShulkerTransaction(ShulkerOrder(ContainerAction.PULL, itemInfo.item, itemInfo.number))) + return } // If the item is obsidian, break down ender chests diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt deleted file mode 100644 index fccbe4d09..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/Action.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.lambda.client.activity.activities.storage - -enum class Action { - PULL, PUSH -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt index 87142b228..63a1d72d9 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt @@ -4,6 +4,10 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.activities.storage.types.ContainerAction +import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemOrder +import com.lambda.client.activity.activities.storage.types.ShulkerOrder import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools @@ -29,7 +33,7 @@ class BreakDownEnderChests( if (freeSlots.isEmpty()) { if (player.inventorySlots.countItem(Blocks.OBSIDIAN.item) > 0) { addSubActivities( - StoreItemToShulkerBox(ItemInfo(Blocks.OBSIDIAN.item, 0)) + ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, Blocks.OBSIDIAN.item, 0)) ) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt deleted file mode 100644 index 18573806c..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ExtractItemFromContainerStack.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.construction.core.BreakBlock -import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.ContainerTransaction -import com.lambda.client.activity.activities.storage.core.PlaceContainer -import com.lambda.client.activity.activities.travel.CollectDrops -import com.lambda.client.event.SafeClientEvent -import net.minecraft.init.Blocks -import net.minecraft.item.ItemStack - -class ExtractItemFromContainerStack( - containerStack: ItemStack, - private val itemInfo: ItemInfo -) : Activity() { - private val containerStack = containerStack.copy() - - override fun SafeClientEvent.onInitialize() { - addSubActivities( - PlaceContainer(containerStack, open = true) - ) - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is PlaceContainer) return - - addSubActivities( - ContainerTransaction(Order(Action.PULL, itemInfo)), - CloseContainer(), - BreakBlock( - childActivity.containerPos, - forceSilk = containerStack.item == Blocks.ENDER_CHEST, - ignoreIgnored = true - ), - CollectDrops(containerStack.item), - AcquireItemInActiveHand(itemInfo) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt deleted file mode 100644 index 673db3020..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/Order.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.lambda.client.activity.activities.storage - -data class Order(val action: Action, val itemInfo: ItemInfo) \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt new file mode 100644 index 000000000..e25ebaf32 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt @@ -0,0 +1,55 @@ +package com.lambda.client.activity.activities.storage + +import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.construction.core.BreakBlock +import com.lambda.client.activity.activities.storage.core.CloseContainer +import com.lambda.client.activity.activities.storage.core.ContainerWindowTransaction +import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.activities.storage.types.ContainerAction +import com.lambda.client.activity.activities.storage.types.ItemOrder +import com.lambda.client.activity.activities.storage.types.ShulkerOrder +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.items.allSlots + +/** + * Push or pull item from a fitting shulker from inventory + */ +class ShulkerTransaction( + val order: ShulkerOrder +) : Activity() { + override fun SafeClientEvent.onInitialize() { + if (order.action == ContainerAction.PULL) { + player.allSlots.mapNotNull { + order.findShulkerToPull(it) + }.minByOrNull { it.second }?.first?.let { slot -> + addSubActivities( + PlaceContainer(slot.stack.copy(), open = true) + ) + return + } + } else { + player.allSlots.mapNotNull { + order.findShulkerToPush(it) + }.minByOrNull { it.second }?.first?.let { slot -> + addSubActivities( + PlaceContainer(slot.stack.copy(), open = true) + ) + return + } + } + } + + override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { + if (childActivity !is PlaceContainer) return + + addSubActivities( + ContainerWindowTransaction(ItemOrder(order.action, order.item, order.amount)), + CloseContainer(), + BreakBlock( + childActivity.containerPos, + collectDrops = true, + ignoreIgnored = true + ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt index 0673091e4..040544739 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt @@ -1,26 +1,34 @@ package com.lambda.client.activity.activities.storage +import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalGetToBlock -import baritone.api.pathing.goals.GoalNear +import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.ContainerTransaction +import com.lambda.client.activity.activities.storage.core.ContainerWindowTransaction import com.lambda.client.activity.activities.storage.core.OpenContainer +import com.lambda.client.activity.activities.storage.types.Stash +import com.lambda.client.activity.activities.storage.types.ContainerOrder import com.lambda.client.activity.activities.travel.CustomGoal +import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent +import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.VectorUtils.distanceTo +import com.lambda.client.util.text.MessageSendHelper import net.minecraft.tileentity.TileEntity /** * [StashTransaction] is an [Activity] that allows you to pull or push items from a [Stash]. - * @param stash The [Stash] to pull or push items from. * @param orders The orders to pull or push items. */ class StashTransaction( - private val orders: List, - private val stash: Stash -) : Activity() { - private val orderQueue = ArrayDeque(orders) + private val orders: Set> +) : LoopWhileActivity, Activity() { + override val loopWhile: SafeClientEvent.() -> Boolean = { orderQueue.isNotEmpty() } + override var currentLoops = 0 + + private val orderQueue = ArrayDeque(orders.sortedBy { it.second.action }) + // try different containers in case one is not matching the search private val containerQueue = ArrayDeque() override fun SafeClientEvent.onInitialize() { @@ -29,59 +37,45 @@ class StashTransaction( return } - //TODO: Use cached chests to instantly find the closest needed container (maybe even shared cache?) + // TODO: Use cached chests to instantly find the closest needed container (maybe even shared cache?) + + orderQueue.firstOrNull()?.first?.let { + val highestNonAirBlock = world.getTopSolidOrLiquidBlock(it.area.center) - addSubActivities( - CustomGoal(GoalNear(stash.area.center, stash.area.maxWidth), timeout = 999999L) - ) + MessageSendHelper.sendWarningMessage("Player is not in the area ${it.area}! Moving to closest position (${highestNonAirBlock.asString()})...") + addSubActivities(CustomGoal(GoalBlock(highestNonAirBlock), + inGoal = { blockPos -> it.area.containedBlocks.contains(blockPos) }, timeout = 999999L) + ) + } } override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { when (childActivity) { is CustomGoal -> { - if (childActivity.goal !is GoalNear) return - - val stashContainer = world.loadedTileEntityList.filter { - stash.area.containedBlocks.contains(it.pos) + if (childActivity.goal !is GoalBlock) return + + orderQueue.removeFirstOrNull()?.let { order -> + val stashContainer = world.loadedTileEntityList.filter { + order.first.area.containedBlocks.contains(it.pos) + } + + if (stashContainer.isEmpty()) { + failedWith(NoContainerFoundInStashException()) + return + } + + stashContainer.minByOrNull { player.distanceTo(it.pos) }?.let { container -> + addSubActivities( + CustomGoal(GoalGetToBlock(container.pos)), + OpenContainer(container.pos), + ContainerWindowTransaction(order.second), + CloseContainer() + ) + } } - - if (stashContainer.isEmpty()) { - failedWith(NoContainerFoundInStashException()) - return - } - - containerQueue.addAll( - stashContainer.sortedBy { player.distanceTo(it.pos) } - ) - - executeOrdersOnContainer(containerQueue.removeFirst()) - } - - is CloseContainer -> { - if (orderQueue.isEmpty()) { - success() - return - } - - executeOrdersOnContainer(containerQueue.removeFirst()) } } } - private fun executeOrdersOnContainer(container: TileEntity) { - addSubActivities( - CustomGoal(GoalGetToBlock(container.pos)), - OpenContainer(container.pos) - ) - - addSubActivities(orders.sortedBy { it.action }.map { - ContainerTransaction(it) - }) - - orderQueue.clear() // TODO: Remove this when order feedback is implemented - - addSubActivities(CloseContainer()) - } - class NoContainerFoundInStashException : Exception("No chest found in area!") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt index ac935c739..f00b1d27c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToEnderChest.kt @@ -1,6 +1,7 @@ package com.lambda.client.activity.activities.storage import com.lambda.client.activity.Activity +import com.lambda.client.activity.activities.storage.types.ItemInfo import net.minecraft.item.ItemStack class StoreItemToEnderChest( diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt deleted file mode 100644 index 0d1604f3e..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StoreItemToShulkerBox.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.lambda.client.activity.activities.storage - -import com.lambda.client.activity.Activity -import com.lambda.client.activity.activities.construction.core.BreakBlock -import com.lambda.client.activity.activities.storage.core.CloseContainer -import com.lambda.client.activity.activities.storage.core.ContainerTransaction -import com.lambda.client.activity.activities.storage.core.PlaceContainer -import com.lambda.client.activity.getShulkerInventory -import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.countItem -import net.minecraft.item.Item - -class StoreItemToShulkerBox( // TODO: Add support for multiple shulker boxes - private val itemInfo: ItemInfo -) : Activity() { - override fun SafeClientEvent.onInitialize() { - if (player.allSlots.countItem(itemInfo.item) == 0) { - success() - return - } - - player.allSlots.mapNotNull { slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - if (inventory.all { itemInfo.stackFilter(it) || it.isEmpty }) { - val count = inventory.count { itemInfo.stackFilter(it) } - - if (count < 27) slot to count else null - } else null - } - }.maxByOrNull { it.second }?.first?.let { slot -> - addSubActivities( - PlaceContainer(slot.stack.copy(), open = true) - ) - return - } - - failedWith(NoShulkerBoxFoundStoreException(itemInfo.item)) - } - - override fun SafeClientEvent.onChildSuccess(childActivity: Activity) { - if (childActivity !is PlaceContainer) return - - addSubActivities( - ContainerTransaction(Order(Action.PUSH, itemInfo)), - CloseContainer(), - BreakBlock( - childActivity.containerPos, - collectDrops = true, - ignoreIgnored = true - ) - ) - } - - class NoShulkerBoxFoundStoreException(item: Item) : Exception("No shulker box was found with space to store ${item.registryName}") -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt similarity index 81% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt index 1be15c499..ef94b7031 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt @@ -3,8 +3,7 @@ package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.core.QuickMoveSlot import com.lambda.client.activity.activities.inventory.core.SwapWithSlot -import com.lambda.client.activity.activities.storage.Action -import com.lambda.client.activity.activities.storage.Order +import com.lambda.client.activity.activities.storage.types.* import com.lambda.client.activity.seperatedSlots import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools @@ -13,31 +12,40 @@ import com.lambda.client.util.items.hotbarSlots import com.lambda.client.util.text.MessageSendHelper import net.minecraft.inventory.Container -class ContainerTransaction( - private val order: Order +class ContainerWindowTransaction( + private val order: ContainerOrder ) : Activity() { override fun SafeClientEvent.onInitialize() { val seperatedSlots = player.openContainer.seperatedSlots - val (fromSlots, toSlots) = if (order.action == Action.PULL) { + val (fromSlots, toSlots) = if (order.action == ContainerAction.PULL) { seperatedSlots.let { (first, second) -> Pair(first, second) } } else { seperatedSlots.let { (first, second) -> Pair(second, first) } } - val toMoveSlots = fromSlots.filter(order.itemInfo.slotFilter) + val toMoveSlots = fromSlots.filter(order.filter) if (toMoveSlots.isEmpty()) { + if (order is GeneralOrder && order.amount == 0) { + success() + return + } + failedWith(NoItemFoundException()) return } - if (toMoveSlots.size < order.itemInfo.number) { + if (toMoveSlots.size < order.amount) { failedWith(NotEnoughSlotsException()) return } - val remainingSlots = if (order.itemInfo.number == 0) toMoveSlots else toMoveSlots.take(order.itemInfo.number) + val remainingSlots = if (order.amount == 0) { + toMoveSlots + } else { + toMoveSlots.take(order.amount) + } remainingSlots.forEach { fromSlot -> if (toSlots.countEmpty() > 0) { diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt index 72c7923b4..1210a41f3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.storage.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.ItemInfo +import com.lambda.client.activity.activities.storage.types.ItemInfo import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition @@ -19,7 +19,7 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class PlaceContainer( - private val targetStack: ItemStack, + private val useStack: ItemStack, private val onlyItem: Boolean = false, private val open: Boolean = false, override val maxAttempts: Int = 5, @@ -35,9 +35,9 @@ class PlaceContainer( addSubActivities( AcquireItemInActiveHand(ItemInfo( - targetStack.item, predicate = { onlyItem || ItemStack.areItemStacksEqual(it, targetStack) } + useStack.item, predicate = { onlyItem || ItemStack.areItemStacksEqual(it, useStack) } )), - PlaceBlock(containerPos, targetStack.item.block.defaultState, ignoreProperties = true) + PlaceBlock(containerPos, useStack.item.block.defaultState, ignoreProperties = true) ) if (open) addSubActivities(OpenContainer(containerPos)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt new file mode 100644 index 000000000..08184bca0 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt @@ -0,0 +1,74 @@ +package com.lambda.client.activity.activities.storage.types + +import com.lambda.client.activity.getShulkerInventory +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +class ItemOrder(override val action: ContainerAction, val item: Item, override val amount: Int) : ContainerOrder { + override val filter = { slot: Slot -> + slot.stack.item == item + } +} + +class ShulkerOrder(override val action: ContainerAction, val item: Item, override val amount: Int) : ContainerOrder { + override val filter = { slot: Slot -> + getShulkerInventory(slot.stack)?.any { it.item == item } == true + } + val findShulkerToPush = { slot: Slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + if (inventory.all { it.item == item || it.isEmpty }) { + val storableItems = inventory.sumOf { +// if (it.isEmpty) item.itemStackLimit else it.maxStackSize - it.count + if (it.isEmpty) item.itemStackLimit else 0 + } + + if (storableItems > 0) slot to storableItems else null + } else null + } + } + val findShulkerToPull = { slot: Slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val usableItems = inventory.sumOf { if (it.item == item) it.count else 0 } + + if (usableItems > 0) slot to usableItems else null + } + } +} + +class SelectionOrder(override val action: ContainerAction, selection: (Slot) -> Boolean, override val amount: Int) : ContainerOrder { + override val filter = selection +} + +class StackOrder(override val action: ContainerAction, val itemStack: ItemStack, override val amount: Int) : ContainerOrder { + override val filter = { slot: Slot -> + ItemStack.areItemStacksEqual(itemStack, slot.stack) + } +} + +class GeneralOrder(override val action: ContainerAction, selection: Selection, override val amount: Int) : ContainerOrder { + override val filter = selection.slotFilter + + enum class Selection(val slotFilter: (Slot) -> Boolean) { + FULL_SHULKERS({ slot -> + getShulkerInventory(slot.stack)?.none { it.isEmpty } == true + }), + EMPTY_SHULKERS({ slot -> + getShulkerInventory(slot.stack)?.all { it.isEmpty } == true + }), + EVERYTHING({ true }) + } +} + +enum class ContainerAction { + PUSH, PULL +} + +/** + * Implemented by [ItemOrder], [ShulkerOrder], [SelectionOrder], [StackOrder], [GeneralOrder] + */ +interface ContainerOrder { + val action: ContainerAction + val amount: Int + val filter: (Slot) -> Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Area.kt similarity index 66% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/types/Area.kt index 4f2e9f472..e38430b92 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/Area.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Area.kt @@ -1,6 +1,7 @@ -package com.lambda.client.activity.activities.storage +package com.lambda.client.activity.activities.storage.types import com.lambda.client.util.math.CoordinateConverter.asString +import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.util.math.BlockPos /** @@ -19,8 +20,17 @@ data class Area(val pos1: BlockPos, val pos2: BlockPos) { val containedBlocks: Set get() = BlockPos.getAllInBox(pos1, pos2).toSet() - val maxWidth: Int - get() = maxOf(maxX - minX + 1, maxZ - minZ + 1) + val minWidth: Int + get() = minOf(maxX - minX + 1, maxZ - minZ + 1) + + fun closestBlockPos(player: EntityPlayerSP) = containedBlocks.minBy { + it.distanceSq(player.posX, player.posY, player.posZ) + } + + fun grow(amount: Int) = Area( + BlockPos(pos1.x - amount, pos1.y - amount, pos1.z - amount), + BlockPos(pos2.x + amount, pos2.y + amount, pos2.z + amount) + ) val minX: Int get() = minOf(pos1.x, pos2.x) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/ItemInfo.kt similarity index 74% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/types/ItemInfo.kt index 9f72a89a5..21b7b57d3 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ItemInfo.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/ItemInfo.kt @@ -1,4 +1,4 @@ -package com.lambda.client.activity.activities.storage +package com.lambda.client.activity.activities.storage.types import com.lambda.client.activity.getShulkerInventory import net.minecraft.inventory.Slot @@ -9,6 +9,7 @@ import net.minecraft.item.ItemStack data class ItemInfo( val item: Item, val number: Int = 1, // 0 = all + val itemStack: ItemStack? = null, val predicate: (ItemStack) -> Boolean = { true }, val metadata: Int? = null, var containedInShulker: Boolean = false @@ -25,10 +26,12 @@ data class ItemInfo( } val stackFilter = { stack: ItemStack -> - item == stack.item + itemStack == null + && item == stack.item && predicate(stack) && (metadata == null || metadata == stack.metadata) + || (itemStack != null && ItemStack.areItemStacksEqual(itemStack, stack)) } - override fun toString() = "ItemInfo(item=$item, number=$number, metadata=$metadata, containedInShulker=$containedInShulker)" + override fun toString() = "ItemInfo(item=$item, number=$number, itemStack=$itemStack, metadata=$metadata, containedInShulker=$containedInShulker)" } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Stash.kt similarity index 70% rename from src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt rename to src/main/kotlin/com/lambda/client/activity/activities/storage/types/Stash.kt index deaf1a6c0..3fb48f89c 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/Stash.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Stash.kt @@ -1,7 +1,8 @@ -package com.lambda.client.activity.activities.storage +package com.lambda.client.activity.activities.storage.types import com.lambda.client.util.math.CoordinateConverter.asString import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos /** * [Stash] is a data class that represents a stash of [Item]s. @@ -14,4 +15,8 @@ data class Stash(val area: Area, val items: List) { it.registryName.toString().split(":").last() } })@(${area.center.asString()})" + + companion object { + val EMPTY = Stash(Area(BlockPos.ORIGIN, BlockPos.ORIGIN), emptyList()) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt index 766f7808b..223a78a5d 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/travel/CustomGoal.kt @@ -7,14 +7,16 @@ import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.BaritoneUtils import com.lambda.client.util.EntityUtils.flooredPosition import com.lambda.client.util.threads.safeListener +import net.minecraft.util.math.BlockPos import net.minecraftforge.fml.common.gameevent.TickEvent class CustomGoal( val goal: Goal, + val inGoal: (BlockPos) -> Boolean = { goal.isInGoal(it) }, override val timeout: Long = 100000L ) : TimeoutActivity, Activity() { override fun SafeClientEvent.onInitialize() { - if (!goal.isInGoal(player.flooredPosition)) return + if (!inGoal(player.flooredPosition)) return success() } @@ -25,7 +27,7 @@ class CustomGoal( BaritoneUtils.primary?.customGoalProcess?.setGoalAndPath(goal) - if (goal.isInGoal(player.flooredPosition)) success() + if (inGoal(player.flooredPosition)) success() } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt index 350ae5c9b..a2e2a1722 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/WorldEaterCommand.kt @@ -1,10 +1,9 @@ package com.lambda.client.command.commands -import com.lambda.client.activity.activities.storage.Area -import com.lambda.client.activity.activities.storage.Stash +import com.lambda.client.activity.activities.storage.types.Area +import com.lambda.client.activity.activities.storage.types.Stash import com.lambda.client.command.ClientCommand import com.lambda.client.command.CommandManager -import com.lambda.client.module.modules.client.BuildTools import com.lambda.client.module.modules.misc.WorldEater import com.lambda.client.module.modules.misc.WorldEater.info import com.lambda.client.util.text.MessageSendHelper diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt index 457029816..e792026c9 100644 --- a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/ActivityManagerHud.kt @@ -12,6 +12,7 @@ internal object ActivityManagerHud: LabelHud( category = Category.MISC, description = "Display current activities." ) { + val maxEntries by setting("Max Entries", 15, 1..100, 1) val anonymize by setting("Anonymize", false) private val details by setting("Details", false) private var startTime = 0L @@ -52,8 +53,8 @@ internal object ActivityManagerHud: LabelHud( if (sync.isNotEmpty() || async.isNotEmpty()) { displayText.addLine("") displayText.addLine("Subscribers:") - if (sync.isNotEmpty()) displayText.addLine("SYNC ${sync.take(100).map { it::class.simpleName }}${if (sync.size > 100) "..." else ""}") - if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.take(100).map { it::class.simpleName }}${if (async.size > 100) "..." else ""}") + if (sync.isNotEmpty()) displayText.addLine("SYNC ${sync.take(maxEntries).map { it::class.simpleName }}${if (sync.size > maxEntries) "..." else ""}") + if (async.isNotEmpty()) displayText.addLine("ASYNC ${async.take(maxEntries).map { it::class.simpleName }}${if (async.size > maxEntries) "..." else ""}") } } diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index cc141caaf..d0e2fc6e8 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -2,6 +2,7 @@ package com.lambda.client.manager.managers import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.storage.* +import com.lambda.client.activity.activities.storage.types.* import com.lambda.client.activity.getShulkerInventory import com.lambda.client.activity.types.RenderAABBActivity import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender @@ -29,19 +30,17 @@ import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.graphics.GlStateUtils import com.lambda.client.util.graphics.ProjectionUtils import com.lambda.client.util.graphics.font.FontRenderAdapter -import com.lambda.client.util.items.allSlots -import com.lambda.client.util.items.countEmpty -import com.lambda.client.util.items.countItem -import com.lambda.client.util.items.inventorySlots +import com.lambda.client.util.items.* import com.lambda.client.util.math.CoordinateConverter.asString import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper import com.lambda.client.util.threads.safeListener +import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.Item -import net.minecraft.item.ItemShulkerBox import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.opengl.GL11 +import scala.tools.nsc.backend.icode.analysis.TypeFlowAnalysis.MethodTFA.Gen import java.util.* object ActivityManager : Manager, Activity() { @@ -158,27 +157,33 @@ object ActivityManager : Manager, Activity() { } private fun SafeClientEvent.maintainInventory() { - if (subActivities.filterIsInstance().isNotEmpty() - || allSubActivities.filterIsInstance().isNotEmpty() - || subActivities.filterIsInstance().isNotEmpty() + if (allSubActivities.filterIsInstance().isNotEmpty() + || allSubActivities.filterIsInstance().isNotEmpty() ) return - val stashOrders = mutableListOf>() + val stashOrders = mutableSetOf>() if (player.allSlots.none { slot -> getShulkerInventory(slot.stack)?.all { it.isEmpty } == true }) { - MessageSendHelper.sendChatMessage("No empty shulker boxes found, requesting new ones.") + // ToDo: Request correct amount of shulkers + WorldEater.stashes.minByOrNull { + player.distanceTo(it.area.center) + }?.let { stash -> + stashOrders.add(stash to GeneralOrder(ContainerAction.PULL, GeneralOrder.Selection.EMPTY_SHULKERS, 5)) + } - val fullShulkerItem = player.allSlots - .filter { slot -> getShulkerInventory(slot.stack)?.none { it.isEmpty } == true } - .mapNotNull { slot -> getShulkerInventory(slot.stack)?.firstOrNull()?.item } + if (player.allSlots.any(GeneralOrder.Selection.FULL_SHULKERS.slotFilter)) { + WorldEater.dropOff.minByOrNull { + player.distanceTo(it.area.center) + }?.let { stash -> + stashOrders.add(stash to GeneralOrder(ContainerAction.PUSH, GeneralOrder.Selection.FULL_SHULKERS, 0)) + } + } - stashOrders.addAll(fullShulkerItem.mapNotNull { itemShulkerToStore -> - WorldEater.dropOff - .filter { it.items.contains(itemShulkerToStore) } - .minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> - stash to Order(Action.PUSH, ItemInfo(itemShulkerToStore, number = 0, containedInShulker = true)) - } - }) + if (stashOrders.isNotEmpty()) { + MessageSendHelper.sendChatMessage("No empty shulker boxes found, getting new ones and dump full ones.") + addSubActivities(StashTransaction(stashOrders)) + return + } } if (player.inventorySlots.countEmpty() <= BuildTools.keepFreeSlots) { @@ -192,54 +197,37 @@ object ActivityManager : Manager, Activity() { } to shulker boxes.") addSubActivities(itemsToStore.map { - StoreItemToShulkerBox(ItemInfo(it, 0)) + ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, it, 0)) }) + return } } - if (BuildTools.usePickaxe) checkItem(Items.DIAMOND_PICKAXE).ifPresent { stashOrders.add(it) } - if (BuildTools.useShovel) checkItem(Items.DIAMOND_SHOVEL).ifPresent { stashOrders.add(it) } - if (BuildTools.useAxe) checkItem(Items.DIAMOND_AXE).ifPresent { stashOrders.add(it) } - if (BuildTools.useSword) checkItem(Items.DIAMOND_SWORD).ifPresent { stashOrders.add(it) } - if (BuildTools.useShears) checkItem(Items.SHEARS).ifPresent { stashOrders.add(it) } - - checkItem(Items.GOLDEN_APPLE).ifPresent { stashOrders.add(it) } - - if (stashOrders.isNotEmpty()) { - addSubActivities(stashOrders.groupBy { it.first }.map { group -> - MessageSendHelper.sendChatMessage("Orders for stash at (${ - group.key.area.center.asString() - }): ${ - stashOrders.joinToString { - "${ - it.second.action.name - }:${ - it.second.itemInfo.item.registryName.toString().split(":")[1] - }" - } - }") + if (BuildTools.usePickaxe) checkItem(Items.DIAMOND_PICKAXE, stashOrders) + if (BuildTools.useShovel) checkItem(Items.DIAMOND_SHOVEL, stashOrders) + if (BuildTools.useAxe) checkItem(Items.DIAMOND_AXE, stashOrders) + if (BuildTools.useSword) checkItem(Items.DIAMOND_SWORD, stashOrders) + if (BuildTools.useShears) checkItem(Items.SHEARS, stashOrders) - StashTransaction(group.value.map { it.second }, group.key) - }) - } + checkItem(Items.GOLDEN_APPLE, stashOrders) + + if (stashOrders.isNotEmpty()) addSubActivities(StashTransaction(stashOrders)) } - private fun SafeClientEvent.checkItem(item: Item): Optional> { + private fun SafeClientEvent.checkItem(item: Item, orders: MutableSet>) { if (player.allSlots.countItem(item) + player.allSlots.sumOf { slot -> getShulkerInventory(slot.stack)?.filter { it.item == item }?.sumOf { it.count } ?: 0 - // ToDo: Add ender chest support - } >= BuildTools.minToolAmount) return Optional.empty() + // ToDo: Add ender chest support also make this use some kind of utils for storage management + } >= BuildTools.minToolAmount) return val optimalStash = WorldEater.stashes .filter { it.items.contains(item) } - .minByOrNull { player.distanceTo(it.area.center) } ?: return Optional.empty() + .minByOrNull { player.distanceTo(it.area.center) } ?: return MessageSendHelper.sendChatMessage("Missing ${ item.registryName - }. Fetching from stash at ${optimalStash.area.center.asString()}.") + }. Fetching shulker from stash (${optimalStash.area.center.asString()}).") - return Optional.of( - optimalStash to Order(Action.PULL, ItemInfo(item)) - ) + orders.add(optimalStash to ShulkerOrder(ContainerAction.PULL, item, 1)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt index 68e8489f3..1eb679145 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/client/BuildTools.kt @@ -25,8 +25,8 @@ object BuildTools : Module( val maxReach by setting("Max Reach", 4.9f, 1.0f..7.0f, 0.1f, { page == Page.BUILDING }, description = "Sets the range of the blueprint. Decrease when tasks fail!", unit = " blocks") val autoPathing by setting("Auto Pathing", true, { page == Page.BUILDING }, description = "Automatically pathfind to the next block") val pathingRecomputeTimeout by setting("Pathing Recompute Timeout", 200, 0..1000, 20, { page == Page.BUILDING }, description = "Timeout for recomputing the path", unit = " ms") - val collectRange by setting("Collect Range", 8, 1..50, 1, { page == Page.BUILDING }, description = "Sets the range of the pickup", unit = " blocks") - val minimumStackSize by setting("Minimum Stack Size To Collect", 32, 1..64, 1, { page == Page.BUILDING }, description = "Minimum amount of items to pick up", unit = " items") + val collectRange by setting("Collect Range", 16, 1..50, 1, { page == Page.BUILDING }, description = "Sets the range of the pickup", unit = " blocks") + val minimumStackSize by setting("Minimum Amount Collect", 32, 1..64, 1, { page == Page.BUILDING }, description = "Minimum amount of items to pick up", unit = " items") // val moveSpeed by setting("Packet Move Speed", 0.2, 0.0..1.0, 0.01, { page == Page.BEHAVIOR }, description = "Maximum player velocity per tick", unit = "m/t") // val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again", unit = " ticks") // val maxRetries by setting("Max Task Retries", 3, 0..10, 1, { page == Page.BEHAVIOR }, description = "Maximum amount of timeouts for a task") diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index f1c2a5e27..8d63c8c83 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -5,9 +5,8 @@ import com.lambda.client.activity.activities.construction.SurroundWithObsidian import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.interaction.crafting.ReachXPLevel import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.BreakDownEnderChests -import com.lambda.client.activity.activities.storage.ItemInfo -import com.lambda.client.activity.activities.storage.StoreItemToShulkerBox +import com.lambda.client.activity.activities.storage.* +import com.lambda.client.activity.activities.storage.types.* import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.activity.types.RenderAABBActivity.Companion.checkAABBRender import com.lambda.client.manager.managers.ActivityManager @@ -22,6 +21,8 @@ import com.lambda.client.util.threads.runSafe import net.minecraft.block.BlockDirectional import net.minecraft.block.BlockHorizontal import net.minecraft.init.Blocks +import net.minecraft.init.Items +import net.minecraft.item.Item import net.minecraft.util.EnumFacing object TestActivityManager : Module( @@ -36,13 +37,41 @@ object TestActivityManager : Module( false }) - private val tie by setting("Store Obby", false, consumer = { _, _-> + private val tie by setting("Store one Obby", false, consumer = { _, _-> addSubActivities( - StoreItemToShulkerBox(ItemInfo(Blocks.OBSIDIAN.item, 0)) + ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, Blocks.OBSIDIAN.item, 1)) ) false }) + private val eictie by setting("Stash request", false, consumer = { _, _-> + WorldEater.stashes.firstOrNull()?.let { + addSubActivities( + StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Blocks.OBSIDIAN.item, 1))) + ) + } + false + }) + + private val ectitie by setting("Stash request multi", false, consumer = { _, _-> + WorldEater.stashes.firstOrNull()?.let { + addSubActivities( + StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Blocks.OBSIDIAN.item, 0))) + ) + } + false + }) + + private val ectiectictietie by setting("Stash request multi more", false, consumer = { _, _-> + WorldEater.stashes.firstOrNull()?.let { + addSubActivities( + StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Items.DIAMOND_SHOVEL, 1))), + StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PUSH, Items.DIAMOND_SHOVEL, 1))) + ) + } + false + }) + private val etit by setting("Acquire Obby", false, consumer = { _, _-> addSubActivities( AcquireItemInActiveHand(ItemInfo(Blocks.OBSIDIAN.item)) diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt index 0a9a930ac..1493ac653 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/WorldEater.kt @@ -2,8 +2,8 @@ package com.lambda.client.module.modules.misc import com.lambda.client.activity.activities.construction.ClearArea import com.lambda.client.activity.activities.construction.core.BuildStructure -import com.lambda.client.activity.activities.storage.Area -import com.lambda.client.activity.activities.storage.Stash +import com.lambda.client.activity.activities.storage.types.Area +import com.lambda.client.activity.activities.storage.types.Stash import com.lambda.client.command.CommandManager.prefix import com.lambda.client.event.SafeClientEvent import com.lambda.client.manager.managers.ActivityManager From 02d3d64b63e2350a0ac42d3703ee434a041e1bde Mon Sep 17 00:00:00 2001 From: Constructor Date: Sat, 12 Aug 2023 20:57:22 +0200 Subject: [PATCH 104/104] Full predicate logic selection support --- .../construction/core/BreakBlock.kt | 18 +- .../construction/core/PlaceBlock.kt | 8 +- .../activities/interaction/AttachItemFrame.kt | 4 +- .../activities/interaction/AttachMap.kt | 4 +- .../interaction/crafting/CraftShulkerBox.kt | 7 +- .../interaction/crafting/ReachXPLevel.kt | 4 +- .../inventory/AcquireItemInActiveHand.kt | 52 ++---- .../storage/BreakDownEnderChests.kt | 23 +-- .../activities/storage/ShulkerTransaction.kt | 18 +- .../activities/storage/StashTransaction.kt | 10 +- .../core/ContainerWindowTransaction.kt | 13 +- .../activities/storage/core/PlaceContainer.kt | 10 +- .../activities/storage/types/Action.kt | 74 -------- .../storage/types/ContainerAction.kt | 5 + .../storage/types/StackSelection.kt | 176 ++++++++++++++++++ .../manager/managers/ActivityManager.kt | 27 ++- .../modules/misc/TestActivityManager.kt | 24 ++- .../modules/player/InventoryManagerTwo.kt | 5 +- 18 files changed, 300 insertions(+), 182 deletions(-) delete mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/types/ContainerAction.kt create mode 100644 src/main/kotlin/com/lambda/client/activity/activities/storage/types/StackSelection.kt diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt index d83e8eb24..29fd41c05 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/BreakBlock.kt @@ -4,7 +4,7 @@ import baritone.api.BaritoneAPI import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.activities.travel.CollectDrops import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent @@ -334,15 +334,15 @@ class BreakBlock( context = BuildActivity.Context.RESTOCK addSubActivities(AcquireItemInActiveHand( - ItemInfo(tool, predicate = { - when { - forceSilk -> EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 1 - forceNoSilk -> EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 - forceFortune -> EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, it) > 0 - forceNoFortune -> EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, it) == 0 - else -> true + StackSelection().apply { + selection = isItem(tool) and when { + forceSilk -> hasEnchantment(Enchantments.SILK_TOUCH) + forceNoSilk -> hasEnchantment(Enchantments.SILK_TOUCH).not() + forceFortune -> hasEnchantment(Enchantments.FORTUNE) + forceNoFortune -> hasEnchantment(Enchantments.FORTUNE).not() + else -> isItem() } - }), + } )) return false } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt index 23a33c6fa..db1fe4d0a 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/construction/core/PlaceBlock.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.construction.core import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.Rotate import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.types.* import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.PacketEvent @@ -305,9 +305,9 @@ class PlaceBlock( ) { context = BuildActivity.Context.RESTOCK - addSubActivities(AcquireItemInActiveHand( - ItemInfo(optimalStack.item, metadata = optimalStack.metadata) - )) + addSubActivities(AcquireItemInActiveHand(StackSelection().apply { + selection = isItem(optimalStack.item) and hasMetadata(optimalStack.metadata) + })) return } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt index 6845caa12..d89b689bf 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachItemFrame.kt @@ -3,7 +3,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.LambdaMod import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent @@ -31,7 +31,7 @@ class AttachItemFrame( rotation = getRotationTo(getHitVec(placePos, facing)) addSubActivities( - AcquireItemInActiveHand(ItemInfo(Items.ITEM_FRAME)) + AcquireItemInActiveHand(StackSelection().apply { selection = isItem(Items.ITEM_FRAME) }) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt index a955054bf..c3b1175a4 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/AttachMap.kt @@ -2,7 +2,7 @@ package com.lambda.client.activity.activities.interaction import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.types.RotatingActivity import com.lambda.client.activity.types.TimeoutActivity import com.lambda.client.event.SafeClientEvent @@ -29,7 +29,7 @@ class AttachMap( rotation = getRotationToEntity(itemFrame) addSubActivities( - AcquireItemInActiveHand(ItemInfo(Items.MAP, predicate = { it.itemDamage == mapID })), + AcquireItemInActiveHand(StackSelection().apply { selection = isItem(Items.MAP) and hasDamage(mapID) }) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt index 69dfa2584..c66261527 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/CraftShulkerBox.kt @@ -2,17 +2,16 @@ package com.lambda.client.activity.activities.interaction.crafting import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.event.SafeClientEvent -import com.lambda.client.util.items.item import net.minecraft.init.Blocks import net.minecraft.init.Items class CraftShulkerBox : Activity() { override fun SafeClientEvent.onInitialize() { addSubActivities( - AcquireItemInActiveHand(ItemInfo(Items.SHULKER_SHELL)), - AcquireItemInActiveHand(ItemInfo(Blocks.CHEST.item)), + AcquireItemInActiveHand(StackSelection().apply { selection = isItem(Items.SHULKER_SHELL) }), + AcquireItemInActiveHand(StackSelection().apply { selection = isBlock(Blocks.CHEST) }), // InventoryTransaction(0, ) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt index 5d7edc037..685fc9505 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/interaction/crafting/ReachXPLevel.kt @@ -4,7 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.interaction.UseThrowableOnEntity import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.inventory.TakeOffArmor -import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent import net.minecraft.init.Items @@ -19,7 +19,7 @@ class ReachXPLevel( override fun SafeClientEvent.onInitialize() { addSubActivities( TakeOffArmor(), - AcquireItemInActiveHand(ItemInfo(Items.EXPERIENCE_BOTTLE)), + AcquireItemInActiveHand(StackSelection().apply { selection = isItem(Items.EXPERIENCE_BOTTLE) }), UseThrowableOnEntity(player) ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt index 657c537c5..710ad6722 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/inventory/AcquireItemInActiveHand.kt @@ -6,10 +6,7 @@ import com.lambda.client.activity.activities.inventory.core.SwapOrSwitchToSlot import com.lambda.client.activity.activities.inventory.core.SwitchToHotbarSlot import com.lambda.client.activity.activities.storage.BreakDownEnderChests import com.lambda.client.activity.activities.storage.ShulkerTransaction -import com.lambda.client.activity.activities.storage.types.ContainerAction -import com.lambda.client.activity.activities.storage.types.ItemInfo -import com.lambda.client.activity.activities.storage.types.ShulkerOrder -import com.lambda.client.activity.getShulkerInventory +import com.lambda.client.activity.activities.storage.types.* import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools @@ -24,12 +21,9 @@ import net.minecraft.item.ItemStack /** * [AcquireItemInActiveHand] is an [Activity] that attempts to acquire an [Item] in the player's active hand. - * It will attempt to acquire the item in the following order: - * 1. Switch to the hotbar slot that contains the item - * 2. Swap the item with an item in the hotbar */ class AcquireItemInActiveHand( - private val itemInfo: ItemInfo, + private val order: StackSelection, private val searchShulkerBoxes: Boolean = true, private val searchEnderChest: Boolean = true, ) : AttemptActivity, Activity() { @@ -38,37 +32,39 @@ class AcquireItemInActiveHand( override fun SafeClientEvent.onInitialize() { // If the item is already in the player's hand, we're done - if (itemInfo.stackFilter(player.heldItemMainhand)) { + if (order.selection(player.heldItemMainhand)) { success() return } // If the item is in the hotbar, switch to it - player.hotbarSlots.firstOrNull(itemInfo.slotFilter)?.let { + player.hotbarSlots.firstOrNull(order.filter)?.let { addSubActivities(SwitchToHotbarSlot(it)) return } // If we are in game mode creative, we can just use the creative inventory (if item not yet in hotbar) if (pickBlock && player.capabilities.isCreativeMode) { - addSubActivities(CreativeInventoryAction(itemInfo.optimalStack)) - return + order.optimalStack?.let { + addSubActivities(CreativeInventoryAction(it)) + return + } } - // If the item is in the inventory, swap it with next best slot in hotbar - player.allSlots.firstOrNull(itemInfo.slotFilter)?.let { slotFrom -> + // If the item is in the inventory, swap it with the next best slot in hotbar + player.allSlots.firstOrNull(order.filter)?.let { slotFrom -> addSubActivities(SwapOrSwitchToSlot(slotFrom)) return } // If the item is in a shulker box, extract it - if (searchShulkerBoxes && itemInfo.item !is ItemShulkerBox) { - addSubActivities(ShulkerTransaction(ShulkerOrder(ContainerAction.PULL, itemInfo.item, itemInfo.number))) + if (searchShulkerBoxes && order.item !is ItemShulkerBox) { + addSubActivities(ShulkerTransaction(ContainerAction.PULL, order)) return } // If the item is obsidian, break down ender chests - if (itemInfo.item == Blocks.OBSIDIAN.item) { + if (order.item == Blocks.OBSIDIAN.item) { addSubActivities(BreakDownEnderChests(maximumRepeats = BuildTools.breakDownCycles)) return } @@ -77,22 +73,22 @@ class AcquireItemInActiveHand( // if (searchEnderChest) { // // TODO: Check cached ender chest inventory if item is in there directly or in a shulker box // player.allSlots.firstOrNull { it.stack.item == Blocks.ENDER_CHEST.item }?.let { slot -> -// addSubActivities(ExtractItemFromContainerStack(slot.stack, itemInfo)) +// addSubActivities(EnderChestTransaction(ShulkerOrder(ContainerAction.PULL, order.item, order.amount), slot)) // return // } // -// addSubActivities(AcquireItemInActiveHand(ItemInfo(Blocks.ENDER_CHEST.item), searchEnderChest = false)) +// addSubActivities(AcquireItemInActiveHand(order, searchEnderChest = false)) // return // } - failedWith(NoItemFoundException(itemInfo)) + failedWith(NoItemFoundException(order)) } override fun SafeClientEvent.onSuccess() { val currentItemStack = player.heldItemMainhand - if (!itemInfo.stackFilter(currentItemStack)) { - failedWith(FailedToMoveItemException(itemInfo, currentItemStack)) + if (!order.selection(currentItemStack)) { + failedWith(FailedToMoveItemException(order, currentItemStack)) } } @@ -102,14 +98,6 @@ class AcquireItemInActiveHand( status = Status.UNINITIALIZED } - private fun SafeClientEvent.selectOptimalShulker() = player.allSlots.mapNotNull { slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - val count = inventory.count(itemInfo.stackFilter) - - if (count > 0) slot to count else null - } - }.minByOrNull { it.second }?.first - - class NoItemFoundException(itemInfo: ItemInfo) : Exception("No $itemInfo found in inventory") - class FailedToMoveItemException(itemInfo: ItemInfo, currentStack: ItemStack) : Exception("Failed to move $itemInfo} to hotbar (current item: ${currentStack.item.registryName})") + class NoItemFoundException(order: StackSelection) : Exception("No $order found in inventory") + class FailedToMoveItemException(order: StackSelection, currentStack: ItemStack) : Exception("Failed to move ${order.item?.registryName?.path} to hotbar (current item: ${currentStack.item.registryName?.path})") } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt index 63a1d72d9..0fbc3bc8b 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/BreakDownEnderChests.kt @@ -4,10 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.core.PlaceContainer -import com.lambda.client.activity.activities.storage.types.ContainerAction -import com.lambda.client.activity.activities.storage.types.ItemInfo -import com.lambda.client.activity.activities.storage.types.ItemOrder -import com.lambda.client.activity.activities.storage.types.ShulkerOrder +import com.lambda.client.activity.activities.storage.types.* import com.lambda.client.activity.types.RepeatingActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.module.modules.client.BuildTools @@ -33,7 +30,9 @@ class BreakDownEnderChests( if (freeSlots.isEmpty()) { if (player.inventorySlots.countItem(Blocks.OBSIDIAN.item) > 0) { addSubActivities( - ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, Blocks.OBSIDIAN.item, 0)) + ShulkerTransaction(ContainerAction.PUSH, StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }) ) return } @@ -42,9 +41,10 @@ class BreakDownEnderChests( return } - // ToDo: Better way to find ender chest addSubActivities( - PlaceContainer(ItemStack(Blocks.ENDER_CHEST, 1, 0), onlyItem = true) + PlaceContainer(StackSelection().apply { + selection = isBlock(Blocks.ENDER_CHEST) + }) ) } @@ -52,12 +52,9 @@ class BreakDownEnderChests( if (childActivity !is PlaceContainer) return addSubActivities( - AcquireItemInActiveHand(ItemInfo( - Items.DIAMOND_PICKAXE, - predicate = { - EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, it) == 0 - } - )), + AcquireItemInActiveHand(StackSelection().apply { + selection = isItem(Items.DIAMOND_PICKAXE) and hasEnchantment(Enchantments.SILK_TOUCH).not() + }), BreakBlock( childActivity.containerPos, collectDrops = true, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt index e25ebaf32..7f8e1cb4f 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/ShulkerTransaction.kt @@ -6,8 +6,7 @@ import com.lambda.client.activity.activities.storage.core.CloseContainer import com.lambda.client.activity.activities.storage.core.ContainerWindowTransaction import com.lambda.client.activity.activities.storage.core.PlaceContainer import com.lambda.client.activity.activities.storage.types.ContainerAction -import com.lambda.client.activity.activities.storage.types.ItemOrder -import com.lambda.client.activity.activities.storage.types.ShulkerOrder +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.items.allSlots @@ -15,15 +14,18 @@ import com.lambda.client.util.items.allSlots * Push or pull item from a fitting shulker from inventory */ class ShulkerTransaction( - val order: ShulkerOrder + val action: ContainerAction, + val order: StackSelection ) : Activity() { override fun SafeClientEvent.onInitialize() { - if (order.action == ContainerAction.PULL) { + if (action == ContainerAction.PULL) { player.allSlots.mapNotNull { order.findShulkerToPull(it) }.minByOrNull { it.second }?.first?.let { slot -> addSubActivities( - PlaceContainer(slot.stack.copy(), open = true) + PlaceContainer(StackSelection().apply { + selection = isItemStack(slot.stack) + }, open = true) ) return } @@ -32,7 +34,9 @@ class ShulkerTransaction( order.findShulkerToPush(it) }.minByOrNull { it.second }?.first?.let { slot -> addSubActivities( - PlaceContainer(slot.stack.copy(), open = true) + PlaceContainer(StackSelection().apply { + selection = isItemStack(slot.stack) + }, open = true) ) return } @@ -43,7 +47,7 @@ class ShulkerTransaction( if (childActivity !is PlaceContainer) return addSubActivities( - ContainerWindowTransaction(ItemOrder(order.action, order.item, order.amount)), + ContainerWindowTransaction(action, order), CloseContainer(), BreakBlock( childActivity.containerPos, diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt index 040544739..6365444fd 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/StashTransaction.kt @@ -2,13 +2,13 @@ package com.lambda.client.activity.activities.storage import baritone.api.pathing.goals.GoalBlock import baritone.api.pathing.goals.GoalGetToBlock -import baritone.api.pathing.goals.GoalXZ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.storage.core.CloseContainer import com.lambda.client.activity.activities.storage.core.ContainerWindowTransaction import com.lambda.client.activity.activities.storage.core.OpenContainer +import com.lambda.client.activity.activities.storage.types.ContainerAction import com.lambda.client.activity.activities.storage.types.Stash -import com.lambda.client.activity.activities.storage.types.ContainerOrder +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.activities.travel.CustomGoal import com.lambda.client.activity.types.LoopWhileActivity import com.lambda.client.event.SafeClientEvent @@ -22,12 +22,12 @@ import net.minecraft.tileentity.TileEntity * @param orders The orders to pull or push items. */ class StashTransaction( - private val orders: Set> + private val orders: Set> ) : LoopWhileActivity, Activity() { override val loopWhile: SafeClientEvent.() -> Boolean = { orderQueue.isNotEmpty() } override var currentLoops = 0 - private val orderQueue = ArrayDeque(orders.sortedBy { it.second.action }) + private val orderQueue = ArrayDeque(orders.sortedBy { it.second }) // try different containers in case one is not matching the search private val containerQueue = ArrayDeque() @@ -68,7 +68,7 @@ class StashTransaction( addSubActivities( CustomGoal(GoalGetToBlock(container.pos)), OpenContainer(container.pos), - ContainerWindowTransaction(order.second), + ContainerWindowTransaction(order.second, order.third), CloseContainer() ) } diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt index ef94b7031..ba82958c2 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/ContainerWindowTransaction.kt @@ -13,12 +13,13 @@ import com.lambda.client.util.text.MessageSendHelper import net.minecraft.inventory.Container class ContainerWindowTransaction( - private val order: ContainerOrder + private val action: ContainerAction, + private val order: StackSelection ) : Activity() { override fun SafeClientEvent.onInitialize() { val seperatedSlots = player.openContainer.seperatedSlots - val (fromSlots, toSlots) = if (order.action == ContainerAction.PULL) { + val (fromSlots, toSlots) = if (action == ContainerAction.PULL) { seperatedSlots.let { (first, second) -> Pair(first, second) } } else { seperatedSlots.let { (first, second) -> Pair(second, first) } @@ -27,7 +28,7 @@ class ContainerWindowTransaction( val toMoveSlots = fromSlots.filter(order.filter) if (toMoveSlots.isEmpty()) { - if (order is GeneralOrder && order.amount == 0) { + if (order.count == 0) { success() return } @@ -36,15 +37,15 @@ class ContainerWindowTransaction( return } - if (toMoveSlots.size < order.amount) { + if (toMoveSlots.size < order.count) { failedWith(NotEnoughSlotsException()) return } - val remainingSlots = if (order.amount == 0) { + val remainingSlots = if (order.count == 0) { toMoveSlots } else { - toMoveSlots.take(order.amount) + toMoveSlots.take(order.count) } remainingSlots.forEach { fromSlot -> diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt index 1210a41f3..fcc97c306 100644 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/core/PlaceContainer.kt @@ -4,6 +4,7 @@ import com.lambda.client.activity.Activity import com.lambda.client.activity.activities.construction.core.PlaceBlock import com.lambda.client.activity.activities.inventory.AcquireItemInActiveHand import com.lambda.client.activity.activities.storage.types.ItemInfo +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.activity.types.AttemptActivity import com.lambda.client.event.SafeClientEvent import com.lambda.client.util.EntityUtils.flooredPosition @@ -19,8 +20,7 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos class PlaceContainer( - private val useStack: ItemStack, - private val onlyItem: Boolean = false, + private val selection: StackSelection, private val open: Boolean = false, override val maxAttempts: Int = 5, override var usedAttempts: Int = 0 @@ -34,10 +34,8 @@ class PlaceContainer( } addSubActivities( - AcquireItemInActiveHand(ItemInfo( - useStack.item, predicate = { onlyItem || ItemStack.areItemStacksEqual(it, useStack) } - )), - PlaceBlock(containerPos, useStack.item.block.defaultState, ignoreProperties = true) + AcquireItemInActiveHand(selection), + PlaceBlock(containerPos, selection.placementResult, ignoreProperties = true) ) if (open) addSubActivities(OpenContainer(containerPos)) diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt deleted file mode 100644 index 08184bca0..000000000 --- a/src/main/kotlin/com/lambda/client/activity/activities/storage/types/Action.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.lambda.client.activity.activities.storage.types - -import com.lambda.client.activity.getShulkerInventory -import net.minecraft.inventory.Slot -import net.minecraft.item.Item -import net.minecraft.item.ItemStack - -class ItemOrder(override val action: ContainerAction, val item: Item, override val amount: Int) : ContainerOrder { - override val filter = { slot: Slot -> - slot.stack.item == item - } -} - -class ShulkerOrder(override val action: ContainerAction, val item: Item, override val amount: Int) : ContainerOrder { - override val filter = { slot: Slot -> - getShulkerInventory(slot.stack)?.any { it.item == item } == true - } - val findShulkerToPush = { slot: Slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - if (inventory.all { it.item == item || it.isEmpty }) { - val storableItems = inventory.sumOf { -// if (it.isEmpty) item.itemStackLimit else it.maxStackSize - it.count - if (it.isEmpty) item.itemStackLimit else 0 - } - - if (storableItems > 0) slot to storableItems else null - } else null - } - } - val findShulkerToPull = { slot: Slot -> - getShulkerInventory(slot.stack)?.let { inventory -> - val usableItems = inventory.sumOf { if (it.item == item) it.count else 0 } - - if (usableItems > 0) slot to usableItems else null - } - } -} - -class SelectionOrder(override val action: ContainerAction, selection: (Slot) -> Boolean, override val amount: Int) : ContainerOrder { - override val filter = selection -} - -class StackOrder(override val action: ContainerAction, val itemStack: ItemStack, override val amount: Int) : ContainerOrder { - override val filter = { slot: Slot -> - ItemStack.areItemStacksEqual(itemStack, slot.stack) - } -} - -class GeneralOrder(override val action: ContainerAction, selection: Selection, override val amount: Int) : ContainerOrder { - override val filter = selection.slotFilter - - enum class Selection(val slotFilter: (Slot) -> Boolean) { - FULL_SHULKERS({ slot -> - getShulkerInventory(slot.stack)?.none { it.isEmpty } == true - }), - EMPTY_SHULKERS({ slot -> - getShulkerInventory(slot.stack)?.all { it.isEmpty } == true - }), - EVERYTHING({ true }) - } -} - -enum class ContainerAction { - PUSH, PULL -} - -/** - * Implemented by [ItemOrder], [ShulkerOrder], [SelectionOrder], [StackOrder], [GeneralOrder] - */ -interface ContainerOrder { - val action: ContainerAction - val amount: Int - val filter: (Slot) -> Boolean -} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/types/ContainerAction.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/ContainerAction.kt new file mode 100644 index 000000000..7c35a9b23 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/ContainerAction.kt @@ -0,0 +1,5 @@ +package com.lambda.client.activity.activities.storage.types + +enum class ContainerAction { + PUSH, PULL +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/activity/activities/storage/types/StackSelection.kt b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/StackSelection.kt new file mode 100644 index 000000000..f4d3ae343 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/activity/activities/storage/types/StackSelection.kt @@ -0,0 +1,176 @@ +package com.lambda.client.activity.activities.storage.types + +import com.lambda.client.activity.getShulkerInventory +import com.lambda.client.util.items.block +import com.lambda.client.util.items.item +import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState +import net.minecraft.enchantment.Enchantment +import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.init.Blocks +import net.minecraft.inventory.Slot +import net.minecraft.item.Item +import net.minecraft.item.ItemStack + +/** + * [StackSelection] is a class that holds a predicate for matching [ItemStack]s. + * @param count The count of item stacks to be matched. + * @param selection The predicate for matching [ItemStack]s. + */ +class StackSelection( + var count: Int = DEFAULT_AMOUNT, + val inShulkerBox: Boolean = false +) { + lateinit var selection: (ItemStack) -> Boolean + + var item: Item? = null + private var metadata: Int? = null + private var damage: Int? = null + private var itemStack: ItemStack? = null + + val filter: (Slot) -> Boolean get() = { slot -> + if (inShulkerBox) { + getShulkerInventory(slot.stack)?.any { selection(it) } ?: false + } else selection(slot.stack) + } + + val optimalStack: ItemStack? + get() = item?.let { ItemStack(it, count, metadata ?: 0) } + + val placementResult: IBlockState + get() = itemStack?.item?.block?.defaultState + ?: optimalStack?.item?.block?.defaultState + ?: Blocks.AIR.defaultState + + /** + * returns a function that finds a shulker box to push matching items into. + */ + val findShulkerToPush = { slot: Slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + if (inventory.all { selection(it) || it.isEmpty }) { + val storableItems = inventory.sumOf { +// if (it.isEmpty) item.itemStackLimit else it.maxStackSize - it.count + if (it.isEmpty) item?.itemStackLimit ?: 0 else 0 + } + + if (storableItems > 0) slot to storableItems else null + } else null + } + } + + /** + * returns a function that finds a shulker box to pull matching items from. + */ + val findShulkerToPull = { slot: Slot -> + getShulkerInventory(slot.stack)?.let { inventory -> + val usableItems = inventory.sumOf { if (selection(it)) it.count else 0 } + + if (usableItems > 0) slot to usableItems else null + } + } + + /** + * [isItem] returns a predicate that matches a specific [Item]. + * @param item The [Item] to be matched. + * @return A predicate that matches the [Item]. + */ + fun isItem(item: Item): (ItemStack) -> Boolean { + this.item = item + return { it.item == item } + } + + /** + * [isItem] returns a predicate that matches a specific [Item] instance. + * @param T The instance of [Item] to be matched. + * @return A predicate that matches the [Item]. + */ + inline fun isItem(): (ItemStack) -> Boolean = { it.item is T } + + /** + * [isBlock] returns a predicate that matches a specific [Block]. + * @param block The [Block] to be matched. + * @return A predicate that matches the [Block]. + */ + fun isBlock(block: Block): (ItemStack) -> Boolean { + item = block.item + return { it.item == block.item } + } + + /** + * [isItemStack] returns a predicate that matches a specific [ItemStack]. + * @param stack The [ItemStack] to be matched. + * @return A predicate that matches the [ItemStack]. + */ + fun isItemStack(stack: ItemStack): (ItemStack) -> Boolean { + this.itemStack = stack + return { ItemStack.areItemStacksEqual(it, stack) } + } + + /** + * [hasMetadata] returns a predicate that matches a specific `metadata`. + * @param metadata The `metadata` to be matched. + * @return A predicate that matches the `metadata`. + */ + fun hasMetadata(metadata: Int): (ItemStack) -> Boolean { + this.metadata = metadata + return { it.metadata == metadata } + } + + /** + * [hasDamage] returns a predicate that matches a specific damage value. + * @param damage The damage value to be matched. + * @return A predicate that matches the damage value. + */ + fun hasDamage(damage: Int): (ItemStack) -> Boolean { + this.damage = damage + return { it.itemDamage == damage } + } + + /** + * [hasEnchantment] returns a predicate that matches a specific [Enchantment] and level. + * @param enchantment The [Enchantment] to be matched. + * @param level The level to be matched (if -1 will look for any level above 0). + * @return A predicate that matches the [Enchantment] and `level`. + */ + fun hasEnchantment(enchantment: Enchantment, level: Int = -1): (ItemStack) -> Boolean = { + if (level < 0) EnchantmentHelper.getEnchantmentLevel(enchantment, it) > 0 + else EnchantmentHelper.getEnchantmentLevel(enchantment, it) == level + } + + /** + * Returns the negation of the original predicate. + * @return A new predicate that matches if the original predicate does not match. + */ + fun ((ItemStack) -> Boolean).not(): (ItemStack) -> Boolean { + return { !this(it) } + } + + /** + * Combines two predicates using the logical AND operator. + * @param otherPredicate The second predicate. + * @return A new predicate that matches if both input predicates match. + */ + infix fun ((ItemStack) -> Boolean).and(otherPredicate: (ItemStack) -> Boolean): (ItemStack) -> Boolean { + return { this(it) && otherPredicate(it) } + } + + /** + * Combines two predicates using the logical OR operator. + * @param otherPredicate The second predicate. + * @return A new predicate that matches if either input predicate matches. + */ + infix fun ((ItemStack) -> Boolean).or(otherPredicate: (ItemStack) -> Boolean): (ItemStack) -> Boolean { + return { this(it) || otherPredicate(it) } + } + + companion object { + const val DEFAULT_AMOUNT = 1 + val FULL_SHULKERS: (ItemStack) -> Boolean = { stack -> + getShulkerInventory(stack)?.none { it.isEmpty } == true + } + val EMPTY_SHULKERS: (ItemStack) -> Boolean = { stack -> + getShulkerInventory(stack)?.all { it.isEmpty } == true + } + val EVERYTHING: (ItemStack) -> Boolean = { true } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt index d0e2fc6e8..68bd062c2 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ActivityManager.kt @@ -161,21 +161,25 @@ object ActivityManager : Manager, Activity() { || allSubActivities.filterIsInstance().isNotEmpty() ) return - val stashOrders = mutableSetOf>() + val stashOrders = mutableSetOf>() - if (player.allSlots.none { slot -> getShulkerInventory(slot.stack)?.all { it.isEmpty } == true }) { + if (player.allSlots.none { StackSelection.EMPTY_SHULKERS(it.stack) }) { // ToDo: Request correct amount of shulkers WorldEater.stashes.minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> - stashOrders.add(stash to GeneralOrder(ContainerAction.PULL, GeneralOrder.Selection.EMPTY_SHULKERS, 5)) + stashOrders.add(Triple(stash, ContainerAction.PULL, StackSelection(5).apply { + selection = StackSelection.EMPTY_SHULKERS + })) } - if (player.allSlots.any(GeneralOrder.Selection.FULL_SHULKERS.slotFilter)) { + if (player.allSlots.any { StackSelection.FULL_SHULKERS(it.stack) }) { WorldEater.dropOff.minByOrNull { player.distanceTo(it.area.center) }?.let { stash -> - stashOrders.add(stash to GeneralOrder(ContainerAction.PUSH, GeneralOrder.Selection.FULL_SHULKERS, 0)) + stashOrders.add(Triple(stash, ContainerAction.PUSH, StackSelection(0).apply { + selection = StackSelection.FULL_SHULKERS + })) } } @@ -196,8 +200,11 @@ object ActivityManager : Manager, Activity() { itemsToStore.joinToString { "${it.registryName?.path}" } } to shulker boxes.") - addSubActivities(itemsToStore.map { - ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, it, 0)) + addSubActivities(itemsToStore.map { item -> + ShulkerTransaction(ContainerAction.PUSH, StackSelection().apply { + selection = isItem(item) + count = 0 + }) }) return } @@ -214,7 +221,7 @@ object ActivityManager : Manager, Activity() { if (stashOrders.isNotEmpty()) addSubActivities(StashTransaction(stashOrders)) } - private fun SafeClientEvent.checkItem(item: Item, orders: MutableSet>) { + private fun SafeClientEvent.checkItem(item: Item, orders: MutableSet>) { if (player.allSlots.countItem(item) + player.allSlots.sumOf { slot -> getShulkerInventory(slot.stack)?.filter { it.item == item }?.sumOf { it.count } ?: 0 // ToDo: Add ender chest support also make this use some kind of utils for storage management @@ -228,6 +235,8 @@ object ActivityManager : Manager, Activity() { item.registryName }. Fetching shulker from stash (${optimalStash.area.center.asString()}).") - orders.add(optimalStash to ShulkerOrder(ContainerAction.PULL, item, 1)) + orders.add(Triple(optimalStash, ContainerAction.PULL, StackSelection(inShulkerBox = true).apply { + selection = isItem(item) + })) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt index 8d63c8c83..578fd0bc5 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/misc/TestActivityManager.kt @@ -39,7 +39,9 @@ object TestActivityManager : Module( private val tie by setting("Store one Obby", false, consumer = { _, _-> addSubActivities( - ShulkerTransaction(ShulkerOrder(ContainerAction.PUSH, Blocks.OBSIDIAN.item, 1)) + ShulkerTransaction(ContainerAction.PUSH, StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }) ) false }) @@ -47,7 +49,9 @@ object TestActivityManager : Module( private val eictie by setting("Stash request", false, consumer = { _, _-> WorldEater.stashes.firstOrNull()?.let { addSubActivities( - StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Blocks.OBSIDIAN.item, 1))) + StashTransaction(setOf(Triple(it, ContainerAction.PULL, StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }))) ) } false @@ -56,7 +60,9 @@ object TestActivityManager : Module( private val ectitie by setting("Stash request multi", false, consumer = { _, _-> WorldEater.stashes.firstOrNull()?.let { addSubActivities( - StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Blocks.OBSIDIAN.item, 0))) + StashTransaction(setOf(Triple(it, ContainerAction.PULL, StackSelection(0).apply { + selection = isBlock(Blocks.OBSIDIAN) + }))) ) } false @@ -65,8 +71,12 @@ object TestActivityManager : Module( private val ectiectictietie by setting("Stash request multi more", false, consumer = { _, _-> WorldEater.stashes.firstOrNull()?.let { addSubActivities( - StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PULL, Items.DIAMOND_SHOVEL, 1))), - StashTransaction(setOf(it to ShulkerOrder(ContainerAction.PUSH, Items.DIAMOND_SHOVEL, 1))) + StashTransaction(setOf(Triple(it, ContainerAction.PULL, StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }))), + StashTransaction(setOf(Triple(it, ContainerAction.PUSH, StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }))) ) } false @@ -74,7 +84,9 @@ object TestActivityManager : Module( private val etit by setting("Acquire Obby", false, consumer = { _, _-> addSubActivities( - AcquireItemInActiveHand(ItemInfo(Blocks.OBSIDIAN.item)) + AcquireItemInActiveHand(StackSelection().apply { + selection = isBlock(Blocks.OBSIDIAN) + }) ) false }) diff --git a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt index f85b52f3e..0c8f195de 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/player/InventoryManagerTwo.kt @@ -2,6 +2,7 @@ package com.lambda.client.module.modules.player import com.lambda.client.activity.activities.construction.core.BreakBlock import com.lambda.client.activity.activities.storage.core.PlaceContainer +import com.lambda.client.activity.activities.storage.types.StackSelection import com.lambda.client.event.events.GuiEvent import com.lambda.client.event.events.WindowClickEvent import com.lambda.client.manager.managers.ActivityManager @@ -35,7 +36,9 @@ object InventoryManagerTwo : Module( player.openContainer.inventorySlots.getOrNull(it.slotId)?.let { slot -> if (!(slot.stack.item is ItemShulkerBox || slot.stack.item == Blocks.ENDER_CHEST.item)) return@safeListener - addSubActivities(PlaceContainer(slot.stack.copy(), open = true)) + addSubActivities(PlaceContainer(StackSelection().apply { + selection = isItemStack(slot.stack) + }, open = true)) it.cancel()