Jump to content

[1.7.10] Send custom packets only to players who have the gui open


Recommended Posts

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

Posted

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.

Posted

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

Posted

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.

Posted

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) ?

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I made a custom pack, but i can't even load it, it just crashes at launcher, giving me Error 1. I looked at the log, and it just doesn't seem to tell me what the issue actually is. Here's the report.   at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:75) [modlauncher-10.2.4.jar!/:?] at SECURE-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapEntry.main(BootstrapEntry.java:17) [modlauncher-10.2.4.jar!/:?] at [email protected]/net.minecraftforge.bootstrap.Bootstrap.moduleMain(Bootstrap.java:188) [bootstrap-2.1.8.jar!/:?] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] at net.minecraftforge.bootstrap.Bootstrap.bootstrapMain(Bootstrap.java:133) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.Bootstrap.start(Bootstrap.java:53) [bootstrap-2.1.8.jar:2.1.8] at net.minecraftforge.bootstrap.ForgeBootstrap.main(ForgeBootstrap.java:19) [bootstrap-2.1.8.jar:2.1.8] Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: cpw.mods.cl.JarModuleFinder$JarModuleReference at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.MixinTransformationService.<init>(MixinTransformationService.java:62) ~[?:?] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[?:?] ... 12 more Caused by: java.lang.ClassNotFoundException: cpw.mods.cl.JarModuleFinder$JarModuleReference at java.base/jdk.internal.loader.Loader.loadClass(Loader.java:571) ~[?:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at cpw.mods.securejarhandler/net.minecraftforge.securemodules.SecureModuleClassLoader.loadClass(SecureModuleClassLoader.java:429) ~[securemodules-2.2.21.jar!/:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] at java.base/java.lang.Class.forName0(Native Method) ~[?:?] at java.base/java.lang.Class.forName(Class.java:421) ~[?:?] at java.base/java.lang.Class.forName(Class.java:412) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.InstrumentationHack.inject(InstrumentationHack.java:46) ~[?:?] at LAYER SERVICE/[email protected]+1.20.1/io.github.steelwoolmc.mixintransmog.MixinTransformationService.<init>(MixinTransformationService.java:59) ~[?:?] at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?] at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?] at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ~[?:?] ... 12 more [22:59:59] [main/INFO]:SpongePowered MIXIN Subsystem Version=0.8.7 Source=jar:file:///C:/Users/mxz/curseforge/minecraft/Install/libraries/org/spongepowered/mixin/0.8.7/mixin-0.8.7.jar!/ Service=ModLauncher Env=CLIENT
    • here is a different world https://ibb.co/Q3VWj9gW and the server console https://ibb.co/dwQf0qrR
    • Mods: Securitycraft Appleskin Architectury betterarchiology betterburning betterchunkloading borderlesswindow botarium cebonsapi cebonsbetterbeacons charmofundying chunkloaders clothconfig cofhcore connectivity coroutil create enchant industry create misc and things create create confectionery create new age forge create stuff additions creative core cupboard curios custom player models drinkbeer drippy loading screen durability tooltip easyanvils embeddium enderitemod entityculling fancymenufarmers delight ferrite core flux networks framed blocks fusion gecolib gravestone mod iceberg inventory profiles next jade jade addons jei journeymap jer konkrete kotlin libIPN lootintegrations lootr melody mes mns mss mvs nethersdelight nullscape nyfsquiver puzzleslib recipeessentials It seems the problem is with mods that place features as different worlds give different errors after the start part  
    • I get this error when joining my 1.20.1 forge 47.4.0 / also tested on 47.3.39. It then shows a long list of mods and errors (see image). No crash occurs. https://cdn.discordapp.com/attachments/324493105313349644/1354950353665265824/image.png?ex=67e7275a&is=67e5d5da&hm=4006cb062aa548c3aff108082bf4ea5e44d6ead972da3b23102b74ea95f54c7c&
    • in fact, after removing the lootr, the situation only got worse
  • Topics

×
×
  • Create New...

Important Information

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