Jump to content

Recommended Posts

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

 

Posted (edited)

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
Posted

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

×   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



×
×
  • Create New...

Important Information

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