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

I'm trying to send GUI-only things (like progress bar update or energy stored) with a custom packet only to player who have the gui open.

 

Obviously I can do this:

for (playersWithGuiOpen)
    PacketHandler.INSTANCE.sendTo(new myCustomMessage(), playerWhoHaveTheGuiOpen);

 

but from my tile I don't know the players, so I decided to use my container:

///////////////Inside myTile/////////////////////
protected void syncMachine() {
    container.sendMessageToCrafters(new MessageTile(this));
    markDirty();
}

/////////////Inside myContainer//////////////
public void sendMessageToCrafters(IMessage message) {
        for (Object crafter : this.crafters) {
            EntityPlayerMP player = (EntityPlayerMP) crafter;
            if (player != null) {
                PacketHandler.INSTANCE.sendTo(message, player);
            }
        }
}

 

But this code works fine with just a player (this.crafters contains just a player even there are three different players with the gui open),  if I use open to LAN feature and I join with other different players, only the last player who opened the gui is updated.

 

Basically I need to sync only the players who have the gui open, so I can't use "PacketHandler.INSTANCE.sendToAllAround" but I need to use "sendTo". The problem is that I don't know the players who need to be updated.

 

I hope I made it clear.  :)

This should probably be done from your override of

Container#detectAndSendChanges

. Look at how

ContainerFurnace

uses this to send progress updates for the burn/cook time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

This should probably be done from your override of

Container#detectAndSendChanges

. Look at how

ContainerFurnace

uses this to send progress updates for the burn/cook time.

I fixed my post, I submitted it uncompleted

Container#crafters

is a list of

ICrafting

objects, it may contain implementations of

ICrafting

other than

EntityPlayerMP

. It's not safe to cast to

EntityPlayerMP

without checking.

 

Every player with the GUI open will have their own

Container

on the client and server, so

Container#crafters

will usually contain 0 players on the client and 1 player on the server.

 

Your

TileEntity

shouldn't interact with your

Container

directly, it certainly shouldn't be storing an instance of it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Container#crafters

is a list of

ICrafting

objects, it may contain implementations of

ICrafting

other than

EntityPlayerMP

. It's not safe to cast to

EntityPlayerMP

without checking.

 

Every player with the GUI open will have their own

Container

on the client and server, so

Container#crafters

will usually contain 0 players on the client and 1 player on the server.

 

Your

TileEntity

shouldn't interact with your

Container

directly, it certainly shouldn't be storing an instance of it.

Ok, so is better if inside Container#detectAndSendChanges I get the message from the tile (if it is changed) and send it to crafter (checking if is a player) ?

Container#crafters

is a list of

ICrafting

objects, it may contain implementations of

ICrafting

other than

EntityPlayerMP

. It's not safe to cast to

EntityPlayerMP

without checking.

 

Every player with the GUI open will have their own

Container

on the client and server, so

Container#crafters

will usually contain 0 players on the client and 1 player on the server.

 

Your

TileEntity

shouldn't interact with your

Container

directly, it certainly shouldn't be storing an instance of it.

Ok, so is better if inside Container#detectAndSendChanges I get the message from the tile (if it is changed) and send it to crafter (checking if is a player) ?

 

Yes, that should work.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.