EntityCamera

Версия Minecraft
1.7.10
126
6
33
Такая проблема: у меня имеется сущность, от лица которого рисуется мир, следующий за другой сущностью, проще говоря что то типо вида от третьего лица для конкретной сущности, но при её спавне камера скачет туда-сюда далеко за пределы отрисвки.

Код:
public class CameraHandler extends EntityLivingBase {

    public Entity msentity;


    public CameraHandler(World world) {
        super(world);
        this.setSize(0.0F, 0.0F);
    }



    public CameraHandler(World world, Entity entity) {
        this(world);
        this.msentity = entity;
        this.setPosition(this.msentity.posX, this.msentity.posY, this.msentity.posZ);
    }


    public void onUpdate() {
        prevPosX = posX;
        prevPosY = posY;
        prevPosZ = posZ;

        this.setPosition(this.msentity.posX - (-MathHelper.sin(-msentity.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(-msentity.rotationPitch / 180.0F * (float) Math.PI) ),
                         this.msentity.posY - (-MathHelper.sin(-msentity.rotationPitch / 180.0F * (float) Math.PI) ),
                         this.msentity.posZ - (MathHelper.cos(-msentity.rotationYaw / 180.0F * (float) Math.PI) * MathHelper.cos(-msentity.rotationPitch / 180.0F * (float) Math.PI) ));

        rotationYaw = msentity.rotationYaw;
        rotationPitch = msentity.rotationPitch;

        for(; rotationYaw - prevRotationYaw >= 180F; rotationYaw -= 360F) ;
        for(; rotationYaw - prevRotationYaw < -180F; rotationYaw += 360F) ;
    }
}

Код:
@SubscribeEvent
    public void onRenderTick(TickEvent.RenderTickEvent event) {
        final Minecraft mc = FMLClientHandler.instance().getClient();
        final EntityPlayerSP player = mc.thePlayer;
      
        if (player != null)
        {
            if (entity != null) {

               setCam(player.worldObj, mc, entity);
            }
            else
            {
                if (camEntity != null){resetCam(mc);}
            }
        }
    }

    public void setCam(World world, Minecraft mc, Entity entity) {
        this.camEntity = new CameraHandler(world, entity);
        world.spawnEntityInWorld(this.camEntity);
        mc.renderViewEntity = this.camEntity;
        mc.gameSettings.hideGUI = true;
        mc.gameSettings.thirdPersonView = 0;
        thirdPersonView = true;
    }

    public void resetCam(Minecraft mc) {
        this.camEntity.setDead();
        if (mc.thePlayer != null) {
            mc.renderViewEntity = mc.thePlayer;
            mc.gameSettings.hideGUI = false;
            mc.gameSettings.thirdPersonView = 0;
        }
        thirdPersonView = false;
    }


Безымянный.png
Безымянный.png
Безымянный.png

UPD: эксперементально получено, что сама сущность летит правильно, но почему-то скачет рендер мира.
 
Последнее редактирование:
Сверху