Skip to content

Commit 982d692

Browse files
committed
Add hotbar spoof test and fix dsync issues
1 parent d9c6a8b commit 982d692

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

common/src/main/java/com/lambda/mixin/entity/PlayerInventoryMixin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717

1818
package com.lambda.mixin.entity;
1919

20+
import net.minecraft.block.BlockState;
2021
import net.minecraft.client.MinecraftClient;
2122
import net.minecraft.client.network.ClientPlayerInteractionManager;
23+
import net.minecraft.entity.player.PlayerEntity;
2224
import net.minecraft.entity.player.PlayerInventory;
2325
import net.minecraft.item.ItemStack;
26+
import org.spongepowered.asm.mixin.Final;
2427
import org.spongepowered.asm.mixin.Mixin;
28+
import org.spongepowered.asm.mixin.Shadow;
2529
import org.spongepowered.asm.mixin.injection.At;
2630
import org.spongepowered.asm.mixin.injection.Inject;
2731
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@@ -30,6 +34,8 @@
3034

3135
@Mixin(PlayerInventory.class)
3236
public class PlayerInventoryMixin {
37+
@Shadow @Final public PlayerEntity player;
38+
3339
@Inject(method = "getMainHandStack", at = @At(value = "HEAD"), cancellable = true)
3440
public void handleSpoofedMainHandStack(CallbackInfoReturnable<ItemStack> cir) {
3541
PlayerInventory instance = (PlayerInventory) (Object) this;
@@ -44,4 +50,9 @@ public void handleSpoofedMainHandStack(CallbackInfoReturnable<ItemStack> cir) {
4450
isValidHotbarIndex(actualSlot) ? instance.main.get(actualSlot) : ItemStack.EMPTY
4551
);
4652
}
53+
54+
@Inject(method = "getBlockBreakingSpeed", at = @At(value = "HEAD"), cancellable = true)
55+
public void handleSpoofedBlockBreakingSpeed(BlockState block, CallbackInfoReturnable<Float> cir) {
56+
cir.setReturnValue(player.getMainHandStack().getMiningSpeedMultiplier(block));
57+
}
4758
}

common/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ data class BreakContext(
8383
}
8484

8585
fun getBlockBreakingProgress(breakingTicks: Int, player: PlayerEntity, world: BlockView): Int {
86-
val currentItemStack = HotbarManager.mainHandStack ?: return -1
86+
val currentItemStack = player.mainHandStack ?: return -1
8787
val breakDelta = checkedState.calcItemBlockBreakingDelta(player, world, expectedPos, currentItemStack)
8888
val progress = breakDelta * breakingTicks
8989
return if (progress > 0.0f)

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ import com.lambda.util.player.SlotUtils.hotbar
2828
object HotbarManager : RequestHandler<HotbarRequest>(), Loadable {
2929
val serverSlot get() = runSafe {
3030
interaction.lastSelectedSlot
31-
} ?: -1
32-
val mainHandStack get() = runSafe {
33-
player.hotbar.getOrNull(serverSlot - 1)
34-
}
31+
} ?: 0
3532

3633
override fun load() = "Loaded Hotbar Manager"
3734

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.debug
19+
20+
import com.lambda.config.groups.HotbarSettings
21+
import com.lambda.event.events.PlayerEvent
22+
import com.lambda.event.events.RenderEvent
23+
import com.lambda.event.events.WorldEvent
24+
import com.lambda.event.listener.SafeListener.Companion.listen
25+
import com.lambda.graphics.renderer.esp.builders.ofBox
26+
import com.lambda.interaction.request.hotbar.HotbarRequest
27+
import com.lambda.module.Module
28+
import com.lambda.module.tag.ModuleTag
29+
import com.lambda.util.Communication.info
30+
import com.lambda.util.world.blockSearch
31+
import net.minecraft.block.Blocks
32+
import net.minecraft.util.math.Vec3i
33+
import java.awt.Color
34+
35+
object SilentSwap : Module(
36+
name = "SilentSwap",
37+
description = "SilentSwap",
38+
defaultTags = setOf(ModuleTag.DEBUG),
39+
) {
40+
private val hotbar = HotbarSettings(this)
41+
42+
init {
43+
listen<PlayerEvent.Attack.Block> {
44+
if (!hotbar.request(HotbarRequest(0)).done) {
45+
it.cancel()
46+
return@listen
47+
}
48+
info("${interaction.lastSelectedSlot} ${player.mainHandStack}")
49+
}
50+
}
51+
}

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class BuildTask @Ta5kBuilder constructor(
103103

104104
init {
105105
listen<TickEvent.Pre> {
106-
val currentItemStack = HotbarManager.mainHandStack ?: return@listen
106+
val currentItemStack = player.mainHandStack ?: return@listen
107107

108108
currentInteraction?.let { context ->
109109
// TaskFlowModule.drawables = listOf(context)
@@ -389,7 +389,7 @@ class BuildTask @Ta5kBuilder constructor(
389389
private fun SafeContext.breakBlock(ctx: BreakContext): Boolean {
390390
if (player.isBlockBreakingRestricted(world, ctx.expectedPos, interaction.currentGameMode)) return false
391391

392-
if (HotbarManager.mainHandStack?.item?.canMine(ctx.checkedState, world, ctx.expectedPos, player) == false)
392+
if (!player.mainHandStack.item.canMine(ctx.checkedState, world, ctx.expectedPos, player))
393393
return false
394394
val block = ctx.checkedState.block
395395
if (block is OperatorBlock && !player.isCreativeLevelTwoOp) return false
@@ -441,9 +441,8 @@ class BuildTask @Ta5kBuilder constructor(
441441
blockState.onBlockBreakStart(world, ctx.expectedPos, player)
442442
}
443443

444-
val currentItemStack = HotbarManager.mainHandStack ?: return false
445-
446-
if (notAir && blockState.calcItemBlockBreakingDelta(player, world, ctx.expectedPos, currentItemStack) >= build.breakThreshold) {
444+
val breakingDelta = blockState.calcItemBlockBreakingDelta(player, world, ctx.expectedPos, player.mainHandStack)
445+
if (notAir && breakingDelta >= build.breakThreshold) {
447446
onBlockBreak(ctx)
448447
return true
449448
} else {

0 commit comments

Comments
 (0)