Jump to content

Recommended Posts

Posted

Okay, I think the next step would be to intercept what the client code regarding names.  Name format is funny because it isn't really cancelable anyway but instead you just change the field value to what you want.  Like for a funny example in my event tutorial I suggested putting the following in the NameEvent to change the way names are displayed:

if (event.username == "myUserName") // put your user name in the string
{
    event.displayname = event.username+" the Great and Powerful";
}        
else if (event.username == "myFriendsUserName") // put your friend's user name in the string
{
    event.displayname = event.username+" the Wise";
}    
else if (event.username == "myGirlFriendsUserName") // put your significant other's user name in the string
{
    event.displayname = event.username+" the Beautiful";
}    
else
{
    event.displayname = event.username+" the Ugly"; // for everyone else            
}

 

The comments say the following about the NameFormat event:

 

This event is fired whenever a player's name is retrieved in

    * EntityPlayer#getDisplayName() or EntityPlayer#refreshDisplayName().<br>

    * <br>

    * This event is fired via the {@link ForgeEventFactory#getPlayerDisplayName(EntityPlayer, String)}.<br>

    * <br>

 

If you follow the call hierarchy, all of this just updates a field in EntityPlayer called displayName.  It is private, but you can change it with Java reflection I think.

 

So what if you did a ClientTickHandler and used Java reflection to inspect and modify (if necessary) the displayName field?

 

I think this would still be limited to Client, so if you want other users to see the effect they'd have to use the mod too probably.

 

If that doesn't work, I think you'd have to try to intercept the chat and the player rendering where they display names.

 

Just intercepting it in chat would be a last rescue thing. Since I want the displayname to change everywhere, scoreboards, tab, etc etc. Anyway, If there is no other we I guess I'll have to modify everything seperately.

 

The thing is, this forge modding is already hard for me and I only have some basic java knowledge.

 

So what if you did a ClientTickHandler and used Java reflection to inspect and modify (if necessary) the displayName field?

 

And I really have no idea how to do the reflection part. There are tutorials on the tickhandler but I can't find a suitable one for reflection. I mean, there surely are some but none seem to be giving me this information. Maybe you can link me to a good one?

Posted

So I adventured down through the minecraft code all the way down.

I eventually ended up in minecrafts EntityPlayer class.

Anyway, how can I know which field is which? Since minecraft even decompiled has fields like this "field_151432_d". I can't access a field if I don't know which one to access.

This is my code for modifying it for now, obviously won't work for above reason.

 

    @Subscribe
    public void everyTick(TickEvent everyTick){

        EntityPlayer privateObject = new EntityPlayer("The Private Value") {
        };

        Field displayNameField = EntityPlayer.class.
                getDeclaredField(displayName);

        displayNameField.setAccessible(true);

        String fieldValue = (String) privateStringField.get(privateObject);
    }

 

 

EDIT:

I had BedrockMiner try to accomplish this, but unfortunately it is impossible to modify for some reason. I am going to start a new thread concering this issue in specific, anyway thanks for all the help I got with proxies. Now I understand a proxy is pretty much useless for me since the mod will only be installed on one side.

 

Link to new thread: http://www.minecraftforge.net/forum/index.php/topic,22449.0.html

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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