Jump to content

Packet Issue[1.8.9]


JelloMOO

Recommended Posts

	public static class Handler implements IMessageHandler<MessageEntityMove, IMessage>
    {
        @Override
	public IMessage onMessage(final MessageEntityMove message,
	MessageContext ctx)
        { 
            IThreadListener mainThread = (IThreadListener) ctx.getServerHandler().playerEntity.worldObj;
            
		final EntityPlayerMP thePlayer = (EntityPlayerMP) YouLoyal.proxy.
		getPlayerEntityFromContext(ctx);
		final Entity theEntity = thePlayer.worldObj.
		getEntityByID(message.entityId);
            mainThread.addScheduledTask(new Runnable()
            {
			@Override
			public void run()
                {

 

This code is taken from a simple packet i made.

 

See what I'm trying to do is pick up a chicken and hold it in my hand. I use a packet to send the chicken's ID to the server so that I can mount the chicken on a bat that i'm constantly teleporting to the player's hand. However, after a while, the server loses the entity, and the chicken goes back to the position it's in before I picked it up. I checked the coords for the bat and the chicken, and I found that the bat isnt the problem.

The server will say that the chicken is in it's last position before it teleported back to its original position. So I'm seeing that the server lost the chicken's entity ID.

 

Would this be attributed to a problem with the piece of the packet I showed above?

 

If not, what would be causing this issue, and how do I fix it?

Link to comment
Share on other sites

	public static class Handler implements IMessageHandler<MessageEntityMove, IMessage>
    {
        @Override
	public IMessage onMessage(final MessageEntityMove message,
	MessageContext ctx)
        { 
            IThreadListener mainThread = (IThreadListener) ctx.getServerHandler().playerEntity.worldObj;
            
		final EntityPlayerMP thePlayer = (EntityPlayerMP) YouLoyal.proxy.
		getPlayerEntityFromContext(ctx);
		final Entity theEntity = thePlayer.worldObj.
		getEntityByID(message.entityId);
            mainThread.addScheduledTask(new Runnable()
            {
			@Override
			public void run()
                {

 

This code is taken from a simple packet i made.

 

See what I'm trying to do is pick up a chicken and hold it in my hand. I use a packet to send the chicken's ID to the server so that I can mount the chicken on a bat that i'm constantly teleporting to the player's hand. However, after a while, the server loses the entity, and the chicken goes back to the position it's in before I picked it up. I checked the coords for the bat and the chicken, and I found that the bat isnt the problem.

The server will say that the chicken is in it's last position before it teleported back to its original position. So I'm seeing that the server lost the chicken's entity ID.

 

Would this be attributed to a problem with the piece of the packet I showed above?

 

If not, what would be causing this issue, and how do I fix it?

Link to comment
Share on other sites

I mount the entity in another class, inside of a

    @SideOnly(Side.CLIENT)
    @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
    public void onEvent(MouseEvent event)

 

event.

 

using this

 

.network.sendToServer(new MessageEntityPacket(ent.getEntityId()));

 

I successfully get the entity's ID and send it to the server, but only temporarily. It seems like it forgets after a while and teleports the entity back.

Link to comment
Share on other sites

I mount the entity in another class, inside of a

    @SideOnly(Side.CLIENT)
    @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
    public void onEvent(MouseEvent event)

 

event.

 

using this

 

.network.sendToServer(new MessageEntityPacket(ent.getEntityId()));

 

I successfully get the entity's ID and send it to the server, but only temporarily. It seems like it forgets after a while and teleports the entity back.

Link to comment
Share on other sites

What does this mean?

 

It means that you never picked it up on client?

 

Proper way:

Client:

1. Right click.

2. Ray trace for entity.

3. If entity was found and is in range (e.g 3 blocks), check if chicken.

4. Send packet containing ray traced chicken ID.

Server:

1. Receive packet, PASS NEW RUNNABLE TO SERVER THREAD: (next steps in runnable)

2. Get EntityPlayerMP from Context, get EntityLivingBase from entityId received.

3. Safety recheck - test if found EntityLivingBase is in proper distance, then check if it is actually EntityChicken.

4. Found instance of EntityChicken save as WeakReference on server side @Capability or IEntityExtendedProperties assigned to player who sent packet.

5. Use EntityTracker to update all players tracking player who picked up chicken with packet.

* Packet will containt entityId of: player who picked up chicken, chicken picked up.

Client: (all receivers)

1. Receive packet, PASS NEW RUNNABLE TO CLIENT THREAD: (next steps in runnable)

2. Set client side @Capability or IEntityExtendedProperties of RECEIVED (from packet's player's entityId) EntityPlayer to have reference to EntityChicken from entityId chicken received.

3. Additionally - since it may happen that new EntityPlayer will come up to you while you are alredy holding chicken - you need to notify them:

* Use PlayerEvent.StartTracking to update event.player about event.target (target is the EntityPlayer that would be holding chicken the moment someone else starts seeing him).

Both:

1. Now - use PlayerTickEvent (START or END) to move chicken on BOTH SIDES in such way it always fits player's Y coord and rotation (this is pure math).

 

This all will give you side-backed smooth movements of held Chicken on all clients seeing given player.

 

Note: It is also possible to totally perform all chicken movements from server, but idk how well that will do with smoothness. In that case you can remove all blue steps.

 

P.S: This is all theorycraft that will work (where I am not sure about blue part). I didn't have fun in field of moving entities for some time, so maybe server-only will work just as smooth as one could expect. Now when I think about it - it even should. For all I care yo ucould be even updating client side entities with RenderTickEvents lol (totally viable).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

What does this mean?

 

It means that you never picked it up on client?

 

Proper way:

Client:

1. Right click.

2. Ray trace for entity.

3. If entity was found and is in range (e.g 3 blocks), check if chicken.

4. Send packet containing ray traced chicken ID.

Server:

1. Receive packet, PASS NEW RUNNABLE TO SERVER THREAD: (next steps in runnable)

2. Get EntityPlayerMP from Context, get EntityLivingBase from entityId received.

3. Safety recheck - test if found EntityLivingBase is in proper distance, then check if it is actually EntityChicken.

4. Found instance of EntityChicken save as WeakReference on server side @Capability or IEntityExtendedProperties assigned to player who sent packet.

5. Use EntityTracker to update all players tracking player who picked up chicken with packet.

* Packet will containt entityId of: player who picked up chicken, chicken picked up.

Client: (all receivers)

1. Receive packet, PASS NEW RUNNABLE TO CLIENT THREAD: (next steps in runnable)

2. Set client side @Capability or IEntityExtendedProperties of RECEIVED (from packet's player's entityId) EntityPlayer to have reference to EntityChicken from entityId chicken received.

3. Additionally - since it may happen that new EntityPlayer will come up to you while you are alredy holding chicken - you need to notify them:

* Use PlayerEvent.StartTracking to update event.player about event.target (target is the EntityPlayer that would be holding chicken the moment someone else starts seeing him).

Both:

1. Now - use PlayerTickEvent (START or END) to move chicken on BOTH SIDES in such way it always fits player's Y coord and rotation (this is pure math).

 

This all will give you side-backed smooth movements of held Chicken on all clients seeing given player.

 

Note: It is also possible to totally perform all chicken movements from server, but idk how well that will do with smoothness. In that case you can remove all blue steps.

 

P.S: This is all theorycraft that will work (where I am not sure about blue part). I didn't have fun in field of moving entities for some time, so maybe server-only will work just as smooth as one could expect. Now when I think about it - it even should. For all I care yo ucould be even updating client side entities with RenderTickEvents lol (totally viable).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

	public static class Handler implements IMessageHandler<MessageEntityMove, IMessage>
    {
        @Override
	public IMessage onMessage(final MessageEntityMove message,
	final MessageContext ctx)
        { 
		// Know it will be on the server so make it thread-safe
            IThreadListener mainThread = (IThreadListener) ctx.getServerHandler().playerEntity.worldObj; // or Minecraft.getMinecraft() on the client
            

            mainThread.addScheduledTask(new Runnable()
            {
    			final EntityPlayerMP thePlayer = (EntityPlayerMP) blessup.proxy.
    					getPlayerEntityFromContext(ctx);
    			final Entity theEntity = thePlayer.worldObj.getEntityByID(message.entityId);
    			final WeakReference<Entity> ent1 = new WeakReference<Entity>(theEntity);

 

So I did this.

 

It didn't quite fix my issue unfortunately.

 

What am I doing wrong?

 

EDIT:

 

Using the weak reference really gave me the entity position and I found that the problem was in how I was mounting the entity on the bat. I didnt mount it in the packet like I should have.

 

So now the entity is truly mounted.

 

 

There seems to be some server lag. Is that normal with this? I'll do some more testing and report back here before setting this to solved.

Link to comment
Share on other sites

	public static class Handler implements IMessageHandler<MessageEntityMove, IMessage>
    {
        @Override
	public IMessage onMessage(final MessageEntityMove message,
	final MessageContext ctx)
        { 
		// Know it will be on the server so make it thread-safe
            IThreadListener mainThread = (IThreadListener) ctx.getServerHandler().playerEntity.worldObj; // or Minecraft.getMinecraft() on the client
            

            mainThread.addScheduledTask(new Runnable()
            {
    			final EntityPlayerMP thePlayer = (EntityPlayerMP) blessup.proxy.
    					getPlayerEntityFromContext(ctx);
    			final Entity theEntity = thePlayer.worldObj.getEntityByID(message.entityId);
    			final WeakReference<Entity> ent1 = new WeakReference<Entity>(theEntity);

 

So I did this.

 

It didn't quite fix my issue unfortunately.

 

What am I doing wrong?

 

EDIT:

 

Using the weak reference really gave me the entity position and I found that the problem was in how I was mounting the entity on the bat. I didnt mount it in the packet like I should have.

 

So now the entity is truly mounted.

 

 

There seems to be some server lag. Is that normal with this? I'll do some more testing and report back here before setting this to solved.

Link to comment
Share on other sites

Alright, new issue.

 

When I put down the chicken, it creates a copy of the chicken, making two chickens, and they walk in sync with each other.

 

What on earth is happening?

 

It appears that when I kill the chickens, the original will die, but the copy will stay.

 

However, this is where it gets creepy.

The copy doesn't stay alive.

 

You know when you kill an animal and it turns over and it's color becomes red right before it disappears?

 

Well, the chicken copy does that, except it doesn't disappear. It stays there.

Forever.

 

Seriously, what dimension did I just walk into?

Whats happening?

Link to comment
Share on other sites

Alright, new issue.

 

When I put down the chicken, it creates a copy of the chicken, making two chickens, and they walk in sync with each other.

 

What on earth is happening?

 

It appears that when I kill the chickens, the original will die, but the copy will stay.

 

However, this is where it gets creepy.

The copy doesn't stay alive.

 

You know when you kill an animal and it turns over and it's color becomes red right before it disappears?

 

Well, the chicken copy does that, except it doesn't disappear. It stays there.

Forever.

 

Seriously, what dimension did I just walk into?

Whats happening?

Link to comment
Share on other sites

Dude, what are you doing? What are you doing with that WeakReference? Is needs to be saved INSIDE PLAYER. My prev post explains step by step what you should do.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Dude, what are you doing? What are you doing with that WeakReference? Is needs to be saved INSIDE PLAYER. My prev post explains step by step what you should do.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

You need the reference inside the capability not the packet handler.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You need the reference inside the capability not the packet handler.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.