Jump to content

[1.7.10] Changing the camera - how to force 3rd person view


Thornack

Recommended Posts

Hi Everyone

 

I have been researching how to change the camera (things like zoom, camera height, position, yaw, roll, pitch etc etc) and have found very little information about it. Apparently it is fairly difficult. I was wondering if anyone has any experience in this. I want to do some custom camera manipulation (force third person and change the zoom level and camera positions) and also I want to force third person view. I currently have figured out how to change the players model (dont know how to change hitbox yet but im working on that) and I need a way to force the camera view to be always third person  when the player has this different model and to have a different zoom than the default since my model is fairly large. Does anyone know where to look/ how to achieve this/has any input?

Link to comment
Share on other sites

Hm, I don't have experience with it but, I would think you'd need to look at the keybinding for changing the camera view and figure out how the game does it. Then, when the model is changed, force the view by changing it as if they pressed F5 then, disable that key until the player changes back.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

I think maybe you can just change Minecraft.getMinecraft().gameSettings.thirdPersonView. You'd need to do this on client side only.

 

EDIT: Actually I tried that and it sort of works, but it makes it look like the player is hovering in the air for some reason.

 

Okay, maybe you should check out this thread here: http://www.minecraftforge.net/forum/index.php?topic=17968.0

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

Link to comment
Share on other sites

When you run while the player looks like he's hovering, does the particles for the ground display? In that case it could be the texture is being misplaced?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Do you know what package the actual code for toggling the camera perspective is in. I found in the game settings the registration for the key  this.keyBindTogglePerspective = new KeyBinding("key.togglePerspective", 63, "key.categories.misc");

Link to comment
Share on other sites

That is where it is registered yes but where is the logic that says (whenever this key is pressed change the view of the camera)

 

In Eclipse, select that field and right-click and choose Call Hierarchy. It will tell you everywhere it is used.

 

interestingly, in 1.8 I tried to put the following into the PlayerTickEvent handler:

		EntityPlayer thePlayer = event.player;
	World world = thePlayer.worldObj;

	if (world.isRemote)
	{
    	Minecraft.getMinecraft().gameSettings.thirdPersonView = 2;
    	// thePlayer.posY -= thePlayer.eyeHeight;
	}

 

And the position is correct but it displays a girl skin instead of the "steve" normal skin!

 

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

Link to comment
Share on other sites

Hmm Ya thats what I tried also but im in 1.7.10.

 

I found this in the vanilla code

 

/**
     * Runs the current tick.
     */
    public void runTick()
    {
//.... A lot of stuff... then this
    if (this.gameSettings.keyBindTogglePerspective.isPressed())
                        {
                            ++this.gameSettings.thirdPersonView;

                            if (this.gameSettings.thirdPersonView > 2)
                            {
                                this.gameSettings.thirdPersonView = 0;
                            }
                        }

//...Alot more stuff....

Link to comment
Share on other sites

it's weird to me that setting the third person view field isn't enough to make it work. Because unless someone presses F5 again, it should be stable even with respect to the rendering timing. I understand that if we were trying to overwrite the value while Minecraft was also trying to overwrite it, but I don't see how that is the case here.

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

Link to comment
Share on other sites

Ya I find that weird also, Do you know where the actual calculation for the camera position occur after F5 has been pressed. I cant seem to find it. I tried to put the following into my RenderPlayerEvent.Pre pre event to force the view to be third person only when I become my new model and the view doesn't change unless I hit F5 then it changes and remains stable. which is weird.

@SubscribeEvent
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {

	//my code for becoming my other model is here
//just for testing
		if (pre.entityPlayer.worldObj.isRemote)
		{
	    	Minecraft.getMinecraft().gameSettings.thirdPersonView = 1;
	    	}
	}

Link to comment
Share on other sites

Even weirder I created two keys one which sets a boolean to true and one which sets that same boolean to false (the boolean is playerIsInFirstPerson). For some reason when im in third person and I want to go to first person (i do a check for my boolean to be false) and if the boolean is false the view should change from third person to first person - this updates the view perfectly fine  when I set the boolean and it updates my view  no problems.

 

However the weird problem occurs in reverse if I am already in first person and want to go to third person (i do this by clicking the key to set the boolean to true) -the boolean gets set to true on both client and server but the view doesnt update.. I have to click the F5 key to force it to update and then after that it is fine.

Link to comment
Share on other sites

I have just been looking into reflections as I have never used them. I am not sure how to approach this, since I dont know how the EntityRenderer works. The fields to change the camera view, angle, rotation, pitch etc etc are all private. I know that I need to use reflection on an object of the EntityRenderer class but I am not sure how to get the object of this class so that I can apply reflection to it. Any ideas?

Link to comment
Share on other sites

This seems to change the zoom level of the camera. Bear in mind this is the first time im using reflection so this is just me messing around. I placed this block of code into an if statement inside a render player event

EntityRenderer entRenderer = Minecraft.getMinecraft().entityRenderer;
		try {
			entRenderer.getClass().getField("cameraZoom").setAccessible(true);
			try {
				entRenderer.getClass().getField("cameraZoom").set(entRenderer, 0.;// I think the default is 1, a negative number flips the camera view a higher number zooms in
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			};
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

Link to comment
Share on other sites

If anyone knows of a better way to access camera fields please post below I believe my method isnt great.

This method changes the zoom to whatever you want

public void cameraZoom(double zoomValue){
	EntityRenderer entRenderer = Minecraft.getMinecraft().entityRenderer;

		try {
			entRenderer.getClass().getField("cameraZoom").set(entRenderer, zoomValue);
			System.out.println();
			} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

Link to comment
Share on other sites

There is FOVUpdateEvent (or something similar), you can use that to change zoom.

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

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

Link to comment
Share on other sites

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.