diff --git a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java index 71f4f2159..457cd0236 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/MortarEntity.java @@ -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()); } @@ -184,35 +183,17 @@ public class MortarEntity extends LivingEntity implements GeoEntity, AnimatedEnt } @Override - public void baseTick() { - super.baseTick(); - final Runnable runnable = doFire(); - Thread thread = new Thread(runnable); - thread.start(); - - this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1); - - this.refreshDimensions(); + public void travel(Vec3 dir) { + this.setXRot(-Mth.clamp((float) this.getAttribute(ModAttributes.MORTAR_PITCH.get()).getBaseValue(), 20, 89)); } - @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 void baseTick() { + super.baseTick(); + if (this.entityData.get(FIRE_TIME) > 0) { + this.entityData.set(FIRE_TIME, this.entityData.get(FIRE_TIME) - 1); + } + this.refreshDimensions(); } @Override diff --git a/src/main/java/net/mcreator/superbwarfare/entity/TargetEntity.java b/src/main/java/net/mcreator/superbwarfare/entity/TargetEntity.java index 062195eb2..c31ce9817 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/TargetEntity.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/TargetEntity.java @@ -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); diff --git a/src/main/java/net/mcreator/superbwarfare/entity/model/TargetModel.java b/src/main/java/net/mcreator/superbwarfare/entity/model/TargetModel.java index d127c341e..c9705c7da 100644 --- a/src/main/java/net/mcreator/superbwarfare/entity/model/TargetModel.java +++ b/src/main/java/net/mcreator/superbwarfare/entity/model/TargetModel.java @@ -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 { @Override @@ -29,10 +29,11 @@ public class TargetModel extends GeoModel { @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)); } } }