Jump to content

Setting held item slot to custom slot?


IdrisQe

Recommended Posts

I started work on a mod, I want to make an extra "empty hand" slot which can be switched to with a hotkey. Before I put in the legwork to actually make the slot and get it working, I'd first like to know if it's even possible to manually set the player's selected slot to one other than the hotbar slots... I mean, I know it's possible with a coremod that changes every reference to the hotbar to be a higher number, but I mean without messing with Vanilla code too much.
I don't need it to be able to hold items, in fact I want the opposite. Just a slot that's perpetually empty which you can switch to and from with a key press. No special scrollwheel selection functionality or anything, no special rendering (aside from the empty hand but considering the slot is empty that should happen automatically). But to do that, I need to be able to set the player's selected slot to something else.

All the information I can find on the subject on these forums, or anywhere, was vague and for waaay earlier versions, so I'd like a clear yes or no (preferably with some reasoning if no, or at least some hints on how I would go about it if yes)
 

I suppose I don't necessarily need to set the selected slot to something else if there's a way to trick the game into thinking the player isn't holding anything?
But that sounds somehow actually less compatible and like it would be even more of a pain to code, and isn't the topic of this post. (Although if there's a way to do that I'd be fine with hearing that too)

Link to comment
Share on other sites

So to clarify, you want the player to have a constantly empty 3rd hand that only appears in the in game GUI that can be switched to with a key press?

do you want this slot to act as a HAND or as a constantly empty inventory slot. (By hand I mean do you want getActiveHand to be able to return your slot & should getActiveItemStack return what’s in your slot)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

I just kinda mean a permanently-empty slot that can be switched to with a hotkey. Doesn't even need to appear, I just want the ability to have an empty hand even with a full hotbar. So basically, anything that requires interaction with an empty hand would work because there's nothing in the slot, but the slot can't pick up any items either. I guess getActiveItemStack would always return... either null or air, I'm not sure which it returns on an empty slot. and I don't think I'd need getActiveHand to returm the slot, since the slot can't be interacted with. All I want is the no-item-held functionality that an empty hotbar slot would have.

Link to comment
Share on other sites

What do you want to show up ingame? If your “in” this slot do you want both held items to still be rendered? (If so how would you know that you were “in” your slot?) can you explain what you want to happen from an end-user perspective? (What you want to happen, not how your planning on coding it). If you just want to have the player have a slot that they can toggle on or off with a keybind, just make a capability that stores if the player has the toggled the slot on or not and subscribe to/override (idk if there’s an event for it yet) getActiveItemStack and if your capability says you should return ItemStack.EMPTY. If you want you can also cancel the rendering for the held itemstacks in both hands

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

11 minutes ago, Cadiboo said:

getActiveItemStack and if your capability says you should return ItemStack.EMPTY. If you want you can also cancel the rendering for the held itemstacks in both hands

OR you could just switch the active itemstack and the new custom slot. 

 

@IdrisQe Your goal can't be achieved through normal means.

  • Like 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

6 minutes ago, Animefan8888 said:

OR you could just switch the active itemstack and the new custom slot. 

That’s a much better solution then mine. However, because the slot won’t appear in any GUI it will appear that the item has just disappeared. Also when you switch the stacks the player will be able to pick up items in their active hand.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

What do you want to show up ingame? If your “in” this slot do you want both held items to still be rendered? (If so how would you know that you were “in” your slot?) can you explain what you want to happen from an end-user perspective? (What you want to happen, not how your planning on coding it). If you just want to have the player have a slot that they can toggle on or off with a keybind, just make a capability that stores if the player has the toggled the slot on or not and subscribe to/override (idk if there’s an event for it yet) getActiveItemStack and if your capability says you should return ItemStack.EMPTY. If you want you can also cancel the rendering for the held itemstacks in both hands

Ingame, I just want the hand to be rendered like if you had an empty slot selected. What I intend, pretty much, is that a user can press a key to empty their hands even if they have a full hotbar, without removing any item from the hotbar. The slot isn't visible or anything, and cannot pick up items, it just functions like a completely empty hotbar slot. Scrolling or pressing a hotbar key or repressing the keybind would let you go back to the item you were holding beforehand.
 

 

1 hour ago, Animefan8888 said:

OR you could just switch the active itemstack and the new custom slot. 

 

@IdrisQe Your goal can't be achieved through normal means.

A mod already does that. https://minecraft.curseforge.com/projects/empty-hand

The thing is, the way that's implemented, once you empty your hands, the items are stored away and your hotbar slot instead becomes empty, allowing anything to fill it back up. In that case, you then need to store those items somewhere, and manually, since pressing the keybind will just swap the already-stored items for the ones now occupying that slot. May seem just like a minor inconvienience, but it can be a real nuisance if you're playing with something like The Monk Mod which encourages you to keep your hands free, since items go into your hotbar before entering your inventory, your hotbar will constantly fill up with stuff.
 

1 hour ago, Cadiboo said:

That’s a much better solution then mine. However, because the slot won’t appear in any GUI it will appear that the item has just disappeared. Also when you switch the stacks the player will be able to pick up items in their active hand.

The mod linked above renders the items off to the side still, and explains how it functions when you first use it to get around the "disappearing" problem. But yeah, the latter part is exactly what I want to avoid.

Link to comment
Share on other sites

I was thinking that you should swap the ItemStacks and intercept calls to stuff like canAddItemStackToInventory & canFitStackInSlot for the hand slot.

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

You could probably do something to prevent a specific slot from taking items whenever the toggle is on. You'd have to implement EntityItemPickupEvent to prevent items from going from the ground into that slot. It would be trickier to prevent the player from manually putting anything in that slot, or from shift-clicking things into it. That might take a PlayerTickEvent that continually checks for changes to the slot and reverses them.

Link to comment
Share on other sites

Hmm... Isn't there a way to specify what things can be put in a slot? Like how armor slots only accept armor of the matching type. I can't imagine they constantly check and reverse changes. So if I just set the slot to not fit any type of item, wouldn't that work? Maybe with occasional checks to make sure items haven't bugged out and gotten into the slot, and if they have, then just drop them automatically.

 

Mmm... To be honest I'm probably biting off way more than I can chew given my lack of experience with Java. I might just save this project for another time, once I've gotten a better hold on the fundamentals.

Link to comment
Share on other sites

16 hours ago, IdrisQe said:

Isn't there a way to specify what things can be put in a slot? Like how armor slots only accept armor of the matching type. I can't imagine they constantly check and reverse changes. So if I just set the slot to not fit any type of item, wouldn't that work? Maybe with occasional checks to make sure items haven't bugged out and gotten into the slot, and if they have, then just drop them automatically.

Yes there is, but your not doing this to your own slot, you own slot is holding the item that was in your ActiveHand, and your having to do all this stuff to the active hand slot which isn’t directly controlled by you

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

10 hours ago, Cadiboo said:

Yes there is, but your not doing this to your own slot, you own slot is holding the item that was in your ActiveHand, and your having to do all this stuff to the active hand slot which isn’t directly controlled by you

Uh... Okay admittedly now I'm a bit confused. I take it you mean if I use the system that the mod I linked uses?

It doesn't really matter either way though. As I said, I'm probably not going to go through with this anytime soon, since I don't have the skill required yet.

Link to comment
Share on other sites

On 10/3/2018 at 10:13 AM, Animefan8888 said:

you could just switch the active itemstack and the new custom slot. 

I’m going off this comment which you agreed with, This isn’t an easy thing to do & there’s many ways in which you could implement it.

If your still thinking of attempting it I think that this is the most straightforward solution.

- Have a custom slot

- Have a capability (shouldActiveHandBeEmpty? isActiveHandEmpty?)

- Enable/Disable your capability with a keybind

- In the player tick event check if the hand should be empty.

If it should be empty try and move the active stack to the custom slot. If you can’t do this, try and move the active stack somewhere else in the inventory. If you can’t move it drop it.

If it should not be empty see if there is anything in your custom slot. If there is try and move the custom slot stack to the active stack. If the active stack isn’t empty try and move one of the stacks somewhere else in the inventory or drop it.

Heres some code. For readability I’ve turned if(!isEmpty){do stuff} into if(isEmpty){} else {do stuff}

(Written on mobile so I can’t put it into spoiler or code tags, I hope I got the formatting right)

if (ActiveStackShouldBeEmptyCapability.shouldBeEmpty()) {

  if (activeHandHeldStack.isEmpty()) {

    // nothing to do here, you can return - everything’s going smoothly

  } else {

    if (customSlot.isEmpty()) {

      //transfer active stack to custom slot

    } else {

      //drop active stack OR drop custom slot stack and move active stack into custom slot 

    }

  }

} else { // hand should not be empty

  if (customSlot.isEmpty()) {

    // nothing to do here, you can return - everything’s going smoothly

  } else {

    if (activeStack.isEmpty()) {

    //transfer custom slot stack to active stack

    } else {

      //drop active stack and move custom slot stack into active stack slot OR drop custom slot stack

    }

  }

}

    

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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.