Fix pathfinding + cleanup

This commit is contained in:
themode 2021-02-25 15:48:48 +01:00
parent a0d5ac12bc
commit e8e8022ec6
4 changed files with 11 additions and 22 deletions

View File

@ -75,7 +75,7 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
protected Entity vehicle;
// Velocity
protected Vector velocity = new Vector(); // Movement in block per second
protected Vector velocity = new Vector(); // Movement in block per second
protected boolean hasPhysics = true;
protected double gravityDragPerTick;
@ -814,7 +814,7 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
/**
* Changes the entity instance, i.e. spawns it.
*
* @param instance the new instance of the entity
* @param instance the new instance of the entity
* @param spawnPosition the spawn position for the entity.
* @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager}
*/
@ -845,7 +845,9 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
* @param instance the new instance of the entity
* @throws NullPointerException if {@code instance} is null
* @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager}
* @deprecated Use {@link Entity#setInstance(Instance, Position)} instead.
*/
@Deprecated
public void setInstance(@NotNull Instance instance) {
setInstance(instance, this.position);
}

View File

@ -69,15 +69,10 @@ public class EntityCreature extends LivingEntity implements NavigableEntity, Ent
}
@Override
public void setInstance(@NotNull Instance instance) {
public void setInstance(@NotNull Instance instance, @NotNull Position spawnPosition) {
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
super.setInstance(instance);
}
@Override
public void spawn() {
super.setInstance(instance, spawnPosition);
}
@Override

View File

@ -26,7 +26,6 @@ import net.minestom.server.utils.block.BlockIterator;
import net.minestom.server.utils.time.CooldownUtils;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -250,11 +249,6 @@ public class LivingEntity extends Entity implements EquipmentHandler {
}
}
@Override
public void spawn() {
}
/**
* Gets the amount of arrows in the entity.
*
@ -723,10 +717,10 @@ public class LivingEntity extends Entity implements EquipmentHandler {
* @return if the current entity has line of sight to the given one.
*/
public boolean hasLineOfSight(Entity entity) {
Vector start = getPosition().toVector().add(0D, getEyeHeight(), 0D);
Vector end = entity.getPosition().toVector().add(0D, getEyeHeight(), 0D);
Vector direction = end.subtract(start);
int maxDistance = (int) Math.ceil(direction.length());
Vector start = getPosition().toVector().add(0D, getEyeHeight(), 0D);
Vector end = entity.getPosition().toVector().add(0D, getEyeHeight(), 0D);
Vector direction = end.subtract(start);
int maxDistance = (int) Math.ceil(direction.length());
Iterator<BlockPosition> it = new BlockIterator(start, direction.normalize(), 0D, maxDistance);
while (it.hasNext()) {

View File

@ -102,9 +102,7 @@ public class Metadata {
}
public static Value<NBT> NBT(@NotNull NBT nbt) {
return new Value<>(TYPE_NBT, nbt, writer -> {
writer.writeNBT("", nbt);
});
return new Value<>(TYPE_NBT, nbt, writer -> writer.writeNBT("", nbt));
}
public static Value<int[]> VillagerData(int villagerType,