Mob/entity attack delay [Question-Temporary Solution found]

Started by __SK__ on

Topic category: Help with modding (Java Edition)

Last seen on 07:12, 12. May 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mob/entity attack delay [Question-Temporary Solution found]
Sat, 02/19/2022 - 15:42 (edited)

Is there any way to force a custom mob to have a delay between attacks? Example, like an attack cooldown every 30 or 40 or 50 ticks.

 

Tried changing this value, but the entity still attacks about every 20 ticks.

Edited by __SK__ on Sat, 02/19/2022 - 15:42
Last seen on 07:12, 12. May 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
  Temporary fix, might…
Sat, 02/19/2022 - 15:42

 

Temporary fix, might become permanent. Change the ticks for +/_ time.

Last seen on 13:41, 11. May 2024
Joined Mar 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
your method works. however,…
Sun, 08/20/2023 - 11:31

your method works. however, I don't see it a bit, does it stretch the whole animation as a whole?

Last seen on 07:12, 12. May 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No, it doesn't. At that time…
Wed, 08/23/2023 - 00:49

No, it doesn't. At that time, it just stopped/slows down the specified attacker entity. Now I did learn how to do custom attack goals with delayed attacks and/or random with different intervals, but I do it manually. Don't know how to integrate it as a plugin. If you or someone else knows how to integrate it as a plugin, I will gladly share my code.

Best wishes. 

Last seen on 21:03, 1. Apr 2024
Joined Jul 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey wanted to ask if you…
Sat, 09/23/2023 - 01:14

hey wanted to ask if you ever found a way to make it work?

Last seen on 07:12, 12. May 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well ... Yes, I did learn…
Sat, 09/23/2023 - 23:02

Well ... Yes, I did learn how to make custom attack goals. But in order to to make it functional, it has to be manually coded. 

Something like the following ... 

 

//INCLUDE THIS IN registerGoals AND remove MCreator's default attack goal

this.goalSelector.addGoal(1, new TesterEntity.AttackGoal(this, 1));

//TODO GOAL

public class AttackGoal extends Goal {
private final TesterEntity entity;
private final double speedModifier;
private int attackTime;

public AttackGoal(TesterEntity zombieIn, double speedIn) {
this.entity = zombieIn;
this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK, Goal.Flag.JUMP));
this.speedModifier = speedIn;
}

public boolean canUse() {
return this.entity.getTarget() != null;
}

public boolean canContinueToUse() {
return this.canUse();
}

public void start() {
super.start();
this.entity.setAggressive(true);
}

public void stop() {
super.stop();
this.entity.setAggressive(false);
this.attackTime = -1;
}

public void tick() {
//if (attackingMarker == 1) {
LivingEntity livingentity = this.entity.getTarget();
if (livingentity != null) {
boolean inLineOfSight = this.entity.getSensing().hasLineOfSight(livingentity);
this.attackTime++;
this.entity.lookAt(livingentity, 30.0F, 30.0F);
if (inLineOfSight && livingentity.distanceTo(entity) >= 3.0D) {
this.entity.getNavigation().moveTo(livingentity, this.speedModifier);
this.attackTime = -3;// TODO GOOD -5 ATTACK IS SLOWER AT -10
} else {
if (this.attackTime == 1) {
this.entity.swing(InteractionHand.MAIN_HAND, true);
}
//if (this.attackTime == 2) { // TODO - **HIT & PARTICLES** - WAS 9
// // TODO - GOOD 0.15 - 1.0
// //playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 2.15F, 1.0F);
// this.entity.doHurtTarget(livingentity);
//}
if (this.attackTime == 7) { // TODO - **PARTICLES** - WAS 9
AreaEffectCloud areaeffectcloudentity = new AreaEffectCloud(entity.level, entity.getX(),entity.getY(), entity.getZ());
//areaeffectcloudentity.setParticle(ParticleTypes.ASH);
// TODO - GOOD 0.15 - 1.0
//playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 0.15F, 1.0F);
areaeffectcloudentity.setRadius(2.0F);
areaeffectcloudentity.setDuration(1);
areaeffectcloudentity.setPos(entity.getX(), entity.getY() + 0.3, entity.getZ());
entity.level.addFreshEntity(areaeffectcloudentity);
this.entity.doHurtTarget(livingentity);
livingentity.invulnerableTime = 0;
}
if (this.attackTime == 8) { // TODO - **PARTICLES** - WAS 9
AreaEffectCloud areaeffectcloudentity = new AreaEffectCloud(entity.level, entity.getX(),entity.getY(), entity.getZ());
//areaeffectcloudentity.setParticle(ParticleTypes.ASH);
// TODO - GOOD 0.15 - 1.0
//playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 0.15F, 1.0F);
areaeffectcloudentity.setRadius(2.0F);
areaeffectcloudentity.setDuration(1);
areaeffectcloudentity.setPos(entity.getX(), entity.getY() + 0.3, entity.getZ());
entity.level.addFreshEntity(areaeffectcloudentity);
this.entity.doHurtTarget(livingentity);
livingentity.invulnerableTime = 0;
}
if (this.attackTime == 9) { // TODO - **PARTICLES** - WAS 9
AreaEffectCloud areaeffectcloudentity = new AreaEffectCloud(entity.level, entity.getX(),entity.getY(), entity.getZ());
//areaeffectcloudentity.setParticle(ParticleTypes.ASH);
// TODO - GOOD 0.15 - 1.0
//playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 0.15F, 1.0F);
areaeffectcloudentity.setRadius(2.0F);
areaeffectcloudentity.setDuration(1);
areaeffectcloudentity.setPos(entity.getX(), entity.getY() + 0.3, entity.getZ());
entity.level.addFreshEntity(areaeffectcloudentity);
this.entity.doHurtTarget(livingentity);
livingentity.invulnerableTime = 0;
}
if (this.attackTime == 10) { // TODO - **PARTICLES** - WAS 9
AreaEffectCloud areaeffectcloudentity = new AreaEffectCloud(entity.level, entity.getX(),entity.getY(), entity.getZ());
//areaeffectcloudentity.setParticle(ParticleTypes.ASH);
// TODO - GOOD 0.15 - 1.0
//playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 0.15F, 1.0F);
areaeffectcloudentity.setRadius(2.0F);
areaeffectcloudentity.setDuration(1);
areaeffectcloudentity.setPos(entity.getX(), entity.getY() + 0.3, entity.getZ());
entity.level.addFreshEntity(areaeffectcloudentity);
this.entity.doHurtTarget(livingentity);
livingentity.invulnerableTime = 0;
}
if (this.attackTime == 11) { // TODO - **PARTICLES** - WAS 9
AreaEffectCloud areaeffectcloudentity = new AreaEffectCloud(entity.level, entity.getX(),entity.getY(), entity.getZ());
//areaeffectcloudentity.setParticle(ParticleTypes.ASH);
// TODO - GOOD 0.15 - 1.0
//playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 0.15F, 1.0F);
areaeffectcloudentity.setRadius(2.0F);
areaeffectcloudentity.setDuration(1);
areaeffectcloudentity.setPos(entity.getX(), entity.getY() + 0.3, entity.getZ());
entity.level.addFreshEntity(areaeffectcloudentity);
this.entity.doHurtTarget(livingentity);
livingentity.invulnerableTime = 0;
}
//if (this.attackTime == 5) { // TODO - **HIT & PARTICLES** - WAS 9
// // TODO - GOOD 0.15 - 1.0
// //playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 2.15F, 1.0F);
// this.entity.doHurtTarget(livingentity);
//}
if (this.attackTime == 8) { // TODO - **JUMP/MOVE** - GOOD 4
Vec3 vec3d = this.entity.getDeltaMovement();
Vec3 vec3d2 = new Vec3(livingentity.getX() - this.entity.getX(), 0.0,
livingentity.getZ() - this.entity.getZ());
vec3d2 = vec3d2.normalize().scale(0.4).add(vec3d.scale(0.4));
this.entity.setDeltaMovement(vec3d2.x, 0.005F, vec3d2.z);
// TODO TO JUMP 0.5F - WILL NOT JUMP WITH 0.01F
}
//if (this.attackTime == 10) { // TODO - **HIT & PARTICLES** - WAS 9
// // TODO - GOOD 0.15 - 1.0
// //playSound(SoundEvents.WARDEN_ATTACK_IMPACT, 2.15F, 1.0F);
// this.entity.doHurtTarget(livingentity);
//}
if (this.attackTime == 15) { // TODO GOOD 13
this.attackTime = -10;// TODO GOOD -5 ATTACK IS SLOWER AT -10
this.entity.getNavigation().moveTo(livingentity, this.speedModifier);
}
}
}
}
}

protected double getAttackReachSqr(LivingEntity p_25556_) {
return (double)(this.getBbWidth() * 2.0F * this.getBbWidth() * 2.0F + p_25556_.getBbWidth());
}

protected PathNavigation createNavigation(Level p_33348_) {
return new TesterEntity.TesterNavigation(this, p_33348_);
}

static class TesterNavigation extends GroundPathNavigation {
public TesterNavigation(Mob p_33379_, Level p_33380_) {
super(p_33379_, p_33380_);
}

protected PathFinder createPathFinder(int p_33382_) {
this.nodeEvaluator = new TesterEntity.TesterNodeEvaluator();
return new PathFinder(this.nodeEvaluator, p_33382_);
}
}

static class TesterNodeEvaluator extends WalkNodeEvaluator {
protected BlockPathTypes evaluateBlockPathType(BlockGetter p_33387_, boolean p_33388_, boolean p_33389_, BlockPos p_33390_, BlockPathTypes p_33391_) {
return p_33391_ == BlockPathTypes.LEAVES ? BlockPathTypes.OPEN : super.evaluateBlockPathType(p_33387_, p_33388_, p_33389_, p_33390_, p_33391_);
}
}
Last seen on 07:12, 12. May 2024
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It seems like a lot, but if…
Sat, 09/23/2023 - 23:06

It seems like a lot, but if you look closer I used "TesterEntity" as template and the word "Tester" is included in the code which can be replaced with your custom entities name. This code can be extended as far as you like making random attacks ... you could also add states which will be used to trigger Geckolib animations.