#Prevent hotbar slots being selected?
40 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Cancellable scroll forge event: https://lexxie.dev/forge/1.20.1/net/minecraftforge/client/event/InputEvent.MouseScrollingEvent.html|
Cancellable key pressed forge event:https://lexxie.dev/forge/1.20.1/net/minecraftforge/client/event/ScreenEvent.KeyPressed.Pre.html
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
does the event really have a player key on it? 😮
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
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
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^
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 😮
😮
going a bit horrible atm but im close i hope XD
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 
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
@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)
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
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?
you should be able to i believe
theres an event for that too lol https://lexxie.dev/forge/1.20.1/net/minecraftforge/client/event/ScreenEvent.MouseButtonPressed.Pre.html
declaration: package: net.minecraftforge.client.event, class: ScreenEvent, class: MouseButtonPressed, class: Pre
i seen that earlier, maybe i can dig around that more. Seems to be more general screen stuff rather specific slot infomation
you could maybe try this then though idk if it fires for air, youll have to test it, i believe its cancellable to where the item wont be swapped if so https://lexxie.dev/forge/1.20.1/net/minecraftforge/event/ItemStackedOnOtherEvent.html#getClickAction()
declaration: package: net.minecraftforge.event, class: ItemStackedOnOtherEvent
Nearly done 😄
For some reason tho it doesnt respond the same to shift clicks
Ty for all the help so far Liopyu!