From 22714210ca24adb39dda0270eab7b46e037aa8d8 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Wed, 22 May 2024 22:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=A7=86=E8=A7=92=E6=8A=96?= =?UTF-8?q?=E5=8A=A8=EF=BC=88AK,SKS=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/item/AK47ItemModel.java | 16 +++ .../client/model/item/SksItemModel.java | 9 ++ .../target/event/ClientEventHandler.java | 15 +++ .../target/animations/ak.animation.json | 93 ++++++++++++++-- .../target/animations/sks.animation.json | 102 ++++++++++++++++++ .../resources/assets/target/geo/sks.geo.json | 4 + 6 files changed, 229 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/mcreator/target/client/model/item/AK47ItemModel.java b/src/main/java/net/mcreator/target/client/model/item/AK47ItemModel.java index 53a32fe79..121b906c5 100644 --- a/src/main/java/net/mcreator/target/client/model/item/AK47ItemModel.java +++ b/src/main/java/net/mcreator/target/client/model/item/AK47ItemModel.java @@ -1,14 +1,22 @@ package net.mcreator.target.client.model.item; +import net.mcreator.target.init.TargetModMobEffects; import net.mcreator.target.item.gun.AK47Item; import net.mcreator.target.network.TargetModVariables; +import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraftforge.client.event.ViewportEvent; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; import software.bernie.geckolib.core.animation.AnimationState; import software.bernie.geckolib.model.GeoModel; +import net.minecraft.network.chat.Component; + public class AK47ItemModel extends GeoModel { @@ -136,5 +144,13 @@ public class AK47ItemModel extends GeoModel { move.setRotZ(3.7f * (float) yaw + 2.7f * (float) m); move.setRotY(1.9f * (float) yaw - (float) m); + + CoreGeoBone camera = getAnimationProcessor().getBone("camera"); + + player.getPersistentData().putDouble("camera_rot_x", Mth.RAD_TO_DEG * camera.getRotX()); + + player.getPersistentData().putDouble("camera_rot_y", Mth.RAD_TO_DEG * camera.getRotY()); + + player.getPersistentData().putDouble("camera_rot_z", Mth.RAD_TO_DEG * camera.getRotZ()); } } diff --git a/src/main/java/net/mcreator/target/client/model/item/SksItemModel.java b/src/main/java/net/mcreator/target/client/model/item/SksItemModel.java index 8770e4bf5..9eafce45a 100644 --- a/src/main/java/net/mcreator/target/client/model/item/SksItemModel.java +++ b/src/main/java/net/mcreator/target/client/model/item/SksItemModel.java @@ -4,6 +4,7 @@ import net.mcreator.target.item.gun.SksItem; import net.mcreator.target.network.TargetModVariables; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; @@ -137,5 +138,13 @@ public class SksItemModel extends GeoModel { move.setRotZ(3.7f * (float) yaw + 2.7f * (float) m); move.setRotY(1.9f * (float) yaw - 1.7f * (float) m); + + CoreGeoBone camera = getAnimationProcessor().getBone("camera"); + + player.getPersistentData().putDouble("camera_rot_x", Mth.RAD_TO_DEG * camera.getRotX()); + + player.getPersistentData().putDouble("camera_rot_y", Mth.RAD_TO_DEG * camera.getRotY()); + + player.getPersistentData().putDouble("camera_rot_z", Mth.RAD_TO_DEG * camera.getRotZ()); } } diff --git a/src/main/java/net/mcreator/target/event/ClientEventHandler.java b/src/main/java/net/mcreator/target/event/ClientEventHandler.java index 98eb32cfa..2b1679fe2 100644 --- a/src/main/java/net/mcreator/target/event/ClientEventHandler.java +++ b/src/main/java/net/mcreator/target/event/ClientEventHandler.java @@ -33,6 +33,7 @@ public class ClientEventHandler { handleWeaponZoom(living); handleWeaponFire(event, living); handleShockCamera(event, living); + PlayerCameraShake(event, living); handleBowPullAnimation(living); } } @@ -425,6 +426,20 @@ public class ClientEventHandler { } } + private static void PlayerCameraShake(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) { + var data = entity.getPersistentData(); + double yaw = event.getYaw(); + double pitch = event.getPitch(); + double roll = event.getRoll(); + + event.setPitch((float) (pitch + data.getDouble("camera_rot_x"))); + + event.setYaw((float) (yaw + data.getDouble("camera_rot_y"))); + + event.setRoll((float) (roll + data.getDouble("camera_rot_z"))); + + } + private static void handleBowPullAnimation(LivingEntity entity) { float fps = Minecraft.getInstance().getFps(); if (fps <= 0) { diff --git a/src/main/resources/assets/target/animations/ak.animation.json b/src/main/resources/assets/target/animations/ak.animation.json index e4389bf77..7ecb0cdd3 100644 --- a/src/main/resources/assets/target/animations/ak.animation.json +++ b/src/main/resources/assets/target/animations/ak.animation.json @@ -40,6 +40,26 @@ "vector": [0, 0, 0] } } + }, + "camera": { + "rotation": { + "0.0": { + "vector": [0, 0, 0] + }, + "0.2": { + "vector": [0, 0, 0] + }, + "0.4": { + "vector": [0, 0, -1], + "easing": "easeInOutSine" + }, + "0.5": { + "vector": [1, -1, 1] + }, + "0.6": { + "vector": [0, 0, 0] + } + } } } }, @@ -241,6 +261,25 @@ "vector": [2.5, -2, 0] } } + }, + "camera": { + "rotation": { + "0.0": { + "vector": [-0.5, -0.5, 0.5] + }, + "0.2": { + "vector": [0.5, 0, -0.5] + }, + "0.4": { + "vector": [-0.5, 0.5, 0.5] + }, + "0.6": { + "vector": [0.5, 0, -0.5] + }, + "0.8": { + "vector": [-0.5, -0.5, 0.5] + } + } } } }, @@ -679,44 +718,44 @@ "vector": [0, 0, 0] }, "0.4": { - "vector": [1, 0, 2], + "vector": [1, 0, 1], "easing": "easeInElastic" }, "0.5": { - "vector": [-1, 0, -2], + "vector": [-0.5, 0, -1], "easing": "easeInElastic" }, "0.7": { "vector": [0, 0, 0], "easing": "easeOutBack" }, - "1.1": { + "1.0": { "vector": [0, 0, 0] }, - "1.3": { + "1.2": { "vector": [0, 0, 1], "easing": "easeInElastic" }, - "1.4": { + "1.3": { "vector": [-1, 0, -2], "easing": "easeInElastic" }, - "1.6": { + "1.5": { "vector": [0, 0, 0], "easing": "easeOutBack" }, - "1.9": { + "1.8": { "vector": [0, 0, 0] }, - "2.0": { + "1.9": { "vector": [0, 2, 1], "easing": "easeInElastic" }, - "2.1": { + "2.0": { "vector": [-1, -1, -2], "easing": "easeInElastic" }, - "2.3": { + "2.2": { "vector": [0, 0, 0], "easing": "easeOutBack" } @@ -927,6 +966,40 @@ "vector": [0, 0, 0] } } + }, + "camera": { + "rotation": { + "0.3": { + "vector": [0, 0, 0] + }, + "0.4": { + "vector": [1, 0, 1], + "easing": "easeInElastic" + }, + "0.5": { + "vector": [-0.5, 0, -1], + "easing": "easeInElastic" + }, + "0.7": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + }, + "1.0": { + "vector": [0, 0, 0] + }, + "1.2": { + "vector": [0, 0, 1], + "easing": "easeInElastic" + }, + "1.3": { + "vector": [-1, 0, -2], + "easing": "easeInElastic" + }, + "1.5": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + } + } } } } diff --git a/src/main/resources/assets/target/animations/sks.animation.json b/src/main/resources/assets/target/animations/sks.animation.json index 0ba3302dc..a2b9aa940 100644 --- a/src/main/resources/assets/target/animations/sks.animation.json +++ b/src/main/resources/assets/target/animations/sks.animation.json @@ -88,6 +88,25 @@ "vector": [2.5, -3, 0] } } + }, + "camera": { + "rotation": { + "0.0": { + "vector": [-0.5, -0.5, 0.5] + }, + "0.2": { + "vector": [0.5, 0, -0.5] + }, + "0.4": { + "vector": [-0.5, 0.5, 0.5] + }, + "0.6": { + "vector": [0.5, 0, -0.5] + }, + "0.8": { + "vector": [-0.5, -0.5, 0.5] + } + } } } }, @@ -411,6 +430,55 @@ "vector": [0, 0, 0] } } + }, + "camera": { + "rotation": { + "0.3": { + "vector": [0, 0, 0] + }, + "0.4": { + "vector": [1, 0, 1], + "easing": "easeInElastic" + }, + "0.5": { + "vector": [-0.5, 0, -1], + "easing": "easeInElastic" + }, + "0.7": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + }, + "1.0": { + "vector": [0, 0, 0] + }, + "1.2": { + "vector": [0, 0, 1], + "easing": "easeInElastic" + }, + "1.3": { + "vector": [-1, 0, -2], + "easing": "easeInElastic" + }, + "1.5": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + }, + "1.8": { + "vector": [0, 0, 0] + }, + "1.9": { + "vector": [0, 2, 1], + "easing": "easeInElastic" + }, + "2.0": { + "vector": [-1, -1, -2], + "easing": "easeInElastic" + }, + "2.2": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + } + } } } }, @@ -594,6 +662,40 @@ "vector": [0, 0, 0] } } + }, + "camera": { + "rotation": { + "0.3": { + "vector": [0, 0, 0] + }, + "0.4": { + "vector": [1, 0, 1], + "easing": "easeInElastic" + }, + "0.5": { + "vector": [-0.5, 0, -1], + "easing": "easeInElastic" + }, + "0.7": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + }, + "1.0": { + "vector": [0, 0, 0] + }, + "1.2": { + "vector": [0, 0, 1], + "easing": "easeInElastic" + }, + "1.3": { + "vector": [-1, 0, -2], + "easing": "easeInElastic" + }, + "1.5": { + "vector": [0, 0, 0], + "easing": "easeOutBack" + } + } } } } diff --git a/src/main/resources/assets/target/geo/sks.geo.json b/src/main/resources/assets/target/geo/sks.geo.json index 5198eb46a..fa0999c2f 100644 --- a/src/main/resources/assets/target/geo/sks.geo.json +++ b/src/main/resources/assets/target/geo/sks.geo.json @@ -11,6 +11,10 @@ "visible_bounds_offset": [0, 0, 0] }, "bones": [ + { + "name": "camera", + "pivot": [0, 0, 0] + }, { "name": "root", "pivot": [0, 0, 0]