Jump to content

[Solved] Packets not updating GUI in published mode only


strumshot

Recommended Posts

I've written a set of guis that display a value stored in the container. While running from eclipse, every test I can do comes back successful. However after publishing to a full server-client setup (meaning not debug-able) ALMOST all of it works.

 

The order of operation is as follows: Player opens gui -> request packet is sent -> server receives request -> server responds with packet containing value -> player receives packet and adjusts local value to be displayed in the gui.

 

Again, while in testing, everything works perfectly. In full publish, I have evidence that the value is indeed stored properly on the server, and I have a way of basically forcing an update as an OP - for lack of better words. (There is another gui in which I can CHANGE the value, and after doing so, it all displays properly.) But any other player - or by logging out then back in - will display 0 in the client gui, despite the value on the server. I don't personally have a way to connect a debug client to a full release server, so I don't know how to find the problem!

 

OnBlockActivate

 

if (world.isRemote)
        {
        	return true;
        }
        else
        {
            IInventory iinventory = (TileEntityShopChest)world.getTileEntity(x, y, z);

            TileEntity tileEntity = world.getTileEntity(x, y, z);
            if (tileEntity == null || player.isSneaking()|| !(tileEntity instanceof TileEntityShopChest)) {
                    return false;
            }
            
            TileEntityShopChest chest = (TileEntityShopChest) tileEntity;
            	
            if (iinventory != null)
            {
            	//if owner, open owner gui, id = 0?
			if (chest.isOwnedBy(player)) {
				FMLNetworkHandler.openGui(player, IShop.INSTANCE, 0, world,
						x, y, z);
				IShop.network.sendToServer(new RequestCost());
			}

			else {
				FMLNetworkHandler.openGui(player, IShop.INSTANCE, 1, world,
						x, y, z);
				IShop.network.sendToServer(new RequestCost());
			}
            	//else open shopper gui, id = 1?
            }

            
            return true;
        }

 

 

RequestCost packet (handled on server)

 

@Override
        public IMessage onMessage(RequestCost message, MessageContext ctx) {
        	
        	EntityPlayer player = ctx.getServerHandler().playerEntity;
        	if(player.openContainer instanceof ContainerShopper){
        		ContainerShopper container = (ContainerShopper)player.openContainer; 
        		return new SendCost((short) container.tileEntity.Cost); 
        	}
            
        	ContainerShop container = (ContainerShop)player.openContainer; 
    		return new SendCost((short) container.tileEntity.Cost); 
        }

 

 

SendCost packet (handled on client)

 

@Override
        public IMessage onMessage(SendCost message, MessageContext ctx) {
        	
        	GuiScreen screen = Minecraft.getMinecraft().currentScreen;
        	
        	if (screen instanceof GuiShopper) {
			ContainerShopper container = ((GuiShopper) screen).container;

			container.tileEntity.Cost = message.cost;
			container.tileEntity.markDirty();
		}
		else if (screen instanceof GuiShop) {
			ContainerShop container = ((GuiShop) screen).container;

			container.tileEntity.Cost = message.cost;
			container.tileEntity.markDirty();
		}

        	return null; // no response in this case
        }

 

 

What am I missing?

 

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

Am I registering these correctly? Are the index numbers supposed to be unique per side or something?

 

        network = NetworkRegistry.INSTANCE.newSimpleChannel("shopChannel");
    	network.registerMessage(ChangeCostUp.Handler.class, ChangeCostUp.class, 0, Side.SERVER);
    	network.registerMessage(ChangeCostDown.Handler.class, ChangeCostDown.class, 3, Side.SERVER);
    	network.registerMessage(RequestCost.Handler.class, RequestCost.class, 2, Side.SERVER);
    	network.registerMessage(SendCost.Handler.class, SendCost.class, 1, Side.CLIENT);

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

After enlisting a friend to assist me in debugging, I have found that RequestCost() ONLY is throwing exception:

 

[server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught

java.lang.RuntimeException: Missing

at cpw.mods.fml.server.FMLServerHandler.getClientToServerNetworkManager(FMLServerHandler.java:238) ~[FMLServerHandler.class:?]

 

Every other packet I registered is executing perfectly.

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

Actually I just checked and I didn't paste that part in here, I do indeed do a check...

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
        if (world.isRemote)
        {
        	return true;
        }
        else
        {
            IInventory iinventory = (TileEntityShopChest)world.getTileEntity(x, y, z);

            TileEntity tileEntity = world.getTileEntity(x, y, z);
            if (tileEntity == null || player.isSneaking()|| !(tileEntity instanceof TileEntityShopChest)) {
                    return false;
            }
            
            TileEntityShopChest chest = (TileEntityShopChest) tileEntity;
            	
            if (iinventory != null)
            {
            	//if owner, open owner gui, id = 0?
			if (chest.isOwnedBy(player)) {
				FMLNetworkHandler.openGui(player, IShop.INSTANCE, 0, world,
						x, y, z);
				IShop.network.sendToServer(new RequestCost());
			}

			else {
				FMLNetworkHandler.openGui(player, IShop.INSTANCE, 1, world,
						x, y, z);
				IShop.network.sendToServer(new RequestCost());
			}
            	//else open shopper gui, id = 1?
            }

            
            return true;
        }
    }

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

I'm moving the RequestCost into the gui initialization to see if that clears it up. I'll edit this post with results... That solved it. Even after doing an explicit remote check. Odd. I'd sure like to know how that happened, but all is well that ends well.

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

Again, you were checking if you are on the serverside and if so, sending a packet to the server. That makes no sense.

 

I had

if(world.isRemote == false) IShop.network.sendToServer(new RequestCost());

and it didn't fix it. Am I dyslexic and looking at this backwards? That is seriously possible, lol.

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

So wait... basically IsRemote is relative to each thread? Meaning the server is remote from client, and the client is remote from server? If so, that seems problematic to me and I should be using SideOnly whenever possible...

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

So wait... basically IsRemote is relative to each thread? Meaning the server is remote from client, and the client is remote from server? If so, that seems problematic to me and I should be using SideOnly whenever possible...

No. No no no.

isRemote is true for client worlds only and false for server worlds (including worlds from the integrated server) only.

So you can detect the logical side with isRemote.

 

@SideOnly completely removes a method, field or class (as if it just did not exist in the java code) from the specified Jar-file. So @SideOnly(Side.SERVER) means that the method will only exist in the minecraft-server.jar. So even the Integrated Server will not have it. Also @SideOnly does not care about any compile errors that might occur from this. It just strips the method/field/class completely no matter what.

Conclusion: @SideOnly is almost never the right choice.

 

Okay, good, that's what I've thought, and that makes me feel better! You scared me for a second. I guess I was looking at my logical check wrong, but I found a better solution by sending the gui update packet from within the gui itself, so problem solved/averted anyway. As usual, big thanks!

 

Although the fact that this didn't work

if(world.isRemote == false) IShop.network.sendToServer(new RequestCost());

still perplexes me, but I think this thread is officially dead! I don't want to know! :D

I'll need help, and I'll give help. Just ask, you know I will!

Link to comment
Share on other sites

The server cannot send a packet to itself.

 

That makes sense, yes.

 

Why I keep reading it as

 

"if(we are not the server) send packet to server" is what doesn't make sense to me, aside from obvious dyslexia on my part - which I have resigned to, because I trust you. lol!

 

I'll need help, and I'll give help. Just ask, you know I will!

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.