Jump to content

Request for on how to update the players inventory.


jangofett890

Recommended Posts

So ive been searching everywhere looking for how to let the server know when you update your inventory such as

 ModLoader.getMinecraftInstance().thePlayer.inventory.setInventorySlotContents(var2, new ItemStack(ITEM.shiftedIndex,1,0));   
                      		

but i havent found out how. i know it requires packets though which ive never had to use in minecraft mod before so im sorta confused ive followed a packet tutorial but i still didnt get it so would someone tell me/create a guide on letting the server know if you inventory is changed? thanks in advanced.

 

 

-Jango

Link to comment
Share on other sites

Could you tell us where you call this kind of code? In a GUI, in an entity (interact(...) method), whatever... Maybe it's not even necessary to send packets.

Also don't use ModLoader stuff anymore. In your example, you can get theMinecraft instance with Minecraft.getMinecraft() instead of ModLoader.getMinecraftInstance() (warning: don't use these in classes which are supposed to be in the server, too!)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Its in a keybind a ModLoader one i find that Forge keybinds are verry over complicated so this is what im using

   public void keyboardEvent(KeyBinding var1)
    {
            if (var1.isPressed() && var1.keyCode == 19)
            {
                    int var2 = ModLoader.getMinecraftInstance().thePlayer.inventory.currentItem;
                    ItemStack var3 = ModLoader.getMinecraftInstance().thePlayer.inventory.getStackInSlot(var2);
                    
                    
                    if (var3 == null)
                    {
                     return;
                    }
                    
                    if (var3.itemID == mod_jangostarwars.LightSaberOFF.shiftedIndex)
                     {
                    
                     sabersound.sndManager.playSoundFX("LightSaberSound.LightSaberOnSound", 1.0F, 1.0F);
                     
                     		if(var3.itemID == mod_jangostarwars.LightSaberOFF.shiftedIndex && var3.getItemDamage() == 0)  
                      		{
                     			Minecraft.getMinecraft().thePlayer.inventory.setInventorySlotContents(var2, new ItemStack(mod_jangostarwars.LightSaber,1,0));   
                      		}
}
}

Link to comment
Share on other sites

Its in a keybind a ModLoader one i find that Forge keybinds are verry over complicated so this is what im using

   public void keyboardEvent(KeyBinding var1)
    {
            if (var1.isPressed() && var1.keyCode == 19)
            {
                    int var2 = ModLoader.getMinecraftInstance().thePlayer.inventory.currentItem;
                    ItemStack var3 = ModLoader.getMinecraftInstance().thePlayer.inventory.getStackInSlot(var2);
                    
                    
                    if (var3 == null)
                    {
                     return;
                    }
                    
                    if (var3.itemID == mod_jangostarwars.LightSaberOFF.shiftedIndex)
                     {
                    
                     sabersound.sndManager.playSoundFX("LightSaberSound.LightSaberOnSound", 1.0F, 1.0F);
                     
                     		if(var3.itemID == mod_jangostarwars.LightSaberOFF.shiftedIndex && var3.getItemDamage() == 0)  
                      		{
                     			Minecraft.getMinecraft().thePlayer.inventory.setInventorySlotContents(var2, new ItemStack(mod_jangostarwars.LightSaber,1,0));   
                      		}
}
}

 

I have no idea what to do to make it better, but you are giving the player the same item again when the metadata of the item they're holding is 0 (and you are also checking the item ID twice. Once, and then again inside the check. You can just remove the second one).

Link to comment
Share on other sites

i have it like that because i have multiple if statements like that on the inside of it for a bunch of meta data and that is required. also that is not the problem its the server replacing it when i use the replaceItemStack or whatever method it dosent work anymore due to the server and client merge so you need to send packets to the server letting it know the inventory has changed but i dont know how to do this that is the problem.

Link to comment
Share on other sites

FMLClientHandler.getMinecraftInstance(). Not FMLCommonHandler

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

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.



×
×
  • Create New...

Important Information

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