Jump to content

[1.7.10] Have a mod installed clientsided only, call server events


Recommended Posts

Posted

Basically I started this thread over here:

http://www.minecraftforge.net/forum/index.php/topic,22260.0.html

 

Basically what I'd like to do is intercept usernames and change them. Clientsided ONLY. The mod is not going to be installed on the server.

If you read towards the few replies in the end of the thread you'll understand what problems this causes.

 

I'd like an explanation of how this can be solved as I really have no idea. Using reflection on entityplayer didn't work.

Maybe there is another event than NameEvent that you can tie into to change the display names? I have no idea.

 

Posted

PlayerEvent.NameFormat seems like exactly what you're looking for but you seem against that in the previous thread from what I've read.

 

I don't actually think reflection would help you at all here (not with displayname) because NameFormat gets fired every time getDisplayName or refreshDisplayName is called, I believe, which is exactly the same as changing displayname through reflection.

 

This should affect scoreboards etc (though only on your client, other people on the server will see the normal username)

 

If it doesn't, what you can try to do is to intercept every time a GUI that contains the name is opened (Player list when you press TAB, chat, scoreboard, etc.) and then replace it with your own GUIScreen that extends the type you're trying to intercept, with your own code in the places you need it, though this seems like a whole lot of extra work and could potentially break compatibility with any other mods trying to do the same thing.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

PlayerEvent.NameFormat seems like exactly what you're looking for but you seem against that in the previous thread from what I've read.

 

I don't actually think reflection would help you at all here (not with displayname) because NameFormat gets fired every time getDisplayName or refreshDisplayName is called, I believe, which is exactly the same as changing displayname through reflection.

 

This should affect scoreboards etc (though only on your client, other people on the server will see the normal username)

 

If it doesn't, what you can try to do is to intercept every time a GUI that contains the name is opened (Player list when you press TAB, chat, scoreboard, etc.) and then replace it with your own GUIScreen that extends the type you're trying to intercept, with your own code in the places you need it, though this seems like a whole lot of extra work and could potentially break compatibility with any other mods trying to do the same thing.

I'd love to use nameformat, but it only fires on the server? If you read the thread my code works properly, but if I try it out on a multiplayer server my events just refuse to fire.

Posted

I tested it, it seems that's true.

 

I'm doing some testing now to try and find a way to do this, I'll tell you if I find anything.

 

So far I've tried reflection on the Minecraft.getMinecraft player, and reflection on the GameProfile too. No results yet.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

I tested it, it seems that's true.

 

I'm doing some testing now to try and find a way to do this, I'll tell you if I find anything.

 

So far I've tried reflection on the Minecraft.getMinecraft player, and reflection on the GameProfile too. No results yet.

Thank you!

If you figure it out it would be nice if you also include the code as that makes it much easier for me to understand. Having some code to reference when reading how someone did it is always helpful.

Posted

I have not had much luck yet. I'm sure there's an easy solution but I can't find it, and I'm too tired to keep checking. I suggest you set up some break-points in places you think might have to do with how certain of the GUIs get the name and trace it to a point you can easily change.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Posted

I have not had much luck yet. I'm sure there's an easy solution but I can't find it, and I'm too tired to keep checking. I suggest you set up some break-points in places you think might have to do with how certain of the GUIs get the name and trace it to a point you can easily change.

 

I'll have a look into intercepting every GUI call... But those are many places. Anyway, I doubt I'll even be done with it today since I don't have much time left. Friends coming over and stuff.

And having someone else look at it is probably a good idea too.

Posted

You could give FMLNetworkEvent.ClientCustomPacketEvent a go. I haven't looked into it, but I'd assume chat messages, and the score board would update using packets.

 

This will allow you to control both the packet that was received, and change the reply so that you might even get away with other clients seeing it the way you want to (as the server will get your information, and relay it to all other clients).

 

Edit: Nevermind, that's only for custom packets. I misread, sorry.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm sure this entire community knows exactly who you are, what mixin you're talking about, and how deer function in minecraft.  But being new here, and I am ignorant about all of those things. That said, I'd love to review your mixin.  I'm also having mixin issues, and I feel that if I can help you, perhaps both of our problems might get solved. Can you provide some links and context for people who aren't aware of your renown?  I'm asking humbly because I know you probably have better things to do, and you just want somebody to fix things for you.
    • I am working in the latest MDK.  Minecraft 1.21.4, Forge 54.1.0. I am trying to create a mixin.  The implementation doesn't matter.  Assume it is doing nothing more than logging to the console: @Mixin(LevelRenderer.class) public abstract class LevelRendererMixin { private static final Logger LOGGER = LogManager.getLogger("LevelRendererMixin"); @Inject(method = "renderLevel", at = @At("TAIL")) private void onRenderLevel( com.mojang.blaze3d.resource.GraphicsResourceAllocator allocator, net.minecraft.client.DeltaTracker deltaTracker, boolean someFlag, Camera camera, GameRenderer gameRenderer, Matrix4f matrix1, Matrix4f matrix2, CallbackInfo ci ) { Assuming my whole implementation is just to write something to console, it works perfectly fine in when I debug (runClient) in IntelliJ.  Whenever the Minecraft `renderLevel` runs every frame, my logging is overlaid at "TAIL". Yes, this spams the sht out of the console. But when I `build` and use the jar as a mod, it does not.  The mixin annotation processor shows to be loading, and my other parts of my mod work, but the nothing gets logged by my mixin. I am apparently generating a proper `refmap` and it's in the jar root.  Other files are also in the jar appropriately, including mods.toml.  And all the naming and reference paths are correct. I had to add this to my build.gradle to get my refmap into the jar ([name] obviously replaced): tasks.register("copyRefmap", Copy) { dependsOn tasks.named("compileJava") from("${project.buildDir}/tmp/compileJava") { include "mixins.[name].refmap.json" } into("${project.buildDir}/resources/main") } tasks.named("processResources", ProcessResources).configure { dependsOn(tasks.named("copyRefmap")) } tasks.named("jar", Jar).configure { // Include the generated refmap from build/resources/main into the jar. from("${project.buildDir}/resources/main") { include "mixins.[name].refmap.json" } }   Just for fun, here is my refmap in case something looks wrong to anybody:   { "mappings": { "com/[name]/mixin/LevelRendererMixin": { "renderLevel": "Lnet/minecraft/client/renderer/LevelRenderer;m_109599_(Lcom/mojang/blaze3d/resource/GraphicsResourceAllocator;Lnet/minecraft/client/DeltaTracker;ZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V" } }, "data": { "searge": { "com/[name]/mixin/LevelRendererMixin": { "renderLevel": "Lnet/minecraft/client/renderer/LevelRenderer;m_109599_(Lcom/mojang/blaze3d/resource/GraphicsResourceAllocator;Lnet/minecraft/client/DeltaTracker;ZLnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/GameRenderer;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V" } } } } TLDR; My mixin works in dev, but not when built and run in an official Forge/Minecraft environment.  Like it's not overlaying/replacing the minecraft function. What are some typical other things to check when a mixin works in dev, but not after build?
    • Thank you, Ugdhar.  But that only confirms the problem.  Both in the github and in my IDE, if I search for objects extended from net.minecraftforge.client.event, it isn't there.  Though the javadocs (at least at nekoyue) say it should be. Maybe since it definitely isn't there, is there some other way anybody knows to highlight some blocks (without mixins and drawing artificial faces on the camera).
    • Please read the FAQ for how to properly post logs.   Also, this is a fabric log, not a forge log, you would probably get better results posting where fabric support is given.
  • Topics

×
×
  • Create New...

Important Information

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