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

Hi again,

 

I need to send via packet more data values at same time like this:

PacketDispatcher.sendToServer(new PacketClientStats(1, 2, 3.5F, itemStack));

 

And I noticed that only the first param is correctly sended instead other params have wrong values:

 

PacketClientStats class:

public class PacketClientStats implements IMessage, IMessageHandler<PacketClientStats, IMessage>
{
  int stats = 0;
  int food = 0;
  float heart = 0;
  static ItemStack drill;
  
  public PacketClientStats()
  {
  }

  public PacketClientStats(int stats, int food, float heart, ItemStack drill)
  {
    this.stats = stats;
    this.food = food;
    this.heart = heart;
    
    this.drill = drill;
  }

  public IMessage onMessage(PacketClientStats message, MessageContext ctx)
  {
    System.out.println("stats = " + message.stats);
    System.out.println("food = " + message.food);
    System.out.println("heart = " + message.heart);
    System.out.println("drill = " + message.drill.getDisplayName());
    
    return null;
  }
  
  public void fromBytes(ByteBuf buf)
  {
       this.stats = buf.getInt(0);
       this.food = buf.getInt(0);
       this.heart = buf.getFloat(0);
  }
  
  public void toBytes(ByteBuf buf)
  {
       buf.writeInt(this.stats);
       buf.writeInt(this.food);
       buf.writeFloat(this.heart);
  }
  
}

 

And the "itemStack" param works properly only if it's declared with "static" option ...

 

  • Author

Don't declare it static. It "doesn't work" because you don't send the "drill" parameter.

And your fromBytes method is broken, use read***, not get***.

Also do not implement IMessage and IMessageHandler on the same class. And you should use @Override where appropriate.

 

How can I send a "ItemStack" object if it's possible?

  • Author

Take a look at FML's ByteBufUtils class.

 

Thanks works. Instaed is it possible to send a "IInventory" object?

  • Author

Short answer: No.

Longer answer: It depends. What kind of inventory is it? Why do you think you need to send it? What is your goal, why do you send this packet in the first place?

 

Well, I realized that I don't need to send a packet to the server because the function "updateTick" of my block container (chest) affects both sides...

 

correct me if I'm wrong

 

thank you again ...

  • Author

In your Block updateTick actually only happens on the server.

 

then I right when I say "I don't need to send a packet to the server" .. and this is all i need to keep updated my inventory .. right?

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.