修改视角摇晃mixin
This commit is contained in:
parent
8cbb448504
commit
2fa0f1ee5d
2 changed files with 51 additions and 56 deletions
|
@ -1,52 +1,39 @@
|
|||
package net.mcreator.target.client;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
public class GunRenderingHandler {
|
||||
private static float sprintIntensity;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderOverlay(RenderHandEvent event) {
|
||||
PoseStack poseStack = event.getPoseStack();
|
||||
poseStack.pushPose();
|
||||
/* Applies custom bobbing animations */
|
||||
applyBobbingTransforms(poseStack, event.getPartialTick());
|
||||
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
private static void applyBobbingTransforms(PoseStack poseStack, float partialTicks) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.options.bobView().get() && mc.getCameraEntity() instanceof Player player) {
|
||||
float deltaDistanceWalked = player.walkDist - player.walkDistO;
|
||||
float distanceWalked = -(player.walkDist + deltaDistanceWalked * partialTicks);
|
||||
float bobbing = Mth.lerp(partialTicks, player.oBob, player.bob);
|
||||
|
||||
/* Reverses the original bobbing rotations and translations so it can be controlled */
|
||||
poseStack.mulPose(Axis.XP.rotationDegrees(-(Math.abs(Mth.cos(distanceWalked * (float) Math.PI - 0.2F) * bobbing) * 5.0F)));
|
||||
poseStack.mulPose(Axis.ZP.rotationDegrees(-(Mth.sin(distanceWalked * (float) Math.PI) * bobbing * 3.0F)));
|
||||
poseStack.translate(-(Mth.sin(distanceWalked * (float) Math.PI) * bobbing * 0.5F), -(-Math.abs(Mth.cos(distanceWalked * (float) Math.PI) * bobbing)), 0.0D);
|
||||
|
||||
/* Slows down the bob by half */
|
||||
bobbing *= player.isSprinting() ? 8.0 : 4.0;
|
||||
bobbing *= 1.0;
|
||||
|
||||
// float intensity = mc.player.isSprinting() ? 0.75F : 1.0F;
|
||||
// sprintIntensity = Mth.approach(sprintIntensity, intensity, 0.1F);
|
||||
/* The new controlled bobbing */
|
||||
// double invertZoomProgress = 1.0 - 0.5 * sprintIntensity;
|
||||
//poseStack.translate((double) (Mth.sin(distanceWalked * (float) Math.PI) * cameraYaw * 0.5F) * invertZoomProgress, (double) (-Math.abs(Mth.cos(distanceWalked * (float) Math.PI) * cameraYaw)) * invertZoomProgress, 0.0D);
|
||||
// poseStack.mulPose(Axis.ZP.rotationDegrees((Mth.sin(distanceWalked * (float) Math.PI) * bobbing * 3.0F) * (float) invertZoomProgress));
|
||||
// poseStack.mulPose(Axis.XP.rotationDegrees((Math.abs(Mth.cos(distanceWalked * (float) Math.PI - 0.2F) * bobbing) * 5.0F) * (float) invertZoomProgress));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//package net.mcreator.target.client;
|
||||
//
|
||||
//import com.mojang.blaze3d.vertex.PoseStack;
|
||||
//import com.mojang.math.Axis;
|
||||
//import net.minecraft.client.Minecraft;
|
||||
//import net.minecraft.util.Mth;
|
||||
//import net.minecraft.world.entity.player.Player;
|
||||
//import net.minecraftforge.api.distmarker.Dist;
|
||||
//import net.minecraftforge.client.event.RenderHandEvent;
|
||||
//import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//import net.minecraftforge.fml.common.Mod;
|
||||
//
|
||||
//@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
|
||||
//public class GunRenderingHandler {
|
||||
//
|
||||
// @SubscribeEvent
|
||||
// public static void onRenderOverlay(RenderHandEvent event) {
|
||||
// PoseStack poseStack = event.getPoseStack();
|
||||
// poseStack.pushPose();
|
||||
// /* Applies custom bobbing animations */
|
||||
// applyBobbingTransforms(poseStack, event.getPartialTick());
|
||||
//
|
||||
// poseStack.popPose();
|
||||
// }
|
||||
//
|
||||
// private static void applyBobbingTransforms(PoseStack poseStack, float partialTicks) {
|
||||
// Minecraft mc = Minecraft.getInstance();
|
||||
// if (mc.options.bobView().get() && mc.getCameraEntity() instanceof Player player) {
|
||||
// float deltaDistanceWalked = player.walkDist - player.walkDistO;
|
||||
// float distanceWalked = -(player.walkDist + deltaDistanceWalked * partialTicks);
|
||||
// float bobbing = Mth.lerp(partialTicks, player.oBob, player.bob);
|
||||
//
|
||||
// /* Reverses the original bobbing rotations and translations so it can be controlled */
|
||||
// poseStack.mulPose(Axis.XP.rotationDegrees(-(Math.abs(Mth.cos(distanceWalked * (float) Math.PI - 0.2F) * bobbing) * 5.0F)));
|
||||
// poseStack.mulPose(Axis.ZP.rotationDegrees(-(Mth.sin(distanceWalked * (float) Math.PI) * bobbing * 3.0F)));
|
||||
// poseStack.translate(-(Mth.sin(distanceWalked * (float) Math.PI) * bobbing * 0.5F), -(-Math.abs(Mth.cos(distanceWalked * (float) Math.PI) * bobbing)), 0.0D);
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -1,13 +1,10 @@
|
|||
package net.mcreator.target.mixins;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -34,4 +31,15 @@ public class GameRendererMixin {
|
|||
// public void renderItemInHandEnd(PoseStack p_109121_, Camera p_109122_, float p_109123_, CallbackInfo ci) {
|
||||
// Minecraft.getInstance().options.bobView().set(flag);
|
||||
// }
|
||||
|
||||
@Inject(method = "bobView(Lcom/mojang/blaze3d/vertex/PoseStack;F)V", at = @At("HEAD"), cancellable = true)
|
||||
public void bobView(PoseStack p_109139_, float p_109140_, CallbackInfo ci) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Player player = mc.player;
|
||||
if (player != null) {
|
||||
if (player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue