Posted September 29, 201212 yr 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
September 29, 201212 yr 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.
September 29, 201212 yr Author 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)); } } }
September 30, 201212 yr 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).
September 30, 201212 yr Author 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.
October 4, 201212 yr if i remember correctly you can use FMLCommonHandler.getMinecraftInstance() to get it working, i haven't coded for a couple of weeks and have not used the latest version of forge, if it does not work then disregard this post
October 4, 201212 yr 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! http://bit.ly/HZ03zy[/img] Tired of waiting for mods to port to bukkit? use BukkitForge! (now with a working version of WorldEdit!)
October 4, 201212 yr Author And again there is no such method and getClient() i have static-nonstatic errors.
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.