平滑靶子的倒伏动画,修改迫击炮的冷却逻辑

This commit is contained in:
Atsuihsio 2024-08-29 15:09:37 +08:00
parent c5e6399d9e
commit 9a0b5dbda3
3 changed files with 24 additions and 36 deletions

View file

@ -16,6 +16,7 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
@ -31,7 +32,6 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
@ -154,10 +154,9 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt
this.yBodyRotO = this.getYRot();
this.yHeadRotO = this.getYRot();
}
if (mainHandItem.getItem() == ModItems.MORTAR_SHELLS.get() && !player.getCooldowns().isOnCooldown(ModItems.MORTAR_SHELLS.get()) && !player.isShiftKeyDown()) {
if (mainHandItem.getItem() == ModItems.MORTAR_SHELLS.get() && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) {
this.entityData.set(FIRE_TIME, 25);
player.getCooldowns().addCooldown(ModItems.MORTAR_SHELLS.get(), 30);
if (!player.isCreative()) {
player.getInventory().clearOrCountMatchingItems(p -> ModItems.MORTAR_SHELLS.get() == p.getItem(), 1, player.inventoryMenu.getCraftSlots());
}
@ -183,38 +182,20 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt
return InteractionResult.sidedSuccess(this.level().isClientSide());
}
@Override
public void travel(Vec3 dir) {
this.setXRot(-Mth.clamp((float) this.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue(), 20, 89));
}
@Override
public void baseTick() {
super.baseTick();
final Runnable runnable = doFire();
Thread thread = new Thread(runnable);
thread.start();
if (this.entityData.get(FIRE_TIME) > 0) {
this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1);
}
this.refreshDimensions();
}
@NotNull
private Runnable doFire() {
double[] timer = {0};
double totalTime = 4;
int sleepTime = 2;
double Duration = totalTime / sleepTime;
return () -> {
while (timer[0] < Duration) {
this.setXRot((float) -this.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue());
timer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
ModUtils.LOGGER.error(e.getLocalizedMessage());
}
}
};
}
@Override
public boolean isPushable() {
return false;

View file

@ -14,6 +14,7 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
@ -138,7 +139,7 @@ public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEnt
if (sourceEntity instanceof Player player) {
player.displayClientMessage(Component.literal(("Target Down " + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceEntity.position()))) + "M")), true);
SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 100, 1);
targetEntity.entityData.set(DOWN_TIME, 90);
targetEntity.entityData.set(DOWN_TIME, 91);
}
}
}
@ -184,6 +185,11 @@ public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEnt
}
}
@Override
public void travel(Vec3 dir) {
this.setXRot(-Mth.clamp(this.entityData.get(DOWN_TIME), 0, 90));
}
@Override
public Vec3 getDeltaMovement() {
return new Vec3(0, 0, 0);

View file

@ -4,11 +4,11 @@ import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.entity.TargetEntity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.model.GeoModel;
import static net.mcreator.superbwarfare.entity.TargetEntity.DOWN_TIME;
import software.bernie.geckolib.model.data.EntityModelData;
public class TargetModel extends GeoModel<TargetEntity> {
@Override
@ -29,10 +29,11 @@ public class TargetModel extends GeoModel<TargetEntity> {
@Override
public void setCustomAnimations(TargetEntity animatable, long instanceId, AnimationState animationState) {
CoreGeoBone head = getAnimationProcessor().getBone("ba");
if (animatable.getEntityData().get(DOWN_TIME) > 20) {
head.setRotX(Mth.clamp(90 - animatable.getEntityData().get(DOWN_TIME),0,3) * 30 * Mth.DEG_TO_RAD);
EntityModelData entityData = (EntityModelData) animationState.getData(DataTickets.ENTITY_MODEL_DATA);
if (entityData.headPitch() > 10) {
head.setRotX(Mth.clamp(Mth.clamp(90 - entityData.headPitch(),0,4) * 22.5f * Mth.DEG_TO_RAD,0,90));
} else {
head.setRotX(4.5f * animatable.getEntityData().get(DOWN_TIME) * Mth.DEG_TO_RAD);
head.setRotX(Mth.clamp(9f * entityData.headPitch() * Mth.DEG_TO_RAD,0,90));
}
}
}