Jump to content

[SOLVED] world.isRemote vs worldServers[0]


gokiburi

Recommended Posts

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?

Link to comment
Share on other sites

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?

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

Why not use this?

par3World.getPlayerEntityByUsername(par2EntityPlayer.username)

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

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.

Link to comment
Share on other sites

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?

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

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.

Link to comment
Share on other sites

Do you return true when par2World.isRemote is true?

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

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.

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.