From 09ce92ec61353a423cc5ee680b70ca37265f174c Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sat, 31 May 2025 03:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E5=AE=9E=E7=8E=B0glock?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/item/Glock17ItemModel.java | 16 +++++++--------- .../client/model/item/Glock18ItemModel.java | 17 +++++++---------- .../renderer/gun/Glock17ItemRenderer.java | 9 +++++---- .../renderer/gun/Glock18ItemRenderer.java | 9 +++++---- .../item/gun/handgun/Glock17Item.java | 7 ++++++- .../item/gun/handgun/Glock18Item.java | 6 ++++++ 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock17ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock17ItemModel.java index 092f92c3b..eb52dac63 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock17ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock17ItemModel.java @@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.data.gun.GunData; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.handgun.Glock17Item; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; @@ -14,9 +13,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import software.bernie.geckolib.animation.AnimationState; import software.bernie.geckolib.cache.object.GeoBone; -import software.bernie.geckolib.model.GeoModel; -public class Glock17ItemModel extends GeoModel { +public class Glock17ItemModel extends CustomGunModel { public static float fireRotY = 0f; public static float fireRotZ = 0f; @@ -37,15 +35,15 @@ public class Glock17ItemModel extends GeoModel { } @Override - public void setCustomAnimations(Glock17Item animatable, long instanceId, AnimationState animationState) { - GeoBone gun = getAnimationProcessor().getBone("bone"); - GeoBone slide = getAnimationProcessor().getBone("huatao"); - GeoBone bullet = getAnimationProcessor().getBone("bullet"); - + public void setCustomAnimations(Glock17Item animatable, long instanceId, AnimationState animationState) { Player player = Minecraft.getInstance().player; if (player == null) return; ItemStack stack = player.getMainHandItem(); - if (!(stack.getItem() instanceof GunItem)) return; + if (shouldCancelRender(stack, animationState)) return; + + GeoBone gun = getAnimationProcessor().getBone("bone"); + GeoBone slide = getAnimationProcessor().getBone("huatao"); + GeoBone bullet = getAnimationProcessor().getBone("bullet"); float times = 0.6f * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); double zt = ClientEventHandler.zoomTime; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock18ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock18ItemModel.java index cc8b198e8..0fe0e57d1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock18ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Glock18ItemModel.java @@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.data.gun.FireMode; import com.atsuishio.superbwarfare.data.gun.GunData; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.handgun.Glock18Item; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; @@ -15,9 +14,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import software.bernie.geckolib.animation.AnimationState; import software.bernie.geckolib.cache.object.GeoBone; -import software.bernie.geckolib.model.GeoModel; -public class Glock18ItemModel extends GeoModel { +public class Glock18ItemModel extends CustomGunModel { public static float fireRotY = 0f; public static float fireRotZ = 0f; @@ -38,17 +36,17 @@ public class Glock18ItemModel extends GeoModel { } @Override - public void setCustomAnimations(Glock18Item animatable, long instanceId, AnimationState animationState) { + public void setCustomAnimations(Glock18Item animatable, long instanceId, AnimationState animationState) { + Player player = Minecraft.getInstance().player; + if (player == null) return; + ItemStack stack = player.getMainHandItem(); + if (shouldCancelRender(stack, animationState)) return; + GeoBone gun = getAnimationProcessor().getBone("bone"); GeoBone slide = getAnimationProcessor().getBone("huatao"); GeoBone bullet = getAnimationProcessor().getBone("bullet"); GeoBone switch_ = getAnimationProcessor().getBone("kuaimanji"); - Player player = Minecraft.getInstance().player; - if (player == null) return; - ItemStack stack = player.getMainHandItem(); - if (!(stack.getItem() instanceof GunItem)) return; - var data = GunData.from(stack); var mode = data.fireMode.get(); if (mode == FireMode.SEMI) { @@ -102,7 +100,6 @@ public class Glock18ItemModel extends GeoModel { GeoBone camera = getAnimationProcessor().getBone("camera"); GeoBone main = getAnimationProcessor().getBone("0"); - float numR = (float) (1 - 0.12 * zt); float numP = (float) (1 - 0.68 * zt); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock17ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock17ItemRenderer.java index 263a952ae..52b1650b9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock17ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock17ItemRenderer.java @@ -11,6 +11,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.world.item.ItemStack; +import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.cache.object.GeoBone; public class Glock17ItemRenderer extends CustomGunRenderer { @@ -34,12 +35,12 @@ public class Glock17ItemRenderer extends CustomGunRenderer { var player = mc.player; if (player == null) return; ItemStack itemStack = player.getMainHandItem(); - if (!(itemStack.getItem() instanceof GunItem)) return; - - AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.3022, 0.3); + if (itemStack.getItem() instanceof GunItem && GeoItem.getId(itemStack) == this.getInstanceId(animatable)) { + AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.3022, 0.3); + } if (renderingArms) { - AnimationHelper.renderArms(player, this.transformType, stack, name, bone, this.currentBuffer, type, packedLightIn, false); + AnimationHelper.renderArms(player, this.renderPerspective, stack, name, bone, buffer, type, packedLightIn, false); } super.renderRecursively(stack, animatable, bone, type, buffer, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, color); } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock18ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock18ItemRenderer.java index 6bf5b614b..cd4b9ba79 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock18ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/gun/Glock18ItemRenderer.java @@ -11,6 +11,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.world.item.ItemStack; +import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.cache.object.GeoBone; public class Glock18ItemRenderer extends CustomGunRenderer { @@ -34,12 +35,12 @@ public class Glock18ItemRenderer extends CustomGunRenderer { var player = mc.player; if (player == null) return; ItemStack itemStack = player.getMainHandItem(); - if (!(itemStack.getItem() instanceof GunItem)) return; - - AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.3022, 0.3); + if (itemStack.getItem() instanceof GunItem && GeoItem.getId(itemStack) == this.getInstanceId(animatable)) { + AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0, 0.3022, 0.3); + } if (renderingArms) { - AnimationHelper.renderArms(player, this.transformType, stack, name, bone, this.currentBuffer, type, packedLightIn, false); + AnimationHelper.renderArms(player, this.renderPerspective, stack, name, bone, buffer, type, packedLightIn, false); } super.renderRecursively(stack, animatable, bone, type, buffer, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, color); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock17Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock17Item.java index 5e648262e..000c1c1cd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock17Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock17Item.java @@ -11,9 +11,11 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import software.bernie.geckolib.animation.*; +import software.bernie.geckolib.constant.DataTickets; import software.bernie.geckolib.renderer.GeoItemRenderer; import java.util.Map; @@ -37,6 +39,8 @@ public class Glock17Item extends GunItem { if (player == null) return PlayState.STOP; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; + if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND) + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock_17.idle")); if (GunData.from(stack).reload.empty()) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock_17.reload_empty")); @@ -46,7 +50,6 @@ public class Glock17Item extends GunItem { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock_17.reload_normal")); } - return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock_17.idle")); } @@ -55,6 +58,8 @@ public class Glock17Item extends GunItem { if (player == null) return PlayState.STOP; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; + if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND) + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock_17.idle")); if (player.isSprinting() && player.onGround() && ClientEventHandler.cantSprint == 0 diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock18Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock18Item.java index e76f21c0f..e7eb5e8a7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock18Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Glock18Item.java @@ -11,9 +11,11 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Rarity; import software.bernie.geckolib.animation.*; +import software.bernie.geckolib.constant.DataTickets; import software.bernie.geckolib.renderer.GeoItemRenderer; import java.util.Map; @@ -37,6 +39,8 @@ public class Glock18Item extends GunItem { if (player == null) return PlayState.STOP; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; + if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND) + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock_17.idle")); if (GunData.from(stack).reload.empty()) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.glock_17.reload_empty")); @@ -54,6 +58,8 @@ public class Glock18Item extends GunItem { if (player == null) return PlayState.STOP; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; + if (event.getData(DataTickets.ITEM_RENDER_PERSPECTIVE) != ItemDisplayContext.FIRST_PERSON_RIGHT_HAND) + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.glock_17.idle")); if (player.isSprinting() && player.onGround() && ClientEventHandler.cantSprint == 0