Jump to content

Server not sending packet to player on multiplayer


GotoLink

Recommended Posts

I have been struggling with this issue for the past few days.

I made an universal packet handler on my network mod, which handles changes to a tileentity induced by a player from a gui.

public class PacketHandler implements IPacketHandler{

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) 
{
	if(packet.channel == GeneralRef.PACKET_CHANNELS[0])
	{//Sent by AnimatorGUI to server when a button has been activated
		handleGuiChange(manager, packet,(EntityPlayer) player);
	}
	else if(packet.channel == GeneralRef.PACKET_CHANNELS[1])
	{//Sent by server to client FIXME: packet isn't received on multiplayer ??
		handleDescriptionPacket(packet,(EntityPlayer) player);
	}
	//DEBUG:
	Side side = ((EntityPlayer)player).worldObj.isRemote?Side.CLIENT:Side.SERVER;
	FMLLog.getLogger().info(side.toString()+" recieved a "+packet.channel +" packet");
}
/**
* Client method to handle a packet describing the TileEntityAnimator from server
* @param packet
* @param player
*/
private static void handleDescriptionPacket(Packet250CustomPayload packet, EntityPlayer player)
{
	DataInputStream dat = new DataInputStream(new ByteArrayInputStream(packet.data));
	try{
        int x = dat.readInt();
        int y = dat.readInt();
        int z = dat.readInt();
        TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
        if (te instanceof TileEntityAnimator)
        {
            TileEntityAnimator animator = (TileEntityAnimator) te;
            animator.setEditing(dat.readBoolean());
            if(!animator.isEditing() && animator.getStackInSlot(0)!=null)
                resetRemote(animator.getStackInSlot(0));
            animator.setFrame(dat.readInt());
            animator.setMaxFrame(dat.readInt());
            animator.setCount(dat.readInt());
            animator.resetDelay();
            animator.setDelay(dat.readInt());
            animator.setMode(Mode.values()[dat.readShort()]);
        }
	}catch(IOException i)
	{
		i.printStackTrace();
	}
}
/**
* Server method to handle a client action in AnimatorGUI
* @param manager 
* @param packet
* @param player
*/
private static void handleGuiChange(INetworkManager manager, Packet250CustomPayload packet, EntityPlayer player) 
{
	DataInputStream inStream = new DataInputStream(new ByteArrayInputStream(packet.data));
	int[] data = new int[packet.data.length/4];
	try 
	{
		for(int id = 0; id < data.length; id++)
			data[id] = inStream.readInt();
	} 
	catch (IOException e) 
	{
            e.printStackTrace();
            return;
	}
	TileEntity tile = player.worldObj.getBlockTileEntity(data[1], data[2], data[3]);
	if(tile instanceof TileEntityAnimator)
	{
		handleData((TileEntityAnimator) tile, data);
            if(player.openContainer instanceof ContainerAnimator && ((ContainerAnimator)player.openContainer).getControl() == tile)
    			player.openContainer.detectAndSendChanges();
		//manager.addToSendQueue(getPacket((TileEntityAnimator) tile));
		player.worldObj.markBlockForUpdate(data[1], data[2], data[3]);
	}
}

public static void handleData(TileEntityAnimator animator, int... data)
{
	switch(data[0])
	{
	case 0://"+" button has been pressed
		animator.setDelay(1);
		break;
	case 1://"-" button has been pressed
		if(animator.getDelay()>-1)
		{//Lower delay won't work and might crash
			animator.setDelay(-1);
		}
		break;
	case 2://"Switch button has been pressed, going LOOP->ORDER->REVERSE->RANDOM->LOOP
		int mod = animator.getMode().ordinal();
		if(mod + 1 < Mode.values().length)
			animator.setMode(Mode.values()[mod + 1]);
		else
			animator.setMode(Mode.LOOP);
            break;
        case 3:
        case 4://One of the "Reset" button has been pressed
                animator.setEditing(false);
                animator.setLinker(null);
                if(data[0]==4)//This is a full reset
                {
                	resetAnimator(animator);
                }
                if(data.length > 4)//Get the item and reset it
                	resetRemote(animator.getStackInSlot(0));
                break;
        case 5://Increment Max number of frames that will run
        	animator.setMaxFrame(animator.getMaxFrame() + 1);
		break;
        case 6://Increment first frame to display
    		animator.setFrame(animator.getFrame() + 1);
        	break;
	}

}

public static void resetAnimator(TileEntityAnimator animator) 
{
	animator.setFrame(0);                
        animator.setMode(Mode.ORDER);
        animator.resetDelay();
        animator.setMaxFrame(-1);
        animator.setCount(0);
}

public static void resetRemote(ItemStack stack)
{
        ItemBase remote = (ItemBase)stack.getItem();
        remote.resetLinker();
        stack.getTagCompound().removeTag(ItemBase.KEYTAG);
}

public static Packet getPacket(TileEntityAnimator animator) 
{
	ByteArrayOutputStream bos = new ByteArrayOutputStream(31);
        DataOutputStream dos = new DataOutputStream(bos);     
        try
        {
            dos.writeInt(animator.xCoord);
            dos.writeInt(animator.yCoord);
            dos.writeInt(animator.zCoord);
            dos.writeBoolean(animator.isEditing());
            dos.writeInt(animator.getFrame());
            dos.writeInt(animator.getMaxFrame());
            dos.writeInt(animator.getCount());
            dos.writeInt(animator.getDelay());
            dos.writeShort(animator.getMode().ordinal());
        }
        catch (IOException e)
        {
        	e.printStackTrace();
        }
        Packet250CustomPayload pkt = new Packet250CustomPayload();
        pkt.channel = GeneralRef.PACKET_CHANNELS[1];
        pkt.data = bos.toByteArray();
        pkt.length = bos.size();
        pkt.isChunkDataPacket = true;
        return pkt;
}
}

While it works on single player, with values being changed and gui following it

("SERVER received a Gui packet","CLIENT received description packet")

it doesn't on multiplayer with mcp test server

("SERVER received a Gui packet",*nothing follows*)

 

Hopefully someone will found where I derped :)

 

Edit: This is on 1.5.2 and Forge 7.8.1.737 by the way.

Link to comment
Share on other sites

player.openContainer.detectAndSendChanges();

//manager.addToSendQueue(getPacket((TileEntityAnimator) tile));

player.worldObj.markBlockForUpdate(data[1], data[2], data[3]);

 

this is commented ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I tried to fix with the commented part, but result is the same.

In my tile entity, i have

@Override
    public Packet getDescriptionPacket()
    {
        return PacketHandler.getPacket(this);
    }

So with

player.worldObj.markBlockForUpdate(data[1], data[2], data[3]);

the description packet is sent. But only on single player... :-\

Link to comment
Share on other sites

btw im looking at your code atm i just wanted to tell you i made a tutorial about tile entity synchronizing on the wiki (its kindaof shitty though)

 

its called: "synchronizing tile entities" or something similar

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

oh, im sorry its so simple, you're not sending the packet with the right channel

 

server will send a packet using GeneralRef.PACKET_CHANNELS[1] but client only accepts [0]

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Nope, the description packet given by getPacket(TileEntityAnimator) has channel 1 and the receiving part handleDescriptionPacket is also waiting for channel 1. It wouldn't work on single player if I made that mistake.

Link to comment
Share on other sites

@NetworkMod(clientSideRequired = true, serverSideRequired = false , channels={"Gui","Animator"}, packetHandler = PacketHandler.class)

public static final String[] PACKET_CHANNELS = {"Gui","Animator"};

While reading your tutorial, I came across PacketDispatcher class. Trying the methods in it right now.

 

Link to comment
Share on other sites

While reading your tutorial, I came across PacketDispatcher class. Trying the methods in it right now.

 

is not really different then

 

manager.addToSendQueue(getPacket((TileEntityAnimator) tile));

 

 

its just that its the same everywhere :P

 

so thats probably not goign to help

 

can you at least println BEFORE the packet from server is sent ? (making sure that it WAS send )

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

ok but when the gui is changed, can you println right before you send the packet so you can tell for sure that the server is sending the packet, because if it IS sending it then you know your client  packet handler is not registered correctly

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Debug says "SERVER received gui packet", even on multiplayer.

But I only have "CLIENT received animator packet" on single player.

That is the whole issue, as my title says, server don't send the packet to the player on multiplayer.

Link to comment
Share on other sites

yes link i know that but just because the message gets to the server doesnt meant that it is sent FROM the server. i jsut want to make sure the server is actually SENDING the packet, if its not sending it the client is obviously not receiving it

 

if(player.openContainer instanceof ContainerAnimator && ((ContainerAnimator)player.openContainer).getControl() == tile)

    player.openContainer.detectAndSendChanges();

//manager.addToSendQueue(getPacket((TileEntityAnimator) tile));

System.out.println("yes i have send the packet :)");

player.worldObj.markBlockForUpdate(data[1], data[2], data[3]);

}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Single player:

[sTDOUT] yes i have send the packet :)

[iNFO] [ForgeModLoader] SERVER recieved a Gui packet

[iNFO] [ForgeModLoader] CLIENT recieved a Animator packet

Multi:

[iNFO] [ForgeModLoader] SERVER recieved a Gui packet

 

Server not sending packet, as I said.

Oh, and there isn't any exception thrown due to bad data.

Link to comment
Share on other sites

(sorry i got to go)

but try println before and after every if, method call, while, for

this way youll know exactly at which point this is stopping

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://drive.google.com/file/d/1fPISu1m5Ica8CKDWj3PWVYPNgn85w2dk/view?usp=drive_link
    • @TileEntity no, the problem must be somewhere else, yes, we know that it eats a lot of frames, but it must be caused by something else, probably a mod or something, because for the first 10 days I played this modpack without problems on 4gb of ram, no problem, 200 fps, suddenly now when I start minecraft, minecraft runs for the first 2 minutes to 200 fps and suddenly the frame starts to be stretched very much. I assigned 8, then 12, then 16, and 24 gb of ram is just one amount. I always assign it after a different time, usually within 5 minutes, the game crashes due to lack of frame. the problem must be somewhere else, not only in the frame but in some mode or something strange, but it worked for me before and it works normally for my friends.
    • If you are using AMD/ATI, get the latest drivers from their website - do not update via system
    • So I don't have any other mods and I try to install my first mod. At first I tried turning on Forge but it didn't work for me. I entered into these logs and this is what debug I found.   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0. 9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   -------------------------------------------------------------   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.428] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [fmlclientdev,forgeclient,minecraft,forgegametestserverdev,fmlserveruserdev,fmlclient,fmldatauserdev,forgeserverdev,forgeserveruserdev,forgeclientdev,forgeclientuserdev,forgeserver,forgedatadev,fmlserver,fmlclientuserdev,fmlserverdev,forgedatauserdev,testharness,forgegametestserveruserdev] [05maj2024 19:29:16.448] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [srgtomcp] [05maj2024 19:29:16.468] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,slf4jfixer,object_holder_definalize,runtime_enum_extender,capability_token_subclass,accesstransformer,runtimedistcleaner] [05maj2024 19:29:16.485] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path GAMEDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path MODSDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\mods [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path CONFIGDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path FMLCONFIG is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config\fml.toml [05maj2024 19:29:16.550] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Found additional transformation services from discovery services:  [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   Can you help me with this?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.