Jump to content

[1.6.4] Server and client synchronization problem in TileEntity - "ghost" items


Recommended Posts

Posted

Hi everyone,

 

I have a little problem with my "machine", but it will probably apply to it more like a "chest". When I place any item in my input slot, nothing strange happens, but if I try to take that item out then it seems copied.

It looks that my machine has that item in the input slot, but it stops working (if(inputSlot.stackSize == 0) progress = 0). It's something like ghost item: it disappears if I try to take it out or reopen the GUI. I had the same problem with shift-clicking, but it was solved by:

 

if(te.worldObj.isRemote) return null;

 

in Container.transferStackInSlot. I know that it is client-server sync problem, but I have no idea what piece of code I should modify in that case.

 

My TileEntity: http://pastebin.com/VxFVf8qj

and Container: http://pastebin.com/edwPCweR

 

Did anyone had similar problem?

Sorry if I write something wrong in English, I'm not native English speaker.

Posted

You shouldn't need to check if the world is remote in your transferStackInSlot method - it can run the same on both sides.

 

#onInventoryChanged is when you are supposed to iterate through all the stacks and replace any that have stack size of 0 with null.

 

Calling super on an interface method (e.g. #onInventoryChanged) does absolutely nothing - interfaces do not provide implementations.

 

You really shouldn't need to constantly mark your block for an update. Look at TileEntityFurnace and you'll see it never calls that method; you probably shouldn't, either. Use your Container properly for sending data to the client side via #detectAndSendChanges etc.

 

In fact, the best advice I can give you is seriously look more closely at TileEntityFurnace and model your methods off of those. You are all over the place in there.

 

Also, don't use FMLCommonHandler#getEffectiveSide when you already have a world object; world.isRemote gives you the side much more efficiently.

Posted

Thanks! It finally works!

 

I checked worldObj.isRemote in #transferStackInSlot because it seemed to remove that issue when shift-clicking. Now, when I iterate through stacks in #onInventoryChanged, I don't need that.

 

When I was changing my code basing on your advises, I observed one interesting thing:

 

Calling super on #onInventoryChanged should do something, because it's implemented in Basic TileEntity from Minecraft. Also, I found out that TileEntityFurnace doesn't implement onInventoryChanged.

 

When I'm implementing a method and super does nothing, then eclipse shows an error if I try to call it.

 

Anyways, I removed that super - it did nothing in my case.

Sorry if I write something wrong in English, I'm not native English speaker.

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.