Skip to content

Commit c2f2ec1

Browse files
committed
player.mainHandStack and, in theory, all other references to the players selected slot / stack will return the hotbar managers selection if there's an active request. This is different compared to the way it worked in 1.20.4 as previously it only altered the interaction managers selected slot
1 parent eedafd9 commit c2f2ec1

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 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.mixin.entity;
19+
20+
import com.lambda.interaction.request.hotbar.HotbarManager;
21+
import com.lambda.interaction.request.hotbar.HotbarRequest;
22+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
23+
import net.minecraft.entity.player.PlayerInventory;
24+
import org.objectweb.asm.Opcodes;
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
30+
@Mixin(PlayerInventory.class)
31+
public class PlayerInventoryMixin {
32+
@SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"})
33+
@ModifyExpressionValue(method = "*", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerInventory;selectedSlot:I", opcode = Opcodes.GETFIELD))
34+
private int modifySelectedSlot(int original) {
35+
final HotbarRequest hotbarRequest = HotbarManager.INSTANCE.getActiveRequest();
36+
if (hotbarRequest == null) return original;
37+
return hotbarRequest.getSlot();
38+
}
39+
40+
@Inject(method = "getSelectedSlot", at = @At("HEAD"), cancellable = true)
41+
private void redirectGetSelectedSlot(CallbackInfoReturnable<Integer> cir) {
42+
final HotbarRequest hotbarRequest = HotbarManager.INSTANCE.getActiveRequest();
43+
if (hotbarRequest == null) return;
44+
cir.setReturnValue(hotbarRequest.getSlot());
45+
}
46+
}

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import com.lambda.interaction.request.breaking.BrokenBlockHandler.destroyBlock
6262
import com.lambda.interaction.request.breaking.BrokenBlockHandler.pendingActions
6363
import com.lambda.interaction.request.breaking.BrokenBlockHandler.setPendingConfigs
6464
import com.lambda.interaction.request.breaking.BrokenBlockHandler.startPending
65-
import com.lambda.interaction.request.hotbar.HotbarManager
6665
import com.lambda.interaction.request.interacting.InteractionManager
6766
import com.lambda.interaction.request.placing.PlaceManager
6867
import com.lambda.interaction.request.rotating.RotationRequest
@@ -304,7 +303,7 @@ object BreakManager : RequestHandler<BreakRequest>(
304303
it.couldReBreak.update()
305304
it.shouldProgress = !it.progressedThisTick &&
306305
tickStage in it.breakConfig.breakStageMask &&
307-
rotated || !it.isPrimary
306+
(rotated || !it.isPrimary)
308307
}
309308
}
310309
.also {
@@ -817,7 +816,7 @@ object BreakManager : RequestHandler<BreakRequest>(
817816
config: BreakConfig,
818817
item: ItemStack? = null
819818
) = runSafe {
820-
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.inventory.getStack(HotbarManager.serverSlot))
819+
val delta = calcItemBlockBreakingDelta(player, world, pos, item ?: player.mainHandStack)
821820
//ToDo: This setting requires some fixes / improvements in the player movement prediction to work properly. Currently, it's broken
822821
// if (config.desyncFix) {
823822
// val nextTickPrediction = buildPlayerPrediction().next()

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.request.hotbar
2020
import com.lambda.context.SafeContext
2121
import com.lambda.event.Event
2222
import com.lambda.event.EventFlow.post
23-
import com.lambda.event.events.InventoryEvent
2423
import com.lambda.event.events.TickEvent
2524
import com.lambda.event.events.UpdateManagerEvent
2625
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -45,7 +44,7 @@ object HotbarManager : RequestHandler<HotbarRequest>(
4544
private var maxSwapsThisTick = 0
4645
private var swapDelay = 0
4746

48-
private var activeRequest: HotbarRequest? = null
47+
var activeRequest: HotbarRequest? = null
4948

5049
override fun load(): String {
5150
super.load()
@@ -60,10 +59,6 @@ object HotbarManager : RequestHandler<HotbarRequest>(
6059
activeInfo.keepTicks--
6160
}
6261

63-
listen<InventoryEvent.HotbarSlot.Update>(priority = Int.MIN_VALUE) {
64-
it.slot = activeRequest?.slot ?: return@listen
65-
}
66-
6762
return "Loaded Hotbar Manager"
6863
}
6964

src/main/resources/lambda.mixins.common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"entity.FireworkRocketEntityMixin",
1616
"entity.LivingEntityMixin",
1717
"entity.PlayerEntityMixin",
18+
"entity.PlayerInventoryMixin",
1819
"input.KeyBindingMixin",
1920
"input.KeyboardMixin",
2021
"input.MouseMixin",

0 commit comments

Comments
 (0)