It is currently January 21st, 2018, 10:22 am


All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Using emoticons in fCraft
PostPosted: September 10th, 2012, 4:02 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
This is a quick tutorial on how to get emoticons to work on fCraft

First things first, you need to allow bytes 1 - 31 in LineWrapper.cs (ignore byte 0, it is null)
In LineWrapper.cs, find bool IsWordChar and replace with

Code:
static bool IsWordChar(byte ch)
        {
            return (ch > (byte)' ' && ch <= (byte)'~') || (ch >= (byte)1 && ch <= (byte)31);
        }


Now visit Chat.cs in the player folder. At the top of the file, add
Code:
static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();


Now add these functions. I will comment them so you know what is going on.

Code:
#region Emotes
        public struct EmoteData //Contains all data needed for the emotes. Emote is the trigger word,
            //example (bullet). ID is the byte value of the char
        {
            public string Emote;
            public byte ID;
        }

        //this list will be loaded with the list of emotes and their replacement values
        static List<EmoteData> EmoteTriggers = null;

        //a method to add all the emotes into EmoteTriggers. You can add your own triggers here
        static void AddEmotes()
        {
            EmoteTriggers = new List<EmoteData>();
                EmoteTriggers.Add(new EmoteData() { Emote = "(darksmile)", ID = 1 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(:))", ID = 1 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(smile)", ID = 2 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(:P)", ID = 2 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(heart)", ID = 3 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(<3)", ID = 3 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(diamond)", ID = 4 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(bullet)", ID = 7 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(hole)", ID = 8 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(male)", ID = 11 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(female)", ID = 12 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(sun)", ID = 15 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(right)", ID = 16 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(>)", ID = 16 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(left)", ID = 17 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(<)", ID = 17 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(double)", ID = 19 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(half)", ID = 22 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(uparrow)", ID = 24 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(^)", ID = 24 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(downarrow)", ID = 25 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(rightarrow)", ID = 26 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(up)", ID = 30 });
                EmoteTriggers.Add(new EmoteData() { Emote = "(down)", ID = 31 });
        }

        //this is the main method. This parses the emotes, correct glitches and makes the emotes safe to display
        public static string ParseEmotes(string rawMessage, bool SentencePart)
        {
            if (EmoteTriggers == null){ //until a message is made, the list is null, so fill it up here
                AddEmotes();
            }
            byte[] stored = new byte[1]; //this byte represents the emoticon, to be used in GetString(
                foreach(EmoteData ed in EmoteTriggers){ //scroll through the emotes, replacing each trigger word with the emote
                    string s = ed.Emote; //s is the emote trigger
                    stored[0] = (byte)ed.ID; //stored is the byte char for the emote
                    string s1 = enc.GetString(stored); //s1 is the emote
                    if (rawMessage.Contains(s)){
                        switch (ed.ID){ //this fixes glitches. Each ID appends a ' to resolve overlapping of letters
                            case 7:
                            case 12:
                            case 22:
                            case 24:
                            case 25:
                                s1 = s1 + "-";
                                break;
                            case 19:
                                s1 = s1 + "' ";
                                break;
                            default: break;
                        }
                        if (!SentencePart) //if sentence being parsed definately ends with no following text (not a displayedname, ect)
                        {
                            if (rawMessage.EndsWith(s))
                            {
                                s1 = s1 + "."; //append a period. A emoticon ONLY shows if some text follows the emoticon (excluding a blank space)
                            }
                        }
                        rawMessage = rawMessage.Replace(s, s1); //replace the triggerword with the emoticon
                    }
                }
            return rawMessage; //return the new sentence
        }

        #endregion


Now all you need to do is hook the main method onto your desired chat room. Example, if you want emoticons to work in global chat, then add

Code:
rawMessage = ParseEmotes(rawMessage, false);


into void SendGlobal

Image

_________________
You cannot use certain BBCodes: [img].


Last edited by Jonty800 on September 11th, 2012, 10:01 pm, edited 1 time in total.

Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: September 11th, 2012, 8:16 pm 
SupOP

Joined: June 24th, 2011, 10:27 pm
Posts: 314
Why do you need the lock when EmoteTriggers is never modified after you add the triggers?


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: September 11th, 2012, 10:00 pm 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
I don't actually know. I wrote it just in case someone was trying to read the list while another player was adding to it, even though the chance of that happening is an extreme rarity since the list is only modified once. I guess I'll remove the locks.

_________________
You cannot use certain BBCodes: [img].


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: September 15th, 2012, 2:13 am 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
Emoticons are highly unstable.

When used in a server message, they kick everyone in the server who sees it and java throws an exception.

DO NOT USE THIS CODE.

I'll leave it here in case someone finds the safe conditions for them

_________________
You cannot use certain BBCodes: [img].


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: September 15th, 2012, 3:06 am 
User avatar

Joined: May 24th, 2011, 1:37 am
Posts: 329
Location: Sealand
I remember joining a server a while back that had proper emoticon support, and I jumped 20 feet in the air when I saw a heart in chat -- I wonder how they might've done it, and which software they were running. It would help if I remembered which server it was in the first place, I suppose.

_________________
<CMB> KingCrab72: Some mixture and contrast would be nice tbh Ollie
<Ollieboy> Some mixture and contrast of your face on my penis would also be nice


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: September 15th, 2012, 3:14 am 

Joined: August 21st, 2011, 6:31 am
Posts: 280
Location: United Kingdom
They seem to work fine in the chat, but when its your displayedName and you kick someone, the entire server disconnects one by one.

Strange.

Edit: Also, (bullet) makes Hexchat / xchat ping O.o

_________________
You cannot use certain BBCodes: [img].


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Using emoticons in fCraft
PostPosted: October 3rd, 2012, 7:57 pm 
fCraft Developer
User avatar

Joined: May 21st, 2011, 10:53 pm
Posts: 1386
An official implementation of emotes in Minecraft is coming soon.

EDIT: And done.


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net