Jump to content

[1.12.2] Return object from packet


MSpace-Dev

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

×
×
  • Create New...

Important Information

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