the renderViewEntity have to extend entityLivingBase, so EntityLiving is fine (better EntityFlying).
I fixed the first issue: my camera didn't like rotationYaw > 360 or < 0 , so I had to adjust player's rotationYaw before to use it.
Now it doesn't spin anymore .
The code I used:
Camera class
public class MAEntityCamera extends EntityFlying {
public MAEntityCamera(World p_i1595_1_) {
super(p_i1595_1_);
}
}
RenderPlayerBase class (I'm using Player API)
public class MARenderPlayerBase extends RenderPlayerBase {
private MAEntityCamera camera;
public MARenderPlayerBase(RenderPlayerAPI renderPlayerAPI) {
super(renderPlayerAPI);
}
@Override
public void renderFirstPersonArm(EntityPlayer p_82441_1_) {
World world = Minecraft.getMinecraft().theWorld;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(!(Minecraft.getMinecraft().renderViewEntity instanceof MAEntityCamera))
{
//change renderViewEntity to camera
if(camera != null) Minecraft.getMinecraft().renderViewEntity = camera;
else
{
camera = new MAEntityCamera(world);
camera.setPositionAndRotation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
world.spawnEntityInWorld(camera);
Minecraft.getMinecraft().renderViewEntity = camera;
}
}
}
@Override
public void renderPlayer(AbstractClientPlayer paramAbstractClientPlayer, double paramDouble1, double paramDouble2,
double paramDouble3, float paramFloat1, float paramFloat2) {
super.renderPlayer(paramAbstractClientPlayer, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2);
//change renderViewEntity to player when rendering in third-person
if(Minecraft.getMinecraft().gameSettings.thirdPersonView > 0) Minecraft.getMinecraft().renderViewEntity = Minecraft.getMinecraft().thePlayer;
}
}
EventHandler class
public class EventHandler {
@SubscribeEvent
public void updateCamera(RenderHandEvent event) {
if(Minecraft.getMinecraft().renderViewEntity instanceof MAEntityCamera)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
//place camera in front of players's eyes
double distanceX = -0.4, distanceY = -0.5, distanceZ = 0.4;
double x = Math.sin(Math.toRadians(player.rotationYaw)) * distanceX;
double y = Math.sin(Math.toRadians(player.rotationPitch)) * distanceY;
double z = Math.cos(Math.toRadians(player.rotationYaw)) * distanceZ;
//adjust rotationYaw
if(player.rotationYaw > 360) player.rotationYaw -= 360;
if(player.rotationYaw < 0) player.rotationYaw += 360;
Minecraft.getMinecraft().renderViewEntity.setPositionAndRotation(player.posX + x, player.posY - 1.63 + y, player.posZ + z, player.rotationYaw, player.rotationPitch);
}
}
}
It works good, but I have to optimize it because of a few problems...
For example I can't interact with the blocks i see in the center of the camera, because the player is not watching exactely there, and so i often get the error: "trying to attack an invalid entity".
Do you know how could I fix this?
thank you very much