#Prevent hotbar slots being selected?

40 messages · Page 1 of 1 (latest)

dry star
#

I want to make it not possible to scroll to (or what ever the keybind is for someone) or number key swap to certain slots.
I been looking for a forgeevent but i cant seem to find one sadly. No such "selected slot change"?

pure micaBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

dry star
#

I have the mouse scroll event, but for some strange reason theres no data about the hotbar

#

and given the nature of when that even is called you would think thats what it would def have

errant blaze
#
event.player.selectedSlot```
#

also js event.player.setSelectedSlot(1)

dry star
#

does the event really have a player key on it? 😮

errant blaze
#

if it doesnt then youll just do js Client.player since they're both client sided

#

shouldnt be an issue

#

on the other hand you dont even need these events if you detect which slot is selected and if its a certain slot you set it to another one

#

in player tick event

dry star
#

Never heard of Client before, ty! 😮
Last thing, how do i safeguard the keypressed events? Seems risky as the hotbar keys can be changed

#

Always been nervous of doing player tick

#

Its a place for good efficient code, which i am not

errant blaze
#

eh its not bad if you dont do weird/expensive things

#

everything runs on tick constantly, you detecting the selected slot and setting it to something else is nothing

#
PlayerEvents.tick(event => {
    if (event.player.selectedSlot == 1) {
        event.player.setSelectedSlot(2)
    }
})```
#

that being said not sure how well thisll work but you can try it^

dry star
#

Well i attempted to implement it, but i think i did it weirdly xD

PlayerEvents.tick(event => {
    if (event.player.stages.has('locked_hotbar'))
    {
        let currentSlot = event.player.selectedSlot
        let lastKnownSlot = event.player.persistentData.slot
        if (currentSlot != lastKnownSlot)
        {
            if (event.player.mainHandItem.hasTag("kubejs:slot"))
                event.player.setSelectedSlot(lastKnownSlot)
            else
                event.player.persistentData.slot = currentSlot
        }
    }
});
#

Appears to work and i tried to make a early exit, not sure how well or expensive it is, but it seems to slightly fail if the user scrolls quickly

#

ooh maybe i can do a mix of both ways 😮

errant blaze
#

😮

dry star
#

going a bit horrible atm but im close i hope XD

errant blaze
#

if you're looking to lock the hotbar then maybe you dont even need a last known slot, just constantly set it to one of the slots

#

another fix would be to basically only update the currentslot once a second so spamming scroll wheel wont matter

#

well, i guess at that point you'd just want to cancel the scroll event anyways hmmm

dry star
#

Small issue in the scrollevent Client.player.getItemBySlot(nextSlot) this crashes when it runs when the hotbar selected is above 5.
7 is not a valid enum index! Valid values are: 0 - 5

#

Im not entirely sure what 0-5 means here

dry star
#

@errant blaze
I got the scrolling script working! 😄

ForgeEvents.onEvent("net.minecraftforge.client.event.InputEvent$MouseScrollingEvent", event => {
    // Utils.server.tell(event.scrollDelta)
    // event.
    Utils.server.tell(`Current Slot: ${Client.player.selectedSlot}, Current Item: ${Client.player.mainHandItem.id}`)
    let nextSlot = Client.player.selectedSlot;
    let nextSlotLocked = true;

    do {
        if (event.scrollDelta < 0)
        {
            if (nextSlot<8) nextSlot+=1
            else nextSlot=0
        }
        else
        {
            if (nextSlot == 0) nextSlot=8
            else nextSlot-=1
        }
        Client.player.setSelectedSlot(nextSlot)
        nextSlotLocked = Client.player.mainHandItem.hasTag("kubejs:slot");
        // nextSlotlocked = false
    }
    while (nextSlotLocked);
    event.setCanceled(true);
})

Thanks for the help!

#

Tho before closing i am curious what your thoughts are on this.
My first solution i checked for game stage and persistentdata every tick pretty much.
How is this in compaison?
Only downside is no shortcut fixes, tho if they do number key to a locked slot, when they scroll theyll be snapped right to the next unlocked in the direction of the scroll(yes infinite loop if filled locked)

errant blaze
#

so why not do the same in the key pressed event?

#

detect if the key is hotbar slot key and if so cancel it, should also cancel if they are inside their inventory and hover over one of the hotbar slots and press it ect

dry star
#

wait...i can detect if its the key for the hotbar being pressed?
I dont have to hardcode 1,2,3,4,5,6,7,8,9?

#

Also im sort of curious, what should i do to make sure a player can pick up these items by clicking on them?
I disabled tool tips, now this, it seems sort of pointless if they can still move them around you know?

errant blaze
errant blaze
dry star
#

i seen that earlier, maybe i can dig around that more. Seems to be more general screen stuff rather specific slot infomation

errant blaze
dry star
#

Nearly done 😄
For some reason tho it doesnt respond the same to shift clicks
Ty for all the help so far Liopyu!