From a0259dd5e3cff5c4768f4de3ddbd3ee3b0d4228a Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 30 May 2025 17:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=9B=B7=E8=BE=BE=E6=97=8B?= =?UTF-8?q?=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/atsuishio/superbwarfare/Mod.java | 2 +- .../block/entity/FuMO25BlockEntity.java | 59 +++++++++---------- .../client/model/block/FuMO25Model.java | 32 ++++++++++ .../animations/fumo_25.animation.json | 26 +------- 4 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/Mod.java b/src/main/java/com/atsuishio/superbwarfare/Mod.java index accd10a61..9c31bfedf 100644 --- a/src/main/java/com/atsuishio/superbwarfare/Mod.java +++ b/src/main/java/com/atsuishio/superbwarfare/Mod.java @@ -132,6 +132,6 @@ public class Mod { } private void registerDataTickets() { - FuMO25BlockEntity.FUMO25_TICK = GeckoLibUtil.addDataTicket(SerializableDataTicket.ofDouble(loc("fumo25_tick"))); + FuMO25BlockEntity.FUMO25_TICK = GeckoLibUtil.addDataTicket(SerializableDataTicket.ofInt(loc("fumo25_tick"))); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java index 904b2a93d..02b984054 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java @@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import software.bernie.geckolib.animatable.GeoBlockEntity; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; -import software.bernie.geckolib.animation.*; +import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.constant.dataticket.SerializableDataTicket; import software.bernie.geckolib.util.GeckoLibUtil; @@ -42,7 +42,7 @@ import java.util.List; public class FuMO25BlockEntity extends BlockEntity implements MenuProvider, GeoBlockEntity { - public static SerializableDataTicket FUMO25_TICK; + public static SerializableDataTicket FUMO25_TICK; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -66,6 +66,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider, GeoB public int time = 0; public boolean powered = false; public int tick = 0; + public float yRot0 = 0; protected final ContainerEnergyData dataAccess = new ContainerEnergyData() { @Override @@ -106,14 +107,17 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider, GeoB return this.energyStorage; } - public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, T blockEntity) { - var radar = (FuMO25BlockEntity) blockEntity; + public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, FuMO25BlockEntity blockEntity) { + if (pState.getValue(FuMO25Block.POWERED)) { + blockEntity.tick++; + blockEntity.setAnimData(FUMO25_TICK, blockEntity.tick); + } - var energyStorage = ((FuMO25BlockEntity) blockEntity).getEnergyStorage(null); + var energyStorage = blockEntity.getEnergyStorage(null); var energy = energyStorage.getEnergyStored(); - radar.tick++; + blockEntity.tick++; - FuncType funcType = radar.type; + FuncType funcType = blockEntity.type; int energyCost; if (funcType == FuncType.WIDER) { energyCost = MAX_ENERGY_COST; @@ -125,45 +129,44 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider, GeoB if (pState.getValue(FuMO25Block.POWERED)) { pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, false)); pLevel.playSound(null, pPos, ModSounds.RADAR_SEARCH_END.get(), SoundSource.BLOCKS, 1.0F, 1.0F); - radar.powered = false; + blockEntity.powered = false; setChanged(pLevel, pPos, pState); } - if (radar.time > 0) { - radar.time = 0; - radar.setChanged(); + if (blockEntity.time > 0) { + blockEntity.time = 0; + blockEntity.setChanged(); } } else { if (!pState.getValue(FuMO25Block.POWERED)) { if (energy >= DEFAULT_MIN_ENERGY) { pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, true)); pLevel.playSound(null, pPos, ModSounds.RADAR_SEARCH_START.get(), SoundSource.BLOCKS, 1.0F, 1.0F); - radar.powered = true; + blockEntity.powered = true; setChanged(pLevel, pPos, pState); } } else { energyStorage.extractEnergy(energyCost, false); - if (radar.tick == 200) { + if (blockEntity.tick == 200) { pLevel.playSound(null, pPos, ModSounds.RADAR_SEARCH_IDLE.get(), SoundSource.BLOCKS, 1.0F, 1.0F); } - if (radar.time > 0) { - if (radar.time % 100 == 0) { - radar.setGlowEffect(); + if (blockEntity.time > 0) { + if (blockEntity.time % 100 == 0) { + blockEntity.setGlowEffect(); } - radar.time--; - radar.setChanged(); + blockEntity.time--; + blockEntity.setChanged(); } } } - if (radar.tick >= 200) { - radar.tick = 0; - radar.setAnimData(FUMO25_TICK, (double) radar.tick); + if (blockEntity.tick >= 200) { + blockEntity.tick = 0; } - if (radar.time <= 0 && radar.type != FuncType.NORMAL) { - radar.type = FuncType.NORMAL; - radar.setChanged(); + if (blockEntity.time <= 0 && blockEntity.type != FuncType.NORMAL) { + blockEntity.type = FuncType.NORMAL; + blockEntity.setChanged(); } } @@ -222,16 +225,8 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider, GeoB return ClientboundBlockEntityDataPacket.create(this); } - private PlayState predicate(AnimationState event) { - if (this.getBlockState().getValue(FuMO25Block.POWERED)) { - return event.setAndContinue(RawAnimation.begin().thenLoop("animation.fumo_25.rot")); - } - return PlayState.STOP; - } - @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { - data.add(new AnimationController<>(this, "controller", 0, this::predicate)); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/block/FuMO25Model.java b/src/main/java/com/atsuishio/superbwarfare/client/model/block/FuMO25Model.java index 14e4e8100..8aaf6916e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/block/FuMO25Model.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/block/FuMO25Model.java @@ -3,9 +3,13 @@ package com.atsuishio.superbwarfare.client.model.block; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.block.entity.FuMO25BlockEntity; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import software.bernie.geckolib.animation.AnimationState; +import software.bernie.geckolib.cache.object.GeoBone; import software.bernie.geckolib.model.GeoModel; public class FuMO25Model extends GeoModel { + @Override public ResourceLocation getAnimationResource(FuMO25BlockEntity animatable) { return Mod.loc("animations/fumo_25.animation.json"); @@ -20,4 +24,32 @@ public class FuMO25Model extends GeoModel { public ResourceLocation getTextureResource(FuMO25BlockEntity animatable) { return Mod.loc("textures/block/fumo_25.png"); } + + @Override + public void setCustomAnimations(FuMO25BlockEntity animatable, long instanceId, AnimationState animationState) { + GeoBone bone = this.getAnimationProcessor().getBone("mian"); + if (bone == null) return; + + float targetDeg = getTick(animatable) * 1.8f; // 目标角度(0~360°) + float currentDeg = animatable.yRot0 * Mth.RAD_TO_DEG; // 当前角度(弧度转角度) + + // 计算最短路径角度差(处理360°跳变) + float diffDeg = Mth.wrapDegrees(targetDeg - currentDeg); + + // 应用插值 + float newDeg = currentDeg + diffDeg * 0.1f; + + // 转换为弧度并更新 + float newRad = newDeg * Mth.DEG_TO_RAD; + animatable.yRot0 = newRad; + bone.setRotY(newRad); + } + + private float getTick(FuMO25BlockEntity animatable) { + Integer tick = animatable.getAnimData(FuMO25BlockEntity.FUMO25_TICK); + if (tick != null) { + return tick.floatValue(); + } + return 0; + } } \ No newline at end of file diff --git a/src/main/resources/assets/superbwarfare/animations/fumo_25.animation.json b/src/main/resources/assets/superbwarfare/animations/fumo_25.animation.json index b3383998e..bf22207f4 100644 --- a/src/main/resources/assets/superbwarfare/animations/fumo_25.animation.json +++ b/src/main/resources/assets/superbwarfare/animations/fumo_25.animation.json @@ -1,25 +1,5 @@ { - "format_version": "1.8.0", - "animations": { - "animation.fumo_25.rot": { - "loop": true, - "animation_length": 8, - "bones": { - "mian": { - "rotation": { - "0.0": [ - 0, - 0, - 0 - ], - "8.0": [ - 0, - 360, - 0 - ] - } - } - } - } - } + "format_version": "1.8.0", + "animations": { + } } \ No newline at end of file