Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.

Posted (edited)

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
Posted

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

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