Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5e32fe9
suspend lambda for concurrent
emyfops Jun 11, 2024
f056268
Instant shulker opener
Avanatiker Jun 11, 2024
349366a
Merge branch 'feature/taskflow' of https://github.com/Avanatiker/NeoL…
Avanatiker Jun 11, 2024
c40e9ab
Task command and tweak fixes
Avanatiker Jun 11, 2024
bc0190c
Fix break on wrong screen close
Avanatiker Jun 12, 2024
85b8451
Fix: Collecting air item
emyfops Jun 12, 2024
84eef67
Merge branch 'master' into feature/taskflow
emyfops Jun 12, 2024
2c888f2
Merge branch 'master' into feature/taskflow
Avanatiker Jun 26, 2024
828800d
Merge branch 'master' into feature/taskflow
Avanatiker Jun 26, 2024
262f00f
Merge branch 'master' into feature/taskflow
Avanatiker Jul 3, 2024
27c2978
Merge branch 'master' into feature/taskflow
Avanatiker Jul 5, 2024
ab5fb35
Server synced interactions
Avanatiker Jul 6, 2024
5a88932
Item collection bug fix
Avanatiker Jul 6, 2024
df8a271
Fix support block and state control
Avanatiker Jul 6, 2024
5639895
Merge remote-tracking branch 'origin/master' into feature/taskflow
Avanatiker Aug 4, 2024
592abb8
Transitive architecture simplification
Avanatiker Aug 4, 2024
5d45429
Further simplifications
Avanatiker Aug 6, 2024
a48f9c4
Merge remote-tracking branch 'origin/master' into feature/taskflow
Avanatiker Aug 6, 2024
3c316fb
Merge branch 'master' into feature/taskflow
Avanatiker Aug 8, 2024
2e9f05c
Merge branch 'master' into feature/taskflow
Avanatiker Aug 19, 2024
d57889e
Merge remote-tracking branch 'origin/master' into feature/taskflow
Avanatiker Aug 20, 2024
5394f64
Fix imports
Avanatiker Aug 20, 2024
a499203
Merge branch 'master' into feature/taskflow
Avanatiker Aug 25, 2024
56e90d3
Merge branch 'master' into feature/taskflow
emyfops Sep 11, 2024
59b178f
Merge remote-tracking branch 'origin/master' into feature/taskflow
Avanatiker Sep 12, 2024
d0a2d2e
Merge branch 'master' into feature/taskflow
Avanatiker Sep 16, 2024
1db197e
Merge remote-tracking branch 'origin/master' into feature/taskflow
Avanatiker Sep 21, 2024
bc5f6d6
Build command and pending placements
Avanatiker Sep 22, 2024
abbdb9c
Dynamic disposables and rotation fix for breaking
Avanatiker Sep 24, 2024
59fbffa
Next tick stack check
Avanatiker Sep 24, 2024
e5b48a5
Iterative inventory transactions
Avanatiker Sep 24, 2024
1561340
Merge branch 'master' into feature/taskflow
Avanatiker Sep 24, 2024
403c7f6
Merge branch 'master' into feature/taskflow
Avanatiker Sep 24, 2024
d2f0906
No rotation on insta break
Avanatiker Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void onStartup(CallbackInfo ci) {
private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
if (screen == null) return;
if (screen instanceof ScreenHandlerProvider<?> handledScreen) {
EventFlow.post(new ScreenHandlerEvent.Open<>(handledScreen.getScreenHandler()));
EventFlow.post(new ScreenHandlerEvent.Open(handledScreen.getScreenHandler()));
}

EventFlow.post(new ScreenEvent.Open<>(screen));
Expand All @@ -61,7 +61,7 @@ private void onScreenOpen(@Nullable Screen screen, CallbackInfo ci) {
private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
if (currentScreen == null) return;
if (currentScreen instanceof ScreenHandlerProvider<?> handledScreen) {
EventFlow.post(new ScreenHandlerEvent.Close<>(handledScreen.getScreenHandler()));
EventFlow.post(new ScreenHandlerEvent.Close(handledScreen.getScreenHandler()));
}

EventFlow.post(new ScreenEvent.Close<>(currentScreen));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -13,6 +15,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerInteractionManager.class)
Expand All @@ -27,4 +30,11 @@ public void interactBlockHead(final ClientPlayerEntity player, final Hand hand,
if (client.world == null) return;
EventFlow.post(new InteractionEvent.Block(client.world, hitResult));
}

@Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true)
public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) {
if (syncId != player.currentScreenHandler.syncId) return;
var click = new InteractionEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler);
if (EventFlow.post(click).isCanceled()) ci.cancel();
}
}
11 changes: 10 additions & 1 deletion common/src/main/java/com/lambda/mixin/entity/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.lambda.Lambda;
import com.lambda.event.EventFlow;
import com.lambda.event.events.EntityEvent;
import com.lambda.event.events.WorldEvent;
import com.lambda.interaction.RotationManager;
import com.lambda.util.math.Vec2d;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -70,4 +72,11 @@ float fixDirectionPitch2(Entity entity) {
private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) {
if (EventFlow.post(new EntityEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel();
}
}

@Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL"))
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
Entity entity = (Entity) (Object) this;

EventFlow.post(new WorldEvent.EntityUpdate(entity, data));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lambda.mixin.render;

import com.lambda.event.EventFlow;
import com.lambda.event.events.ScreenEvent;
import com.lambda.event.events.ScreenHandlerEvent;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
Expand All @@ -16,6 +15,6 @@
public class ScreenHandlerMixin {
@Inject(method = "updateSlotStacks", at = @At("TAIL"))
private void onUpdateSlotStacksHead(int revision, List<ItemStack> stacks, ItemStack cursorStack, CallbackInfo ci) {
EventFlow.post(new ScreenHandlerEvent.Loaded(revision, stacks, cursorStack));
EventFlow.post(new ScreenHandlerEvent.Update(revision, stacks, cursorStack));
}
}
24 changes: 24 additions & 0 deletions common/src/main/kotlin/com/lambda/command/commands/TaskCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.lambda.command.commands

import com.lambda.brigadier.argument.literal
import com.lambda.brigadier.execute
import com.lambda.brigadier.required
import com.lambda.command.LambdaCommand
import com.lambda.task.RootTask
import com.lambda.util.Communication.info
import com.lambda.util.primitives.extension.CommandBuilder

object TaskCommand : LambdaCommand(
name = "task",
usage = "task <cancel>",
description = "Control tasks"
) {
override fun CommandBuilder.create() {
required(literal("cancel")) {
execute {
[email protected]("Cancelling all tasks")
RootTask.cancel()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.lambda.config.groups

interface BuildConfig {
val breakCoolDown: Int
val placeCooldown: Int
val breakConfirmation: Boolean
val placeConfirmation: Boolean
val collectDrops: Boolean
Expand All @@ -11,5 +9,4 @@ interface BuildConfig {
val breaksPerTick: Int
val rotateForBreak: Boolean
val rotateForPlace: Boolean
val pingTimeout: Boolean
}
12 changes: 5 additions & 7 deletions common/src/main/kotlin/com/lambda/config/groups/BuildSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ class BuildSettings(
vis: () -> Boolean = { true }
) : BuildConfig {
enum class Page {
BREAK, PLACE, GENERAL
GENERAL, BREAK, PLACE
}

private val page by c.setting("Build Page", Page.BREAK, "Current page", vis)
private val page by c.setting("Build Page", Page.GENERAL, "Current page", vis)

override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.GENERAL }

override val breakCoolDown by c.setting("Break Cooldown", 0, 0..1000, 1, "Delay between breaking blocks", " ms") { vis() && page == Page.BREAK }
override val breakConfirmation by c.setting("Break Confirmation", false, "Wait for block break confirmation") { vis() && page == Page.BREAK }
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() && page == Page.BREAK }
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 10, 1..30, 1, "Maximum instant block breaks per tick") { vis() && page == Page.BREAK }
override val rotateForBreak by c.setting("Rotate For Break", false, "Rotate towards block while breaking") { vis() && page == Page.BREAK }

override val collectDrops by c.setting("Collect All Drops", false, "Collect all drops when breaking blocks") { vis() && page == Page.BREAK }

override val placeCooldown by c.setting("Place Cooldown", 0, 0..1000, 1, "Delay between placing blocks", " ms") { vis() && page == Page.PLACE }
override val placeConfirmation by c.setting("Place Confirmation", true, "Wait for block placement confirmation") { vis() && page == Page.PLACE }

override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing") { vis() && page == Page.PLACE }

override val pathing by c.setting("Pathing", true, "Path to blocks") { vis() && page == Page.GENERAL }
override val pingTimeout by c.setting("Ping Timeout", true, "Timeout on high ping") { vis() && page == Page.GENERAL }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lambda.config.groups

import com.lambda.core.PingManager

interface InteractionConfig {
/**
* Maximum distance to interact.
Expand All @@ -13,4 +15,12 @@ interface InteractionConfig {

val useRayCast: Boolean
val swingHand: Boolean
val inScopeThreshold: Int
val pingTimeout: Boolean

val scopeThreshold: Int get() = if (pingTimeout) {
(PingManager.lastPing / 50L).toInt()
} else {
inScopeThreshold
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.lambda.config.groups

import com.lambda.config.Configurable
import com.lambda.config.groups.BuildSettings.Page
import com.lambda.core.PingManager
import com.lambda.module.modules.client.TaskFlow
import com.lambda.util.world.raycast.RayCastMask

class InteractionSettings(
Expand All @@ -11,4 +14,8 @@ class InteractionSettings(
override val useRayCast by c.setting("Raycast", false, "Verify hit vector with ray casting (for very strict ACs)", vis)
override val resolution by c.setting("Resolution", 5, 1..20, 1, "How many raycast checks per surface (will be squared)") { vis() && useRayCast }
override val swingHand by c.setting("Swing Hand", true, "Swing hand on interactions", vis)
override val pingTimeout by c.setting("Ping Timeout", false, "Timeout on high ping", vis)
override val inScopeThreshold by c.setting("Constant Timeout", 1, 0..20, 1, "How many ticks to wait until target box is in rotation scope"," ticks") {
vis() && !pingTimeout
}
}
12 changes: 12 additions & 0 deletions common/src/main/kotlin/com/lambda/event/events/InteractionEvent.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package com.lambda.event.events

import com.lambda.event.Event
import com.lambda.event.callback.Cancellable
import com.lambda.event.callback.ICancellable
import net.minecraft.client.world.ClientWorld
import net.minecraft.screen.ScreenHandler
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.util.hit.BlockHitResult

sealed class InteractionEvent : Event {
class Block(
val world: ClientWorld,
val blockHitResult: BlockHitResult
) : InteractionEvent()

data class SlotClick(
val syncId: Int,
val slot: Int,
val button: Int,
val action: SlotActionType,
val screenHandler: ScreenHandler,
) : ScreenHandlerEvent(), ICancellable by Cancellable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import net.minecraft.item.ItemStack
import net.minecraft.screen.ScreenHandler

sealed class ScreenHandlerEvent : Event {
class Open<H : ScreenHandler>(val screenHandler: H) : ScreenHandlerEvent()
class Close<H : ScreenHandler>(val screenHandler: H) : ScreenHandlerEvent()
data class Loaded(
class Open(val screenHandler: ScreenHandler) : ScreenHandlerEvent()
class Close(val screenHandler: ScreenHandler) : ScreenHandlerEvent()

data class Update(
val revision: Int,
val stacks: List<ItemStack>,
val cursorStack: ItemStack,
Expand Down
8 changes: 7 additions & 1 deletion common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.lambda.event.callback.ICancellable
import net.minecraft.block.BlockState
import net.minecraft.client.world.ClientWorld
import net.minecraft.entity.Entity
import net.minecraft.entity.data.TrackedData
import net.minecraft.util.math.BlockPos
import net.minecraft.world.chunk.WorldChunk

Expand Down Expand Up @@ -34,4 +35,9 @@ abstract class WorldEvent : Event {
class EntitySpawn(
val entity: Entity
) : WorldEvent(), ICancellable by Cancellable()
}

class EntityUpdate(
val entity: Entity,
val data: TrackedData<*>,
) : WorldEvent(), ICancellable by Cancellable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ abstract class BuildResult : ComparableResult<Rank> {
val distance: Double
) : Navigable, Drawable, BuildResult() {
override val rank = Rank.NOT_VISIBLE
private val color = Color(46, 0, 0, 30)
private val color = Color(46, 0, 0, 80)

override val goal = GoalPlace(blockPos)

override fun SafeContext.buildRenderer() {
withPos(blockPos, color, side)
withBox(Box(blockPos), color)
}

override fun compareTo(other: ComparableResult<Rank>): Int {
Expand Down Expand Up @@ -174,7 +174,7 @@ abstract class BuildResult : ComparableResult<Rank> {
neededItem.select().transfer(MainHandContainer)?.solve ?: failTask("Item ${neededItem.name.string} not found")

override fun SafeContext.buildRenderer() {
withPos(blockPos, color)
withBox(Box(blockPos), color)
}

override fun compareTo(other: ComparableResult<Rank>): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ object BuildSimulator {

val currentHandStack = player.getStackInHand(Hand.MAIN_HAND)
if (target is TargetState.Stack && !target.itemStack.equal(currentHandStack)) {
acc.add(BuildResult.WrongStack(pos, placeContext, target.copy))
acc.add(BuildResult.WrongStack(pos, placeContext, target.itemStack))
return@forEach
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sealed class TargetState : StateMatcher {
data class Support(val direction: Direction) : TargetState() {
override fun matches(state: BlockState, pos: BlockPos, world: ClientWorld) =
pos.offset(direction).blockState(world).isSolidBlock(world, pos.offset(direction))
|| pos.blockState(world).isSolidBlock(world, pos)
|| state.isSolidBlock(world, pos)

override fun getStack(world: ClientWorld, pos: BlockPos) =
ItemStack(Items.NETHERRACK) // ToDo: Find any disposable block
Expand All @@ -43,12 +43,12 @@ sealed class TargetState : StateMatcher {
block.getPickStack(world, pos, block.defaultState)
}
data class Stack(val itemStack: ItemStack) : TargetState() {
val copy: ItemStack = itemStack.copy()
private val block = itemStack.item.block

override fun matches(state: BlockState, pos: BlockPos, world: ClientWorld) =
state.block == copy.item.block
state.block == block

override fun getStack(world: ClientWorld, pos: BlockPos): ItemStack =
copy
itemStack
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ object ContainerManager : Loadable {
lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world)
}

listener<ScreenHandlerEvent.Close<ScreenHandler>> { event ->
// ToDo: ;-; i hate type erasure.
// The listener will be triggered for any H, not just GenericContainerScreenHandler
listener<ScreenHandlerEvent.Close> { event ->
if (event.screenHandler !is GenericContainerScreenHandler) return@listener

val handler = event.screenHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class ChestContainer(
// }

override fun withdraw(selection: StackSelection) =
openContainer<GenericContainerScreenHandler>(blockPos)
openContainer(blockPos)
// .withMaxAttempts(3)
// .withTimeout(20)
.onSuccess { open, screen ->
Expand All @@ -39,7 +39,7 @@ data class ChestContainer(
}

override fun deposit(selection: StackSelection) =
openContainer<GenericContainerScreenHandler>(blockPos)
openContainer(blockPos)
// .withMaxAttempts(3)
// .withTimeout(20)
.onSuccess { open, screen ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lambda.interaction.material.container

import com.lambda.Lambda.LOG
import com.lambda.context.SafeContext
import com.lambda.interaction.material.MaterialContainer
import com.lambda.interaction.material.StackSelection
Expand All @@ -11,7 +10,6 @@ import com.lambda.task.tasks.InventoryTask.Companion.withdraw
import com.lambda.task.tasks.OpenContainer.Companion.openContainer
import com.lambda.task.tasks.PlaceContainer.Companion.placeContainer
import net.minecraft.item.ItemStack
import net.minecraft.screen.ShulkerBoxScreenHandler

data class ShulkerBoxContainer(
override var stacks: List<ItemStack>,
Expand All @@ -27,10 +25,9 @@ data class ShulkerBoxContainer(
private val shulkerStack: ItemStack
) : Task<Unit>() {
override fun SafeContext.onStart() {
placeContainer(shulkerStack).thenRun { _, placePos ->
openContainer<ShulkerBoxScreenHandler>(placePos).thenRun { _, screen ->
LOG.info("Opened shulker box screen now withdrawing $selection.")
withdraw(screen, selection).thenRun { _, _ ->
placeContainer(shulkerStack).thenRun(this@Withdraw) { _, placePos ->
openContainer(placePos).thenRun(this@Withdraw) { _, screen ->
withdraw(screen, selection).thenRun(this@Withdraw) { _, _ ->
breakAndCollectBlock(placePos).onSuccess { _, _ ->
success(Unit)
}
Expand All @@ -47,9 +44,9 @@ data class ShulkerBoxContainer(
private val shulkerStack: ItemStack
) : Task<Unit>() {
override fun SafeContext.onStart() {
placeContainer(shulkerStack).thenRun { _, placePos ->
openContainer<ShulkerBoxScreenHandler>(placePos).thenRun { _, screen ->
deposit(screen, selection).thenRun { _, _ ->
placeContainer(shulkerStack).thenRun(this@Deposit) { _, placePos ->
openContainer(placePos).thenRun(this@Deposit) { _, screen ->
deposit(screen, selection).thenRun(this@Deposit) { _, _ ->
breakAndCollectBlock(placePos).onSuccess { _, _ ->
success(Unit)
}
Expand Down
Loading