尝试实现m60渲染分离

This commit is contained in:
17146 2025-05-31 02:17:27 +08:00 committed by Light_Quanta
parent 3818c5dc4c
commit ba9301f702
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 16 additions and 13 deletions

View file

@ -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.machinegun.M60Item;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
@ -14,11 +13,10 @@ 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;
import static com.atsuishio.superbwarfare.event.ClientEventHandler.isProne;
public class M60ItemModel extends GeoModel<M60Item> {
public class M60ItemModel extends CustomGunModel<M60Item> {
@Override
public ResourceLocation getAnimationResource(M60Item animatable) {
@ -36,7 +34,12 @@ public class M60ItemModel extends GeoModel<M60Item> {
}
@Override
public void setCustomAnimations(M60Item animatable, long instanceId, AnimationState animationState) {
public void setCustomAnimations(M60Item animatable, long instanceId, AnimationState<M60Item> 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 shen = getAnimationProcessor().getBone("shen");
GeoBone tiba = getAnimationProcessor().getBone("tiba");
@ -48,11 +51,6 @@ public class M60ItemModel extends GeoModel<M60Item> {
GeoBone l = getAnimationProcessor().getBone("l");
GeoBone r = getAnimationProcessor().getBone("r");
Player player = Minecraft.getInstance().player;
if (player == null) return;
ItemStack stack = player.getMainHandItem();
if (!(stack.getItem() instanceof GunItem)) return;
if (isProne(player)) {
l.setRotX(1.5f);
r.setRotX(1.5f);

View file

@ -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 M60ItemRenderer extends CustomGunRenderer<M60Item> {
@ -34,12 +35,12 @@ public class M60ItemRenderer extends CustomGunRenderer<M60Item> {
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.1, 1.95, 0.45);
if (itemStack.getItem() instanceof GunItem && GeoItem.getId(itemStack) == this.getInstanceId(animatable)) {
AnimationHelper.handleShootFlare(name, stack, itemStack, bone, buffer, packedLightIn, 0, 0.1, 1.95, 0.45);
}
if (renderingArms) {
AnimationHelper.renderArms(player, this.transformType, stack, name, bone, this.currentBuffer, type, packedLightIn, true);
AnimationHelper.renderArms(player, this.renderPerspective, stack, name, bone, buffer, type, packedLightIn, true);
}
super.renderRecursively(stack, animatable, bone, type, buffer, bufferIn, isReRender, partialTick, packedLightIn, packedOverlayIn, color);
}

View file

@ -13,10 +13,12 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
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 net.minecraft.world.level.Level;
import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.renderer.GeoItemRenderer;
import javax.annotation.ParametersAreNonnullByDefault;
@ -54,6 +56,8 @@ public class M60Item 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.m_60.idle"));
if (GunData.from(stack).reload.empty()) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m_60.reload"));