Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So i'm trying to synchronise these arrays between the client and server, except i cant even get an int to sync using packets (must be packets, not datawatcher). Here's my packet class :

 

(Seriously, is there a problem with macs and that damn code button?)

 

package mine.packethandling;

 

import cpw.mods.fml.common.FMLCommonHandler;

import cpw.mods.fml.common.FMLLog;

import mine.player.PlayerSkills;

import mine.player.PlayerSkills.Skill;

import mine.util.Me;

import io.netty.buffer.ByteBuf;

import io.netty.channel.ChannelHandlerContext;

import net.minecraft.entity.player.EntityPlayer;

 

public class PacketSyncProps extends AbstractPacket {

 

int times;

public PacketSyncProps(){}

 

public PacketSyncProps(int times)

{

Me.log(this.getClass(),"When created, times = " + times);

this.times = times;

}

 

 

@Override

public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {

 

}

 

@Override

public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {

 

}

 

@Override

public void handleClientSide(EntityPlayer player)

{

Me.log(this.getClass(), "Client side syncing player with sent data");

Me.log(this.getClass(), "Existing data : Times : " + this.times);

}

 

@Override

public void handleServerSide(EntityPlayer player)

{

Me.log(this.getClass(), "Why was this sent to server?");

Me.log(this.getClass(), "Fish level pre death " + PlayerStats(player).getSkill(Skill.ONE));

PlayerStats(player).incrementSkill(Skill.ONE, player);

 

}

 

}

 

And that packet is created server-side with :

Me.packetPipeline.sendTo(new PacketSyncProps(12), (EntityPlayerMP) player);

 

(The Me.log spits out the class, the effective side and then the message, and everything is happeneing on the right side)

Why does this.times say 0 when i set it to 12?

  • Author

Oh... (facepalm) Nowhere in all the tutorials i found said that... Hmm, how would i go about that?

  • Author

You sir, are a life saver. Have all the upvotes/highfives/whatevers.

 

Well, now what do i do with : readerIndex(4) + length(4) exceeds writerIndex(4)?

For an example of sending/receiving packets, take a look at my network code;

https://github.com/wiggertolsma/usefullstuff/tree/master/src/main/java/ace/usefullstuff/packets

 

This code comes from the wiki, and works perfectly.

To send a packet, you use ModInstance.packetPipeline.sendTo(new -packetClass-, player).

 

Hope this helps you! It's fully 1.7.4 compatible :)

Follow me on twitter: https://twitter.com/CoderAce_

Well, now what do i do with : readerIndex(4) + length(4) exceeds writerIndex(4)?

That sounds like the packet data that you are reading is larger than the packet data you wrote, or maybe the other way around, though I could be completely wrong. Why not show us your encodeInto and decodeInto code?

  • Author

I solved it now, but was away when i was doing it so couldnt update you all. Here's how it works for me :

 

@Override

public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer)

{

RSLogging.log(this.getClass(), "Encoding Exp " + ExpAmount + " " + SkillAmount + " for " + theSkill.ordinal());

buffer.writeInt(ExpAmount);

buffer.writeInt(SkillAmount);

buffer.writeInt(theSkill.ordinal());

}

 

@Override

public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer)

{

this.ExpAmount = buffer.readInt();

this.SkillAmount = buffer.readInt();

this.theSkill = Skill.getValue(buffer.readInt());

 

Me.log(this.getClass(), "Decoding : Exp " + ExpAmount + " " + SkillAmount + " for " + theSkill);

 

}

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.