FreeLook как в нурсултане впринципе просто позволяет от третьего лица осматриваться
// класс самой функции
private boolean swap = false;
private static float cameraYaw;
private static float cameraPitch;
private static float originalX;
private static float originalY;
private static float originalBodyY;
private double lastMouseX;
private double lastMouseY;
BooleanSetting bypass = new BooleanSetting("Pitch bypass", false);
FloatSetting sensitivity = new FloatSetting("Sensitivity", 10,20,12,1);
public FreeLook() {
super("Free Look", Category.Visuals, ";-;");
addSettings(bypass, sensitivity);
}
@Override
public void onEnable() {
cameraYaw = mc.player.xRot;
cameraPitch = mc.player.yRot;
originalX = mc.player.xRot;
originalY = mc.player.yRot;
originalBodyY = mc.player.yBodyRot;
lastMouseX = mc.mouseHandler.xpos();
lastMouseY = mc.mouseHandler.ypos();
togglePerspective();
swap = true;
super.onEnable();
}
@Override
public void onDisable() {
togglePerspective();
super.onDisable();
}
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event) {
if (isEnabled() && !mc.options.getCameraType().isFirstPerson() && event.phase == TickEvent.Phase.START && mc.player != null && mc.level != null && mc.screen == null) {
if (swap) {
setCameraYaw(mc.player.yRot);
setCameraPitch(1.0F);
swap = false;
}
double currentMouseX = mc.mouseHandler.xpos();
double currentMouseY = mc.mouseHandler.ypos();
float sens = (float) (sensitivity.getValueFloat() / 100.0f);
double deltaX = currentMouseX - lastMouseX;
double deltaY = currentMouseY - lastMouseY;
cameraYaw += (float) (deltaX * sens);
cameraPitch -= (float) (deltaY * sens);
if (!bypass.isEnabled()) {
cameraPitch = MathHelper.clamp(cameraPitch, -90.0F, 90.0F);
}
lastMouseX = currentMouseX;
lastMouseY = currentMouseY;
if (mc.mouseHandler.isMouseGrabbed() && !mc.isPaused()) {
mc.mouseHandler.grabMouse();
}
}
}
private void togglePerspective() {
mc.options.setCameraType(isEnabled() ? PointOfView.FIRST_PERSON : PointOfView.THIRD_PERSON_BACK);
}
// тут не будьте как я и юзайте ломбок)
public static void setCameraYaw(float yaw) {
cameraYaw = yaw;
}
public static void setCameraPitch(float pitch) {
cameraPitch = pitch;
}
public static float getCameraYaw() {
return cameraYaw;
}
public static float getCameraPitch() {
return cameraPitch;
}
public static float getOriginalX() {
return originalX;
}
public static float getOriginalY() {
return originalY;
}
Далее нам нужно создать 2 хука - GameRendererHook и ActiveRenderInfoHook
После создания гуляем в GameRendererHook, ищем метод render
и строку
this.renderLevel(p_195458_1_, p_195458_2_, new MatrixStack());
И вставляем вместо нее
/*
* Думаю и так понятно, что isEnabled - проверка на то, включена функция или нет
*/
if (ModuleManager.isEnabled(FreeLook.class) && !this.minecraft.options.getCameraType().isFirstPerson()) {
this.minecraft.player.yRot = FreeLook.getOriginalY();
this.minecraft.player.xRot = FreeLook.getOriginalX();
this.renderLevel(p_195458_1_, p_195458_2_, new MatrixStack());
} else {
this.renderLevel(p_195458_1_, p_195458_2_, new MatrixStack());
}
Окей, переходим к ActiveRenderInfoHook, ищем метод setup и заменяем
public void setup(IBlockReader p_216772_1_, Entity p_216772_2_, boolean p_216772_3_, boolean p_216772_4_, float p_216772_5_) {
this.initialized = true;
this.level = p_216772_1_;
this.entity = p_216772_2_;
this.detached = p_216772_3_;
this.mirror = p_216772_4_;
float targetYaw, targetPitch;
double targetZoom = 0.0;
if (ModuleManager.isEnabled(FreeLook.class) && p_216772_3_) {
targetYaw = FreeLook.getCameraYaw();
targetPitch = FreeLook.getCameraPitch();
} else {
targetYaw = p_216772_2_.getViewYRot(p_216772_5_);
targetPitch = p_216772_2_.getViewXRot(p_216772_5_);
}
this.setRotation(targetYaw, targetPitch);
this.setPosition(MathHelper.lerp(p_216772_5_, p_216772_2_.xo, p_216772_2_.getX()),
MathHelper.lerp(p_216772_5_, p_216772_2_.yo, p_216772_2_.getY()) + (double)MathHelper.lerp(p_216772_5_, this.eyeHeightOld, this.eyeHeight),
MathHelper.lerp(p_216772_5_, p_216772_2_.zo, p_216772_2_.getZ()));
if (p_216772_3_) {
if (p_216772_4_) {
this.setRotation(this.yRot + 180.0F, -this.xRot);
}
targetZoom = -this.getMaxZoom(4.0);
} else if (p_216772_2_ instanceof LivingEntity && ((LivingEntity)p_216772_2_).isSleeping()) {
Direction direction = ((LivingEntity)p_216772_2_).getBedOrientation();
this.setRotation(direction != null ? direction.toYRot() - 180.0F : 0.0F, 0.0F);
targetZoom = 0.3;
}
if (zoomAnimation == null) {
zoomAnimation = new Animation(0, 0, 0.1f);
}
zoomAnimation.to = (float) targetZoom;
double currentZoom = zoomAnimation.getAnim();
this.move(currentZoom, 0.0, 0.0);
}
Пока не обращаем внимание на ошибки связанные с анимацией
Так-же нам нужен крутой CameraHandler
Создаем новый класс и пастим
public class CameraHandler {
@SubscribeEvent
public void onRenderWorld(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getInstance();
if (mc.player == null || mc.level == null) return;
if (ModuleManager.isEnabled(FreeLook.class)) {
GameRenderer gameRenderer = mc.gameRenderer;
ActiveRenderInfo activeRenderInfo = gameRenderer.getMainCamera();
float originalYaw = activeRenderInfo.getXRot();
float originalPitch = activeRenderInfo.getYRot();
activeRenderInfo.setAnglesInternal(FreeLook.getCameraYaw(), FreeLook.getCameraPitch());
activeRenderInfo.setAnglesInternal(originalYaw, originalPitch);
}
}
}
Данный класс просто регаем в ините
MinecraftForge.EVENT_BUS.register(new CameraHandler());
Далее для анимаций в ActiveRenderInfo компостируем себе
public class Animation {
long mc;
float anim;
public float to;
public float speed;
public Animation(float anim, float to, float speed) {
this.anim = anim;
this.to = to;
this.speed = speed;
this.mc = System.currentTimeMillis();
}
public float getAnim() {
int count = (int) ((System.currentTimeMillis() - this.mc) / 5L);
if (count > 0) {
this.mc = System.currentTimeMillis();
}
for (int i = 0; i < count; ++i) {
this.anim = MathUtil.harp(anim, to, speed);
}
return MathUtil.roundToDecimal(anim, 10);
}
public void reset() {
this.mc = System.currentTimeMillis();
}
public void setAnim(float anim) {
this.anim = anim;
this.mc = System.currentTimeMillis();
}
}
По итогу мы имеем анимацию при переключении перспективы, а так-же классный фанкш.
Далее просто регаем наши хуки и все готово, улыбаемся и машем!