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