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

Hey all,

 

I am trying to return an ITextComponent from the client to the server again.

 

The reason I need to do this is so that I can use the i18n class to do some translations client side, and then send that message to the player server side. I have the bulk of it working, just need to figure out how to get a return from a packet.

 

My onMessage function

@Override
public IMessage onMessage(PacketRetrieveTileData message, MessageContext ctx) {
	TileEntityBlockBase tile = message.tile;
  	ITextComponent component = new TextComponentString("");
			
  	component.appendText("\n" + I18n.format("translate.key.here"));

  	// RETURN CHAT COMPONENT BACK TO PLAYER THAT SENT INITIAL PACKET

  	return null;
}

 

How I send the packet:

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
	if (!world.isRemote)
	{
		TileEntityBlockBase tile = world.getTileEntity(pos);
		
		// Tile entity null checks, etc, etc...
			PacketDispatcher.sendTileData(tile, (EntityPlayerMP) player); // <- Packet is sent here
	}

	return true;
}

 

I want to do something like this:

ITextComponent component = PacketDispatcher.sendTileData(tile, (EntityPlayerMP) player);

Is that possible? ^^

Edited by MSpace-Dev

  • Author

When a player right clicks a block, they get information about it outputted to the chat. I want that to accept all translations my mod supports.

 

I've tried to send a packet back, but I can not figure out for the life of me how to send it back to the same player that activated the block.

  • Author

I'm not sending IComponentText in my first packet, that gets constructed in the onMessage() function. I send my TileEntity in the first packet. Am I missing something here? Not sure what a Chat Packet is exactly

Edited by MSpace-Dev
typo

  • Author

Oh, never knew that class existed! That simplifies things so much more.

I was detecting right-click on the server -> sending a packet to client to get translated -> constructed ITextComponent -> to display to the player.

 

This is a much simpler option, thanks.

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.