Jump to content

Recommended Posts

Posted

While working on my spell-casting entity, I got the spell to render in front of the main entity, but I noticed that its position was not always correct, nor would it ever change position as the main entity turned or moved. This got me thinking and printing stuff to the screen, and I discovered that for the entire time while my spell was rendering (about 20 ticks), the entity's look vector, rotationYaw, and the yaw parameter passed to the doRender method did not ever change.

 

Here's the relevant sections of my entity's render code:

 

// this render class extends RenderLiving
@Override
public void doRender(Entity entity, double dx, double dy, double dz, float yaw, float partialTick) {
	super.doRender(entity, dx, dy, dz, yaw, partialTick); // renders the caster, nothing special here
	if (shouldRenderSpell) {
		renderSpell((EntityCaster) entity, dx, dy, dz, yaw, partialTick);
	}
}

private void renderSpell(EntityCaster caster, double dx, double dy, double dz, float yaw, float partialTick) {
	GL11.glPushMatrix();
	// alpha and stuff
	Vec3 look = caster.getLookVec();
	double vecX = (double)(-MathHelper.sin(caster.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(caster.rotationPitch / 180.0F * (float) Math.PI));
	double vecZ = (double)(MathHelper.cos(caster.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(caster.rotationPitch / 180.0F * (float) Math.PI));
	LogHelper.info("Rendering yaw: " + yaw + " | vecX: " + vecX + " | vecZ: " + vecZ + " | look vector: " + look);
	GL11.glTranslated(dx + vecX, dy + caster.getEyeHeight(), dz + vecZ); // should always be right in front of the caster, but isn't
	// GL11.glTranslated(dx + look.xCoord, dy + caster.getEyeHeight(), dz + look.zCoord); // same poor results
	GL11.glScalef(scale, scale, scale);
	float roll = ((float) caster.getCurrentCastingTime() + partialTick) * 40;
	while (roll > 360) roll -= 360;
	// this stuff all works for rendering the spell spinning around in place
	GL11.glRotatef(yaw, 0, 1, 0);
	GL11.glRotatef(roll, 0.8F, 0F, -0.6F);
	bindTexture(caster.getType().getEntityTexture());
	// etc., nothing interesting after this
}

 

 

Here is some sample output from my logging:

 

[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
[22:20:48] [ZeldaSwordSkills] [iNFO] Rendering yaw: -26.71875 | vecX: 0.4496113359928131 | vecZ: 0.89322429895401 | look vector: (0.44969695806503296, 0.0, 0.8931812047958374)
// Goes on exactly the same for quite some time
[22:20:52] [server thread/INFO]: Saving and pausing game...
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/Overworld
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/Nether
[22:20:52] [server thread/INFO]: Saving chunks for level 'Dungeons'/The End
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
[22:21:09] [ZeldaSwordSkills] [iNFO] Rendering yaw: -7.03125 | vecX: 0.12241067737340927 | vecZ: 0.9924795627593994 | look vector: (0.12250582873821259, 0.0, 0.9924678206443787)
// and again, stays exactly the same the entire render cycle
[22:21:12] [server thread/INFO]: Saving and pausing game...

 

 

So I'm curious: if the caster turns, should not his look vector change to match, or at least the caster's rotationYaw as I clearly can see the caster rotating on the screen, so the client is obviously aware of the current rotationYaw, and how is the 'yaw' parameter from the doRender method determined / why would it be identical for over 20 ticks straight?

 

Thanks for any tips,

 

coolAlias

Posted

I've been doing some debugging and here's what I've discovered:

 

The parameters to RenderLiving#doRender(dx, dy, dz, yaw, partialTick) are apparently all relative to the player. dy is usually -1.6200..., becoming more negative if you jump, and both dx and dz appear to be the difference between the entity and the player's position (which implies that dy is also the difference in y position).

 

I'm not sure yet how yaw is determined, but it is not affected by the player's rotation at all - the player spinning around in circles did not change the yaw parameter in the entity's doRender call. In fact, during my last test it stayed exactly at -21.09375 the entire game session... no matter where I stood, which way the spell-casting entity was facing, nothing changed it. I'm at a loss with this one.

 

I still have no idea why the entity's rotationYaw and look vector remain the same for such extended periods of time, either. I can see the entity turning this way and that on the screen, but apparently the rotationYaw is somehow disconnected from it.

 

Needless to say, what I've found is not at all what I expected. Am I missing something glaringly obvious? As it is, I don't see how any object could possibly be rendered in front of an entity, if the parameters are always relative to the on-looking player(s), but clearly it IS possible.

Posted

Hi

 

Some guesses from me-

Maybe yaw is no longer used (and the name might be wrong/misleading too)

 

Have you looked at renderYawOffset instead of just rotationYaw?  Vanilla seems to use it for setting model rotations.

 

-TGG

 

 

Posted

@TGG Yes, I looked at the renderYawOffset and a host of other fields as well. No dice :P

 

Anyway, shortly after realizing what the dx/dy/dz parameters were, I was able to come up with a solution:

Vec3 vec3 = Vec3.createVectorHelper(dx, dy, dz).normalize();
GL11.glTranslated(dx - vec3.xCoord, dy + caster.getEyeHeight(), dz - vec3.zCoord);

 

This renders the spell perfectly in front of the caster's eyes, though I am not yet sure how well it will work if there are a bunch of players all looking at the entity from different angles... whatever, it looks great in single player, at least! xD

Posted

Interesting.  I've always found look vector trustworthy, but admit I mostly use it for the player not for other entities.  I'll have to try that...

 

I'm also wondering about your statement that "I clearly see the caster rotating on the screen".  One thing to think about is that the actual head of some entities moves independent of the body.  I'm not sure about your entity, but I can see a case where the yaw and look vector were based on the body rotation but not the head.

 

Similarly, if you looked at the rendering / model of the caster itself i *must* have a field that is controlling the rotation of the render so it seems you should be able to hook onto that.

 

Anyway, it seems you have a work around, but like you I hate having something that is not fully understood in my code...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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 need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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