Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.