Jump to content

Recommended Posts

Posted

Hi all,

 

I've been messing around with changing the player's size, and I've run into a snag: I can't seem to figure out how to get the player's in-game viewpoint to render at what should be their current eye height.

 

Changing player.eyeHeight has no visible effect (and, quite counter-intuitively, the value appears to be zero by default on the client anyway).

 

Then I found that Minecraft.getMinecraft().renderViewEntity is what determines the camera position and angle, but the docs say it's not suitable for changing the viewpoint mid-render. Indeed, when I changed the y position of the renderViewEntity during either render tick or render game overlay events, not only does the game bounce up and down, but the player also renders as floating above the ground by whatever value I set, which makes sense when I think about it because mc.renderViewEntity is likely just pointing to mc.thePlayer's memory location.

 

So my question is, what's a good way to alter the in-game render position without also affecting the player's render position?

 

Cheers,

coolAlias

Posted

Hi coolAlias

 

I think you may need to use reflection to modify the base class; the setting up of the viewpoint in EntityRenderer.setupCameraTransform and .orientCamera doesn't look like you can easily "intercept" it.

 

If you could find a way to add an extra GL11.glTranslatef after the setupCameraTransform and before the start of the rendering, that might do it.  Alternatively, you might be able to change the renderViewEntity to your own copy of the player, which you manually synchronise with the real player.  You're right that renderViewEntity refers to the player object, but perhaps it doesn't have to:

 

EntityRenderer.renderWorld:
        if (this.mc.renderViewEntity == null)
        {
            this.mc.renderViewEntity = this.mc.thePlayer;
        }

 

If necessary you might be able to change it immediately before render, then change it back immediately afterwards

 

-TGG

 

 

Posted

Thanks TGG, that sounds reasonable. To change the player's render size, I did sneak in an extra glScalef using RenderPlayerEvent.Pre and Post, but that didn't work for the render view. Too bad there isn't a Forge hook in EntityRenderer#orientCamera :P

 

Anyway, I'll post back here after I've had a chance to try your suggestion. Thanks again.

 

EDIT: I tried creating a new EntityClientPlayerMP as a sort of fake player copy, and that kind of worked - the viewpoint was indeed where I put it, but the camera angle was freaking out between two different views. The same thing happened when I used a dummy extended EntityLivingBase, suggesting that the renderview entity is switching back and forth between the one I'm setting and mc.thePlayer.

 

I set the fake entity at the start of the render tick (only if it is null do I create a new one), and tried both leaving it set and setting mc.renderViewEntity back to mc.thePlayer or null at tick end; neither way prevents the camera from freaking out which is strange, since the renderViewEntity should only be set in EntityRenderer when null. At any rate, lots of bad stuff happens when the renderViewEntity isn't an instance of EntityPlayer, so looks like it's time to try the first suggestion ;)

 

EDIT 2: Turns out the camera freaking out was because I forgot to set the previous positions... oops xD So actually the fake player / entitylivingbase works pretty well for changing the viewpoint, though 3rd person is still a bit jittery while walking. Using RenderPlayerEvent.Pre was still funky, but moving it to RenderGameOverlayEvent.Pre (for element type HELMET) works very well for 1st person, and avoids the camera shake in 3rd person (player movement is jittery).

 

Interestingly, I don't have to explicitly set the camera height and it just works, even though I set the fakePlayer.posY to mc.thePlayer.posY (after resizing thePlayer, but not ever changing the position [due to Illegal Stance rubbish - same with trying to use yOffset]).

 

However, as soon as I try to left-click, even air, it kicks me from the game with the following message:

"[WARNING] [Minecraft-Server] Player coolAlias tried to attack an invalid entity"

 

I tried to set the renderViewEntity back to mc.thePlayer for all overlays except the HELMET overlay, with the effect that clicking worked, but the camera was back to the original position.

 

For context, here is my current code:

 

Resizing of the player is done using Entity#setSize using either magnified or original width/height values. Size is changed only when the special item is equipped or unequipped.

 

OverlayEvent

 

  Reveal hidden contents

 

 

FakeClientPlayer (nothing in it really specifies client only, but whatever)

 

  Reveal hidden contents

 

Posted

It might be unstable if you changes the Camera Entity every time.

See EntityRenderer#orientCamera, which sets up the Camera.

You can see that 'f1' variable in the function is setting eye height,

and it was the entity's yOffset - 1.62F.

So you can do it by setting yOffset of the Entity!

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted
  On 4/6/2014 at 10:53 PM, Abastro said:

It might be unstable if you changes the Camera Entity every time.

See EntityRenderer#orientCamera, which sets up the Camera.

You can see that 'f1' variable in the function is setting eye height,

and it was the entity's yOffset - 1.62F.

So you can do it by setting yOffset of the Entity!

If only it were that simple. Changing the yOffset of the player results in the game crashing due to "an Illegal Stance" - that was the first thing I tried ;)

Posted
  On 4/6/2014 at 1:49 AM, coolAlias said:

However, as soon as I try to left-click, even air, it kicks me from the game with the following message:

"[WARNING] [Minecraft-Server] Player coolAlias tried to attack an invalid entity"

Do you think the look vector, or whatever the server thinks you're looking at needs to be modified?  The render stuff you're doing presumably is client side, but at some point you have to translate what you're looking at into server side and maybe that is getting mucked up?  Although I'm not sure why that would actually crash though, you think it would just think you're looking at the wrong thing and process as a proper left-click on whatever it thought you were looking at.

 

I don't have Minecraft on this computer, but can't you look up that error message in the code and maybe figure out where it is going wrong based on the location of that message?

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

Posted
  On 4/7/2014 at 5:19 AM, jabelar said:

  Quote

However, as soon as I try to left-click, even air, it kicks me from the game with the following message:

"[WARNING] [Minecraft-Server] Player coolAlias tried to attack an invalid entity"

Do you think the look vector, or whatever the server thinks you're looking at needs to be modified?  The render stuff you're doing presumably is client side, but at some point you have to translate what you're looking at into server side and maybe that is getting mucked up?  Although I'm not sure why that would actually crash though, you think it would just think you're looking at the wrong thing and process as a proper left-click on whatever it thought you were looking at.

 

I don't have Minecraft on this computer, but can't you look up that error message in the code and maybe figure out where it is going wrong based on the location of that message?

That is indeed the problem - Minecraft uses the renderViewEntity not just for camera position, but also for calculating various other things among which is the objectMouseOver (from EntityRenderer). Changing the renderViewEntity to my dummy entity living base works for changing the camera position, but breaks the mouse over calculations somehow, and probably breaks many other things as well that I have yet to notice.

 

It is possible to intercept mouse clicks, so it may also be possible to completely gloss over the vanilla objectMouseOver, using a custom one instead, but I am not a fan of that kind of solution in general.

 

One would think that adjusting the camera's render viewpoint would be a simple matter of adjusting a single Y value or the like, but it's turning out to be much more complicated than I expected >.<

 

Anyway, if I make any more progress on it, I will post it here. Until then, if anyone happens to know an easier way to accomplish this, I would be much obliged.

Posted

There is a mod that allows the player to morph into creatures and mobs, such as a bat. The mod author must surely have solved this issue. I wonder if the author would share his experience.

Posted
  On 4/7/2014 at 1:05 AM, coolAlias said:

  Quote

It might be unstable if you changes the Camera Entity every time.

See EntityRenderer#orientCamera, which sets up the Camera.

You can see that 'f1' variable in the function is setting eye height,

and it was the entity's yOffset - 1.62F.

So you can do it by setting yOffset of the Entity!

If only it were that simple. Changing the yOffset of the player results in the game crashing due to "an Illegal Stance" - that was the first thing I tried ;)

 

You can do that by setting yOffset on Render Tick Start, and return it to original yOffset on Render Tick End.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted
  On 4/7/2014 at 9:15 AM, Abastro said:

You can do that by setting yOffset on Render Tick Start, and return it to original yOffset on Render Tick End.

Well look at that, so you can! :D hahaha, though it has the hilarious side effect of keeping the same bounding box for collisions, so most of the player's body is in the ground with just his giant head sticking out - at least it doesn't crash when I click on stuff xD

 

I could have sworn I tried setting the yOffset back to normal, but apparently I didn't, at least not every tick. Thanks for the tip!

 

EDIT: Actually, that doesn't work for changing the viewpoint of the camera - it actually ends up moving to the player's posY (not even normal eye height!), even after changing player.eyeHeight. The player's bounding box is correct, since I do not fall through the ground and cannot walk under trees and such (I made the player about 4-5 blocks tall), and I can easily fix the rendering of the player to match the bounding box position, but the camera stays at the ground... Looks like it's back to square one :(

 

@sequituri - iChun's Morph mod is indeed open source, and I've seen a video where the eye height moves higher or lower, so he certainly figured out how to do it. Hopefully it's not some crazy complicated mechanism like the rest of his code :P I'll have to poke around in there and see if I can find it.

Posted

I'm not at a computer with Minecraft source on it right now, but have you looked at the code for when you change the viewpoint in vanilla Minecraft when you press F5?  If that can move the camera to behind / in front / or "in" your player while retaining all other gameplay, it seems that has got to give you some sort of clue.

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

Posted
  On 4/8/2014 at 4:00 AM, jabelar said:

I'm not at a computer with Minecraft source on it right now, but have you looked at the code for when you change the viewpoint in vanilla Minecraft when you press F5?  If that can move the camera to behind / in front / or "in" your player while retaining all other gameplay, it seems that has got to give you some sort of clue.

The code for third person view just moves the camera to the looking direction, so it cannot give any clue for this case.

 

Btw, I think the ASM is necessary for this case.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted
  On 4/8/2014 at 5:57 AM, Abastro said:

The code for third person view just moves the camera to the looking direction, so it cannot give any clue for this case.

 

Btw, I think the ASM is necessary for this case.

 

But isn't moving the camera pretty much what he's hoping to do?  Just move it to where the eyes are supposed to be, right?  If you can move it "to the looking direction" you should be able to figure out how to move it elsewhere.

 

In particular, if you look at the orientCamera() method of the EntityRenderer class, the description of the method says "sets up player's eye (or camera in third person mode)".  In fact the code for orientCamera() method includes changing camera for debug camera mode, for sleeping in bed, third person, etc.

 

So why isn't the OP's desire to move camera to different "eye height" pretty much the same as having a debug camera that is just at same level as the model's eye?

 

Here is the code from the orientCamera() class.  It seems to have a lot of examples of controlling the camera:

 

  Reveal hidden contents

 

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

Posted

@jabelar You're correct that orientCamera is where F5 (i.e. 3rd person mode) and other camera-related effects are handled, but it's useless to me without using ASM as there is no Forge hook called from within that method (other than one for sleeping, for some reason). What this means is that trying to change any of the camera values from anywhere else will not have any effect since they are all handled locally within that method. Changing the player / render view entity's actual position or yOffset does have an effect, since that can be updated at any time before the camera orientation is determined, as has been mentioned and attempted.

 

@coolboy4531 Indeed he did, and I still need to do a more thorough study of his code and see if it's a simple solution or not. iChun's Morph mod is a real work of coding genius, to say the least :P I'm hoping it's not over my head lol.

 

In other news, I found out why using a dummy render view entity screws up object mouse over / left-click:

List list = this.mc.theWorld.getEntitiesWithinAABBExcludingEntity(this.mc.renderViewEntity, this.mc.renderViewEntity.boundingBox.addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand((double)f1, (double)f1, (double)f1));

 

Since the renderViewEntity is supposed to be the player, normally the player is excluded from the list of potential targets, but with the dummy entity, the player is included. Now it makes sense why I was getting "Invalid entity" errors - the player can't attack himself!

Posted
  On 4/9/2014 at 7:13 AM, coolAlias said:

@jabelar You're correct that orientCamera is where F5 (i.e. 3rd person mode) and other camera-related effects are handled, but it's useless to me without using ASM as there is no Forge hook called from within that method (other than one for sleeping, for some reason). What this means is that trying to change any of the camera values from anywhere else will not have any effect since they are all handled locally within that method.

 

Yeah, I figured would be hard to intercept this vanilla code if it didn't have the hooks.  Also, yeah it is wierd that sleeping case does have a hook.  Do think there is any hacky way to intercept the sleeping case?  Like what if you set the player as "sleeping" even though they weren't and then took control of the camera?

 

  Quote
iChun's Morph mod is a real work of coding genius, to say the least :P I'm hoping it's not over my head lol.

 

I do have to say that that guy is a real programmer -- does some sophisticated stuff and apparently is pretty confident doing it.

 

I noticed that in his ModelMorph() class he has a render() method in which he has this one line (line #202) that looks related to maybe what you're trying to do:

 

  Reveal hidden contents

 

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

Posted

Alright, I've gotten a solution from Noppes that I've modified to suit my needs. It involves extending EntityRenderer and switching to the alternate one when needed, and after changing some stuff I got it to return a correct mouse over object as well.

 

For those who may be interested in this particular solution, here is the current code. Lots of hard-coded stuff at the moment, but it works fairly well.

 

EntityRendererAlt

 

  Reveal hidden contents

 

 

RenderTickEvent / Handler

 

  Reveal hidden contents

 

 

RenderPlayerEvent

 

  Reveal hidden contents

 

  • Thanks 1

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



×
×
  • Create New...

Important Information

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