Refactor CarryOn functionality to improve slot selection logic. Ensure that inventory slot changes are only allowed when not carrying an item.
This commit is contained in:
parent
ece3ed7ff2
commit
c4346a4c00
|
|
@ -52,14 +52,16 @@ public class CarryOnCommonClient
|
|||
return (CarryOnKeybinds.carryKey.matchesMouse(0) && mc.mouseHandler.isLeftPressed()) || (CarryOnKeybinds.carryKey.matchesMouse(1) && mc.mouseHandler.isRightPressed()) || (CarryOnKeybinds.carryKey.matchesMouse(3) && mc.mouseHandler.isMiddlePressed());
|
||||
}
|
||||
|
||||
public static void onCarryClientTick()
|
||||
{
|
||||
public static void onCarryClientTick() {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if(player != null) {
|
||||
if (player != null) {
|
||||
CarryOnData carry = CarryOnDataManager.getCarryData(player);
|
||||
if(carry.isCarrying())
|
||||
{
|
||||
player.getInventory().setSelectedSlot(carry.getSelected());
|
||||
if (carry.isCarrying()) {
|
||||
int wantedSlot = carry.getSelected();
|
||||
if (player.getInventory().getSelectedSlot() != wantedSlot) {
|
||||
// System.out.println("[CarryOn] Forcing slot " + wantedSlot);
|
||||
player.getInventory().setSelectedSlot(wantedSlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,11 +29,30 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
import tschipp.carryon.common.carry.CarryOnDataManager;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin
|
||||
{
|
||||
@WrapWithCondition(method = "handleKeybinds()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;setSelectedSlot(I)V", ordinal = 0))
|
||||
private boolean allowSlotSelection(Inventory inv,int slot)
|
||||
{
|
||||
return !CarryOnDataManager.getCarryData(inv.player).isCarrying();
|
||||
}
|
||||
public class MinecraftMixin {
|
||||
|
||||
@WrapWithCondition(
|
||||
method = "handleKeybinds()V",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/player/Inventory;setSelectedSlot(I)V",
|
||||
ordinal = 0
|
||||
)
|
||||
)
|
||||
private boolean allowSlotSelection(Inventory inv, int slot) {
|
||||
boolean carrying = CarryOnDataManager.getCarryData(inv.player).isCarrying();
|
||||
|
||||
// Allow if not carrying
|
||||
if (!carrying) return true;
|
||||
|
||||
// Block only if trying to switch away
|
||||
boolean allow = inv.getSelectedSlot() == slot;
|
||||
|
||||
if (!allow) {
|
||||
// System.out.println("[CarryOn] Blocked hotbar change while carrying. Tried " + slot + ", staying on " + inv.getSelectedSlot());
|
||||
}
|
||||
|
||||
return allow;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user