尝试移植cgm的取消晃动
This commit is contained in:
parent
7b95d0ffe8
commit
8cbb448504
3 changed files with 70 additions and 18 deletions
|
@ -4,7 +4,7 @@ plugins {
|
|||
id 'org.spongepowered.mixin' version '0.7.+'
|
||||
}
|
||||
|
||||
version = '0.0.4-SNAPSHOT'
|
||||
version = '0.0.5-SNAPSHOT'
|
||||
group = 'com.Atsushio.target'
|
||||
archivesBaseName = 'target'
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,23 +15,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(GameRenderer.class)
|
||||
public class GameRendererMixin {
|
||||
private boolean flag;
|
||||
// private boolean flag;
|
||||
|
||||
@Inject(method = "renderItemInHand(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/Camera;F)V", at = @At("HEAD"))
|
||||
public void renderItemInHand(PoseStack p_109121_, Camera p_109122_, float p_109123_, CallbackInfo ci) {
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
Player player = minecraft.player;
|
||||
if (player != null) {
|
||||
flag = minecraft.options.bobView().get();
|
||||
ItemStack heldItem = player.getMainHandItem();
|
||||
if (heldItem.is(ItemTags.create(new ResourceLocation("target", "gun"))) && heldItem.getOrCreateTag().getBoolean("aiming")) {
|
||||
minecraft.options.bobView().set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @Inject(method = "renderItemInHand(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/Camera;F)V", at = @At("HEAD"))
|
||||
// public void renderItemInHand(PoseStack p_109121_, Camera p_109122_, float p_109123_, CallbackInfo ci) {
|
||||
// Minecraft minecraft = Minecraft.getInstance();
|
||||
// Player player = minecraft.player;
|
||||
// if (player != null) {
|
||||
// flag = minecraft.options.bobView().get();
|
||||
// ItemStack heldItem = player.getMainHandItem();
|
||||
// if (heldItem.is(ItemTags.create(new ResourceLocation("target", "gun"))) && heldItem.getOrCreateTag().getBoolean("aiming")) {
|
||||
// minecraft.options.bobView().set(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@Inject(method = "renderItemInHand(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/Camera;F)V", at = @At("RETURN"))
|
||||
public void renderItemInHandEnd(PoseStack p_109121_, Camera p_109122_, float p_109123_, CallbackInfo ci) {
|
||||
Minecraft.getInstance().options.bobView().set(flag);
|
||||
}
|
||||
// @Inject(method = "renderItemInHand(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/Camera;F)V", at = @At("RETURN"))
|
||||
// public void renderItemInHandEnd(PoseStack p_109121_, Camera p_109122_, float p_109123_, CallbackInfo ci) {
|
||||
// Minecraft.getInstance().options.bobView().set(flag);
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue