Skip to content

Commit

Permalink
avoid potential final-tick stability issue with 'push' command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 16, 2020
1 parent 3ab36b2 commit 0be540d
Showing 1 changed file with 3 additions and 13 deletions.
Expand Up @@ -278,50 +278,40 @@ public void execute(final ScriptEntry scriptEntry) {

@Override
public void run() {

if (runs < maxTicks && lastEntity.isValid()) {

Vector v1 = lastEntity.getLocation().toVector();
Vector v3 = v2.clone().subtract(v1).normalize();
Vector newVel = v3.multiply(speed);

lastEntity.setVelocity(newVel);

if (forceAlong) {
Vector newDest = v2.clone().subtract(Origin).normalize().multiply(runs / 20).add(Origin);
lastEntity.teleport(new Location(lastEntity.getLocation().getWorld(),
newDest.getX(), newDest.getY(), newDest.getZ(),
lastEntity.getLocation().getYaw(), lastEntity.getLocation().getPitch()));
}

runs += prec;

// Check if the entity is close to its destination
if (Math.abs(v2.getX() - v1.getX()) < 1.5f && Math.abs(v2.getY() - v1.getY()) < 1.5f
&& Math.abs(v2.getZ() - v1.getZ()) < 1.5f) {
runs = maxTicks;
return;
}

Vector newVel = v3.multiply(speed);
lastEntity.setVelocity(newVel);
// Check if the entity has collided with something
// using the most basic possible calculation
BlockHelper blockHelper = NMSHandler.getBlockHelper();
if (!ignoreCollision && (!blockHelper.isSafeBlock(lastEntity.getLocation().add(v3).getBlock().getType())
|| !blockHelper.isSafeBlock(lastEntity.getLocation().add(newVel).getBlock().getType()))) {
runs = maxTicks;
}

if (no_damage && lastEntity.isLivingEntity()) {
lastEntity.getLivingEntity().setFallDistance(0);
}

// Record the location in case the entity gets lost (EG, if a pushed arrow hits a mob)
lastLocation = lastEntity.getLocation();
}
else {
this.cancel();

if (script != null) {

List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
ScriptQueue queue = new InstantQueue(script.getContainer().getName())
.addEntries(entries);
Expand Down

0 comments on commit 0be540d

Please sign in to comment.