gokiburi Posted November 15, 2012 Posted November 15, 2012 Solution: Something else was causing the issue. Using !world.isRemote was the correct thing to do. With an onItemUse I consume an item from the players inventory. This command is run when world.isRemote. The server does not register these items as consumed if I pass in the player from onItemUse, but does consume the items if I pass in the player from MinecraftServer.getServer().worldServers[0].getPlayerEntityByUsername(player.username). Why? Quote http://www.minecraftforum.net/topic/1522738-132-forge-425-gokimods/
SanAndreaP Posted November 15, 2012 Posted November 15, 2012 With an onItemUse I consume an item from the players inventory. This command is run when world.isRemote. The server does not register these items as consumed if I pass in the player from onItemUse, but does consume the items if I pass in the player from MinecraftServer.getServer().worldServers[0].getPlayerEntityByUsername(player.username). Why? Do you execute your code if world.isRemote is true? Quote 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.
gokiburi Posted November 15, 2012 Author Posted November 15, 2012 Remote or not, the changes don't persist unless I get the world from the worldServers array. Quote http://www.minecraftforum.net/topic/1522738-132-forge-425-gokimods/
SanAndreaP Posted November 15, 2012 Posted November 15, 2012 Why not use this? par3World.getPlayerEntityByUsername(par2EntityPlayer.username) Quote 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.
gokiburi Posted November 15, 2012 Author Posted November 15, 2012 Here's a list of outcomes. par3EntityPlayer.worldObj.setBlock + par3EntityPlayer.inventory.consumeItem: onItemUse with par3EntityPlayer.worldObj.isRemote - Blocks placed, items consumed, changes do not persist. onItemUse with !par3EntityPlayer.worldObj.isRemote - No blocks placed, no items consumed. onItemUse with par3EntityPlayer.worldObj.isRemote and !player.worldObj.isRemote - Shows the blocks being placed and consumes the items, but after saving and reloading the changes have not persisted. Why not use this? par3World.getPlayerEntityByUsername(par2EntityPlayer.username) This has the same effect as above. If I use MinecraftServer.getServer().worldServers[0].getPlayerEntityByUsername(par3EntityPlayer.username) it actually returns a "server" player and everything works exactly as expected, but that seems like an erroneous, not very proper way to get the current players multiplayer world. Quote http://www.minecraftforum.net/topic/1522738-132-forge-425-gokimods/
SanAndreaP Posted November 15, 2012 Posted November 15, 2012 Here's a list of outcomes. par3EntityPlayer.worldObj.setBlock + par3EntityPlayer.inventory.consumeItem: onItemUse with par3EntityPlayer.worldObj.isRemote - Blocks placed, items consumed, changes do not persist. onItemUse with !par3EntityPlayer.worldObj.isRemote - No blocks placed, no items consumed. onItemUse with par3EntityPlayer.worldObj.isRemote and !player.worldObj.isRemote - Shows the blocks being placed and consumes the items, but after saving and reloading the changes have not persisted. Why not use this? par3World.getPlayerEntityByUsername(par2EntityPlayer.username) This has the same effect as above. If I use MinecraftServer.getServer().worldServers[0].getPlayerEntityByUsername(par3EntityPlayer.username) it actually returns a "server" player and everything works exactly as expected, but that seems like an erroneous, not very proper way to get the current players multiplayer world. No, because you cannot get the server instance when you are connected to a dedicated server. If you put this at the beginning of the method: System.out.println(par3World.isRemote); and you execute it it should print something in the console two times, "true" and "false". Anyway, could you provide the code of your onItemUse method? Quote 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.
gokiburi Posted November 15, 2012 Author Posted November 15, 2012 I must have been doing something else wrong before. Your solution above mostly works now, after moving things around. There are two separate problems now, but I'll make another thread for one of them. The solution was to use par2World.getPlayerEntityByUsername(par3EntityPlayer.username) instead of MinecraftServer.getServer.worldServers[0].getPlayerEntityByUsername(par3EntityPlayer) while !par2World.isRemote. Now the players items get consumed server side but not client side. I may just have to split up portions of the code to run onItemUse for if it's the client or server or add code to simply remove from client side as well. Quote http://www.minecraftforum.net/topic/1522738-132-forge-425-gokimods/
SanAndreaP Posted November 15, 2012 Posted November 15, 2012 Do you return true when par2World.isRemote is true? Quote 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.
gokiburi Posted November 15, 2012 Author Posted November 15, 2012 Do you return true when par2World.isRemote is true? I return the ItemStack and don't proceed with the use call. The item itself isn't consumed; other items in the players inventory are supposed to be. I could access the ItemStack to change it around, but what's actually going on is that the recursive function tells the players inventory to decrease the stack size of the itemID with metadata if it exists and end recursion if it doesn't. Server side their items are decreased, client side they're still lingering and I don't know how to force the client to pick up on those changes without user interaction. I could send a packet but I feel that's the wrong answer. The other problem I have is that my raytrace returns the proper co-ordinates when par2World.isRemote is false but the block directly under the player when it's true, meaning I still have to figure out how to fix that before the function works properly. I figured I'd put that in another thread though. Quote http://www.minecraftforum.net/topic/1522738-132-forge-425-gokimods/
Recommended Posts
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.