Jump to content

[1.8] Catch when player swaps item to some Item - smooth.


Recommended Posts

Posted

Since like forever people been doing this kind of thing where "you are not allowed to use this item".

 

Now - everytime it was done (that I know of) the way was to use PlayerTickEvent or Item#onUpdate() and check if item is current item and if so - move it to other slot, because "you can't use it".

 

Question arises - is there other more "right now" way when executing code (changing the current slot).

 

Whenever, whoever makes some IInventory - it's clear and you can use isItemValid or some other stuff, you can't really do that in vanilla. Is there a hook somewhere?

 

I can deal with ticks, but just asking for yes or no (or something else?).

 

EDIT

By "right now" I ment that you don't use tick-checks, which would avoid e.g constatly checking NBT or other stuff.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Maybe you can handle the clicking on the hotbar and related input / keybind ect. that are used when player wants to put something in the hand?

You certainly can, sort of - I do this while one of the sword skills is active to prevent changing the current item.

 

MouseEvent has a field called 'dwheel' which indicates whether the mouse wheel is in use (+/- for up/down scrolling, zero for no input). You will also need to check the number keys using KeyInputEvent for direct changes.

 

I haven't tried it within a GUI screen, but as long as both of those events are fired, you could probably rig up something. Checking if the open GUI is a GuiContainer, for example, and then casting would probably allow you to figure out what the current slot clicked / item is.

 

Honestly, though, and contrary to what I usually try to promote, I think the ticking solutions are the better solution here. There are just so many ways that an item can get into a player's hotbar slot (picking up, shift-click, manually via direct inventory manipulation in code, etc.), that you can't possibly cover them all unless you actually check the slots involved and what they currently contain.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.