mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-08 08:21:50 +01:00
Slightly rewritten EntityAIGroupBuilder
This commit is contained in:
parent
20f581cc11
commit
57e2bdb5d6
@ -50,7 +50,7 @@ public interface EntityAI {
|
||||
* @return a builder to create and add an {@link EntityAIGroup}.
|
||||
*/
|
||||
default EntityAIGroupBuilder newAIGroupBuilder() {
|
||||
return new EntityAIGroupBuilder(this);
|
||||
return new EntityAIGroupBuilder();
|
||||
}
|
||||
|
||||
default void aiTick(long time) {
|
||||
|
@ -1,17 +1,8 @@
|
||||
package net.minestom.server.entity.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityAIGroupBuilder {
|
||||
|
||||
private final EntityAI ai;
|
||||
private final List<GoalSelector> goalSelectors = new ArrayList<>();
|
||||
private final List<TargetSelector> targetSelectors = new ArrayList<>();
|
||||
|
||||
EntityAIGroupBuilder(EntityAI ai) {
|
||||
this.ai = ai;
|
||||
}
|
||||
private final EntityAIGroup group = new EntityAIGroup();
|
||||
|
||||
/**
|
||||
* Adds {@link GoalSelector} to the list of goal selectors of the building {@link EntityAIGroup}.
|
||||
@ -21,7 +12,7 @@ public class EntityAIGroupBuilder {
|
||||
* @return this builder.
|
||||
*/
|
||||
public EntityAIGroupBuilder addGoalSelector(GoalSelector goalSelector) {
|
||||
this.goalSelectors.add(goalSelector);
|
||||
this.group.getGoalSelectors().add(goalSelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -33,15 +24,17 @@ public class EntityAIGroupBuilder {
|
||||
* @return this builder.
|
||||
*/
|
||||
public EntityAIGroupBuilder addTargetSelector(TargetSelector targetSelector) {
|
||||
this.targetSelectors.add(targetSelector);
|
||||
this.group.getTargetSelectors().add(targetSelector);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link EntityAIGroup} and adds it to the owning {@link EntityAI} of this builder.
|
||||
* Creates new {@link EntityAIGroup}.
|
||||
*
|
||||
* @return new {@link EntityAIGroup}.
|
||||
*/
|
||||
public void build() {
|
||||
this.ai.addAIGroup(this.goalSelectors, this.targetSelectors);
|
||||
public EntityAIGroup build() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,13 +33,15 @@ public class ChickenCreature extends EntityChicken {
|
||||
);
|
||||
|
||||
// Another way to register previously added EntityAIGroup, using specialized builder:
|
||||
// newAIGroupBuilder()
|
||||
// .addGoalSelector(new DoNothingGoal(this, 500, .1F))
|
||||
// .addGoalSelector(new MeleeAttackGoal(this, 500, 2, TimeUnit.MILLISECOND))
|
||||
// .addGoalSelector(new RandomStrollGoal(this, 2))
|
||||
// .addTargetSelector(new LastEntityDamagerTarget(this, 15))
|
||||
// .addTargetSelector(new ClosestEntityTarget(this, 15, LivingEntity.class))
|
||||
// .build();
|
||||
// addAIGroup(
|
||||
// newAIGroupBuilder()
|
||||
// .addGoalSelector(new DoNothingGoal(this, 500, .1F))
|
||||
// .addGoalSelector(new MeleeAttackGoal(this, 500, 2, TimeUnit.MILLISECOND))
|
||||
// .addGoalSelector(new RandomStrollGoal(this, 2))
|
||||
// .addTargetSelector(new LastEntityDamagerTarget(this, 15))
|
||||
// .addTargetSelector(new ClosestEntityTarget(this, 15, LivingEntity.class))
|
||||
// .build()
|
||||
// );
|
||||
|
||||
getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.1f);
|
||||
|
||||
|
@ -1,18 +1,17 @@
|
||||
package demo.entity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minestom.server.entity.ai.goal.RandomLookAroundGoal;
|
||||
import net.minestom.server.entity.type.monster.EntityZombie;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class ZombieCreature extends EntityZombie {
|
||||
|
||||
public ZombieCreature(Position spawnPosition) {
|
||||
super(spawnPosition);
|
||||
newAIGroupBuilder()
|
||||
.addGoalSelector(new RandomLookAroundGoal(this, 20))
|
||||
.build();
|
||||
addAIGroup(
|
||||
newAIGroupBuilder()
|
||||
.addGoalSelector(new RandomLookAroundGoal(this, 20))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user