Added secondary constructors without predicates
This commit is contained in:
@@ -14,13 +14,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Avoid entities.
|
||||
*
|
||||
* @param entity The entity type to avoid.
|
||||
* @param fleeDistance The distance to flee to.
|
||||
* @param distance The distance to flee to.
|
||||
* @param slowSpeed The slow movement speed.
|
||||
* @param fastSpeed The fast movement speed.
|
||||
*/
|
||||
public record EntityGoalAvoidEntity(
|
||||
@NotNull TestableEntity entity,
|
||||
double fleeDistance,
|
||||
double distance,
|
||||
double slowSpeed,
|
||||
double fastSpeed
|
||||
) implements EntityGoal<Mob> {
|
||||
@@ -38,7 +38,7 @@ public record EntityGoalAvoidEntity(
|
||||
public EntityGoalAvoidEntity deserialize(@NotNull final Config config) {
|
||||
if (!(
|
||||
config.has("entity")
|
||||
&& config.has("fleeDistance")
|
||||
&& config.has("distance")
|
||||
&& config.has("slowSpeed")
|
||||
&& config.has("fastSpeed")
|
||||
)) {
|
||||
@@ -50,7 +50,7 @@ public record EntityGoalAvoidEntity(
|
||||
|
||||
return new EntityGoalAvoidEntity(
|
||||
entity,
|
||||
config.getDouble("fleeDistance"),
|
||||
config.getDouble("distance"),
|
||||
config.getDouble("slowSpeed"),
|
||||
config.getDouble("fastSpeed")
|
||||
);
|
||||
|
||||
@@ -11,10 +11,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* Allows an entity to break down doors.
|
||||
*
|
||||
* @param maxProgress The time taken to break the door (any integer above 240).
|
||||
* @param ticks The time taken to break the door. Minimum value is 240, as set by the game.
|
||||
*/
|
||||
public record EntityGoalBreakDoors(
|
||||
int maxProgress
|
||||
int ticks
|
||||
) implements EntityGoal<Mob> {
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
@@ -29,14 +29,14 @@ public record EntityGoalBreakDoors(
|
||||
@Nullable
|
||||
public EntityGoalBreakDoors deserialize(@NotNull final Config config) {
|
||||
if (!(
|
||||
config.has("maxProgress")
|
||||
config.has("ticks")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new EntityGoalBreakDoors(
|
||||
config.getInt("maxProgress")
|
||||
config.getInt("ticks")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
|
||||
@@ -11,10 +11,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* Allows an entity to interact and open a door.
|
||||
*
|
||||
* @param delayedClose If closing the door should be delayed.
|
||||
* @param delayClosing If closing the door should be delayed.
|
||||
*/
|
||||
public record EntityGoalOpenDoors(
|
||||
boolean delayedClose
|
||||
boolean delayClosing
|
||||
) implements EntityGoal<Mob> {
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
@@ -29,14 +29,14 @@ public record EntityGoalOpenDoors(
|
||||
@Nullable
|
||||
public EntityGoalOpenDoors deserialize(@NotNull final Config config) {
|
||||
if (!(
|
||||
config.has("delayedClose")
|
||||
config.has("delayClosing")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new EntityGoalOpenDoors(
|
||||
config.getBool("delayedClose")
|
||||
config.getBool("delayClosing")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
|
||||
@@ -13,13 +13,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
* <p>
|
||||
* Only supports mobs that have ranged attacks.
|
||||
*
|
||||
* @param mobSpeed The mob speed.
|
||||
* @param speed The speed.
|
||||
* @param minInterval The minimum interval between attacks (in ticks).
|
||||
* @param maxInterval The maximum interval between attacks (in ticks).
|
||||
* @param maxRange The max range at which to attack.
|
||||
*/
|
||||
public record EntityGoalRangedAttack(
|
||||
double mobSpeed,
|
||||
double speed,
|
||||
int minInterval,
|
||||
int maxInterval,
|
||||
double maxRange
|
||||
|
||||
@@ -14,12 +14,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* Only supports monsters that have bow attacks.
|
||||
*
|
||||
* @param speed The speed.
|
||||
* @param attackInterval The interval between attacks (in ticks).
|
||||
* @param interval The interval between attacks (in ticks).
|
||||
* @param range The max range at which to attack.
|
||||
*/
|
||||
public record EntityGoalRangedBowAttack(
|
||||
double speed,
|
||||
int attackInterval,
|
||||
int interval,
|
||||
double range
|
||||
) implements EntityGoal<Monster> {
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ public record EntityGoalRangedBowAttack(
|
||||
public EntityGoalRangedBowAttack deserialize(@NotNull final Config config) {
|
||||
if (!(
|
||||
config.has("speed")
|
||||
&& config.has("attackInterval")
|
||||
&& config.has("interval")
|
||||
&& config.has("range")
|
||||
)) {
|
||||
return null;
|
||||
@@ -45,7 +45,7 @@ public record EntityGoalRangedBowAttack(
|
||||
try {
|
||||
return new EntityGoalRangedBowAttack(
|
||||
config.getDouble("speed"),
|
||||
config.getInt("attackInterval"),
|
||||
config.getInt("interval"),
|
||||
config.getDouble("range")
|
||||
);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*
|
||||
* @param blacklist The entities not to attack when hurt by.
|
||||
*/
|
||||
@SuppressWarnings({"varargs", "unchecked"})
|
||||
@SuppressWarnings({"varargs"})
|
||||
public record TargetGoalHurtBy(
|
||||
@NotNull TestableEntity blacklist
|
||||
) implements TargetGoal<Mob> {
|
||||
|
||||
@@ -29,6 +29,19 @@ public record TargetGoalNearestAttackable(
|
||||
int reciprocalChance,
|
||||
@NotNull Predicate<LivingEntity> targetFilter
|
||||
) implements TargetGoal<Raider> {
|
||||
/**
|
||||
* @param target The type of entities to attack.
|
||||
* @param checkVisibility If visibility should be checked.
|
||||
* @param checkCanNavigate If navigation should be checked.
|
||||
* @param reciprocalChance 1 in reciprocalChance chance of not activating on any tick.
|
||||
*/
|
||||
public TargetGoalNearestAttackable(@NotNull final TestableEntity target,
|
||||
final boolean checkVisibility,
|
||||
final boolean checkCanNavigate,
|
||||
final int reciprocalChance) {
|
||||
this(target, checkVisibility, checkCanNavigate, reciprocalChance, it -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
*/
|
||||
@@ -46,21 +59,29 @@ public record TargetGoalNearestAttackable(
|
||||
&& config.has("checkVisibility")
|
||||
&& config.has("checkCanNavigate")
|
||||
&& config.has("reciprocalChance")
|
||||
&& config.has("targetFilter")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
if (config.has("targetFilter")) {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
|
||||
return new TargetGoalNearestAttackable(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance"),
|
||||
filter::matches
|
||||
);
|
||||
return new TargetGoalNearestAttackable(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance"),
|
||||
filter::matches
|
||||
);
|
||||
} else {
|
||||
return new TargetGoalNearestAttackable(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance")
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
Exceptions could be caused by configs having values of a wrong type,
|
||||
|
||||
@@ -29,6 +29,19 @@ public record TargetGoalNearestAttackableWitch(
|
||||
int reciprocalChance,
|
||||
@NotNull Predicate<LivingEntity> targetFilter
|
||||
) implements TargetGoal<Raider> {
|
||||
/**
|
||||
* @param target The type of entities to attack.
|
||||
* @param checkVisibility If visibility should be checked.
|
||||
* @param checkCanNavigate If navigation should be checked.
|
||||
* @param reciprocalChance 1 in reciprocalChance chance of not activating on any tick.
|
||||
*/
|
||||
public TargetGoalNearestAttackableWitch(@NotNull final TestableEntity target,
|
||||
final boolean checkVisibility,
|
||||
final boolean checkCanNavigate,
|
||||
final int reciprocalChance) {
|
||||
this(target, checkVisibility, checkCanNavigate, reciprocalChance, it -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
*/
|
||||
@@ -46,21 +59,29 @@ public record TargetGoalNearestAttackableWitch(
|
||||
&& config.has("checkVisibility")
|
||||
&& config.has("checkCanNavigate")
|
||||
&& config.has("reciprocalChance")
|
||||
&& config.has("targetFilter")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
if (config.has("targetFilter")) {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
|
||||
return new TargetGoalNearestAttackableWitch(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance"),
|
||||
filter::matches
|
||||
);
|
||||
return new TargetGoalNearestAttackableWitch(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance"),
|
||||
filter::matches
|
||||
);
|
||||
} else {
|
||||
return new TargetGoalNearestAttackableWitch(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
config.getBool("checkCanNavigate"),
|
||||
config.getInt("reciprocalChance")
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
Exceptions could be caused by configs having values of a wrong type,
|
||||
|
||||
@@ -25,6 +25,15 @@ public record TargetGoalNearestHealableRaider(
|
||||
boolean checkVisibility,
|
||||
@NotNull Predicate<LivingEntity> targetFilter
|
||||
) implements TargetGoal<Raider> {
|
||||
/**
|
||||
* @param target The target.
|
||||
* @param checkVisibility If visibility should be checked.
|
||||
*/
|
||||
public TargetGoalNearestHealableRaider(@NotNull final TestableEntity target,
|
||||
final boolean checkVisibility) {
|
||||
this(target, checkVisibility, it -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
*/
|
||||
@@ -40,19 +49,25 @@ public record TargetGoalNearestHealableRaider(
|
||||
if (!(
|
||||
config.has("target")
|
||||
&& config.has("checkVisibility")
|
||||
&& config.has("targetFilter")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
if (config.has("targetFilter")) {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
|
||||
return new TargetGoalNearestHealableRaider(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
filter::matches
|
||||
);
|
||||
return new TargetGoalNearestHealableRaider(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
filter::matches
|
||||
);
|
||||
} else {
|
||||
return new TargetGoalNearestHealableRaider(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility")
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
Exceptions could be caused by configs having values of a wrong type,
|
||||
|
||||
@@ -25,6 +25,15 @@ public record TargetGoalNonTameRandom(
|
||||
boolean checkVisibility,
|
||||
@NotNull Predicate<LivingEntity> targetFilter
|
||||
) implements TargetGoal<Tameable> {
|
||||
/**
|
||||
* @param target The types of entities to heal.
|
||||
* @param checkVisibility If visibility should be checked.
|
||||
*/
|
||||
public TargetGoalNonTameRandom(@NotNull final TestableEntity target,
|
||||
final boolean checkVisibility) {
|
||||
this(target, checkVisibility, it -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The deserializer for the goal.
|
||||
*/
|
||||
@@ -40,19 +49,25 @@ public record TargetGoalNonTameRandom(
|
||||
if (!(
|
||||
config.has("targetClass")
|
||||
&& config.has("checkVisibility")
|
||||
&& config.has("targetFilter")
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
if (config.has("targetFilter")) {
|
||||
TestableEntity filter = Entities.lookup(config.getString("targetFilter"));
|
||||
|
||||
return new TargetGoalNonTameRandom(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
filter::matches
|
||||
);
|
||||
return new TargetGoalNonTameRandom(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility"),
|
||||
filter::matches
|
||||
);
|
||||
} else {
|
||||
return new TargetGoalNonTameRandom(
|
||||
Entities.lookup(config.getString("target")),
|
||||
config.getBool("checkVisibility")
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
/*
|
||||
Exceptions could be caused by configs having values of a wrong type,
|
||||
|
||||
Reference in New Issue
Block a user