Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -57,7 +57,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 @@ -67,7 +67,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 @@ -8,6 +8,7 @@
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.Entity;
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 Down Expand Up @@ -37,6 +38,13 @@ public void interactBlockHead(final ClientPlayerEntity player, final Hand hand,
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();
}

@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) {
if (EventFlow.post(new AttackEvent.Pre(target)).isCanceled()) ci.cancel();
Expand Down
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));
}
}
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/command/LambdaCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class LambdaCommand(
// ToDo: Include usage and description in the help command
init {
(listOf(name) + aliases).forEach {
val argument = LiteralArgumentBuilder.literal<CommandSource>(it)
val argument = LiteralArgumentBuilder.literal<CommandSource>(it.lowercase())
argument.create()
dispatcher.register(argument)
}
Expand Down
47 changes: 47 additions & 0 deletions common/src/main/kotlin/com/lambda/command/commands/BuildCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.interaction.construction.Blueprint.Companion.toStructure
import com.lambda.interaction.construction.DynamicBlueprint.Companion.toBlueprint
import com.lambda.interaction.construction.verify.TargetState
import com.lambda.task.tasks.BuildTask.Companion.build
import com.lambda.threading.runSafe
import com.lambda.util.extension.CommandBuilder
import net.minecraft.block.Blocks
import net.minecraft.util.math.BlockBox

object BuildCommand : LambdaCommand(
name = "Build",
description = "Builds a structure",
usage = "build <structure>"
) {
override fun CommandBuilder.create() {
required(literal("place")) {
execute {
runSafe {
val materials = setOf(
TargetState.Block(Blocks.NETHERRACK),
TargetState.Block(Blocks.AIR),
TargetState.Block(Blocks.COBBLESTONE),
TargetState.Block(Blocks.AIR),
)
val facing = player.horizontalFacing
val pos = player.blockPos.add(facing.vector.multiply(2))

BlockBox.create(pos, pos.add(facing.rotateYClockwise().vector.multiply(3)))
.toStructure(TargetState.Block(Blocks.NETHERRACK))
.toBlueprint {
it.mapValues { (_, _) ->
materials.elementAt((System.currentTimeMillis() / 5000).toInt() % materials.size)
}
}
.build(finishOnDone = false)
.start(null)
}
}
}
}
}
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.extension.CommandBuilder

object TaskCommand : LambdaCommand(
name = "task",
usage = "task <cancel>",
description = "Control tasks"
) {
override fun CommandBuilder.create() {
required(literal("cancel")) {
execute {
this@TaskCommand.info("Cancelling all tasks")
RootTask.cancel()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object TransferCommand : LambdaCommand(
usage = "transfer <move|cancel|undo> <item> <amount> <to>",
description = "Transfer items from anywhere to anywhere",
) {
private var lastTransfer: TransferResult.Success? = null
private var lastTransfer: TransferResult.Transfer? = null

override fun CommandBuilder.create() {
required(itemStack("stack", registry)) { stack ->
Expand Down Expand Up @@ -61,10 +61,10 @@ object TransferCommand : LambdaCommand(
} ?: return@executeWithResult failure("To container not found")

when (val result = fromContainer.transfer(selection, toContainer)) {
is TransferResult.Success -> {
is TransferResult.Transfer -> {
info("$result started.")
lastTransfer = result
result.solve.onSuccess { _, _ ->
result.onSuccess { _, _ ->
info("$lastTransfer completed.")
}.start(null)
return@executeWithResult success()
Expand All @@ -86,23 +86,13 @@ object TransferCommand : LambdaCommand(

required(literal("cancel")) {
executeWithResult {
lastTransfer?.solve?.cancel() ?: run {
lastTransfer?.cancel() ?: run {
return@executeWithResult failure("No transfer to cancel")
}
info("$lastTransfer cancelled")
lastTransfer = null
success()
}
}

required(literal("undo")) {
executeWithResult {
lastTransfer?.undo ?: run {
return@executeWithResult failure("No transfer to undo")
}
info("Undoing $lastTransfer")
success()
}
}
}
}
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
}
14 changes: 6 additions & 8 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 rotateForBreak by c.setting("Rotate For Break", true, "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,14 +1,22 @@
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(
c: Configurable,
defaultReach: Double = 4.9,
defaultReach: Double = 4.6,
vis: () -> Boolean = { true },
) : InteractionConfig {
override val reach by c.setting("Reach", defaultReach, 0.1..10.0, 0.1, "Players reach / range", " blocks", vis)
override val useRayCast by c.setting("Raycast", true, "Verify hit vector with ray casting (for very strict ACs)", vis)
override val resolution by c.setting("Resolution", 20, 1..40, 1, "How many raycast checks per surface (will be squared)") { vis() && useRayCast }
override val resolution by c.setting("Resolution", 4, 1..40, 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 after target box is in rotation scope"," ticks") {
vis() && !pingTimeout
}
}
10 changes: 10 additions & 0 deletions common/src/main/kotlin/com/lambda/event/events/InteractionEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
Expand Down Expand Up @@ -39,4 +41,12 @@ sealed class InteractionEvent : Event {
val progress: Float,
) : BreakingProgress()
}

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.util.shape.VoxelShape
import net.minecraft.world.chunk.WorldChunk
Expand Down Expand Up @@ -36,5 +37,10 @@ abstract class WorldEvent : Event {
val entity: Entity
) : WorldEvent(), ICancellable by Cancellable()

class EntityUpdate(
val entity: Entity,
val data: TrackedData<*>,
) : WorldEvent(), ICancellable by Cancellable()

class Collision(val pos: BlockPos, val state: BlockState, var shape: VoxelShape) : WorldEvent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class Blueprint {
}

companion object {
fun emptyStructure(): Structure = emptyMap()

fun Box.toStructure(targetState: TargetState): Structure =
BlockPos.stream(this)
.map { it.blockPos }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ data class DynamicBlueprint(
}.toMap()
}

fun blueprintOnTick(
init: SafeContext.(Structure) -> Structure = { emptyMap() },
onTick: SafeContext.(Structure) -> Structure
) = DynamicBlueprint(init = init, update = onTick)

fun Structure.toBlueprint(
init: SafeContext.(Structure) -> Structure = { this@toBlueprint },
onTick: SafeContext.(Structure) -> Structure
) = DynamicBlueprint(init = { emptyMap() }, update = onTick)
) = DynamicBlueprint(init = init, update = onTick)
}
}

This file was deleted.

Loading