-
Custom Monster has a weird walking behaviour
package net.user.vampirethemasquerade.entity.custom; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.Difficulty; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.AnimationState; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.goal.*; import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; import net.minecraft.world.entity.ai.util.GoalUtils; import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.animal.IronGolem; import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.ai.goal.BreakDoorGoal; import net.minecraft.world.entity.npc.AbstractVillager; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; public class WightEntity extends Monster { private static final Predicate<Difficulty> DOOR_BREAKING_PREDICATE = (p_34284_) -> { return p_34284_ == Difficulty.HARD; }; public WightEntity(EntityType<? extends Monster> pEntityType, Level pLevel) { super(pEntityType, pLevel); } public final AnimationState idleAnimationState = new AnimationState(); public int idleAnimationTimeout = 0; @Override public void tick(){ super.tick(); if(this.level().isClientSide()){ setupAnimationState(); } } private void setupAnimationState(){ if(this.idleAnimationTimeout <= 0){ this.idleAnimationTimeout = this.random.nextInt(40) +80; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } } @Override protected void updateWalkAnimation(float pPartialTick) { float f; if(this.getPose() == Pose.STANDING){ f = Math.min(pPartialTick * 6F, 1f); } else{ f = 0f; } this.walkAnimation.update(f, 0.2f); } @Override protected void registerGoals() { this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); this.addBehaviourGoals(); } protected void addBehaviourGoals() { this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0D, false)); this.goalSelector.addGoal(6, new MoveThroughVillageGoal(this, 1.0D, true, 4, this::canBreakDoors)); this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, true)); this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Animal.class, true)); this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, IronGolem.class, true, false)); } public static AttributeSupplier.Builder createAttribute(){ return Monster.createMonsterAttributes() .add(Attributes.MAX_HEALTH, 60D) .add(Attributes.MOVEMENT_SPEED, 0.45F) .add(Attributes.FOLLOW_RANGE, 20D) .add(Attributes.ATTACK_DAMAGE, 7D) .add(Attributes.ARMOR, 7D); } @Override protected SoundEvent getHurtSound(DamageSource pDamageSource) { return SoundEvents.ZOMBIE_HURT; } @Nullable @Override protected SoundEvent getAmbientSound() { return SoundEvents.ZOMBIE_AMBIENT; } @Override protected SoundEvent getDeathSound() { return SoundEvents.ZOMBIE_DEATH; } public boolean canBreakDoors() { return this.canBreakDoors; } /** * Sets or removes EntityAIBreakDoor task */ private final BreakDoorGoal breakDoorGoal = new BreakDoorGoal(this, DOOR_BREAKING_PREDICATE); private boolean canBreakDoors; protected boolean supportsBreakDoorGoal() { return true; } public void setCanBreakDoors(boolean pCanBreakDoors) { if (this.supportsBreakDoorGoal() && GoalUtils.hasGroundPathNavigation(this)) { if (this.canBreakDoors != pCanBreakDoors) { this.canBreakDoors = pCanBreakDoors; ((GroundPathNavigation)this.getNavigation()).setCanOpenDoors(pCanBreakDoors); if (pCanBreakDoors) { this.goalSelector.addGoal(1, this.breakDoorGoal); } else { this.goalSelector.removeGoal(this.breakDoorGoal); } } } else if (this.canBreakDoors) { this.goalSelector.removeGoal(this.breakDoorGoal); this.canBreakDoors = false; } } } Here is the whole Class, sorry for the late reply
-
Carteie joined the community
-
Custom Monster has a weird walking behaviour
I am new to modding though not without java knowlodge. I am trying to make a new monster and got almost everything down right, he attacks all the entities it should attack correctly but when following said target he starts to do 360 turns or stops moving for a split second and then go back to chasing, any ideas on how to solve it is welcome @Override protected void registerGoals() { this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F)); this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); this.addBehaviourGoals(); } protected void addBehaviourGoals() { this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0D, false)); this.goalSelector.addGoal(6, new MoveThroughVillageGoal(this, 1.0D, true, 4, this::canBreakDoors)); this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, true)); this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false)); this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, Animal.class, true)); this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, IronGolem.class, true, false)); } Above is his behaviour goals, most of them took from the Zombie class.
IPS spam blocked by CleanTalk.