Jump to content

Recommended Posts

Posted

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.

Posted

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-

Posted

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... :-\

Posted

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-

Posted

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-

Posted

only accepts GeneralRef.PACKET_CHANNELS[0]

 

 

wtf formatting ?

 

 

also, yeah those kind of error sucks !

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

-hydroflame, author of the forge revolution-

Posted

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.

Posted

in single player the server has access to the client and the client to the server.

how are they registered ?

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

-hydroflame, author of the forge revolution-

Posted

@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.

 

Posted
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-

Posted

Well same results for all PacketDispatcher methods... :-\

 

Ok some news:

one packet is sent on player login and one when the block is placed.

It isn't sent after gui change.

Posted

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-

Posted

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.

Posted

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-

Posted

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.

Posted

(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-

Posted

Feeling really stupid right now.

Channels strings have to be compared with String.equals(Object) since they can't be the same object.

 

*solved*

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! There is an issue with my world(Chocolate Edition modpack), after joining the world all creatures are frozen and the game is not responding or the game crashes after short period of time. Reproduction Steps: Turn on the game Join the world Game crashes immediately or after short period of time. Additional info: Crash log saying that an entity crashed the game is created after the crash(not the logs that I posted, different file from crash-logs, game crashed 3x by Snail, 1x by Small Snail, 1x by Tortoise) Specification: CPU: i5-13600KF GPU: GTX 1070 RAM: 32GB 3200MhZ - allocated 10GB Log links: latest.log: https://mclo.gs/Lp8zlsv crash-reports/crash: https://mclo.gs/XhtyJQI Minecraft version: 1.19.2 Modpack Version: Chocolate Edition 1.9 OS: Windows 10 Java Version: 22.0.2 Minecraft Java: Java 17
    • Hello, for several days I've been trying to find a way to add my animations in this style. @Override public void setupAnim(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { }   My current public class is : public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<EntityRenderState>   But i can't do that :  public class FakePlayerModelWithAnim<T extends FakePlayerEntity> extends EntityModel<T> Type parameter 'T' is not within its bound; should extend 'net.minecraft.client.renderer.entity.state.EntityRenderState' But with EntityRenderState it ok and it work !   But my setupAnim look like this :  @Override public void setupAnim(EntityRenderState p_370046_) { super.setupAnim(p_370046_); }   I don't have any access to my entity ! Look like 1.21.1 : @Override public void setupAnim(FakePlayerEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { this.root().getAllParts().forEach(ModelPart::resetPose); this.applyHeadRotation(netHeadYaw, headPitch); this.animateWalk(FakePlayerEntityAnimations.ANIM_PLAYERS_WALKING, limbSwing, limbSwingAmount, 2f, 2.5f); this.animate(entity.idleAnimationState, FakePlayerEntityAnimations.ANIM_PLAYERS_IDLE, ageInTicks, 1f); } But i'm stuck with new version of Forge...
    • Looks like an issue with abyssalsovereigns - this mod has functions that are not working on a server (client-side-only mod)
    • I added some new mods and updated old ones to my forge server and they will run successfully but the moment I try to join ill briefly load into the world and get booted with the message, internal server error. The mods in question work fine on singleplayer and removing too many from the server causes it to stop working so I cant be sure which one is causing the problem... any ideas? server log: https://pastebin.com/hGH8UUjm client log (from modrinth app): https://mclo.gs/a3oOUGY
    • The level.dat contains an invalid tag ID (115) Try to load the world in singleplayer - then test this world on the server
  • Topics

×
×
  • Create New...

Important Information

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