mirror of
https://github.com/Minestom/Minestom.git
synced 2024-10-01 07:57:41 +02:00
Codestyle formatting and several comments
This commit is contained in:
parent
6e23552d9a
commit
504e8cafb4
@ -16,13 +16,13 @@ import java.util.function.BiFunction;
|
|||||||
|
|
||||||
public class RangedAttackGoal extends GoalSelector {
|
public class RangedAttackGoal extends GoalSelector {
|
||||||
|
|
||||||
private long lastShot;
|
private long lastShot;
|
||||||
private final int delay;
|
private final int delay;
|
||||||
private final TimeUnit timeUnit;
|
private final TimeUnit timeUnit;
|
||||||
private final int attackRangeSquared;
|
private final int attackRangeSquared;
|
||||||
private final int desirableRangeSquared;
|
private final int desirableRangeSquared;
|
||||||
private final boolean comeClose;
|
private final boolean comeClose;
|
||||||
private final double spread;
|
private final double spread;
|
||||||
|
|
||||||
private BiFunction<Entity, Position, Projectile> projectileGenerator;
|
private BiFunction<Entity, Position, Projectile> projectileGenerator;
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ public class RangedAttackGoal extends GoalSelector {
|
|||||||
this.stop = true;
|
this.stop = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double distanceSquared = this.entityCreature.getDistanceSquared(target);
|
double distanceSquared = this.entityCreature.getDistanceSquared(target);
|
||||||
boolean comeClose = false;
|
boolean comeClose = false;
|
||||||
if (distanceSquared <= this.attackRangeSquared) {
|
if (distanceSquared <= this.attackRangeSquared) {
|
||||||
if (!CooldownUtils.hasCooldown(time, this.lastShot, this.timeUnit, this.delay)) {
|
if (!CooldownUtils.hasCooldown(time, this.lastShot, this.timeUnit, this.delay)) {
|
||||||
if (this.entityCreature.hasLineOfSight(target)) {
|
if (this.entityCreature.hasLineOfSight(target)) {
|
||||||
@ -91,8 +91,8 @@ public class RangedAttackGoal extends GoalSelector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Navigator navigator = this.entityCreature.getNavigator();
|
Navigator navigator = this.entityCreature.getNavigator();
|
||||||
Position pathPosition = navigator.getPathPosition();
|
Position pathPosition = navigator.getPathPosition();
|
||||||
if (!comeClose && distanceSquared <= this.desirableRangeSquared) {
|
if (!comeClose && distanceSquared <= this.desirableRangeSquared) {
|
||||||
if (pathPosition != null) {
|
if (pathPosition != null) {
|
||||||
navigator.setPathTo(null);
|
navigator.setPathTo(null);
|
||||||
|
@ -19,7 +19,7 @@ import java.util.stream.Collectors;
|
|||||||
public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
||||||
|
|
||||||
private final static byte CRITICAL_BIT = 0x01;
|
private final static byte CRITICAL_BIT = 0x01;
|
||||||
private final static byte NO_CLIP_BIT = 0x02;
|
private final static byte NO_CLIP_BIT = 0x02;
|
||||||
|
|
||||||
private final Entity shooter;
|
private final Entity shooter;
|
||||||
|
|
||||||
@ -53,21 +53,33 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an arrow is stuck in block / hit an entity.
|
||||||
|
*
|
||||||
|
* @param pos position right before current tick.
|
||||||
|
* @param posNow position after current tick.
|
||||||
|
* @return if an arrow is stuck in block / hit an entity.
|
||||||
|
*/
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private boolean isStuck(Position pos, Position posNow) {
|
private boolean isStuck(Position pos, Position posNow) {
|
||||||
if (pos.isSimilar(posNow)) {
|
if (pos.isSimilar(posNow)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance instance = getInstance();
|
Instance instance = getInstance();
|
||||||
Chunk chunk = null;
|
Chunk chunk = null;
|
||||||
Collection<Entity> entities = null;
|
Collection<Entity> entities = null;
|
||||||
|
|
||||||
double part = .25D; // half of the bounding box
|
/*
|
||||||
Vector dir = posNow.toVector().subtract(pos.toVector());
|
What we're about to do is to discretely jump from the previous position to the new one.
|
||||||
int parts = (int) Math.ceil(dir.length() / part);
|
For each point we will be checking blocks and entities we're in.
|
||||||
|
*/
|
||||||
|
double part = .25D; // half of the bounding box
|
||||||
|
Vector dir = posNow.toVector().subtract(pos.toVector());
|
||||||
|
int parts = (int) Math.ceil(dir.length() / part);
|
||||||
Position direction = dir.normalize().multiply(part).toPosition();
|
Position direction = dir.normalize().multiply(part).toPosition();
|
||||||
for (int i = 0; i < parts; ++i) {
|
for (int i = 0; i < parts; ++i) {
|
||||||
|
// If we're at last part, we can't just add another direction-vector, because we can exceed end point.
|
||||||
if (i == parts - 1) {
|
if (i == parts - 1) {
|
||||||
pos.setX(posNow.getX());
|
pos.setX(posNow.getX());
|
||||||
pos.setY(posNow.getY());
|
pos.setY(posNow.getY());
|
||||||
@ -75,8 +87,8 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
|||||||
} else {
|
} else {
|
||||||
pos.add(direction);
|
pos.add(direction);
|
||||||
}
|
}
|
||||||
BlockPosition bpos = pos.toBlockPosition();
|
BlockPosition bpos = pos.toBlockPosition();
|
||||||
Block block = getInstance().getBlock(bpos.getX(), bpos.getY() - 1, bpos.getZ());
|
Block block = instance.getBlock(bpos.getX(), bpos.getY() - 1, bpos.getZ());
|
||||||
if (!block.isAir() && !block.isLiquid()) {
|
if (!block.isAir() && !block.isLiquid()) {
|
||||||
teleport(pos);
|
teleport(pos);
|
||||||
return true;
|
return true;
|
||||||
@ -90,6 +102,10 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
|||||||
.filter(entity -> entity instanceof LivingEntity)
|
.filter(entity -> entity instanceof LivingEntity)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
We won't check collisions with entities for first ticks of arrow's life, because it spawns in the
|
||||||
|
shooter and will immediately damage him.
|
||||||
|
*/
|
||||||
if (getAliveTicks() < 3) {
|
if (getAliveTicks() < 3) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -140,7 +156,7 @@ public class EntityAbstractArrow extends ObjectEntity implements Projectile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void modifyMask(byte bit, boolean value) {
|
private void modifyMask(byte bit, boolean value) {
|
||||||
byte mask = getMask();
|
byte mask = getMask();
|
||||||
boolean isPresent = (mask & bit) == bit;
|
boolean isPresent = (mask & bit) == bit;
|
||||||
if (isPresent == value) {
|
if (isPresent == value) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user