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 have a TileEntity with a custom capability that changes the texture. I have a GUI where the texture can be changed.

When the texture is updated, I would like to send a message to any player in the area to re-render the TileEntity with the new texture.

I have a message with the required information, but how do I send it?

NETWORK.send( PacketDistributor.???.with( () -> ??? ), new UpdateConfigMessage( pos, this ) )

 

You might find this working example useful

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe60_network_messages

 

 The relevant bit is 

StartupCommon.simpleChannel.sendToServer(airstrikeMessageToServer);

in ItemAirStrike class

and for sending to clients

 

  // This message is called from the Server thread.
  //   It spawns a random number of the given projectile at a position above the target location
  static void processMessage(AirstrikeMessageToServer message, ServerPlayerEntity sendingPlayer)
  {
    // 1) First send a message to all other clients who are in the same dimension, to tell them to render a "target"
    //      effect on the ground
    // There are a number of other PacketDistributor types defined for other cases, for example
    // Sending to one player
    //    simpleChannel.send(PacketDistributor.PLAYER.with(playerMP), new MyMessage());
    //
    // Send to all players tracking this chunk
    //    simpleChannel.send(PacketDistributor.TRACKING_CHUNK.with(chunk), new MyMessage());
    //
    // Sending to all connected players
    //    simpleChannel.send(PacketDistributor.ALL.noArg(), new MyMessage());

    TargetEffectMessageToClient msg = new TargetEffectMessageToClient(message.getTargetCoordinates());
    RegistryKey<World> playerDimension = sendingPlayer.func_241141_L_();  // func_241141_L_ is getPlayerDimension
    StartupCommon.simpleChannel.send(PacketDistributor.DIMENSION.with(() -> playerDimension), msg);

 

-TGG

Edited by TheGreyGhost
cut short

  • Author

It doesn't quite work - I don't have access to the player. But I can access the TileEntity that the capability is attached to.

	public TileEntityReinforcedChest()
	{
		super( BetterStorageTileEntityTypes.REINFORCED_CHEST.get() );
		config = new HexKeyConfig()
		{
			@Override
			protected void onContentsChanged( int slot )
			{
				TileEntityReinforcedChest.this.markDirty();
				BetterStorage.NETWORK.send( PacketDistributor.DIMENSION.with( () -> ??? ), new UpdateConfigMessage( pos, this ) );
			}
		};
	}

 

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.